; draws a tile
; to the screen
; inputs:
- ; b/c: y/x position
+ ; update_tile_to_draw/vram: filled with valid ptr and tile data
map_draw_tile:
- ; find tile to draw
- push bc
- call map_get_tile
- ld bc, t_tile
- add hl, bc ; hl = tile gfx
- pop bc
-
- ; load tile into a
- ld a, [hl] ; a = tile
- push af ; save tile gfx
+ ; load vram destination
+ ld a, [update_tile_vram]
+ ld h, a
+ ld a, [update_tile_vram+1]
+ ld l, a
- ld hl, SCRN0
- ld de, MAP_W * 4 ; * 4 because tiles are 8x8
+ ld de, update_tile_to_draw
- ; skip y loop if b is 0
- ld a, b
- cp a, 0
- jr z, @skip_y REL
-
-@y_loop:
- add hl, de
- dec b
- jr nz, @y_loop REL
-@skip_y:
-
- ld d, 0
- ld a, c
- add a, a ; * 2 because tiles are 8x8
- ld e, a
- add hl, de ; hl = SCRN location
-
- pop af
-
- ; draw 2x2 tile
+ ; draw 4 tiles
+ ld a, [de]
+ inc de
ld [hl+], a
- inc a
+
+ ld a, [de]
+ inc de
ld [hl], a
+ ; next row
; next row
- ld de, (MAP_W * 2) - 1
- add hl, de
-
- ; move down one tile row as well
- add a, 15
+ ld bc, (MAP_W * 2) - 1
+ add hl, bc
+ ld a, [de]
+ inc de
ld [hl+], a
- inc a
- ld [hl], a
+ ld a, [de]
+ inc de
+ ld [hl], a
ret
; gets a tile based on a position
; to tile_to_draw[0] to [3]
; inputs:
; b/c: y/x position
+ ; returns:
+ ; update_tile_to_draw: 4 bytes of new tile data
+ ; upte_tile_vram: ptr to vram
map_draw_tile_prep:
+ ; find tile to draw
+ push bc
call map_get_tile
- ; hl = tile
+ ld bc, t_tile
+ add hl, bc ; hl = tile gfx
+ pop bc
- ld de, update_tile_to_draw
+ ; load tile into a
+ ld a, [hl] ; a = tile
+ push af ; save tile gfx
+
+ ld hl, SCRN0
+ ld de, MAP_W * 4 ; * 4 because tiles are 8x8
+
+ ; skip y loop if b is 0
+ ld a, b
+ cp a, 0
+ jr z, @skip_y REL
+
+@y_loop:
+ add hl, de
+ dec b
+ jr nz, @y_loop REL
+@skip_y:
+
+ ld d, 0
+ ld a, c
+ add a, a ; * 2 because tiles are 8x8
+ ld e, a
+ add hl, de ; hl = SCRN location
+
+ ; save hl to vram ptr
+
+ ld a, h
+ ld [update_tile_vram], a
+ ld a, l
+ ld [update_tile_vram+1], a
+
+ ; hl = tile data buffer
+ ld hl, update_tile_to_draw
+
+ ; a = start tile
+ pop af
+
+ ; draw 2x2 tile
+ ld [hl+], a
+ inc a
+ ld [hl+], a
+
+
+ ; move down one tile row as well
+ add a, 15
+
+ ld [hl+], a
+ inc a
+ ld [hl], a
- ; TODO:
ret
#macro map_draw_row_inc_c