l1:
mapdef 0, map_r_nop, bank8000, bank8800, bank8C00, bank9000
.db TPH, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
- .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
- .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
+ .db TPH, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
+ .db TPH, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
.db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
.db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
.db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
; draws a tile
; to the screen
; inputs:
- ; hl: tile
; b/c: y/x position
map_draw_tile:
; find tile to draw
- ld de, t_tile
- add hl, de
+ 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
ld hl, SCRN0
- ld de, MAP_W
+ ld de, MAP_W * 4 ; * 4 because tiles are 8x8
; skip y loop if b is 0
ld a, b
@skip_y:
ld d, 0
- ld e, c
+ 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
+ ld [hl+], a
+ inc a
+ ld [hl], a
+
+ ; next row
+ ld de, (MAP_W * 2) - 1
+ add hl, de
+
+ ; move down one tile row as well
+ add a, 15
+
+ ld [hl+], a
+ inc a
ld [hl], a
ret
+ ; gets a tile based on a position
+ ; inputs:
+ ; b/c: y/x
+ ; returns:
+ ; hl: tile
+map_get_tile:
+ ld hl, tiles
+
+ ld de, MAP_W * t_size
+ ld a, b
+ cp a, 0
+ jr z, @skip_y_loop REL
+
+@y_loop:
+ add hl, de ; next row
+ dec b
+ jr z, @y_loop REL
+@skip_y_loop:
+
+ ld de, t_size
+ ld a, c
+ cp a, 0
+ jr z, @skip_x_loop REL
+
+@x_loop:
+ add hl, de ; next tile over
+ dec c
+ jr z, @x_loop REL
+@skip_x_loop:
+
+ ; hl = tile now
+ ret
+
+#macro map_draw_row_inc_c
+ push bc
+ call map_draw_tile
+ pop bc
+ inc c
+#endmacro
+
; draws 16 tiles
; inputs:
- ; hl: start tile
; b: y position
map_draw_row:
+ ld c, 0
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
+ map_draw_row_inc_c
ret
-
+
+#macro map_full_draw_inc_b
+ call map_draw_row
+ inc b
+#endmacro
+
; draws a full page of the currently selected map
; inputs:
; [map]
map_full_draw:
- ld bc, MAP_TILES
- ld hl, tiles
-
- push hl
- ld bc, 0
- call map_draw_tile
- pop hl
+ ld b, 0
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+ map_full_draw_inc_b
+
ret
; nop map rotuine