From db3ec335b834116f1ea543dde348073f766cc7d8 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 26 Nov 2025 05:45:29 +0100 Subject: [PATCH] map: maps are now 10x8 tiles This will allow enough room for smooth scrolling to take palce when loading a new map. --- src/defs.s | 15 +++++++++--- src/levels.s | 26 +++++++------------- src/macros.inc | 14 +++++++---- src/map.s | 65 ++++++-------------------------------------------- src/wram.s | 13 ---------- 5 files changed, 38 insertions(+), 95 deletions(-) diff --git a/src/defs.s b/src/defs.s index 83e876f..6234d09 100644 --- a/src/defs.s +++ b/src/defs.s @@ -27,8 +27,8 @@ #define UI_TILE_HEIGHT 4 ; player position offset to get center of tile -#define MAP_W 16 -#define MAP_H 16 +#define MAP_W 10 +#define MAP_H 8 #define MAP_TILES (MAP_W * MAP_H) ; actor type enum @@ -68,13 +68,22 @@ .de act_cb_state, 1 .de act_cb_size, 0 - + + ; map flags +.se 1 +.de MAP_F_HOSTILE, 1 ; map header struct .se 0 .de map_flags, 1 ; ptr to map routine .de map_routine, 2 + ; ptr to actor table for this map +.de map_acts, 2 + ; ptr to encounter table +.de map_encounters, 2 + ; ptr to exit table +.de map_exits, 2 ; pointers to tile banks to be loaded ; maps to map property tile_bank0, tile_bank1, tile_bank2, tile_bank3 ; note that tile_bank1 and tile_bank2 are 128 bytes each diff --git a/src/levels.s b/src/levels.s index 3f0f1ca..3831820 100644 --- a/src/levels.s +++ b/src/levels.s @@ -13,20 +13,12 @@ ; where each tile has values and its current state. The map can be drawn from this. l1: - mapdef 0, map_r_nop, bank8000, bank8800, bank8C00, bank9000 - .db TWL, 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 - .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 - .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 - .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 - .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, TWL + mapdef 0, map_r_nop, 0, 0, 0, bank8000, bank8800, bank8C00, bank9000 + .db TWL, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TWL + .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TWL diff --git a/src/macros.inc b/src/macros.inc index 47483fd..8c8ffa2 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -154,10 +154,13 @@ $1: ; inputs: ; $1: flags ; $2: map routine - ; $3: tile bank 0 - ; $4: tile bank 1 - ; $5: tile bank 2 - ; $6: tile bank 3 + ; $3: actors + ; $4: encounters + ; $5: exits + ; $6: tile bank 0 + ; $7: tile bank 1 + ; $8: tile bank 2 + ; $9: tile bank 3 #macro mapdef .db $1 dw $2 @@ -165,6 +168,9 @@ $1: dw $4 dw $5 dw $6 + dw $7 + dw $8 + dw $9 #endmacro ; define a tile diff --git a/src/map.s b/src/map.s index 2f3d4bc..a457a80 100644 --- a/src/map.s +++ b/src/map.s @@ -23,6 +23,11 @@ map_load: push de call map_tiles_load pop de + + ; TODO: + ; load actors + ; encounter table + ; exit table call map_full_draw @@ -156,7 +161,7 @@ map_draw_tile: ; next row ; next row - ld bc, (MAP_W * 2) - 1 + ld bc, ((MAP_W * 2) + 12) - 1 add hl, bc ld a, [de] @@ -201,36 +206,6 @@ map_get_tile: ; hl = tile now ret - ; modifies the status gfx of a tile - ; based on flags - ; inputs: - ; update_tile_ptr: ptr to tile - ; a: current gfx - ; returns: - ; a: gfx to display -map_draw_tile_modify_status: - push af - ld a, [update_tile_ptr] - ld h, a - ld a, [update_tile_ptr+1] - ld l, a - ; a = original gfx - pop af - - inc hl ; hl = flags - bit 0, [hl] ; test bit 0 (TF_INC) - jr nz, @inc REL - - bit 1, [hl] ; test bit 1 (TF_DEC) - jr nz, @dec REL - ret -@inc: - ld a, UI_TILE_PLUS - ret -@dec: - ld a, UI_TILE_MINUS - ret - ; prepares tile draw ; by writing the expected tiles ; to tile_to_draw[0] to [3] @@ -257,7 +232,7 @@ map_draw_tile_prep: push af ; save tile gfx ld hl, SCRN0 - ld de, MAP_W * 4 ; * 4 because tiles are 8x8 + ld de, ((MAP_W * 2) + 12) * 2 ; * 4 because tiles are 8x8 ; skip y loop if b is 0 ld a, b @@ -292,17 +267,7 @@ map_draw_tile_prep: ; draw 2x2 tile ld [hl+], a inc a - - push af - ; top left corner of tile - ; may display status effects - ; based on flags - push hl - call map_draw_tile_modify_status - pop hl - ld [hl+], a - pop af ; move down one tile row as well @@ -339,15 +304,9 @@ map_draw_row: 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 @@ -370,16 +329,6 @@ map_full_draw: 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 diff --git a/src/wram.s b/src/wram.s index 4a57ad6..4dcc26c 100644 --- a/src/wram.s +++ b/src/wram.s @@ -91,19 +91,6 @@ tiles_end: .adv 0 - ; the following valuess are set by ui_update - ; coordinates of current tile -current_tile_y: .adv 1 -current_tile_x: .adv 1 - ; ptr to current tile - ; selected by the player cursor -current_tile: .adv 2 - - ; the following values are set by tile_next_update -update_tile_y: .adv 1 -update_tile_x: .adv 1 -update_tile: .adv 2 - ; space for 4 tile ids ; that represent the current tile ; this gets drawn during the next blank -- 2.30.2