; This is a very simple moderately fast map drawing routine. It requires 10 bytes ;of RAM, 6 of which are for internal counters, the other two are the pointer to ;the map and the ofset into the map. It also requires that 6 constants be defined ;within the program somewhere. The PutSprite routine must also preserve ix. ;DrawMap also requires a list of pointers to the sprites available for maps.
;This routine is a highly modified version of Jim Reardon's DrawMap. Like his ;routine this was designed to be easily modified.
; Steve Teater
;Constants:
; ColStart - (byte) the column at which drawing starts, relative to the width of
; the sprite
; RowStart - (byte) the row at which drawing starts, relative to sprite height
; MapTotal - (word) the total number of sprites to draw
; NextYAt - (byte) number of sprites per row
; SHeight - (byte) height of sprite, whatever unit the sprite routine uses
; SWidth - (byte) width of sprite, whatever unit the sprite routine uses
;Variable:
; MapPointer - (word) pointer to map to draw
; MapOffsetX - (byte) offset into map in the x direction
; MapOffsetY - (byte) offset into map in the y direction
;These are the temporary variables:
; MapCurrent - (word) used to keep track of how many sprites are left
; MapWidth - (word) holds the width of the map
; MapCoords - (word) where to draw the next sprite
;MapFormat:
; .db width
; .db spriteNumbers
DrawMap:
ld b,ColStart * SWidth
ld c,RowStart * SHeight
ld (MapCoords),bc ; store the starting draw coords
ld ix,(MapPointer) ; ix -> current map
ld a,(ix) ; get map width
inc ix ; get past width byte
ld (MapWidth),a ; store map width
ld b,a
ld a,(MapOffsetY) ; get y coordinate of offset
ld e,a ; this is the same as call MUL_HL
ld h,0 ; but it eliminates the call, jp, ret, and is
ld d,h ; 2 bytes shorter than rom (10.0) version
ld l,h
DrawMapMultLoop:
add hl,de
djnz DrawMapMultLoop ; hl = mapwidth * offset.y
ld a,(MapOffsetX) ; get x coordinate of offset
ld e,a
ld d,0
add hl,de ; hl = mapwidth * offset.y + offset.x
ex de,hl
add ix,de ; ix -> start of visible map
ld hl,MapTotal
DrawMapLoop:
ld (MapCurrent),hl ; save away number of sprites left
ld a,(ix + 00) ; get sprite num from map
inc ix ; increment map pointer
ld hl,&SpriteTable
ld e,a
ld d,0
add hl,de ; done twice, because pointers are
add hl,de ; 2 bytes
ld a,(hl) ; same as call LD_HL_MHL, but faster
inc hl ; (no call and ret)
ld h,(hl)
ld l,a
ld de,(PROGRAM_ADDR)
add hl,de ; relocation doesn't work here
ld bc,(MapCoords)
; push ix ; if your PutSprite does not save ix
call &PutSprite ; the sprite is drawn
; pop ix ; if your PutSprite does not save ix
ld a,(MapCoords + 1) ; get x draw coordinate
add a,SWidth ; make equal to next location
cp NextYAt * SWidth ; time for a new row?
jr c,DrawMapNoUpdate ;
DrawMapUpdate: ; updates coords for a new row
ld a,(MapCoords) ; get y draw coord
add a,SHeight ; next row down
ld (MapCoords),a ; save y draw coord
ld a,ColStart ; return with beginning value of x coord