From e13f03ae4447b741a7af9b4c28b7c36f38311c0d Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 7 Sep 2013 23:22:17 -0400 Subject: [PATCH 1/8] comment PrintMonTypes --- main.asm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.asm b/main.asm index c589b5e29..65a9c2ba3 100644 --- a/main.asm +++ b/main.asm @@ -59141,26 +59141,33 @@ Function508d5: ; 508d5 PrintMonTypes: ; 5090d +; Print both types of CurSpecies on the stats screen at hl. + push hl call GetBaseData pop hl + push hl ld a, [BaseType1] - call .asm_50928 + call .PrintType + ld a, [BaseType1] ld b, a ld a, [BaseType2] cp b pop hl - jr z, .asm_5092b + jr z, .HideSecondType + +; Next row ld bc, 20 add hl, bc -.asm_50928 +.PrintType ld b, a jr PrintType -.asm_5092b +.HideSecondType +; This doesn't actually do anything. ld a, " " ld bc, 20 - 3 add hl, bc From 801861458537ce88a7b5b608af25401989bab20a Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 7 Sep 2013 23:24:22 -0400 Subject: [PATCH 2/8] split type strings and related asm out into text/types.asm --- main.asm | 162 +------------------------------------------------ text/types.asm | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 161 deletions(-) create mode 100644 text/types.asm diff --git a/main.asm b/main.asm index 65a9c2ba3..293697989 100644 --- a/main.asm +++ b/main.asm @@ -59140,167 +59140,7 @@ Function508d5: ; 508d5 ; 5090d -PrintMonTypes: ; 5090d -; Print both types of CurSpecies on the stats screen at hl. - - push hl - call GetBaseData - pop hl - - push hl - ld a, [BaseType1] - call .PrintType - - ld a, [BaseType1] - ld b, a - ld a, [BaseType2] - cp b - pop hl - jr z, .HideSecondType - -; Next row - ld bc, 20 - add hl, bc - -.PrintType - ld b, a - jr PrintType - -.HideSecondType -; This doesn't actually do anything. - ld a, " " - ld bc, 20 - 3 - add hl, bc - ld [hl], a - inc bc - add hl, bc - ld bc, 5 - jp ByteFill -; 5093a - -PrintMoveType: ; 5093a -; Print the type of move b at hl. - - push hl - ld a, b - dec a - ld bc, Move2 - Move1 - ld hl, Moves - call AddNTimes - ld de, StringBuffer1 - ld a, BANK(Moves) - call FarCopyBytes - ld a, [StringBuffer1 + PlayerMoveType - PlayerMoveStruct] - pop hl - - ld b, a -; 50953 - -PrintType: ; 50953 -; Print type b at hl. - ld a, b - - push hl - add a - ld hl, TypeNames - ld e, a - ld d, 0 - add hl, de - ld a, [hli] - ld e, a - ld d, [hl] - pop hl - - jp PlaceString -; 50964 - - -GetTypeName: ; 50964 -; Copy the name of type $d265 to StringBuffer1. - ld a, [$d265] - ld hl, TypeNames - ld e, a - ld d, 0 - add hl, de - add hl, de - ld a, [hli] - ld h, [hl] - ld l, a - ld de, StringBuffer1 - ld bc, $000d - jp CopyBytes -; 5097b - - -TypeNames: ; 5097b - dw Normal - dw Fighting - dw Flying - dw Poison - dw Ground - dw Rock - dw Bird - dw Bug - dw Ghost - dw Steel - dw Normal - dw Normal - dw Normal - dw Normal - dw Normal - dw Normal - dw Normal - dw Normal - dw Normal - dw UnknownType - dw Fire - dw Water - dw Grass - dw Electric - dw Psychic - dw Ice - dw Dragon - dw Dark - -Normal: - db "NORMAL@" -Fighting: - db "FIGHTING@" -Flying: - db "FLYING@" -Poison: - db "POISON@" -UnknownType: - db "???@" -Fire: - db "FIRE@" -Water: - db "WATER@" -Grass: - db "GRASS@" -Electric: - db "ELECTRIC@" -Psychic: - db "PSYCHIC@" -Ice: - db "ICE@" -Ground: - db "GROUND@" -Rock: - db "ROCK@" -Bird: - db "BIRD@" -Bug: - db "BUG@" -Ghost: - db "GHOST@" -Steel: - db "STEEL@" -Dragon: - db "DRAGON@" -Dark: - db "DARK@" -; 50a28 +INCLUDE "text/types.asm" Function50a28: ; 50a28 diff --git a/text/types.asm b/text/types.asm new file mode 100644 index 000000000..0addaaf6e --- /dev/null +++ b/text/types.asm @@ -0,0 +1,162 @@ +PrintMonTypes: ; 5090d +; Print both types of CurSpecies on the stats screen at hl. + + push hl + call GetBaseData + pop hl + + push hl + ld a, [BaseType1] + call .PrintType + + ld a, [BaseType1] + ld b, a + ld a, [BaseType2] + cp b + pop hl + jr z, .HideSecondType + +; Next row + ld bc, 20 + add hl, bc + +.PrintType + ld b, a + jr PrintType + +.HideSecondType +; This doesn't actually do anything. + ld a, " " + ld bc, 20 - 3 + add hl, bc + ld [hl], a + inc bc + add hl, bc + ld bc, 5 + jp ByteFill +; 5093a + +PrintMoveType: ; 5093a +; Print the type of move b at hl. + + push hl + ld a, b + dec a + ld bc, Move2 - Move1 + ld hl, Moves + call AddNTimes + ld de, StringBuffer1 + ld a, BANK(Moves) + call FarCopyBytes + ld a, [StringBuffer1 + PlayerMoveType - PlayerMoveStruct] + pop hl + + ld b, a +; 50953 + +PrintType: ; 50953 +; Print type b at hl. + ld a, b + + push hl + add a + ld hl, TypeNames + ld e, a + ld d, 0 + add hl, de + ld a, [hli] + ld e, a + ld d, [hl] + pop hl + + jp PlaceString +; 50964 + + +GetTypeName: ; 50964 +; Copy the name of type $d265 to StringBuffer1. + ld a, [$d265] + ld hl, TypeNames + ld e, a + ld d, 0 + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld de, StringBuffer1 + ld bc, $000d + jp CopyBytes +; 5097b + + +TypeNames: ; 5097b + dw Normal + dw Fighting + dw Flying + dw Poison + dw Ground + dw Rock + dw Bird + dw Bug + dw Ghost + dw Steel + dw Normal + dw Normal + dw Normal + dw Normal + dw Normal + dw Normal + dw Normal + dw Normal + dw Normal + dw UnknownType + dw Fire + dw Water + dw Grass + dw Electric + dw Psychic + dw Ice + dw Dragon + dw Dark + +Normal: + db "NORMAL@" +Fighting: + db "FIGHTING@" +Flying: + db "FLYING@" +Poison: + db "POISON@" +UnknownType: + db "???@" +Fire: + db "FIRE@" +Water: + db "WATER@" +Grass: + db "GRASS@" +Electric: + db "ELECTRIC@" +Psychic: + db "PSYCHIC@" +Ice: + db "ICE@" +Ground: + db "GROUND@" +Rock: + db "ROCK@" +Bird: + db "BIRD@" +Bug: + db "BUG@" +Ghost: + db "GHOST@" +Steel: + db "STEEL@" +Dragon: + db "DRAGON@" +Dark: + db "DARK@" +; 50a28 + From 7a3a4f913b32784480dc297e8a4794934ec87b06 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 7 Sep 2013 23:26:28 -0400 Subject: [PATCH 3/8] split fruit tree asm out into engine/fruit_trees.asm --- engine/fruit_trees.asm | 165 ++++++++++++++++++++++++++++++++++++++++ main.asm | 166 +---------------------------------------- 2 files changed, 166 insertions(+), 165 deletions(-) create mode 100644 engine/fruit_trees.asm diff --git a/engine/fruit_trees.asm b/engine/fruit_trees.asm new file mode 100644 index 000000000..5890d6784 --- /dev/null +++ b/engine/fruit_trees.asm @@ -0,0 +1,165 @@ +FruitTreeScript: ; 44000 + 3callasm BANK(GetCurTreeFruit), GetCurTreeFruit + loadfont + copybytetovar CurFruit + itemtotext $0, $0 + 2writetext FruitBearingTreeText + keeptextopen + 3callasm BANK(TryResetFruitTrees), TryResetFruitTrees + 3callasm BANK(CheckFruitTree), CheckFruitTree + iffalse .fruit + 2writetext NothingHereText + closetext + 2jump .end + +.fruit + 2writetext HeyItsFruitText + copybytetovar CurFruit + giveitem $ff, 1 + iffalse .packisfull + keeptextopen + 2writetext ObtainedFruitText + 3callasm BANK(PickedFruitTree), PickedFruitTree + specialsound + itemnotify + 2jump .end + +.packisfull + keeptextopen + 2writetext FruitPackIsFullText + closetext + +.end + loadmovesprites + end +; 44041 + +GetCurTreeFruit: ; 44041 + ld a, [CurFruitTree] + dec a + call GetFruitTreeItem + ld [CurFruit], a + ret +; 4404c + +TryResetFruitTrees: ; 4404c + ld hl, $dc1e + bit 4, [hl] + ret nz + jp ResetFruitTrees +; 44055 + +CheckFruitTree: ; 44055 + ld b, 2 + call GetFruitTreeFlag + ld a, c + ld [ScriptVar], a + ret +; 4405f + +PickedFruitTree: ; 4405f + ld a, $41 + ld hl, $609b + rst FarCall ; empty function + + ld b, 1 + jp GetFruitTreeFlag +; 4406a + +ResetFruitTrees: ; 4406a + xor a + ld hl, FruitTreeFlags + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld hl, $dc1e + set 4, [hl] + ret +; 44078 + +GetFruitTreeFlag: ; 44078 + push hl + push de + ld a, [CurFruitTree] + dec a + ld e, a + ld d, 0 + ld hl, FruitTreeFlags + call FlagAction + pop de + pop hl + ret +; 4408a + +GetFruitTreeItem: ; 4408a + push hl + push de + ld e, a + ld d, 0 + ld hl, FruitTreeItems + add hl, de + ld a, [hl] + pop de + pop hl + ret +; 44097 + +FruitTreeItems: ; 44097 + db BERRY + db BERRY + db BERRY + db BERRY + db PSNCUREBERRY + db PSNCUREBERRY + db BITTER_BERRY + db BITTER_BERRY + db PRZCUREBERRY + db PRZCUREBERRY + db MYSTERYBERRY + db MYSTERYBERRY + db ICE_BERRY + db ICE_BERRY + db MINT_BERRY + db BURNT_BERRY + db RED_APRICORN + db BLU_APRICORN + db BLK_APRICORN + db WHT_APRICORN + db PNK_APRICORN + db GRN_APRICORN + db YLW_APRICORN + db BERRY + db PSNCUREBERRY + db BITTER_BERRY + db PRZCUREBERRY + db ICE_BERRY + db MINT_BERRY + db BURNT_BERRY +; 440b5 + +FruitBearingTreeText: ; 440b5 + text_jump _FruitBearingTreeText, BANK(_FruitBearingTreeText) + db "@" +; 440ba + +HeyItsFruitText: ; 440ba + text_jump _HeyItsFruitText, BANK(_HeyItsFruitText) + db "@" +; 440bf + +ObtainedFruitText: ; 440bf + text_jump _ObtainedFruitText, BANK(_ObtainedFruitText) + db "@" +; 440c4 + +FruitPackIsFullText: ; 440c4 + text_jump _FruitPackIsFullText, BANK(_FruitPackIsFullText) + db "@" +; 440c9 + +NothingHereText: ; 440c9 + text_jump _NothingHereText, BANK(_NothingHereText) + db "@" +; 440ce + diff --git a/main.asm b/main.asm index 293697989..5e0e782ba 100644 --- a/main.asm +++ b/main.asm @@ -51896,171 +51896,7 @@ INCLUDE "stats/evos_attacks.asm" SECTION "bank11",ROMX,BANK[$11] -FruitTreeScript: ; 44000 - 3callasm BANK(GetCurTreeFruit), GetCurTreeFruit - loadfont - copybytetovar CurFruit - itemtotext $0, $0 - 2writetext FruitBearingTreeText - keeptextopen - 3callasm BANK(TryResetFruitTrees), TryResetFruitTrees - 3callasm BANK(CheckFruitTree), CheckFruitTree - iffalse .fruit - 2writetext NothingHereText - closetext - 2jump .end - -.fruit - 2writetext HeyItsFruitText - copybytetovar CurFruit - giveitem $ff, 1 - iffalse .packisfull - keeptextopen - 2writetext ObtainedFruitText - 3callasm BANK(PickedFruitTree), PickedFruitTree - specialsound - itemnotify - 2jump .end - -.packisfull - keeptextopen - 2writetext FruitPackIsFullText - closetext - -.end - loadmovesprites - end -; 44041 - -GetCurTreeFruit: ; 44041 - ld a, [CurFruitTree] - dec a - call GetFruitTreeItem - ld [CurFruit], a - ret -; 4404c - -TryResetFruitTrees: ; 4404c - ld hl, $dc1e - bit 4, [hl] - ret nz - jp ResetFruitTrees -; 44055 - -CheckFruitTree: ; 44055 - ld b, 2 - call GetFruitTreeFlag - ld a, c - ld [ScriptVar], a - ret -; 4405f - -PickedFruitTree: ; 4405f - ld a, $41 - ld hl, $609b - rst FarCall ; empty function - - ld b, 1 - jp GetFruitTreeFlag -; 4406a - -ResetFruitTrees: ; 4406a - xor a - ld hl, FruitTreeFlags - ld [hli], a - ld [hli], a - ld [hli], a - ld [hl], a - ld hl, $dc1e - set 4, [hl] - ret -; 44078 - -GetFruitTreeFlag: ; 44078 - push hl - push de - ld a, [CurFruitTree] - dec a - ld e, a - ld d, 0 - ld hl, FruitTreeFlags - call FlagAction - pop de - pop hl - ret -; 4408a - -GetFruitTreeItem: ; 4408a - push hl - push de - ld e, a - ld d, 0 - ld hl, FruitTreeItems - add hl, de - ld a, [hl] - pop de - pop hl - ret -; 44097 - -FruitTreeItems: ; 44097 - db BERRY - db BERRY - db BERRY - db BERRY - db PSNCUREBERRY - db PSNCUREBERRY - db BITTER_BERRY - db BITTER_BERRY - db PRZCUREBERRY - db PRZCUREBERRY - db MYSTERYBERRY - db MYSTERYBERRY - db ICE_BERRY - db ICE_BERRY - db MINT_BERRY - db BURNT_BERRY - db RED_APRICORN - db BLU_APRICORN - db BLK_APRICORN - db WHT_APRICORN - db PNK_APRICORN - db GRN_APRICORN - db YLW_APRICORN - db BERRY - db PSNCUREBERRY - db BITTER_BERRY - db PRZCUREBERRY - db ICE_BERRY - db MINT_BERRY - db BURNT_BERRY -; 440b5 - -FruitBearingTreeText: ; 440b5 - text_jump _FruitBearingTreeText, BANK(_FruitBearingTreeText) - db "@" -; 440ba - -HeyItsFruitText: ; 440ba - text_jump _HeyItsFruitText, BANK(_HeyItsFruitText) - db "@" -; 440bf - -ObtainedFruitText: ; 440bf - text_jump _ObtainedFruitText, BANK(_ObtainedFruitText) - db "@" -; 440c4 - -FruitPackIsFullText: ; 440c4 - text_jump _FruitPackIsFullText, BANK(_FruitPackIsFullText) - db "@" -; 440c9 - -NothingHereText: ; 440c9 - text_jump _NothingHereText, BANK(_NothingHereText) - db "@" -; 440ce - +INCLUDE "engine/fruit_trees.asm" AIChooseMove: ; 440ce From 9f53825ce2701f94470a98b3decd8013fbeba91a Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 7 Sep 2013 23:38:19 -0400 Subject: [PATCH 4/8] move common asm from engine/ to common/ engine/ was getting really bloated and common asm wasnt what it was made for --- {engine => common}/copy.asm | 0 {engine => common}/decompress.asm | 0 {engine => common}/delay.asm | 0 {engine => common}/fade.asm | 0 {engine => common}/farcall.asm | 0 {engine => common}/game_time.asm | 0 {engine => common}/init.asm | 0 {engine => common}/joypad.asm | 0 {engine => common}/lcd.asm | 0 {engine => common}/map_objects.asm | 0 {engine => common}/menu.asm | 0 {engine => common}/palettes.asm | 0 {engine => common}/rtc.asm | 0 {engine => common}/serial.asm | 0 {engine => common}/sine.asm | 0 {engine => common}/text.asm | 0 {engine => common}/time.asm | 0 {engine => common}/vblank.asm | 0 {engine => common}/video.asm | 0 main.asm | 38 +++++++++++++++--------------- 20 files changed, 19 insertions(+), 19 deletions(-) rename {engine => common}/copy.asm (100%) rename {engine => common}/decompress.asm (100%) rename {engine => common}/delay.asm (100%) rename {engine => common}/fade.asm (100%) rename {engine => common}/farcall.asm (100%) rename {engine => common}/game_time.asm (100%) rename {engine => common}/init.asm (100%) rename {engine => common}/joypad.asm (100%) rename {engine => common}/lcd.asm (100%) rename {engine => common}/map_objects.asm (100%) rename {engine => common}/menu.asm (100%) rename {engine => common}/palettes.asm (100%) rename {engine => common}/rtc.asm (100%) rename {engine => common}/serial.asm (100%) rename {engine => common}/sine.asm (100%) rename {engine => common}/text.asm (100%) rename {engine => common}/time.asm (100%) rename {engine => common}/vblank.asm (100%) rename {engine => common}/video.asm (100%) diff --git a/engine/copy.asm b/common/copy.asm similarity index 100% rename from engine/copy.asm rename to common/copy.asm diff --git a/engine/decompress.asm b/common/decompress.asm similarity index 100% rename from engine/decompress.asm rename to common/decompress.asm diff --git a/engine/delay.asm b/common/delay.asm similarity index 100% rename from engine/delay.asm rename to common/delay.asm diff --git a/engine/fade.asm b/common/fade.asm similarity index 100% rename from engine/fade.asm rename to common/fade.asm diff --git a/engine/farcall.asm b/common/farcall.asm similarity index 100% rename from engine/farcall.asm rename to common/farcall.asm diff --git a/engine/game_time.asm b/common/game_time.asm similarity index 100% rename from engine/game_time.asm rename to common/game_time.asm diff --git a/engine/init.asm b/common/init.asm similarity index 100% rename from engine/init.asm rename to common/init.asm diff --git a/engine/joypad.asm b/common/joypad.asm similarity index 100% rename from engine/joypad.asm rename to common/joypad.asm diff --git a/engine/lcd.asm b/common/lcd.asm similarity index 100% rename from engine/lcd.asm rename to common/lcd.asm diff --git a/engine/map_objects.asm b/common/map_objects.asm similarity index 100% rename from engine/map_objects.asm rename to common/map_objects.asm diff --git a/engine/menu.asm b/common/menu.asm similarity index 100% rename from engine/menu.asm rename to common/menu.asm diff --git a/engine/palettes.asm b/common/palettes.asm similarity index 100% rename from engine/palettes.asm rename to common/palettes.asm diff --git a/engine/rtc.asm b/common/rtc.asm similarity index 100% rename from engine/rtc.asm rename to common/rtc.asm diff --git a/engine/serial.asm b/common/serial.asm similarity index 100% rename from engine/serial.asm rename to common/serial.asm diff --git a/engine/sine.asm b/common/sine.asm similarity index 100% rename from engine/sine.asm rename to common/sine.asm diff --git a/engine/text.asm b/common/text.asm similarity index 100% rename from engine/text.asm rename to common/text.asm diff --git a/engine/time.asm b/common/time.asm similarity index 100% rename from engine/time.asm rename to common/time.asm diff --git a/engine/vblank.asm b/common/vblank.asm similarity index 100% rename from engine/vblank.asm rename to common/vblank.asm diff --git a/engine/video.asm b/common/video.asm similarity index 100% rename from engine/video.asm rename to common/video.asm diff --git a/main.asm b/main.asm index 5e0e782ba..30084dbf2 100644 --- a/main.asm +++ b/main.asm @@ -14,22 +14,22 @@ Start: SECTION "start",ROM0[$150] -INCLUDE "engine/init.asm" -INCLUDE "engine/vblank.asm" -INCLUDE "engine/delay.asm" -INCLUDE "engine/rtc.asm" -INCLUDE "engine/fade.asm" -INCLUDE "engine/lcd.asm" -INCLUDE "engine/time.asm" -INCLUDE "engine/serial.asm" -INCLUDE "engine/joypad.asm" -INCLUDE "engine/decompress.asm" -INCLUDE "engine/palettes.asm" -INCLUDE "engine/copy.asm" -INCLUDE "engine/text.asm" -INCLUDE "engine/video.asm" -INCLUDE "engine/map_objects.asm" -INCLUDE "engine/sine.asm" +INCLUDE "common/init.asm" +INCLUDE "common/vblank.asm" +INCLUDE "common/delay.asm" +INCLUDE "common/rtc.asm" +INCLUDE "common/fade.asm" +INCLUDE "common/lcd.asm" +INCLUDE "common/time.asm" +INCLUDE "common/serial.asm" +INCLUDE "common/joypad.asm" +INCLUDE "common/decompress.asm" +INCLUDE "common/palettes.asm" +INCLUDE "common/copy.asm" +INCLUDE "common/text.asm" +INCLUDE "common/video.asm" +INCLUDE "common/map_objects.asm" +INCLUDE "common/sine.asm" Function1b1e: ; 1b1e ld [$d003], a @@ -473,7 +473,7 @@ Function1d19: ; 1d19 ; 1d35 -INCLUDE "engine/menu.asm" +INCLUDE "common/menu.asm" AskSerial: ; 2063 @@ -515,7 +515,7 @@ AskSerial: ; 2063 ; 208a -INCLUDE "engine/game_time.asm" +INCLUDE "common/game_time.asm" Function210f: ; 210f @@ -2906,7 +2906,7 @@ Function2d43: ; 2d43 ; 2d54 -INCLUDE "engine/farcall.asm" +INCLUDE "common/farcall.asm" Predef: ; 2d83 From 847843d866aa79727f7d1dd98c2b212e8b5053ef Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 7 Sep 2013 23:49:20 -0400 Subject: [PATCH 5/8] rename BUTTON_A and BUTTON_B constants to A_BUTTON and B_BUTTON --- common/joypad.asm | 12 ++++++------ common/text.asm | 4 ++-- constants.asm | 4 ++-- main.asm | 20 ++++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/common/joypad.asm b/common/joypad.asm index 388c84e22..198e1c47b 100644 --- a/common/joypad.asm +++ b/common/joypad.asm @@ -101,8 +101,8 @@ Joypad: ; 935 ; Now that we have the input, we can do stuff with it. ; For example, soft reset: - and BUTTON_A | BUTTON_B | SELECT | START - cp BUTTON_A | BUTTON_B | SELECT | START + and A_BUTTON | B_BUTTON | SELECT | START + cp A_BUTTON | B_BUTTON | SELECT | START jp z, Reset ret @@ -283,11 +283,11 @@ Functiona1b: ; a1b pop bc ld a, [hJoyDown] - cp D_UP | SELECT | BUTTON_B + cp D_UP | SELECT | B_BUTTON jr z, .asm_a34 ld a, [$ffa9] - and START | BUTTON_A + and START | A_BUTTON jr nz, .asm_a34 dec c @@ -306,7 +306,7 @@ Functiona36: ; a36 call DelayFrame call GetJoypadPublic ld a, [hJoyPressed] - and BUTTON_A | BUTTON_B + and A_BUTTON | B_BUTTON ret nz call RTC jr Functiona36 @@ -382,7 +382,7 @@ Functiona80: ; a80 Functionaa5: ; aa5 call Functiona57 ld a, [$ffa9] - and BUTTON_A | BUTTON_B + and A_BUTTON | B_BUTTON jr z, Functionaa5 ret ; aaf diff --git a/common/text.asm b/common/text.asm index 4f39a95df..e010de6d4 100644 --- a/common/text.asm +++ b/common/text.asm @@ -1054,7 +1054,7 @@ Text_0A: ; 14ed push bc call GetJoypadPublic ld a, [hJoyDown] - and BUTTON_A | BUTTON_B + and A_BUTTON | B_BUTTON jr nz, .asm_14fd ld c, 30 call DelayFrames @@ -1136,7 +1136,7 @@ Text_0C: ; 1543 ld [hli], a call GetJoypadPublic ld a, [hJoyDown] - and BUTTON_A | BUTTON_B + and A_BUTTON | B_BUTTON jr nz, .asm_155a ld c, 10 call DelayFrames diff --git a/constants.asm b/constants.asm index 70405446e..84d93f9dd 100644 --- a/constants.asm +++ b/constants.asm @@ -170,8 +170,8 @@ BUTTONS EQU %00010000 D_PAD EQU %00100000 NO_INPUT EQU %00000000 -BUTTON_A EQU %00000001 -BUTTON_B EQU %00000010 +A_BUTTON EQU %00000001 +B_BUTTON EQU %00000010 SELECT EQU %00000100 START EQU %00001000 D_RIGHT EQU %00010000 diff --git a/main.asm b/main.asm index 30084dbf2..e5f9675d7 100644 --- a/main.asm +++ b/main.asm @@ -23902,9 +23902,9 @@ StartMenu: ; 125cd call .PrintMenuAccount call Function1f1a ld a, [$cf73] - cp BUTTON_B + cp B_BUTTON jr z, .b - cp BUTTON_A + cp A_BUTTON jr z, .a jr .loop .a @@ -31482,11 +31482,11 @@ Function16be4: ; 16be4 call Functiona57 ld a, [hJoyPressed] - and BUTTON_B + and B_BUTTON jr nz, .asm_16c95 ld a, [hJoyPressed] - and BUTTON_A + and A_BUTTON jr nz, .asm_16c82 call Function16ca0 @@ -61158,7 +61158,7 @@ CheckForcedMovementInput: ; 802cb ld hl, .data_802e8 add hl, de ld a, [CurInput] - and BUTTON_A | BUTTON_B | SELECT | START + and A_BUTTON | B_BUTTON | SELECT | START or [hl] ld [CurInput], a ret @@ -70599,7 +70599,7 @@ OWPlayerInput: ; 96974 CheckAPressOW: ; 96999 ld a, [hJoyPressed] - and BUTTON_A + and A_BUTTON ret z call TryObjectEvent ret c @@ -75887,7 +75887,7 @@ Functione4512: ; e4512 Options_Cancel: ; e4520 ld a, [hJoyPressed] - and BUTTON_A + and A_BUTTON jr nz, .asm_e4528 and a ret @@ -90228,7 +90228,7 @@ Function1de299: ; 1de299 DudeAutoInput_A: ; 1de29f db NO_INPUT, $50 - db BUTTON_A, $00 + db A_BUTTON, $00 db NO_INPUT, $ff ; end ; 1de2a5 @@ -90236,7 +90236,7 @@ DudeAutoInput_RightA: ; 1de2a5 db NO_INPUT, $08 db D_RIGHT, $00 db NO_INPUT, $08 - db BUTTON_A, $00 + db A_BUTTON, $00 db NO_INPUT, $ff ; end ; 1de2af @@ -90250,7 +90250,7 @@ DudeAutoInput_DownA: ; 1de2af db NO_INPUT, $fe db NO_INPUT, $fe db NO_INPUT, $fe - db BUTTON_A, $00 + db A_BUTTON, $00 db NO_INPUT, $ff ; end ; 1de2c5 From f513cdd8883336096031f91b00791864ded473f9 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 00:14:26 -0400 Subject: [PATCH 6/8] split map engine asm into common/map.asm --- common/map.asm | 2369 ++++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 2367 +---------------------------------------------- 2 files changed, 2370 insertions(+), 2366 deletions(-) create mode 100644 common/map.asm diff --git a/common/map.asm b/common/map.asm new file mode 100644 index 000000000..d4cfe1be9 --- /dev/null +++ b/common/map.asm @@ -0,0 +1,2369 @@ +; Functions dealing with rendering and interacting with maps. + +Function210f: ; 210f + ld hl, $c7e8 + ld bc, $0018 + ld a, $0 + call ByteFill + ret +; 211b + +Function211b: ; 211b + push hl + ld hl, $dbf7 + ld a, [hli] + ld h, [hl] + ld l, a + or h + ld a, [hl] + jr nz, .asm_2128 + ld a, $ff + +.asm_2128 + pop hl + ret +; 212a + +Function212a: ; 212a + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a + xor a + ld [$dbf7], a + ld [$dbf8], a + call Function2147 + ret c + ld a, e + ld [$dbf7], a + ld a, d + ld [$dbf8], a + xor a + ret +; 2147 + +Function2147: ; 2147 + push bc + ld a, [hROMBank] + push af + ld a, $13 + rst Bankswitch + + ld hl, $501e +.asm_2151 + push hl + ld a, [hli] + cp $ff + jr z, .asm_2167 + cp b + jr nz, .asm_2160 + ld a, [hli] + cp c + jr nz, .asm_2160 + jr .asm_216a + +.asm_2160 + pop hl + ld de, $0004 + add hl, de + jr .asm_2151 + +.asm_2167 + scf + jr .asm_216d + +.asm_216a + ld e, [hl] + inc hl + ld d, [hl] + +.asm_216d + pop hl + pop bc + ld a, b + rst Bankswitch + + pop bc + ret +; 2173 + +Function2173: ; 2173 + call Function217a + call Functiondb1 + ret +; 217a + +Function217a: ; 217a + ld a, [hROMBank] + push af + ld a, [TilesetBlocksBank] + rst Bankswitch + + call Function2198 + ld a, $60 + ld hl, TileMap + ld bc, $0168 + call ByteFill + ld a, $13 + rst Bankswitch + + call $515b + pop af + rst Bankswitch + + ret +; 2198 + +Function2198: ; 2198 + ld a, [$d194] + ld e, a + ld a, [$d195] + ld d, a + ld hl, EnemyMoveAnimation + ld b, $5 + +.asm_21a5 + push de + push hl + ld c, $6 + +.asm_21a9 + push de + push hl + ld a, [de] + and a + jr nz, .asm_21b2 + ld a, [$d19d] + +.asm_21b2 + ld e, l + ld d, h + add a + ld l, a + ld h, $0 + add hl, hl + add hl, hl + add hl, hl + ld a, [TilesetBlocksAddress] + add l + ld l, a + ld a, [TilesetBlocksAddress + 1] + adc h + ld h, a + +rept 3 + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + + ld a, e + add 20 + ld e, a + jr nc, .next\@ + inc d +.next\@ +endr + + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + + pop hl + ld de, $0004 + add hl, de + pop de + inc de + dec c + jp nz, .asm_21a9 + pop hl + ld de, $0060 + add hl, de + pop de + ld a, [$d19f] + add $6 + add e + ld e, a + jr nc, .asm_2225 + inc d + +.asm_2225 + dec b + jp nz, .asm_21a5 + ret +; 222a + +Function222a: ; 222a + ld a, $fa + ld [$ff9f], a + callba Function15363 + xor a + ld [$ff9f], a + ret +; 2238 + +Function2238: ; 2238 + call Function2252 + ret nc + push bc + callba Function149af + pop bc + ret nc + call Function22a7 + scf + ret +; 224a + + + +Function224a: ; 224a + call Function2252 + ret nc + call Function22a7 + ret +; 2252 + +Function2252: ; 2252 + callba Function1499a + ret nc + + ld a, [hROMBank] + push af + + call Function2c52 + call Function2266 + + pop de + ld a, d + rst Bankswitch + ret +; 2266 + +Function2266: ; 2266 + ld a, [MapY] + sub $4 + ld e, a + ld a, [MapX] + sub $4 + ld d, a + ld a, [$dbfb] + and a + ret z + ld c, a + ld hl, $dbfc + ld a, [hli] + ld h, [hl] + ld l, a +.asm_227e + push hl + ld a, [hli] + cp e + jr nz, .asm_2289 + ld a, [hli] + cp d + jr nz, .asm_2289 + jr .asm_2296 + +.asm_2289 + pop hl + ld a, $5 + add l + ld l, a + jr nc, .asm_2291 + inc h + +.asm_2291 + dec c + jr nz, .asm_227e + xor a + ret + +.asm_2296 + pop hl + call Function22a3 + ret nc + ld a, [$dbfb] + inc a + sub c + ld c, a + scf + ret +; 22a3 + +Function22a3: ; 22a3 + inc hl + inc hl + scf + ret +; 22a7 + +Function22a7: ; 22a7 + ld a, [hROMBank] + push af + + call Function2c52 + call Function22b4 + + pop af + rst Bankswitch + scf + ret +; 22b4 + +Function22b4: ; 22b4 + push bc + ld hl, $dbfc + ld a, [hli] + ld h, [hl] + ld l, a + ld a, c + dec a + ld bc, $0005 + call AddNTimes + ld bc, $0002 + add hl, bc + ld a, [hli] + cp $ff + jr nz, .asm_22d0 + ld hl, $dcac + ld a, [hli] + +.asm_22d0 + pop bc + ld [$d146], a + ld a, [hli] + ld [$d147], a + ld a, [hli] + ld [$d148], a + ld a, c + ld [$d149], a + ld a, [MapGroup] + ld [$d14a], a + ld a, [MapNumber] + ld [$d14b], a + scf + ret +; 22ee + + + +CheckOutdoorMap: ; 22ee + cp ROUTE + ret z + cp TOWN + ret +; 22f4 + +CheckIndoorMap: ; 22f4 + cp INDOOR + ret z + cp CAVE + ret z + cp DUNGEON + ret z + cp GATE + ret +; 2300 + +Function2300: ; 2300 + cp INDOOR + ret z + cp GATE + ret z + cp $5 + ret +; 2309 + + +Function2309: ; 2309 + call Function2326 + call Function2c52 + call Function234f + xor a + call Function2336 + ret +; 2317 + +Function2317: ; 2317 + call Function2326 + call Function2c52 + call Function234f + ld a, $1 + call Function2336 + ret +; 2326 + +Function2326: ; 2326 + call Function2c3d + call Function2c1c + call GetSecondaryMapHeaderPointer + call Function235c + call Function2368 + ret +; 2336 + +Function2336: ; 2336 + push af + ld hl, $d1a6 + ld a, [hli] + ld h, [hl] + ld l, a + inc hl + inc hl + call Function23da + call Function23f1 + call Function2408 + pop af + and a + ret nz + call Function241f + ret +; 234f + +Function234f: ; 234f + ld hl, $d1a4 + ld a, [hli] + ld h, [hl] + ld l, a + call Function23ac + call Function23c3 + ret +; 235c + +Function235c: ; 235c + ld de, $d19d + ld c, $c +.asm_2361 + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .asm_2361 + ret +; 2368 + +Function2368: ; 2368 + ld a, $ff + ld [NorthConnectedMapGroup], a + ld [SouthConnectedMapGroup], a + ld [WestConnectedMapGroup], a + ld [EastConnectedMapGroup], a + + ld a, [$d1a8] + ld b, a + + bit 3, b + jr z, .asm_2384 + ld de, NorthMapConnection + call GetMapConnection + +.asm_2384 + bit 2, b + jr z, .asm_238e + ld de, SouthMapConnection + call GetMapConnection + +.asm_238e + bit 1, b + jr z, .asm_2398 + ld de, WestMapConnection + call GetMapConnection + +.asm_2398 + bit 0, b + jr z, .asm_23a2 + ld de, EastMapConnection + call GetMapConnection + +.asm_23a2 + ret +; 23a3 + + +GetMapConnection: ; 23a3 +; Load map connection struct at hl into de. + ld c, SouthMapConnection - NorthMapConnection +.loop + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .loop + ret +; 23ac + + +Function23ac: ; 23ac + ld a, [hli] + ld c, a + ld [$dc07], a + ld a, l + ld [$dc08], a + ld a, h + ld [$dc09], a + ld a, c + and a + ret z + ld bc, $0004 + call AddNTimes + ret +; 23c3 + +Function23c3: ; 23c3 + ld a, [hli] + ld c, a + ld [$dc0a], a + ld a, l + ld [$dc0b], a + ld a, h + ld [$dc0c], a + ld a, c + and a + ret z + ld bc, $0003 + call AddNTimes + ret +; 23da + +Function23da: ; 23da + ld a, [hli] + ld c, a + ld [$dbfb], a + ld a, l + ld [$dbfc], a + ld a, h + ld [$dbfd], a + ld a, c + and a + ret z + ld bc, $0005 + call AddNTimes + ret +; 23f1 + +Function23f1: ; 23f1 + ld a, [hli] + ld c, a + ld [$dbfe], a + ld a, l + ld [$dbff], a + ld a, h + ld [$dc00], a + ld a, c + and a + ret z + ld bc, $0008 + call AddNTimes + ret +; 2408 + +Function2408: ; 2408 + ld a, [hli] + ld c, a + ld [$dc01], a + ld a, l + ld [$dc02], a + ld a, h + ld [$dc03], a + ld a, c + and a + ret z + ld bc, $0005 + call AddNTimes + ret +; 241f + +Function241f: ; 241f + push hl + call Function2471 + pop de + ld hl, $d72e + ld a, [de] + inc de + ld [$dc04], a + ld a, e + ld [$dc05], a + ld a, d + ld [$dc06], a + ld a, [$dc04] + call Function2457 + ld a, [$dc04] + ld c, a + ld a, $10 + sub c + jr z, .asm_2454 + ld bc, $0001 + add hl, bc + ld bc, $0010 +.asm_244a + ld [hl], $0 + inc hl + ld [hl], $ff + dec hl + add hl, bc + dec a + jr nz, .asm_244a + +.asm_2454 + ld h, d + ld l, e + ret +; 2457 + +Function2457: ; 2457 + and a + ret z + ld c, a +.asm_245a + push bc + push hl + ld a, $ff + ld [hli], a + ld b, $d +.asm_2461 + ld a, [de] + inc de + ld [hli], a + dec b + jr nz, .asm_2461 + pop hl + ld bc, $0010 + add hl, bc + pop bc + dec c + jr nz, .asm_245a + ret +; 2471 + +Function2471: ; 2471 + ld hl, $d4fe + ld bc, $01e0 + xor a + call ByteFill + ld hl, $d4fe + ld de, $0028 + ld c, $c + xor a +.asm_2484 + ld [hl], a + add hl, de + dec c + jr nz, .asm_2484 + ret +; 248a + +Function248a: ; 248a + call GetMapEventBank + rst Bankswitch + + ld hl, $d1a6 + ld a, [hli] + ld h, [hl] + ld l, a + inc hl + inc hl + inc hl + ld a, [WarpNumber] + dec a + ld c, a + ld b, $0 + ld a, $5 + call AddNTimes + ld a, [hli] + ld [YCoord], a + ld a, [hli] + ld [XCoord], a + ld a, [hli] + cp $ff + jr nz, .asm_24b3 + call Function24ba + +.asm_24b3 + ld a, $41 + ld hl, $486d + rst FarCall + ret +; 24ba + +Function24ba: ; 24ba + ld a, [$d149] + ld [$dcac], a + ld a, [$d14a] + ld [BackupMapGroup], a + ld a, [$d14b] + ld [BackupMapNumber], a + ret +; 24cd + +Function24cd: ; 24cd + ld hl, OverworldMap + ld bc, $0514 + ld a, $0 + call ByteFill + call Function24e4 + call FillMapConnections + ld a, $1 + call Function263b + ret +; 24e4 + + + +Function24e4: ; 24e4 + ld a, [hROMBank] + push af + ld hl, OverworldMap + ld a, [$d19f] + ld [hConnectedMapWidth], a + add $6 + ld [hConnectionStripLength], a + ld c, a + ld b, $0 + add hl, bc + add hl, bc + add hl, bc + ld c, $3 + add hl, bc + ld a, [$d1a0] + rst Bankswitch + + ld a, [$d1a1] + ld e, a + ld a, [$d1a2] + ld d, a + ld a, [$d19e] + ld b, a +.asm_250c + push hl + ld a, [hConnectedMapWidth] + ld c, a +.asm_2510 + ld a, [de] + inc de + ld [hli], a + dec c + jr nz, .asm_2510 + pop hl + ld a, [hConnectionStripLength] + add l + ld l, a + jr nc, .asm_251e + inc h + +.asm_251e + dec b + jr nz, .asm_250c + pop af + rst Bankswitch + + ret +; 2524 + + + +FillMapConnections: ; 2524 + +; North + ld a, [NorthConnectedMapGroup] + cp $ff + jr z, .South + ld b, a + ld a, [NorthConnectedMapNumber] + ld c, a + call GetAnyMapBlockdataBank + + ld a, [NorthConnectionStripPointer] + ld l, a + ld a, [NorthConnectionStripPointer + 1] + ld h, a + ld a, [NorthConnectionStripLocation] + ld e, a + ld a, [NorthConnectionStripLocation + 1] + ld d, a + ld a, [NorthConnectionStripLength] + ld [hConnectionStripLength], a + ld a, [NorthConnectedMapWidth] + ld [hConnectedMapWidth], a + call FillNorthConnectionStrip + +.South + ld a, [SouthConnectedMapGroup] + cp $ff + jr z, .West + ld b, a + ld a, [SouthConnectedMapNumber] + ld c, a + call GetAnyMapBlockdataBank + + ld a, [SouthConnectionStripPointer] + ld l, a + ld a, [SouthConnectionStripPointer + 1] + ld h, a + ld a, [SouthConnectionStripLocation] + ld e, a + ld a, [SouthConnectionStripLocation + 1] + ld d, a + ld a, [SouthConnectionStripLength] + ld [hConnectionStripLength], a + ld a, [SouthConnectedMapWidth] + ld [hConnectedMapWidth], a + call FillSouthConnectionStrip + +.West + ld a, [WestConnectedMapGroup] + cp $ff + jr z, .East + ld b, a + ld a, [WestConnectedMapNumber] + ld c, a + call GetAnyMapBlockdataBank + + ld a, [WestConnectionStripPointer] + ld l, a + ld a, [WestConnectionStripPointer + 1] + ld h, a + ld a, [WestConnectionStripLocation] + ld e, a + ld a, [WestConnectionStripLocation + 1] + ld d, a + ld a, [WestConnectionStripLength] + ld b, a + ld a, [WestConnectedMapWidth] + ld [hConnectionStripLength], a + call FillWestConnectionStrip + +.East + ld a, [EastConnectedMapGroup] + cp $ff + jr z, .Done + ld b, a + ld a, [EastConnectedMapNumber] + ld c, a + call GetAnyMapBlockdataBank + + ld a, [EastConnectionStripPointer] + ld l, a + ld a, [EastConnectionStripPointer + 1] + ld h, a + ld a, [EastConnectionStripLocation] + ld e, a + ld a, [EastConnectionStripLocation + 1] + ld d, a + ld a, [EastConnectionStripLength] + ld b, a + ld a, [EastConnectedMapWidth] + ld [hConnectionStripLength], a + call FillEastConnectionStrip + +.Done + ret +; 25d3 + + +FillNorthConnectionStrip: +FillSouthConnectionStrip: ; 25d3 + + ld c, 3 +.y + push de + + push hl + ld a, [hConnectionStripLength] + ld b, a +.x + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, .x + pop hl + + ld a, [hConnectedMapWidth] + ld e, a + ld d, 0 + add hl, de + pop de + + ld a, [$d19f] + add 6 + add e + ld e, a + jr nc, .asm_25f2 + inc d +.asm_25f2 + dec c + jr nz, .y + ret +; 25f6 + + +FillWestConnectionStrip: +FillEastConnectionStrip: ; 25f6 + +.asm_25f6 + ld a, [$d19f] + add 6 + ld [hConnectedMapWidth], a + + push de + + push hl + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + pop hl + + ld a, [hConnectionStripLength] + ld e, a + ld d, 0 + add hl, de + pop de + + ld a, [hConnectedMapWidth] + add e + ld e, a + jr nc, .asm_2617 + inc d +.asm_2617 + dec b + jr nz, .asm_25f6 + ret +; 261b + +Function261b: ; 261b + ld [$d432], a + ret +; 261f + + +CallScript: ; 261f +; Call a script at a:hl. + + ld [ScriptBank], a + ld a, l + ld [ScriptPos], a + ld a, h + ld [ScriptPos + 1], a + + ld a, $ff + ld [ScriptRunning], a + + scf + ret +; 2631 + +Function2631: ; 2631 + ld a, [ScriptRunning] + and a + ret nz + call GetMapEventBank + jr CallScript +; 263b + +Function263b: ; 263b + ld b, a + ld a, [hROMBank] + push af + call Function2c52 + call Function2653 + jr nc, .done + + call GetMapEventBank + ld b, a + ld d, h + ld e, l + call Function2674 + +.done + pop af + rst Bankswitch + ret +; 2653 + +Function2653: ; 2653 + ld a, [$dc0a] + ld c, a + and a + ret z + ld hl, $dc0b + ld a, [hli] + ld h, [hl] + ld l, a + or h + ret z + ld de, $0003 +.asm_2664 + ld a, [hl] + cp b + jr z, .asm_266e + add hl, de + dec c + jr nz, .asm_2664 + xor a + ret + +.asm_266e + inc hl + ld a, [hli] + ld h, [hl] + ld l, a + scf + ret +; 2674 + +Function2674: ; 2674 + callba Unknown_0x974f3 + ld a, [ScriptMode] + push af + ld hl, ScriptFlags + ld a, [hl] + push af + set 1, [hl] + callba Function96c56 + callba ScriptEvents + pop af + ld [ScriptFlags], a + pop af + ld [ScriptMode], a + ret +; 269a + +Function269a: ; 269a + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + + push hl + call SpeechTextBox + call Function2e31 + ld a, 1 + ld [hOAMUpdate], a + call Function321c + pop hl + call PrintTextBoxText + xor a + ld [hOAMUpdate], a + pop af + rst Bankswitch + + ret +; 26b7 + +Function26b7: ; 26b7 +; Call a:de. + + ld [hBuffer], a + ld a, [hROMBank] + push af + ld a, [hBuffer] + rst Bankswitch + + call .de + + pop af + rst Bankswitch + ret + +.de + push de + ret +; 26c7 + +Function26c7: ; 26c7 + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + + ld a, c + call Function19e9 + + pop hl + ld a, h + rst Bankswitch + ret +; 26d4 + + +GetScriptByte: ; 0x26d4 +; Return byte at ScriptBank:ScriptPos in a. + + push hl + push bc + ld a, [hROMBank] + push af + ld a, [ScriptBank] + rst Bankswitch + + ld hl, ScriptPos + ld c, [hl] + inc hl + ld b, [hl] + + ld a, [bc] + + inc bc + ld [hl], b + dec hl + ld [hl], c + + ld b, a + pop af + rst Bankswitch + ld a, b + pop bc + pop hl + ret +; 0x26ef + + +ObjectEvent: ; 0x26ef + jumptextfaceplayer ObjectEventText +; 0x26f2 + +ObjectEventText: + TX_FAR _ObjectEventText + db "@" +; 0x26f7 + + +BGEvent: ; 26f7 + jumptext BGEventText +; 26fa + +BGEventText: ; 26fa + text_jump UnknownText_0x1c46fc, BANK(UnknownText_0x1c46fc) + db "@" +; 26ff + + +CoordinatesEvent: ; 26ff + jumptext CoordinatesEventText +; 2702 + +CoordinatesEventText: ; 2702 + text_jump UnknownText_0x1c4706, BANK(UnknownText_0x1c4706) + db "@" +; 2707 + + +Function2707: ; 2707 + ld a, [hConnectionStripLength] + ld e, a + ld d, $0 + ld hl, $d81e + add hl, de + ld a, [hl] + ret +; 2712 + +Function2712: ; 2712 + ld a, [hConnectionStripLength] + ld e, a + ld d, $0 + ld hl, $d81e + add hl, de + ld [hl], $ff + ret +; 271e + +Function271e: ; 271e + ld a, [hConnectionStripLength] + ld e, a + ld d, $0 + ld hl, $d81e + add hl, de + ld [hl], $0 + ret +; 272a + + +Function272a: ; 272a + ld hl, TileMap + ld de, BGMapBuffer + call Function27b7 + ld c, $28 + call Functiondbd + ld a, [$d152] + ld e, a + ld a, [$d153] + ld d, a + call Function27d3 + ld a, $1 + ld [hBGMapUpdate], a + ret +; 2748 + +Function2748: ; 2748 + ld hl, $c5e0 + ld de, BGMapBuffer + call Function27b7 + ld c, $28 + call Functiondbd + ld a, [$d152] + ld l, a + ld a, [$d153] + ld h, a + ld bc, $0200 + add hl, bc + ld a, h + and $3 + or $98 + ld e, l + ld d, a + call Function27d3 + ld a, $1 + ld [hBGMapUpdate], a + ret +; 2771 + +Function2771: ; 2771 + ld hl, TileMap + ld de, BGMapBuffer + call Function27c0 + ld c, $24 + call Functiondbd + ld a, [$d152] + ld e, a + ld a, [$d153] + ld d, a + call Function27f8 + ld a, $1 + ld [hBGMapUpdate], a + ret +; 278f + +Function278f: ; 278f + ld hl, $c4b2 + ld de, BGMapBuffer + call Function27c0 + ld c, $24 + call Functiondbd + ld a, [$d152] + ld e, a + and $e0 + ld b, a + ld a, e + add $12 + and $1f + or b + ld e, a + ld a, [$d153] + ld d, a + call Function27f8 + ld a, $1 + ld [hBGMapUpdate], a + ret +; 27b7 + +Function27b7: ; 27b7 + ld c, $28 +.asm_27b9 + ld a, [hli] + ld [de], a + inc de + dec c + jr nz, .asm_27b9 + ret +; 27c0 + +Function27c0: ; 27c0 + ld c, $12 +.asm_27c2 + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + inc de + ld a, $13 + add l + ld l, a + jr nc, .asm_27cf + inc h + +.asm_27cf + dec c + jr nz, .asm_27c2 + ret +; 27d3 + +Function27d3: ; 27d3 + ld hl, BGMapBufferPtrs + push de + call .asm_27df + pop de + ld a, $20 + add e + ld e, a + +.asm_27df + ld c, $a +.asm_27e1 + ld a, e + ld [hli], a + ld a, d + ld [hli], a + ld a, e + inc a + inc a + and $1f + ld b, a + ld a, e + and $e0 + or b + ld e, a + dec c + jr nz, .asm_27e1 + ld a, $14 + ld [$ffdc], a + ret +; 27f8 + +Function27f8: ; 27f8 + ld hl, BGMapBufferPtrs + ld c, $12 +.asm_27fd + ld a, e + ld [hli], a + ld a, d + ld [hli], a + ld a, $20 + add e + ld e, a + jr nc, .asm_280e + inc d + ld a, d + and $3 + or $98 + ld d, a + +.asm_280e + dec c + jr nz, .asm_27fd + ld a, $12 + ld [$ffdc], a + ret +; 2816 + +Function2816: ; 2816 + ld hl, BGMapBuffer + ld bc, $0078 + xor a + call ByteFill + ret +; 2821 + +Function2821: ; 2821 + ld hl, TilesetAddress + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [TilesetBank] + ld e, a + ld a, [rSVBK] + push af + ld a, $6 + ld [rSVBK], a + ld a, e + ld de, $d000 + call FarDecompress + ld hl, $d000 + ld de, VTiles2 + ld bc, $0600 + call CopyBytes + ld a, [rVBK] + push af + ld a, $1 + ld [rVBK], a + ld hl, $d600 + ld de, VTiles2 + ld bc, $0600 + call CopyBytes + pop af + ld [rVBK], a + pop af + ld [rSVBK], a + ld a, [$d199] + cp $1 + jr z, .asm_286f + cp $2 + jr z, .asm_286f + cp $4 + jr z, .asm_286f + jr .asm_2875 + +.asm_286f + ld a, $7 + ld hl, $4000 + rst FarCall + +.asm_2875 + xor a + ld [hTileAnimFrame], a + ret +; 2879 + +Function2879: ; 2879 + ld hl, $d194 + ld a, [hli] + ld h, [hl] + ld l, a + ld de, $dcb9 + ld c, $5 + ld b, $6 +.asm_2886 + push bc + push hl +.asm_2888 + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, .asm_2888 + pop hl + ld a, [$d19f] + add $6 + ld c, a + ld b, $0 + add hl, bc + pop bc + dec c + jr nz, .asm_2886 + ret +; 289d + +Function289d: ; 289d + ld hl, $d194 + ld a, [hli] + ld h, [hl] + ld l, a + ld de, $dcb9 + ld a, [$d19f] + add $6 + ld [hConnectionStripLength], a + ld a, [$d151] + and a + jr z, .asm_28cb + cp $1 + jr z, .asm_28c0 + cp $2 + jr z, .asm_28d4 + cp $3 + jr z, .asm_28da + ret + +.asm_28c0 + ld de, $dcbf + ld a, [hConnectionStripLength] + ld c, a + ld b, $0 + add hl, bc + jr .asm_28ce + +.asm_28cb + ld de, $dcb9 + +.asm_28ce + ld b, $6 + ld c, $4 + jr .asm_28f7 + +.asm_28d4 + ld de, $dcba + inc hl + jr .asm_28dd + +.asm_28da + ld de, $dcb9 + +.asm_28dd + ld b, $5 + ld c, $5 + jr .asm_28f7 + + ld hl, $d194 + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [$d19f] + add $6 + ld [hConnectionStripLength], a + ld de, $dcb9 + ld b, $6 + ld c, $5 + +.asm_28f7 + push bc + push hl + push de +.asm_28fa + ld a, [de] + inc de + ld [hli], a + dec b + jr nz, .asm_28fa + pop de + ld a, e + add $6 + ld e, a + jr nc, .asm_2908 + inc d + +.asm_2908 + pop hl + ld a, [hConnectionStripLength] + ld c, a + ld b, $0 + add hl, bc + pop bc + dec c + jr nz, .asm_28f7 + ret +; 2914 + +Function2914: ; 2914 + xor a + ld [TilePermissions], a + call Function296c + call Function294d + ld a, [MapX] + ld d, a + ld a, [MapY] + ld e, a + call Function2a3c + ld [StandingTile], a + call Function29ff + ret nz + ld a, [StandingTile] + and 7 + ld hl, .data_2945 + add l + ld l, a + ld a, 0 + adc h + ld h, a + ld a, [hl] + ld hl, TilePermissions + or [hl] + ld [hl], a + ret +; 2945 + +.data_2945 ; 2945 + db 1, 2, 4, 8, 9, 10, 5, 6 +; 294d + +Function294d: ; 294d + ld a, [MapX] + ld d, a + ld a, [MapY] + ld e, a + push de + inc e + call Function2a3c + ld [TileDown], a + call Function298b + pop de + dec e + call Function2a3c + ld [TileUp], a + call Function29a8 + ret +; 296c + +Function296c: ; 296c + ld a, [MapX] + ld d, a + ld a, [MapY] + ld e, a + push de + dec d + call Function2a3c + ld [TileLeft], a + call Function29e2 + pop de + inc d + call Function2a3c + ld [TileRight], a + call Function29c5 + ret +; 298b + +Function298b: ; 298b + call Function29ff + ret nz + ld a, [TileDown] + and $7 + cp $2 + jr z, .asm_299f + cp $6 + jr z, .asm_299f + cp $7 + ret nz + +.asm_299f + ld a, [TilePermissions] + or $8 + ld [TilePermissions], a + ret +; 29a8 + +Function29a8: ; 29a8 + call Function29ff + ret nz + ld a, [TileUp] + and $7 + cp $3 + jr z, .asm_29bc + cp $4 + jr z, .asm_29bc + cp $5 + ret nz + +.asm_29bc + ld a, [TilePermissions] + or $4 + ld [TilePermissions], a + ret +; 29c5 + +Function29c5: ; 29c5 + call Function29ff + ret nz + ld a, [TileRight] + and $7 + cp $1 + jr z, .asm_29d9 + cp $5 + jr z, .asm_29d9 + cp $7 + ret nz + +.asm_29d9 + ld a, [TilePermissions] + or $1 + ld [TilePermissions], a + ret +; 29e2 + +Function29e2: ; 29e2 + call Function29ff + ret nz + ld a, [TileLeft] + and $7 + cp $0 + jr z, .asm_29f6 + cp $4 + jr z, .asm_29f6 + cp $6 + ret nz + +.asm_29f6 + ld a, [TilePermissions] + or $2 + ld [TilePermissions], a + ret +; 29ff + +Function29ff: ; 29ff + and $f0 + cp $b0 + ret z + cp $c0 + ret +; 2a07 + + +GetFacingTileCoord: ; 2a07 +; Return map coordinates in (d, e) and tile id in a +; of the tile the player is facing. + + ld a, [PlayerDirection] + and %1100 + srl a + srl a + ld l, a + ld h, 0 + add hl, hl + add hl, hl + ld de, .Directions + add hl, de + + ld d, [hl] + inc hl + ld e, [hl] + inc hl + + ld a, [hli] + ld h, [hl] + ld l, a + + ld a, [MapX] + add d + ld d, a + ld a, [MapY] + add e + ld e, a + ld a, [hl] + ret + +.Directions + ; x, y + db 0, 1 + dw TileDown + db 0, -1 + dw TileUp + db -1, 0 + dw TileLeft + db 1, 0 + dw TileRight +; 2a3c + + +Function2a3c: ; 2a3c + call Function2a66 + ld a, [hl] + and a + jr z, .asm_2a63 + ld l, a + ld h, $0 + add hl, hl + add hl, hl + ld a, [TilesetCollisionAddress] + ld c, a + ld a, [$d1e1] + ld b, a + add hl, bc + rr d + jr nc, .asm_2a56 + inc hl + +.asm_2a56 + rr e + jr nc, .asm_2a5c + inc hl + inc hl + +.asm_2a5c + ld a, [TilesetCollisionBank] + call GetFarByte + ret + +.asm_2a63 + ld a, $ff + ret +; 2a66 + +Function2a66: ; 2a66 + ld a, [$d19f] + add $6 + ld c, a + ld b, $0 + ld hl, $c801 + add hl, bc + ld a, e + srl a + jr z, .asm_2a84 + and a +.asm_2a78 + srl a + jr nc, .asm_2a7d + add hl, bc + +.asm_2a7d + sla c + rl b + and a + jr nz, .asm_2a78 + +.asm_2a84 + ld c, d + srl c + ld b, $0 + add hl, bc + ret +; 2a8b + + +CheckFacingSign: ; 2a8b + call GetFacingTileCoord + ld b, a + ld a, d + sub 4 + ld d, a + ld a, e + sub 4 + ld e, a + ld a, [$dc01] + and a + ret z + ld c, a + ld a, [hROMBank] + push af + call Function2c52 + call Function2aaa + pop hl + ld a, h + rst Bankswitch + ret +; 2aaa + +Function2aaa: ; 2aaa + ld hl, $dc02 + ld a, [hli] + ld h, [hl] + ld l, a +.asm_2ab0 + push hl + ld a, [hli] + cp e + jr nz, .asm_2abb + ld a, [hli] + cp d + jr nz, .asm_2abb + jr .asm_2ac8 + +.asm_2abb + pop hl + ld a, 5 + add l + ld l, a + jr nc, .asm_2ac3 + inc h + +.asm_2ac3 + dec c + jr nz, .asm_2ab0 + xor a + ret + +.asm_2ac8 + pop hl + ld de, EngineBuffer1 + ld bc, 5 + call CopyBytes + scf + ret +; 2ad4 + +Function2ad4: ; 2ad4 + ld a, [$dbfe] + and a + ret z + ld c, a + ld a, [hROMBank] + push af + call Function2c52 + call Function2ae7 + pop hl + ld a, h + rst Bankswitch + ret +; 2ae7 + +Function2ae7: ; 2ae7 + ld hl, $dbff + ld a, [hli] + ld h, [hl] + ld l, a + call Function211b + ld b, a + ld a, [MapX] + sub $4 + ld d, a + ld a, [MapY] + sub $4 + ld e, a +.asm_2afd + push hl + ld a, [hli] + cp b + jr z, .asm_2b06 + cp $ff + jr nz, .asm_2b10 + +.asm_2b06 + ld a, [hli] + cp e + jr nz, .asm_2b10 + ld a, [hli] + cp d + jr nz, .asm_2b10 + jr .asm_2b1d + +.asm_2b10 + pop hl + ld a, $8 + add l + ld l, a + jr nc, .asm_2b18 + inc h + +.asm_2b18 + dec c + jr nz, .asm_2afd + xor a + ret + +.asm_2b1d + pop hl + ld de, EngineBuffer1 + ld bc, $0008 + call CopyBytes + scf + ret +; 2b29 + + +FadeToMenu: ; 2b29 + xor a + ld [hBGMapMode], a + call Function1d6e + ld a, $23 + ld hl, $4084 + rst FarCall + call ClearSprites + call Function2ed3 + ret +; 2b3c + + +Function2b3c: ; 2b3c + call WhiteBGMap + call Function2bae + call Function1ad2 + call Function1d7d + call Functiond90 + jr Function2b5c +; 2b4d + +Function2b4d: ; 2b4d + call WhiteBGMap + call Function1d7d + call Function2bae + call Function1ad2 + call Functiond90 +; 2b5c + +Function2b5c: ; 2b5c + ld b, $9 + call GetSGBLayout + ld a, $12 + ld hl, $5409 + rst FarCall + call Function3200 + ld a, $23 + ld hl, $4079 + rst FarCall + call Function2ee4 + ret +; 2b74 + + +Function2b74: ; 0x2b74 + push af + ld a, $1 + ld [$c2ce], a + call WhiteBGMap + call ClearSprites + call Function2bae + ld hl, $c590 ; tile 0, 12 + ld bc, $0412 + call TextBox + ld hl, VramState + set 0, [hl] + call Function1ad2 + call Function3200 + ld b, $9 + call GetSGBLayout + callba Function49409 + call UpdateTimePals + call DelayFrame + ld a, $1 + ld [$ffde], a + pop af + ret +; 0x2bae + +Function2bae: ; 2bae + call DisableLCD + call ClearSprites + ld a, $5 + ld hl, $4168 + rst FarCall + call Functione51 + call Functione5f + ld a, [hROMBank] + push af + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a + call Function2c24 + ld a, $23 + ld hl, $4001 + rst FarCall + call Function2173 + call Function2821 + ld a, $9 + call Function3cb4 + pop af + rst Bankswitch + + call EnableLCD + ret +; 2be5 + + +GetMapHeaderPointer: ; 2be5 + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a +; 2bed + +GetAnyMapHeaderPointer: ; 0x2bed +; Prior to calling this function, you must have switched banks so that +; MapGroupPointers is visible. + +; inputs: +; b = map group, c = map number +; XXX de = ??? + +; outputs: +; hl points to the map header + push bc ; save map number for later + + ; get pointer to map group + dec b + ld c, b + ld b, $0 + ld hl, MapGroupPointers + add hl, bc + add hl, bc + + ld a, [hli] + ld h, [hl] + ld l, a + pop bc ; restore map number + + ; find the cth map header + dec c + ld b, $0 + ld a, OlivineGym_MapHeader - OlivinePokeCenter1F_MapHeader + call AddNTimes + ret +; 0x2c04 + +GetMapHeaderMember: ; 0x2c04 +; Extract data from the current map's header. + +; inputs: +; de = offset of desired data within the mapheader + +; outputs: +; bc = data from the current map's header +; (e.g., de = $0003 would return a pointer to the secondary map header) + + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a + ; fallthrough + +GetAnyMapHeaderMember: ; 0x2c0c + ; bankswitch + ld a, [hROMBank] + push af + ld a, BANK(MapGroupPointers) + rst Bankswitch + + call GetAnyMapHeaderPointer + add hl, de + ld c, [hl] + inc hl + ld b, [hl] + + ; bankswitch back + pop af + rst Bankswitch + ret +; 0x2c1c + + +Function2c1c: ; 2c1c + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a +; 2c24 + +Function2c24: ; 2c24 + call Function2c31 + rst Bankswitch + ret +; 2c29 + + +Function2c29: ; 2c29 + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a +; 2c31 + +Function2c31: ; 2c31 + push hl + push de + ld de, $0000 + call GetAnyMapHeaderMember + ld a, c + pop de + pop hl + ret +; 2c3d + +Function2c3d: ; 2c3d + ld a, [hROMBank] + push af + ld a, $25 + rst Bankswitch + call GetMapHeaderPointer + ld de, $d198 + ld bc, $0005 + call CopyBytes + pop af + rst Bankswitch + ret +; 2c52 + +Function2c52: ; 2c52 + ld a, [MapEventBank] + rst Bankswitch + ret +; 2c57 + + +GetMapEventBank: ; 2c57 + ld a, [MapEventBank] + ret +; 2c5b + +GetAnyMapBlockdataBank: ; 2c5b +; Return the blockdata bank for group b map c. + push hl + push de + push bc + + push bc + ld de, 3 ; second map header pointer + call GetAnyMapHeaderMember + ld l, c + ld h, b + pop bc + + push hl + ld de, 0 ; second map header bank + call GetAnyMapHeaderMember + pop hl + + ld de, 3 ; blockdata bank + add hl, de + ld a, c + call GetFarByte + rst Bankswitch + + pop bc + pop de + pop hl + ret +; 2c7d + +GetSecondaryMapHeaderPointer: ; 0x2c7d +; returns the current map's secondary map header pointer in hl. + push bc + push de + ld de, $0003 ; secondary map header pointer (offset within header) + call GetMapHeaderMember + ld l, c + ld h, b + pop de + pop bc + ret +; 2c8a + +GetMapPermission: ; 2c8a + push hl + push de + push bc + ld de, 2 + call GetMapHeaderMember + ld a, c + pop bc + pop de + pop hl + ret +; 2c98 + +Function2c98: ; 2c98 + ret +; 2c99 + +Function2c99: ; 2c99 + push hl + push de + push bc + ld de, $0002 + call GetAnyMapHeaderMember + ld a, c + pop bc + pop de + pop hl + ret +; 2ca7 + +Function2ca7: ; 2ca7 + ld de, $0001 + call GetAnyMapHeaderMember + ld a, c + ret +; 2caf + +GetWorldMapLocation: ; 0x2caf +; given a map group/id in bc, return its location on the Pokégear map. + push hl + push de + push bc + ld de, 5 + call GetAnyMapHeaderMember + ld a, c + pop bc + pop de + pop hl + ret +; 0x2cbd + +Function2cbd: ; 2cbd + push hl + push bc + ld de, $0006 + call GetMapHeaderMember + ld a, c + cp $64 + jr z, .asm_2cee + bit 7, c + jr nz, .asm_2cda + ld a, $22 + ld hl, $7342 + rst FarCall + ld e, c + ld d, $0 +.asm_2cd7 + pop bc + pop hl + ret + +.asm_2cda + ld a, [StatusFlags2] + bit 0, a + jr z, .asm_2ce6 + ld de, $0056 + jr .asm_2cd7 + +.asm_2ce6 + ld a, c + and $7f + ld e, a + ld d, $0 + jr .asm_2cd7 + +.asm_2cee + ld a, [StatusFlags2] + bit 7, a + jr z, .asm_2cfa + ld de, $0048 + jr .asm_2cd7 + +.asm_2cfa + ld de, $0026 + jr .asm_2cd7 +; 2cff + +Function2cff: ; 2cff + call Function2d0d + and $f + ret +; 2d05 + +Function2d05: ; 2d05 + call Function2d0d + and $f0 + swap a + ret +; 2d0d + +Function2d0d: ; 2d0d + push hl + push bc + ld de, $0007 + call GetMapHeaderMember + ld a, c + pop bc + pop hl + ret +; 2d19 + +Function2d19: ; 2d19 + push de + push hl + push bc + ld de, $0008 + call GetMapHeaderMember + ld a, c + pop bc + pop hl + pop de + ret +; 2d27 + +Function2d27: ; 2d27 + push hl + push bc + ld hl, $5596 + ld bc, $000f + ld a, [$d199] + call AddNTimes + ld de, TilesetBank + ld bc, $000f + ld a, $13 + call FarCopyBytes + pop bc + pop hl + ret +; 2d43 + diff --git a/main.asm b/main.asm index e5f9675d7..f53f5d4bf 100644 --- a/main.asm +++ b/main.asm @@ -517,2373 +517,8 @@ AskSerial: ; 2063 INCLUDE "common/game_time.asm" +INCLUDE "common/map.asm" -Function210f: ; 210f - ld hl, $c7e8 - ld bc, $0018 - ld a, $0 - call ByteFill - ret -; 211b - -Function211b: ; 211b - push hl - ld hl, $dbf7 - ld a, [hli] - ld h, [hl] - ld l, a - or h - ld a, [hl] - jr nz, .asm_2128 - ld a, $ff - -.asm_2128 - pop hl - ret -; 212a - -Function212a: ; 212a - ld a, [MapGroup] - ld b, a - ld a, [MapNumber] - ld c, a - xor a - ld [$dbf7], a - ld [$dbf8], a - call Function2147 - ret c - ld a, e - ld [$dbf7], a - ld a, d - ld [$dbf8], a - xor a - ret -; 2147 - -Function2147: ; 2147 - push bc - ld a, [hROMBank] - push af - ld a, $13 - rst Bankswitch - - ld hl, $501e -.asm_2151 - push hl - ld a, [hli] - cp $ff - jr z, .asm_2167 - cp b - jr nz, .asm_2160 - ld a, [hli] - cp c - jr nz, .asm_2160 - jr .asm_216a - -.asm_2160 - pop hl - ld de, $0004 - add hl, de - jr .asm_2151 - -.asm_2167 - scf - jr .asm_216d - -.asm_216a - ld e, [hl] - inc hl - ld d, [hl] - -.asm_216d - pop hl - pop bc - ld a, b - rst Bankswitch - - pop bc - ret -; 2173 - -Function2173: ; 2173 - call Function217a - call Functiondb1 - ret -; 217a - -Function217a: ; 217a - ld a, [hROMBank] - push af - ld a, [TilesetBlocksBank] - rst Bankswitch - - call Function2198 - ld a, $60 - ld hl, TileMap - ld bc, $0168 - call ByteFill - ld a, $13 - rst Bankswitch - - call $515b - pop af - rst Bankswitch - - ret -; 2198 - -Function2198: ; 2198 - ld a, [$d194] - ld e, a - ld a, [$d195] - ld d, a - ld hl, EnemyMoveAnimation - ld b, $5 - -.asm_21a5 - push de - push hl - ld c, $6 - -.asm_21a9 - push de - push hl - ld a, [de] - and a - jr nz, .asm_21b2 - ld a, [$d19d] - -.asm_21b2 - ld e, l - ld d, h - add a - ld l, a - ld h, $0 - add hl, hl - add hl, hl - add hl, hl - ld a, [TilesetBlocksAddress] - add l - ld l, a - ld a, [TilesetBlocksAddress + 1] - adc h - ld h, a - -rept 3 - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - - ld a, e - add 20 - ld e, a - jr nc, .next\@ - inc d -.next\@ -endr - - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - - pop hl - ld de, $0004 - add hl, de - pop de - inc de - dec c - jp nz, .asm_21a9 - pop hl - ld de, $0060 - add hl, de - pop de - ld a, [$d19f] - add $6 - add e - ld e, a - jr nc, .asm_2225 - inc d - -.asm_2225 - dec b - jp nz, .asm_21a5 - ret -; 222a - -Function222a: ; 222a - ld a, $fa - ld [$ff9f], a - callba Function15363 - xor a - ld [$ff9f], a - ret -; 2238 - -Function2238: ; 2238 - call Function2252 - ret nc - push bc - callba Function149af - pop bc - ret nc - call Function22a7 - scf - ret -; 224a - - - -Function224a: ; 224a - call Function2252 - ret nc - call Function22a7 - ret -; 2252 - -Function2252: ; 2252 - callba Function1499a - ret nc - - ld a, [hROMBank] - push af - - call Function2c52 - call Function2266 - - pop de - ld a, d - rst Bankswitch - ret -; 2266 - -Function2266: ; 2266 - ld a, [MapY] - sub $4 - ld e, a - ld a, [MapX] - sub $4 - ld d, a - ld a, [$dbfb] - and a - ret z - ld c, a - ld hl, $dbfc - ld a, [hli] - ld h, [hl] - ld l, a -.asm_227e - push hl - ld a, [hli] - cp e - jr nz, .asm_2289 - ld a, [hli] - cp d - jr nz, .asm_2289 - jr .asm_2296 - -.asm_2289 - pop hl - ld a, $5 - add l - ld l, a - jr nc, .asm_2291 - inc h - -.asm_2291 - dec c - jr nz, .asm_227e - xor a - ret - -.asm_2296 - pop hl - call Function22a3 - ret nc - ld a, [$dbfb] - inc a - sub c - ld c, a - scf - ret -; 22a3 - -Function22a3: ; 22a3 - inc hl - inc hl - scf - ret -; 22a7 - -Function22a7: ; 22a7 - ld a, [hROMBank] - push af - - call Function2c52 - call Function22b4 - - pop af - rst Bankswitch - scf - ret -; 22b4 - -Function22b4: ; 22b4 - push bc - ld hl, $dbfc - ld a, [hli] - ld h, [hl] - ld l, a - ld a, c - dec a - ld bc, $0005 - call AddNTimes - ld bc, $0002 - add hl, bc - ld a, [hli] - cp $ff - jr nz, .asm_22d0 - ld hl, $dcac - ld a, [hli] - -.asm_22d0 - pop bc - ld [$d146], a - ld a, [hli] - ld [$d147], a - ld a, [hli] - ld [$d148], a - ld a, c - ld [$d149], a - ld a, [MapGroup] - ld [$d14a], a - ld a, [MapNumber] - ld [$d14b], a - scf - ret -; 22ee - - - -CheckOutdoorMap: ; 22ee - cp ROUTE - ret z - cp TOWN - ret -; 22f4 - -CheckIndoorMap: ; 22f4 - cp INDOOR - ret z - cp CAVE - ret z - cp DUNGEON - ret z - cp GATE - ret -; 2300 - -Function2300: ; 2300 - cp INDOOR - ret z - cp GATE - ret z - cp $5 - ret -; 2309 - - -Function2309: ; 2309 - call Function2326 - call Function2c52 - call Function234f - xor a - call Function2336 - ret -; 2317 - -Function2317: ; 2317 - call Function2326 - call Function2c52 - call Function234f - ld a, $1 - call Function2336 - ret -; 2326 - -Function2326: ; 2326 - call Function2c3d - call Function2c1c - call GetSecondaryMapHeaderPointer - call Function235c - call Function2368 - ret -; 2336 - -Function2336: ; 2336 - push af - ld hl, $d1a6 - ld a, [hli] - ld h, [hl] - ld l, a - inc hl - inc hl - call Function23da - call Function23f1 - call Function2408 - pop af - and a - ret nz - call Function241f - ret -; 234f - -Function234f: ; 234f - ld hl, $d1a4 - ld a, [hli] - ld h, [hl] - ld l, a - call Function23ac - call Function23c3 - ret -; 235c - -Function235c: ; 235c - ld de, $d19d - ld c, $c -.asm_2361 - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, .asm_2361 - ret -; 2368 - -Function2368: ; 2368 - ld a, $ff - ld [NorthConnectedMapGroup], a - ld [SouthConnectedMapGroup], a - ld [WestConnectedMapGroup], a - ld [EastConnectedMapGroup], a - - ld a, [$d1a8] - ld b, a - - bit 3, b - jr z, .asm_2384 - ld de, NorthMapConnection - call GetMapConnection - -.asm_2384 - bit 2, b - jr z, .asm_238e - ld de, SouthMapConnection - call GetMapConnection - -.asm_238e - bit 1, b - jr z, .asm_2398 - ld de, WestMapConnection - call GetMapConnection - -.asm_2398 - bit 0, b - jr z, .asm_23a2 - ld de, EastMapConnection - call GetMapConnection - -.asm_23a2 - ret -; 23a3 - - -GetMapConnection: ; 23a3 -; Load map connection struct at hl into de. - ld c, SouthMapConnection - NorthMapConnection -.loop - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, .loop - ret -; 23ac - - -Function23ac: ; 23ac - ld a, [hli] - ld c, a - ld [$dc07], a - ld a, l - ld [$dc08], a - ld a, h - ld [$dc09], a - ld a, c - and a - ret z - ld bc, $0004 - call AddNTimes - ret -; 23c3 - -Function23c3: ; 23c3 - ld a, [hli] - ld c, a - ld [$dc0a], a - ld a, l - ld [$dc0b], a - ld a, h - ld [$dc0c], a - ld a, c - and a - ret z - ld bc, $0003 - call AddNTimes - ret -; 23da - -Function23da: ; 23da - ld a, [hli] - ld c, a - ld [$dbfb], a - ld a, l - ld [$dbfc], a - ld a, h - ld [$dbfd], a - ld a, c - and a - ret z - ld bc, $0005 - call AddNTimes - ret -; 23f1 - -Function23f1: ; 23f1 - ld a, [hli] - ld c, a - ld [$dbfe], a - ld a, l - ld [$dbff], a - ld a, h - ld [$dc00], a - ld a, c - and a - ret z - ld bc, $0008 - call AddNTimes - ret -; 2408 - -Function2408: ; 2408 - ld a, [hli] - ld c, a - ld [$dc01], a - ld a, l - ld [$dc02], a - ld a, h - ld [$dc03], a - ld a, c - and a - ret z - ld bc, $0005 - call AddNTimes - ret -; 241f - -Function241f: ; 241f - push hl - call Function2471 - pop de - ld hl, $d72e - ld a, [de] - inc de - ld [$dc04], a - ld a, e - ld [$dc05], a - ld a, d - ld [$dc06], a - ld a, [$dc04] - call Function2457 - ld a, [$dc04] - ld c, a - ld a, $10 - sub c - jr z, .asm_2454 - ld bc, $0001 - add hl, bc - ld bc, $0010 -.asm_244a - ld [hl], $0 - inc hl - ld [hl], $ff - dec hl - add hl, bc - dec a - jr nz, .asm_244a - -.asm_2454 - ld h, d - ld l, e - ret -; 2457 - -Function2457: ; 2457 - and a - ret z - ld c, a -.asm_245a - push bc - push hl - ld a, $ff - ld [hli], a - ld b, $d -.asm_2461 - ld a, [de] - inc de - ld [hli], a - dec b - jr nz, .asm_2461 - pop hl - ld bc, $0010 - add hl, bc - pop bc - dec c - jr nz, .asm_245a - ret -; 2471 - -Function2471: ; 2471 - ld hl, $d4fe - ld bc, $01e0 - xor a - call ByteFill - ld hl, $d4fe - ld de, $0028 - ld c, $c - xor a -.asm_2484 - ld [hl], a - add hl, de - dec c - jr nz, .asm_2484 - ret -; 248a - -Function248a: ; 248a - call GetMapEventBank - rst Bankswitch - - ld hl, $d1a6 - ld a, [hli] - ld h, [hl] - ld l, a - inc hl - inc hl - inc hl - ld a, [WarpNumber] - dec a - ld c, a - ld b, $0 - ld a, $5 - call AddNTimes - ld a, [hli] - ld [YCoord], a - ld a, [hli] - ld [XCoord], a - ld a, [hli] - cp $ff - jr nz, .asm_24b3 - call Function24ba - -.asm_24b3 - ld a, $41 - ld hl, $486d - rst FarCall - ret -; 24ba - -Function24ba: ; 24ba - ld a, [$d149] - ld [$dcac], a - ld a, [$d14a] - ld [BackupMapGroup], a - ld a, [$d14b] - ld [BackupMapNumber], a - ret -; 24cd - -Function24cd: ; 24cd - ld hl, OverworldMap - ld bc, $0514 - ld a, $0 - call ByteFill - call Function24e4 - call FillMapConnections - ld a, $1 - call Function263b - ret -; 24e4 - - - -Function24e4: ; 24e4 - ld a, [hROMBank] - push af - ld hl, OverworldMap - ld a, [$d19f] - ld [hConnectedMapWidth], a - add $6 - ld [hConnectionStripLength], a - ld c, a - ld b, $0 - add hl, bc - add hl, bc - add hl, bc - ld c, $3 - add hl, bc - ld a, [$d1a0] - rst Bankswitch - - ld a, [$d1a1] - ld e, a - ld a, [$d1a2] - ld d, a - ld a, [$d19e] - ld b, a -.asm_250c - push hl - ld a, [hConnectedMapWidth] - ld c, a -.asm_2510 - ld a, [de] - inc de - ld [hli], a - dec c - jr nz, .asm_2510 - pop hl - ld a, [hConnectionStripLength] - add l - ld l, a - jr nc, .asm_251e - inc h - -.asm_251e - dec b - jr nz, .asm_250c - pop af - rst Bankswitch - - ret -; 2524 - - - -FillMapConnections: ; 2524 - -; North - ld a, [NorthConnectedMapGroup] - cp $ff - jr z, .South - ld b, a - ld a, [NorthConnectedMapNumber] - ld c, a - call GetAnyMapBlockdataBank - - ld a, [NorthConnectionStripPointer] - ld l, a - ld a, [NorthConnectionStripPointer + 1] - ld h, a - ld a, [NorthConnectionStripLocation] - ld e, a - ld a, [NorthConnectionStripLocation + 1] - ld d, a - ld a, [NorthConnectionStripLength] - ld [hConnectionStripLength], a - ld a, [NorthConnectedMapWidth] - ld [hConnectedMapWidth], a - call FillNorthConnectionStrip - -.South - ld a, [SouthConnectedMapGroup] - cp $ff - jr z, .West - ld b, a - ld a, [SouthConnectedMapNumber] - ld c, a - call GetAnyMapBlockdataBank - - ld a, [SouthConnectionStripPointer] - ld l, a - ld a, [SouthConnectionStripPointer + 1] - ld h, a - ld a, [SouthConnectionStripLocation] - ld e, a - ld a, [SouthConnectionStripLocation + 1] - ld d, a - ld a, [SouthConnectionStripLength] - ld [hConnectionStripLength], a - ld a, [SouthConnectedMapWidth] - ld [hConnectedMapWidth], a - call FillSouthConnectionStrip - -.West - ld a, [WestConnectedMapGroup] - cp $ff - jr z, .East - ld b, a - ld a, [WestConnectedMapNumber] - ld c, a - call GetAnyMapBlockdataBank - - ld a, [WestConnectionStripPointer] - ld l, a - ld a, [WestConnectionStripPointer + 1] - ld h, a - ld a, [WestConnectionStripLocation] - ld e, a - ld a, [WestConnectionStripLocation + 1] - ld d, a - ld a, [WestConnectionStripLength] - ld b, a - ld a, [WestConnectedMapWidth] - ld [hConnectionStripLength], a - call FillWestConnectionStrip - -.East - ld a, [EastConnectedMapGroup] - cp $ff - jr z, .Done - ld b, a - ld a, [EastConnectedMapNumber] - ld c, a - call GetAnyMapBlockdataBank - - ld a, [EastConnectionStripPointer] - ld l, a - ld a, [EastConnectionStripPointer + 1] - ld h, a - ld a, [EastConnectionStripLocation] - ld e, a - ld a, [EastConnectionStripLocation + 1] - ld d, a - ld a, [EastConnectionStripLength] - ld b, a - ld a, [EastConnectedMapWidth] - ld [hConnectionStripLength], a - call FillEastConnectionStrip - -.Done - ret -; 25d3 - - -FillNorthConnectionStrip: -FillSouthConnectionStrip: ; 25d3 - - ld c, 3 -.y - push de - - push hl - ld a, [hConnectionStripLength] - ld b, a -.x - ld a, [hli] - ld [de], a - inc de - dec b - jr nz, .x - pop hl - - ld a, [hConnectedMapWidth] - ld e, a - ld d, 0 - add hl, de - pop de - - ld a, [$d19f] - add 6 - add e - ld e, a - jr nc, .asm_25f2 - inc d -.asm_25f2 - dec c - jr nz, .y - ret -; 25f6 - - -FillWestConnectionStrip: -FillEastConnectionStrip: ; 25f6 - -.asm_25f6 - ld a, [$d19f] - add 6 - ld [hConnectedMapWidth], a - - push de - - push hl - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - ld a, [hli] - ld [de], a - inc de - pop hl - - ld a, [hConnectionStripLength] - ld e, a - ld d, 0 - add hl, de - pop de - - ld a, [hConnectedMapWidth] - add e - ld e, a - jr nc, .asm_2617 - inc d -.asm_2617 - dec b - jr nz, .asm_25f6 - ret -; 261b - -Function261b: ; 261b - ld [$d432], a - ret -; 261f - - -CallScript: ; 261f -; Call a script at a:hl. - - ld [ScriptBank], a - ld a, l - ld [ScriptPos], a - ld a, h - ld [ScriptPos + 1], a - - ld a, $ff - ld [ScriptRunning], a - - scf - ret -; 2631 - -Function2631: ; 2631 - ld a, [ScriptRunning] - and a - ret nz - call GetMapEventBank - jr CallScript -; 263b - -Function263b: ; 263b - ld b, a - ld a, [hROMBank] - push af - call Function2c52 - call Function2653 - jr nc, .done - - call GetMapEventBank - ld b, a - ld d, h - ld e, l - call Function2674 - -.done - pop af - rst Bankswitch - ret -; 2653 - -Function2653: ; 2653 - ld a, [$dc0a] - ld c, a - and a - ret z - ld hl, $dc0b - ld a, [hli] - ld h, [hl] - ld l, a - or h - ret z - ld de, $0003 -.asm_2664 - ld a, [hl] - cp b - jr z, .asm_266e - add hl, de - dec c - jr nz, .asm_2664 - xor a - ret - -.asm_266e - inc hl - ld a, [hli] - ld h, [hl] - ld l, a - scf - ret -; 2674 - -Function2674: ; 2674 - callba Unknown_0x974f3 - ld a, [ScriptMode] - push af - ld hl, ScriptFlags - ld a, [hl] - push af - set 1, [hl] - callba Function96c56 - callba ScriptEvents - pop af - ld [ScriptFlags], a - pop af - ld [ScriptMode], a - ret -; 269a - -Function269a: ; 269a - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - - push hl - call SpeechTextBox - call Function2e31 - ld a, 1 - ld [hOAMUpdate], a - call Function321c - pop hl - call PrintTextBoxText - xor a - ld [hOAMUpdate], a - pop af - rst Bankswitch - - ret -; 26b7 - -Function26b7: ; 26b7 -; Call a:de. - - ld [hBuffer], a - ld a, [hROMBank] - push af - ld a, [hBuffer] - rst Bankswitch - - call .de - - pop af - rst Bankswitch - ret - -.de - push de - ret -; 26c7 - -Function26c7: ; 26c7 - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - - ld a, c - call Function19e9 - - pop hl - ld a, h - rst Bankswitch - ret -; 26d4 - - -GetScriptByte: ; 0x26d4 -; Return byte at ScriptBank:ScriptPos in a. - - push hl - push bc - ld a, [hROMBank] - push af - ld a, [ScriptBank] - rst Bankswitch - - ld hl, ScriptPos - ld c, [hl] - inc hl - ld b, [hl] - - ld a, [bc] - - inc bc - ld [hl], b - dec hl - ld [hl], c - - ld b, a - pop af - rst Bankswitch - ld a, b - pop bc - pop hl - ret -; 0x26ef - - -ObjectEvent: ; 0x26ef - jumptextfaceplayer ObjectEventText -; 0x26f2 - -ObjectEventText: - TX_FAR _ObjectEventText - db "@" -; 0x26f7 - - -BGEvent: ; 26f7 - jumptext BGEventText -; 26fa - -BGEventText: ; 26fa - text_jump UnknownText_0x1c46fc, BANK(UnknownText_0x1c46fc) - db "@" -; 26ff - - -CoordinatesEvent: ; 26ff - jumptext CoordinatesEventText -; 2702 - -CoordinatesEventText: ; 2702 - text_jump UnknownText_0x1c4706, BANK(UnknownText_0x1c4706) - db "@" -; 2707 - - -Function2707: ; 2707 - ld a, [hConnectionStripLength] - ld e, a - ld d, $0 - ld hl, $d81e - add hl, de - ld a, [hl] - ret -; 2712 - -Function2712: ; 2712 - ld a, [hConnectionStripLength] - ld e, a - ld d, $0 - ld hl, $d81e - add hl, de - ld [hl], $ff - ret -; 271e - -Function271e: ; 271e - ld a, [hConnectionStripLength] - ld e, a - ld d, $0 - ld hl, $d81e - add hl, de - ld [hl], $0 - ret -; 272a - - -Function272a: ; 272a - ld hl, TileMap - ld de, BGMapBuffer - call Function27b7 - ld c, $28 - call Functiondbd - ld a, [$d152] - ld e, a - ld a, [$d153] - ld d, a - call Function27d3 - ld a, $1 - ld [hBGMapUpdate], a - ret -; 2748 - -Function2748: ; 2748 - ld hl, $c5e0 - ld de, BGMapBuffer - call Function27b7 - ld c, $28 - call Functiondbd - ld a, [$d152] - ld l, a - ld a, [$d153] - ld h, a - ld bc, $0200 - add hl, bc - ld a, h - and $3 - or $98 - ld e, l - ld d, a - call Function27d3 - ld a, $1 - ld [hBGMapUpdate], a - ret -; 2771 - -Function2771: ; 2771 - ld hl, TileMap - ld de, BGMapBuffer - call Function27c0 - ld c, $24 - call Functiondbd - ld a, [$d152] - ld e, a - ld a, [$d153] - ld d, a - call Function27f8 - ld a, $1 - ld [hBGMapUpdate], a - ret -; 278f - -Function278f: ; 278f - ld hl, $c4b2 - ld de, BGMapBuffer - call Function27c0 - ld c, $24 - call Functiondbd - ld a, [$d152] - ld e, a - and $e0 - ld b, a - ld a, e - add $12 - and $1f - or b - ld e, a - ld a, [$d153] - ld d, a - call Function27f8 - ld a, $1 - ld [hBGMapUpdate], a - ret -; 27b7 - -Function27b7: ; 27b7 - ld c, $28 -.asm_27b9 - ld a, [hli] - ld [de], a - inc de - dec c - jr nz, .asm_27b9 - ret -; 27c0 - -Function27c0: ; 27c0 - ld c, $12 -.asm_27c2 - ld a, [hli] - ld [de], a - inc de - ld a, [hl] - ld [de], a - inc de - ld a, $13 - add l - ld l, a - jr nc, .asm_27cf - inc h - -.asm_27cf - dec c - jr nz, .asm_27c2 - ret -; 27d3 - -Function27d3: ; 27d3 - ld hl, BGMapBufferPtrs - push de - call .asm_27df - pop de - ld a, $20 - add e - ld e, a - -.asm_27df - ld c, $a -.asm_27e1 - ld a, e - ld [hli], a - ld a, d - ld [hli], a - ld a, e - inc a - inc a - and $1f - ld b, a - ld a, e - and $e0 - or b - ld e, a - dec c - jr nz, .asm_27e1 - ld a, $14 - ld [$ffdc], a - ret -; 27f8 - -Function27f8: ; 27f8 - ld hl, BGMapBufferPtrs - ld c, $12 -.asm_27fd - ld a, e - ld [hli], a - ld a, d - ld [hli], a - ld a, $20 - add e - ld e, a - jr nc, .asm_280e - inc d - ld a, d - and $3 - or $98 - ld d, a - -.asm_280e - dec c - jr nz, .asm_27fd - ld a, $12 - ld [$ffdc], a - ret -; 2816 - -Function2816: ; 2816 - ld hl, BGMapBuffer - ld bc, $0078 - xor a - call ByteFill - ret -; 2821 - -Function2821: ; 2821 - ld hl, TilesetAddress - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [TilesetBank] - ld e, a - ld a, [rSVBK] - push af - ld a, $6 - ld [rSVBK], a - ld a, e - ld de, $d000 - call FarDecompress - ld hl, $d000 - ld de, VTiles2 - ld bc, $0600 - call CopyBytes - ld a, [rVBK] - push af - ld a, $1 - ld [rVBK], a - ld hl, $d600 - ld de, VTiles2 - ld bc, $0600 - call CopyBytes - pop af - ld [rVBK], a - pop af - ld [rSVBK], a - ld a, [$d199] - cp $1 - jr z, .asm_286f - cp $2 - jr z, .asm_286f - cp $4 - jr z, .asm_286f - jr .asm_2875 - -.asm_286f - ld a, $7 - ld hl, $4000 - rst FarCall - -.asm_2875 - xor a - ld [hTileAnimFrame], a - ret -; 2879 - -Function2879: ; 2879 - ld hl, $d194 - ld a, [hli] - ld h, [hl] - ld l, a - ld de, $dcb9 - ld c, $5 - ld b, $6 -.asm_2886 - push bc - push hl -.asm_2888 - ld a, [hli] - ld [de], a - inc de - dec b - jr nz, .asm_2888 - pop hl - ld a, [$d19f] - add $6 - ld c, a - ld b, $0 - add hl, bc - pop bc - dec c - jr nz, .asm_2886 - ret -; 289d - -Function289d: ; 289d - ld hl, $d194 - ld a, [hli] - ld h, [hl] - ld l, a - ld de, $dcb9 - ld a, [$d19f] - add $6 - ld [hConnectionStripLength], a - ld a, [$d151] - and a - jr z, .asm_28cb - cp $1 - jr z, .asm_28c0 - cp $2 - jr z, .asm_28d4 - cp $3 - jr z, .asm_28da - ret - -.asm_28c0 - ld de, $dcbf - ld a, [hConnectionStripLength] - ld c, a - ld b, $0 - add hl, bc - jr .asm_28ce - -.asm_28cb - ld de, $dcb9 - -.asm_28ce - ld b, $6 - ld c, $4 - jr .asm_28f7 - -.asm_28d4 - ld de, $dcba - inc hl - jr .asm_28dd - -.asm_28da - ld de, $dcb9 - -.asm_28dd - ld b, $5 - ld c, $5 - jr .asm_28f7 - - ld hl, $d194 - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [$d19f] - add $6 - ld [hConnectionStripLength], a - ld de, $dcb9 - ld b, $6 - ld c, $5 - -.asm_28f7 - push bc - push hl - push de -.asm_28fa - ld a, [de] - inc de - ld [hli], a - dec b - jr nz, .asm_28fa - pop de - ld a, e - add $6 - ld e, a - jr nc, .asm_2908 - inc d - -.asm_2908 - pop hl - ld a, [hConnectionStripLength] - ld c, a - ld b, $0 - add hl, bc - pop bc - dec c - jr nz, .asm_28f7 - ret -; 2914 - -Function2914: ; 2914 - xor a - ld [TilePermissions], a - call Function296c - call Function294d - ld a, [MapX] - ld d, a - ld a, [MapY] - ld e, a - call Function2a3c - ld [StandingTile], a - call Function29ff - ret nz - ld a, [StandingTile] - and 7 - ld hl, .data_2945 - add l - ld l, a - ld a, 0 - adc h - ld h, a - ld a, [hl] - ld hl, TilePermissions - or [hl] - ld [hl], a - ret -; 2945 - -.data_2945 ; 2945 - db 1, 2, 4, 8, 9, 10, 5, 6 -; 294d - -Function294d: ; 294d - ld a, [MapX] - ld d, a - ld a, [MapY] - ld e, a - push de - inc e - call Function2a3c - ld [TileDown], a - call Function298b - pop de - dec e - call Function2a3c - ld [TileUp], a - call Function29a8 - ret -; 296c - -Function296c: ; 296c - ld a, [MapX] - ld d, a - ld a, [MapY] - ld e, a - push de - dec d - call Function2a3c - ld [TileLeft], a - call Function29e2 - pop de - inc d - call Function2a3c - ld [TileRight], a - call Function29c5 - ret -; 298b - -Function298b: ; 298b - call Function29ff - ret nz - ld a, [TileDown] - and $7 - cp $2 - jr z, .asm_299f - cp $6 - jr z, .asm_299f - cp $7 - ret nz - -.asm_299f - ld a, [TilePermissions] - or $8 - ld [TilePermissions], a - ret -; 29a8 - -Function29a8: ; 29a8 - call Function29ff - ret nz - ld a, [TileUp] - and $7 - cp $3 - jr z, .asm_29bc - cp $4 - jr z, .asm_29bc - cp $5 - ret nz - -.asm_29bc - ld a, [TilePermissions] - or $4 - ld [TilePermissions], a - ret -; 29c5 - -Function29c5: ; 29c5 - call Function29ff - ret nz - ld a, [TileRight] - and $7 - cp $1 - jr z, .asm_29d9 - cp $5 - jr z, .asm_29d9 - cp $7 - ret nz - -.asm_29d9 - ld a, [TilePermissions] - or $1 - ld [TilePermissions], a - ret -; 29e2 - -Function29e2: ; 29e2 - call Function29ff - ret nz - ld a, [TileLeft] - and $7 - cp $0 - jr z, .asm_29f6 - cp $4 - jr z, .asm_29f6 - cp $6 - ret nz - -.asm_29f6 - ld a, [TilePermissions] - or $2 - ld [TilePermissions], a - ret -; 29ff - -Function29ff: ; 29ff - and $f0 - cp $b0 - ret z - cp $c0 - ret -; 2a07 - - -GetFacingTileCoord: ; 2a07 -; Return map coordinates in (d, e) and tile id in a -; of the tile the player is facing. - - ld a, [PlayerDirection] - and %1100 - srl a - srl a - ld l, a - ld h, 0 - add hl, hl - add hl, hl - ld de, .Directions - add hl, de - - ld d, [hl] - inc hl - ld e, [hl] - inc hl - - ld a, [hli] - ld h, [hl] - ld l, a - - ld a, [MapX] - add d - ld d, a - ld a, [MapY] - add e - ld e, a - ld a, [hl] - ret - -.Directions - ; x, y - db 0, 1 - dw TileDown - db 0, -1 - dw TileUp - db -1, 0 - dw TileLeft - db 1, 0 - dw TileRight -; 2a3c - - -Function2a3c: ; 2a3c - call Function2a66 - ld a, [hl] - and a - jr z, .asm_2a63 - ld l, a - ld h, $0 - add hl, hl - add hl, hl - ld a, [TilesetCollisionAddress] - ld c, a - ld a, [$d1e1] - ld b, a - add hl, bc - rr d - jr nc, .asm_2a56 - inc hl - -.asm_2a56 - rr e - jr nc, .asm_2a5c - inc hl - inc hl - -.asm_2a5c - ld a, [TilesetCollisionBank] - call GetFarByte - ret - -.asm_2a63 - ld a, $ff - ret -; 2a66 - -Function2a66: ; 2a66 - ld a, [$d19f] - add $6 - ld c, a - ld b, $0 - ld hl, $c801 - add hl, bc - ld a, e - srl a - jr z, .asm_2a84 - and a -.asm_2a78 - srl a - jr nc, .asm_2a7d - add hl, bc - -.asm_2a7d - sla c - rl b - and a - jr nz, .asm_2a78 - -.asm_2a84 - ld c, d - srl c - ld b, $0 - add hl, bc - ret -; 2a8b - - -CheckFacingSign: ; 2a8b - call GetFacingTileCoord - ld b, a - ld a, d - sub 4 - ld d, a - ld a, e - sub 4 - ld e, a - ld a, [$dc01] - and a - ret z - ld c, a - ld a, [hROMBank] - push af - call Function2c52 - call Function2aaa - pop hl - ld a, h - rst Bankswitch - ret -; 2aaa - -Function2aaa: ; 2aaa - ld hl, $dc02 - ld a, [hli] - ld h, [hl] - ld l, a -.asm_2ab0 - push hl - ld a, [hli] - cp e - jr nz, .asm_2abb - ld a, [hli] - cp d - jr nz, .asm_2abb - jr .asm_2ac8 - -.asm_2abb - pop hl - ld a, 5 - add l - ld l, a - jr nc, .asm_2ac3 - inc h - -.asm_2ac3 - dec c - jr nz, .asm_2ab0 - xor a - ret - -.asm_2ac8 - pop hl - ld de, EngineBuffer1 - ld bc, 5 - call CopyBytes - scf - ret -; 2ad4 - -Function2ad4: ; 2ad4 - ld a, [$dbfe] - and a - ret z - ld c, a - ld a, [hROMBank] - push af - call Function2c52 - call Function2ae7 - pop hl - ld a, h - rst Bankswitch - ret -; 2ae7 - -Function2ae7: ; 2ae7 - ld hl, $dbff - ld a, [hli] - ld h, [hl] - ld l, a - call Function211b - ld b, a - ld a, [MapX] - sub $4 - ld d, a - ld a, [MapY] - sub $4 - ld e, a -.asm_2afd - push hl - ld a, [hli] - cp b - jr z, .asm_2b06 - cp $ff - jr nz, .asm_2b10 - -.asm_2b06 - ld a, [hli] - cp e - jr nz, .asm_2b10 - ld a, [hli] - cp d - jr nz, .asm_2b10 - jr .asm_2b1d - -.asm_2b10 - pop hl - ld a, $8 - add l - ld l, a - jr nc, .asm_2b18 - inc h - -.asm_2b18 - dec c - jr nz, .asm_2afd - xor a - ret - -.asm_2b1d - pop hl - ld de, EngineBuffer1 - ld bc, $0008 - call CopyBytes - scf - ret -; 2b29 - - -FadeToMenu: ; 2b29 - xor a - ld [hBGMapMode], a - call Function1d6e - ld a, $23 - ld hl, $4084 - rst FarCall - call ClearSprites - call Function2ed3 - ret -; 2b3c - - -Function2b3c: ; 2b3c - call WhiteBGMap - call Function2bae - call Function1ad2 - call Function1d7d - call Functiond90 - jr Function2b5c -; 2b4d - -Function2b4d: ; 2b4d - call WhiteBGMap - call Function1d7d - call Function2bae - call Function1ad2 - call Functiond90 -; 2b5c - -Function2b5c: ; 2b5c - ld b, $9 - call GetSGBLayout - ld a, $12 - ld hl, $5409 - rst FarCall - call Function3200 - ld a, $23 - ld hl, $4079 - rst FarCall - call Function2ee4 - ret -; 2b74 - - -Function2b74: ; 0x2b74 - push af - ld a, $1 - ld [$c2ce], a - call WhiteBGMap - call ClearSprites - call Function2bae - ld hl, $c590 ; tile 0, 12 - ld bc, $0412 - call TextBox - ld hl, VramState - set 0, [hl] - call Function1ad2 - call Function3200 - ld b, $9 - call GetSGBLayout - callba Function49409 - call UpdateTimePals - call DelayFrame - ld a, $1 - ld [$ffde], a - pop af - ret -; 0x2bae - -Function2bae: ; 2bae - call DisableLCD - call ClearSprites - ld a, $5 - ld hl, $4168 - rst FarCall - call Functione51 - call Functione5f - ld a, [hROMBank] - push af - ld a, [MapGroup] - ld b, a - ld a, [MapNumber] - ld c, a - call Function2c24 - ld a, $23 - ld hl, $4001 - rst FarCall - call Function2173 - call Function2821 - ld a, $9 - call Function3cb4 - pop af - rst Bankswitch - - call EnableLCD - ret -; 2be5 - - -GetMapHeaderPointer: ; 2be5 - ld a, [MapGroup] - ld b, a - ld a, [MapNumber] - ld c, a -; 2bed - -GetAnyMapHeaderPointer: ; 0x2bed -; Prior to calling this function, you must have switched banks so that -; MapGroupPointers is visible. - -; inputs: -; b = map group, c = map number -; XXX de = ??? - -; outputs: -; hl points to the map header - push bc ; save map number for later - - ; get pointer to map group - dec b - ld c, b - ld b, $0 - ld hl, MapGroupPointers - add hl, bc - add hl, bc - - ld a, [hli] - ld h, [hl] - ld l, a - pop bc ; restore map number - - ; find the cth map header - dec c - ld b, $0 - ld a, OlivineGym_MapHeader - OlivinePokeCenter1F_MapHeader - call AddNTimes - ret -; 0x2c04 - -GetMapHeaderMember: ; 0x2c04 -; Extract data from the current map's header. - -; inputs: -; de = offset of desired data within the mapheader - -; outputs: -; bc = data from the current map's header -; (e.g., de = $0003 would return a pointer to the secondary map header) - - ld a, [MapGroup] - ld b, a - ld a, [MapNumber] - ld c, a - ; fallthrough - -GetAnyMapHeaderMember: ; 0x2c0c - ; bankswitch - ld a, [hROMBank] - push af - ld a, BANK(MapGroupPointers) - rst Bankswitch - - call GetAnyMapHeaderPointer - add hl, de - ld c, [hl] - inc hl - ld b, [hl] - - ; bankswitch back - pop af - rst Bankswitch - ret -; 0x2c1c - - -Function2c1c: ; 2c1c - ld a, [MapGroup] - ld b, a - ld a, [MapNumber] - ld c, a -; 2c24 - -Function2c24: ; 2c24 - call Function2c31 - rst Bankswitch - ret -; 2c29 - - -Function2c29: ; 2c29 - ld a, [MapGroup] - ld b, a - ld a, [MapNumber] - ld c, a -; 2c31 - -Function2c31: ; 2c31 - push hl - push de - ld de, $0000 - call GetAnyMapHeaderMember - ld a, c - pop de - pop hl - ret -; 2c3d - -Function2c3d: ; 2c3d - ld a, [hROMBank] - push af - ld a, $25 - rst Bankswitch - call GetMapHeaderPointer - ld de, $d198 - ld bc, $0005 - call CopyBytes - pop af - rst Bankswitch - ret -; 2c52 - -Function2c52: ; 2c52 - ld a, [MapEventBank] - rst Bankswitch - ret -; 2c57 - - -GetMapEventBank: ; 2c57 - ld a, [MapEventBank] - ret -; 2c5b - -GetAnyMapBlockdataBank: ; 2c5b -; Return the blockdata bank for group b map c. - push hl - push de - push bc - - push bc - ld de, 3 ; second map header pointer - call GetAnyMapHeaderMember - ld l, c - ld h, b - pop bc - - push hl - ld de, 0 ; second map header bank - call GetAnyMapHeaderMember - pop hl - - ld de, 3 ; blockdata bank - add hl, de - ld a, c - call GetFarByte - rst Bankswitch - - pop bc - pop de - pop hl - ret -; 2c7d - -GetSecondaryMapHeaderPointer: ; 0x2c7d -; returns the current map's secondary map header pointer in hl. - push bc - push de - ld de, $0003 ; secondary map header pointer (offset within header) - call GetMapHeaderMember - ld l, c - ld h, b - pop de - pop bc - ret -; 2c8a - -GetMapPermission: ; 2c8a - push hl - push de - push bc - ld de, 2 - call GetMapHeaderMember - ld a, c - pop bc - pop de - pop hl - ret -; 2c98 - -Function2c98: ; 2c98 - ret -; 2c99 - -Function2c99: ; 2c99 - push hl - push de - push bc - ld de, $0002 - call GetAnyMapHeaderMember - ld a, c - pop bc - pop de - pop hl - ret -; 2ca7 - -Function2ca7: ; 2ca7 - ld de, $0001 - call GetAnyMapHeaderMember - ld a, c - ret -; 2caf - -GetWorldMapLocation: ; 0x2caf -; given a map group/id in bc, return its location on the Pokégear map. - push hl - push de - push bc - ld de, 5 - call GetAnyMapHeaderMember - ld a, c - pop bc - pop de - pop hl - ret -; 0x2cbd - -Function2cbd: ; 2cbd - push hl - push bc - ld de, $0006 - call GetMapHeaderMember - ld a, c - cp $64 - jr z, .asm_2cee - bit 7, c - jr nz, .asm_2cda - ld a, $22 - ld hl, $7342 - rst FarCall - ld e, c - ld d, $0 -.asm_2cd7 - pop bc - pop hl - ret - -.asm_2cda - ld a, [StatusFlags2] - bit 0, a - jr z, .asm_2ce6 - ld de, $0056 - jr .asm_2cd7 - -.asm_2ce6 - ld a, c - and $7f - ld e, a - ld d, $0 - jr .asm_2cd7 - -.asm_2cee - ld a, [StatusFlags2] - bit 7, a - jr z, .asm_2cfa - ld de, $0048 - jr .asm_2cd7 - -.asm_2cfa - ld de, $0026 - jr .asm_2cd7 -; 2cff - -Function2cff: ; 2cff - call Function2d0d - and $f - ret -; 2d05 - -Function2d05: ; 2d05 - call Function2d0d - and $f0 - swap a - ret -; 2d0d - -Function2d0d: ; 2d0d - push hl - push bc - ld de, $0007 - call GetMapHeaderMember - ld a, c - pop bc - pop hl - ret -; 2d19 - -Function2d19: ; 2d19 - push de - push hl - push bc - ld de, $0008 - call GetMapHeaderMember - ld a, c - pop bc - pop hl - pop de - ret -; 2d27 - -Function2d27: ; 2d27 - push hl - push bc - ld hl, $5596 - ld bc, $000f - ld a, [$d199] - call AddNTimes - ld de, TilesetBank - ld bc, $000f - ld a, $13 - call FarCopyBytes - pop bc - pop hl - ret -; 2d43 Function2d43: ; 2d43 nop From 82c3bb464f192c8d2ab29a8ef5bd8440f4567065 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 00:19:52 -0400 Subject: [PATCH 7/8] split flag action asm into common/flag.asm --- common/flag.asm | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 111 +---------------------------------------------- 2 files changed, 114 insertions(+), 110 deletions(-) create mode 100644 common/flag.asm diff --git a/common/flag.asm b/common/flag.asm new file mode 100644 index 000000000..e99248a3e --- /dev/null +++ b/common/flag.asm @@ -0,0 +1,113 @@ +Function2e50: ; 2e50 + xor a + ld hl, EventFlags + ld [hli], a + ret +; 2e56 + +Function2e56: ; 2e56 + xor a + ld hl, BikeFlags + ld [hli], a + ld [hl], a + ret +; 2e5d + +Function2e5d: ; 2e5d + ld a, [$d19a] + cp $2 + jr z, .asm_2e69 + cp $1 + jr z, .asm_2e69 + ret + +.asm_2e69 + ld hl, StatusFlags + res 2, [hl] + ret +; 2e6f + + +EventFlagAction: ; 0x2e6f + ld hl, EventFlags + call FlagAction + ret + +FlagAction: ; 0x2e76 +; Perform action b on bit de in flag array hl. + +; inputs: +; b: function +; 0 clear bit +; 1 set bit +; 2 check bit +; de: bit number +; hl: index within bit table + + ; get index within the byte + ld a, e + and 7 + + ; shift de right by three bits (get the index within memory) + srl d + rr e + srl d + rr e + srl d + rr e + add hl, de + + ; implement a decoder + ld c, 1 + rrca + jr nc, .one + rlc c +.one + rrca + jr nc, .two + rlc c + rlc c +.two + rrca + jr nc, .three + swap c +.three + + ; check b's value: 0, 1, 2 + ld a, b + cp 1 + jr c, .clearbit ; 0 + jr z, .setbit ; 1 + + ; check bit + ld a, [hl] + and c + ld c, a + ret + +.setbit + ; set bit + ld a, [hl] + or c + ld [hl], a + ret + +.clearbit + ; clear bit + ld a, c + cpl + and [hl] + ld [hl], a + ret +; 0x2ead + + +Function2ead: ; 2ead + ld de, ENGINE_POKEDEX + ld b, CHECK_FLAG + callba EngineFlagAction + ld a, c + and a + ret +; 2ebb + diff --git a/main.asm b/main.asm index f53f5d4bf..fc77d60ed 100644 --- a/main.asm +++ b/main.asm @@ -706,118 +706,9 @@ Function2e4e: ; 2e4e ret ; 2e50 -Function2e50: ; 2e50 - xor a - ld hl, EventFlags - ld [hli], a - ret -; 2e56 -Function2e56: ; 2e56 - xor a - ld hl, BikeFlags - ld [hli], a - ld [hl], a - ret -; 2e5d +INCLUDE "common/flag.asm" -Function2e5d: ; 2e5d - ld a, [$d19a] - cp $2 - jr z, .asm_2e69 - cp $1 - jr z, .asm_2e69 - ret - -.asm_2e69 - ld hl, StatusFlags - res 2, [hl] - ret -; 2e6f - - -EventFlagAction: ; 0x2e6f - ld hl, EventFlags - call FlagAction - ret - -FlagAction: ; 0x2e76 -; Perform a function on a bit in memory. - -; inputs: -; b: function -; 0 clear bit -; 1 set bit -; 2 check bit -; de: bit number -; hl: index within bit table - - ; get index within the byte - ld a, e - and $7 - - ; shift de right by three bits (get the index within memory) - srl d - rr e - srl d - rr e - srl d - rr e - add hl, de - - ; implement a decoder - ld c, $1 - rrca - jr nc, .one - rlc c -.one - rrca - jr nc, .two - rlc c - rlc c -.two - rrca - jr nc, .three - swap c -.three - - ; check b's value: 0, 1, 2 - ld a, b - cp 1 - jr c, .clearbit ; 0 - jr z, .setbit ; 1 - - ; check bit - ld a, [hl] - and c - ld c, a - ret - -.setbit - ; set bit - ld a, [hl] - or c - ld [hl], a - ret - -.clearbit - ; clear bit - ld a, c - cpl - and [hl] - ld [hl], a - ret -; 0x2ead - - -Function2ead: ; 2ead - ld de, ENGINE_POKEDEX - ld b, CHECK_FLAG - callba EngineFlagAction - ld a, c - and a - ret -; 2ebb Function2ebb: ; 2ebb ld a, [$c2cc] From 705e6824687ed247a28cfbaedd47bf33bd1da32a Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 00:22:33 -0400 Subject: [PATCH 8/8] split InitString asm into common/string.asm --- common/string.asm | 39 +++++++++++++++++++++++++++++++++++++++ main.asm | 38 +------------------------------------- 2 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 common/string.asm diff --git a/common/string.asm b/common/string.asm new file mode 100644 index 000000000..a871b4d2a --- /dev/null +++ b/common/string.asm @@ -0,0 +1,39 @@ +InitString: ; 2ef6 +; Init a string of length c. + push hl + jr _InitString +; 2ef9 + +InitName: ; 2ef9 +; Intended for names, so this function is limited to ten characters. + push hl + ld c, 10 +; 2efc + +_InitString: ; 2efc +; if the string pointed to by hl is empty (defined as "zero or more spaces +; followed by a null"), then initialize it to the string pointed to by de. + push bc +.loop + ld a, [hli] + cp "@" + jr z, .blank + cp " " + jr nz, .notblank + dec c + jr nz, .loop +.blank + pop bc + ld l, e + ld h, d + pop de + ld b, 0 + inc c + call CopyBytes + ret +.notblank + pop bc + pop hl + ret +; 2f17 + diff --git a/main.asm b/main.asm index fc77d60ed..9a096202f 100644 --- a/main.asm +++ b/main.asm @@ -765,44 +765,8 @@ Function2ee4: ; 2ee4 ; 2ef6 -InitString: ; 2ef6 -; Init a string of length c. - push hl - jr _InitString -; 2ef9 +INCLUDE "common/string.asm" -InitName: ; 2ef9 -; Intended for names, so this function is limited to ten characters. - push hl - ld c, 10 -; 2efc - -_InitString: ; 2efc -; if the string pointed to by hl is empty (defined as "zero or more spaces -; followed by a null"), then initialize it to the string pointed to by de. - push bc -.loop - ld a, [hli] - cp "@" - jr z, .blank - cp " " - jr nz, .notblank - dec c - jr nz, .loop -.blank - pop bc - ld l, e - ld h, d - pop de - ld b, $0 - inc c - call CopyBytes - ret -.notblank - pop bc - pop hl - ret -; 2f17 Function2f17: ; 2f17 ld a, [MapGroup]