[A83] Tilemap
[Prev][Next][Index][Thread]
[A83] Tilemap
Here is an easy to read tilemap routine. This should show anyone the
fundamentals of a tilemap routine. It uses 8x8 tiles, in a 8x12 array that
takes up the full screen.
http://void.calc.org/archives/routines/mapdemo.h
paintTilemap:
ld de,plotsscreen ; area to be painted
ld hl,(mapStart) ; map data area
ld c,8 ; number of rows to display
rowLoop:
ld b,12 ; number of columns to display
columnLoop:
ld a,(hl) ; tile Identification
or a
jr z,skipBlankTile
push bc
; now we determine what sprite we need to use from this
push hl
dec a ; 0 = blank space
ld c,a
ld b,0
ld hl,0
add hl,bc ; hl = a*8
add hl,hl ; since each sprite is 8 bytes long
add hl,hl
add hl,hl
ld bc,mapSprites
add hl,bc ; add offset to sprites
; paint sprite with Aligned 8x8 sprite routine
; OPCODE "LDI"
; same as:
; ld a,(hl)
; ld (de),a
; inc hl
; inc de
; dec bc
push de
ld b,8
drawTile:
push bc
ldi
push hl ; we want to go to the next row of the
ld hl,11 ; graph buffer. must add 12 bytes!
add hl,de
ex de,hl
pop hl
pop bc
djnz drawTile
pop de
pop hl
pop bc
skipBlankTile:
inc de ; next tile = next byte on graph buffer
inc hl ; next byte = next tile ID
djnz columnLoop
; tricky arithmetic is involved when moving from the right edge
; and back to the left.
push hl ; 7 rows = 84 bytes
ld hl,84 ; 12*7
add hl,de
ex de,hl
pop hl
push de
ld de,columnSize-12 ; not 12, since we already incremented
add hl,de
pop de
dec c
jr nz,rowLoop ; do we need to loop again?
ret
-------------------------------------------------
Sent through Cyberbuzz- A Server for the Students
http://cyberbuzz.gatech.edu/
References: