From: Lukas Krickl Date: Sat, 20 Sep 2025 11:13:11 +0000 (+0200) Subject: mapobj: Added basic mapobject handling. X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=ce84875ae01ee3ebf8a06eb43b1c234f4fdaa286;p=gbrg%2F.git mapobj: Added basic mapobject handling. Map objects get loaded as new map rows are drawn. --- diff --git a/src/defs.s b/src/defs.s index 48ac0fe..ae493a7 100644 --- a/src/defs.s +++ b/src/defs.s @@ -89,6 +89,14 @@ .de pat_tilemap, 10 .de pat_size, 0 + ; map object types +.se 0 +.de MOT_SET_PAT, 1 +.de MOT_DISABLE_SCROLL, 1 +.de MOT_ENABLE_SCROLL, 1 +.de MOT_RECT, 1 +.de MOT_ACTOR_SPAWNER, 1 + ; map object struct .se 0 .de mo_type, 1 diff --git a/src/macros.inc b/src/macros.inc index f7a3427..f687d22 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -189,10 +189,10 @@ $1: ; $1: type ; $2: flags ; $3: row - ; $4: dat1 - ; $5: dat2 + ; $4: dat1/dat2 (word) #macro modef - .db $1, $2, $3, $4, $5 + .db $1, $2, $3 + dw $4 #endmacro ; adjusts an input position diff --git a/src/map.s b/src/map.s index 3e19a67..5c59384 100644 --- a/src/map.s +++ b/src/map.s @@ -35,6 +35,14 @@ map_load: ld a, SCRN0_END HI ld [map_scrn_ptr+1], a + ; load mo ptr + ld hl, map_objs_ptr + add hl, de + ld a, [hl+] + ld [map_curr_obj], a + ld a, [hl+] + ld [map_curr_obj+1], a + call lcd_on call vblank_wait @@ -176,15 +184,11 @@ map_advance_row: ld a, [map_curr_row] inc a ld [map_curr_row], a - call map_check_obj + + call mo_exec ret - ; checks the newly drawn row for objects - ; that can execute code -map_check_obj: - ; TODO - ret ; draws a full page of the currently selected map ; waits for blank between each row @@ -218,4 +222,8 @@ map_page_full_draw: ret l1_map: - mapdef 0, pat_empty, NULL, bank8000, bank8800, bank8C00, bank9000 + mapdef 0, pat_empty, l1_objs, bank8000, bank8800, bank8C00, bank9000 + +l1_objs: + modef MOT_SET_PAT, 0, 3, pat_center_grass + modef MOT_SET_PAT, 0, 5, pat_empty diff --git a/src/mapobj.s b/src/mapobj.s index f9803c4..fbd0c33 100644 --- a/src/mapobj.s +++ b/src/mapobj.s @@ -4,3 +4,106 @@ ; is checked ; if the row matches it is loaded into ram and executed ; when an object is off-screen it is unloded + +mo_routines: + dw mo_set_pat + dw mo_disable_scroll + dw mo_enable_scroll + dw mo_rect + dw mo_actor_spawner + + ; executes all map objects in the map object list + ; until the mo's row != current row + ; advances mo ptr +mo_exec: + ld a, [map_curr_obj] + ld e, a + ld a, [map_curr_obj+1] + ld d, a + + ld a, [map_curr_row] + ld b, a ; b = current row +@loop: + ; execute map object by type + ld hl, mo_row + add hl, de + ld a, [hl] + ; if rows do not match exit + cp a, b + jr nz, @done REL + + ; otherwise call object routine + push_all + ld a, [de] ; type + add a, a ; * 2 for offset + ld hl, mo_routines + ld b, 0 + ld c, a + add hl, bc + + ; hl = rotuine ptr + ld a, [hl+] + ld b, a + ld a, [hl+] + ld h, a + ld l, b + + ; call routine + call_hl + + + pop_all + ; go to next object + ld hl, mo_size + add hl, de + push hl + pop de ; de = next obj + jr @loop REL + +@done: + + ; write back next ptr + ld a, e + ld [map_curr_obj], a + ld a, d + ld [map_curr_obj+1], a + + ret + + ; sets the next draw pattern + ; inputs: + ; de: map object ptr +mo_set_pat: + ; new pattern is in dat1 and dat2 + ld hl, mo_dat + add hl, de + + ld a, [hl+] + ld [map_curr_pat], a + ld a, [hl] + ld [map_curr_pat+1], a + ret + + ; disables map scrolling + ; inputs: + ; de: map object ptr +mo_disable_scroll: + ret + + ; enables map scrolling + ; inputs: + ; de: map object ptr +mo_enable_scroll: + ret + + ; spawns a collision rectangle + ; inputs: + ; de: map object ptr +mo_rect: + ret + + ; spawns an actor spawner + ; inputs: + ; de: map object ptr +mo_actor_spawner: + ret diff --git a/src/rowpatterns.s b/src/rowpatterns.s index 3ca43c6..36bc135 100644 --- a/src/rowpatterns.s +++ b/src/rowpatterns.s @@ -1,9 +1,14 @@ ; tile space .def int TS = 0x40 +.def int GS = 0x62 pat_empty: .db TS, TS, TS, TS, TS, TS, TS, TS, TS, TS + +pat_center_grass: +.db TS, TS, TS, GS, GS, GS, TS, TS, TS, TS + ; enf of level row pattern pat_eol: diff --git a/src/wram.s b/src/wram.s index 94c8728..c26d6dd 100644 --- a/src/wram.s +++ b/src/wram.s @@ -69,7 +69,7 @@ map_curr_pat: .adv 2 map: .adv 2 ; ptr to the next map object ; that may be loaded -map_obj_ptr: .adv 2 +map_curr_obj: .adv 2 ; current bg pointer to write to map_scrn_ptr: .adv 2