map: Added map routine and map object that can set map routines
authorLukas Krickl <lukas@krickl.dev>
Sun, 5 Oct 2025 04:08:33 +0000 (06:08 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 5 Oct 2025 04:08:33 +0000 (06:08 +0200)
src/defs.s
src/map.s
src/mapobj.s
src/update.s
src/wram.s

index 28965baba33027a9ce7b208563aec6a1756d608b..ad55b8560e19c750b28f1db9975ae942ab748322 100644 (file)
@@ -14,7 +14,7 @@
 #define NULL 0
 
 #define ACTS_PLAYER_PROJECTILES 6
-#define ACTS_ENEMY 6
+#define ACTS_ENEMY 4
 #define ACTS_ENEMY_PROJECTILES 6
 #define ACTS_MAX (ACTS_PLAYER_PROJECTILES + ACTS_ENEMY + ACTS_ENEMY_PROJECTILES) 
 
 .de MOT_ENABLE_SCROLL, 1
 .de MOT_RECT, 1
 .de MOT_ACTOR_SPAWNER, 1
+.de MOT_SET_MAP_ROUTINE, 1
 
        ; map object struct
 .se 0
index 0c5f2568835d19d62ea1e1543fafa40ab9ada587..8a8a2fbe1715bda9dcd1d2c9f4c2f4b5536c6c3b 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -8,6 +8,12 @@
        ; inputs:
        ;               de: map ptr
 map_load:
+       ; clear map routine
+       ld a, map_r_nop LO
+       ld [map_routine], a
+       ld a, map_r_nop HI
+       ld [map_routine+1], a
+
        call disableinterrupts
        call next_vblank_wait
        call lcd_off
@@ -236,6 +242,16 @@ map_page_full_draw:
        call next_vblank_wait
        call map_advance_row
        ret
+       
+       ; nop map rotuine
+map_r_nop:
+       ret
+
+       ; checks if all enemies are defeated
+       ; and re-enables scroll
+map_r_enable_scroll_all_enemies_defeated:
+       ; TODO
+       ret
 
 l1_map:
        mapdef 0, pat_empty, l1_objs, bank8000, bank8800, bank8C00, bank9000    
@@ -261,4 +277,7 @@ l1_objs:
 
        modef MOT_SET_PAT, 0, 0x1E, pat_empty 
        modef MOT_DISABLE_SCROLL, 0, 0x20, 0
+       modef MOT_SET_MAP_ROUTINE, 0, 0x20, map_r_enable_scroll_all_enemies_defeated
        modef MOT_NOP, 0, 0xFF, 0
+
+
index 8c0bd40c83ba47888c05204b2b4ef80095cfbc5d..99fa9a8743db935c63eb698592554f13f51bf0af 100644 (file)
@@ -12,6 +12,7 @@ mo_routines:
         dw mo_enable_scroll
         dw mo_rect
         dw mo_actor_spawner
+        dw mo_set_map_routine
        
 mo_nop:
        ret
@@ -215,3 +216,16 @@ mo_actor_spawner:
        call actor_init
 
        ret
+       
+       ; sets the current map routine
+       ; dat1/2: map routine ptw
+       ; inputs:
+       ;               de: map object ptr 
+mo_set_map_routine:
+       ld hl, mo_dat
+       add hl, de
+       ld a, [hl+]
+       ld [map_routine], a
+       ld a, [hl+]
+       ld [map_routine+1], a
+       ret
index d44be69f6cec34f3ae32bd917fc71ed48c2b9b38..4248076ab45216899df7c4c069ca65197378a204 100644 (file)
@@ -11,11 +11,17 @@ update_game:
        call player_update
 
        call actor_update_all
-
        
   ; clear oam
   call shadow_oam_clear_rest
 
+       ; update map
+       ld a, [map_routine]
+       ld l, a
+       ld a, [map_routine+1]
+       ld h, a
+       call_hl
+
   ret
 
 new_game:
index aa53b347a5ee8954e9f37edc69a15f3c120b4654..62dd7769a94ccf22c3542e452335dfcfe11c8f11 100644 (file)
@@ -109,6 +109,11 @@ map_curr_obj: .adv 2
        
        ; current bg pointer to write to
 map_scrn_ptr: .adv 2
+
+       ; map update routine
+       ; can be set by map object
+map_routine: .adv 2
+
        
        ; current debug function
 dbg_fn: .adv 1