; =================================
Draw_Map_Tile:
; Takes:
; e - map location to draw (YYYYXXXX)
; d - # of tile to draw
; window_min_x & window_min_y
ld a, e
and %00001111 ; c will be our x coord
; be efficient and leave it in a for now
srl e ; e will be our y coord
srl e
srl e
srl e
; now we need to account for the window
ld hl, (window_min_x)
sub (hl)
; while we are at it, do a bounds check
; do it here because it needs the coord in a
cp 12
ret nc ; bye bye
ld c, a ; now x is in c
ld a, e
ld hl, (window_min_y)
sub (hl)
; see above
cp 8
ret nc ; bye bye again!
ld e, a ; now Y is in e, will see why...
; Y will actually be in de
ld a, d ; save tile number
; ---- begin multiply by 96 ----
ld d, 0
ld b, 5
_Draw_Map_Tile_x32:
add hl, hl
djnz _Draw_Map_Tile_x32
ld h, d
ld l, e
add hl, hl
add hl, de
; ---- end multiply by 96 -----
; HL will contain the address of our screen location shortly
; add our X to our new Y
ld b, 0
add hl, bc
; We no longer need our map location, so b & c are free
ld bc, PlotSScreen
add hl, bc
; We are done with the screen address now!
; Just get the tile address...
; Tile number is in a
; Add a with unit_tiles
ld d, 0
ld e, a
ld bc, unit_tiles
ex de, hl
add hl, bc
ex de, hl
; Fun Fun Fun!!!
call Copy_Tile
ret
; =================================
Copy_Tile:
; takes screen address in hl, tile address in de
LD c, 12
LD b, 8
; ---------------------------------
Copy_Tile_Loop:
PUSH bc
LD a, (de)
INC de
LD (hl),a
LD b, 0
ADD hl, bc
POP bc
DJNZ Copy_Tile_Loop
RET
; =================================