TriOS-alt/demo/VGA_JB_Demo - Archive [Dat.../VGA_JB_Demo.spin

116 lines
3.5 KiB
Plaintext
Raw Normal View History

2010-11-26 23:58:06 +01:00
''***************************************
''* VGA Tile + Sprite Driver Demo v1.0 *
''* (C) Jim Bagley *
''***************************************
_clkmode = xtal1 + pll16x ' enable external clock and pll times 16
_xinfreq = 5_000_000 ' set frequency to 5 MHZ
CON
NUM_COGS = 3 'if not using sprites, you can set this to 1 :)
NUM_SPRITES = 32 '64 'buffer is 3 words ( X,Y,TILENUM), so use even numbers.
OBJ
vga : "VGA_JB_001"
rend : "VGA_REND_JB_001"
PUB start | i,c,x,y
vga.start(@vga_params)
rend.start(@rend_params)
repeat y from 0 to 29
repeat x from 0 to 63
PutChar(x,y,word[@map][y*64+x])
print(0,0,string("Hallo Welt"))
c:=$deadface
if NUM_SPRITES>0
repeat i from 0 to rend_num_sprites-1 step 2
x:=c?
y:=c?
SetSprite(i ,x ,y,0)
SetSprite(i+1,x+4,y,1)
' SetSprite(i,4+i*3,8+i*2,0)
repeat
repeat while vga_params<>1
repeat while vga_params==1
if NUM_SPRITES>0
wordmove(@sprite_list,@sprite_list2,3*rend_num_sprites)
repeat i from 0 to rend_num_sprites-1
sprite_list2[i*3+0]++
sprite_list2[i*3+1]++
PUB print(x,y,str) | c,a
repeat
c:=byte[str++]
if(c==0)
return
a:=-1
if(c>"A"-1) and (c<"Z"+1)
a:=(c-"A")+10
if(c>"a"-1) and (c<"z"+1)
a:=(c-"a")+10
if(c>"0"-1) and (c<"9"+1)
a:=c-"0"
if(a==-1)
screen[y<<6+x++]:=0
screen[y<<6+x++]:=0
else
a:=(a<<6)+(@font-@chars) '*64 ( 2 4x8 chars per letter ) + offset from chars to font
screen[y<<6+x++]:=a
screen[y<<6+x++]:=a+32
PUB PutChar(x,y,charnum)
screen[y<<6+x]:=charnum<<5
PUB SetSprite(sprnum,x,y,tilenum)
sprite_list2[sprnum*3+0]:=x
sprite_list2[sprnum*3+1]:=y
sprite_list2[sprnum*3+2]:=tilenum<<5
DAT
rend_params
rend_cognum long 0
rend_image long 0
rend_pixels long @pixelsdata+$10 'pointer to line buffers ( (256+8)*rendercogs )
rend_screen long @screen+$10 'pointer to screen charmap buffer ( 64x30 )
rend_chars long @chars+$10 'pointer to screen character image tiles ( 4x8 )
rend_sprite_ptr long @sprite_list+$10 'pointer to sprite list ( X,Y,CHR )
rend_sprchr_ptr long @sprchrs+$10 'pointer to sprite image tiles ( 4x8 )
rend_num_sprites long NUM_SPRITES
'vga_params falls after rend_params
vga_params long 0 'sync
vga_pixels long @pixelsdata+$10 'pointer to line buffers
vga_nextlineptr long @next_line+$10 'pointer to nextline to be draw
vga_enable long 1 'enable display
vga_cogs long NUM_COGS 'number of display lines before looping to top of buffer
sprite_list word 0[3*NUM_SPRITES] '4 words as it reads data in longs
sprite_list2 word 0[3*NUM_SPRITES] '4 words as it reads data in longs
next_line long 0
pixelsdata byte 0[(256+8)*NUM_COGS]
screen word 0*32[64*30] 'Character map layout, TILENUM*32, as you can use pixel offsets into chars if you want, or set the charset to 0, and use as pointer to area
chars file "mario.chr"
sprchrs
font file "font.chr"
byte $0f,$0f,$0f,$0f
byte $0f,$03,$03,$0f
byte $0f,$ff,$ff,$0f
byte $0f,$ff,$ff,$0f
byte $0f,$ff,$ff,$0f
byte $0f,$ff,$ff,$0f
byte $0f,$03,$03,$0f
byte $0f,$0f,$0f,$0f
map file "mario.map"