Skip to content

Commit

Permalink
New tilemap demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Robson committed May 16, 2024
1 parent 6abe8d4 commit e54bf0f
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 65 deletions.
Binary file modified basic/images/graphics.gfx
Binary file not shown.
Binary file modified basic/images/tile_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified basic/storage/graphics.gfx
Binary file not shown.
92 changes: 63 additions & 29 deletions basic/test.bsc
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
'
' New Blitter
' *** Tile map demonstration program ***
'
f = alloc(16)
t = alloc(16)
cls:sprite clear:gload "graphics.gfx"
rect 0,0 solid ink 4 to 319,239

cls:sprite clear:cursor 0,20
dat = alloc(256)
for i = 0 to 255:poke dat+i,(i >> 4)+5:next

call setup(f,0,dat,64,64,1)
call setup(t,$80,0,8,320,8)
t1 = time()
for x = 0 to 39
for y = 0 to 23
while peek($FF00):wend
doke t,x*8+y*320*8
poke $FF04,0
doke $FF05,f
doke $FF07,t
poke $FF01,3
poke $FF00,12
next
next
print time()-t1
call CreateTileMap()
xPos = 0:yPos = 0
call DrawTileMap(xPos,yPos)
repeat
if event(t1,2)
fire = joypad(dx,dy)
xPos = max(xPos+dx,0):yPos = max(yPos+dy,0)
call DrawTileMap(xPos,yPos)
endif
until false
end
'
' This draws the tilemap offset by x,y
'
proc DrawTileMap(xo,yo)
ink 7:print chr$(20);"At offset ";xo;" ";yo;" "
' Sets the tilemap data to draw with and the offset in pixels.
tilemap map,xo,yo
' Draw the tilemap in a window
tiledraw 10,20 to 240,210
' Draw a small second one using the same data
tiledraw 250,20 to 310,80
endproc
'
' This creates a single tile map in memory. See api.pdf
'
proc CreateTileMap()
width = 30:height = 20
' an array of memory with a small header : type, width and height.
map = alloc(width*height+3)
poke map,1: poke map+1, width: poke map+2, height
' Fill the map with $F2 which is a solid green block.
for i = 0 to width*height-1:poke map+3+i,$F2:next
' Draw a frame around the whole screen
call DrawRect(0,0,width,height,$F3,-1)
' Draw some things on the tilemap
call DrawRect(3,2,8,5,6,0)
call DrawRect(17,6,10,7,6,3)
call DrawRect(5,10,10,7,6,5)
endproc

proc setup(a,p,addr,size,offset,count)
doke a+0,addr
poke a+2,p
doke a+4,size:doke a+6,0
doke a+8,offset:doke a+10,0
doke a+12,count:doke a+14,0
endproc
'
' Draw a rectangle on the tile map at (x,y) size (w,h) with frame edgeColour
' and fill with fillColour (if >= 0)
'
proc DrawRect(x,y,w,h,edgeColour,fillColour)
if fillColour >= 0
for i = x to x+w-1
for j = y to y+h-1
call set(i,j,fillColour)
next
next
endif
for i = x to x+w-1:call set(i,y,edgeColour):call set(i,y+h-1,edgeColour):next
for i = y to y+h-1:call set(x,i,edgeColour):call set(x+w-1,i,edgeColour):next
endproc
'
' Set tilemap tile to x,y
'
proc set(x,y,t)
poke map+x+3+y*width,t
endproc
13 changes: 13 additions & 0 deletions documents/release/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ fontsize: 12pt

# Basic Reference

This is a reference for Neo6502's BASIC interpreter.

There are many example programs available which are designed to show and explain the features of the Neo6502
and its hardware and firmware in the examples directory of the release.

For example if.bsc/if.bas so the options available for the 'if' statement, graphics.bsc/graphics.bas show the
drawing commands, and joypad.bsc/joypad.bas show how to access the joypad (or the keyboard backup if none is
plugged in)

Many of these are helpful for understanding specific API functions, as many BASIC commands are just wrappers
for those functions.


## Binary Operators

+------------+----------+--------------------------------------------+
Expand Down
Binary file added examples/basic/examples/tilebenchmark.bas
Binary file not shown.
47 changes: 47 additions & 0 deletions examples/basic/examples/tilebenchmark.bsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'
' Tile map testing program.
'
cls:sprite clear:gload "graphics.gfx":cls
for i = 0 to 64:line i*5,0 ink 1 to i*5,239:next
call BuildTileMap()
' call PrintTileMap()
rect ink 3 frame 9,9 to 307,233
rCount = 0:t1 = time()
for j = 1 to 20
for i = 0 to 15
tilemap map,i,i
tiledraw 10,10 to 306,232
't2 = time()+10:repeat:until time() > t2
rCount = rCount + 1
next
next
t = (time()-t1)/100/rCount
print 1/t
end

proc BuildTileMap()
width = 22:height = 14
map = alloc(width*height+3)
poke map,1
poke map+1, width
poke map+2, height
for i = 0 to width*height-1:poke map+3+i,$F2:next
for i = 0 to width-1:call set(i,0,0):call set(i,height-1,0):next
for i = 0 to height-1:call set(0,i,1):call set(width-1,i,1):next
for i = 2 to 6:call set(i,i,i):call set(i+4,i+1,i):next
for i = 1 to 9:call set(2+i,height-3,i+$F0):next
call set(0,1,$F3):call set(0,2,$F1)
endproc

proc PrintTileMap()
for y = 0 to height-1
for x = 0 to width-1
c = peek(map+3+y*width+x):if c <> 7:print c;:else:print " ";:endif
next
print
next
endproc

proc set(x,y,t)
poke map+x+3+y*width,t
endproc
Binary file modified examples/basic/examples/tiles.bas
Binary file not shown.
93 changes: 57 additions & 36 deletions examples/basic/examples/tiles.bsc
Original file line number Diff line number Diff line change
@@ -1,47 +1,68 @@
'
' Tile map testing program.
'
cls:sprite clear:gload "graphics.gfx":cls
for i = 0 to 64:line i*5,0 ink 1 to i*5,239:next
call BuildTileMap()
' call PrintTileMap()
rect ink 3 frame 9,9 to 307,233
rCount = 0:t1 = time()
for j = 1 to 20
for i = 0 to 15
tilemap map,i,i
tiledraw 10,10 to 306,232
't2 = time()+10:repeat:until time() > t2
rCount = rCount + 1
next
next
t = (time()-t1)/100/rCount
print 1/t
end
' *** Tile map demonstration program ***
'
cls:sprite clear:gload "graphics.gfx"
rect 0,0 solid ink 4 to 319,239

proc BuildTileMap()
width = 22:height = 14
call CreateTileMap()
xPos = 0:yPos = 0
call DrawTileMap(xPos,yPos)
repeat
if event(t1,2)
fire = joypad(dx,dy)
xPos = max(xPos+dx,0):yPos = max(yPos+dy,0)
call DrawTileMap(xPos,yPos)
endif
until false
end
'
' This draws the tilemap offset by x,y
'
proc DrawTileMap(xo,yo)
ink 7:print chr$(20);"At offset ";xo;" ";yo;" "
' Sets the tilemap data to draw with and the offset in pixels.
tilemap map,xo,yo
' Draw the tilemap in a window
tiledraw 10,20 to 240,210
' Draw a small second one using the same data
tiledraw 250,20 to 310,80
endproc
'
' This creates a single tile map in memory. See api.pdf
'
proc CreateTileMap()
width = 30:height = 20
' an array of memory with a small header : type, width and height.
map = alloc(width*height+3)
poke map,1
poke map+1, width
poke map+2, height
poke map,1: poke map+1, width: poke map+2, height
' Fill the map with $F2 which is a solid green block.
for i = 0 to width*height-1:poke map+3+i,$F2:next
for i = 0 to width-1:call set(i,0,0):call set(i,height-1,0):next
for i = 0 to height-1:call set(0,i,1):call set(width-1,i,1):next
for i = 2 to 6:call set(i,i,i):call set(i+4,i+1,i):next
for i = 1 to 9:call set(2+i,height-3,i+$F0):next
call set(0,1,$F3):call set(0,2,$F1)
' Draw a frame around the whole screen
call DrawRect(0,0,width,height,$F3,-1)
' Draw some things on the tilemap
call DrawRect(3,2,8,5,6,0)
call DrawRect(17,6,10,7,6,3)
call DrawRect(5,10,10,7,6,5)
endproc

proc PrintTileMap()
for y = 0 to height-1
for x = 0 to width-1
c = peek(map+3+y*width+x):if c <> 7:print c;:else:print " ";:endif
'
' Draw a rectangle on the tile map at (x,y) size (w,h) with frame edgeColour
' and fill with fillColour (if >= 0)
'
proc DrawRect(x,y,w,h,edgeColour,fillColour)
if fillColour >= 0
for i = x to x+w-1
for j = y to y+h-1
call set(i,j,fillColour)
next
next
print
next
endif
for i = x to x+w-1:call set(i,y,edgeColour):call set(i,y+h-1,edgeColour):next
for i = y to y+h-1:call set(x,i,edgeColour):call set(x+w-1,i,edgeColour):next
endproc

'
' Set tilemap tile to x,y
'
proc set(x,y,t)
poke map+x+3+y*width,t
endproc

0 comments on commit e54bf0f

Please sign in to comment.