Me starting out with scrolling tiles

All aspects of programming on the Commander X16.
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Me starting out with scrolling tiles

Post by rje »


@ZeroByte recommended I start playing with tiles by writing a BASIC program.  Which turns out to be a pretty good idea!

I also dug into my Rogue Forest code, which uses Layer 0 to emulate a fog of war situation.

Et voila', my first scrolling code.




200 REM ------------------------



201 REM SET UP VIDEO REGISTERS



202 REM ------------------------



210 POKE $9F2D, %01100000 :REM MAP HEIGHT=1, WIDTH=2 = 64X128 TILES



220 POKE $9F2E, %10000000 :REM MAP BASE ADDR = 128 X512 = $10000.



230 POKE $9F2F, %11111000 :REM TILE BASE ADDR = $1F000.



240 REM ALSO, TILE HT=0, WD=0, SO 8 PIXELS X 8 PIXELS

 


300 REM -----------------------------------



301 REM NO SCROLLING YET, PLEASE ($9F30-$9F33)



302 REM -----------------------------------



310 POKE $9F30, 0



320 POKE $9F31, 0



330 POKE $9F32, 0



340 POKE $9F33, 0

 


400 COLOR 1,0 :CLS :REM 0=TRANSPARENT

 


500 POKE $9F29, %00110001 :REM $31=LAYERS 1,0. OUTPUT MODE=1 (VGA)

 


600 REM -----------------------------------



601 REM NOW SCROLL, ETERNALLY



602 REM -----------------------------------



610 FOR X = 1 TO 255



620 POKE $9F30, X



630 NEXT



640 GOTO 610




ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

Me starting out with scrolling tiles

Post by ZeroByte »


I need to either find or write a bmp->tiles utility because this gave me an idea for a funny X16 port of an old meme from YTMND.

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Me starting out with scrolling tiles

Post by rje »


So, these scroll registers are the horizontal and vertical pixel offsets.  If I use a 32 x 32 map of sixteen bit tiles, then the effective horiz and vert offset values run from 0 to 511.

Now the ACTUAL map will be superhuge.  I keep track of that in code.

As the offset shifts towards the edge of the viewport, I set the VERA address to point ahead a row (or column) and write that data to the map.  The target address is modded based on the dimensions of the map data in VERA.

Easy to say.  Trickier to conceptualize in code.

Johan Kårlin
Posts: 292
Joined: Wed Jun 03, 2020 11:33 am
Location: Kalmar, Sweden

Me starting out with scrolling tiles

Post by Johan Kårlin »


If you are lucky a map size of 128x256 or 256x128 is enough. VERA supports it and it will fit into VRAM (64 KB). If you want a larger map I think you have to do what I have done in Rally Speedway, start with tiles, then define blocks of tiles of a certain size and finally define your game world with a map of blocks. Then while scrolling you constantly calculate which actual tiles should populate the actual VERA map. By doing this I have implemented virtual maps (or what to call them) consisting of 256x256 tiles. Pretty cool but the code is complicated as well as the workflow for creating graphics.  

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Me starting out with scrolling tiles

Post by rje »


Thanks @Johan Kårlin, it's the larger-map case, where I have to populate just beyond of the viewport coordinates, populating rows or columns from the larger map in Banked RAM.

"Viewport coordinates" seems like the appropriate term for what VERA calls the horizontal and vertical scroll values.

 

 

ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

Me starting out with scrolling tiles

Post by ZeroByte »


I like to call it the "camera"

And one thing to point out in case you missed it - the scroll value itself auto-wraps, so if the map size is 512px wide, you can keep right on incrementing the scroll register. The view just wraps back around again anyway - it doesn't walk off into the void if you say scroll=513.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Me starting out with scrolling tiles

Post by rje »


Next two steps.

(1) Create a temporary map, or at least part of it, at MAP BASE ADDR ($10000).  A 32 x 32 map at 8bpp is 2K bytes, right?  So the map runs from $10000 to $10800.

(2) Make some tiles and load them to TILE BASE ADDR.  (I can probably set the base addr as $11000, right?)

 

 

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Me starting out with scrolling tiles

Post by rje »


So I'm getting the tile base and map base all mixed up.


100 REM -------------------------



101 REM LOAD TILES AND STUFF



102 REM -------------------------



110 VLOAD "LANDTILES.BIN", 8, 1, $1000 :REM LOAD TO $11XXX


I *THINK* this loads into $11000+ on VERA.  Yes?


200 REM ------------------------



201 REM SET UP VIDEO REGISTERS



202 REM ------------------------



210 POKE $9F2D, %00000000 :REM MAP HEIGHT=0, WIDTH=0 = 32X32 MAP



220 POKE $9F2E, %10000000 :REM MAP BASE ADDR = 128 X512 = $10000.



230 POKE $9F2F, %00100011 :REM TILE BASE ADDR = $11000.



240 REM ALSO, TILE H=1, W=1, SO 16 x 16 PIX


Here's where I think my errors are. I *THINK* this sets the Map Base at $10000, and the Tile Base at $11000.  HOWEVER, the tiles appear random to me, indicating that I either loaded it to the wrong place, or I set the Tile Base wrong.


400 COLOR 1,0 :CLS :REM 0=TRANSPARENT

 


500 REM -----------------------------------



501 REM LAYER 0 ENABLE



502 REM -----------------------------------



510 POKE $9F29, %00010001 :REM LAYER 0, OUTPUT MODE=1 (VGA)


That works.  At least I'm pretty sure it works.


600 REM ------------------------------------



601 REM WRITE A SIMPLE MAP TO $10000



602 REM ------------------------------------



611 POKE $9F20, 0 :REM VRAM 7:0



612 POKE $9F21, 0 :REM VRAM 15:8



612 POKE $9F22, %00010001 :REM INCR 1, VERA $10000



620 FOR X = 0 TO 1024 :REM 32 X 32



650 POKE $9F23, INT(RND(1)*8) :REM TILE INDEX 7:0



660 POKE $9F23, %00000000 :REM PAL,V,H,IDX 9:8



690 NEXT


OK the map entries are two bytes each.  The first byte is the low index of the tile.  Since I only have 8 tiles, that's all I need to set.

The second byte sets the palette offset, flips, and upper index to zero.

I have set the auto increment to 1.  So, that loop fills the map from $10000 to $10400.  Right?

Maybe I'm setting the target address wrong?  But it seems OK.


1000 REM -----------------------------------



1001 REM NOW SCROLL, ETERNALLY



1002 REM -----------------------------------



1040 POKE $9F30, 255 AND (PEEK($9F30)+1)



1050 FOR T = 1 TO 5000 : NEXT



1060 GOTO 1040


And we scroll.

So it scrolls, but.... but I'm either loading the tiles to the wrong address, or the map address is wrong, or the tile address is wrong.  Or something else is wrong.

test.gif.5a8ca173b730b46cec7edd25955060ce.gif

 

Ed Minchau
Posts: 497
Joined: Sat Jul 11, 2020 3:30 pm

Me starting out with scrolling tiles

Post by Ed Minchau »


To load into bank 1 of VERA, 

VLOAD"LANDTILES.BIN",8,3,$1000

should work better. 8,1,$1000 would load it into low RAM at address $1000.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Me starting out with scrolling tiles

Post by rje »


Thanks.  Anyway I started moving things around.

I've pre-generated a map that I can load directly into VERA, that only has tile indexes 0-8 (randomly), and the second byte is always zero since I'm not offsetting the palette, flipping, or etc.

Can I load these into bank 0?  Would that work?

This doesn't work:


100 REM -------------------------



101 REM TILES ARE 2048b



102 REM MAP IS 2048b



103 REM -------------------------



110 VLOAD "LANDTILES.BIN", 8, 0, $5000 :REM LOAD TILES TO $05000+



120 VLOAD "MAP.BIN", 8, 0, $4000 :REM LOAD MAP TO $04000+

 


200 REM ------------------------



201 REM SET UP VIDEO REGISTERS



202 REM ------------------------



210 POKE $9F2D, %00000000 :REM MAP HEIGHT=0, WIDTH=0 = 32X32 MAP



220 POKE $9F2E, %00100000 :REM MAP BASE = 32 X 512 = $04000.



230 POKE $9F2F, %00101011 :REM TILE BASE = 10 X 2048 = $05000.



240 REM ALSO, TILE H=1, W=1, SO 16 X 16 PIX


 

Figuring out these VERA fields in BASIC is a royal pain.

Post Reply