From 6f7c710d0582b00f8b02cc5ead4c02dff960b89d Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 31 Jul 2025 19:00:56 +0200 Subject: [PATCH] unit rendering: units are now hidden if they are inside a room This is done by simply swapping the bg tilemap to a tile when the player is not indoors. The BG priority bit is also set for all unit objects. --- src/hw.inc | 2 +- src/player.s | 2 +- src/roompatterns.s | 2 +- src/unit_demo.s | 10 ++++---- src/video.s | 48 ++++++++++++++++++++++++++-------- tiles/bank8000.inc | 64 +++++++++++++++++++++++----------------------- 6 files changed, 78 insertions(+), 50 deletions(-) diff --git a/src/hw.inc b/src/hw.inc index e781a94..0f0294e 100644 --- a/src/hw.inc +++ b/src/hw.inc @@ -89,7 +89,7 @@ .def int OBJSIZE = 4 .def int OAMRAM_SIZE = OBJSMAX * OBJSIZE -#define OAM_FPRIO 0b10000000 +.def int OAM_FPRIO = 0b10000000 #define OAM_FYFLIP 0b01000000 #define OAM_FXFLIP 0b00100000 #define OAM_DMG_PAL 0b00010000 diff --git a/src/player.s b/src/player.s index 5a8e8c9..d843ba0 100644 --- a/src/player.s +++ b/src/player.s @@ -214,7 +214,7 @@ unit_player: act_stat_def1 1, 1, 1, 1 act_stat_def2 1, 1, 90, 1 act_st_def NULL, NULL, st_unit_player_update, st_unit_idle - act_def_meta unit_draw, 0x8C, 0, NULL + act_def_meta unit_draw, 0x8C, OAM_FPRIO, NULL st_unit_player_update: st_def 0x00, unit_player_update, st_unit_player_update diff --git a/src/roompatterns.s b/src/roompatterns.s index 76e7459..dc43f01 100644 --- a/src/roompatterns.s +++ b/src/roompatterns.s @@ -111,7 +111,7 @@ room_pattern_tile_translation: ; doors .db 0x2E, 0x0E, 0x0C, 0x2C ; roof - .db 0x4A + .db 0x48 ; translation table for flags room_pattern_flags_translation: diff --git a/src/unit_demo.s b/src/unit_demo.s index f041689..1a9e313 100644 --- a/src/unit_demo.s +++ b/src/unit_demo.s @@ -41,11 +41,11 @@ unit_demo_1_cpu_update_idle: unit_demo_2: st_def 0x00, unit_demo_1_init, st_unit_idle - act_def ACT_T_DEMO_1, 0, 8, 8, 0 + act_def ACT_T_DEMO_1, 0, 3, 3, 0 act_stat_def1 1, 1, 1, 1 act_stat_def2 1, 1, 32, 1 act_st_def NULL, NULL, st_unit_demo_1_cpu_update_idle, st_unit_idle - act_def_meta unit_draw, 0x88, 0, NULL + act_def_meta unit_draw, 0x88, OAM_FPRIO, NULL unit_demo_warrior: st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update @@ -53,7 +53,7 @@ unit_demo_warrior: act_stat_def1 1, 1, 1, 1 act_stat_def2 1, 1, 32, 1 act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle - act_def_meta unit_draw, 0x88, 0, NULL + act_def_meta unit_draw, 0x88, OAM_FPRIO, NULL unit_demo_mage: st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update @@ -61,7 +61,7 @@ unit_demo_mage: act_stat_def1 1, 1, 1, 1 act_stat_def2 1, 1, 32, 1 act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle - act_def_meta unit_draw, 0x8C, 0, NULL + act_def_meta unit_draw, 0x8C, OAM_FPRIO, NULL unit_demo_thief: st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update @@ -69,7 +69,7 @@ unit_demo_thief: act_stat_def1 1, 1, 1, 1 act_stat_def2 1, 1, 32, 1 act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle - act_def_meta unit_draw, 0x90, 0, NULL + act_def_meta unit_draw, 0x90, OAM_FPRIO, NULL unit_demo_priest: diff --git a/src/video.s b/src/video.s index 1b7e60f..ddba5e5 100644 --- a/src/video.s +++ b/src/video.s @@ -22,16 +22,7 @@ vblank: ; get inputs call poll_inputs - - ; cycle bg tiles for animations - ld a, [frame_count] - and a, BG_CYCLE_FRAMES - jr nz, @skip_cycle REL - - ld a, [RLCD] - xor a, LCDCF_TILE_BANK - ld [RLCD], a -@skip_cycle: + call video_swap_tile_bank_player_indoors ld a, 1 ld [frame_ready], a @@ -50,6 +41,43 @@ scroll_write: ret + ; swaps tilebank if the player is currently + ; inside a room + ; sets LCDC_TILE_BANK if player is inside + ; unsets it otherwise +video_swap_tile_bank_player_indoors: + ld a, [player_rt_special_flags] + and a, CF_COVERED + jr nz, @not_covered REL + + ld a, [RLCD] + ; set bit + or a, LCDCF_TILE_BANK + ld [RLCD], a + + ret +@not_covered: + ld a, [RLCD] + ; unset bit + and a, (~LCDCF_TILE_BANK) & 0xFF + ld [RLCD], a + + ret + + ; swaps the current tilebank by setting/unsetting + ; LCDC_TILE_BANK +video_swap_tile_bank: + ; cycle bg tiles for animations + ld a, [frame_count] + and a, BG_CYCLE_FRAMES + jr nz, @skip_cycle REL + + ld a, [RLCD] + xor a, LCDCF_TILE_BANK + ld [RLCD], a +@skip_cycle: + ret + ; wait for next vblank vblank_wait: ; disable interrupts diff --git a/tiles/bank8000.inc b/tiles/bank8000.inc index cc016f4..e75f707 100644 --- a/tiles/bank8000.inc +++ b/tiles/bank8000.inc @@ -647,23 +647,23 @@ .chr 11111111 .chr 11111111 ; tile 72 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 73 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 74 .chr 33333333 .chr 32222222 @@ -791,23 +791,23 @@ .chr 11111111 .chr 11111111 ; tile 88 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 89 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 90 .chr 32222222 .chr 32222222 -- 2.30.2