Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - rain_storm

Pages: 1 2 3 [4] 5
61
C / C++ /C# / How to link to tinyptc?
« on: October 14, 2007 »
I am hitting a brickwall here with this library I cant seem to build the .lib file from the files that came with tinyptc, I tried to link to a static library but the compiler complains that tinyptc doesnt exist, I even tried including the library directly in the project itself, still no joy. Has anyone got a precompiled tinyptc.lib that I could use or perhaps some info explaining how to link to it as a static library

62
Yabasic / Fake Phong Shading
« on: September 26, 2007 »
This is a very fast fake phong shaded circle drawing routine that can handle ovals and even cones (move the highlight to a point outside of the circle to produce cones) use it freely

Code: [Select]
# FAKE PHONG SHADED CIRCLES
open window 640, 512
circles = 255

sub pcircle(a,b,c,d,g,h)
  doubpi = pi*2
  x = a+c/g
  y = b+d/h
  f = pi/30
  for e = f to doubpi step f
    gtriangle x,y to a+cos(e)*c,b+sin(e)*d to a+cos(e+f)*c,b+sin(e+f)*d
  next
end sub

label loop
  setdispbuf draw
  draw = 1 - draw
  setdrawbuf draw
  for c = 0 to circles
    centerx = ran(640)
    centery = ran(512)
    radiusx = ran(50) + 25
    radiusy = ran(50) + 25
    r = ran(255)
    g = ran(255)
    b = ran(255)
    l = ran(0.6)
    setrgb 1, r, g, b
    setrgb 2, l*r, l*g, l*b
    setrgb 3, l*r, l*g, l*b
    pcircle(centerx,centery, radiusx,radiusy, 3,-3)
  next
  goto loop

Here is the same routine but with an extra parameter that allows you to rotate the ovals
Code: [Select]
sub pcircle(a,b, c,d, g,h, r)
  doubpi = pi*2
  x = a + (c/g) * cos(r)
  y = b + (d/h) * sin(r)
  f = pi/30
  for e = f+r to doubpi+r step f
    gtriangle x,y to a+cos(e)*c,b+sin(e)*d to a+cos(e+f)*c,b+sin(e+f)*d
  next
end sub

63
General chat / Happy Birthday CLANKY
« on: September 25, 2007 »
Happy birthday buddy

64
Yabasic / Simple AI for following a target
« on: September 18, 2007 »
this is a very basic routine that i did a long time ago that will control an NPC's reaction to your movements so that it will always turn to face you while moving towards you. If you are directly in the line of sight of an NPC that is targeting you the NPC will shoot at you (if you move out of the way they will miss)

Code: [Select]
########################################
# Controls angular direction and inertial momentum in 3D #
# As well as governing camera & charictor A.I. actions   #
# such as "homming in", "following" & "firing weapon".   #
##########################################################

' Initialisation
mom.inc = 1
mom.max = 20
ang.inc = .25
ang.max = 20
rng.max = 100
radian = pi / 180
halfpi = pi / 2

' Charictor dynamics
charictors = 9
camera = 0
hero = 1
dim posx(charictors), posy(charictors), posz(charictors)
dim dirx(charictors), diry(charictors), dirz(charictors)
dim momx(charictors), momy(charictors), momz(charictors)
dim angx(charictors), angy(charictors), angz(charictors)
dim rotx(charictors), roty(charictors), rotz(charictors)
dim fire(charictors), ammo(charictors), magz(charictors)
dim looktarget(charictors), movetarget(charictors)

for c = 0 to charictors
  if c<>hero then
    posx(c) = int(ran(640)) - 320
    posy(c) = int(ran(512)) - 256
    posz(c) = int(ran(0))
    rotx(c) = int(ran(15))*radian
    roty(c) = int(ran(15))*radian
    rotz(c) = int(ran(15))*radian
    target = int(ran(charictors))
    looktarget(c) = target
    movetarget(c) = target
  endif
next
looktarget(camera) = hero
movetarget(camera) = hero

setrgb 0, 0, 0, 90:window origin "cc":open window 640, 512
Up = 16:Right = 32:Down = 64:Left = 128
L2 = 256:R2 = 512:L1 = 1024:R1 = 2048
Trin = 4096:Circ = 8192:Cros = 16384:Sqar = 32768

' Calculation
sub navigate(c)
' Momentum
    xm = momx(c)
    if xm>0 then xm = xm - mom.inc
    elsif xm<0 then xm = xm + mom.inc endif
    if xm>mom.max then xm = mom.max
    elsif xm<-mom.max then xm = -mom.max endif
    momx(c) = xm

    ym = momy(c)
    if ym>0 then ym = ym - mom.inc
    elsif ym<0 then ym = ym + mom.inc endif
    if ym>mom.max then ym = mom.max
    elsif ym<-mom.max then ym = -mom.max endif
    momy(c) = ym

' Orientation
    a = rotz(c)
    if a>ang.max then a = ang.max
    elsif a<-ang.max then a = -ang.max endif
    a = a*radian

' Direction
    angz(c) = angz(c) + a
    a = angz(c)
    xm = momx(c)
    ym = momy(c)
    if ym<>0 then
      dx1 = sin(a)*ym:    dy1 = cos(a)*ym
    else    dx1 = 0:    dy1 = 0  endif
    if xm<>0 then
      dx2 = sin(a+halfpi)*xm:    dy2 = cos(a+halfpi)*xm
    else    dx2 = 0:    dy2 = 0  endif
    dirx(c) = (dx1+dx2) / 2
    diry(c) = (dy1+dy2) / 2

' Limit to screen dimensions
    posx = posx(c) + dirx(c)
    posy = posy(c) + diry(c)
    if posx>300 posx = 300
    if posx<-300 posx = -300
    if posy>240 posy = 240
    if posy<-240 posy = -240
    posx(c) = posx
    posy(c) = posy
end sub

sub homein(viewer, target)
  posx = posx(viewer)
  posy = posy(viewer)
  trgx = posx(target)
  trgy = posy(target)
  vx = posx(viewer)-sin(angz(viewer))
  vy = posy(viewer)-cos(angz(viewer))
  cp = (posx-trgx)*(vy-trgy) - (vx-trgx)*(posy-trgy)
  rotz(viewer) = -cp / 10

' Fire if target is roughly in viwers sights
  if cp>-10 and cp<10 then    fire(c) = 1-fire(c)
  else    fire(c) = 0 endif
end sub

sub follow(viewer, target)
  posx = posx(viewer)
  posy = posy(viewer)
  trgx = posx(target)
  trgy = posy(target)
  adjacent = trgx-posx
  opposite = trgy-posy
  hypotenuse = sqrt( sqr(adjacent) + sqr(opposite))
  if hypotenuse>rng.max then
    posx = adjacent / hypotenuse + posx
    posy = opposite / hypotenuse + posy
  endif
  posx(viewer) = posx
  posy(viewer) = posy
end sub


label loop
  setdrawbuf curbuffer:  curbuffer = 1 - curbuffer
  setdispbuf curbuffer:  clear window
  gosub readpad

  for c = 0 to charictors
    if c<>hero momy(c) = momy(c) - mom.inc*2
    navigate(c)
    posx = posx(c)
    posy = posy(c)

    setrgb 1, 255, 100, 100
    if c=hero setrgb 1, 100, 255, 100
    if c=camera setrgb 1, 100, 100, 255
    fill circle posx, posy, 10

    if fire(c)=0 f = 20
    if fire(c)=1 f = 1000
    line posx, posy to posx-sin(angz(c))*f, posy-cos(angz(c))*f
  next

 framerate = framerate + 1
  if mod(framerate,5)=0 then
    for c = 0 to charictors
      if c<>hero homein(c, looktarget(c))
    next
  elsif mod(framerate,10)=0 then
    for c = 0 to charictors
      if c<>hero follow(c, movetarget(c))
    next
  endif
goto loop

label readpad
  control = peek("port1")

  if and(control, Up)>0 then momy(hero) = momy(hero) - 2
  elsif and(control,Down)>0 then momy(hero) = momy(hero)+2
  endif
  if and(control, Right)>0 then momx(hero) = momx(hero) +2
  elsif and(control,Left)>0 then momx(hero) = momx(hero)-2
  endif

  if and(control, Circ)>0 then
    rotz(hero) = rotz(hero) - ang.inc
  elsif and(control, Sqar)>0 then
    rotz(hero) = rotz(hero) + ang.inc
  else rotz(hero) = 0 endif

  if and(control, R1)>0 then fire(hero) = 1 - fire(hero)
  else fire(hero) = 0 endif
return


65
General chat / GFX card causing me grief
« on: June 07, 2007 »
I got myself a graphics card today NVidia GeForce FX5200 but the drivers wont install. The error is
"The VGA detected seems not XFX's product"
I cant figure it out I uninstalled the VGA from the device manager along with all the other video adapter stuff. Now tiny code runs about 10 times slower and San Andreas will not start up because it cant enter fullscreen mode
 I just hope I can get this fixed as its the only PCI compatible GFX card that I could find that does shaders 2.0+

66
Freebasic / Another plasma effect using tinyptc
« on: May 16, 2007 »
Here is a neat plasma effect its not the fastest but it runs okay here. I think it could be stripped down further though but it does the job for me

67
Freebasic / My First FB Program :D
« on: May 05, 2007 »
Okay I have given up learning C++ with Visual studio its simply to finicky for my taste hell I found assembler a whole lot easier to pick up than that so I turned my attention back towards basic and well this is my first proper program in FreeBasic that I actually understand (Except for the triangle drawing subroutine which was borrowed from one of Shockys post over on the FreeBasic Forum)

Code: [Select]
'Declarations For The Program ...
Option Static
Option Explicit

Const XRES = 800
Const YRES = 600
Const GridX = 63
Const GridY = 63
Const METER = 5

Dim Shared As Uinteger BUFFER(XRES*YRES)
Dim Shared As Double   OldTime, GAdd
Dim Shared As Uinteger NewTime, Ticks

#include Once "tinyptc.bi"
Declare Sub FLAT_TRIANGLE( Byval X1 As Integer , Byval Y1 As Integer, Byval X2 As Integer , Byval Y2 As Integer , Byval X3 As Integer, Byval Y3 As Integer , Byval TC As Integer)
Declare Sub FPS()

'Open Graphics Screen ...
If (ptc_open("Triangles", XRES, YRES) = 0) Then
    End -1
End If



' Initialise The Vertex Array & Variables For Accessing Them ...
Type Vertex
    X As Integer
    Y As Integer
End Type

Dim As Vertex  V(0 To GridX, 0 To Gridy)
Dim AS Integer X, Y
Dim As Single ROTX,     ROTY,     ROTZ
Dim As Single CX,SX,    CY,SY,    CZ,SZ
Dim As Single XX,XY,XZ, YX,YY,YZ, ZX,ZY,ZZ
Dim As Single X1,Y1,Z1, X2,Y2,Z2, X3,Y3,Z3
Dim As Single ANG
ANG = 3.14159/180




'Main Drawing Routine ...
OldTime = Timer
Do
    FPS()
    GAdd += 0.02

    'Rotate the planes ...
    ROTX = ROTX + ANG
    ROTY = ROTY + ANG
    ROTZ = ROTZ + ANG
    CX = Cos(ROTX)
    CY = Cos(ROTY)
    CZ = Cos(ROTZ)
    SX = Sin(ROTX)
    SY = Sin(ROTY)
    SZ = Sin(ROTZ)
   
    'Optimised Rotation Shortuct ...
    XX = CY*CZ*METER*300
    XY = (CX*-SZ + SX*SY*CZ)*METER*300
    XZ = (CX*SY*CZ - SX*-SZ)*METER
    YX = CY*SZ*METER*300
    YY = (CX*CZ + SX*SY*SZ)*METER*300
    YZ = (CX*SY*SZ - SX*CZ)*METER
    ZX =-SY*METER*300
    ZY = SX*CY*METER*300
    ZZ = CX*CY*METER

    X1 = -XX*GridX/2 -YX*GridY/2
    Y1 = -XY*GridX/2 -YY*GridY/2
    Z1 = -XZ*GridX/2 -YZ*GridY/2 + 300
    For Y = 0 To GridY
        X2 = X1
        Y2 = Y1
        Z2 = Z1
        For X = 0 To GridX
            With V(X, Y)
                .X = 400 + X2 / Z2
                .Y = 300 + Y2 / Z2
            End With
            X2 = X2 + XX
            Y2 = Y2 + XY
            Z2 = Z2 + XZ
        Next X
        X1 = X1 + YX
        Y1 = Y1 + YY
        Z1 = Z1 + YZ
    Next Y


    Dim C As Integer
    C = 0
    For Y = 1 To GridY
        For X = 1 To GridX
            FLAT_TRIANGLE ( _
                V(X-1,Y-1).X, V(X-1,Y-1).Y, _
                V(X-1,Y).X, V(X-1,Y).Y, _
                V(X,Y).X, V(X,Y).Y, _
                rgb( C*255, C*255, 255) _
            )
            FLAT_TRIANGLE ( _
                V(X-1,Y-1).X, V(X-1,Y-1).Y, _
                V(X,Y-1).X, V(X,Y-1).Y, _
                V(X,Y).X, V(X,Y).Y, _
                rgb( C*255, C*255, 255) _
            )
            C = 1 - C
        Next X
    Next Y
   
    PTC_UPDATE@BUFFER(0)
    Erase BUFFER
    Ticks = Ticks + 1
Loop Until Inkey$ <> ""




'SubRoutine For Calculating Framerate ...
Sub FPS()
    Dim Z As Uinteger
    If (Timer-OldTime) >= 1 Then
        NewTime = Ticks
        OldTime = Timer
        Print "FPS ... " + Str$(NewTime)
        Ticks = 0
    End IF
End Sub




'SubRoutine For Drawing Flat Shaded Triangles ... (Borrowed From Shackwaves Code)
Sub FLAT_TRIANGLE(Byval X1 As Integer , Byval Y1 As Integer, Byval X2 As Integer , Byval Y2 As Integer , Byval X3 As Integer, Byval Y3 As Integer , Byval TC As Integer)
'-------------------------------------------------------------------------
' FLAT TRIANGLE RENDERER WITH ASSEMBLY LANGUAGE RASTERISING BY SHOCKWAVE ^ DBF ^ S!P 2006.
'-------------------------------------------------------------------------
'-------------------------------------------------------------------------
' WE NEED TO SORT THESE POINTS INTO ORDER FROM TOP TO BOTTOM, AN EXCHANGE SORT IS OK.
' AS WE ONLY HAVE GOT 3 POINTS TO ARRANGE.
'-------------------------------------------------------------------------
Dim As Integer TEMPX,TEMPY,LO,LI
                Dim As Integer PX(3)
                Dim As Integer PY(3)
                Dim TFLAG As Integer
                Dim pp As Uinteger Ptr
                Dim As Integer IL1,IL2,SLICE
                TFLAG=0
        PX(1)= X1
        PX(2)= X2
        PX(3)= X3
       
        PY(1)= Y1
        PY(2)= Y2
        PY(3)= Y3
For LO = 1 To 2
    For LI =1 To 2     
        If PY(LI+1) <= PY(LI) Then
        TEMPX = PX(LI) : TEMPY = PY(LI)
        PX(LI) = PX(LI+1)
        PY(LI) = PY(LI+1)
        PX(LI+1) = TEMPX
        PY(LI+1) = TEMPY
        End If   
    Next LI
Next LO

        Dim As Double XP1,XP2:' SCREEN POSITIONS.
        Dim As Double XI1,XI2:' INTERPOLATIONS.
       
'***
'*** REGULAR TRIANGLE (Y1<Y2 Y2<Y3)
'***

If PY(1)<PY(2) And PY(2)<PY(3) Or (PY(2) = PY(3)) Then
    TFLAG=1
XP1 = PX(1)
XP2 = PX(1)
XI1 = (PX(1)-PX(2)) / (PY(2) - PY(1))
XI2 = (PX(1)-PX(3)) / (PY(3) - PY(1))

For LO = PY(1) To PY(2)-1
   
If LO>=0 And LO<YRES Then

    If XP1<=XP2 Then
        IL1=XP1
        IL2=XP2
    Else
        IL1=XP2
        IL2=XP1
    End If
   
    If IL2>XRES Then IL2=XRES
    If IL1<0 Then IL1=0

    SLICE = IL2-IL1
    If SLICE>0 Then
    PP = @BUFFER(IL1+(LO*XRES))   
    asm
        mov eax,dword Ptr[TC]
        mov ecx, [slice]
        mov edi, [PP]
        rep stosd
    End asm   
    End If
   

End If

XP1=XP1-XI1
XP2=XP2-XI2
Next

XI1 = (PX(2)-PX(3)) / (PY(3) - PY(2))
XP1 = PX(2)

For LO = PY(2) To PY(3)
If LO>=0 And LO<YRES Then
    If XP1<=XP2 Then
        IL1=XP1
        IL2=XP2
    Else
        IL1=XP2
        IL2=XP1
    End If

    If IL2>XRES Then IL2=XRES
    If IL1<0 Then IL1=0

    SLICE = IL2-IL1
    If SLICE>0 Then
    PP = @BUFFER(IL1+(LO*XRES))   
    asm
        mov eax,dword Ptr[TC]
        mov ecx, [slice]
        mov edi, [PP]
        rep stosd
    End asm   
    End If
End If
XP1=XP1-XI1
XP2=XP2-XI2
Next

End If


'***
'*** FLAT TOPPED TRIANGLE Y1=Y2
'***

If TFLAG=0 And PY(1) = PY(2) Then
   
        TFLAG=1
        XP1 = PX(1)
        XP2 = PX(2)
        XI1 = (PX(1)-PX(3)) / (PY(3) - PY(1))
        XI2 = (PX(2)-PX(3)) / (PY(3) - PY(2))
For LO = PY(1) To PY(3)
If LO>=0 And LO<YRES Then
    If XP1<=XP2 Then
        IL1=XP1
        IL2=XP2
    Else
        IL1=XP2
        IL2=XP1
    End If
   
    If IL2>XRES Then IL2=XRES
    If IL1<0 Then IL1=0
   
    SLICE = IL2-IL1
    If SLICE>0 Then
    PP = @BUFFER(IL1+(LO*XRES))   
    asm
        mov eax,dword Ptr[TC]
        mov ecx, [slice]
        mov edi, [PP]
        rep stosd
    End asm   
    End If
End If
    XP1=XP1-XI1
    XP2=XP2-XI2

Next
End If
End Sub


So how did I do? Anything in there that looks improper please point it out

68
GFX & sound / Terminator
« on: April 30, 2007 »
Is this ascii art or do you actually have to use letters and punctuation? The font I used was terminal does it show up as terminal for you guys

69
General chat / earthlike planet
« on: April 26, 2007 »
Earthlike planet found we are starting to fill in some blanks spots in the drake equation, anyone wanna discuss this.

70
Console homebrew / Best GBA Emulator?
« on: April 23, 2007 »
Okay I have downloaded Ham_dev_kit and also some demos from Here but I dont know how to get the roms to run. Do I need a dedicated emulator to run these? If so which emulator should I go for

71
ASM / checkers
« on: April 12, 2007 »
this is an experiment I got plenty of bytes left for a 64b but I still cant make it colourful cos all my registers are tied up if anyone can improve on this please post here an explaination of the workaround

edit -
Don't run this at work or school the beeps and squeks the speaker makes will attract the attention of people nearby (sorry Thygrion)

edit -
Fixed the colours even managed to syncronize the tune to the display :D

72
ASM / Diamonds.com
« on: April 09, 2007 »
This was originally 27b but I used the additional 4b to exit cleanly in text mode something that is unusual for a 32b demo. Hope ya'll like it

73
ASM / scrolling boxes
« on: April 03, 2007 »
This one is still hot from the oven can anyone take a screen shot for me my printscreen doesnt work in mode 13h and niether does my screen capture software (hoversnap)

74
ASM / Tiny scrolling bars
« on: April 03, 2007 »
Well here's a little something I cooked up its as small as I could get it enjoy :D

75
Console homebrew / Anyone code in MIPS Rxxxx ???
« on: March 31, 2007 »
I was just wondering coz I came across a few sites that had demos that ran on N64, PS1, PS2, etc I was just wondering how easy / hard it was to pick up. Is it worth spending a whole lotta time on or is it yesterdays fab?
I was thinking of installin the Indhependence day thing on my PS2 and see what I can code up for it. But just thought I check out some unbiosed opinions first

76
ASM / A question regarding macros
« on: March 28, 2007 »
I was wondering if this kind of thing is considered good practice or if its real bad I wanna simulate subroutine calls by using macros to define the inputs but use a proceedure to do all the horse work the advantage being that only a small portion of code is assembled at the point of calling the macro also functionality of macros is improved you can loop in a proceedure but not in macros.
The disadvantage is that it becomes necessary to use the org directive prior to include directives and I am not sure if it works in multiple segment exes. Also proceedures will make their way into code even if the macro which uses that proceedure is not called in the program. Also com files require that a jump be placed before the include directive or else those proceedures will be executed (not good when cpu comes accross a ret instruction)

This example demonstrates the idea what it does is prints a zero terminated string to the screen at the specified co-ordinates then returns the length of the string. both macros share the same proceedure that calculates the length of the string so thats one bonus

Code: [Select]
name "consoleio.inc"
org  100h
jmp  start

$col db 0Fh
;#######################################################
; prints string to screen at the given co-ordinates
; current text colour is used (set colour with col$)
text macro x$,y$,$
    push es       ; preserve es
    pusha         ; preserve registers
    mov  bx,x$    ; get x value
    mov  dx,y$    ; get y value
    lea  si,$     ; get string offset
    call textproc
    popa          ; restore registers
    pop  es       ; restore es
text endm
textproc proc
    ; find length of string
    mov   di,si    ; string address
    call lenproc
    mov   di,si    ; string address
    ; prepare offset for co-ordinates
    push  0B800h   ; screen text buffer
    pop   es
    mov   ax,160   ; screen width in bytes (80 words/chars)
    mul   dx       ; convert to offset
    add   ax,bx    ; x co-ordinate
    add   ax,bx    ; double x (for word)
    mov   di,ax    ; load finished offset
    ; print it to screen
    mov   ah,$col  ; colour attributes
    textloop:
        lodsb      ; load next char
        stosw      ; store char & colour
        loop textloop
    ret
textproc endp

;#######################################################
; returns the length of strint (terminated by zero)
; result is stored in cx
len$ macro $
    push di
    lea  di,$   ; string offset
    call lenproc
    pop  di
len$ endm
lenproc proc
    push es     ; preserve es
    pusha       ; preserve registers
    cld         ; clear flags
    xor   al,al ; compare zero
    mov   cx,-1 ; compare maximum 0FFFFh times
    repnz scasb ; compare until both are zero
    not   cx    ; invert cx
    dec   cx    ; point cx to char before the zero
    mov   es,cx ; conserve value in es
    popa        ; restore registers
    mov  cx,es  ; restore value
    pop  es     ; restore es
    ret
lenproc endp

start:
    mov  ax,03h     ; text mode
    int  10h        ; bios call
    mov  ah,01h     ; cursor attributes
    mov  cx,2B0Bh   ; hide blinking
    int  10h        ; bios call
    text 5,5,string ; prints string to screen
    len$ string     ; length of input is stored to cx
    xor  ah,ah      ; wait for keypress
    int  16h
    ret

    string db "Hello world",00h

77
Heres my entry which is written in Yabasic you will need Jims emulator to run it you can find the emulator here - http://members.iinet.net.au/~jimshaw/Yabasic/ps2yabasic1.6b3.zip
I have managed to squeze in 12 effects  :D Hope you guys like what I've done

78
Yabasic / Matrix Effect
« on: March 08, 2007 »

Code: [Select]
open window 640, 512
resx = 80
resy = 64
size = 640/resx
dim buffer(resx,resy)
dim drop(resx), fall(resx)

for a = 0 to resx
  drop(a) = rnd(resy)
  fall(a) = rnd(0.5)+0.5
next

repeat
  setdispbuf draw
  draw = 1 - draw
  setdrawbuf draw
  a = 0
  for x = 0 to resx a = a + size
    drop(x) = drop(x) + fall(x)
    if (drop(x) > resy) then
      drop(x) = drop(x) - resy
      fall(x) = rnd(0.5) + 0.5
    fi
    buffer(x,drop(x)) = 255
    b = 0
    for y = 0 to resy b = b + size
      c = buffer(x,y)
      setrgb 1, 0, c, 0
      fill box a,b to a-size,b-size
      buffer(x,y) = c - 4
    next
  next
until (0=1)

sub rnd(range) rnd$ = time$ : length = len(rnd$)
  local rnd$(length) : static rnd, seed
  for l = 1 to length
    if (mid$(rnd$,l,1) = "-") then rnd$ = left$(rnd$,l-1) + " " + right$(rnd$,length-l)
    else rnd$ = left$(rnd$,l-1) + str$(9-val(mid$(rnd$,l,1))) + right$(rnd$,length-l)
    fi
  next l
  seed = ran(rnd) : if (seed < 1) seed = range + 1
  random = token(rnd$, rnd$())
  for r = 1 to random rnd = val(rnd$(r)) + rnd next
  rnd = ran(rnd) / ran(seed) : return range*frac(rnd)
end sub
[/font]

79
ASM / Fast Text Routine
« on: March 06, 2007 »
Basically what this does is write a char to the text buffer (offset 0B800h) in text mode only the charictors ascii is held in cl and the colour is held in ch then we store cx to whatever address (which is in si) you want. updating the address by 2 bytes with each write (colour & ascii). this meathod is about ten times faster than using interrupts. I have the routine down to about 34 bytes i think. it will compile with FASM and emu8086.
Code: [Select]
org 100h
mov  al, 03h ; enter text mode
int  10h        ; do it ya lazy bios!
push 0B800h     ; text buffer offset
pop  ds         ; point ds to offset
mov  cl, 58h ; ascii char
call text

text:
  mov [si], cx  ; write colour and char
  add si, 02h   ; update cursor
  inc ch        ; update colour
  cmp si, 0FA0h ; check for screen limit
  jb  text      ; loop if necessary

  inc ch        ; scroll colours
  xor si, si    ; reset cursor
  mov ah, 01h   ; get keyboard input
  int 16h       ; ahem
  jz  text      ; loop if necessary
  ret           ; lets get outta here

80
Yabasic / Compressed Font
« on: February 14, 2007 »
Heres a little conversion of this font but its been altered so that each scanline takes up only one byte of data. This compresses the font to 1/8th of its original size  ;D press any key to move on to the next charictor once the full sequence has been displayed it starts over again. This should prove useful for text displays when you really dont want to use a lot of bytes creating a font. remember that the bitmaps dont use two dimensions (x,y) so you need to get the correct index value. You may chose to change this it makes little or no difference.

Code: [Select]
open window 640, 512
size = 50
set_font(01)

label display
   for c = 1 to chars
      repeat
         setdispbuf draw
         draw = 1 - draw
         setdrawbuf draw
         clear window
         for y = 1 to fonty fy = y * size
            for x = 1 to fontx fx = x * size
               p = (y-1)*fontx + x : rem access the correct array entry through indexing
               box fx, fy to fx + size, fy + size
               if (font(c, p) <> 0) then
                  fill box fx, fy to fx + size, fy + size
               fi
            next
         next
      until (inkey$(0) <> "")
   next
   goto display

sub set_font(font_num)
   on font_num goto 01

00 read chars, fontx, fonty
   redim font(chars, fontx*fonty)
   for c = 1 to chars
      p = 1
      for y = 1 to fonty
         read f
         n = 1
         for x = 1 to fontx
            if (and(n,f) <> 0) then
               font(c, p) = 1
            else
               font(c, p) = 0
            fi
            p = p + 1
            n = n * 2
         next
      next
   next
   return

01 restore font_01 : goto 00
end sub


label font_01
data 64 : rem total charictor amount
data 08 : rem font width in pixels
data 08 : rem font height in pixels
data 000,000,000,000,000,000,000,000
data 056,056,056,056,000,056,056,056
data 238,238,238,000,000,000,000,000
data 000,110,255,110,110,255,110,000
data 124,238,031,014,014,014,014,255
data 000,230,118,056,028,110,103,000
data 024,126,126,255,255,126,126,024
data 056,056,056,000,000,000,000,000
data 060,030,014,014,014,014,030,060
data 060,120,112,112,112,112,120,060
data 000,090,060,126,126,060,090,000
data 000,024,024,126,126,024,024,000
data 000,000,000,000,000,056,056,060
data 000,000,000,126,126,000,000,000
data 000,000,000,000,000,000,024,024
data 000,224,112,056,028,014,007,000
data 126,231,231,239,247,231,231,126
data 056,060,060,056,056,056,056,124
data 124,238,224,126,007,007,199,255
data 126,231,112,224,224,224,231,126
data 119,119,254,028,028,028,028,028
data 127,119,007,126,224,224,231,126
data 003,003,003,127,231,231,231,126
data 127,231,240,224,224,224,224,224
data 126,231,126,231,231,231,231,126
data 254,227,254,224,224,224,224,224
data 000,000,056,056,000,056,056,060
data 000,000,056,056,000,056,056,056
data 000,028,014,007,007,014,028,000
data 000,060,060,000,000,060,060,000
data 000,056,112,224,224,112,056,000
data 126,231,120,056,000,056,056,056
data 000,060,102,090,066,090,060,000
data 126,231,255,231,231,231,231,231
data 127,231,127,231,231,231,231,127
data 126,231,007,007,007,231,231,126
data 127,231,231,231,231,231,231,127
data 126,231,015,007,007,231,231,126
data 126,231,015,007,007,007,007,007
data 126,231,007,007,247,231,231,126
data 231,231,255,231,231,231,231,231
data 062,028,028,028,028,028,028,062
data 254,231,224,160,239,231,231,126
data 119,119,063,231,231,231,231,231
data 007,007,007,007,007,231,231,126
data 118,255,239,239,231,231,231,231
data 127,231,231,231,231,231,231,231
data 126,231,231,231,231,231,231,126
data 127,231,127,007,007,007,007,007
data 126,231,231,231,215,183,103,126
data 127,231,127,231,231,231,231,231
data 126,231,007,126,224,231,231,126
data 062,028,028,028,028,028,028,028
data 231,231,231,231,231,231,231,126
data 231,231,231,231,231,231,102,060
data 231,231,231,231,239,239,239,126
data 231,231,126,231,231,231,231,231
data 231,231,254,224,224,231,231,126
data 254,231,224,126,007,007,231,127
data 015,007,007,007,007,007,007,015
data 003,007,014,028,056,112,224,192
data 240,224,224,224,224,224,224,240
data 024,060,102,231,000,000,000,000
data 000,000,000,000,000,000,000,126


Pages: 1 2 3 [4] 5