From e06e485c0ac901c2a3eca3ec5e34324d2eaa27d9 Mon Sep 17 00:00:00 2001 From: ElectroDeoxys Date: Fri, 12 May 2023 00:35:30 +0100 Subject: [PATCH] Split bank 7 --- src/engine/debug_sprites.asm | 67 +++++ src/engine/masters_beaten_list.asm | 55 ++++ .../overworld/debug_player_coordinates.asm | 50 ++++ src/engine/overworld/load_map_header.asm | 43 +++ .../{bank07.asm => overworld/npc_core.asm} | 269 ------------------ .../overworld/{npcs.asm => npc_data.asm} | 0 src/engine/overworld/warp.asm | 49 ++++ src/main.asm | 9 +- 8 files changed, 271 insertions(+), 271 deletions(-) create mode 100644 src/engine/debug_sprites.asm create mode 100644 src/engine/masters_beaten_list.asm create mode 100644 src/engine/overworld/debug_player_coordinates.asm create mode 100644 src/engine/overworld/load_map_header.asm rename src/engine/{bank07.asm => overworld/npc_core.asm} (74%) rename src/engine/overworld/{npcs.asm => npc_data.asm} (100%) create mode 100644 src/engine/overworld/warp.asm diff --git a/src/engine/debug_sprites.asm b/src/engine/debug_sprites.asm new file mode 100644 index 0000000..b6f0343 --- /dev/null +++ b/src/engine/debug_sprites.asm @@ -0,0 +1,67 @@ +Func_1c865: + ret + +; debug function +; adjusts hSCX and hSCY by using the arrow keys +; pressing B makes it scroll faster +Func_1c866: ; unreferenced + ldh a, [hKeysHeld] + and B_BUTTON + call nz, .asm_1c86d ; executes following part twice +.asm_1c86d + ldh a, [hSCX] + ld b, a + ldh a, [hSCY] + ld c, a + ldh a, [hKeysHeld] + bit D_UP_F, a + jr z, .check_d_down + inc c +.check_d_down + bit D_DOWN_F, a + jr z, .check_d_left + dec c +.check_d_left + bit D_LEFT_F, a + jr z, .check_d_right + inc b +.check_d_right + bit D_RIGHT_F, a + jr z, .asm_1c889 + dec b +.asm_1c889 + ld a, b + ldh [hSCX], a + ld a, c + ldh [hSCY], a + ret + +; sets some flags on a given sprite +Func_1c890: ; unreferenced + ld a, [wVBlankCounter] + and %111111 + ret nz + + ld a, [wd41b] + cp $11 + jr z, .asm_1c8a3 + cp $0e + ret c + cp $10 + ret nc + +; wd41b == $11 || (wd41b >= $0e && wd41b < $10) +.asm_1c8a3 + ld a, [wd41c] + ld [wWhichSprite], a + ld c, SPRITE_ANIM_FLAGS + call GetSpriteAnimBufferProperty + call UpdateRNGSources + and (1 << SPRITE_ANIM_FLAG_X_SUBTRACT) + jr nz, .asm_1c8b9 + res SPRITE_ANIM_FLAG_SPEED, [hl] + jr .asm_1c8bb +.asm_1c8b9 + set SPRITE_ANIM_FLAG_SPEED, [hl] +.asm_1c8bb + ret diff --git a/src/engine/masters_beaten_list.asm b/src/engine/masters_beaten_list.asm new file mode 100644 index 0000000..ecd14be --- /dev/null +++ b/src/engine/masters_beaten_list.asm @@ -0,0 +1,55 @@ +ClearMasterBeatenList: + push hl + push bc + ld c, $a + ld hl, wMastersBeatenList + xor a +.loop + ld [hli], a + dec c + jr nz, .loop + pop bc + pop hl + ret + +; writes Master in register a to +; first empty slot in wMastersBeatenList +AddMasterBeatenToList: + push hl + push bc + ld b, a + ld c, $a + ld hl, wMastersBeatenList +.loop + ld a, [hl] + or a + jr z, .found_empty_slot + cp b + jr z, .exit + inc hl + dec c + jr nz, .loop + debug_nop + jr .exit + +.found_empty_slot + ld a, b + ld [hl], a + +.exit + pop bc + pop hl + ret + +; iterates all masters and attempts to +; add each of them to wMastersBeatenList +AddAllMastersToMastersBeatenList: + ld a, $01 +.loop + push af + call AddMasterBeatenToList + pop af + inc a + cp $0b + jr c, .loop + ret diff --git a/src/engine/overworld/debug_player_coordinates.asm b/src/engine/overworld/debug_player_coordinates.asm new file mode 100644 index 0000000..2d58f11 --- /dev/null +++ b/src/engine/overworld/debug_player_coordinates.asm @@ -0,0 +1,50 @@ +JumpSetWindowOff: + jp SetWindowOff + +; debug function +; prints player's coordinates by pressing B +; and draws palettes by pressing A +Func_1c003: ; unreferenced + ld a, [wCurMap] + or a + jr z, JumpSetWindowOff + ld a, [wOverworldMode] + cp OWMODE_START_SCRIPT + jr nc, JumpSetWindowOff + + ldh a, [hKeysHeld] + ld b, a + and A_BUTTON | B_BUTTON + cp b + jr nz, JumpSetWindowOff + and B_BUTTON + jr z, JumpSetWindowOff + + ld bc, $20 + ld a, [wPlayerXCoord] + bank1call WriteTwoByteNumberInTxSymbolFormat + ld bc, $320 + ld a, [wPlayerYCoord] + bank1call WriteTwoByteNumberInTxSymbolFormat + ld a, $77 + ldh [hWX], a + ld a, $88 + ldh [hWY], a + + ldh a, [hKeysPressed] + and A_BUTTON + jr z, .skip_load_scene + ld a, SCENE_COLOR_PALETTE + lb bc, 0, 33 + call LoadScene +.skip_load_scene + ldh a, [hKeysHeld] + and A_BUTTON + jr z, .set_wd_on + ld a, $67 + ldh [hWX], a + ld a, $68 + ldh [hWY], a +.set_wd_on + call SetWindowOn + ret diff --git a/src/engine/overworld/load_map_header.asm b/src/engine/overworld/load_map_header.asm new file mode 100644 index 0000000..06099e8 --- /dev/null +++ b/src/engine/overworld/load_map_header.asm @@ -0,0 +1,43 @@ +; loads data from the map header of wCurMap +LoadMapHeader: + push hl + push bc + push de + ld a, [wCurMap] + add a + ld c, a + add a + add c + ld c, a + ld b, 0 + ld hl, MapHeaders + add hl, bc + ld a, [hli] + ld [wCurTilemap], a + ld a, [hli] + ld c, a ; CGB tilemap variant + ld a, [hli] + ld [wCurMapInitialPalette], a ; always 0? + ld a, [hli] + ld [wCurMapSGBPals], a + ld a, [hli] + ld [wCurMapPalette], a + ld a, [hli] + ld [wDefaultSong], a + + ld a, [wConsole] + cp CONSOLE_CGB + jr nz, .got_tilemap + ; use CGB variant, if valid + ld a, c + or a + jr z, .got_tilemap + ld [wCurTilemap], a +.got_tilemap + + pop de + pop bc + pop hl + ret + +INCLUDE "data/map_headers.asm" diff --git a/src/engine/bank07.asm b/src/engine/overworld/npc_core.asm similarity index 74% rename from src/engine/bank07.asm rename to src/engine/overworld/npc_core.asm index a3184b5..428f05a 100644 --- a/src/engine/bank07.asm +++ b/src/engine/overworld/npc_core.asm @@ -1,148 +1,3 @@ -JumpSetWindowOff: - jp SetWindowOff - -; debug function -; prints player's coordinates by pressing B -; and draws palettes by pressing A -Func_1c003: ; unreferenced - ld a, [wCurMap] - or a - jr z, JumpSetWindowOff - ld a, [wOverworldMode] - cp OWMODE_START_SCRIPT - jr nc, JumpSetWindowOff - - ldh a, [hKeysHeld] - ld b, a - and A_BUTTON | B_BUTTON - cp b - jr nz, JumpSetWindowOff - and B_BUTTON - jr z, JumpSetWindowOff - - ld bc, $20 - ld a, [wPlayerXCoord] - bank1call WriteTwoByteNumberInTxSymbolFormat - ld bc, $320 - ld a, [wPlayerYCoord] - bank1call WriteTwoByteNumberInTxSymbolFormat - ld a, $77 - ldh [hWX], a - ld a, $88 - ldh [hWY], a - - ldh a, [hKeysPressed] - and A_BUTTON - jr z, .skip_load_scene - ld a, SCENE_COLOR_PALETTE - lb bc, 0, 33 - call LoadScene -.skip_load_scene - ldh a, [hKeysHeld] - and A_BUTTON - jr z, .set_wd_on - ld a, $67 - ldh [hWX], a - ld a, $68 - ldh [hWY], a -.set_wd_on - call SetWindowOn - ret - -_HandleMapWarp:: - push hl - push bc - push de - ld a, [wCurMap] - add a - ld c, a - ld b, $0 - ld hl, WarpDataPointers - add hl, bc - ld a, [hli] - ld h, [hl] - ld l, a - ld bc, $5 - ld a, [wPlayerXCoord] - ld d, a - ld a, [wPlayerYCoord] - ld e, a -.loop_warp_list - ld a, [hli] - or [hl] - jr z, .done ; end of warp data - ld a, [hld] ; y coord - cp e - jr nz, .next_warp - ld a, [hl] ; x coord - cp d - jr z, .warp_player -.next_warp - add hl, bc - jr .loop_warp_list -.warp_player - inc hl - inc hl - ld a, [hli] - ld [wTempMap], a - ld a, [hli] - ld [wTempPlayerXCoord], a - ld a, [hli] - ld [wTempPlayerYCoord], a - ld a, [wPlayerDirection] - ld [wTempPlayerDirection], a -.done - pop de - pop bc - pop hl - ret - -INCLUDE "data/warps.asm" - -; loads data from the map header of wCurMap -LoadMapHeader: - push hl - push bc - push de - ld a, [wCurMap] - add a - ld c, a - add a - add c - ld c, a - ld b, 0 - ld hl, MapHeaders - add hl, bc - ld a, [hli] - ld [wCurTilemap], a - ld a, [hli] - ld c, a ; CGB tilemap variant - ld a, [hli] - ld [wCurMapInitialPalette], a ; always 0? - ld a, [hli] - ld [wCurMapSGBPals], a - ld a, [hli] - ld [wCurMapPalette], a - ld a, [hli] - ld [wDefaultSong], a - - ld a, [wConsole] - cp CONSOLE_CGB - jr nz, .got_tilemap - ; use CGB variant, if valid - ld a, c - or a - jr z, .got_tilemap - ld [wCurTilemap], a -.got_tilemap - - pop de - pop bc - pop hl - ret - -INCLUDE "data/map_headers.asm" - ClearNPCs: push hl push bc @@ -887,127 +742,3 @@ UpdateNPCPosition: pop bc pop hl ret - -ClearMasterBeatenList: - push hl - push bc - ld c, $a - ld hl, wMastersBeatenList - xor a -.loop - ld [hli], a - dec c - jr nz, .loop - pop bc - pop hl - ret - -; writes Master in register a to -; first empty slot in wMastersBeatenList -AddMasterBeatenToList: - push hl - push bc - ld b, a - ld c, $a - ld hl, wMastersBeatenList -.loop - ld a, [hl] - or a - jr z, .found_empty_slot - cp b - jr z, .exit - inc hl - dec c - jr nz, .loop - debug_nop - jr .exit - -.found_empty_slot - ld a, b - ld [hl], a - -.exit - pop bc - pop hl - ret - -; iterates all masters and attempts to -; add each of them to wMastersBeatenList -AddAllMastersToMastersBeatenList: - ld a, $01 -.loop - push af - call AddMasterBeatenToList - pop af - inc a - cp $0b - jr c, .loop - ret - -Func_1c865: - ret - -; debug function -; adjusts hSCX and hSCY by using the arrow keys -; pressing B makes it scroll faster -Func_1c866: ; unreferenced - ldh a, [hKeysHeld] - and B_BUTTON - call nz, .asm_1c86d ; executes following part twice -.asm_1c86d - ldh a, [hSCX] - ld b, a - ldh a, [hSCY] - ld c, a - ldh a, [hKeysHeld] - bit D_UP_F, a - jr z, .check_d_down - inc c -.check_d_down - bit D_DOWN_F, a - jr z, .check_d_left - dec c -.check_d_left - bit D_LEFT_F, a - jr z, .check_d_right - inc b -.check_d_right - bit D_RIGHT_F, a - jr z, .asm_1c889 - dec b -.asm_1c889 - ld a, b - ldh [hSCX], a - ld a, c - ldh [hSCY], a - ret - -; sets some flags on a given sprite -Func_1c890: ; unreferenced - ld a, [wVBlankCounter] - and %111111 - ret nz - - ld a, [wd41b] - cp $11 - jr z, .asm_1c8a3 - cp $0e - ret c - cp $10 - ret nc - -; wd41b == $11 || (wd41b >= $0e && wd41b < $10) -.asm_1c8a3 - ld a, [wd41c] - ld [wWhichSprite], a - ld c, SPRITE_ANIM_FLAGS - call GetSpriteAnimBufferProperty - call UpdateRNGSources - and (1 << SPRITE_ANIM_FLAG_X_SUBTRACT) - jr nz, .asm_1c8b9 - res SPRITE_ANIM_FLAG_SPEED, [hl] - jr .asm_1c8bb -.asm_1c8b9 - set SPRITE_ANIM_FLAG_SPEED, [hl] -.asm_1c8bb - ret diff --git a/src/engine/overworld/npcs.asm b/src/engine/overworld/npc_data.asm similarity index 100% rename from src/engine/overworld/npcs.asm rename to src/engine/overworld/npc_data.asm diff --git a/src/engine/overworld/warp.asm b/src/engine/overworld/warp.asm new file mode 100644 index 0000000..7e43631 --- /dev/null +++ b/src/engine/overworld/warp.asm @@ -0,0 +1,49 @@ +_HandleMapWarp:: + push hl + push bc + push de + ld a, [wCurMap] + add a + ld c, a + ld b, $0 + ld hl, WarpDataPointers + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld bc, $5 + ld a, [wPlayerXCoord] + ld d, a + ld a, [wPlayerYCoord] + ld e, a +.loop_warp_list + ld a, [hli] + or [hl] + jr z, .done ; end of warp data + ld a, [hld] ; y coord + cp e + jr nz, .next_warp + ld a, [hl] ; x coord + cp d + jr z, .warp_player +.next_warp + add hl, bc + jr .loop_warp_list +.warp_player + inc hl + inc hl + ld a, [hli] + ld [wTempMap], a + ld a, [hli] + ld [wTempPlayerXCoord], a + ld a, [hli] + ld [wTempPlayerYCoord], a + ld a, [wPlayerDirection] + ld [wTempPlayerDirection], a +.done + pop de + pop bc + pop hl + ret + +INCLUDE "data/warps.asm" diff --git a/src/main.asm b/src/main.asm index c27c3e5..a30e2bf 100644 --- a/src/main.asm +++ b/src/main.asm @@ -50,7 +50,7 @@ INCLUDE "engine/save.asm" SECTION "Map Scripts", ROMX INCLUDE "data/map_scripts.asm" -INCLUDE "engine/overworld/npcs.asm" +INCLUDE "engine/overworld/npc_data.asm" INCLUDE "data/duel/duel_configurations.asm" INCLUDE "data/script_table.asm" INCLUDE "data/multichoice.asm" @@ -124,7 +124,12 @@ SECTION "Auto Deck Machines", ROMX INCLUDE "engine/auto_deck_machines.asm" SECTION "Bank 7", ROMX -INCLUDE "engine/bank07.asm" +INCLUDE "engine/overworld/debug_player_coordinates.asm" +INCLUDE "engine/overworld/warp.asm" +INCLUDE "engine/overworld/load_map_header.asm" +INCLUDE "engine/overworld/npc_core.asm" +INCLUDE "engine/masters_beaten_list.asm" +INCLUDE "engine/debug_sprites.asm" SECTION "Duel Animations", ROMX INCLUDE "engine/duel/animations/core.asm"