From cc1f57ec93cc439b4910ee2e619c517989fff675 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 21 Aug 2013 14:49:35 -0400 Subject: [PATCH 01/96] condense IncGradGBPalTable this way is more readable too --- main.asm | 85 ++++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 67 deletions(-) diff --git a/main.asm b/main.asm index 13021b926..6c7f1933e 100644 --- a/main.asm +++ b/main.asm @@ -225,73 +225,24 @@ Function501: ; 501 ; 517 -IncGradGBPalTable_00: ; 517 - db %11111111 ; bgp - db %11111111 ; obp1 - db %11111111 ; obp2 - ; and so on... -IncGradGBPalTable_01: ; 51a - db %11111110 - db %11111110 - db %11111110 -IncGradGBPalTable_02: ; 51d - db %11111001 - db %11111001 - db %11111001 -IncGradGBPalTable_03: ; 520 - db %11100100 - db %11100100 - db %11100100 -IncGradGBPalTable_04: ; 523 - db %11100100 - db %11100100 - db %11100100 -IncGradGBPalTable_05: ; 526 - db %10010000 - db %10010000 - db %10010000 -IncGradGBPalTable_06: ; 529 - db %01000000 - db %01000000 - db %01000000 -IncGradGBPalTable_07: ; 52c - db %00000000 - db %00000000 - db %00000000 -; 52f - -IncGradGBPalTable_08: ; 52f - db %11111111 - db %11111111 - db %11111111 -IncGradGBPalTable_09: ; 532 - db %11111110 - db %11111110 - db %11111000 -IncGradGBPalTable_10: ; 535 - db %11111001 - db %11100100 - db %11100100 -IncGradGBPalTable_11: ; 538 - db %11100100 - db %11010000 - db %11100000 -IncGradGBPalTable_12: ; 53b - db %11100100 - db %11010000 - db %11100000 -IncGradGBPalTable_13: ; 53e - db %10010000 - db %10000000 - db %10010000 -IncGradGBPalTable_14: ; 541 - db %01000000 - db %01000000 - db %01000000 -IncGradGBPalTable_15: ; 544 - db %00000000 - db %00000000 - db %00000000 +; 517 +IncGradGBPalTable_00: db %11111111, %11111111, %11111111 +IncGradGBPalTable_01: db %11111110, %11111110, %11111110 +IncGradGBPalTable_02: db %11111001, %11111001, %11111001 +IncGradGBPalTable_03: db %11100100, %11100100, %11100100 +IncGradGBPalTable_04: db %11100100, %11100100, %11100100 +IncGradGBPalTable_05: db %10010000, %10010000, %10010000 +IncGradGBPalTable_06: db %01000000, %01000000, %01000000 +IncGradGBPalTable_07: db %00000000, %00000000, %00000000 +; bgp obp1 obp2 +IncGradGBPalTable_08: db %11111111, %11111111, %11111111 +IncGradGBPalTable_09: db %11111110, %11111110, %11111000 +IncGradGBPalTable_10: db %11111001, %11100100, %11100100 +IncGradGBPalTable_11: db %11100100, %11010000, %11100000 +IncGradGBPalTable_12: db %11100100, %11010000, %11100000 +IncGradGBPalTable_13: db %10010000, %10000000, %10010000 +IncGradGBPalTable_14: db %01000000, %01000000, %01000000 +IncGradGBPalTable_15: db %00000000, %00000000, %00000000 ; 547 From 7f96387411d8f739f90e8693282ed131eedf70f5 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 21 Aug 2013 16:02:18 -0400 Subject: [PATCH 02/96] dump odd eggs --- main.asm | 6 +- stats/odd_eggs.asm | 364 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 stats/odd_eggs.asm diff --git a/main.asm b/main.asm index 6c7f1933e..c5fc13de5 100644 --- a/main.asm +++ b/main.asm @@ -73883,7 +73883,11 @@ BattleTowerMons: ; 1f8450 INCLUDE "stats/battle_tower.asm" ; 1fb4b6 -INCBIN "baserom.gbc", $1fb4b6, $1fb8a8 - $1fb4b6 +INCBIN "baserom.gbc", $1fb4b6, $1fb56e - $1fb4b6 + +OddEggs: ; 1fb56e + INCLUDE "stats/odd_eggs.asm" +; 1fb8a8 SECTION "bank7F",ROMX,BANK[$7F] diff --git a/stats/odd_eggs.asm b/stats/odd_eggs.asm new file mode 100644 index 000000000..071b52d5e --- /dev/null +++ b/stats/odd_eggs.asm @@ -0,0 +1,364 @@ + db PICHU + db NO_ITEM + db THUNDERSHOCK, CHARM, DIZZY_PUNCH, NONE + dw 02048 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 30, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 17 ; Max HP + bigdw 9 ; Atk + bigdw 6 ; Def + bigdw 11 ; Spd + bigdw 8 ; SAtk + bigdw 8 ; SDef + db "EGG@@@@@@@@" + + db PICHU + db NO_ITEM + db THUNDERSHOCK, CHARM, DIZZY_PUNCH, NONE + dw 00256 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 30, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 17 ; Max HP + bigdw 9 ; Atk + bigdw 7 ; Def + bigdw 12 ; Spd + bigdw 9 ; SAtk + bigdw 9 ; SDef + db "EGG@@@@@@@@" + + db CLEFFA + db NO_ITEM + db POUND, CHARM, DIZZY_PUNCH, NONE + dw 04096 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 35, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 20 ; Max HP + bigdw 7 ; Atk + bigdw 7 ; Def + bigdw 6 ; Spd + bigdw 9 ; SAtk + bigdw 10 ; SDef + db "EGG@@@@@@@@" + + db CLEFFA + db NO_ITEM + db POUND, CHARM, DIZZY_PUNCH, NONE + dw 00768 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 35, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 20 ; Max HP + bigdw 7 ; Atk + bigdw 8 ; Def + bigdw 7 ; Spd + bigdw 10 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db IGGLYBUFF + db NO_ITEM + db SING, CHARM, DIZZY_PUNCH, NONE + dw 04096 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 15, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 24 ; Max HP + bigdw 8 ; Atk + bigdw 6 ; Def + bigdw 6 ; Spd + bigdw 9 ; SAtk + bigdw 7 ; SDef + db "EGG@@@@@@@@" + + db IGGLYBUFF + db NO_ITEM + db SING, CHARM, DIZZY_PUNCH, NONE + dw 00768 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 15, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 24 ; Max HP + bigdw 8 ; Atk + bigdw 7 ; Def + bigdw 7 ; Spd + bigdw 10 ; SAtk + bigdw 8 ; SDef + db "EGG@@@@@@@@" + + db SMOOCHUM + db NO_ITEM + db POUND, LICK, DIZZY_PUNCH, NONE + dw 03584 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 35, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 8 ; Atk + bigdw 6 ; Def + bigdw 11 ; Spd + bigdw 13 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db SMOOCHUM + db NO_ITEM + db POUND, LICK, DIZZY_PUNCH, NONE + dw 00512 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 35, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 8 ; Atk + bigdw 7 ; Def + bigdw 12 ; Spd + bigdw 14 ; SAtk + bigdw 12 ; SDef + db "EGG@@@@@@@@" + + db MAGBY + db NO_ITEM + db EMBER, DIZZY_PUNCH, NONE, NONE + dw 02560 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 25, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 12 ; Atk + bigdw 8 ; Def + bigdw 13 ; Spd + bigdw 12 ; SAtk + bigdw 10 ; SDef + db "EGG@@@@@@@@" + + db MAGBY + db NO_ITEM + db EMBER, DIZZY_PUNCH, NONE, NONE + dw 00512 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 25, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 12 ; Atk + bigdw 9 ; Def + bigdw 14 ; Spd + bigdw 13 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db ELEKID + db NO_ITEM + db QUICK_ATTACK, LEER, DIZZY_PUNCH, NONE + dw 03072 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 30, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 11 ; Atk + bigdw 8 ; Def + bigdw 14 ; Spd + bigdw 11 ; SAtk + bigdw 10 ; SDef + db "EGG@@@@@@@@" + + db ELEKID + db NO_ITEM + db QUICK_ATTACK, LEER, DIZZY_PUNCH, NONE + dw 00512 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 30, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 11 ; Atk + bigdw 9 ; Def + bigdw 15 ; Spd + bigdw 12 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db TYROGUE + db NO_ITEM + db TACKLE, DIZZY_PUNCH, NONE, NONE + dw 02560 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 35, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 18 ; Max HP + bigdw 8 ; Atk + bigdw 8 ; Def + bigdw 8 ; Spd + bigdw 8 ; SAtk + bigdw 8 ; SDef + db "EGG@@@@@@@@" + + db TYROGUE + db NO_ITEM + db TACKLE, DIZZY_PUNCH, NONE, NONE + dw 00256 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 35, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 18 ; Max HP + bigdw 8 ; Atk + bigdw 9 ; Def + bigdw 9 ; Spd + bigdw 9 ; SAtk + bigdw 9 ; SDef + db "EGG@@@@@@@@" + From 179decd644ae723c2efa30a282f459a44c16c6d3 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 21 Aug 2013 17:18:58 -0400 Subject: [PATCH 03/96] GiveOddEgg and related asm That's it for bank 7e --- main.asm | 199 ++++++++++++++++++++++++++++++++++++++++++++- stats/odd_eggs.asm | 2 + 2 files changed, 199 insertions(+), 2 deletions(-) diff --git a/main.asm b/main.asm index c5fc13de5..73f9d5db4 100644 --- a/main.asm +++ b/main.asm @@ -71766,7 +71766,107 @@ UnknownText_0x11ac1f: ; 0x11ac1f db "Please wait…", $57 ; 0x11ac3e -INCBIN "baserom.gbc", $11ac3e, $11bc9e - $11ac3e +INCBIN "baserom.gbc", $11ac3e, $11b98f - $11ac3e + +Function11b98f: ; 11b98f + ld hl, PartyCount + ld a, [hl] + ld e, a + inc [hl] + ld a, [BGMapBuffer] + ld l, a + ld a, [$cd21] + ld h, a + inc hl + ld bc, PartySpecies + ld d, e +.asm_11b9a2 + inc bc + dec d + jr nz, .asm_11b9a2 + ld a, e + ld [CurPartyMon], a + ld a, [hl] + ld [bc], a + inc bc + ld a, $ff + ld [bc], a + ld hl, PartyMon1Species + ld bc, $0030 + ld a, e + ld [$cd2a], a +.asm_11b9ba + add hl, bc + dec a + and a + jr nz, .asm_11b9ba + ld e, l + ld d, h + ld a, [CreditsTimer] + ld l, a + ld a, [$cd23] + ld h, a + ld bc, $0030 + call CopyBytes + ld hl, PartyMon1OT + ld bc, $000b + ld a, [$cd2a] +.asm_11b9d8 + add hl, bc + dec a + and a + jr nz, .asm_11b9d8 + ld e, l + ld d, h + ld a, [$cd24] + ld l, a + ld a, [$cd25] + ld h, a + ld bc, $000a + call CopyBytes + ld a, $50 + ld [de], a + ld hl, PartyMon1Nickname + ld bc, $000b + ld a, [$cd2a] +.asm_11b9f9 + add hl, bc + dec a + and a + jr nz, .asm_11b9f9 + ld e, l + ld d, h + ld a, [$cd26] + ld l, a + ld a, [$cd27] + ld h, a + ld bc, $000a + call CopyBytes + ld a, $50 + ld [de], a + ld hl, $a600 + ld bc, $002f + ld a, [$cd2a] +.asm_11ba1a + add hl, bc + dec a + and a + jr nz, .asm_11ba1a + ld a, $0 + call GetSRAMBank + ld e, l + ld d, h + ld a, [$cd28] + ld l, a + ld a, [$cd29] + ld h, a + ld bc, $002f + call CopyBytes + call CloseSRAM + ret +; 11ba38 + +INCBIN "baserom.gbc", $11ba38, $11bc9e - $11ba38 SECTION "bank47",ROMX,BANK[$47] @@ -73883,7 +73983,102 @@ BattleTowerMons: ; 1f8450 INCLUDE "stats/battle_tower.asm" ; 1fb4b6 -INCBIN "baserom.gbc", $1fb4b6, $1fb56e - $1fb4b6 + +GiveOddEgg: ; 1fb4b6 + +; Figure out which egg to give. + call RNG + ld hl, .Probabilities + ld c, 0 + ld b, c +.next + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, d + cp $ff + jr nz, .first + ld a, e + cp $ff + jr z, .done +.first + ld a, [hRandomSub] + cp d + jr c, .done + jr z, .second + jr .good +.second + ld a, [hRandomAdd] + cp e + jr c, .done + jr z, .done +.good + inc bc + jr .next +.done + + ld hl, OddEggs + ld a, OddEgg2 - OddEgg1 + call AddNTimes + ld de, EnemyMoveAnimation + ld bc, $0046 + call CopyBytes + ld a, EGG_TICKET + ld [CurItem], a + ld a, $1 + ld [$d10c], a + ld a, $ff + ld [$d107], a + ld hl, NumItems + call Function2f53 + ld a, EGG + ld [$cd2a], a + ld a, $29 + ld [$cd20], a + ld a, $cd + ld [$cd21], a + ld a, $8 + ld [$cd22], a + ld a, $c6 + ld [$cd23], a + + ld hl, .Odd + ld de, $cd2b + ld bc, $000b + call CopyBytes + + ld a, $2b + ld [$cd24], a + ld a, $cd + ld [$cd25], a + ld a, $38 + ld [$cd26], a + ld a, $c6 + ld [$cd27], a + callba Function11b98f + ret +; 1fb546 + +.Odd + db "ODD@@@@@@@@@" + +.Probabilities + dw $147a ; 92% -> 8% + dw $170a ; 91% -> 1% + dw $3fff ; 75% -> 16% + dw $47ad ; 72% -> 3% + dw $70a3 ; 56% -> 16% + dw $7851 ; 53% -> 3% + dw $9c28 ; 39% -> 14% + dw $a147 ; 37% -> 2% + dw $bae0 ; 27% -> 10% + dw $bfff ; 25% -> 2% + dw $deb7 ; 13% -> 12% + dw $e3d6 ; 11% -> 2% + dw $fd6f ; 1% -> 10% + dw $ffff ; 0% -> 1% +; 1fb56e OddEggs: ; 1fb56e INCLUDE "stats/odd_eggs.asm" diff --git a/stats/odd_eggs.asm b/stats/odd_eggs.asm index 071b52d5e..bab41be71 100644 --- a/stats/odd_eggs.asm +++ b/stats/odd_eggs.asm @@ -1,3 +1,4 @@ +OddEgg1: db PICHU db NO_ITEM db THUNDERSHOCK, CHARM, DIZZY_PUNCH, NONE @@ -24,6 +25,7 @@ bigdw 8 ; SDef db "EGG@@@@@@@@" +OddEgg2: db PICHU db NO_ITEM db THUNDERSHOCK, CHARM, DIZZY_PUNCH, NONE From 231adfe99c5b01505f622884709281923ddaa7d2 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 22 Aug 2013 04:16:41 -0400 Subject: [PATCH 04/96] boxmon labels in sram --- wram.asm | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/wram.asm b/wram.asm index 014a86f6b..b2128ec54 100644 --- a/wram.asm +++ b/wram.asm @@ -2099,3 +2099,176 @@ BGPals: OBPals: ds $40 + + +SECTION "SRAMBank1",SRAM,BANK[1] + +SECTION "BoxMons",SRAM[$ad10],BANK[1] +BoxCount: ; ad10 + ds 1 +BoxSpecies: ; ad11 + ds 20 + ds 1 +BoxMons: +BoxMon1: +BoxMon1Species: ; ad26 + ds 1 +BoxMon1Item: ; ad27 + ds 1 +BoxMon1Moves: ; ad28 + ds 4 +BoxMon1ID: ; ad2c + ds 2 +BoxMon1Exp: ; ad2e + ds 3 +BoxMon1HPExp: ; ad31 + ds 2 +BoxMon1AtkExp: ; ad33 + ds 2 +BoxMon1DefExp: ; ad35 + ds 2 +BoxMon1SpdExp: ; ad37 + ds 2 +BoxMon1SpcExp: ; ad39 + ds 2 +BoxMon1DVs: ; ad3b + ds 2 +BoxMon1PP: ; ad3d + ds 4 +BoxMon1Happiness: ; ad41 + ds 1 +BoxMon1PokerusStatus: ; ad42 + ds 1 +BoxMon1CaughtData: +BoxMon1CaughtTime: +BoxMon1CaughtLevel: ; ad43 + ds 1 +BoxMon1CaughtGender: +BoxMon1CaughtLocation: ; ad44 + ds 1 +BoxMon1Level: ; ad45 + ds 1 + +BoxMon2: ; ad46 + ds 32 +BoxMon3: ; ad66 + ds 32 +BoxMon4: ; ad86 + ds 32 +BoxMon5: ; ada6 + ds 32 +BoxMon6: ; adc6 + ds 32 +BoxMon7: ; ade6 + ds 32 +BoxMon8: ; ae06 + ds 32 +BoxMon9: ; ae26 + ds 32 +BoxMon10: ; ae46 + ds 32 +BoxMon11: ; ae66 + ds 32 +BoxMon12: ; ae86 + ds 32 +BoxMon13: ; aea6 + ds 32 +BoxMon14: ; aec6 + ds 32 +BoxMon15: ; aee6 + ds 32 +BoxMon16: ; af06 + ds 32 +BoxMon17: ; af26 + ds 32 +BoxMon18: ; af46 + ds 32 +BoxMon19: ; af66 + ds 32 +BoxMon20: ; af86 + ds 32 + +BoxMonOT: +BoxMon1OT: ; afa6 + ds 11 +BoxMon2OT: ; afb1 + ds 11 +BoxMon3OT: ; afbc + ds 11 +BoxMon4OT: ; afc7 + ds 11 +BoxMon5OT: ; afd2 + ds 11 +BoxMon6OT: ; afdd + ds 11 +BoxMon7OT: ; afe8 + ds 11 +BoxMon8OT: ; aff3 + ds 11 +BoxMon9OT: ; affe + ds 11 +BoxMon10OT: ; b009 + ds 11 +BoxMon11OT: ; b014 + ds 11 +BoxMon12OT: ; b01f + ds 11 +BoxMon13OT: ; b02a + ds 11 +BoxMon14OT: ; b035 + ds 11 +BoxMon15OT: ; b040 + ds 11 +BoxMon16OT: ; b04b + ds 11 +BoxMon17OT: ; b056 + ds 11 +BoxMon18OT: ; b061 + ds 11 +BoxMon19OT: ; b06c + ds 11 +BoxMon20OT: ; b077 + ds 11 + +BoxMonNicknames: +BoxMon1Nickname: ; b082 + ds 11 +BoxMon2Nickname: ; b08d + ds 11 +BoxMon3Nickname: ; b098 + ds 11 +BoxMon4Nickname: ; b0a3 + ds 11 +BoxMon5Nickname: ; b0ae + ds 11 +BoxMon6Nickname: ; b0b9 + ds 11 +BoxMon7Nickname: ; b0c4 + ds 11 +BoxMon8Nickname: ; b0cf + ds 11 +BoxMon9Nickname: ; b0da + ds 11 +BoxMon10Nickname: ; b0e5 + ds 11 +BoxMon11Nickname: ; b0f0 + ds 11 +BoxMon12Nickname: ; b0fb + ds 11 +BoxMon13Nickname: ; b106 + ds 11 +BoxMon14Nickname: ; b111 + ds 11 +BoxMon15Nickname: ; b11c + ds 11 +BoxMon16Nickname: ; b127 + ds 11 +BoxMon17Nickname: ; b132 + ds 11 +BoxMon18Nickname: ; b13d + ds 11 +BoxMon19Nickname: ; b148 + ds 11 +BoxMon20Nickname: ; b153 + ds 11 + From 35a16b4860f6fe138227bccda3e7a876c7d7ca0e Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 22 Aug 2013 15:40:00 -0400 Subject: [PATCH 05/96] Party/BoxMon nickname enders --- wram.asm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wram.asm b/wram.asm index b2128ec54..93eb636b0 100644 --- a/wram.asm +++ b/wram.asm @@ -1982,6 +1982,7 @@ PartyMon5Nickname: ; de6d ds 11 PartyMon6Nickname: ; de78 ds 11 +PartyMonNicknamesEnd SECTION "Pokedex",WRAMX[$de99],BANK[1] PokedexSeen: ; de99 @@ -2271,4 +2272,5 @@ BoxMon19Nickname: ; b148 ds 11 BoxMon20Nickname: ; b153 ds 11 +BoxMonNicknamesEnd From 8105dc6c7ce2197a4c0e74680a2bf78e60664dad Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 22 Aug 2013 15:40:21 -0400 Subject: [PATCH 06/96] BoxMons in main.asm --- main.asm | 171 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 94 insertions(+), 77 deletions(-) diff --git a/main.asm b/main.asm index 73f9d5db4..82d78b5b6 100644 --- a/main.asm +++ b/main.asm @@ -15271,7 +15271,7 @@ Function5bae: ; 5bae call Function5ca6 ld a, $1 call GetSRAMBank - ld hl, $ad10 + ld hl, BoxCount call Function5ca1 call CloseSRAM ld hl, NumItems @@ -22813,39 +22813,41 @@ INCBIN "baserom.gbc", $da96, $dcb6 - $da96 Functiondcb6: ; dcb6 + ld a, b - ld hl, $ad26 - ld bc, $0020 + ld hl, BoxMons + ld bc, BoxMon2 - BoxMon1 call AddNTimes ld b, h ld c, l - ld hl, $0017 + ld hl, BoxMon1PP - BoxMon1 add hl, bc push hl push bc ld de, TempMonPP - ld bc, $0004 + ld bc, NUM_MOVES call CopyBytes pop bc - ld hl, $0002 + ld hl, BoxMon1Moves - BoxMon1 add hl, bc push hl - ld de, TempMonMove1 - ld bc, $0004 + ld de, TempMonMoves + ld bc, NUM_MOVES call CopyBytes pop hl pop de + ld a, [$cfa9] push af ld a, [MonType] push af - ld b, $0 + ld b, 0 .asm_dcec ld a, [hli] and a jr z, .asm_dd18 ld [TempMonMove1], a - ld a, $2 + ld a, BOXMON ld [MonType], a ld a, b ld [$cfa9], a @@ -22867,7 +22869,7 @@ Functiondcb6: ; dcb6 inc de inc b ld a, b - cp $4 + cp NUM_MOVES jr c, .asm_dcec .asm_dd18 @@ -22878,15 +22880,16 @@ Functiondcb6: ; dcb6 ret ; dd21 + INCBIN "baserom.gbc", $dd21, $de6e - $dd21 Functionde6e: ; de6e - ld a, $1 + ld a, 1 ; BANK(BoxCount) call GetSRAMBank - ld de, $ad10 + ld de, BoxCount ld a, [de] - cp $14 + cp 20 jp nc, Functiondf42 inc a ld [de], a @@ -22903,21 +22906,21 @@ Functionde6e: ; de6e inc a jr nz, .asm_de85 call GetBaseData - call Functiondf47 + call ShiftBoxMon ld hl, PlayerName - ld de, $afa6 - ld bc, $000b + ld de, BoxMonOT + ld bc, BoxMon2OT - BoxMon1OT call CopyBytes ld a, [CurPartySpecies] ld [$d265], a call GetPokemonName - ld de, $b082 + ld de, BoxMon1Nickname ld hl, StringBuffer1 - ld bc, $000b + ld bc, BoxMon2Nickname - BoxMon1Nickname call CopyBytes - ld hl, EnemyMonSpecies - ld de, $ad26 - ld bc, $0006 + ld hl, EnemyMon + ld de, BoxMon1 + ld bc, 6 ; species + item + moves call CopyBytes ld hl, PlayerID ld a, [hli] @@ -22973,9 +22976,9 @@ Functionde6e: ; de6e dec a call SetSeenAndCaughtMon ld a, [CurPartySpecies] - cp $c9 + cp UNOWN jr nz, .asm_df20 - ld hl, $ad3b + ld hl, BoxMon1DVs ld a, $2d call Predef ld hl, $7a18 @@ -22983,15 +22986,15 @@ Functionde6e: ; de6e rst FarCall .asm_df20 - ld hl, $ad28 + ld hl, BoxMon1Moves ld de, TempMonMove1 - ld bc, $0004 + ld bc, NUM_MOVES call CopyBytes - ld hl, $ad3d + ld hl, BoxMon1PP ld de, TempMonPP - ld bc, $0004 + ld bc, NUM_MOVES call CopyBytes - ld b, $0 + ld b, 0 call Functiondcb6 call CloseSRAM scf @@ -23004,44 +23007,51 @@ Functiondf42: ; df42 ret ; df47 -Functiondf47: ; df47 - ld hl, $afa6 - ld bc, $000b - call $5f5f - ld hl, $b082 - ld bc, $000b - call $5f5f - ld hl, $ad26 - ld bc, $0020 - ld a, [$ad10] - cp $2 +ShiftBoxMon: ; df47 + ld hl, BoxMonOT + ld bc, BoxMon2OT - BoxMon1OT + call .asm_df5f + + ld hl, BoxMonNicknames + ld bc, BoxMon2Nickname - BoxMon1Nickname + call .asm_df5f + + ld hl, BoxMons + ld bc, BoxMon2 - BoxMon1 + +.asm_df5f + ld a, [BoxCount] + cp 2 ret c + push hl call AddNTimes dec hl ld e, l ld d, h pop hl - ld a, [$ad10] + + ld a, [BoxCount] dec a call AddNTimes dec hl + push hl - ld a, [$ad10] + ld a, [BoxCount] dec a - ld hl, $0000 + ld hl, 0 call AddNTimes ld c, l ld b, h pop hl -.asm_df83 +.loop ld a, [hld] ld [de], a dec de dec bc ld a, c or b - jr nz, .asm_df83 + jr nz, .loop ret ; df8c @@ -23138,13 +23148,16 @@ INCBIN "baserom.gbc", $e035, $e039 - $e035 Functione039: ; e039 + ld hl, PartyCount + ld a, [$d10b] and a jr z, .asm_e04a - ld a, $1 + + ld a, 1 ; BANK(BoxCount) call GetSRAMBank - ld hl, $ad10 + ld hl, BoxCount .asm_e04a ld a, [hl] @@ -23152,7 +23165,7 @@ Functione039: ; e039 ld [hli], a ld a, [CurPartyMon] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld e, l ld d, h @@ -23168,7 +23181,7 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e06d - ld hl, $afa6 + ld hl, BoxMonOT ld d, $13 .asm_e06d @@ -23178,7 +23191,7 @@ Functione039: ; e039 cp d jr nz, .asm_e07e ld [hl], $ff - jp $60f0 + jp .asm_60f0 .asm_e07e ld d, h @@ -23189,17 +23202,17 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e090 - ld bc, $b082 - + ld bc, BoxMonNicknames .asm_e090 call CopyDataUntil - ld hl, PartyMon1Species - ld bc, $0030 + + ld hl, PartyMons + ld bc, PartyMon2 - PartyMon1 ld a, [$d10b] and a jr z, .asm_e0a5 - ld hl, $ad26 - ld bc, $0020 + ld hl, BoxMons + ld bc, BoxMon2 - BoxMon1 .asm_e0a5 ld a, [CurPartyMon] @@ -23209,13 +23222,13 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e0bc - ld bc, $0020 + ld bc, BoxMon2 - BoxMon1 add hl, bc - ld bc, $afa6 + ld bc, BoxMonOT jr .asm_e0c3 .asm_e0bc - ld bc, $0030 + ld bc, PartyMon2 - PartyMon1 add hl, bc ld bc, PartyMon1OT @@ -23225,24 +23238,26 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e0d2 - ld hl, $b082 + ld hl, BoxMonNicknames .asm_e0d2 - ld bc, $000b + ld bc, BoxMon2Nickname - BoxMon1Nickname ld a, [CurPartyMon] call AddNTimes ld d, h ld e, l - ld bc, $000b + ld bc, BoxMon2Nickname - BoxMon1Nickname add hl, bc - ld bc, $de83 + ld bc, PartyMonNicknamesEnd ld a, [$d10b] and a jr z, .asm_e0ed - ld bc, $b15e + ld bc, BoxMonNicknamesEnd .asm_e0ed call CopyDataUntil + +.asm_60f0 ld a, [$d10b] and a jp nz, CloseSRAM @@ -24234,22 +24249,22 @@ Functionf8ec: ; f8ec push af ld a, [MonType] and a - ld hl, PartyMon1Move1 - ld bc, $0030 + ld hl, PartyMon1Moves + ld bc, PartyMon2 - PartyMon1 jr z, .asm_f91a - ld hl, OTPartyMon1Move1 + ld hl, OTPartyMon1Moves dec a jr z, .asm_f91a - ld hl, TempMonMove1 + ld hl, TempMonMoves dec a jr z, .asm_f915 - ld hl, TempMonMove1 + ld hl, TempMonMoves dec a jr z, .asm_f915 - ld hl, BattleMonMove1 + ld hl, BattleMonMoves .asm_f915 - call $7969 + call Function7969 jr .asm_f91d .asm_f91a @@ -24271,7 +24286,7 @@ Functionf8ec: ; f8ec push bc ld bc, $0015 ld a, [MonType] - cp $4 + cp WILDMON jr nz, .asm_f942 ld bc, $0006 @@ -24300,6 +24315,8 @@ Functionf8ec: ; f8ec Functionf963: ; f963 ld a, [CurPartyMon] call AddNTimes + +Function7969: ; 7969 ld a, [$cfa9] ld c, a ld b, $0 @@ -53616,9 +53633,9 @@ Function508d5: ; 508d5 jr .asm_50905 .asm_508f1 - ld a, $1 + ld a, 1 ; BANK(BoxSpecies) call GetSRAMBank - ld hl, $ad11 + ld hl, BoxSpecies call .asm_50905 call CloseSRAM ret @@ -53912,13 +53929,13 @@ GetGender: ; 50bdd jr z, .PartyMon ; 2: BoxMon - ld hl, $ad26 + $15 ; BoxMon1DVs - ld bc, $20 ; BoxMon2 - BoxMon1 + ld hl, BoxMon1DVs + ld bc, BoxMon2 - BoxMon1 dec a jr z, .BoxMon ; 3: Unknown - ld hl, TempMonDVs ; DVBuffer + ld hl, TempMonDVs dec a jr z, .DVs From ac7b7ede0bacd35af3ef3ce77cbfc35e317f67fb Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 22 Aug 2013 18:48:20 -0400 Subject: [PATCH 07/96] more bank 0 labels instead of static addresses --- main.asm | 97 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/main.asm b/main.asm index 82d78b5b6..01338f38c 100644 --- a/main.asm +++ b/main.asm @@ -732,7 +732,7 @@ Function75f: ; 75f .asm_763 ld a, [hl] ld [$ffcd], a - call $078a + call Function78a push bc ld b, a inc hl @@ -780,9 +780,9 @@ Function78a: ; 78a ld a, [$ffcb] cp $1 jr nz, .asm_7c0 - call $082b + call Function82b jr z, .asm_7c0 - call $0825 + call .asm_825 push hl ld hl, $cf5c inc [hl] @@ -792,9 +792,9 @@ Function78a: ; 78a .asm_7b7 pop hl - call $082b + call Function82b jr nz, .asm_79b - jp $0833 + jp Function833 .asm_7c0 ld a, [rIE] @@ -832,7 +832,7 @@ Function78a: ; 78a ld a, [$ffce] cp $fe ret nz - call $082b + call Function82b jr z, .asm_813 push hl ld hl, $cf5c @@ -845,8 +845,8 @@ Function78a: ; 78a .asm_80d pop hl - call $082b - jr z, .asm_833 + call Function82b + jr z, Function833 .asm_813 ld a, [rIE] @@ -857,22 +857,26 @@ Function78a: ; 78a ld a, [hl] ld [$ffcd], a call DelayFrame - jp $078a + jp Function78a +.asm_825 ld a, $f .asm_827 dec a jr nz, .asm_827 ret +; 82b +Function82b: ; 82b push hl ld hl, $cf5b ld a, [hli] or [hl] pop hl ret +; 833 -.asm_833 +Function833: ; 833 dec a ld [$cf5b], a ld [$cf5c], a @@ -925,9 +929,9 @@ Function87d: ; 87d ld a, $ff ld [$cf52], a .asm_882 - call $08c1 + call Function8c1 call DelayFrame - call $082b + call Function82b jr z, .asm_89e push hl ld hl, $cf5c @@ -938,7 +942,7 @@ Function87d: ; 87d jr nz, .asm_89d pop hl xor a - jp $0833 + jp Function833 .asm_89d pop hl @@ -950,13 +954,13 @@ Function87d: ; 87d ld b, $a .asm_8a6 call DelayFrame - call $08c1 + call Function8c1 dec b jr nz, .asm_8a6 ld b, $a .asm_8b1 call DelayFrame - call $0908 + call Function908 dec b jr nz, .asm_8b1 ld a, [$cf52] @@ -978,7 +982,7 @@ Function8c1: ; 8c1 ld b, $80 .asm_8d7 - call $08f3 + call Function8f3 ld a, [$cf56] add b ld [$ffcd], a @@ -991,7 +995,7 @@ Function8c1: ; 8c1 ld [rSC], a .asm_8ee - call $08f3 + call Function8f3 pop bc ret ; 8f3 @@ -1084,7 +1088,7 @@ Functiona46: ; a46 ld a, $1 ld [hOAMUpdate], a call WaitBGMap - call $0a36 + call Functiona36 pop af ld [hOAMUpdate], a ret @@ -1135,7 +1139,7 @@ Functiona80: ; a80 .asm_a8d push hl ld hl, $c606 - call $0b06 + call Functionb06 pop hl call Functiona57 ld a, [$ffa9] @@ -4663,7 +4667,7 @@ Function2147: ; 2147 Function2173: ; 2173 call Function217a - call $0db1 + call Functiondb1 ret ; 217a @@ -6564,16 +6568,19 @@ Function2b3c: ; 2b3c call Function2bae call Function1ad2 call Function1d7d - call $0d90 - jr .asm_2b5c + call Functiond90 + jr Function2b5c +; 2b4c +Function2b4c: ; 2b4c call WhiteBGMap call Function1d7d call Function2bae call Function1ad2 - call $0d90 + call Functiond90 +; 2b5c -.asm_2b5c +Function2b5c: ; 2b5c ld b, $9 call GetSGBLayout ld a, $12 @@ -6621,7 +6628,7 @@ Function2bae: ; 2bae ld a, $5 ld hl, $4168 rst FarCall - call $0e51 + call Functione51 call Functione5f ld a, [hROMBank] push af @@ -8188,6 +8195,8 @@ Function31be: ; 31be Function31cd: ; 31cd ld a, [hROMBank] + +Function31cf: ; 31cf ld [$d0e8], a ld a, l ld [$d0e9], a @@ -15172,7 +15181,7 @@ Function5b44: ; 5b44 ld [$ffde], a call ClearTileMap call Functione5f - call $0e51 + call Functione51 call Function1fbf ret ; 5b54 @@ -15589,7 +15598,7 @@ Function5e34: ; 5e34 ; 5e48 Function5e48: ; 5e48 - call $06e3 + call Function6e3 and $80 jr z, .asm_5e5b ld a, $8 @@ -15628,7 +15637,7 @@ Function5e5d: ; 5e5d ; 5e85 Function5e85: ; 5e85 - call $06e3 + call Function6e3 and $80 jr z, .asm_5e93 ld de, $0408 @@ -15798,7 +15807,7 @@ OakSpeech: ; 0x5f99 ld a, $24 ld hl, $4672 rst FarCall - call $04dd + call Function4dd call ClearTileMap ld de, MUSIC_ROUTE_30 @@ -16586,7 +16595,7 @@ Function64cd: ; 64cd ld a, $90 ld [hWY], a call Function2e31 - call $0e51 + call Functione51 ret ; 64db @@ -18719,7 +18728,7 @@ Function831e: ; 831e call Function1b3f ld a, [CurFruit] dec a - jr z, .asm_833b + jr z, Function833b ld a, [$ffe0] ld b, a ld c, $0 @@ -18727,7 +18736,7 @@ Function831e: ; 831e call Function8341 call Function1b35 -.asm_833b +Function833b ld a, $47 call Function1b3f ret @@ -25027,7 +25036,7 @@ INCBIN "baserom.gbc", $11bf7, $11c51 - $11bf7 Function11c51: ; 11c51 call ClearSprites callab Function8cf53 - call $0e51 + call Functione51 call Functione5f ld de, $5e65 ld hl, $8eb0 @@ -25359,7 +25368,7 @@ StartMenu: ; 125cd call MenuFunc_1e7f call .DrawBugContestStatus call Function1ad2 - call $0d90 + call Functiond90 call $2b5c ret ; 126d3 @@ -25629,7 +25638,7 @@ StartMenu_Quit: ; 128f0 jr c, .asm_12903 ld a, $4 ld hl, $760b - call $31cf + call Function31cf ld a, 4 ret .asm_12903 @@ -27591,7 +27600,7 @@ Function1409b: ; 1409b ; 140ae Function140ae: ; 140ae - call $06e3 + call Function6e3 ld c, a and $c0 jr nz, .asm_140c8 @@ -32999,7 +33008,7 @@ Function24528: ; 24528 call Function2173 call Function321c call Function1ad2 - call $0e51 + call Functione51 ret ; 24547 @@ -47571,7 +47580,7 @@ Function414b7: ; 414b7 ; 414fb Function414fb: ; 414fb - call $0e51 + call Functione51 ld hl, VTiles1 ld bc, $0800 .asm_41504 @@ -49574,7 +49583,7 @@ Function49e09: ; 49e09 Function49e27: ; 49e27 - call $06e3 + call Function6e3 and $80 jr nz, .asm_49e39 ld hl, $c5b8 @@ -49593,7 +49602,7 @@ Function49e3d: ; 49e3d ld a, [$cfcd] and a ret z - call $06e3 + call Function6e3 and $80 jp nz, Function49e75 call UpdateTime @@ -49668,7 +49677,7 @@ Function49ed0: ; 49ed0 ld [$ffde], a call ClearTileMap call Functione5f - call $0e51 + call Functione51 call Function1fbf ret ; 49ee0 @@ -51948,7 +51957,7 @@ Function4e881: ; 4e881 call ClearTileMap call ClearSprites call DisableLCD - call $0e51 + call Functione51 call $0e58 ld hl, VBGMap0 ld bc, VBlank5 @@ -51977,7 +51986,7 @@ Function4e8c2: ; 4e8c2 call ClearTileMap call ClearSprites call DisableLCD - call $0e51 + call Functione51 call $0e58 ld hl, VBGMap0 ld bc, VBlank5 @@ -73015,7 +73024,7 @@ Function17c000: ; 17c000 ld bc, $0310 xor a call ByteFill - call $0e51 + call Functione51 call Functione5f ld hl, $4b83 ld de, TileMap From 849e5a7d0fe432944a2ad3722f72144b5f89cefa Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 23 Aug 2013 01:10:55 -0400 Subject: [PATCH 08/96] game freak presents splash --- main.asm | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/main.asm b/main.asm index 01338f38c..e89385b28 100644 --- a/main.asm +++ b/main.asm @@ -65753,8 +65753,8 @@ Functione465e: ; e465e Functione4670: ; e4670 ld a, [$cf63] ld e, a - ld d, $0 - ld hl, $467f + ld d, 0 + ld hl, .pointers add hl, de add hl, de ld a, [hli] @@ -65763,7 +65763,90 @@ Functione4670: ; e4670 jp [hl] ; e467f -INCBIN "baserom.gbc", $e467f, $e48ac - $e467f +.pointers + dw Functione468c + dw Functione468d + dw Functione46ba + dw Functione46dd +; e4687 + +Functione4687: ; e4687 + ld hl, $cf63 + inc [hl] + ret +; e468c + +Functione468c: ; e468c + ret +; e468d + +Functione468d: ; e468d + ld hl, $cf65 + ld a, [hl] + cp $20 + jr nc, .asm_e4697 + inc [hl] + ret + +.asm_e4697 + ld [hl], 0 + ld hl, .GAME_FREAK + decoord 5, 10 + ld bc, .end - .GAME_FREAK + call CopyBytes + call Functione4687 + ld de, SFX_GAME_FREAK_PRESENTS + call StartSFX + ret +; e46af + +.GAME_FREAK + ; G A M E _ F R E A K + db 0, 1, 2, 3, 13, 4, 5, 3, 1, 6 +.end + db "@" +; e46ba + +Functione46ba: ; e46ba + ld hl, $cf65 + ld a, [hl] + cp $40 + jr nc, .asm_e46c4 + inc [hl] + ret + +.asm_e46c4 + ld [hl], 0 + ld hl, .presents + decoord 7,11 + ld bc, .end - .presents + call CopyBytes + call Functione4687 + ret +; e46d6 + +.presents + db 7, 8, 9, 10, 11, 12 +.end + db "@" +; e46dd + +Functione46dd: ; e46dd + ld hl, $cf65 + ld a, [hl] + cp $80 + jr nc, .asm_e46e7 + inc [hl] + ret + +.asm_e46e7 + ld hl, $cf63 + set 7, [hl] + ret +; e46ed + + +INCBIN "baserom.gbc", $e46ed, $e48ac - $e46ed Functione48ac: ; e48ac @@ -65776,6 +65859,8 @@ Functione48ac: ; e48ac ld a, [$ff9e] push af call Functione4901 + +Functione48bc: ; e48bc call Functiona57 ld a, [$ffa9] and $f @@ -65786,7 +65871,7 @@ Functione48ac: ; e48ac call Functione490f callba Function8cf69 call DelayFrame - jp $48bc + jp Functione48bc .asm_e48db ld de, $0000 From bc7b63b44a2d57d4cd67e4470fa88fbe6e303218 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 23 Aug 2013 15:00:07 -0400 Subject: [PATCH 09/96] EventFlags label (bittable1) --- main.asm | 2 +- wram.asm | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/main.asm b/main.asm index e89385b28..34e001ffe 100644 --- a/main.asm +++ b/main.asm @@ -7267,7 +7267,7 @@ Function2e5d: ; 2e5d BitTable1Func: ; 0x2e6f - ld hl, $da72 + ld hl, EventFlags call BitTableFunc ret diff --git a/wram.asm b/wram.asm index 93eb636b0..15e5dbfd6 100644 --- a/wram.asm +++ b/wram.asm @@ -1753,23 +1753,20 @@ UndergroundSwitchPositions: ; d963 FarfetchdPosition: ; d964 ds 1 ; which position the ilex farfetch'd is in -SECTION "Events",WRAMX[$dad4],BANK[1] +SECTION "Events",WRAMX[$da72],BANK[1] +EventFlags: ; da72 ;RoomDecorations: ; dac6 -; db 7 - -HoOhEvent: ; dad4 - ds 1 -LugiaEvent: ; dad5 - ds 1 - -; TODO +;HoOhEvent: ; dad4 +;LugiaEvent: ; dad5 ;SuicuneEvent: ; dad8 (tin tower) ;TeamRocketAzaleaTownAttackEvent: ; db51 ;SudowoodoEvent: ; db51 ;PoliceAtElmsLabEvent: ; db52 ;SalesmanMahoganyTownEvent: ; db5c ;RedGyaradosEvent: ; db5c + ds 250 +; db6c SECTION "BoxNames",WRAMX[$db75],BANK[1] ; 8 chars + $50 From 3a24cff5eb7ae82b6f9ee8ac24e64496adab7a7e Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 23 Aug 2013 15:48:26 -0400 Subject: [PATCH 10/96] BitTableFunc -> FlagAction --- engine/scripting.asm | 10 +++++----- main.asm | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index 79fbe69ee..68487a49d 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -843,7 +843,7 @@ Script_trainerstatus: ; 0x97132 ld d, [hl] call GetScriptByte ld b, a - call BitTable1Func + call EventFlagAction ld a, c and a ret z @@ -1256,7 +1256,7 @@ Unknown_0x9730b: ; 0x9730b xor a ret .asm_97321 - call BitTable1Func + call EventFlagAction ret ; 0x97325 @@ -2677,7 +2677,7 @@ Script_setbit1: ; 0x97988 call GetScriptByte ld d, a ld b, $1 - call BitTable1Func + call EventFlagAction ret ; 0x97996 @@ -2691,7 +2691,7 @@ Script_clearbit1: ; 0x97996 call GetScriptByte ld d, a ld b, $0 - call BitTable1Func + call EventFlagAction ret ; 0x979a4 @@ -2705,7 +2705,7 @@ Script_checkbit1: ; 0x979a4 call GetScriptByte ld d, a ld b, $2 - call BitTable1Func + call EventFlagAction ld a, c and a jr z, .asm_979b7 ; 0x979b3 $2 diff --git a/main.asm b/main.asm index 34e001ffe..da9ca74cd 100644 --- a/main.asm +++ b/main.asm @@ -7266,12 +7266,12 @@ Function2e5d: ; 2e5d ; 2e6f -BitTable1Func: ; 0x2e6f +EventFlagAction: ; 0x2e6f ld hl, EventFlags - call BitTableFunc + call FlagAction ret -BitTableFunc: ; 0x2e76 +FlagAction: ; 0x2e76 ; Perform a function on a bit in memory. ; inputs: @@ -9224,7 +9224,7 @@ CheckTrainerBattle: ; 360d inc hl ld d, [hl] ld b, CHECK_FLAG - call BitTable1Func + call EventFlagAction ld a, c pop de pop bc @@ -9379,7 +9379,7 @@ Function36f5: ; 36f5 ld e, l push de ld b, $2 - call BitTable1Func + call EventFlagAction pop de ld a, c and a @@ -30776,7 +30776,7 @@ Function15cef: ; 15cef ld d, $0 ld b, $1 ld hl, WalkingDirection - call BitTableFunc + call FlagAction call Function15fc3 ld de, Money ld bc, $ffc3 @@ -30838,7 +30838,7 @@ Function15da5: ; 15da5 ld d, $0 ld b, $2 ld hl, WalkingDirection - call BitTableFunc + call FlagAction ld a, c and a jr nz, .asm_15dd8 @@ -34862,7 +34862,7 @@ Function26a3b: ; 26a3b push bc call Function26a30 pop bc - call BitTable1Func + call EventFlagAction ret ; 26a44 @@ -48336,7 +48336,7 @@ GetFruitTreeFlag: ; 44078 ld e, a ld d, 0 ld hl, FruitTreeFlags - call BitTableFunc + call FlagAction pop de pop hl ret @@ -56916,7 +56916,7 @@ SpecialHoOhChamber: ; 0x8addb call GetSecondaryMapHeaderPointer ld de, $0326 ld b, $1 - call BitTable1Func + call EventFlagAction .done ret ; 0x8adef @@ -56935,7 +56935,7 @@ Function8ae30: ; 8ae30 jr nz, .asm_8ae4a ld de, $0329 ld b, $1 - call BitTable1Func + call EventFlagAction scf jr .asm_8ae4b @@ -60459,7 +60459,7 @@ CheckSignFlag: ; 96ad8 ld e, l ld d, h ld b, $2 - call BitTable1Func + call EventFlagAction ld a, c and a pop hl @@ -63124,7 +63124,7 @@ Functionb8172: ; b8172 ld d, h ld e, l ld b, $2 - call BitTable1Func + call EventFlagAction ld a, c and a jr z, .asm_b81df From af205a72170526ea098da0e4e7b013ecad74af8e Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 23 Aug 2013 16:06:43 -0400 Subject: [PATCH 11/96] BitTable2 -> EngineFlags --- engine/{bittable2.asm => engine_flags.asm} | 0 main.asm | 39 +++++++++++----------- 2 files changed, 19 insertions(+), 20 deletions(-) rename engine/{bittable2.asm => engine_flags.asm} (100%) diff --git a/engine/bittable2.asm b/engine/engine_flags.asm similarity index 100% rename from engine/bittable2.asm rename to engine/engine_flags.asm diff --git a/main.asm b/main.asm index da9ca74cd..757619ad8 100644 --- a/main.asm +++ b/main.asm @@ -7343,7 +7343,7 @@ FlagAction: ; 0x2e76 Function2ead: ; 2ead ld de, $000b ld b, $2 - callba GetFlag2 + callba EngineFlagAction ld a, c and a ret @@ -18031,7 +18031,7 @@ SpecialGiveShuckle: ; 7305 ld de, SpecialShuckleOT call CopyName2 -; Bittable2 flag for this event. +; Engine flag for this event. ld hl, $dc1e set 5, [hl] @@ -20764,12 +20764,11 @@ GetPartyNick: ; c706 ret ; c721 -CheckFlag2: ; c721 -; using bittable2 -; check flag id in de -; return carry if flag is not set +CheckEngineFlag: ; c721 +; Check engine flag de +; Return carry if flag is not set ld b, $02 ; check flag - callba GetFlag2 + callba EngineFlagAction ld a, c and a jr nz, .isset @@ -20782,7 +20781,7 @@ CheckFlag2: ; c721 CheckBadge: ; c731 ; input: a = badge flag id ($1b-$2b) - call CheckFlag2 + call CheckEngineFlag ret nc ld hl, BadgeRequiredText call Function1d67 ; push text to queue @@ -21136,7 +21135,7 @@ TrySurfOW: ; c9e7 jr c, .quit ld de, $1e ; FLAG_FOG_BADGE - call CheckFlag2 + call CheckEngineFlag jr c, .quit ld d, SURF @@ -21341,7 +21340,7 @@ TryWaterfallOW: ; cb56 call CheckPartyMove jr c, .asm_cb74 ld de, $0022 - call CheckFlag2 + call CheckEngineFlag jr c, .asm_cb74 call Functioncb07 jr c, .asm_cb74 @@ -21534,7 +21533,7 @@ TryWhirlpoolOW: ; ce3e call CheckPartyMove jr c, .asm_ce5c ld de, $0021 - call CheckFlag2 + call CheckEngineFlag jr c, .asm_ce5c call Functioncdde jr c, .asm_ce5c @@ -21780,7 +21779,7 @@ TryCutOW: ; d186 call CheckPartyMove jr c, .asm_d19f ld de, $001c - call CheckFlag2 + call CheckEngineFlag jr c, .asm_d19f ld a, BANK(UnknownScript_0xd1a9) ld hl, UnknownScript_0xd1a9 @@ -55472,8 +55471,8 @@ Function80422: ; 80422 -GetFlag2: ; 80430 -; Do action b on flag de from BitTable2 +EngineFlagAction: ; 80430 +; Do action b on engine flag de ; ; b = 0: reset flag ; = 1: set flag @@ -55491,8 +55490,8 @@ GetFlag2: ; 80430 jr c, .read ; cp 0 can't set carry! jr .invalid -; There are only $a2 flags in BitTable2, so anything beyond that -; is invalid too. +; There are only $a2 engine flags, so +; anything beyond that is invalid too. .ceiling ld a, e @@ -55506,10 +55505,10 @@ GetFlag2: ; 80430 ld e, a ld d, a -; Read BitTable2 for this flag's location. +; Get this flag's location. .read - ld hl, BitTable2 + ld hl, EngineFlags ; location add hl, de add hl, de @@ -55557,8 +55556,8 @@ GetFlag2: ; 80430 ; 80462 -BitTable2: ; 80462 -INCLUDE "engine/bittable2.asm" +EngineFlags: ; 80462 +INCLUDE "engine/engine_flags.asm" ; 80648 From 744d1d8599825ecdea6879c315ced75cbc2c9b60 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 23 Aug 2013 21:19:58 -0400 Subject: [PATCH 12/96] first event flag constants --- constants.asm | 1 + constants/event_flags.asm | 6 ++++++ wram.asm | 4 ---- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 constants/event_flags.asm diff --git a/constants.asm b/constants.asm index e929a48f2..4013bf74d 100644 --- a/constants.asm +++ b/constants.asm @@ -13,6 +13,7 @@ INCLUDE "constants/map_constants.asm" INCLUDE "constants/item_constants.asm" INCLUDE "constants/trainer_constants.asm" INCLUDE "constants/script_constants.asm" +INCLUDE "constants/event_flags.asm" INCLUDE "constants/music_constants.asm" diff --git a/constants/event_flags.asm b/constants/event_flags.asm new file mode 100644 index 000000000..a533761fb --- /dev/null +++ b/constants/event_flags.asm @@ -0,0 +1,6 @@ +EVENT_FOUGHT_SUDOWOODO EQU $02a +EVENT_FOUGHT_HO_OH EQU $317 +EVENT_FOUGHT_LUGIA EQU $318 +EVENT_FOUGHT_SUICUNE EQU $335 +EVENT_FOUGHT_SNORLAX EQU $750 + diff --git a/wram.asm b/wram.asm index 15e5dbfd6..619bf42b5 100644 --- a/wram.asm +++ b/wram.asm @@ -1757,11 +1757,7 @@ SECTION "Events",WRAMX[$da72],BANK[1] EventFlags: ; da72 ;RoomDecorations: ; dac6 -;HoOhEvent: ; dad4 -;LugiaEvent: ; dad5 -;SuicuneEvent: ; dad8 (tin tower) ;TeamRocketAzaleaTownAttackEvent: ; db51 -;SudowoodoEvent: ; db51 ;PoliceAtElmsLabEvent: ; db52 ;SalesmanMahoganyTownEvent: ; db5c ;RedGyaradosEvent: ; db5c From 18e42e8c6e1825b00958c1a8813d377ad36c9e07 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 24 Aug 2013 04:09:32 -0400 Subject: [PATCH 13/96] battle init and battle transition predefs --- constants.asm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/constants.asm b/constants.asm index 4013bf74d..ccaead73f 100644 --- a/constants.asm +++ b/constants.asm @@ -232,6 +232,7 @@ PREDEF_PRINT_MOVE_DESCRIPTION EQU $11 PREDEF_UPDATE_PLAYER_HUD EQU $12 PREDEF_FILL_BOX EQU $13 PREDEF_UPDATE_ENEMY_HUD EQU $15 +PREDEF_START_BATTLE EQU $16 PREDEF_FILL_IN_EXP_BAR EQU $17 PREDEF_FILLMOVES EQU $1B PREDEF_GET_GENDER EQU $24 @@ -244,6 +245,7 @@ PREDEF_PRINT_TYPE EQU $2B PREDEF_GET_UNOWN_LETTER EQU $2D PREDEF_LOAD_SGB_LAYOUT EQU $31 PREDEF_CHECK_CONTEST_MON EQU $33 +PREDEF_BATTLE_TRANSITION EQU $34 PREDEF_PARTYMON_ITEM_NAME EQU $3B PREDEF_DECOMPRESS EQU $40 From 17725d7af1d55b4a23659d4b8d3ff3925979e7e6 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 24 Aug 2013 04:10:38 -0400 Subject: [PATCH 14/96] battle init and some overworld actions --- engine/scripting.asm | 6 +- main.asm | 444 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 407 insertions(+), 43 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index 68487a49d..0676c8681 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -1497,9 +1497,9 @@ Script_loadtrainer: ; 0x97424 Script_startbattle: ; 0x97436 ; script command 0x5f - call $2879 - ld a, $16 - call $2d83 + call Function2879 + ld a, PREDEF_START_BATTLE + call Predef ld a, [$d0ee] and $3f ld [$c2dd], a diff --git a/main.asm b/main.asm index 757619ad8..23107a577 100644 --- a/main.asm +++ b/main.asm @@ -19156,7 +19156,7 @@ PredefPointers: ; 856b dwb FillBox, BANK(FillBox) dwb Function3d873, BANK(Function3d873) dwb Function3e036, BANK(Function3e036) ; UpdateEnemyHUD - dwb Function3f4c1, BANK(Function3f4c1) + dwb StartBattle, BANK(StartBattle) dwb FillInExpBar, BANK(FillInExpBar) dwb Function3f43d, BANK(Function3f43d) dwb Function3f47c, BANK(Function3f47c) @@ -19186,7 +19186,7 @@ PredefPointers: ; 856b dwb $464c, $02 ; LoadSGBLayout, BANK(LoadSGBLayout) dwb $5d11, $24 dwb CheckContestMon, BANK(CheckContestMon) - dwb $420f, $23 + dwb Function8c20f, BANK(Function8c20f) dwb $4000, $23 dwb $4000, $23 dwb Functioncc0d6, BANK(Functioncc0d6) @@ -21679,6 +21679,7 @@ Functioncf8e: ; cf8e ret ; cfa5 + INCBIN "baserom.gbc", $cfa5, $d0b3 - $cfa5 @@ -27368,7 +27369,7 @@ Function1353f: ; 1353f push hl ld a, [$d041] ld e, a - ld d, $0 + ld d, 0 ld hl, $d0f1 add hl, de ld a, [hl] @@ -27392,8 +27393,8 @@ Function1356b: ; 1356b Function13575: ; 13575 push de ld e, a - ld d, $0 - ld hl, $7583 + ld d, 0 + ld hl, .floors add hl, de add hl, de ld a, [hli] @@ -27403,7 +27404,60 @@ Function13575: ; 13575 ret ; 13583 -INCBIN "baserom.gbc", $13583, $135eb - $13583 +.floors + dw .b4f + dw .b3f + dw .b2f + dw .b1f + dw ._1f + dw ._2f + dw ._3f + dw ._4f + dw ._5f + dw ._6f + dw ._7f + dw ._8f + dw ._9f + dw ._10f + dw ._11f + dw .roof + +.b4f + db "B4F@" +.b3f + db "B3F@" +.b2f + db "B2F@" +.b1f + db "B1F@" +._1f + db "1F@" +._2f + db "2F@" +._3f + db "3F@" +._4f + db "4F@" +._5f + db "5F@" +._6f + db "6F@" +._7f + db "7F@" +._8f + db "8F@" +._9f + db "9F@" +._10f + db "10F@" +._11f + db "11F@" +.roof + db "ROOF@" +; 135db + + +INCBIN "baserom.gbc", $135db, $135eb - $135db UnknownScript_0x135eb: ; 0x135eb writecode $3, $6 @@ -27418,7 +27472,7 @@ UnknownScript_0x135eb: ; 0x135eb INCBIN "baserom.gbc", $135f8, $13603 - $135f8 UnknownScript_0x13603: ; 0x13603 - playsound $0027 + playsound SFX_ELEVATOR_END loadfont 2writetext UnknownText_0x13614 closetext @@ -27433,7 +27487,53 @@ UnknownText_0x13614: ; 0x13614 db $50 ; 0x13619 -INCBIN "baserom.gbc", $13619, $13b87 - $13619 +INCBIN "baserom.gbc", $13619, $1365b - $13619 + + +Function1365b: ; 1365b + ld a, c + ld de, .table2 - .table1 + ld hl, .table1 + call IsInArray + jr nc, .asm_1367f + + ld a, $c ; jumpstd + ld [$d03f], a + inc hl + ld a, [hli] + ld [$d03f + 1], a + ld a, [hli] + ld [$d03f + 2], a + ld a, BANK(UnknownScript_0x1369a) + ld hl, UnknownScript_0x1369a + call PushScriptPointer + scf + ret + +.asm_1367f + xor a + ret +; 13681 + +.table1 + dbw $91, $0003 ; bookshelf +.table2 + dbw $93, $0031 ; pc + dbw $94, $000b ; radio + dbw $95, $0007 ; map + dbw $96, $0006 ; merchandise + dbw $97, $0009 ; tv + dbw $9d, $0008 ; window + dbw $9f, $0005 ; incense burner + dbw $ff ; end +; 1369a + +UnknownScript_0x1369a: ; 0x1369a + 2jump $d03f +; 0x1369d + + +INCBIN "baserom.gbc", $1369d, $13b87 - $1369d GetSquareRoot: ; 13b87 @@ -35242,7 +35342,35 @@ INCBIN "baserom.gbc", $27a28, $27a2d - $27a28 SECTION "bankA",ROMX,BANK[$A] -INCBIN "baserom.gbc", $28000, $2a111 - $28000 +INCBIN "baserom.gbc", $28000, $2a0e7 - $28000 + +Function2a0e7: ; 2a0e7 + call Function2a103 + jr nc, .asm_2a0f8 + call Function2a14f + jr nz, .asm_2a0f8 + call $61df + jr nc, .asm_2a0f8 + xor a + ret + +.asm_2a0f8 + xor a + ld [$d22e], a + ld [BattleType], a + ld a, 1 + and a + ret +; 2a103 + +Function2a103: ; 2a103 + call Function2a111 + call Function2a124 + call Function2a138 + call RNG + cp b + ret +; 2a111 Function2a111: ; 2a111 ld hl, $d25a @@ -35259,7 +35387,40 @@ Function2a111: ; 2a111 ret ; 2a124 -INCBIN "baserom.gbc", $2a124, $2a14f - $2a124 +Function2a124: ; 2a124 + ld a, [CurMusic] + cp MUSIC_POKEMON_MARCH + jr z, .asm_2a135 + cp MUSIC_RUINS_OF_ALPH_RADIO + jr z, .asm_2a135 + cp MUSIC_POKEMON_LULLABY + ret nz + srl b + ret + +.asm_2a135 + sla b + ret +; 2a138 + +Function2a138: ; 2a138 + ld hl, PartyMon1Item + ld de, $0030 + ld a, [PartyCount] + ld c, a +.asm_2a142 + ld a, [hl] + cp $5e + jr z, .asm_2a14c + add hl, de + dec c + jr nz, .asm_2a142 + ret + +.asm_2a14c + srl b + ret +; 2a14f Function2a14f: ; 2a14f call Function2a200 @@ -35347,7 +35508,36 @@ Function2a14f: ; 2a14f ret ; 2a1cb -INCBIN "baserom.gbc", $2a1cb, $2a200 - $2a1cb +INCBIN "baserom.gbc", $2a1cb, $2a1df - $2a1cb + +Function2a1df: ; 2a1df + ld a, [$dca1] + and a + jr z, .asm_2a1fe + ld hl, PartyMon1CurHP + ld bc, $002f +.asm_2a1eb + ld a, [hli] + or [hl] + jr nz, .asm_2a1f2 + add hl, bc + jr .asm_2a1eb + +.asm_2a1f2 + dec hl + dec hl + dec hl + dec hl + ld a, [CurPartyLevel] + cp [hl] + jr nc, .asm_2a1fe + and a + ret + +.asm_2a1fe + scf + ret +; 2a200 Function2a200: ; 2a200 call Function1852 @@ -36530,13 +36720,14 @@ Function2ee18: ; 2ee18 ret ; 2ee2f + Function2ee2f: ; 2ee2f xor a ld [$ffde], a call DelayFrame - ld b, $6 + ld b, 6 ld hl, PartyMon1CurHP - ld de, $002f + ld de, PartyMon2 - PartyMon1 - 1 .asm_2ee3d ld a, [hli] or [hl] @@ -36546,16 +36737,14 @@ Function2ee2f: ; 2ee2f jr nz, .asm_2ee3d .asm_2ee45 - ld de, $fffd + ld de, PartyMon1Level - PartyMon1CurHP add hl, de ld a, [hl] ld [BattleMonLevel], a - ld a, $34 + ld a, PREDEF_BATTLE_TRANSITION call Predef - ld a, $f - ld hl, $6d9f - rst FarCall - ld a, $1 + callba Function3ed9f + ld a, 1 ld [hBGMapMode], a call ClearSprites call ClearTileMap @@ -36568,7 +36757,6 @@ Function2ee2f: ; 2ee2f ; 2ee6c - PlayBattleMusic: ; 2ee6c push hl @@ -46002,7 +46190,7 @@ Function3f47c: ; 3f47c ; 3f4c1 -Function3f4c1: ; 3f4c1 +StartBattle: ; 3f4c1 ld a, [PartyCount] and a ret z @@ -46046,17 +46234,17 @@ Function3f4dd: ; 3f4dd ld hl, rLCDC res 6, [hl] call Function3fb6c - call $7c8b + call BattleStartMessage ld hl, rLCDC set 6, [hl] xor a ld [hBGMapMode], a call EmptyBattleTextBox - ld hl, $c535 - ld bc, $050b + hlcoord 9, 7 + ld bc, 5 << 8 + 11 call ClearBox - ld hl, $c4a1 - ld bc, $040a + hlcoord 1, 0 + ld bc, 4 << 8 + 10 call ClearBox call ClearSprites ld a, [IsInBattle] @@ -47111,7 +47299,7 @@ Function3fc5b: ; 3fc5b ; 3fc8b -BattleStartMessage ; 3fc8b +BattleStartMessage: ; 3fc8b ld a, [IsInBattle] dec a jr z, .asm_3fcaa @@ -57555,7 +57743,179 @@ GetTimePalFade: ; 8c17c db %00000000 ; 8c20f -INCBIN "baserom.gbc", $8c20f, $8c940 - $8c20f + +Function8c20f: ; 8c20f + call $426d + ld a, [rBGP] + ld [$cfc7], a + ld a, [rOBP0] + ld [$cfc8], a + ld a, [rOBP1] + ld [$cfc9], a + call DelayFrame + ld hl, $ff9e + ld a, [hl] + push af + ld [hl], $1 +.asm_8c22b + ld a, [$cf63] + bit 7, a + jr nz, .asm_8c23a + call $4314 + call DelayFrame + jr .asm_8c22b + +.asm_8c23a + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, Unkn1Pals + ld bc, $0040 + xor a + call ByteFill + pop af + ld [rSVBK], a + ld a, $ff + ld [$cfc7], a + call DmgToCgbBGPals + call DelayFrame + xor a + ld [hLCDStatCustom], a + ld [$ffc7], a + ld [$ffc8], a + ld [hSCY], a + ld a, $1 + ld [rSVBK], a + pop af + ld [$ff9e], a + call DelayFrame + ret +; 8c26d + +Function8c26d: ; 8c26d + ld a, [InLinkBattle] + cp $4 + jr z, .asm_8c288 + callba Function6454 + call Function1ad2 + call DelayFrame + call $42a0 + call $4f4f + jr .asm_8c28b + +.asm_8c288 + call $42aa + +.asm_8c28b + ld a, $90 + ld [hWY], a + call DelayFrame + xor a + ld [hBGMapMode], a + ld hl, $cf63 + xor a + ld [hli], a + ld [hli], a + ld [hl], a + call $46d8 + ret +; 8c2a0 + +Function8c2a0: ; 8c2a0 + call $42aa + ld hl, VBGMap0 + call $42cf + ret +; 8c2aa + +Function8c2aa: ; 8c2aa + ld de, $42f4 + ld hl, $8fe0 + ld b, $23 + ld c, $2 + call Request2bpp + ld a, [rVBK] + push af + ld a, $1 + ld [rVBK], a + ld de, $42f4 + ld hl, $8fe0 + ld b, $23 + ld c, $2 + call Request2bpp + pop af + ld [rVBK], a + ret +; 8c2cf + +Function8c2cf: ; 8c2cf + ld a, [rSVBK] + push af + ld a, $6 + ld [rSVBK], a + push hl + ld hl, Unkn1Pals + ld bc, $0280 +.asm_8c2dd + ld [hl], $ff + inc hl + dec bc + ld a, c + or b + jr nz, .asm_8c2dd + pop hl + ld de, Unkn1Pals + ld b, $23 + ld c, $28 + call Request2bpp + pop af + ld [rSVBK], a + ret +; 8c2f4 + +INCBIN "baserom.gbc", $8c2f4, $8c314 - $8c2f4 + +Function8c314: ; 8c314 + ld a, [$cf63] + ld e, a + ld d, $0 + ld hl, $4323 + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + jp [hl] +; 8c323 + +INCBIN "baserom.gbc", $8c323, $8c6d8 - $8c323 + +Function8c6d8: ; 8c6d8 + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, $d100 + call $46ef + ld hl, $d200 + call $46ef + pop af + ld [rSVBK], a + ret +; 8c6ef + +Function8c6ef: ; 8c6ef + xor a + ld c, $90 +.asm_8c6f2 + ld [hli], a + dec c + jr nz, .asm_8c6f2 + ret +; 8c6f7 + +INCBIN "baserom.gbc", $8c6f7, $8c940 - $8c6f7 Function8c940: ; 8c940 ld a, e @@ -57612,7 +57972,12 @@ Function8ca0c: ; 8ca0c jp [hl] ; 8ca1b -INCBIN "baserom.gbc", $8ca1b, $8cf53 - $8ca1b +INCBIN "baserom.gbc", $8ca1b, $8cf4f - $8ca1b + +Function8cf4f: ; 8cf4f + call $3238 + ret +; 8cf53 Function8cf53: ; 8cf53 @@ -60890,9 +61255,7 @@ Function97c5f: ; 97c5f call GetFacingTileCoord ld [EngineBuffer1], a ld c, a - ld a, $4 - ld hl, $765b - rst FarCall + callba Function1365b jr c, .asm_97cb9 call CheckCutTreeTile @@ -60938,7 +61301,10 @@ Function97c5f: ; 97c5f ret ; 97cc0 + Function97cc0: ; 97cc0 +; Rock Smash encounter + call Function968c7 jr c, .asm_97ce2 call Function97cfd @@ -60946,9 +61312,7 @@ Function97cc0: ; 97cc0 ld hl, StatusFlags2 bit 2, [hl] jr nz, .asm_97cdb - ld a, $a - ld hl, $60e7 - rst FarCall + callba Function2a0e7 jr nz, .asm_97ce2 jr .asm_97ce6 @@ -60963,13 +61327,13 @@ Function97cc0: ; 97cc0 ret .asm_97ce6 - ld a, BANK(UnknownScript_0x97cf9) - ld hl, UnknownScript_0x97cf9 + ld a, BANK(RockSmashBattleScript) + ld hl, RockSmashBattleScript jr .asm_97cf4 .asm_97ced - ld a, $4 - ld hl, Script_dotrigger + ld a, BANK(UnknownScript_0x135eb) + ld hl, UnknownScript_0x135eb jr .asm_97cf4 .asm_97cf4 @@ -60978,7 +61342,7 @@ Function97cc0: ; 97cc0 ret ; 97cf9 -UnknownScript_0x97cf9: ; 97cf9 +RockSmashBattleScript: ; 97cf9 battlecheck startbattle returnafterbattle From 9cf90f6c7bf8df14eb74e22b2c48f3d446e9bef2 Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 26 Aug 2013 19:47:42 -0400 Subject: [PATCH 15/96] deobfuscate some encounter asm --- main.asm | 95 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/main.asm b/main.asm index 23107a577..4a75809d1 100644 --- a/main.asm +++ b/main.asm @@ -2743,7 +2743,7 @@ Function184a: ; 184a Function1852: ; 1852 ld a, [StandingTile] call GetTileCollision - sub $1 + sub 1 ret z and a ret @@ -35345,11 +35345,12 @@ SECTION "bankA",ROMX,BANK[$A] INCBIN "baserom.gbc", $28000, $2a0e7 - $28000 Function2a0e7: ; 2a0e7 +; Try to trigger a wild encounter. call Function2a103 jr nc, .asm_2a0f8 call Function2a14f jr nz, .asm_2a0f8 - call $61df + call Function2a1df jr nc, .asm_2a0f8 xor a ret @@ -35375,19 +35376,20 @@ Function2a103: ; 2a103 Function2a111: ; 2a111 ld hl, $d25a call Function1852 - ld a, $3 + ld a, 3 jr z, .asm_2a11e ld a, [TimeOfDay] - .asm_2a11e ld c, a - ld b, $0 + ld b, 0 add hl, bc ld b, [hl] ret ; 2a124 Function2a124: ; 2a124 +; Pokemon March and Ruins of Alph signal double encounter rate. +; Pokemon Lullaby halves encounter rate. ld a, [CurMusic] cp MUSIC_POKEMON_MARCH jr z, .asm_2a135 @@ -35404,17 +35406,18 @@ Function2a124: ; 2a124 ; 2a138 Function2a138: ; 2a138 +; Cleanse Tag halves encounter rate. ld hl, PartyMon1Item - ld de, $0030 + ld de, PartyMon2 - PartyMon1 ld a, [PartyCount] ld c, a -.asm_2a142 +.next ld a, [hl] - cp $5e + cp CLEANSE_TAG jr z, .asm_2a14c add hl, de dec c - jr nz, .asm_2a142 + jr nz, .next ret .asm_2a14c @@ -35424,9 +35427,10 @@ Function2a138: ; 2a138 Function2a14f: ; 2a14f call Function2a200 - jp nc, $61c1 + jp nc, .asm_2a1c1 call Function2a2ce - jp c, $61c9 + jp c, .asm_2a1c9 + inc hl inc hl inc hl @@ -35436,7 +35440,7 @@ Function2a14f: ; 2a14f inc hl inc hl ld a, [TimeOfDay] - ld bc, $000e + ld bc, $e call AddNTimes ld de, $61cb @@ -35444,7 +35448,7 @@ Function2a14f: ; 2a14f push hl .asm_2a175 call RNG - cp $64 + cp 100 jr nc, .asm_2a175 inc a ld b, a @@ -35459,24 +35463,25 @@ Function2a14f: ; 2a14f .asm_2a187 ld c, [hl] - ld b, $0 + ld b, 0 pop hl add hl, bc ld a, [hli] ld b, a call Function1852 jr nz, .asm_2a1aa + call RNG - cp $59 + cp 89 jr c, .asm_2a1aa inc b - cp $a5 + cp 165 jr c, .asm_2a1aa inc b - cp $d8 + cp 216 jr c, .asm_2a1aa inc b - cp $f2 + cp 242 jr c, .asm_2a1aa inc b @@ -35486,9 +35491,11 @@ Function2a14f: ; 2a14f ld b, [hl] call Function2a4a0 jr c, .asm_2a1c1 + ld a, b - cp $c9 + cp UNOWN jr nz, .asm_2a1bf + ld a, [UnlockedUnowns] and a jr z, .asm_2a1c1 @@ -35497,25 +35504,29 @@ Function2a14f: ; 2a14f jr .asm_2a1c5 .asm_2a1c1 - ld a, $1 + ld a, 1 and a ret .asm_2a1c5 ld a, b ld [$d22e], a + +.asm_2a1c9 xor a ret ; 2a1cb + INCBIN "baserom.gbc", $2a1cb, $2a1df - $2a1cb + Function2a1df: ; 2a1df ld a, [$dca1] and a jr z, .asm_2a1fe ld hl, PartyMon1CurHP - ld bc, $002f + ld bc, PartyMon2 - PartyMon1 - 1 .asm_2a1eb ld a, [hli] or [hl] @@ -35524,10 +35535,12 @@ Function2a1df: ; 2a1df jr .asm_2a1eb .asm_2a1f2 +; to PartyMonLevel dec hl dec hl dec hl dec hl + ld a, [CurPartyLevel] cp [hl] jr nc, .asm_2a1fe @@ -35544,25 +35557,26 @@ Function2a200: ; 2a200 jr z, .asm_2a21d ld hl, WildMons5 ld bc, $002f - call $623d + call .asm_2a23d ret c ld hl, WildMons1 ld de, WildMons3 - call $6235 + call .asm_2a235 ld bc, $002f jr .asm_2a27a .asm_2a21d ld hl, WildMons6 ld bc, $0009 - call $623d + call .asm_2a23d ret c ld hl, WildMons2 ld de, WildMons4 - call $6235 + call .asm_2a235 ld bc, $0009 jr .asm_2a27a +.asm_2a235 call Function2f17 and a ret z @@ -35570,7 +35584,8 @@ Function2a200: ; 2a200 ld l, e ret - call $627f +.asm_2a23d + call Function2a27f push hl ld hl, $dc20 bit 2, [hl] @@ -35582,7 +35597,7 @@ Function2a200: ; 2a200 ld a, [$dfcd] cp e jr nz, .asm_2a25c - call $6288 + call Function2a288 jr nc, .asm_2a278 scf ret @@ -35599,7 +35614,7 @@ Function2a200: ; 2a200 ld a, [$dc5b] cp e jr nz, .asm_2a278 - call $6288 + call Function2a288 jr nc, .asm_2a278 scf ret @@ -35609,16 +35624,19 @@ Function2a200: ; 2a200 ret .asm_2a27a - call $627f - jr .asm_2a288 + call Function2a27f + jr Function2a288 +; 2a27f +Function2a27f: ; 2a27f ld a, [MapGroup] ld d, a ld a, [MapNumber] ld e, a ret +; 2a288 -.asm_2a288 +Function2a288: ; 2a288 push hl ld a, [hl] inc a @@ -35634,7 +35652,7 @@ Function2a200: ; 2a200 .asm_2a296 pop hl add hl, bc - jr .asm_2a288 + jr Function2a288 .asm_2a29a pop hl @@ -35647,6 +35665,7 @@ Function2a200: ; 2a200 ret ; 2a2a0 + SpecialRoamMons: ; 2a2a0 ; initialize RoamMon structs ; include commented-out parts from the gs function @@ -35697,17 +35716,17 @@ Function2a2ce: ; 2a2ce push hl call Function1852 jr z, .asm_2a30a - call $627f + call Function2a27f call RNG - cp $64 + cp 100 jr nc, .asm_2a30a - and $3 + and 3 jr z, .asm_2a30a dec a ld hl, RoamMon1MapGroup ld c, a - ld b, $0 - ld a, $7 + ld b, 0 + ld a, 7 call AddNTimes ld a, d cp [hl] @@ -35723,7 +35742,7 @@ Function2a2ce: ; 2a2ce ld [$d22e], a ld a, [hl] ld [CurPartyLevel], a - ld a, $5 + ld a, BATTLETYPE_ROAMING ld [BattleType], a pop hl scf From 2f5ed8468d0a7da1ee9de73fcecce86e8d6ef96c Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 26 Aug 2013 19:48:44 -0400 Subject: [PATCH 16/96] SpecialRoamMons -> InitRoamMons --- main.asm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.asm b/main.asm index 4a75809d1..64a55b5de 100644 --- a/main.asm +++ b/main.asm @@ -20302,7 +20302,7 @@ SpecialsPointers: ; c029 dbw BANK(SpecialGameboyCheck),SpecialGameboyCheck dbw BANK(SpecialTrainerHouse),SpecialTrainerHouse dbw $05, $6dc7 - dbw BANK(SpecialRoamMons), SpecialRoamMons + dbw BANK(InitRoamMons), InitRoamMons dbw $03, $448f dbw $03, $449f dbw $03, $44ac @@ -35666,9 +35666,8 @@ Function2a288: ; 2a288 ; 2a2a0 -SpecialRoamMons: ; 2a2a0 +InitRoamMons: ; 2a2a0 ; initialize RoamMon structs -; include commented-out parts from the gs function ; species ld a, RAIKOU From 2b10d184b084cdd3390ad201db5f79af9bc224b9 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 00:10:22 -0400 Subject: [PATCH 17/96] recomment some common asm (rtc/lcd) --- main.asm | 57 +++++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/main.asm b/main.asm index 64a55b5de..aaea423f5 100644 --- a/main.asm +++ b/main.asm @@ -100,7 +100,6 @@ RTC: ; 46f ld a, [VramState] bit 0, a ; obj update ret z -; 47e TimeOfDayPals: ; 47e callab _TimeOfDayPals @@ -171,7 +170,7 @@ Function4c7: ; 4c7 ld a, [hli] ld d, a call DmgToCgbObjPals - ld c, $8 + ld c, 8 call DelayFrames pop de dec b @@ -216,7 +215,7 @@ Function501: ; 501 call DmgToCgbObjPals ld a, [hld] call DmgToCgbBGPals - ld c, $8 + ld c, 8 call DelayFrames pop de dec b @@ -282,41 +281,33 @@ Function552: ; 552 DisableLCD: ; 568 ; Turn the LCD off -; Most of this is just going through the motions -; don't need to do anything if lcd is already off +; Don't need to do anything if the LCD is already off ld a, [rLCDC] bit 7, a ; lcd enable ret z - -; reset ints + xor a ld [rIF], a - -; save enabled ints ld a, [rIE] ld b, a -; disable vblank +; Disable VBlank res 0, a ; vblank ld [rIE], a - + .wait -; wait until vblank +; Wait until VBlank would normally happen ld a, [rLY] - cp 145 ; >144 (ensure beginning of vblank) + cp 145 jr nz, .wait - -; turn lcd off + ld a, [rLCDC] and %01111111 ; lcd enable off ld [rLCDC], a - -; reset ints + xor a ld [rIF], a - -; restore enabled ints ld a, b ld [rIE], a ret @@ -355,13 +346,9 @@ LatchClock: ; 59c UpdateTime: ; 5a7 -; get rtc data call GetClock -; condense days to one byte, update rtc w/ new day count call FixDays -; add game time to rtc time call FixTime -; update time of day (0 = morn, 1 = day, 2 = nite) callba GetTimeOfDay ret ; 5b7 @@ -373,40 +360,38 @@ GetClock: ; 5b7 ; enable clock r/w ld a, SRAM_ENABLE ld [MBC3SRamEnable], a - -; get clock data -; stored 'backwards' in hram - + +; clock data is 'backwards' in hram + call LatchClock ld hl, MBC3SRamBank ld de, MBC3RTC - -; seconds + ld [hl], RTC_S ld a, [de] and $3f ld [hRTCSeconds], a -; minutes + ld [hl], RTC_M ld a, [de] and $3f ld [hRTCMinutes], a -; hours + ld [hl], RTC_H ld a, [de] and $1f ld [hRTCHours], a -; day lo + ld [hl], RTC_DL ld a, [de] ld [hRTCDayLo], a -; day hi + ld [hl], RTC_DH ld a, [de] ld [hRTCDayHi], a - -; cleanup - call CloseSRAM ; unlatch clock, disable clock r/w + +; unlatch clock / disable clock r/w + call CloseSRAM ret ; 5e8 From 517da9357b1e3b382ae9573d32d1a1ba7c808867 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 13:49:32 -0400 Subject: [PATCH 18/96] PlayerPalette and PlayerAction wram labels --- wram.asm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/wram.asm b/wram.asm index 619bf42b5..1ce0c2ca6 100644 --- a/wram.asm +++ b/wram.asm @@ -1627,7 +1627,12 @@ SATURDAY EQU 6 PlayerSprite: ; d4d8 ds 1 - ds 5 + ds 3 + +PlayerPalette: ; d4dc + ds 1 + + ds 1 PlayerDirection: ; d4de ; uses bits 2 and 3 / $0c / %00001100 @@ -1638,7 +1643,16 @@ PlayerDirection: ; d4de ds 1 -SECTION "MapEngine",WRAMX[$d4e4],BANK[1] +SECTION "MapEngine",WRAMX[$d4e1],BANK[1] +PlayerAction: ; d4e1 +; 1 standing +; 2 walking +; 4 spinning +; 6 fishing + ds 1 + + ds 2 + StandingTile: ; d4e4 ds 1 StandingTile2: ; d4e5 From 7cba224d4acdac5f2ca0f92bf999a4a34ffb0025 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 14:12:05 -0400 Subject: [PATCH 19/96] engine flag constants --- constants.asm | 1 + constants/engine_flags.asm | 163 +++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 constants/engine_flags.asm diff --git a/constants.asm b/constants.asm index ccaead73f..19049702e 100644 --- a/constants.asm +++ b/constants.asm @@ -14,6 +14,7 @@ INCLUDE "constants/item_constants.asm" INCLUDE "constants/trainer_constants.asm" INCLUDE "constants/script_constants.asm" INCLUDE "constants/event_flags.asm" +INCLUDE "constants/engine_flags.asm" INCLUDE "constants/music_constants.asm" diff --git a/constants/engine_flags.asm b/constants/engine_flags.asm new file mode 100644 index 000000000..826a33c17 --- /dev/null +++ b/constants/engine_flags.asm @@ -0,0 +1,163 @@ +ENGINE_RADIO_CARD EQU $00 +ENGINE_MAP_CARD EQU $01 +ENGINE_PHONE_CARD EQU $02 +ENGINE_EXPN_CARD EQU $03 +ENGINE_POKEGEAR EQU $04 +ENGINE_DAYCARE_MONS_ARE_COMPATIBLE EQU $05 +ENGINE_DAYCARE_MAN_HAS_MON EQU $06 +ENGINE_DAYCARE_LADY_HAS_MON EQU $07 +ENGINE_MOM_SAVING_MONEY EQU $08 +ENGINE_DST EQU $09 +ENGINE_0A EQU $0a +ENGINE_POKEDEX EQU $0b +ENGINE_UNOWN_DEX EQU $0c +ENGINE_POKERUS EQU $0d +ENGINE_ROCKET_SIGNAL_ON_CH20 EQU $0e +ENGINE_CREDITS_SKIP EQU $0f +ENGINE_BUG_CONTEST_ON EQU $10 +ENGINE_BUG_CONTEST_TIMER EQU $11 +ENGINE_ROCKETS_IN_RADIO_TOWER EQU $12 +ENGINE_BIKE_SHOP_CALL_ENABLED EQU $13 +ENGINE_14 EQU $14 +ENGINE_GIVE_POKERUS EQU $15 +ENGINE_16 EQU $16 +ENGINE_ROCKETS_IN_MAHOGANY EQU $17 +ENGINE_STRENGTH_ACTIVE EQU $18 +ENGINE_ALWAYS_ON_BIKE EQU $19 +ENGINE_DOWNHILL EQU $1a +ENGINE_ZEPHYRBADGE EQU $1b +ENGINE_HIVEBADGE EQU $1c +ENGINE_PLAINBADGE EQU $1d +ENGINE_FOGBADGE EQU $1e +ENGINE_MINERALBADGE EQU $1f +ENGINE_STORMBADGE EQU $20 +ENGINE_GLACIERBADGE EQU $21 +ENGINE_RISINGBADGE EQU $22 +ENGINE_BOULDERBADGE EQU $23 +ENGINE_CASCADEBADGE EQU $24 +ENGINE_THUNDERBADGE EQU $25 +ENGINE_RAINBOWBADGE EQU $26 +ENGINE_SOULBADGE EQU $27 +ENGINE_MARSHBADGE EQU $28 +ENGINE_VOLCANOBADGE EQU $29 +ENGINE_EARTHBADGE EQU $2a +ENGINE_UNLOCKED_UNOWNS_1 EQU $2b +ENGINE_UNLOCKED_UNOWNS_2 EQU $2c +ENGINE_UNLOCKED_UNOWNS_3 EQU $2d +ENGINE_UNLOCKED_UNOWNS_4 EQU $2e +ENGINE_UNLOCKED_UNOWNS_5 EQU $2f +ENGINE_UNLOCKED_UNOWNS_6 EQU $30 +ENGINE_UNLOCKED_UNOWNS_7 EQU $31 +ENGINE_UNLOCKED_UNOWNS_8 EQU $32 +ENGINE_FLYPOINT_KRISS_HOUSE EQU $33 +ENGINE_FLYPOINT_VIRIDIAN_POKECENTER EQU $34 +ENGINE_FLYPOINT_PALLET EQU $35 +ENGINE_FLYPOINT_VIRIDIAN EQU $36 +ENGINE_FLYPOINT_PEWTER EQU $37 +ENGINE_FLYPOINT_CERULEAN EQU $38 +ENGINE_FLYPOINT_ROCK_TUNNEL EQU $39 +ENGINE_FLYPOINT_VERMILION EQU $3a +ENGINE_FLYPOINT_LAVENDER EQU $3b +ENGINE_FLYPOINT_SAFFRON EQU $3c +ENGINE_FLYPOINT_CELADON EQU $3d +ENGINE_FLYPOINT_FUCHSIA EQU $3e +ENGINE_FLYPOINT_CINNABAR EQU $3f +ENGINE_FLYPOINT_INDIGO_PLATEAU EQU $40 +ENGINE_FLYPOINT_NEW_BARK EQU $41 +ENGINE_FLYPOINT_CHERRYGROVE EQU $42 +ENGINE_FLYPOINT_VIOLET EQU $43 +ENGINE_FLYPOINT_AZALEA EQU $44 +ENGINE_FLYPOINT_CIANWOOD EQU $45 +ENGINE_FLYPOINT_GOLDENROD EQU $46 +ENGINE_FLYPOINT_OLIVINE EQU $47 +ENGINE_FLYPOINT_ECRUTEAK EQU $48 +ENGINE_FLYPOINT_MAHOGANY EQU $49 +ENGINE_FLYPOINT_LAKE_OF_RAGE EQU $4a +ENGINE_FLYPOINT_BLACKTHORN EQU $4b +ENGINE_FLYPOINT_SILVER_CAVE EQU $4c +ENGINE_FLYPOINT_UNUSED EQU $4d +ENGINE_LUCKY_NUMBER_SHOW EQU $4e +ENGINE_4F EQU $4f +ENGINE_KURT_MAKING_BALLS EQU $50 +ENGINE_51 EQU $51 +ENGINE_SPECIAL_WILDDATA EQU $52 +ENGINE_TIME_CAPSULE EQU $53 +ENGINE_ALL_FRUIT_TREES EQU $54 +ENGINE_SHUCKLE_GIVEN EQU $55 +ENGINE_GOLDENROD_UNDERGROUND_MERCHANT_CLOSED EQU $56 +ENGINE_FOUGHT_IN_TRAINER_HALL_TODAY EQU $57 +ENGINE_MT_MOON_SQUARE_CLEFAIRY EQU $58 +ENGINE_UNION_CAVE_LAPRAS EQU $59 +ENGINE_GOLDENROD_UNDERGROUND_GOT_HAIRCUT EQU $5a +ENGINE_GOLDENROD_MALL_5F_HAPPINESS_EVENT EQU $5b +ENGINE_TEA_IN_BLUES_HOUSE EQU $5c +ENGINE_INDIGO_PLATEAU_RIVAL_FIGHT EQU $5d +ENGINE_5E EQU $5e +ENGINE_5F EQU $5f +ENGINE_60 EQU $60 +ENGINE_GOLDENROD_DEPT_STORE_SALE_IS_ON EQU $61 +ENGINE_62 EQU $62 +ENGINE_PLAYER_IS_FEMALE EQU $63 +ENGINE_HAVE_EXAMINED_GS_BALL EQU $64 +ENGINE_JACK EQU $65 +ENGINE_HUEY EQU $66 +ENGINE_GAVEN EQU $67 +ENGINE_BETH EQU $68 +ENGINE_JOSE EQU $69 +ENGINE_REENA EQU $6a +ENGINE_JOEY EQU $6b +ENGINE_WADE EQU $6c +ENGINE_RALPH EQU $6d +ENGINE_LIZ EQU $6e +ENGINE_ANTHONY EQU $6f +ENGINE_TODD EQU $70 +ENGINE_GINA EQU $71 +ENGINE_ARNIE EQU $72 +ENGINE_ALAN EQU $73 +ENGINE_DANA EQU $74 +ENGINE_CHAD EQU $75 +ENGINE_TULLY EQU $76 +ENGINE_BRENT EQU $77 +ENGINE_TIFFANY EQU $78 +ENGINE_VANCE EQU $79 +ENGINE_WILTON EQU $7a +ENGINE_PARRY EQU $7b +ENGINE_ERIN EQU $7c +ENGINE_BEVERLY_HAS_NUGGET EQU $7d +ENGINE_JOSE_HAS_STAR_PIECE EQU $7e +ENGINE_WADE_HAS_ITEM EQU $7f +ENGINE_GINA_HAS_LEAF_STONE EQU $80 +ENGINE_ALAN_HAS_FIRE_STONE EQU $81 +ENGINE_LIZ_HAS_THUNDERSTONE EQU $82 +ENGINE_DEREK_HAS_NUGGET EQU $83 +ENGINE_TULLY_HAS_WATER_STONE EQU $84 +ENGINE_TIFFANY_HAS_PINK_BOW EQU $85 +ENGINE_WILTON_HAS_ITEM EQU $86 +ENGINE_87 EQU $87 +ENGINE_88 EQU $88 +ENGINE_89 EQU $89 +ENGINE_8A EQU $8a +ENGINE_8B EQU $8b +ENGINE_8C EQU $8c +ENGINE_8D EQU $8d +ENGINE_8E EQU $8e +ENGINE_8F EQU $8f +ENGINE_90 EQU $90 +ENGINE_91 EQU $91 +ENGINE_92 EQU $92 +ENGINE_93 EQU $93 +ENGINE_94 EQU $94 +ENGINE_95 EQU $95 +ENGINE_96 EQU $96 +ENGINE_97 EQU $97 +ENGINE_98 EQU $98 +ENGINE_99 EQU $99 +ENGINE_9A EQU $9a +ENGINE_9B EQU $9b +ENGINE_9C EQU $9c +ENGINE_9D EQU $9d +ENGINE_9E EQU $9e +ENGINE_KRIS_IN_CABLE_CLUB EQU $9f +ENGINE_DUNSPARCE_SWARM EQU $a0 +ENGINE_YANMA_SWARM EQU $a1 + From 94fc90a243f4fce4b65e5f08a0e2e783525ff550 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 15:35:44 -0400 Subject: [PATCH 20/96] badge engine flags in main.asm --- main.asm | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/main.asm b/main.asm index aaea423f5..70c052d9d 100644 --- a/main.asm +++ b/main.asm @@ -7326,8 +7326,8 @@ FlagAction: ; 0x2e76 Function2ead: ; 2ead - ld de, $000b - ld b, $2 + ld de, ENGINE_POKEDEX + ld b, CHECK_FLAG callba EngineFlagAction ld a, c and a @@ -20737,7 +20737,7 @@ Functionc6f5: ; c6f5 GetPartyNick: ; c706 ; write CurPartyMon nickname to StringBuffer1-3 ld hl, PartyMon1Nickname - ld a, $02 + ld a, BOXMON ld [MonType], a ld a, [CurPartyMon] call GetNick @@ -20752,7 +20752,7 @@ GetPartyNick: ; c706 CheckEngineFlag: ; c721 ; Check engine flag de ; Return carry if flag is not set - ld b, $02 ; check flag + ld b, CHECK_FLAG callba EngineFlagAction ld a, c and a @@ -20765,7 +20765,8 @@ CheckEngineFlag: ; c721 ; c731 CheckBadge: ; c731 -; input: a = badge flag id ($1b-$2b) +; Check engine flag a (ENGINE_ZEPHYRBADGE thru ENGINE_EARTHBADGE) +; Display "Badge required" text and return carry if the badge is not owned call CheckEngineFlag ret nc ld hl, BadgeRequiredText @@ -20775,8 +20776,10 @@ CheckBadge: ; c731 ; c73d BadgeRequiredText: ; c73d - TX_FAR _BadgeRequiredText ; Sorry! A new BADGE - db "@" ; is required. + ; Sorry! A new BADGE + ; is required. + TX_FAR _BadgeRequiredText + db "@" ; c742 CheckPartyMove: ; c742 @@ -20956,10 +20959,9 @@ Functionc8ac: ; c8ac ; c8b5 Functionc8b5: ; c8b5 - ld de, $001b - ld a, $3 - ld hl, $4731 - rst FarCall +; Flash + ld de, ENGINE_ZEPHYRBADGE + callba CheckBadge jr c, .asm_c8dd push hl ld a, $22 @@ -21119,7 +21121,7 @@ TrySurfOW: ; c9e7 call CheckDirection jr c, .quit - ld de, $1e ; FLAG_FOG_BADGE + ld de, ENGINE_FOGBADGE call CheckEngineFlag jr c, .quit @@ -21183,7 +21185,7 @@ Functionca3b: ; ca3b Functionca52: ; ca52 ; Fly - ld de, $0020 ; storm badge + ld de, ENGINE_STORMBADGE call CheckBadge jr c, .asm_ca85 call GetMapPermission @@ -21246,10 +21248,9 @@ Functioncade: ; cade ; cae7 Functioncae7: ; cae7 - ld de, $0022 - ld a, $3 - ld hl, $4731 - rst FarCall +; Waterfall + ld de, ENGINE_RISINGBADGE + callba CheckBadge ld a, $80 ret c call Functioncb07 @@ -21324,7 +21325,7 @@ TryWaterfallOW: ; cb56 ld d, WATERFALL call CheckPartyMove jr c, .asm_cb74 - ld de, $0022 + ld de, ENGINE_RISINGBADGE call CheckEngineFlag jr c, .asm_cb74 call Functioncb07 @@ -21409,7 +21410,8 @@ Functioncce5: ; cce5 ; ccee Functionccee: ; ccee - ld de, $001d +; Strength + ld de, ENGINE_PLAINBADGE call CheckBadge jr c, Functioncd06 jr Functioncd09 @@ -21517,7 +21519,7 @@ TryWhirlpoolOW: ; ce3e ld d, WHIRLPOOL call CheckPartyMove jr c, .asm_ce5c - ld de, $0021 + ld de, ENGINE_GLACIERBADGE call CheckEngineFlag jr c, .asm_ce5c call Functioncdde @@ -21764,7 +21766,7 @@ TryCutOW: ; d186 ld d, CUT call CheckPartyMove jr c, .asm_d19f - ld de, $001c + ld de, ENGINE_HIVEBADGE call CheckEngineFlag jr c, .asm_d19f ld a, BANK(UnknownScript_0xd1a9) @@ -26359,9 +26361,7 @@ Function12e55: ; 12e55 ; 12e6a Function12e6a: ; 12e6a - ld a, $3 - ld hl, $4ce5 - rst FarCall + callba Functioncce5 ld a, [$d0ec] cp $1 jr nz, .asm_12e7c From 886ab6888409dc6ac0502c6866c74aade7d3568e Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 16:56:34 -0400 Subject: [PATCH 21/96] add some field move asm and scripts --- main.asm | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/main.asm b/main.asm index 70c052d9d..74a51db71 100644 --- a/main.asm +++ b/main.asm @@ -21191,7 +21191,7 @@ Functionca52: ; ca52 call GetMapPermission call CheckOutdoorMap jr z, .asm_ca64 - jr .asm_ca88 + jr .indoors .asm_ca64 xor a @@ -21213,7 +21213,7 @@ Functionca52: ; ca52 ld a, $82 ret -.asm_ca88 +.indoors ld a, $2 ret @@ -21225,7 +21225,7 @@ Functionca52: ; ca52 ; ca94 Functionca94: ; ca94 - ld hl, Datacaa3 + ld hl, UnknownScript_0xcaa3 call Function31cd ld a, $81 ret @@ -21237,8 +21237,29 @@ Functionca9d: ; ca9d ret ; caa3 -Datacaa3: ; caa3 -INCBIN "baserom.gbc", $caa3, $cade - $caa3 +UnknownScript_0xcaa3: ; 0xcaa3 + reloadmappart + 3callasm BANK(HideSprites), HideSprites + special $0035 + 3callasm $23, $4aed + 3call BANK(UnknownScript_0x122c1), UnknownScript_0x122c1 + special $0000 + 3callasm $05, $54f1 + writecode $8, $0 + newloadmap $fc + 3callasm $23, $4b33 + special $003b + 3callasm BANK(Functioncacb), Functioncacb + end +; 0xcacb + +Functioncacb: ; cacb + callba Function561d + call DelayFrame + call Functione4a + callba Function106594 + ret +; cade Functioncade: ; cade call Functioncae7 @@ -21255,7 +21276,7 @@ Functioncae7: ; cae7 ret c call Functioncb07 jr c, .asm_cb01 - ld hl, $4b1c + ld hl, UnknownScript_0xcb1c call Function31cd ld a, $81 ret @@ -21269,7 +21290,7 @@ Functioncae7: ; cae7 Functioncb07: ; cb07 ld a, [PlayerDirection] and $c - cp $4 + cp FACE_UP jr nz, .asm_cb1a ld a, [TileUp] call CheckWaterfallTile @@ -21282,7 +21303,9 @@ Functioncb07: ; cb07 ret ; cb1c -INCBIN "baserom.gbc", $cb1c, $cb20 - $cb1c +UnknownScript_0xcb1c: ; 0xcb1c + reloadmappart + special $0035 UnknownScript_0xcb20: ; 0xcb20 3callasm BANK(GetPartyNick), GetPartyNick From be9c504b24d56cde5ea50d8af169ff8361610453 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 18:00:41 -0400 Subject: [PATCH 22/96] rename PushScriptPointer -> CallScript --- main.asm | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/main.asm b/main.asm index 74a51db71..2c4d6d267 100644 --- a/main.asm +++ b/main.asm @@ -5554,7 +5554,7 @@ Function261b: ; 261b ret ; 261f -PushScriptPointer: ; 261f +CallScript: ; 261f ; Call a script at a:hl. ld [ScriptBank], a @@ -5575,7 +5575,7 @@ Function2631: ; 2631 and a ret nz call GetMapEventBank - jr PushScriptPointer + jr CallScript ; 263b Function263b: ; 263b @@ -21139,7 +21139,7 @@ TrySurfOW: ; c9e7 ld a, BANK(AskSurfScript) ld hl, AskSurfScript - call PushScriptPointer + call CallScript scf ret @@ -21355,14 +21355,14 @@ TryWaterfallOW: ; cb56 jr c, .asm_cb74 ld a, BANK(UnknownScript_0xcb86) ld hl, UnknownScript_0xcb86 - call PushScriptPointer + call CallScript scf ret .asm_cb74 ld a, BANK(UnknownScript_0xcb7e) ld hl, UnknownScript_0xcb7e - call PushScriptPointer + call CallScript scf ret ; cb7e @@ -21549,14 +21549,14 @@ TryWhirlpoolOW: ; ce3e jr c, .asm_ce5c ld a, BANK(UnknownScript_0xce6e) ld hl, UnknownScript_0xce6e - call PushScriptPointer + call CallScript scf ret .asm_ce5c ld a, BANK(UnknownScript_0xce66) ld hl, UnknownScript_0xce66 - call PushScriptPointer + call CallScript scf ret ; ce66 @@ -21614,7 +21614,7 @@ TryHeadbuttOW: ; cec9 jr c, .asm_ceda ld a, $3 ld hl, $4edc - call PushScriptPointer + call CallScript scf ret @@ -21794,14 +21794,14 @@ TryCutOW: ; d186 jr c, .asm_d19f ld a, BANK(UnknownScript_0xd1a9) ld hl, UnknownScript_0xd1a9 - call PushScriptPointer + call CallScript scf ret .asm_d19f ld a, BANK(UnknownScript_0xd1cd) ld hl, UnknownScript_0xd1cd - call PushScriptPointer + call CallScript scf ret ; d1a9 @@ -27514,7 +27514,7 @@ Function1365b: ; 1365b ld [$d03f + 2], a ld a, BANK(UnknownScript_0x1369a) ld hl, UnknownScript_0x1369a - call PushScriptPointer + call CallScript scf ret @@ -53358,7 +53358,7 @@ Function505da: ; 505da .asm_50622 ld a, $14 ld hl, UnknownScript_0x50669 - call PushScriptPointer + call CallScript scf ret @@ -60436,7 +60436,7 @@ CheckTileEvent: ; 96874 ld h, [hl] ld l, a call GetMapEventBank - call PushScriptPointer + call CallScript ret ; 968c7 @@ -60502,7 +60502,7 @@ Function968ec: ; 968ec call GetMapEventBank call GetFarHalfword call GetMapEventBank - call PushScriptPointer + call CallScript ld hl, ScriptFlags res 3, [hl] @@ -60519,7 +60519,7 @@ Function968ec: ; 968ec ld h, [hl] ld l, a ld a, [$d44e] - call PushScriptPointer + call CallScript scf ret @@ -60561,7 +60561,7 @@ Function9693a: ; 9693a .asm_96966 ld a, $4 ld hl, $75f8 - call PushScriptPointer + call CallScript scf ret ; 96970 @@ -60685,7 +60685,7 @@ TryObjectEvent: ; 969b5 ld h, [hl] ld l, a call GetMapEventBank - call PushScriptPointer + call CallScript ; ld a, -1 ret ; 96a12 @@ -60783,7 +60783,7 @@ TryReadSign: ; 96a38 ld h, [hl] ld l, a call GetMapEventBank - call PushScriptPointer + call CallScript scf ret @@ -60797,7 +60797,7 @@ TryReadSign: ; 96a38 call FarCopyBytes ld a, $4 ld hl, $7625 - call PushScriptPointer + call CallScript scf ret @@ -60828,7 +60828,7 @@ TryReadSign: ; 96a38 call GetMapEventBank call GetFarHalfword call GetMapEventBank - call PushScriptPointer + call CallScript scf ret @@ -60908,7 +60908,7 @@ PlayerMovement: ; 96af0 ; force the player to move in some direction ld a, $4 ld hl, $653d - call PushScriptPointer + call CallScript ; ld a, -1 ld c, a scf @@ -60938,7 +60938,7 @@ CheckMenuOW: ; 96b30 ld a, BANK(StartMenuScript) ld hl, StartMenuScript - call PushScriptPointer + call CallScript scf ret @@ -60950,7 +60950,7 @@ CheckMenuOW: ; 96b30 call PlayTalkObject ld a, BANK(SelectMenuScript) ld hl, SelectMenuScript - call PushScriptPointer + call CallScript scf ret ; 96b58 @@ -61061,7 +61061,7 @@ Function96bd7: ; 96bd7 ret nz ld a, $4 ld hl, $7619 - call PushScriptPointer + call CallScript scf ret ; 96beb @@ -61250,7 +61250,7 @@ Function97c30: ; 97c30 ld h, [hl] ld l, a ld a, [$d45d] - call PushScriptPointer + call CallScript scf push af xor a @@ -61363,7 +61363,7 @@ Function97cc0: ; 97cc0 jr .asm_97cf4 .asm_97cf4 - call PushScriptPointer + call CallScript scf ret ; 97cf9 From 12ab33b37e26d8f44478a6bbb918901e283b2e24 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 18:16:42 -0400 Subject: [PATCH 23/96] rename FarCall family labels FarJump labels renamed to FarCall register aliases JpHl and JpDe renamed to _hl_ and _de_ --- engine/vblank.asm | 2 +- main.asm | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/engine/vblank.asm b/engine/vblank.asm index 6a319356c..44e3e37c8 100644 --- a/engine/vblank.asm +++ b/engine/vblank.asm @@ -26,7 +26,7 @@ ld l, a ; down to business - call JpHl + call _hl_ ; since this is called once per frame call GameTimer diff --git a/main.asm b/main.asm index 2c4d6d267..86091d83b 100644 --- a/main.asm +++ b/main.asm @@ -4,7 +4,7 @@ SECTION "rst0",ROM0[$0] jp Start SECTION "rst8",ROM0[$8] ; FarCall - jp FarJpHl + jp FarCall_hl SECTION "rst10",ROM0[$10] ; Bankswitch ld [hROMBank], a @@ -6985,27 +6985,28 @@ Function2d43: ; 2d43 ; 2d54 -FarJpDe: ; 2d54 +FarCall_de: ; 2d54 +; Call a:de. +; Preserves other registers. + ld [hBuffer], a ld a, [hROMBank] push af ld a, [hBuffer] rst Bankswitch - call Function2d61 - jr ReturnFarJump -; 2d61 + call .de + jr ReturnFarCall -Function2d61: ; 2d61 +.de push de ret ; 2d63 -FarJpHl: ; 2d63 -; Jump to a:hl. -; Preserves all registers besides a. +FarCall_hl: ; 2d63 +; Call a:hl. +; Preserves other registers. -; Switch to the new bank. ld [hBuffer], a ld a, [hROMBank] push af @@ -7014,7 +7015,7 @@ FarJpHl: ; 2d63 call Function2d82 ; 2d6e -ReturnFarJump: ; 2d6e +ReturnFarCall: ; 2d6e ; We want to retain the contents of f. ; To do this, we can pop to bc instead of af. @@ -7650,11 +7651,14 @@ CloseSRAM: ; 2fe1 ret ; 2fec -JpHl: ; 2fec + +; Register aliases + +_hl_: ; 2fec jp [hl] ; 2fed -JpDe: ; 2fed +_de_: ; 2fed push de ret ; 2fef @@ -8170,11 +8174,12 @@ Function31be: ; 31be ld a, [hli] ld h, [hl] ld l, a - call JpHl + + call _hl_ + pop hl ld a, h rst Bankswitch - ret ; 31cd @@ -11702,7 +11707,7 @@ Function444d: ; 444d ld a, [hli] ld h, [hl] ld l, a - call JpHl + call _hl_ ret ; 445f @@ -34544,7 +34549,7 @@ Function25072: ; 25072 ld a, [$cf87] ld d, a ld a, [$cf8a] - call FarJpDe + call FarCall_de ret ; 25097 @@ -48744,7 +48749,7 @@ AIChooseMove: ; 440ce ld h, [hl] ld l, a ld a, BANK(AIScoring) - call FarJpHl + call FarCall_hl jr .CheckLayer @@ -51643,7 +51648,7 @@ StatsScreenInit: ; 4dc8a ld hl, $753e rst FarCall ; this loads graphics pop hl - call JpHl + call _hl_ call WhiteBGMap call ClearTileMap pop bc @@ -69428,7 +69433,7 @@ Function100b12: ; 100b12 ld hl, $4f2c ld a, $9 ld de, LoadMenuDataHeader - call FarJpDe + call FarCall_de ld a, $9 ld [$cf94], a ld a, [$d0d2] From 25dcc71c4c445c40fae550bd21f61fadf33f584a Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 20:46:15 -0400 Subject: [PATCH 24/96] rename some LCD functions --- main.asm | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/main.asm b/main.asm index 86091d83b..bcedca852 100644 --- a/main.asm +++ b/main.asm @@ -38,7 +38,7 @@ SECTION "vblank",ROM0[$40] ; vblank interrupt jp VBlank SECTION "lcd",ROM0[$48] ; lcd interrupt - jp Function552 + jp LCD SECTION "timer",ROM0[$50] ; timer interrupt jp Function3e93 @@ -138,13 +138,13 @@ Function4a3: ; 4a3 and a jr z, .asm_4af ld hl, IncGradGBPalTable_00 - ld b, $4 - jr Function4c7 + ld b, 4 + jr FadeOut .asm_4af ld hl, IncGradGBPalTable_08 - ld b, $4 - jr Function4c7 + ld b, 4 + jr FadeOut ; 4b6 Function4b6: ; 4b6 @@ -152,16 +152,15 @@ Function4b6: ; 4b6 and a jr z, .asm_4c2 ld hl, IncGradGBPalTable_05 - ld b, $3 - jr Function4c7 + ld b, 3 + jr FadeOut .asm_4c2 ld hl, IncGradGBPalTable_13 - ld b, $3 + ld b, 3 ; 4c7 -Function4c7: ; 4c7 -.asm_4c7 +FadeOut: ; 4c7 push de ld a, [hli] call DmgToCgbBGPals @@ -174,7 +173,7 @@ Function4c7: ; 4c7 call DelayFrames pop de dec b - jr nz, .asm_4c7 + jr nz, FadeOut ret ; 4dd @@ -183,13 +182,13 @@ Function4dd: ; 4dd and a jr z, .asm_4e9 ld hl, IncGradGBPalTable_04 - 1 - ld b, $4 - jr Function501 + ld b, 4 + jr FadeIn .asm_4e9 ld hl, IncGradGBPalTable_12 - 1 - ld b, $4 - jr Function501 + ld b, 4 + jr FadeIn ; 4f0 Function4f0: ; 4f0 @@ -197,16 +196,16 @@ Function4f0: ; 4f0 and a jr z, .asm_4fc ld hl, IncGradGBPalTable_07 - 1 - ld b, $3 - jr Function501 + ld b, 3 + jr FadeIn .asm_4fc ld hl, IncGradGBPalTable_15 - 1 - ld b, $3 + ld b, 3 ; fallthrough ; 501 -Function501: ; 501 +FadeIn: ; 501 push de ld a, [hld] ld d, a @@ -219,7 +218,7 @@ Function501: ; 501 call DelayFrames pop de dec b - jr nz, Function501 + jr nz, FadeIn ret ; 517 @@ -247,7 +246,7 @@ IncGradGBPalTable_15: db %00000000, %00000000, %00000000 Function547: ; 547 ld a, [hLCDStatCustom] - cp $43 + cp rSCX & $ff ret nz ld c, a ld a, [$d100] @@ -255,15 +254,17 @@ Function547: ; 547 ret ; 552 -Function552: ; 552 +LCD: ; 552 push af ld a, [hLCDStatCustom] and a - jr z, .asm_566 + jr z, .done + +; At this point it's assumed we're in WRAM bank 5! push bc ld a, [rLY] ld c, a - ld b, $d1 + ld b, $d100 >> 8 ld a, [bc] ld b, a ld a, [hLCDStatCustom] @@ -272,7 +273,7 @@ Function552: ; 552 ld [$ff00+c], a pop bc -.asm_566 +.done pop af reti ; 568 From 64bb7d2253b0b964fcd052562c96bc39e0b01012 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 20:46:31 -0400 Subject: [PATCH 25/96] add LYOverrides in wram bank 5 --- wram.asm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wram.asm b/wram.asm index 1ce0c2ca6..e93318db0 100644 --- a/wram.asm +++ b/wram.asm @@ -2098,15 +2098,18 @@ RoamMon3DVs: ; dfe2 SECTION "WRAMBank5",WRAMX[$d000],BANK[5] ; 8 4-color palettes -Unkn1Pals: +Unkn1Pals: ; d000 ds $40 -Unkn2Pals: +Unkn2Pals: ; d040 ds $40 -BGPals: +BGPals: ; d080 ds $40 -OBPals: +OBPals: ; d0c0 ds $40 +LYOverrides: ; d100 + ds 144 +LYOverridesEnd SECTION "SRAMBank1",SRAM,BANK[1] From 651e0a4245d8749e7926fce01110a12bb7453246 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 20:56:28 -0400 Subject: [PATCH 26/96] LYOverrides in main.asm --- main.asm | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/main.asm b/main.asm index bcedca852..5b4f3d913 100644 --- a/main.asm +++ b/main.asm @@ -249,11 +249,12 @@ Function547: ; 547 cp rSCX & $ff ret nz ld c, a - ld a, [$d100] + ld a, [LYOverrides] ld [$ff00+c], a ret ; 552 + LCD: ; 552 push af ld a, [hLCDStatCustom] @@ -264,7 +265,7 @@ LCD: ; 552 push bc ld a, [rLY] ld c, a - ld b, $d100 >> 8 + ld b, LYOverrides >> 8 ld a, [bc] ld b, a ld a, [hLCDStatCustom] @@ -279,7 +280,6 @@ LCD: ; 552 ; 568 - DisableLCD: ; 568 ; Turn the LCD off @@ -71398,7 +71398,7 @@ StartTitleScreen: ; 10ed67 call DrawGraphic ; Draw copyright text - ld hl, $9c03 ; BG Map 1 (3,0) + ld hl, $9c03 ; BGMap1(3,0) ld bc, $010d ; 13x1 ld d, $c ld e, $10 @@ -71436,11 +71436,9 @@ StartTitleScreen: ; 10ed67 ; LY/SCX trickery starts here -; Save WRAM bank ld a, [rSVBK] push af -; WRAM bank 5 - ld a, 5 + ld a, 5 ; BANK(LYOverrides) ld [rSVBK], a ; Make alternating lines come in from opposite sides @@ -71448,28 +71446,27 @@ StartTitleScreen: ; 10ed67 ; ( This part is actually totally pointless, you can't ; see anything until these values are overwritten! ) - ld b, 40 ; alternate for 80 lines - ld hl, $d100 ; LY buffer + ld b, 80 / 2 ; alternate for 80 lines + ld hl, LYOverrides .loop ; $00 is the middle position - ld [hl], $70 ; coming from the left + ld [hl], +112 ; coming from the left inc hl - ld [hl], $90 ; coming from the right + ld [hl], -112 ; coming from the right inc hl dec b jr nz, .loop ; Make sure the rest of the buffer is empty - ld hl, $d150 + ld hl, LYOverrides + 80 xor a - ld bc, $0040 + ld bc, LYOverridesEnd - (LYOverrides + 80) call ByteFill ; Let LCD Stat know we're messing around with SCX ld a, rSCX - rJOYP ld [hLCDStatCustom], a -; Restore WRAM bank pop af ld [rSVBK], a @@ -71483,14 +71480,13 @@ StartTitleScreen: ; 10ed67 set 2, a ld [rLCDC], a -; - ld a, $70 + ld a, +112 ld [hSCX], a - ld a, $8 + ld a, 8 ld [hSCY], a - ld a, $7 + ld a, 7 ld [hWX], a - ld a, $90 + ld a, -112 ld [hWY], a ld a, $1 From e48899c1f4e59db41b5647f03c6651d39d7dd44d Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 23:37:24 -0400 Subject: [PATCH 27/96] gbhw: flag constants for interrupts and timer registers --- gbhw.asm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gbhw.asm b/gbhw.asm index 6f2c68c97..0f12e4842 100644 --- a/gbhw.asm +++ b/gbhw.asm @@ -21,15 +21,29 @@ RTC_DH EQU $0c ; Upper 1 bit of Day Counter, Carry Bit, Halt Flag ; Bit 6 Halt (0=Active, 1=Stop Timer) ; Bit 7 Day Counter Carry Bit (1=Counter Overflow) +; interrupt flags +VBLANK EQU 0 +LCD_STAT EQU 1 +TIMER EQU 2 +SERIAL EQU 3 +JOYPAD EQU 4 ; Hardware registers rJOYP EQU $ff00 ; Joypad (R/W) rSB EQU $ff01 ; Serial transfer data (R/W) rSC EQU $ff02 ; Serial Transfer Control (R/W) +rSC_ON EQU 7 +rSC_CGB EQU 1 +rSC_CLOCK EQU 0 rDIV EQU $ff04 ; Divider Register (R/W) rTIMA EQU $ff05 ; Timer counter (R/W) rTMA EQU $ff06 ; Timer Modulo (R/W) rTAC EQU $ff07 ; Timer Control (R/W) +rTAC_ON EQU 2 +rTAC_4096_HZ EQU 0 +rTAC_262144_HZ EQU 1 +rTAC_65536_HZ EQU 2 +rTAC_16384_HZ EQU 3 rIF EQU $ff0f ; Interrupt Flag (R/W) rNR10 EQU $ff10 ; Channel 1 Sweep register (R/W) rNR11 EQU $ff11 ; Channel 1 Sound length/Wave pattern duty (R/W) From 8898f63fc788d1d0e9cb3efab7f833fcba07fe07 Mon Sep 17 00:00:00 2001 From: yenatch Date: Tue, 27 Aug 2013 23:38:05 -0400 Subject: [PATCH 28/96] timer interrupt --- main.asm | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/main.asm b/main.asm index 5b4f3d913..4028a4d5d 100644 --- a/main.asm +++ b/main.asm @@ -41,7 +41,7 @@ SECTION "lcd",ROM0[$48] ; lcd interrupt jp LCD SECTION "timer",ROM0[$50] ; timer interrupt - jp Function3e93 + jp Timer SECTION "serial",ROM0[$58] ; serial interrupt jp Function6ef @@ -328,7 +328,7 @@ AskTimer: ; 591 ld a, [$ffe9] and a jr z, .asm_59a - call Function3e93 + call Timer .asm_59a pop af @@ -10975,28 +10975,36 @@ Function3e80: ; 3e80 ; 3e93 -Function3e93: ; 3e93 +Timer: ; 3e93 push af push bc push de push hl + ld a, [$ffe9] and a jr z, .asm_3ed2 + xor a ld [rTAC], a + +; Turn off timer interrupt ld a, [rIF] - and $1b + and 1 << VBLANK | 1 << LCD_STAT | 1 << SERIAL | 1 << JOYPAD ld [rIF], a + ld a, [$c86a] or a jr z, .asm_3ed2 + ld a, [$c822] bit 1, a jr nz, .asm_3eca + ld a, [rSC] - and $80 + and 1 << rSC_ON jr nz, .asm_3eca + ld a, [hROMBank] push af ld a, $44 @@ -11004,16 +11012,17 @@ Function3e93: ; 3e93 rst Bankswitch call $58de + pop bc ld a, b ld [$c981], a rst Bankswitch - .asm_3eca ld a, [rTMA] ld [rTIMA], a - ld a, $6 + + ld a, 1 << rTAC_ON | rTAC_65536_HZ ld [rTAC], a .asm_3ed2 From faae0e10290d962e595dceea5013c4b1ffea409f Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 28 Aug 2013 01:24:52 -0400 Subject: [PATCH 29/96] serial interrupt --- main.asm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.asm b/main.asm index 4028a4d5d..99f386167 100644 --- a/main.asm +++ b/main.asm @@ -44,7 +44,7 @@ SECTION "timer",ROM0[$50] ; timer interrupt jp Timer SECTION "serial",ROM0[$58] ; serial interrupt - jp Function6ef + jp Serial SECTION "joypad",ROM0[$60] ; joypad interrupt jp JoypadInt @@ -633,20 +633,24 @@ Function6e3: ; 6e3 -Function6ef: ; 6ef +Serial: ; 6ef push af push bc push de push hl + ld a, [$ffc9] and a jr nz, .asm_71c + ld a, [$c2d4] bit 0, a jr nz, .asm_721 + ld a, [$ffcb] inc a jr z, .asm_726 + ld a, [rSB] ld [$ffce], a ld a, [$ffcd] @@ -654,7 +658,8 @@ Function6ef: ; 6ef ld a, [$ffcb] cp $2 jr z, .asm_752 - ld a, $0 + + ld a, $00 ld [rSC], a ld a, $80 ld [rSC], a @@ -688,7 +693,7 @@ Function6ef: ; 6ef ld a, [rDIV] bit 7, a jr nz, .asm_73f - ld a, $0 + ld a, $00 ld [rSC], a ld a, $80 ld [rSC], a From 03abb8947431eaa40ee4c703b92c04c9a25feef1 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 28 Aug 2013 04:28:45 -0400 Subject: [PATCH 30/96] serial hram constants --- hram.asm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hram.asm b/hram.asm index d8e8d0f34..051d4186a 100644 --- a/hram.asm +++ b/hram.asm @@ -41,6 +41,9 @@ hMathBuffer EQU $ffb8 hLCDStatCustom EQU $ffc6 +hSerialSend EQU $ffcd +hSerialReceive EQU $ffce + hSCX EQU $ffcf hSCY EQU $ffd0 hWX EQU $ffd1 From 7fe1fa58e313312229ca4d8715ca304b47002eca Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 28 Aug 2013 04:28:53 -0400 Subject: [PATCH 31/96] hram constants in serial interrupt --- main.asm | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/main.asm b/main.asm index 99f386167..b34e87298 100644 --- a/main.asm +++ b/main.asm @@ -632,7 +632,6 @@ Function6e3: ; 6e3 ; 6ef - Serial: ; 6ef push af push bc @@ -652,16 +651,18 @@ Serial: ; 6ef jr z, .asm_726 ld a, [rSB] - ld [$ffce], a - ld a, [$ffcd] + ld [hSerialReceive], a + + ld a, [hSerialSend] ld [rSB], a + ld a, [$ffcb] cp $2 jr z, .asm_752 - ld a, $00 + ld a, 0 << rSC_ON ld [rSC], a - ld a, $80 + ld a, 1 << rSC_ON ld [rSC], a jr .asm_752 @@ -681,21 +682,24 @@ Serial: ; 6ef jr nz, .asm_752 .asm_730 - ld [$ffce], a + ld [hSerialReceive], a ld [$ffcb], a cp $2 jr z, .asm_74f + xor a ld [rSB], a ld a, $3 ld [rDIV], a + .asm_73f ld a, [rDIV] bit 7, a jr nz, .asm_73f - ld a, $00 + + ld a, 0 << rSC_ON ld [rSC], a - ld a, $80 + ld a, 1 << rSC_ON ld [rSC], a jr .asm_752 @@ -707,7 +711,7 @@ Serial: ; 6ef ld a, $1 ld [$ffca], a ld a, $fe - ld [$ffcd], a + ld [hSerialSend], a .asm_75a pop hl @@ -722,7 +726,7 @@ Function75f: ; 75f ld [$ffcc], a .asm_763 ld a, [hl] - ld [$ffcd], a + ld [hSerialSend], a call Function78a push bc ld b, a @@ -820,7 +824,7 @@ Function78a: ; 78a ld [$cf5e], a .asm_7f8 - ld a, [$ffce] + ld a, [hSerialReceive] cp $fe ret nz call Function82b @@ -846,7 +850,7 @@ Function78a: ; 78a ld a, $fe ret z ld a, [hl] - ld [$ffcd], a + ld [hSerialSend], a call DelayFrame jp Function78a @@ -883,7 +887,7 @@ Function83b: ; 83b .asm_847 call DelayFrame ld a, [hl] - ld [$ffcd], a + ld [hSerialSend], a call Function78a ld b, a inc hl @@ -976,7 +980,7 @@ Function8c1: ; 8c1 call Function8f3 ld a, [$cf56] add b - ld [$ffcd], a + ld [hSerialSend], a ld a, [$ffcb] cp $2 jr nz, .asm_8ee @@ -992,13 +996,13 @@ Function8c1: ; 8c1 ; 8f3 Function8f3: ; 8f3 - ld a, [$ffce] + ld a, [hSerialReceive] ld [$cf51], a and $f0 cp b ret nz xor a - ld [$ffce], a + ld [hSerialReceive], a ld a, [$cf51] and $f ld [$cf52], a @@ -1007,7 +1011,7 @@ Function8f3: ; 8f3 Function908: ; 908 xor a - ld [$ffcd], a + ld [hSerialSend], a ld a, [$ffcb] cp $2 ret nz @@ -1025,7 +1029,7 @@ Function919: ; 919 ld a, $2 ld [rSB], a xor a - ld [$ffce], a + ld [hSerialReceive], a ld a, $0 ld [rSC], a ld a, $80 From 53d208ce4ce459506ad2de6a6860edbef49f21c4 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Wed, 28 Aug 2013 16:22:50 -0500 Subject: [PATCH 32/96] fail fast when the baserom.gbc file doesn't exist One day this will not be required. But until then, waiting one or more seconds for the build to fail just to learn that you forgot baserom.gbc is really silly. This makes failure almost instantaneous compared to before, which would take between one and ten seconds depending on system performance. fixes #167 --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2b6aa311a..54b8b57a3 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,10 @@ pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constan .asm.tx: $(eval TEXTQUEUE := $(TEXTQUEUE) $<) @rm -f $@ +baserom: + python -c "import os; assert 'baserom.gbc' in os.listdir('.'), 'Wait! Need baserom.gbc first. Check README and INSTALL for details.';" -pokecrystal.gbc: pokecrystal.o +pokecrystal.gbc: baserom pokecrystal.o rgblink -n pokecrystal.sym -m pokecrystal.map -o $@ $< rgbfix -Cjv -i BYTE -k 01 -l 0x33 -m 0x10 -p 0 -r 3 -t PM_CRYSTAL $@ From eff81fb0807b55180c32e7529171404f1ff36408 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 02:10:32 -0400 Subject: [PATCH 33/96] fix Stack's address ($c100 -> $c0ff) using negative ds --- engine/init.asm | 2 +- wram.asm | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/init.asm b/engine/init.asm index d7594ae1d..3104c416d 100644 --- a/engine/init.asm +++ b/engine/init.asm @@ -79,7 +79,7 @@ Init: ; 17d or c jr nz, .asm_1b1 - ld sp, Stack - 1 + ld sp, Stack ; Clear HRAM ld a, [hCGB] diff --git a/wram.asm b/wram.asm index e93318db0..74927ca7c 100644 --- a/wram.asm +++ b/wram.asm @@ -13,9 +13,9 @@ VBGMap1: SECTION "WRAMBank0",WRAM0[$c000] -SECTION "stack",WRAM0[$c000] - ds $100 -Stack: ; c100 +SECTION "stack",WRAM0[$c0ff] +Stack: ; c0ff + ds -$100 SECTION "audio",WRAM0[$c100] From a4b69a123fcaa11128104ac6cb93a5ca08d22951 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 02:23:29 -0400 Subject: [PATCH 34/96] more text_jumps in known functions --- main.asm | 57 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/main.asm b/main.asm index b34e87298..554f97b02 100644 --- a/main.asm +++ b/main.asm @@ -20853,12 +20853,15 @@ CheckPartyMove: ; c742 ; c779 Functionc779: ; c779 - ld hl, $4780 + ld hl, UnknownText_0xc780 call Function1d67 ret ; c780 -INCBIN "baserom.gbc", $c780, $c785 - $c780 +UnknownText_0xc780: ; 0xc780 + text_jump UnknownText_0x1c05c8, BANK(UnknownText_0x1c05c8) + db "@" +; 0xc785 Functionc785: ; c785 call Functionc6ea @@ -26272,13 +26275,13 @@ Function12d45: ; 12d45 call LoadMenuDataHeader call Function1d81 call Function1c07 - jp c, $6dc6 + jp c, .asm_12dc6 ld a, [$cfa9] cp $1 jr z, .asm_12d6d cp $2 jr z, .asm_12d76 - jp $6dc6 + jp .asm_12dc6 .asm_12d6d ld a, $2e @@ -26288,24 +26291,24 @@ Function12d45: ; 12d45 ret .asm_12d76 - ld hl, $6df1 + ld hl, UnknownText_0x12df1 call Function12cf5 jr c, .asm_12d9a ld a, [CurPartyMon] ld b, a callba Function4456e jr c, .asm_12d92 - ld hl, $6dfb + ld hl, UnknownText_0x12dfb call Function1d67 jr .asm_12dc6 .asm_12d92 - ld hl, $6df6 + ld hl, UnknownText_0x12df6 call Function1d67 jr .asm_12dc6 .asm_12d9a - ld hl, $6de2 + ld hl, UnknownText_0x12de2 call Function12cf5 jr c, .asm_12dc6 call GetPartyItemLocation @@ -26316,12 +26319,12 @@ Function12d45: ; 12d45 call GetPartyItemLocation ld [hl], $0 call GetCurNick - ld hl, $6de7 + ld hl, UnknownText_0x12de7 call Function1d67 jr .asm_12dc6 .asm_12dbe - ld hl, $6dec + ld hl, UnknownText_0x12dec call Function1d67 jr .asm_12dc6 @@ -26330,7 +26333,39 @@ Function12d45: ; 12d45 ret ; 12dc9 -INCBIN "baserom.gbc", $12dc9, $12e00 - $12dc9 + +INCBIN "baserom.gbc", $12dc9, $12de2 - $12dc9 + + +UnknownText_0x12de2: ; 0x12de2 + text_jump UnknownText_0x1c1c22, BANK(UnknownText_0x1c1c22) + db "@" +; 0x12de7 + +UnknownText_0x12de7: ; 0x12de7 + text_jump UnknownText_0x1c1c47, BANK(UnknownText_0x1c1c47) + db "@" +; 0x12dec + +UnknownText_0x12dec: ; 0x12dec + text_jump UnknownText_0x1c1c62, BANK(UnknownText_0x1c1c62) + db "@" +; 0x12df1 + +UnknownText_0x12df1: ; 0x12df1 + text_jump UnknownText_0x1c1c86, BANK(UnknownText_0x1c1c86) + db "@" +; 0x12df6 + +UnknownText_0x12df6: ; 0x12df6 + text_jump UnknownText_0x1c1ca9, BANK(UnknownText_0x1c1ca9) + db "@" +; 0x12dfb + +UnknownText_0x12dfb: ; 0x12dfb + text_jump UnknownText_0x1c1cc4, BANK(UnknownText_0x1c1cc4) + db "@" +; 0x12e00 OpenPartyStats: ; 12e00 From 9d1a6fe5bbf342434037bbd28d6e9133aa9eb39d Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 02:53:04 -0400 Subject: [PATCH 35/96] more field move scripts --- main.asm | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 160 insertions(+), 16 deletions(-) diff --git a/main.asm b/main.asm index 554f97b02..05b6cd056 100644 --- a/main.asm +++ b/main.asm @@ -20896,7 +20896,7 @@ Functionc7ce: ; c7ce ld c, [hl] push hl ld hl, $4862 - call $4840 + call Functionc840 pop hl jr nc, .asm_c7fc ld a, l @@ -21016,11 +21016,36 @@ Functionc8b5: ; c8b5 ; c8e0 Functionc8e0: ; c8e0 - ld hl, $48e6 + ld hl, UnknownScript_0xc8e6 jp Function31cd ; c8e6 -INCBIN "baserom.gbc", $c8e6, $c909 - $c8e6 +UnknownScript_0xc8e6: ; 0xc8e6 + reloadmappart + special $0035 + 2writetext UnknownText_0xc8f3 + 3callasm $23, $47e1 + loadmovesprites + end +; 0xc8f3 + +UnknownText_0xc8f3: ; 0xc8f3 + text_jump UnknownText_0x1c0609, BANK(UnknownText_0x1c0609) + start_asm +; 0xc8f8 + +Functionc8f8: ; c8f8 + call WaitSFX + ld de, SFX_FLASH + call StartSFX + call WaitSFX + ld hl, UnknownText_0xc908 + ret +; c908 + +UnknownText_0xc908: ; 0xc908 + db "@" +; 0xc909 Functionc909: ; c909 call Functionc6ea @@ -21485,13 +21510,20 @@ Functioncd06: ; cd06 ; cd09 Functioncd09: ; cd09 - ld hl, $4d29 + ld hl, UnknownScript_0xcd29 call Function31cd ld a, $81 ret ; cd12 -INCBIN "baserom.gbc", $cd12, $cd1d - $cd12 +Functioncd12: ; cd12 + ld hl, BikeFlags + set 0, [hl] + ld a, [CurPartyMon] + ld e, a + ld d, 0 + ; fallthrough +; cd1d Functioncd1d: ; cd1d ld hl, PartySpecies @@ -21502,7 +21534,30 @@ Functioncd1d: ; cd1d ret ; cd29 -INCBIN "baserom.gbc", $cd29, $cd9d - $cd29 +UnknownScript_0xcd29: ; 0xcd29 + reloadmappart + special $0035 + 3callasm BANK(Functioncd12), Functioncd12 + 2writetext UnknownText_0xcd41 + copybytetovar $d1ef + cry $0000 + pause 3 + 2writetext UnknownText_0xcd46 + loadmovesprites + end +; 0xcd41 + +UnknownText_0xcd41: ; 0xcd41 + text_jump UnknownText_0x1c0774, BANK(UnknownText_0x1c0774) + db $50 +; 0xcd46 + +UnknownText_0xcd46: ; 0xcd46 + text_jump UnknownText_0x1c0788, BANK(UnknownText_0x1c0788) + db $50 +; 0xcd4b + +INCBIN "baserom.gbc", $cd4b, $cd9d - $cd4b Functioncd9d: ; cd9d call Functionc6ea @@ -21533,7 +21588,7 @@ Functioncdde: ; cdde ld c, [hl] push hl ld hl, $48a4 - call $4840 + call Functionc840 pop hl jr nc, .asm_ce09 ld a, l @@ -21555,15 +21610,33 @@ Functioncdde: ; cdde INCBIN "baserom.gbc", $ce0b, $ce0f - $ce0b UnknownScript_0xce0f: ; 0xce0f - 3callasm $03, $4706 + 3callasm BANK(GetPartyNick), GetPartyNick 2writetext UnknownText_0xcdd9 reloadmappart - 3callasm $03, $4e1d + 3callasm BANK(Functionce1d), Functionce1d loadmovesprites end ; 0xce1d -INCBIN "baserom.gbc", $ce1d, $ce3e - $ce1d +Functionce1d: ; ce1d + ld hl, $d1ec + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [$d1ee] + ld [hl], a + xor a + ld [hBGMapMode], a + call Function2173 + ld a, [$d1ef] + ld e, a + ld a, $23 + ld hl, $47d4 + rst FarCall + call Function2879 + call Function2914 + ret +; ce3e TryWhirlpoolOW: ; ce3e ld d, WHIRLPOOL @@ -21622,7 +21695,7 @@ Functionce86: ; ce86 call GetFacingTileCoord call CheckHeadbuttTreeTile jr nz, .asm_ce97 - ld hl, $4ea7 + ld hl, UnknownScript_0xcea7 call Function31cd ld a, $81 ret @@ -21633,7 +21706,38 @@ Functionce86: ; ce86 ret ; ce9d -INCBIN "baserom.gbc", $ce9d, $cec9 - $ce9d +UnknownText_0xce9d: ; 0xce9d + text_jump UnknownText_0x1c0897, BANK(UnknownText_0x1c0897) + db $50 +; 0xcea2 + +UnknownText_0xcea2: ; 0xcea2 + text_jump UnknownText_0x1c08ac, BANK(UnknownText_0x1c08ac) + db $50 +; 0xcea7 + +UnknownScript_0xcea7: ; 0xcea7 + reloadmappart + special $0035 + 3callasm BANK(GetPartyNick), GetPartyNick + 2writetext UnknownText_0xce9d + reloadmappart + 3callasm $23, $480a + 3callasm $2e, $41ea + iffalse UnknownScript_0xcec3 + loadmovesprites + battlecheck + startbattle + returnafterbattle + end +; 0xcec3 + +UnknownScript_0xcec3: ; 0xcec3 + 2writetext UnknownText_0xcea2 + closetext + loadmovesprites + end +; 0xcec9 TryHeadbuttOW: ; cec9 ld d, $1d @@ -21665,7 +21769,7 @@ Functioncef4: ; cef4 ld a, d cp $18 jr nz, .asm_cf07 - ld hl, $4f2e + ld hl, UnknownScript_0xcf2e call Function31cd ld a, $81 ret @@ -21698,7 +21802,37 @@ Functioncf0d: ; cf0d ret ; cf2e -INCBIN "baserom.gbc", $cf2e, $cf8e - $cf2e +UnknownScript_0xcf2e: ; 0xcf2e + reloadmappart + special $0035 + 3callasm BANK(GetPartyNick), GetPartyNick + 2writetext UnknownText_0xcf58 + loadmovesprites + special $003b + playsound SFX_STRENGTH + earthquake 84 + applymovement2 MovementData_0xcf55 + disappear $fe + 3callasm $2e, $4219 + copybytetovar $d22e + iffalse .done + battlecheck + startbattle + returnafterbattle +.done + end +; 0xcf55 + +MovementData_0xcf55: ; 0xcf55 + db $57, $0a + step_end + +UnknownText_0xcf58: ; 0xcf58 + text_jump UnknownText_0x1c08f0, BANK(UnknownText_0x1c08f0) + db $50 +; 0xcf5d + +INCBIN "baserom.gbc", $cf5d, $cf8e - $cf5d Functioncf8e: ; cf8e @@ -53534,7 +53668,7 @@ Function506bc: ; 506bc UnknownScript_0x506c8: ; 0x506c8 reloadmappart special $0035 - 3callasm $03, $4706 + 3callasm BANK(GetPartyNick), GetPartyNick 2writetext UnknownText_0x50726 closetext 3callasm BANK(Function506ef), Function506ef @@ -58000,7 +58134,17 @@ Function8c6ef: ; 8c6ef ret ; 8c6f7 -INCBIN "baserom.gbc", $8c6f7, $8c940 - $8c6f7 +INCBIN "baserom.gbc", $8c6f7, $8c7d4 - $8c6f7 + +Function8c7d4: ; 8c7d4 + call WaitSFX + ld de, $0053 + call StartSFX + call WaitSFX + ret +; 8c7e1 + +INCBIN "baserom.gbc", $8c7e1, $8c940 - $8c7e1 Function8c940: ; 8c940 ld a, e From 99760c2cc99b6e235b490ec5a9b8599adce20bfa Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 03:04:23 -0400 Subject: [PATCH 36/96] more hlcoords in bank 1 --- main.asm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.asm b/main.asm index 05b6cd056..411e84c3f 100644 --- a/main.asm +++ b/main.asm @@ -65788,7 +65788,7 @@ Options_TextSpeed: ; e42f5 ld e, [hl] inc hl ld d, [hl] - ld hl, $c4e7 + hlcoord 11, 3 call PlaceString and a ret @@ -65862,7 +65862,7 @@ Options_BattleScene: ; e4365 ld de, .Off .asm_e4390 - ld hl, $c50f + hlcoord 11, 5 call PlaceString and a ret @@ -65905,7 +65905,7 @@ Options_BattleStyle: ; e43a0 ld de, .Set .asm_e43c9 - ld hl, $c537 + hlcoord 11, 7 call PlaceString and a ret @@ -65955,7 +65955,7 @@ Options_Sound: ; e43dd ld de, .Stereo .asm_e440e - ld hl, $c55f + hlcoord 11, 9 call PlaceString and a ret @@ -66007,7 +66007,7 @@ Options_Print: ; e4424 ld e, [hl] inc hl ld d, [hl] - ld hl, $c587 + hlcoord 11, 11 call PlaceString and a ret @@ -66098,7 +66098,7 @@ Options_MenuAccount: ; e44c1 ld de, .On .asm_e44ea - ld hl, $c5af + hlcoord 11, 13 call PlaceString and a ret @@ -66206,7 +66206,7 @@ Functione452a: ; e452a ; e455c Functione455c: ; e455c - ld hl, $c4b5 + hlcoord 1, 1 ld de, $0014 ld c, $10 .asm_e4564 @@ -66214,7 +66214,7 @@ Functione455c: ; e455c add hl, de dec c jr nz, .asm_e4564 - ld hl, $c4c9 + hlcoord 1, 2 ld bc, $0028 ld a, [$cf63] call AddNTimes From 1a5f9426c8fad04abad2ed2c39956f4dae4d7980 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 03:20:46 -0400 Subject: [PATCH 37/96] get rid of a trailing incbin at the end of bank 21 --- main.asm | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/main.asm b/main.asm index 411e84c3f..6b389a411 100644 --- a/main.asm +++ b/main.asm @@ -56957,7 +56957,7 @@ Function86810: ; 86810 callba GetPlayerBackpic ld a, $31 ld [$ffad], a - ld hl, $c51e + hlcoord 6, 6 ld bc, $0606 ld a, $13 call Predef @@ -56984,7 +56984,7 @@ Function86810: ; 86810 rst FarCall xor a ld [$ffad], a - ld hl, $c510 + hlcoord 12, 5 ld bc, $0707 ld a, $13 call Predef @@ -56997,29 +56997,29 @@ Function86810: ; 86810 call Function86643 xor a ld [hBGMapMode], a - ld hl, $c4c8 + hlcoord 0, 2 ld bc, $0809 call TextBox - ld hl, $c590 + hlcoord 0, 12 ld bc, $0412 call TextBox - ld hl, $c4f2 + hlcoord 2, 4 ld de, PlayerName call PlaceString - ld hl, $c519 + hlcoord 1, 6 ld a, $73 ld [hli], a ld a, $74 ld [hli], a ld [hl], $f3 - ld hl, $c51c + hlcoord 4, 6 ld de, PlayerID ld bc, $8205 call PrintNum - ld hl, $c541 - ld de, $68ed + hlcoord 1, 8 + ld de, .PlayTime call PlaceString - ld hl, $c557 + hlcoord 3, 9 ld de, GameTimeHours ld bc, $0203 call PrintNum @@ -57033,7 +57033,10 @@ Function86810: ; 86810 ret ; 868ed -INCBIN "baserom.gbc", $868ed, $88000 - $868ed +.PlayTime + db "PLAY TIME@" +; 868f7 + SECTION "bank22",ROMX,BANK[$22] From 9da5768b34316e5b6a68daa9e789c8163b31d4ad Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Thu, 29 Aug 2013 11:56:20 -0500 Subject: [PATCH 38/96] fix baserom.gbc check in Makefile --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 54b8b57a3..00c634b3e 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ PNG_GFX := $(shell find gfx/ -type f -name '*.png') LZ_GFX := $(shell find gfx/ -type f -name '*.lz') TWOBPP_GFX := $(shell find gfx/ -type f -name '*.2bpp') -all: pokecrystal.gbc - cmp baserom.gbc $< +all: baserom.gbc pokecrystal.gbc + cmp baserom.gbc pokecrystal.gbc clean: rm -f pokecrystal.o pokecrystal.gbc @echo 'rm -f $(TEXTFILES:.asm=.tx)' @@ -19,10 +19,10 @@ pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constan .asm.tx: $(eval TEXTQUEUE := $(TEXTQUEUE) $<) @rm -f $@ -baserom: +baserom.gbc: python -c "import os; assert 'baserom.gbc' in os.listdir('.'), 'Wait! Need baserom.gbc first. Check README and INSTALL for details.';" -pokecrystal.gbc: baserom pokecrystal.o +pokecrystal.gbc: pokecrystal.o rgblink -n pokecrystal.sym -m pokecrystal.map -o $@ $< rgbfix -Cjv -i BYTE -k 01 -l 0x33 -m 0x10 -p 0 -r 3 -t PM_CRYSTAL $@ From a167620109f5a71503e11fc43bbfef7686cf74b6 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 14:49:07 -0400 Subject: [PATCH 39/96] more field move scripts and some map header references --- main.asm | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 206 insertions(+), 13 deletions(-) diff --git a/main.asm b/main.asm index 6b389a411..38cd0c037 100644 --- a/main.asm +++ b/main.asm @@ -21454,7 +21454,7 @@ Functioncb95: ; cb95 .asm_cba1 ld [Buffer2], a .asm_cba4 - ld hl, $4bb2 + ld hl, Tablecbb2 call Functionc6f5 jr nc, .asm_cba4 and $7f @@ -21462,12 +21462,134 @@ Functioncb95: ; cb95 ret ; cbb2 -INCBIN "baserom.gbc", $cbb2, $cc61 - $cbb2 +Tablecbb2: ; cbb2 + dw Functioncbb8 + dw Functioncbd8 + dw Functioncc06 +; cbb8 + +Functioncbb8: ; cbb8 + call GetMapPermission + cp $4 + jr z, .asm_cbc6 + cp $7 + jr z, .asm_cbc6 +.asm_cbc3 + ld a, $2 + ret + +.asm_cbc6 + ld hl, $dca9 + ld a, [hli] + and a + jr z, .asm_cbc3 + ld a, [hli] + and a + jr z, .asm_cbc3 + ld a, [hl] + and a + jr z, .asm_cbc3 + ld a, $1 + ret +; cbd8 + +Functioncbd8: ; cbd8 + ld hl, $dca9 + ld de, $d146 + ld bc, $0003 + call CopyBytes + call GetPartyNick + ld a, [Buffer2] + cp $2 + jr nz, .asm_cbf7 + ld hl, $4c35 + call Function31cd + ld a, $81 + ret + +.asm_cbf7 + callba Function8ae4e + ld hl, UnknownScript_0xcc2b + call Function31cd + ld a, $81 + ret +; cc06 + +Functioncc06: ; cc06 + ld a, [Buffer2] + cp $2 + jr nz, .asm_cc19 + ld hl, UnknownText_0xcc26 + call Function1d4f + call Functiona80 + call Function1c17 + +.asm_cc19 + ld a, $80 + ret +; cc1c + +UnknownText_0xcc1c: ; 0xcc1c + ; used DIG! + text_jump UnknownText_0x1c06de, BANK(UnknownText_0x1c06de) + db "@" +; 0xcc21 + +UnknownText_0xcc21: ; 0xcc21 + ; used an ESCAPE ROPE. + text_jump UnknownText_0x1c06ed, BANK(UnknownText_0x1c06ed) + db "@" +; 0xcc26 + +UnknownText_0xcc26: ; 0xcc26 + ; Can't use that here. + text_jump UnknownText_0x1c0705, BANK(UnknownText_0x1c0705) + db "@" +; 0xcc2b + +UnknownScript_0xcc2b: ; 0xcc2b + reloadmappart + special $0035 + 2writetext UnknownText_0xcc21 + 2jump UnknownScript_0xcc3c +; 0xcc35 + +UnknownScript_0xcc35: ; 0xcc35 + reloadmappart + special $0035 + 2writetext UnknownText_0xcc1c + +UnknownScript_0xcc3c: ; 0xcc3c + closetext + loadmovesprites + playsound $0013 + applymovement $0, MovementData_0xcc59 + 3call BANK(UnknownScript_0x122c1), UnknownScript_0x122c1 + special $0000 + writecode $8, $0 + newloadmap $f5 + playsound $0014 + applymovement $0, MovementData_0xcc5d + end +; 0xcc59 + +MovementData_0xcc59: ; 0xcc59 + step_wait5 + turn_away_down + hide_person + step_end +; 0xcc5d + +MovementData_0xcc5d: ; 0xcc5d + db $3c, $58 + turn_away_down + step_end +; 0xcc61 Functioncc61: ; cc61 call Functionc6ea .asm_cc64 - ld hl, $4c72 + ld hl, Tablecc72 call Functionc6f5 jr nc, .asm_cc64 and $7f @@ -21475,7 +21597,51 @@ Functioncc61: ; cc61 ret ; cc72 -INCBIN "baserom.gbc", $cc72, $cce5 - $cc72 +Tablecc72: ; cc72 + dw Functioncc78 + dw Functioncc9c + dw Functioncca8 +; cc78 + +Functioncc78: ; cc78 + call GetMapPermission + call CheckOutdoorMap + jr z, .asm_cc82 + jr .asm_cc99 + +.asm_cc82 + ld a, [$dcb2] + ld d, a + ld a, [$dcb3] + ld e, a + callba Function15344 + jr nc, .asm_cc99 + ld a, c + ld [$d001], a + ld a, $1 + ret + +.asm_cc99 + ld a, $2 + ret +; cc9c + +Functioncc9c: ; cc9c + call GetPartyNick + ld hl, $4cbb + call Function31cd + ld a, $81 + ret +; cca8 + +Functioncca8: ; cca8 + ld hl, $4cb6 + call Function1d67 + ld a, $80 + ret +; ccb1 + +INCBIN "baserom.gbc", $ccb1, $cce5 - $ccb1 Functioncce5: ; cce5 call Functionccee @@ -57286,8 +57452,9 @@ ClearScreenArea: ; 0x896ff ; hl = address of upper left corner of the area ; b = height ; c = width - ld a, $7f ; blank tile - ld de, 20 ; screen width + + ld a, " " ; blank tile + ld de, 20 ; screen width .loop push bc push hl @@ -57300,6 +57467,7 @@ ClearScreenArea: ; 0x896ff add hl, de dec b jr nz, .loop + dec hl inc c inc c @@ -57324,7 +57492,7 @@ SpecialHoOhChamber: ; 0x8addb jr nz, .done ; if not, we're done call GetSecondaryMapHeaderPointer ld de, $0326 - ld b, $1 + ld b, SET_FLAG call EventFlagAction .done ret @@ -57335,29 +57503,54 @@ INCBIN "baserom.gbc", $8adef, $8ae30 - $8adef Function8ae30: ; 8ae30 push de push bc + call GetSecondaryMapHeaderPointer ld a, h - cp $58 + cp RuinsofAlphAerodactylChamber_SecondMapHeader >> 8 jr nz, .asm_8ae4a ld a, l - cp $e8 + cp RuinsofAlphAerodactylChamber_SecondMapHeader & $ff jr nz, .asm_8ae4a + ld de, $0329 - ld b, $1 + ld b, SET_FLAG call EventFlagAction + scf - jr .asm_8ae4b + jr .done .asm_8ae4a and a -.asm_8ae4b +.done pop bc pop de ret ; 8ae4e -INCBIN "baserom.gbc", $8ae4e, $8b170 - $8ae4e +Function8ae4e: ; 8ae4e + push hl + push de + + call GetSecondaryMapHeaderPointer + ld a, h + cp RuinsofAlphKabutoChamber_SecondMapHeader >> 8 + jr nz, .done + ld a, l + cp RuinsofAlphKabutoChamber_SecondMapHeader & $ff + jr nz, .done + + ld de, $0327 + ld b, SET_FLAG + call EventFlagAction + +.done + pop de + pop hl + ret +; 8ae68 + +INCBIN "baserom.gbc", $8ae68, $8b170 - $8ae68 SpecialDratini: ; 0x8b170 ; if ScriptVar is 0 or 1, change the moveset of the last Dratini in the party. From ae1d50c0262ff63557929dea47d6c20c2651d1ba Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 15:24:37 -0400 Subject: [PATCH 40/96] warp sound effects in field moves --- main.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.asm b/main.asm index 38cd0c037..01d6cc5bb 100644 --- a/main.asm +++ b/main.asm @@ -21562,13 +21562,13 @@ UnknownScript_0xcc35: ; 0xcc35 UnknownScript_0xcc3c: ; 0xcc3c closetext loadmovesprites - playsound $0013 + playsound SFX_WARP_TO applymovement $0, MovementData_0xcc59 3call BANK(UnknownScript_0x122c1), UnknownScript_0x122c1 special $0000 writecode $8, $0 newloadmap $f5 - playsound $0014 + playsound SFX_WARP_FROM applymovement $0, MovementData_0xcc5d end ; 0xcc59 From 37a841797e3f36c6a1155e4310d232057c192107 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 16:03:18 -0400 Subject: [PATCH 41/96] secret ruins of alph water stone room asm --- main.asm | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/main.asm b/main.asm index 01d6cc5bb..bd2b407c6 100644 --- a/main.asm +++ b/main.asm @@ -57498,7 +57498,47 @@ SpecialHoOhChamber: ; 0x8addb ret ; 0x8adef -INCBIN "baserom.gbc", $8adef, $8ae30 - $8adef +Function8adef: ; 8adef + call GetSecondaryMapHeaderPointer + ld de, $0328 + ld b, CHECK_FLAG + call EventFlagAction + ld a, c + and a + jr nz, .asm_8ae2f + + ld a, WATER_STONE + ld [CurItem], a + ld hl, NumItems + call Function2f79 + jr c, .asm_8ae24 + + ld a, [PartyCount] + ld b, a + inc b +.asm_8ae10 + dec b + jr z, .asm_8ae2f + ld a, b + dec a + ld [CurPartyMon], a + push bc + ld a, $1 + call GetPartyParamLocation + pop bc + ld a, [hl] + cp $18 + jr nz, .asm_8ae10 + +.asm_8ae24 + call GetSecondaryMapHeaderPointer + ld de, $0328 + ld b, SET_FLAG + call EventFlagAction + +.asm_8ae2f + ret +; 8ae30 Function8ae30: ; 8ae30 push de From 2b5b6f3e3a1375066371beecb7e14ae9be1ae626 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 18:50:59 -0400 Subject: [PATCH 42/96] split fading functions out of main.asm --- engine/fade.asm | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 130 +--------------------------------------------- 2 files changed, 135 insertions(+), 129 deletions(-) create mode 100644 engine/fade.asm diff --git a/engine/fade.asm b/engine/fade.asm new file mode 100644 index 000000000..d67211e29 --- /dev/null +++ b/engine/fade.asm @@ -0,0 +1,134 @@ +; Functions to fade the screen in and out. + + +Function48c: ; 48c + ld a, [TimeOfDayPal] + ld b, a + ld hl, IncGradGBPalTable_11 + ld a, l + sub b + ld l, a + jr nc, .asm_499 + dec h + +.asm_499 + ld a, [hli] + ld [rBGP], a + ld a, [hli] + ld [rOBP0], a + ld a, [hli] + ld [rOBP1], a + ret +; 4a3 + + +Function4a3: ; 4a3 + ld a, [hCGB] + and a + jr z, .asm_4af + ld hl, IncGradGBPalTable_00 + ld b, 4 + jr FadeOut + +.asm_4af + ld hl, IncGradGBPalTable_08 + ld b, 4 + jr FadeOut +; 4b6 + +Function4b6: ; 4b6 + ld a, [hCGB] + and a + jr z, .asm_4c2 + ld hl, IncGradGBPalTable_05 + ld b, 3 + jr FadeOut + +.asm_4c2 + ld hl, IncGradGBPalTable_13 + ld b, 3 +; 4c7 + +FadeOut: ; 4c7 + push de + ld a, [hli] + call DmgToCgbBGPals + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + call DmgToCgbObjPals + ld c, 8 + call DelayFrames + pop de + dec b + jr nz, FadeOut + ret +; 4dd + +Function4dd: ; 4dd + ld a, [hCGB] + and a + jr z, .asm_4e9 + ld hl, IncGradGBPalTable_04 - 1 + ld b, 4 + jr FadeIn + +.asm_4e9 + ld hl, IncGradGBPalTable_12 - 1 + ld b, 4 + jr FadeIn +; 4f0 + +Function4f0: ; 4f0 + ld a, [hCGB] + and a + jr z, .asm_4fc + ld hl, IncGradGBPalTable_07 - 1 + ld b, 3 + jr FadeIn + +.asm_4fc + ld hl, IncGradGBPalTable_15 - 1 + ld b, 3 + ; fallthrough +; 501 + +FadeIn: ; 501 + push de + ld a, [hld] + ld d, a + ld a, [hld] + ld e, a + call DmgToCgbObjPals + ld a, [hld] + call DmgToCgbBGPals + ld c, 8 + call DelayFrames + pop de + dec b + jr nz, FadeIn + ret +; 517 + + +; 517 +IncGradGBPalTable_00: db %11111111, %11111111, %11111111 +IncGradGBPalTable_01: db %11111110, %11111110, %11111110 +IncGradGBPalTable_02: db %11111001, %11111001, %11111001 +IncGradGBPalTable_03: db %11100100, %11100100, %11100100 +IncGradGBPalTable_04: db %11100100, %11100100, %11100100 +IncGradGBPalTable_05: db %10010000, %10010000, %10010000 +IncGradGBPalTable_06: db %01000000, %01000000, %01000000 +IncGradGBPalTable_07: db %00000000, %00000000, %00000000 +; bgp obp1 obp2 +IncGradGBPalTable_08: db %11111111, %11111111, %11111111 +IncGradGBPalTable_09: db %11111110, %11111110, %11111000 +IncGradGBPalTable_10: db %11111001, %11100100, %11100100 +IncGradGBPalTable_11: db %11100100, %11010000, %11100000 +IncGradGBPalTable_12: db %11100100, %11010000, %11100000 +IncGradGBPalTable_13: db %10010000, %10000000, %10010000 +IncGradGBPalTable_14: db %01000000, %01000000, %01000000 +IncGradGBPalTable_15: db %00000000, %00000000, %00000000 +; 547 + diff --git a/main.asm b/main.asm index bd2b407c6..487599ddb 100644 --- a/main.asm +++ b/main.asm @@ -112,136 +112,8 @@ Function485: ; 485 ret ; 48c -Function48c: ; 48c - ld a, [TimeOfDayPal] - ld b, a - ld hl, IncGradGBPalTable_11 - ld a, l - sub b - ld l, a - jr nc, .asm_499 - dec h -.asm_499 - ld a, [hli] - ld [rBGP], a - ld a, [hli] - ld [rOBP0], a - ld a, [hli] - ld [rOBP1], a - ret -; 4a3 - - -Function4a3: ; 4a3 - ld a, [hCGB] - and a - jr z, .asm_4af - ld hl, IncGradGBPalTable_00 - ld b, 4 - jr FadeOut - -.asm_4af - ld hl, IncGradGBPalTable_08 - ld b, 4 - jr FadeOut -; 4b6 - -Function4b6: ; 4b6 - ld a, [hCGB] - and a - jr z, .asm_4c2 - ld hl, IncGradGBPalTable_05 - ld b, 3 - jr FadeOut - -.asm_4c2 - ld hl, IncGradGBPalTable_13 - ld b, 3 -; 4c7 - -FadeOut: ; 4c7 - push de - ld a, [hli] - call DmgToCgbBGPals - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - call DmgToCgbObjPals - ld c, 8 - call DelayFrames - pop de - dec b - jr nz, FadeOut - ret -; 4dd - -Function4dd: ; 4dd - ld a, [hCGB] - and a - jr z, .asm_4e9 - ld hl, IncGradGBPalTable_04 - 1 - ld b, 4 - jr FadeIn - -.asm_4e9 - ld hl, IncGradGBPalTable_12 - 1 - ld b, 4 - jr FadeIn -; 4f0 - -Function4f0: ; 4f0 - ld a, [hCGB] - and a - jr z, .asm_4fc - ld hl, IncGradGBPalTable_07 - 1 - ld b, 3 - jr FadeIn - -.asm_4fc - ld hl, IncGradGBPalTable_15 - 1 - ld b, 3 - ; fallthrough -; 501 - -FadeIn: ; 501 - push de - ld a, [hld] - ld d, a - ld a, [hld] - ld e, a - call DmgToCgbObjPals - ld a, [hld] - call DmgToCgbBGPals - ld c, 8 - call DelayFrames - pop de - dec b - jr nz, FadeIn - ret -; 517 - - -; 517 -IncGradGBPalTable_00: db %11111111, %11111111, %11111111 -IncGradGBPalTable_01: db %11111110, %11111110, %11111110 -IncGradGBPalTable_02: db %11111001, %11111001, %11111001 -IncGradGBPalTable_03: db %11100100, %11100100, %11100100 -IncGradGBPalTable_04: db %11100100, %11100100, %11100100 -IncGradGBPalTable_05: db %10010000, %10010000, %10010000 -IncGradGBPalTable_06: db %01000000, %01000000, %01000000 -IncGradGBPalTable_07: db %00000000, %00000000, %00000000 -; bgp obp1 obp2 -IncGradGBPalTable_08: db %11111111, %11111111, %11111111 -IncGradGBPalTable_09: db %11111110, %11111110, %11111000 -IncGradGBPalTable_10: db %11111001, %11100100, %11100100 -IncGradGBPalTable_11: db %11100100, %11010000, %11100000 -IncGradGBPalTable_12: db %11100100, %11010000, %11100000 -IncGradGBPalTable_13: db %10010000, %10000000, %10010000 -IncGradGBPalTable_14: db %01000000, %01000000, %01000000 -IncGradGBPalTable_15: db %00000000, %00000000, %00000000 -; 547 +INCLUDE "engine/fade.asm" Function547: ; 547 From 906496e10735bb7ad6b4b5de9802b3021aebaf28 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 18:52:16 -0400 Subject: [PATCH 43/96] split lcd functions out of main.asm --- engine/lcd.asm | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 78 +----------------------------------------------- 2 files changed, 82 insertions(+), 77 deletions(-) create mode 100644 engine/lcd.asm diff --git a/engine/lcd.asm b/engine/lcd.asm new file mode 100644 index 000000000..9c86eaa5c --- /dev/null +++ b/engine/lcd.asm @@ -0,0 +1,81 @@ +; LCD handling + + +Function547: ; 547 + ld a, [hLCDStatCustom] + cp rSCX & $ff + ret nz + ld c, a + ld a, [LYOverrides] + ld [$ff00+c], a + ret +; 552 + + +LCD: ; 552 + push af + ld a, [hLCDStatCustom] + and a + jr z, .done + +; At this point it's assumed we're in WRAM bank 5! + push bc + ld a, [rLY] + ld c, a + ld b, LYOverrides >> 8 + ld a, [bc] + ld b, a + ld a, [hLCDStatCustom] + ld c, a + ld a, b + ld [$ff00+c], a + pop bc + +.done + pop af + reti +; 568 + + +DisableLCD: ; 568 +; Turn the LCD off + +; Don't need to do anything if the LCD is already off + ld a, [rLCDC] + bit 7, a ; lcd enable + ret z + + xor a + ld [rIF], a + ld a, [rIE] + ld b, a + +; Disable VBlank + res 0, a ; vblank + ld [rIE], a + +.wait +; Wait until VBlank would normally happen + ld a, [rLY] + cp 145 + jr nz, .wait + + ld a, [rLCDC] + and %01111111 ; lcd enable off + ld [rLCDC], a + + xor a + ld [rIF], a + ld a, b + ld [rIE], a + ret +; 58a + + +EnableLCD: ; 58a + ld a, [rLCDC] + set 7, a ; lcd enable + ld [rLCDC], a + ret +; 591 + diff --git a/main.asm b/main.asm index 487599ddb..1771f7a47 100644 --- a/main.asm +++ b/main.asm @@ -116,83 +116,7 @@ Function485: ; 485 INCLUDE "engine/fade.asm" -Function547: ; 547 - ld a, [hLCDStatCustom] - cp rSCX & $ff - ret nz - ld c, a - ld a, [LYOverrides] - ld [$ff00+c], a - ret -; 552 - - -LCD: ; 552 - push af - ld a, [hLCDStatCustom] - and a - jr z, .done - -; At this point it's assumed we're in WRAM bank 5! - push bc - ld a, [rLY] - ld c, a - ld b, LYOverrides >> 8 - ld a, [bc] - ld b, a - ld a, [hLCDStatCustom] - ld c, a - ld a, b - ld [$ff00+c], a - pop bc - -.done - pop af - reti -; 568 - - -DisableLCD: ; 568 -; Turn the LCD off - -; Don't need to do anything if the LCD is already off - ld a, [rLCDC] - bit 7, a ; lcd enable - ret z - - xor a - ld [rIF], a - ld a, [rIE] - ld b, a - -; Disable VBlank - res 0, a ; vblank - ld [rIE], a - -.wait -; Wait until VBlank would normally happen - ld a, [rLY] - cp 145 - jr nz, .wait - - ld a, [rLCDC] - and %01111111 ; lcd enable off - ld [rLCDC], a - - xor a - ld [rIF], a - ld a, b - ld [rIE], a - ret -; 58a - - -EnableLCD: ; 58a - ld a, [rLCDC] - set 7, a ; lcd enable - ld [rLCDC], a - ret -; 591 +INCLUDE "engine/lcd.asm" AskTimer: ; 591 From 0a829301ae610f855c29e3288ac59dde8730fa20 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 18:58:38 -0400 Subject: [PATCH 44/96] reformat some joypad functions --- main.asm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/main.asm b/main.asm index 1771f7a47..6c04f5cf2 100644 --- a/main.asm +++ b/main.asm @@ -839,19 +839,24 @@ INCLUDE "engine/joypad.asm" Functiona1b: ; a1b -.asm_a1b + call DelayFrame + push bc call Functiona57 pop bc + ld a, [hJoyDown] - cp $46 + cp D_UP | SELECT | BUTTON_B jr z, .asm_a34 + ld a, [$ffa9] and $9 jr nz, .asm_a34 + dec c - jr nz, .asm_a1b + jr nz, Functiona1b + and a ret @@ -861,22 +866,20 @@ Functiona1b: ; a1b ; a36 - Functiona36: ; a36 -.asm_a36 call DelayFrame call GetJoypadPublic ld a, [hJoyPressed] - and $3 + and BUTTON_A | BUTTON_B ret nz call RTC - jr .asm_a36 + jr Functiona36 ; a46 Functiona46: ; a46 ld a, [hOAMUpdate] push af - ld a, $1 + ld a, 1 ld [hOAMUpdate], a call WaitBGMap call Functiona36 @@ -885,8 +888,6 @@ Functiona46: ; a46 ret ; a57 - - Functiona57: ; a57 call GetJoypadPublic ld a, [$ffaa] @@ -894,13 +895,12 @@ Functiona57: ; a57 ld a, [hJoyPressed] jr z, .asm_a63 ld a, [hJoyDown] - .asm_a63 ld [$ffa9], a ld a, [hJoyPressed] and a jr z, .asm_a70 - ld a, $f + ld a, 15 ld [TextDelayFrames], a ret @@ -913,7 +913,7 @@ Functiona57: ; a57 ret .asm_a7a - ld a, $5 + ld a, 5 ld [TextDelayFrames], a ret ; a80 From dd11c22b316681b0c6e5dac69d519439163efc53 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 19:08:25 -0400 Subject: [PATCH 45/96] more joypad function cleanup --- main.asm | 75 +++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/main.asm b/main.asm index 6c04f5cf2..fa72231d3 100644 --- a/main.asm +++ b/main.asm @@ -851,7 +851,7 @@ Functiona1b: ; a1b jr z, .asm_a34 ld a, [$ffa9] - and $9 + and START | BUTTON_A jr nz, .asm_a34 dec c @@ -919,14 +919,14 @@ Functiona57: ; a57 ; a80 Functiona80: ; a80 - ld a, [hConnectionStripLength] + ld a, [$ffaf] push af - ld a, [hConnectedMapWidth] + ld a, [$ffb0] push af xor a - ld [hConnectionStripLength], a + ld [$ffaf], a ld a, $6 - ld [hConnectedMapWidth], a + ld [$ffb0], a .asm_a8d push hl ld hl, $c606 @@ -937,23 +937,20 @@ Functiona80: ; a80 and $3 jr z, .asm_a8d pop af - ld [hConnectedMapWidth], a + ld [$ffb0], a pop af - ld [hConnectionStripLength], a + ld [$ffaf], a ret ; aa5 Functionaa5: ; aa5 -.asm_aa5 call Functiona57 ld a, [$ffa9] - and $3 - jr z, .asm_aa5 + and BUTTON_A | BUTTON_B + jr z, Functionaa5 ret ; aaf - - Functionaaf: ; aaf ld a, [InLinkBattle] and a @@ -966,7 +963,7 @@ Functionaaf: ; aaf ret .asm_ac1 - ld c, $41 + ld c, 65 jp DelayFrames ; ac6 @@ -978,10 +975,7 @@ Functionac6: ; ac6 ld a, [InputType] or a jr z, .asm_ad9 - ld a, $77 - ld hl, $628a - rst FarCall - + callba Function1de28a .asm_ad9 call Functionaf5 call Functiona57 @@ -1023,37 +1017,37 @@ Functionb06: ; b06 cp b pop bc jr nz, .asm_b27 - ld a, [hConnectionStripLength] + ld a, [$ffaf] dec a - ld [hConnectionStripLength], a + ld [$ffaf], a ret nz - ld a, [hConnectedMapWidth] + ld a, [$ffb0] dec a - ld [hConnectedMapWidth], a + ld [$ffb0], a ret nz ld a, $7a ld [hl], a ld a, $ff - ld [hConnectionStripLength], a + ld [$ffaf], a ld a, $6 - ld [hConnectedMapWidth], a + ld [$ffb0], a ret .asm_b27 - ld a, [hConnectionStripLength] + ld a, [$ffaf] and a ret z dec a - ld [hConnectionStripLength], a + ld [$ffaf], a ret nz dec a - ld [hConnectionStripLength], a - ld a, [hConnectedMapWidth] + ld [$ffaf], a + ld a, [$ffb0] dec a - ld [hConnectedMapWidth], a + ld [$ffb0], a ret nz ld a, $6 - ld [hConnectedMapWidth], a + ld [$ffb0], a ld a, $ee ld [hl], a ret @@ -24665,9 +24659,7 @@ Function107bb: ; 107bb ld a, [InputType] or a jr z, .asm_107ca - ld a, $77 - ld hl, $628f - rst FarCall + callba Function1de28f .asm_107ca call Function107d7 @@ -43088,10 +43080,7 @@ Function3e139: ; 3e139 ld a, [InputType] or a jr z, .asm_3e171 - ld a, $77 - ld hl, $6294 - rst FarCall - + callba Function1de294 .asm_3e171 call Function3e19b ret c @@ -74326,22 +74315,26 @@ Function1de27f: ; 1de27f Function1de28a: ; 1de28a ld hl, DudeAutoInput_A - jr .asm_1de299 + jr Function1de299 +; 1de28f +Function1de28f: ; 1de28f ld hl, DudeAutoInput_RightA - jr .asm_1de299 + jr Function1de299 +; 1de294 +Function1de294: ; 1de294 ld hl, DudeAutoInput_DownA - jr .asm_1de299 + jr Function1de299 +; 1de299 -.asm_1de299 +Function1de299: ; 1de299 ld a, $77 call StartAutoInput ret ; 1de29f - DudeAutoInput_A: ; 1de29f db NO_INPUT, $50 db BUTTON_A, $00 From 2341bb148ad651ca20e09ee6e48abd16c6aaee38 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 19:10:06 -0400 Subject: [PATCH 46/96] move more joypad code from main.asm into engine/joypad.asm --- engine/joypad.asm | 216 ++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 216 ---------------------------------------------- 2 files changed, 216 insertions(+), 216 deletions(-) diff --git a/engine/joypad.asm b/engine/joypad.asm index 5266ef8a8..388c84e22 100644 --- a/engine/joypad.asm +++ b/engine/joypad.asm @@ -273,3 +273,219 @@ StopAutoInput: ; a0a ret ; a1b + +Functiona1b: ; a1b + + call DelayFrame + + push bc + call Functiona57 + pop bc + + ld a, [hJoyDown] + cp D_UP | SELECT | BUTTON_B + jr z, .asm_a34 + + ld a, [$ffa9] + and START | BUTTON_A + jr nz, .asm_a34 + + dec c + jr nz, Functiona1b + + and a + ret + +.asm_a34 + scf + ret +; a36 + + +Functiona36: ; a36 + call DelayFrame + call GetJoypadPublic + ld a, [hJoyPressed] + and BUTTON_A | BUTTON_B + ret nz + call RTC + jr Functiona36 +; a46 + +Functiona46: ; a46 + ld a, [hOAMUpdate] + push af + ld a, 1 + ld [hOAMUpdate], a + call WaitBGMap + call Functiona36 + pop af + ld [hOAMUpdate], a + ret +; a57 + +Functiona57: ; a57 + call GetJoypadPublic + ld a, [$ffaa] + and a + ld a, [hJoyPressed] + jr z, .asm_a63 + ld a, [hJoyDown] +.asm_a63 + ld [$ffa9], a + ld a, [hJoyPressed] + and a + jr z, .asm_a70 + ld a, 15 + ld [TextDelayFrames], a + ret + +.asm_a70 + ld a, [TextDelayFrames] + and a + jr z, .asm_a7a + xor a + ld [$ffa9], a + ret + +.asm_a7a + ld a, 5 + ld [TextDelayFrames], a + ret +; a80 + +Functiona80: ; a80 + ld a, [$ffaf] + push af + ld a, [$ffb0] + push af + xor a + ld [$ffaf], a + ld a, $6 + ld [$ffb0], a +.asm_a8d + push hl + ld hl, $c606 + call Functionb06 + pop hl + call Functiona57 + ld a, [$ffa9] + and $3 + jr z, .asm_a8d + pop af + ld [$ffb0], a + pop af + ld [$ffaf], a + ret +; aa5 + +Functionaa5: ; aa5 + call Functiona57 + ld a, [$ffa9] + and BUTTON_A | BUTTON_B + jr z, Functionaa5 + ret +; aaf + +Functionaaf: ; aaf + ld a, [InLinkBattle] + and a + jr nz, .asm_ac1 + call Functionac6 + push de + ld de, SFX_READ_TEXT_2 + call StartSFX + pop de + ret + +.asm_ac1 + ld c, 65 + jp DelayFrames +; ac6 + +Functionac6: ; ac6 + ld a, [hOAMUpdate] + push af + ld a, $1 + ld [hOAMUpdate], a + ld a, [InputType] + or a + jr z, .asm_ad9 + callba Function1de28a +.asm_ad9 + call Functionaf5 + call Functiona57 + ld a, [hJoyPressed] + and $3 + jr nz, .asm_af1 + call RTC + ld a, $1 + ld [hBGMapMode], a + call DelayFrame + jr .asm_ad9 + +.asm_af1 + pop af + ld [hOAMUpdate], a + ret +; af5 + +Functionaf5: ; af5 + ld a, [$ff9b] + and $10 + jr z, .asm_aff + ld a, $ee + jr .asm_b02 + +.asm_aff + ld a, [$c605] + +.asm_b02 + ld [$c606], a + ret +; b06 + +Functionb06: ; b06 + push bc + ld a, [hl] + ld b, a + ld a, $ee + cp b + pop bc + jr nz, .asm_b27 + ld a, [$ffaf] + dec a + ld [$ffaf], a + ret nz + ld a, [$ffb0] + dec a + ld [$ffb0], a + ret nz + ld a, $7a + ld [hl], a + ld a, $ff + ld [$ffaf], a + ld a, $6 + ld [$ffb0], a + ret + +.asm_b27 + ld a, [$ffaf] + and a + ret z + dec a + ld [$ffaf], a + ret nz + dec a + ld [$ffaf], a + ld a, [$ffb0] + dec a + ld [$ffb0], a + ret nz + ld a, $6 + ld [$ffb0], a + ld a, $ee + ld [hl], a + ret +; b40 + diff --git a/main.asm b/main.asm index fa72231d3..4eac9573d 100644 --- a/main.asm +++ b/main.asm @@ -838,222 +838,6 @@ Function919: ; 919 INCLUDE "engine/joypad.asm" -Functiona1b: ; a1b - - call DelayFrame - - push bc - call Functiona57 - pop bc - - ld a, [hJoyDown] - cp D_UP | SELECT | BUTTON_B - jr z, .asm_a34 - - ld a, [$ffa9] - and START | BUTTON_A - jr nz, .asm_a34 - - dec c - jr nz, Functiona1b - - and a - ret - -.asm_a34 - scf - ret -; a36 - - -Functiona36: ; a36 - call DelayFrame - call GetJoypadPublic - ld a, [hJoyPressed] - and BUTTON_A | BUTTON_B - ret nz - call RTC - jr Functiona36 -; a46 - -Functiona46: ; a46 - ld a, [hOAMUpdate] - push af - ld a, 1 - ld [hOAMUpdate], a - call WaitBGMap - call Functiona36 - pop af - ld [hOAMUpdate], a - ret -; a57 - -Functiona57: ; a57 - call GetJoypadPublic - ld a, [$ffaa] - and a - ld a, [hJoyPressed] - jr z, .asm_a63 - ld a, [hJoyDown] -.asm_a63 - ld [$ffa9], a - ld a, [hJoyPressed] - and a - jr z, .asm_a70 - ld a, 15 - ld [TextDelayFrames], a - ret - -.asm_a70 - ld a, [TextDelayFrames] - and a - jr z, .asm_a7a - xor a - ld [$ffa9], a - ret - -.asm_a7a - ld a, 5 - ld [TextDelayFrames], a - ret -; a80 - -Functiona80: ; a80 - ld a, [$ffaf] - push af - ld a, [$ffb0] - push af - xor a - ld [$ffaf], a - ld a, $6 - ld [$ffb0], a -.asm_a8d - push hl - ld hl, $c606 - call Functionb06 - pop hl - call Functiona57 - ld a, [$ffa9] - and $3 - jr z, .asm_a8d - pop af - ld [$ffb0], a - pop af - ld [$ffaf], a - ret -; aa5 - -Functionaa5: ; aa5 - call Functiona57 - ld a, [$ffa9] - and BUTTON_A | BUTTON_B - jr z, Functionaa5 - ret -; aaf - -Functionaaf: ; aaf - ld a, [InLinkBattle] - and a - jr nz, .asm_ac1 - call Functionac6 - push de - ld de, SFX_READ_TEXT_2 - call StartSFX - pop de - ret - -.asm_ac1 - ld c, 65 - jp DelayFrames -; ac6 - -Functionac6: ; ac6 - ld a, [hOAMUpdate] - push af - ld a, $1 - ld [hOAMUpdate], a - ld a, [InputType] - or a - jr z, .asm_ad9 - callba Function1de28a -.asm_ad9 - call Functionaf5 - call Functiona57 - ld a, [hJoyPressed] - and $3 - jr nz, .asm_af1 - call RTC - ld a, $1 - ld [hBGMapMode], a - call DelayFrame - jr .asm_ad9 - -.asm_af1 - pop af - ld [hOAMUpdate], a - ret -; af5 - -Functionaf5: ; af5 - ld a, [$ff9b] - and $10 - jr z, .asm_aff - ld a, $ee - jr .asm_b02 - -.asm_aff - ld a, [$c605] - -.asm_b02 - ld [$c606], a - ret -; b06 - -Functionb06: ; b06 - push bc - ld a, [hl] - ld b, a - ld a, $ee - cp b - pop bc - jr nz, .asm_b27 - ld a, [$ffaf] - dec a - ld [$ffaf], a - ret nz - ld a, [$ffb0] - dec a - ld [$ffb0], a - ret nz - ld a, $7a - ld [hl], a - ld a, $ff - ld [$ffaf], a - ld a, $6 - ld [$ffb0], a - ret - -.asm_b27 - ld a, [$ffaf] - and a - ret z - dec a - ld [$ffaf], a - ret nz - dec a - ld [$ffaf], a - ld a, [$ffb0] - dec a - ld [$ffb0], a - ret nz - ld a, $6 - ld [$ffb0], a - ld a, $ee - ld [hl], a - ret -; b40 - - INCLUDE "engine/decompress.asm" From 64677555685eeeaf6d3d6ae056d93bf2348a0993 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 19:11:39 -0400 Subject: [PATCH 47/96] move serial asm from main.asm into engine/serial.asm --- engine/serial.asm | 408 ++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 406 +-------------------------------------------- 2 files changed, 409 insertions(+), 405 deletions(-) create mode 100644 engine/serial.asm diff --git a/engine/serial.asm b/engine/serial.asm new file mode 100644 index 000000000..fca9d82c3 --- /dev/null +++ b/engine/serial.asm @@ -0,0 +1,408 @@ +Serial: ; 6ef +; The serial interrupt. + + push af + push bc + push de + push hl + + ld a, [$ffc9] + and a + jr nz, .asm_71c + + ld a, [$c2d4] + bit 0, a + jr nz, .asm_721 + + ld a, [$ffcb] + inc a + jr z, .asm_726 + + ld a, [rSB] + ld [hSerialReceive], a + + ld a, [hSerialSend] + ld [rSB], a + + ld a, [$ffcb] + cp $2 + jr z, .asm_752 + + ld a, 0 << rSC_ON + ld [rSC], a + ld a, 1 << rSC_ON + ld [rSC], a + jr .asm_752 + +.asm_71c + call Function3e80 + jr .asm_75a + +.asm_721 + call Function2057 + jr .asm_75a + +.asm_726 + ld a, [rSB] + cp $1 + jr z, .asm_730 + cp $2 + jr nz, .asm_752 + +.asm_730 + ld [hSerialReceive], a + ld [$ffcb], a + cp $2 + jr z, .asm_74f + + xor a + ld [rSB], a + ld a, $3 + ld [rDIV], a + +.asm_73f + ld a, [rDIV] + bit 7, a + jr nz, .asm_73f + + ld a, 0 << rSC_ON + ld [rSC], a + ld a, 1 << rSC_ON + ld [rSC], a + jr .asm_752 + +.asm_74f + xor a + ld [rSB], a + +.asm_752 + ld a, $1 + ld [$ffca], a + ld a, $fe + ld [hSerialSend], a + +.asm_75a + pop hl + pop de + pop bc + pop af + reti +; 75f + +Function75f: ; 75f + ld a, $1 + ld [$ffcc], a +.asm_763 + ld a, [hl] + ld [hSerialSend], a + call Function78a + push bc + ld b, a + inc hl + ld a, $30 +.asm_76e + dec a + jr nz, .asm_76e + ld a, [$ffcc] + and a + ld a, b + pop bc + jr z, .asm_782 + dec hl + cp $fd + jr nz, .asm_763 + xor a + ld [$ffcc], a + jr .asm_763 + +.asm_782 + ld [de], a + inc de + dec bc + ld a, b + or c + jr nz, .asm_763 + ret +; 78a + +Function78a: ; 78a + xor a + ld [$ffca], a + ld a, [$ffcb] + cp $2 + jr nz, .asm_79b + ld a, $1 + ld [rSC], a + ld a, $81 + ld [rSC], a + +.asm_79b + ld a, [$ffca] + and a + jr nz, .asm_7e5 + ld a, [$ffcb] + cp $1 + jr nz, .asm_7c0 + call Function82b + jr z, .asm_7c0 + call .asm_825 + push hl + ld hl, $cf5c + inc [hl] + jr nz, .asm_7b7 + dec hl + inc [hl] + +.asm_7b7 + pop hl + call Function82b + jr nz, .asm_79b + jp Function833 + +.asm_7c0 + ld a, [rIE] + and $f + cp $8 + jr nz, .asm_79b + ld a, [$cf5d] + dec a + ld [$cf5d], a + jr nz, .asm_79b + ld a, [$cf5e] + dec a + ld [$cf5e], a + jr nz, .asm_79b + ld a, [$ffcb] + cp $1 + jr z, .asm_7e5 + ld a, $ff +.asm_7e2 + dec a + jr nz, .asm_7e2 + +.asm_7e5 + xor a + ld [$ffca], a + ld a, [rIE] + and $f + sub $8 + jr nz, .asm_7f8 + ld [$cf5d], a + ld a, $50 + ld [$cf5e], a + +.asm_7f8 + ld a, [hSerialReceive] + cp $fe + ret nz + call Function82b + jr z, .asm_813 + push hl + ld hl, $cf5c + ld a, [hl] + dec a + ld [hld], a + inc a + jr nz, .asm_80d + dec [hl] + +.asm_80d + pop hl + call Function82b + jr z, Function833 + +.asm_813 + ld a, [rIE] + and $f + cp $8 + ld a, $fe + ret z + ld a, [hl] + ld [hSerialSend], a + call DelayFrame + jp Function78a + +.asm_825 + ld a, $f +.asm_827 + dec a + jr nz, .asm_827 + ret +; 82b + +Function82b: ; 82b + push hl + ld hl, $cf5b + ld a, [hli] + or [hl] + pop hl + ret +; 833 + +Function833: ; 833 + dec a + ld [$cf5b], a + ld [$cf5c], a + ret +; 83b + +Function83b: ; 83b + ld hl, $cf56 + ld de, $cf51 + ld c, $2 + ld a, $1 + ld [$ffcc], a +.asm_847 + call DelayFrame + ld a, [hl] + ld [hSerialSend], a + call Function78a + ld b, a + inc hl + ld a, [$ffcc] + and a + ld a, $0 + ld [$ffcc], a + jr nz, .asm_847 + ld a, b + ld [de], a + inc de + dec c + jr nz, .asm_847 + ret +; 862 + +Function862: ; 862 + call Function309d + callab Function4000 + call Function87d + jp Function30b4 +; 871 + + +Function871: ; 871 + call Function309d + callab Function4000 + jp Function87d +; 87d + + + +Function87d: ; 87d + ld a, $ff + ld [$cf52], a +.asm_882 + call Function8c1 + call DelayFrame + call Function82b + jr z, .asm_89e + push hl + ld hl, $cf5c + dec [hl] + jr nz, .asm_89d + dec hl + dec [hl] + jr nz, .asm_89d + pop hl + xor a + jp Function833 + +.asm_89d + pop hl + +.asm_89e + ld a, [$cf52] + inc a + jr z, .asm_882 + ld b, $a +.asm_8a6 + call DelayFrame + call Function8c1 + dec b + jr nz, .asm_8a6 + ld b, $a +.asm_8b1 + call DelayFrame + call Function908 + dec b + jr nz, .asm_8b1 + ld a, [$cf52] + ld [$cf51], a + ret +; 8c1 + +Function8c1: ; 8c1 + push bc + ld b, $60 + ld a, [InLinkBattle] + cp $1 + jr z, .asm_8d7 + ld b, $60 + jr c, .asm_8d7 + cp $2 + ld b, $70 + jr z, .asm_8d7 + ld b, $80 + +.asm_8d7 + call Function8f3 + ld a, [$cf56] + add b + ld [hSerialSend], a + ld a, [$ffcb] + cp $2 + jr nz, .asm_8ee + ld a, $1 + ld [rSC], a + ld a, $81 + ld [rSC], a + +.asm_8ee + call Function8f3 + pop bc + ret +; 8f3 + +Function8f3: ; 8f3 + ld a, [hSerialReceive] + ld [$cf51], a + and $f0 + cp b + ret nz + xor a + ld [hSerialReceive], a + ld a, [$cf51] + and $f + ld [$cf52], a + ret +; 908 + +Function908: ; 908 + xor a + ld [hSerialSend], a + ld a, [$ffcb] + cp $2 + ret nz + ld a, $1 + ld [rSC], a + ld a, $81 + ld [rSC], a + ret +; 919 + +Function919: ; 919 + ld a, [InLinkBattle] + and a + ret nz + ld a, $2 + ld [rSB], a + xor a + ld [hSerialReceive], a + ld a, $0 + ld [rSC], a + ld a, $80 + ld [rSC], a + ret +; 92e + + diff --git a/main.asm b/main.asm index 4eac9573d..f69484000 100644 --- a/main.asm +++ b/main.asm @@ -428,411 +428,7 @@ Function6e3: ; 6e3 ; 6ef -Serial: ; 6ef - push af - push bc - push de - push hl - - ld a, [$ffc9] - and a - jr nz, .asm_71c - - ld a, [$c2d4] - bit 0, a - jr nz, .asm_721 - - ld a, [$ffcb] - inc a - jr z, .asm_726 - - ld a, [rSB] - ld [hSerialReceive], a - - ld a, [hSerialSend] - ld [rSB], a - - ld a, [$ffcb] - cp $2 - jr z, .asm_752 - - ld a, 0 << rSC_ON - ld [rSC], a - ld a, 1 << rSC_ON - ld [rSC], a - jr .asm_752 - -.asm_71c - call Function3e80 - jr .asm_75a - -.asm_721 - call Function2057 - jr .asm_75a - -.asm_726 - ld a, [rSB] - cp $1 - jr z, .asm_730 - cp $2 - jr nz, .asm_752 - -.asm_730 - ld [hSerialReceive], a - ld [$ffcb], a - cp $2 - jr z, .asm_74f - - xor a - ld [rSB], a - ld a, $3 - ld [rDIV], a - -.asm_73f - ld a, [rDIV] - bit 7, a - jr nz, .asm_73f - - ld a, 0 << rSC_ON - ld [rSC], a - ld a, 1 << rSC_ON - ld [rSC], a - jr .asm_752 - -.asm_74f - xor a - ld [rSB], a - -.asm_752 - ld a, $1 - ld [$ffca], a - ld a, $fe - ld [hSerialSend], a - -.asm_75a - pop hl - pop de - pop bc - pop af - reti -; 75f - -Function75f: ; 75f - ld a, $1 - ld [$ffcc], a -.asm_763 - ld a, [hl] - ld [hSerialSend], a - call Function78a - push bc - ld b, a - inc hl - ld a, $30 -.asm_76e - dec a - jr nz, .asm_76e - ld a, [$ffcc] - and a - ld a, b - pop bc - jr z, .asm_782 - dec hl - cp $fd - jr nz, .asm_763 - xor a - ld [$ffcc], a - jr .asm_763 - -.asm_782 - ld [de], a - inc de - dec bc - ld a, b - or c - jr nz, .asm_763 - ret -; 78a - -Function78a: ; 78a - xor a - ld [$ffca], a - ld a, [$ffcb] - cp $2 - jr nz, .asm_79b - ld a, $1 - ld [rSC], a - ld a, $81 - ld [rSC], a - -.asm_79b - ld a, [$ffca] - and a - jr nz, .asm_7e5 - ld a, [$ffcb] - cp $1 - jr nz, .asm_7c0 - call Function82b - jr z, .asm_7c0 - call .asm_825 - push hl - ld hl, $cf5c - inc [hl] - jr nz, .asm_7b7 - dec hl - inc [hl] - -.asm_7b7 - pop hl - call Function82b - jr nz, .asm_79b - jp Function833 - -.asm_7c0 - ld a, [rIE] - and $f - cp $8 - jr nz, .asm_79b - ld a, [$cf5d] - dec a - ld [$cf5d], a - jr nz, .asm_79b - ld a, [$cf5e] - dec a - ld [$cf5e], a - jr nz, .asm_79b - ld a, [$ffcb] - cp $1 - jr z, .asm_7e5 - ld a, $ff -.asm_7e2 - dec a - jr nz, .asm_7e2 - -.asm_7e5 - xor a - ld [$ffca], a - ld a, [rIE] - and $f - sub $8 - jr nz, .asm_7f8 - ld [$cf5d], a - ld a, $50 - ld [$cf5e], a - -.asm_7f8 - ld a, [hSerialReceive] - cp $fe - ret nz - call Function82b - jr z, .asm_813 - push hl - ld hl, $cf5c - ld a, [hl] - dec a - ld [hld], a - inc a - jr nz, .asm_80d - dec [hl] - -.asm_80d - pop hl - call Function82b - jr z, Function833 - -.asm_813 - ld a, [rIE] - and $f - cp $8 - ld a, $fe - ret z - ld a, [hl] - ld [hSerialSend], a - call DelayFrame - jp Function78a - -.asm_825 - ld a, $f -.asm_827 - dec a - jr nz, .asm_827 - ret -; 82b - -Function82b: ; 82b - push hl - ld hl, $cf5b - ld a, [hli] - or [hl] - pop hl - ret -; 833 - -Function833: ; 833 - dec a - ld [$cf5b], a - ld [$cf5c], a - ret -; 83b - -Function83b: ; 83b - ld hl, $cf56 - ld de, $cf51 - ld c, $2 - ld a, $1 - ld [$ffcc], a -.asm_847 - call DelayFrame - ld a, [hl] - ld [hSerialSend], a - call Function78a - ld b, a - inc hl - ld a, [$ffcc] - and a - ld a, $0 - ld [$ffcc], a - jr nz, .asm_847 - ld a, b - ld [de], a - inc de - dec c - jr nz, .asm_847 - ret -; 862 - -Function862: ; 862 - call Function309d - callab Function4000 - call Function87d - jp Function30b4 -; 871 - - -Function871: ; 871 - call Function309d - callab Function4000 - jp Function87d -; 87d - - - -Function87d: ; 87d - ld a, $ff - ld [$cf52], a -.asm_882 - call Function8c1 - call DelayFrame - call Function82b - jr z, .asm_89e - push hl - ld hl, $cf5c - dec [hl] - jr nz, .asm_89d - dec hl - dec [hl] - jr nz, .asm_89d - pop hl - xor a - jp Function833 - -.asm_89d - pop hl - -.asm_89e - ld a, [$cf52] - inc a - jr z, .asm_882 - ld b, $a -.asm_8a6 - call DelayFrame - call Function8c1 - dec b - jr nz, .asm_8a6 - ld b, $a -.asm_8b1 - call DelayFrame - call Function908 - dec b - jr nz, .asm_8b1 - ld a, [$cf52] - ld [$cf51], a - ret -; 8c1 - -Function8c1: ; 8c1 - push bc - ld b, $60 - ld a, [InLinkBattle] - cp $1 - jr z, .asm_8d7 - ld b, $60 - jr c, .asm_8d7 - cp $2 - ld b, $70 - jr z, .asm_8d7 - ld b, $80 - -.asm_8d7 - call Function8f3 - ld a, [$cf56] - add b - ld [hSerialSend], a - ld a, [$ffcb] - cp $2 - jr nz, .asm_8ee - ld a, $1 - ld [rSC], a - ld a, $81 - ld [rSC], a - -.asm_8ee - call Function8f3 - pop bc - ret -; 8f3 - -Function8f3: ; 8f3 - ld a, [hSerialReceive] - ld [$cf51], a - and $f0 - cp b - ret nz - xor a - ld [hSerialReceive], a - ld a, [$cf51] - and $f - ld [$cf52], a - ret -; 908 - -Function908: ; 908 - xor a - ld [hSerialSend], a - ld a, [$ffcb] - cp $2 - ret nz - ld a, $1 - ld [rSC], a - ld a, $81 - ld [rSC], a - ret -; 919 - -Function919: ; 919 - ld a, [InLinkBattle] - and a - ret nz - ld a, $2 - ld [rSB], a - xor a - ld [hSerialReceive], a - ld a, $0 - ld [rSC], a - ld a, $80 - ld [rSC], a - ret -; 92e - +INCLUDE "engine/serial.asm" INCLUDE "engine/joypad.asm" From 6d29673a5fe731e4705f0f11e885d89b47eec927 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 19:32:03 -0400 Subject: [PATCH 48/96] move time-related asm from main.asm into engine/time.asm --- engine/time.asm | 311 ++++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 308 +---------------------------------------------- 2 files changed, 312 insertions(+), 307 deletions(-) create mode 100644 engine/time.asm diff --git a/engine/time.asm b/engine/time.asm new file mode 100644 index 000000000..fff52b173 --- /dev/null +++ b/engine/time.asm @@ -0,0 +1,311 @@ +; Functions relating to the timer interrupt and the real-time-clock. + + +AskTimer: ; 591 + push af + ld a, [$ffe9] + and a + jr z, .asm_59a + call Timer + +.asm_59a + pop af + reti +; 59c + + +LatchClock: ; 59c +; latch clock counter data + ld a, 0 + ld [MBC3LatchClock], a + ld a, 1 + ld [MBC3LatchClock], a + ret +; 5a7 + + +UpdateTime: ; 5a7 + call GetClock + call FixDays + call FixTime + callba GetTimeOfDay + ret +; 5b7 + + +GetClock: ; 5b7 +; store clock data in hRTCDayHi-hRTCSeconds + +; enable clock r/w + ld a, SRAM_ENABLE + ld [MBC3SRamEnable], a + +; clock data is 'backwards' in hram + + call LatchClock + ld hl, MBC3SRamBank + ld de, MBC3RTC + + ld [hl], RTC_S + ld a, [de] + and $3f + ld [hRTCSeconds], a + + ld [hl], RTC_M + ld a, [de] + and $3f + ld [hRTCMinutes], a + + ld [hl], RTC_H + ld a, [de] + and $1f + ld [hRTCHours], a + + ld [hl], RTC_DL + ld a, [de] + ld [hRTCDayLo], a + + ld [hl], RTC_DH + ld a, [de] + ld [hRTCDayHi], a + +; unlatch clock / disable clock r/w + call CloseSRAM + ret +; 5e8 + + +FixDays: ; 5e8 +; fix day count +; mod by 140 + +; check if day count > 255 (bit 8 set) + ld a, [hRTCDayHi] ; DH + bit 0, a + jr z, .daylo +; reset dh (bit 8) + res 0, a + ld [hRTCDayHi], a ; DH + +; mod 140 +; mod twice since bit 8 (DH) was set + ld a, [hRTCDayLo] ; DL +.modh + sub 140 + jr nc, .modh +.modl + sub 140 + jr nc, .modl + add 140 + +; update dl + ld [hRTCDayLo], a ; DL + +; unknown output + ld a, $40 ; %1000000 + jr .set + +.daylo +; quit if fewer than 140 days have passed + ld a, [hRTCDayLo] ; DL + cp 140 + jr c, .quit + +; mod 140 +.mod + sub 140 + jr nc, .mod + add 140 + +; update dl + ld [hRTCDayLo], a ; DL + +; unknown output + ld a, $20 ; %100000 + +.set +; update clock with modded day value + push af + call SetClock + pop af + scf + ret + +.quit + xor a + ret +; 61d + + +FixTime: ; 61d +; add ingame time (set at newgame) to current time +; day hr min sec +; store time in CurDay, hHours, hMinutes, hSeconds + +; second + ld a, [hRTCSeconds] ; S + ld c, a + ld a, [StartSecond] + add c + sub 60 + jr nc, .updatesec + add 60 +.updatesec + ld [hSeconds], a + +; minute + ccf ; carry is set, so turn it off + ld a, [hRTCMinutes] ; M + ld c, a + ld a, [StartMinute] + adc c + sub 60 + jr nc, .updatemin + add 60 +.updatemin + ld [hMinutes], a + +; hour + ccf ; carry is set, so turn it off + ld a, [hRTCHours] ; H + ld c, a + ld a, [StartHour] + adc c + sub 24 + jr nc, .updatehr + add 24 +.updatehr + ld [hHours], a + +; day + ccf ; carry is set, so turn it off + ld a, [hRTCDayLo] ; DL + ld c, a + ld a, [StartDay] + adc c + ld [CurDay], a + ret +; 658 + +Function658: ; 658 + xor a + ld [StringBuffer2], a + ld a, $0 + ld [$d089], a + jr .asm_677 + + call UpdateTime + ld a, [hHours] + ld [$d087], a + ld a, [hMinutes] + ld [$d088], a + ld a, [hSeconds] + ld [$d089], a + jr .asm_677 + +.asm_677 + ld a, $5 + ld hl, $40ed + rst FarCall + ret +; 67e + + + +Function67e: ; 67e + call Function685 + call SetClock + ret +; 685 + +Function685: ; 685 + xor a + ld [hRTCSeconds], a + ld [hRTCMinutes], a + ld [hRTCHours], a + ld [hRTCDayLo], a + ld [hRTCDayHi], a + ret +; 691 + + +SetClock: ; 691 +; set clock data from hram + +; enable clock r/w + ld a, SRAM_ENABLE + ld [MBC3SRamEnable], a + +; set clock data +; stored 'backwards' in hram + + call LatchClock + ld hl, MBC3SRamBank + ld de, MBC3RTC + +; seems to be a halt check that got partially commented out +; this block is totally pointless + ld [hl], RTC_DH + ld a, [de] + bit 6, a ; halt + ld [de], a + +; seconds + ld [hl], RTC_S + ld a, [hRTCSeconds] + ld [de], a +; minutes + ld [hl], RTC_M + ld a, [hRTCMinutes] + ld [de], a +; hours + ld [hl], RTC_H + ld a, [hRTCHours] + ld [de], a +; day lo + ld [hl], RTC_DL + ld a, [hRTCDayLo] + ld [de], a +; day hi + ld [hl], RTC_DH + ld a, [hRTCDayHi] + res 6, a ; make sure timer is active + ld [de], a + +; cleanup + call CloseSRAM ; unlatch clock, disable clock r/w + ret +; 6c4 + + +Function6c4: ; 6c4 + xor a + push af + ld a, $0 + call GetSRAMBank + pop af + ld [$ac60], a + call CloseSRAM + ret +; 6d3 + +Function6d3: ; 6d3 + ld hl, $ac60 + push af + ld a, $0 + call GetSRAMBank + pop af + or [hl] + ld [hl], a + call CloseSRAM + ret +; 6e3 + +Function6e3: ; 6e3 + ld a, $0 + call GetSRAMBank + ld a, [$ac60] + call CloseSRAM + ret +; 6ef + diff --git a/main.asm b/main.asm index f69484000..8aabd491b 100644 --- a/main.asm +++ b/main.asm @@ -119,313 +119,7 @@ INCLUDE "engine/fade.asm" INCLUDE "engine/lcd.asm" -AskTimer: ; 591 - push af - ld a, [$ffe9] - and a - jr z, .asm_59a - call Timer - -.asm_59a - pop af - reti -; 59c - - -LatchClock: ; 59c -; latch clock counter data - ld a, 0 - ld [MBC3LatchClock], a - ld a, 1 - ld [MBC3LatchClock], a - ret -; 5a7 - - -UpdateTime: ; 5a7 - call GetClock - call FixDays - call FixTime - callba GetTimeOfDay - ret -; 5b7 - - -GetClock: ; 5b7 -; store clock data in hRTCDayHi-hRTCSeconds - -; enable clock r/w - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - -; clock data is 'backwards' in hram - - call LatchClock - ld hl, MBC3SRamBank - ld de, MBC3RTC - - ld [hl], RTC_S - ld a, [de] - and $3f - ld [hRTCSeconds], a - - ld [hl], RTC_M - ld a, [de] - and $3f - ld [hRTCMinutes], a - - ld [hl], RTC_H - ld a, [de] - and $1f - ld [hRTCHours], a - - ld [hl], RTC_DL - ld a, [de] - ld [hRTCDayLo], a - - ld [hl], RTC_DH - ld a, [de] - ld [hRTCDayHi], a - -; unlatch clock / disable clock r/w - call CloseSRAM - ret -; 5e8 - - -FixDays: ; 5e8 -; fix day count -; mod by 140 - -; check if day count > 255 (bit 8 set) - ld a, [hRTCDayHi] ; DH - bit 0, a - jr z, .daylo -; reset dh (bit 8) - res 0, a - ld [hRTCDayHi], a ; DH - -; mod 140 -; mod twice since bit 8 (DH) was set - ld a, [hRTCDayLo] ; DL -.modh - sub 140 - jr nc, .modh -.modl - sub 140 - jr nc, .modl - add 140 - -; update dl - ld [hRTCDayLo], a ; DL - -; unknown output - ld a, $40 ; %1000000 - jr .set - -.daylo -; quit if fewer than 140 days have passed - ld a, [hRTCDayLo] ; DL - cp 140 - jr c, .quit - -; mod 140 -.mod - sub 140 - jr nc, .mod - add 140 - -; update dl - ld [hRTCDayLo], a ; DL - -; unknown output - ld a, $20 ; %100000 - -.set -; update clock with modded day value - push af - call SetClock - pop af - scf - ret - -.quit - xor a - ret -; 61d - - -FixTime: ; 61d -; add ingame time (set at newgame) to current time -; day hr min sec -; store time in CurDay, hHours, hMinutes, hSeconds - -; second - ld a, [hRTCSeconds] ; S - ld c, a - ld a, [StartSecond] - add c - sub 60 - jr nc, .updatesec - add 60 -.updatesec - ld [hSeconds], a - -; minute - ccf ; carry is set, so turn it off - ld a, [hRTCMinutes] ; M - ld c, a - ld a, [StartMinute] - adc c - sub 60 - jr nc, .updatemin - add 60 -.updatemin - ld [hMinutes], a - -; hour - ccf ; carry is set, so turn it off - ld a, [hRTCHours] ; H - ld c, a - ld a, [StartHour] - adc c - sub 24 - jr nc, .updatehr - add 24 -.updatehr - ld [hHours], a - -; day - ccf ; carry is set, so turn it off - ld a, [hRTCDayLo] ; DL - ld c, a - ld a, [StartDay] - adc c - ld [CurDay], a - ret -; 658 - -Function658: ; 658 - xor a - ld [StringBuffer2], a - ld a, $0 - ld [$d089], a - jr .asm_677 - - call UpdateTime - ld a, [hHours] - ld [$d087], a - ld a, [hMinutes] - ld [$d088], a - ld a, [hSeconds] - ld [$d089], a - jr .asm_677 - -.asm_677 - ld a, $5 - ld hl, $40ed - rst FarCall - ret -; 67e - - - -Function67e: ; 67e - call Function685 - call SetClock - ret -; 685 - -Function685: ; 685 - xor a - ld [hRTCSeconds], a - ld [hRTCMinutes], a - ld [hRTCHours], a - ld [hRTCDayLo], a - ld [hRTCDayHi], a - ret -; 691 - - -SetClock: ; 691 -; set clock data from hram - -; enable clock r/w - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - -; set clock data -; stored 'backwards' in hram - - call LatchClock - ld hl, MBC3SRamBank - ld de, MBC3RTC - -; seems to be a halt check that got partially commented out -; this block is totally pointless - ld [hl], RTC_DH - ld a, [de] - bit 6, a ; halt - ld [de], a - -; seconds - ld [hl], RTC_S - ld a, [hRTCSeconds] - ld [de], a -; minutes - ld [hl], RTC_M - ld a, [hRTCMinutes] - ld [de], a -; hours - ld [hl], RTC_H - ld a, [hRTCHours] - ld [de], a -; day lo - ld [hl], RTC_DL - ld a, [hRTCDayLo] - ld [de], a -; day hi - ld [hl], RTC_DH - ld a, [hRTCDayHi] - res 6, a ; make sure timer is active - ld [de], a - -; cleanup - call CloseSRAM ; unlatch clock, disable clock r/w - ret -; 6c4 - - -Function6c4: ; 6c4 - xor a - push af - ld a, $0 - call GetSRAMBank - pop af - ld [$ac60], a - call CloseSRAM - ret -; 6d3 - -Function6d3: ; 6d3 - ld hl, $ac60 - push af - ld a, $0 - call GetSRAMBank - pop af - or [hl] - ld [hl], a - call CloseSRAM - ret -; 6e3 - -Function6e3: ; 6e3 - ld a, $0 - call GetSRAMBank - ld a, [$ac60] - call CloseSRAM - ret -; 6ef +INCLUDE "engine/time.asm" INCLUDE "engine/serial.asm" From 04da88a285b0d43192db4ecd5d49d86e5bfeaea3 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 19:37:35 -0400 Subject: [PATCH 49/96] move palette asm from main.asm to engine/palettes.asm --- engine/palettes.asm | 347 +++++++++++++++++++++++++++++++++++++++++++ main.asm | 349 +------------------------------------------- 2 files changed, 348 insertions(+), 348 deletions(-) create mode 100644 engine/palettes.asm diff --git a/engine/palettes.asm b/engine/palettes.asm new file mode 100644 index 000000000..accaa96b5 --- /dev/null +++ b/engine/palettes.asm @@ -0,0 +1,347 @@ +; Functions dealing with palettes. + + +UpdatePalsIfCGB: ; c2f +; update bgp data from BGPals +; update obp data from OBPals +; return carry if successful + +; check cgb + ld a, [hCGB] + and a + ret z + + +UpdateCGBPals: ; c33 +; return carry if successful +; any pals to update? + ld a, [hCGBPalUpdate] + and a + ret z + + +ForceUpdateCGBPals: ; c37 + + ld a, [rSVBK] + push af + ld a, 5 ; BANK(BGPals) + ld [rSVBK], a + + ld hl, BGPals ; 5:d080 + +; copy 8 pals to bgpd + ld a, %10000000 ; auto increment, index 0 + ld [rBGPI], a + ld c, rBGPD % $100 + ld b, 4 ; NUM_PALS / 2 +.bgp + rept $10 + ld a, [hli] + ld [$ff00+c], a + endr + + dec b + jr nz, .bgp + +; hl is now 5:d0c0 OBPals + +; copy 8 pals to obpd + ld a, %10000000 ; auto increment, index 0 + ld [rOBPI], a + ld c, rOBPD - rJOYP + ld b, 4 ; NUM_PALS / 2 +.obp + rept $10 + ld a, [hli] + ld [$ff00+c], a + endr + + dec b + jr nz, .obp + + pop af + ld [rSVBK], a + +; clear pal update queue + xor a + ld [hCGBPalUpdate], a + + scf + ret +; c9f + + +DmgToCgbBGPals: ; c9f +; exists to forego reinserting cgb-converted image data + +; input: a -> bgp + + ld [rBGP], a + push af + + ld a, [hCGB] + and a + jr z, .end + + push hl + push de + push bc + ld a, [rSVBK] + push af + + ld a, 5 + ld [rSVBK], a + +; copy & reorder bg pal buffer + ld hl, BGPals ; to + ld de, Unkn1Pals ; from +; order + ld a, [rBGP] + ld b, a +; all pals + ld c, 8 + call CopyPals +; request pal update + ld a, 1 + ld [hCGBPalUpdate], a + + pop af + ld [rSVBK], a + pop bc + pop de + pop hl +.end + pop af + ret +; ccb + + +DmgToCgbObjPals: ; ccb +; exists to forego reinserting cgb-converted image data + +; input: d -> obp1 +; e -> obp2 + + ld a, e + ld [rOBP0], a + ld a, d + ld [rOBP1], a + + ld a, [hCGB] + and a + ret z + + push hl + push de + push bc + ld a, [rSVBK] + push af + + ld a, 5 + ld [rSVBK], a + +; copy & reorder obj pal buffer + ld hl, OBPals ; to + ld de, Unkn2Pals ; from +; order + ld a, [rOBP0] + ld b, a +; all pals + ld c, 8 + call CopyPals +; request pal update + ld a, 1 + ld [hCGBPalUpdate], a + + pop af + ld [rSVBK], a + pop bc + pop de + pop hl + ret +; cf8 + + +Functioncf8: ; cf8 + ld [rOBP0], a + push af + ld a, [hCGB] + and a + jr z, .asm_d22 + push hl + push de + push bc + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, $d0c0 + ld de, MartPointer + ld a, [rOBP0] + ld b, a + ld c, $1 + call CopyPals + ld a, $1 + ld [hCGBPalUpdate], a + pop af + ld [rSVBK], a + pop bc + pop de + pop hl + +.asm_d22 + pop af + ret +; d24 + +Functiond24: ; d24 + ld [rOBP1], a + push af + ld a, [hCGB] + and a + jr z, .asm_d4e + push hl + push de + push bc + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, $d0c8 + ld de, $d048 + ld a, [rOBP1] + ld b, a + ld c, $1 + call CopyPals + ld a, $1 + ld [hCGBPalUpdate], a + pop af + ld [rSVBK], a + pop bc + pop de + pop hl + +.asm_d4e + pop af + ret +; d50 + + + +CopyPals: ; d50 +; copy c palettes in order b from de to hl + + push bc + ld c, 4 ; NUM_PAL_COLORS +.loop + push de + push hl + +; get pal color + ld a, b + and %11 ; color +; 2 bytes per color + add a + ld l, a + ld h, 0 + add hl, de + ld e, [hl] + inc hl + ld d, [hl] + +; dest + pop hl +; write color + ld [hl], e + inc hl + ld [hl], d + inc hl +; next pal color + srl b + srl b +; source + pop de +; done pal? + dec c + jr nz, .loop + +; de += 8 (next pal) + ld a, 8 ; NUM_PAL_COLORS * 2 ; bytes per pal + add e + jr nc, .ok + inc d +.ok + ld e, a + +; how many more pals? + pop bc + dec c + jr nz, CopyPals + ret +; d79 + + +Functiond79: ; d79 + ld a, [hCGB] + and a + ret z + ld a, 1 + ld [rVBK], a + ld hl, VTiles0 + ld bc, $2000 + xor a + call ByteFill + ld a, 0 + ld [rVBK], a + ret +; d90 + + +Functiond90: ; d90 + ret +; d91 + + +Functiond91: ; d91 + ld a, [hCGB] + and a + ret z + ld a, [rSVBK] + push af + ld a, 5 ; BANK(BGPals) + ld [rSVBK], a + ld hl, BGPals + ld bc, $40 + $10 + xor a + call ByteFill + pop af + ld [rSVBK], a + ld a, 1 + ld [hCGBPalUpdate], a + call DelayFrame + ret +; db1 + + +Functiondb1: ; db1 + ld a, [hROMBank] + push af + ld a, BANK(Function4c000) + rst Bankswitch + call Function4c000 + pop af + rst Bankswitch + ret +; dbd + +Functiondbd: ; dbd + ld a, [hROMBank] + push af + ld a, BANK(Function4c03f) + rst Bankswitch + call Function4c03f + pop af + rst Bankswitch + ret +; dc9 + diff --git a/main.asm b/main.asm index 8aabd491b..86fc6a96a 100644 --- a/main.asm +++ b/main.asm @@ -131,354 +131,7 @@ INCLUDE "engine/joypad.asm" INCLUDE "engine/decompress.asm" -UpdatePalsIfCGB: ; c2f -; update bgp data from BGPals -; update obp data from OBPals -; return carry if successful - -; check cgb - ld a, [hCGB] - and a - ret z - - -UpdateCGBPals: ; c33 -; return carry if successful -; any pals to update? - ld a, [hCGBPalUpdate] - and a - ret z - - -ForceUpdateCGBPals: ; c37 - - ld a, [rSVBK] - push af - ld a, 5 ; BANK(BGPals) - ld [rSVBK], a - - ld hl, BGPals ; 5:d080 - -; copy 8 pals to bgpd - ld a, %10000000 ; auto increment, index 0 - ld [rBGPI], a - ld c, rBGPD % $100 - ld b, 4 ; NUM_PALS / 2 -.bgp - rept $10 - ld a, [hli] - ld [$ff00+c], a - endr - - dec b - jr nz, .bgp - -; hl is now 5:d0c0 OBPals - -; copy 8 pals to obpd - ld a, %10000000 ; auto increment, index 0 - ld [rOBPI], a - ld c, rOBPD - rJOYP - ld b, 4 ; NUM_PALS / 2 -.obp - rept $10 - ld a, [hli] - ld [$ff00+c], a - endr - - dec b - jr nz, .obp - - pop af - ld [rSVBK], a - -; clear pal update queue - xor a - ld [hCGBPalUpdate], a - - scf - ret -; c9f - - -DmgToCgbBGPals: ; c9f -; exists to forego reinserting cgb-converted image data - -; input: a -> bgp - - ld [rBGP], a - push af - - ld a, [hCGB] - and a - jr z, .end - - push hl - push de - push bc - ld a, [rSVBK] - push af - - ld a, 5 - ld [rSVBK], a - -; copy & reorder bg pal buffer - ld hl, BGPals ; to - ld de, Unkn1Pals ; from -; order - ld a, [rBGP] - ld b, a -; all pals - ld c, 8 - call CopyPals -; request pal update - ld a, 1 - ld [hCGBPalUpdate], a - - pop af - ld [rSVBK], a - pop bc - pop de - pop hl -.end - pop af - ret -; ccb - - -DmgToCgbObjPals: ; ccb -; exists to forego reinserting cgb-converted image data - -; input: d -> obp1 -; e -> obp2 - - ld a, e - ld [rOBP0], a - ld a, d - ld [rOBP1], a - - ld a, [hCGB] - and a - ret z - - push hl - push de - push bc - ld a, [rSVBK] - push af - - ld a, 5 - ld [rSVBK], a - -; copy & reorder obj pal buffer - ld hl, OBPals ; to - ld de, Unkn2Pals ; from -; order - ld a, [rOBP0] - ld b, a -; all pals - ld c, 8 - call CopyPals -; request pal update - ld a, 1 - ld [hCGBPalUpdate], a - - pop af - ld [rSVBK], a - pop bc - pop de - pop hl - ret -; cf8 - - -Functioncf8: ; cf8 - ld [rOBP0], a - push af - ld a, [hCGB] - and a - jr z, .asm_d22 - push hl - push de - push bc - ld a, [rSVBK] - push af - ld a, $5 - ld [rSVBK], a - ld hl, $d0c0 - ld de, MartPointer - ld a, [rOBP0] - ld b, a - ld c, $1 - call CopyPals - ld a, $1 - ld [hCGBPalUpdate], a - pop af - ld [rSVBK], a - pop bc - pop de - pop hl - -.asm_d22 - pop af - ret -; d24 - -Functiond24: ; d24 - ld [rOBP1], a - push af - ld a, [hCGB] - and a - jr z, .asm_d4e - push hl - push de - push bc - ld a, [rSVBK] - push af - ld a, $5 - ld [rSVBK], a - ld hl, $d0c8 - ld de, $d048 - ld a, [rOBP1] - ld b, a - ld c, $1 - call CopyPals - ld a, $1 - ld [hCGBPalUpdate], a - pop af - ld [rSVBK], a - pop bc - pop de - pop hl - -.asm_d4e - pop af - ret -; d50 - - - -CopyPals: ; d50 -; copy c palettes in order b from de to hl - - push bc - ld c, 4 ; NUM_PAL_COLORS -.loop - push de - push hl - -; get pal color - ld a, b - and %11 ; color -; 2 bytes per color - add a - ld l, a - ld h, $0 - add hl, de - ld e, [hl] - inc hl - ld d, [hl] - -; dest - pop hl -; write color - ld [hl], e - inc hl - ld [hl], d - inc hl -; next pal color - srl b - srl b -; source - pop de -; done pal? - dec c - jr nz, .loop - -; de += 8 (next pal) - ld a, 8 ; NUM_PAL_COLORS * 2 ; bytes per pal - add e - jr nc, .ok - inc d -.ok - ld e, a - -; how many more pals? - pop bc - dec c - jr nz, CopyPals - ret -; d79 - - -Functiond79: ; d79 - ld a, [hCGB] - and a - ret z - ld a, $1 - ld [rVBK], a - ld hl, VTiles0 - ld bc, $2000 - xor a - call ByteFill - ld a, $0 - ld [rVBK], a - ret -; d90 - - -Functiond90: ; d90 - ret -; d91 - - -Functiond91: ; d91 - ld a, [hCGB] - and a - ret z - ld a, [rSVBK] - push af - ld a, $5 - ld [rSVBK], a - ld hl, $d080 - ld bc, $0050 - xor a - call ByteFill - pop af - ld [rSVBK], a - ld a, $1 - ld [hCGBPalUpdate], a - call DelayFrame - ret -; db1 - - -Functiondb1: ; db1 - ld a, [hROMBank] - push af - ld a, $13 - rst Bankswitch - - call $4000 - pop af - rst Bankswitch - - ret -; dbd - -Functiondbd: ; dbd - ld a, [hROMBank] - push af - ld a, $13 - rst Bankswitch - - call $403f - pop af - rst Bankswitch - - ret -; dc9 - +INCLUDE "engine/palettes.asm" Functiondc9: ; dc9 From 2c16bc7ab9df0b341406e108ac44c09cf403f9b4 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 19:39:21 -0400 Subject: [PATCH 50/96] move copy asm from main.asm to engine/copy.asm --- engine/copy.asm | 431 ++++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 428 +---------------------------------------------- 2 files changed, 432 insertions(+), 427 deletions(-) create mode 100644 engine/copy.asm diff --git a/engine/copy.asm b/engine/copy.asm new file mode 100644 index 000000000..c5ba92c65 --- /dev/null +++ b/engine/copy.asm @@ -0,0 +1,431 @@ +; Functions to copy data from ROM. + + +Functiondc9: ; dc9 + ld a, [rLCDC] + bit 7, a + jp z, Copy2bpp + + ld a, [hROMBank] + push af + ld a, BANK(Function104284) + rst Bankswitch + call Function104284 + pop af + rst Bankswitch + + ret +; ddc + +Functionddc: ; ddc + ld a, [rLCDC] + bit 7, a + jp z, Copy1bpp + + ld a, [hROMBank] + push af + ld a, BANK(Function1042b2) + rst Bankswitch + call Function1042b2 + pop af + rst Bankswitch + + ret +; def + +Functiondef: ; def + ld [hBuffer], a + ld a, [hROMBank] + push af + ld a, [hBuffer] + rst Bankswitch + call FarCopyBytesDouble + pop af + rst Bankswitch + ret +; dfd + +Functiondfd: ; dfd + dec c + ld a, [hBGMapMode] + push af + xor a + ld [hBGMapMode], a + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + +.asm_e09 + ld a, d + ld [rHDMA1], a + ld a, e + and $f0 + ld [rHDMA2], a + ld a, h + and $1f + ld [rHDMA3], a + ld a, l + and $f0 + ld [rHDMA4], a + ld a, c + cp $8 + jr c, .asm_e3c + sub $8 + ld c, a + ld a, $f + ld [hDMATransfer], a + call DelayFrame + ld a, l + add $0 + ld l, a + ld a, h + adc $1 + ld h, a + ld a, e + add $0 + ld e, a + ld a, d + adc $1 + ld d, a + jr .asm_e09 + +.asm_e3c + ld a, c + and $7f + ld [hDMATransfer], a + call DelayFrame + pop af + rst Bankswitch + + pop af + ld [hBGMapMode], a + ret +; e4a + + + +Functione4a: ; e4a + ld a, $5 + ld hl, $4135 + rst FarCall + ret +; e51 + + + +Functione51: ; e51 + ld a, $3e + ld hl, $7449 + rst FarCall + ret +; e58 + +Functione58: ; e58 + ld a, $3e + ld hl, $74be + rst FarCall + ret +; e5f + + + +Functione5f: ; e5f + ld a, $3e + ld hl, $748a + rst FarCall + ld a, $3e + ld hl, $74b0 + rst FarCall + ret +; e6c + +Functione6c: ; e6c + ld a, $3e + ld hl, $74b0 + rst FarCall + ret +; e73 + +Functione73: ; e73 + push de + ld a, $0 + call GetSRAMBank + push bc + ld de, $a000 + ld a, b + call FarDecompress + pop bc + pop hl + ld de, $a000 + call Request2bpp + call CloseSRAM + ret +; e8d + + + +FarCopyBytes: ; e8d +; copy bc bytes from a:hl to de + + ld [hBuffer], a + ld a, [hROMBank] + push af + ld a, [hBuffer] + rst Bankswitch + + call CopyBytes + + pop af + rst Bankswitch + ret +; 0xe9b + + +FarCopyBytesDouble: ; e9b +; Copy bc bytes from a:hl to bc*2 bytes at de, +; doubling each byte in the process. + + ld [hBuffer], a + ld a, [hROMBank] + push af + ld a, [hBuffer] + rst Bankswitch + +; switcheroo, de <> hl + ld a, h + ld h, d + ld d, a + ld a, l + ld l, e + ld e, a + + inc b + inc c + jr .dec + +.loop + ld a, [de] + inc de + ld [hli], a + ld [hli], a +.dec + dec c + jr nz, .loop + dec b + jr nz, .loop + + pop af + rst Bankswitch + ret +; 0xeba + + +Request2bpp: ; eba + ld a, [hBGMapMode] + push af + xor a + ld [hBGMapMode], a + + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + + ld a, [$ffd3] + push af + + ld a, $8 + ld [$ffd3], a + ld a, [InLinkBattle] + cp $4 + jr nz, .asm_edc + ld a, [$ffe9] + and a + jr nz, .asm_edc + ld a, $6 + ld [$ffd3], a + +.asm_edc + ld a, e + ld [$cf68], a + ld a, d + ld [$cf69], a + ld a, l + ld [$cf6a], a + ld a, h + ld [$cf6b], a + +.asm_eec + ld a, c + ld hl, $ffd3 + cp [hl] + jr nc, .asm_f08 + + ld [$cf67], a +.wait + call DelayFrame + ld a, [$cf67] + and a + jr nz, .wait + + pop af + ld [$ffd3], a + + pop af + rst Bankswitch + + pop af + ld [hBGMapMode], a + ret + +.asm_f08 + ld a, [$ffd3] + ld [$cf67], a +.asm_f0d + call DelayFrame + ld a, [$cf67] + and a + jr nz, .asm_f0d + ld a, c + ld hl, $ffd3 + sub [hl] + ld c, a + jr .asm_eec +; f1e + + +Request1bpp: ; f1e + ld a, [hBGMapMode] + push af + xor a + ld [hBGMapMode], a + + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + + ld a, [$ffd3] + push af + + ld a, $8 + ld [$ffd3], a + ld a, [InLinkBattle] + cp $4 + jr nz, .asm_f40 + ld a, [$ffe9] + and a + jr nz, .asm_f40 + ld a, $6 + ld [$ffd3], a + +.asm_f40 + ld a, e + ld [$cf6d], a + ld a, d + ld [$cf6e], a + ld a, l + ld [$cf6f], a + ld a, h + ld [$cf70], a +.asm_f50 + ld a, c + ld hl, $ffd3 + cp [hl] + jr nc, .asm_f6c + + ld [$cf6c], a +.wait + call DelayFrame + ld a, [$cf6c] + and a + jr nz, .wait + + pop af + ld [$ffd3], a + + pop af + rst Bankswitch + + pop af + ld [hBGMapMode], a + ret + +.asm_f6c + ld a, [$ffd3] + ld [$cf6c], a +.asm_f71 + call DelayFrame + ld a, [$cf6c] + and a + jr nz, .asm_f71 + ld a, c + ld hl, $ffd3 + sub [hl] + ld c, a + jr .asm_f50 +; f82 + + +Get2bpp: ; f82 + ld a, [rLCDC] + bit 7, a + jp nz, Request2bpp + +Copy2bpp: ; f89 +; copy c 2bpp tiles from b:de to hl + + push hl + ld h, d + ld l, e + pop de + +; bank + ld a, b + +; bc = c * $10 + push af + swap c + ld a, $f + and c + ld b, a + ld a, $f0 + and c + ld c, a + pop af + + jp FarCopyBytes +; f9d + + +Get1bpp: ; f9d + ld a, [rLCDC] + bit 7, a + jp nz, Request1bpp + +Copy1bpp: ; fa4 +; copy c 1bpp tiles from b:de to hl + + push de + ld d, h + ld e, l + +; bank + ld a, b + +; bc = c * $10 / 2 + push af + ld h, 0 + ld l, c + add hl, hl + add hl, hl + add hl, hl + ld b, h + ld c, l + pop af + + pop hl + jp FarCopyBytesDouble +; fb6 + diff --git a/main.asm b/main.asm index 86fc6a96a..6bb500c22 100644 --- a/main.asm +++ b/main.asm @@ -134,433 +134,7 @@ INCLUDE "engine/decompress.asm" INCLUDE "engine/palettes.asm" -Functiondc9: ; dc9 - ld a, [rLCDC] - bit 7, a - jp z, Copy2bpp - - ld a, [hROMBank] - push af - ld a, BANK(Function104284) - rst Bankswitch - call Function104284 - pop af - rst Bankswitch - - ret -; ddc - -Functionddc: ; ddc - ld a, [rLCDC] - bit 7, a - jp z, Copy1bpp - - ld a, [hROMBank] - push af - ld a, BANK(Function1042b2) - rst Bankswitch - call Function1042b2 - pop af - rst Bankswitch - - ret -; def - -Functiondef: ; def - ld [hBuffer], a - ld a, [hROMBank] - push af - ld a, [hBuffer] - rst Bankswitch - call FarCopyBytesDouble - pop af - rst Bankswitch - ret -; dfd - -Functiondfd: ; dfd - dec c - ld a, [hBGMapMode] - push af - xor a - ld [hBGMapMode], a - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - -.asm_e09 - ld a, d - ld [rHDMA1], a - ld a, e - and $f0 - ld [rHDMA2], a - ld a, h - and $1f - ld [rHDMA3], a - ld a, l - and $f0 - ld [rHDMA4], a - ld a, c - cp $8 - jr c, .asm_e3c - sub $8 - ld c, a - ld a, $f - ld [hDMATransfer], a - call DelayFrame - ld a, l - add $0 - ld l, a - ld a, h - adc $1 - ld h, a - ld a, e - add $0 - ld e, a - ld a, d - adc $1 - ld d, a - jr .asm_e09 - -.asm_e3c - ld a, c - and $7f - ld [hDMATransfer], a - call DelayFrame - pop af - rst Bankswitch - - pop af - ld [hBGMapMode], a - ret -; e4a - - - -Functione4a: ; e4a - ld a, $5 - ld hl, $4135 - rst FarCall - ret -; e51 - - - -Functione51: ; e51 - ld a, $3e - ld hl, $7449 - rst FarCall - ret -; e58 - -Functione58: ; e58 - ld a, $3e - ld hl, $74be - rst FarCall - ret -; e5f - - - -Functione5f: ; e5f - ld a, $3e - ld hl, $748a - rst FarCall - ld a, $3e - ld hl, $74b0 - rst FarCall - ret -; e6c - -Functione6c: ; e6c - ld a, $3e - ld hl, $74b0 - rst FarCall - ret -; e73 - -Functione73: ; e73 - push de - ld a, $0 - call GetSRAMBank - push bc - ld de, $a000 - ld a, b - call FarDecompress - pop bc - pop hl - ld de, $a000 - call Request2bpp - call CloseSRAM - ret -; e8d - - - -FarCopyBytes: ; e8d -; copy bc bytes from a:hl to de - - ld [hBuffer], a - ld a, [hROMBank] - push af - ld a, [hBuffer] - rst Bankswitch - - call CopyBytes - - pop af - rst Bankswitch - ret -; 0xe9b - - -FarCopyBytesDouble: ; e9b -; Copy bc bytes from a:hl to bc*2 bytes at de, -; doubling each byte in the process. - - ld [hBuffer], a - ld a, [hROMBank] - push af - ld a, [hBuffer] - rst Bankswitch - -; switcheroo, de <> hl - ld a, h - ld h, d - ld d, a - ld a, l - ld l, e - ld e, a - - inc b - inc c - jr .dec - -.loop - ld a, [de] - inc de - ld [hli], a - ld [hli], a -.dec - dec c - jr nz, .loop - dec b - jr nz, .loop - - pop af - rst Bankswitch - ret -; 0xeba - - -Request2bpp: ; eba - ld a, [hBGMapMode] - push af - xor a - ld [hBGMapMode], a - - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - - ld a, [$ffd3] - push af - - ld a, $8 - ld [$ffd3], a - ld a, [InLinkBattle] - cp $4 - jr nz, .asm_edc - ld a, [$ffe9] - and a - jr nz, .asm_edc - ld a, $6 - ld [$ffd3], a - -.asm_edc - ld a, e - ld [$cf68], a - ld a, d - ld [$cf69], a - ld a, l - ld [$cf6a], a - ld a, h - ld [$cf6b], a - -.asm_eec - ld a, c - ld hl, $ffd3 - cp [hl] - jr nc, .asm_f08 - - ld [$cf67], a -.wait - call DelayFrame - ld a, [$cf67] - and a - jr nz, .wait - - pop af - ld [$ffd3], a - - pop af - rst Bankswitch - - pop af - ld [hBGMapMode], a - ret - -.asm_f08 - ld a, [$ffd3] - ld [$cf67], a -.asm_f0d - call DelayFrame - ld a, [$cf67] - and a - jr nz, .asm_f0d - ld a, c - ld hl, $ffd3 - sub [hl] - ld c, a - jr .asm_eec -; f1e - - -Request1bpp: ; f1e - ld a, [hBGMapMode] - push af - xor a - ld [hBGMapMode], a - - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - - ld a, [$ffd3] - push af - - ld a, $8 - ld [$ffd3], a - ld a, [InLinkBattle] - cp $4 - jr nz, .asm_f40 - ld a, [$ffe9] - and a - jr nz, .asm_f40 - ld a, $6 - ld [$ffd3], a - -.asm_f40 - ld a, e - ld [$cf6d], a - ld a, d - ld [$cf6e], a - ld a, l - ld [$cf6f], a - ld a, h - ld [$cf70], a -.asm_f50 - ld a, c - ld hl, $ffd3 - cp [hl] - jr nc, .asm_f6c - - ld [$cf6c], a -.wait - call DelayFrame - ld a, [$cf6c] - and a - jr nz, .wait - - pop af - ld [$ffd3], a - - pop af - rst Bankswitch - - pop af - ld [hBGMapMode], a - ret - -.asm_f6c - ld a, [$ffd3] - ld [$cf6c], a -.asm_f71 - call DelayFrame - ld a, [$cf6c] - and a - jr nz, .asm_f71 - ld a, c - ld hl, $ffd3 - sub [hl] - ld c, a - jr .asm_f50 -; f82 - - -Get2bpp: ; f82 - ld a, [rLCDC] - bit 7, a - jp nz, Request2bpp - -Copy2bpp: ; f89 -; copy c 2bpp tiles from b:de to hl - - push hl - ld h, d - ld l, e - pop de - -; bank - ld a, b - -; bc = c * $10 - push af - swap c - ld a, $f - and c - ld b, a - ld a, $f0 - and c - ld c, a - pop af - - jp FarCopyBytes -; f9d - - -Get1bpp: ; f9d - ld a, [rLCDC] - bit 7, a - jp nz, Request1bpp - -Copy1bpp: ; fa4 -; copy c 1bpp tiles from b:de to hl - - push de - ld d, h - ld e, l - -; bank - ld a, b - -; bc = c * $10 / 2 - push af - ld h, 0 - ld l, c - add hl, hl - add hl, hl - add hl, hl - ld b, h - ld c, l - pop af - - pop hl - jp FarCopyBytesDouble -; fb6 +INCLUDE "engine/copy.asm" INCLUDE "engine/text.asm" From cc98fab33ed222d89bba5fa3f96641ad3c8db6fb Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 19:40:33 -0400 Subject: [PATCH 51/96] move VBlank interrupt label from main.asm to engine/vblank.asm --- engine/vblank.asm | 2 ++ main.asm | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/vblank.asm b/engine/vblank.asm index 44e3e37c8..44b3195f8 100644 --- a/engine/vblank.asm +++ b/engine/vblank.asm @@ -6,6 +6,8 @@ ; This prevents the display and audio output from lagging. + +VBlank: ; 283 push af push bc push de diff --git a/main.asm b/main.asm index 6bb500c22..ab23266d3 100644 --- a/main.asm +++ b/main.asm @@ -58,7 +58,7 @@ SECTION "start",ROM0[$150] INCLUDE "engine/init.asm" -VBlank: ; 283 + INCLUDE "engine/vblank.asm" From 64a6af405240dcef1fdf4b4d321d9cc2093d2fd0 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 20:02:40 -0400 Subject: [PATCH 52/96] condense some repetitive asm with rept macros --- main.asm | 95 +++++--------------------------------------------------- 1 file changed, 7 insertions(+), 88 deletions(-) diff --git a/main.asm b/main.asm index ab23266d3..17a7b7b8a 100644 --- a/main.asm +++ b/main.asm @@ -421,51 +421,13 @@ UpdateBGMap: ; 164c .row ; write a row of 20 tiles +rept 9 pop de ld [hl], e inc l ld [hl], d inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l +endr pop de ld [hl], e inc l @@ -528,6 +490,8 @@ GetTiles2: ; 1717 .loop ; put 1 tile (16 bytes) into hl from sp + +rept 3 pop de ld [hl], e inc l @@ -537,24 +501,7 @@ GetTiles2: ; 1717 inc l ld [hl], d inc l - pop de - ld [hl], e - inc l - ld [hl], e - inc l - ld [hl], d - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], e - inc l - ld [hl], d - inc l - ld [hl], d - inc l +endr pop de ld [hl], e inc l @@ -639,41 +586,13 @@ GetTiles: ; 177d .loop ; put 1 tile (16 bytes) into hl from sp +rept 7 pop de ld [hl], e inc l ld [hl], d inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l +endr pop de ld [hl], e inc l From 579ab1350762a553d4f61e4c3534b52e857bc682 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 20:03:46 -0400 Subject: [PATCH 53/96] proper labeling of common function GetSpritePalette --- main.asm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.asm b/main.asm index 17a7b7b8a..0cd3625b4 100644 --- a/main.asm +++ b/main.asm @@ -668,12 +668,12 @@ SafeTileAnimation: ; 17d3 ; 17ff -Function17ff: ; 17ff +GetSpritePalette: ; 17ff push hl push de push bc ld c, a - callba GetSpritePalette + callba _GetSpritePalette ld a, c pop bc pop de @@ -16422,7 +16422,7 @@ Function811d: ; 811d call Function180e ld [$c2f2], a ld a, [hl] - call Function17ff + call GetSpritePalette ld [$c2f3], a ld hl, $0008 add hl, bc @@ -26460,7 +26460,7 @@ Function142a7: ; 142a7 ; 142c4 -GetSpritePalette: ; 142c4 +_GetSpritePalette: ; 142c4 ld a, c call GetMonSprite jr c, .asm_142d8 From fb28d24bd78c7a322c4bd3129b57808c8f7cbbad Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 21:42:28 -0400 Subject: [PATCH 54/96] condense repeated asm with rept macros --- main.asm | 81 +++++--------------------------------------------------- 1 file changed, 7 insertions(+), 74 deletions(-) diff --git a/main.asm b/main.asm index 0cd3625b4..0ff75f115 100644 --- a/main.asm +++ b/main.asm @@ -6367,87 +6367,19 @@ Function327b: ; 327b ld c, $41 .asm_328c pop de -.asm_328d + +rept 9 +.loop\@ ld a, [$ff00+c] and b - jr nz, .asm_328d - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_3296 - ld a, [$ff00+c] - and b - jr nz, .asm_3296 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_329f - ld a, [$ff00+c] - and b - jr nz, .asm_329f - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32a8 - ld a, [$ff00+c] - and b - jr nz, .asm_32a8 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32b1 - ld a, [$ff00+c] - and b - jr nz, .asm_32b1 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32ba - ld a, [$ff00+c] - and b - jr nz, .asm_32ba - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32c3 - ld a, [$ff00+c] - and b - jr nz, .asm_32c3 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32cc - ld a, [$ff00+c] - and b - jr nz, .asm_32cc - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32d5 - ld a, [$ff00+c] - and b - jr nz, .asm_32d5 + jr nz, .loop\@ ld [hl], e inc l ld [hl], d inc l pop de +endr + .asm_32de ld a, [$ff00+c] and b @@ -6456,6 +6388,7 @@ Function327b: ; 327b inc l ld [hl], d inc l + ld de, $000c add hl, de ld a, [$ffd3] From 55cd8920263afd82500f6120ef2acea95bdcd2fe Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 23:19:21 -0400 Subject: [PATCH 55/96] fix/add some missing function labels in bank 0 --- main.asm | 207 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 116 insertions(+), 91 deletions(-) diff --git a/main.asm b/main.asm index 0ff75f115..1f0be9632 100644 --- a/main.asm +++ b/main.asm @@ -720,15 +720,17 @@ Function180e: ; 180e Function1836: ; 1836 push de push hl + ld b, a ld a, [hROMBank] push af - ld a, $5 + ld a, BANK(Function142a7) rst Bankswitch ld a, b - call $42a7 + call Function142a7 ld c, a + pop de ld a, d rst Bankswitch @@ -1194,12 +1196,13 @@ Function1a61: ; 1a61 ld l, a ld a, [hROMBank] push af - ld a, $1 + ld a, BANK(Data4273) rst Bankswitch - ld a, l push bc + call Function1a71 + pop bc pop af rst Bankswitch @@ -1213,8 +1216,8 @@ Function1a71: ; 1a71 ld [hl], a push de ld e, a - ld d, $0 - ld hl, $4274 + ld d, 0 + ld hl, Data4273 + 1 add hl, de add hl, de add hl, de @@ -1293,7 +1296,6 @@ Function1acc: ; 1acc ; 1ad2 - Function1ad2: ; 1ad2 ld a, [VramState] bit 0, a @@ -1304,7 +1306,6 @@ Function1ad2: ; 1ad2 ; 1ae5 - Function1ae5: ; 1ae5 ld bc, $0028 ld hl, $d4d6 @@ -1337,28 +1338,30 @@ Function1af8: ; 1af8 ; 1b07 - GetSpriteDirection: ; 1b07 ld hl, $0008 add hl, bc ld a, [hl] - and %00001100 + and $c ret ; 1b0f Function1b0f: ; 1b0f add $10 + +Function1b11: ; 1b11 ld e, a + ld a, [hROMBank] push af - ld a, $2 + ld a, BANK(Function84d9) rst Bankswitch - call $44d9 + call Function84d9 + pop af rst Bankswitch - ret ; 1b1e @@ -1928,14 +1931,18 @@ Function1db8: ; 0x1db8 ret ; 0x1dcf + Function1dcf: ; 1dcf ld bc, $0e07 - jr .asm_1dd9 +Function1dd2: ; 1dd2 + jr Function1dd9 + +Function1dd4: ; 1dd4 call LoadMenuDataHeader - jr .asm_1dfe + jr Function1dfe -.asm_1dd9 +Function1dd9: ; 1dd9 push bc ld hl, MenuDataHeader_0x1e1d call Function1d3c @@ -1957,7 +1964,7 @@ Function1dcf: ; 1dcf ld [$cf84], a call Function1c00 -.asm_1dfe +Function1dfe: ; 1dfe call Function1d81 push af ld c, $f @@ -2704,9 +2711,13 @@ Function2198: ; 2198 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] @@ -2804,7 +2815,7 @@ Function2198: ; 2198 pop de inc de dec c - jp nz, $21a9 + jp nz, .asm_21a9 pop hl ld de, $0060 add hl, de @@ -2818,7 +2829,7 @@ Function2198: ; 2198 .asm_2225 dec b - jp nz, $21a5 + jp nz, .asm_21a5 ret ; 222a @@ -3932,11 +3943,13 @@ Function27c0: ; 27c0 Function27d3: ; 27d3 ld hl, BGMapBufferPtrs push de - call $27df + call .asm_27df pop de ld a, $20 add e ld e, a + +.asm_27df ld c, $a .asm_27e1 ld a, e @@ -4575,9 +4588,9 @@ Function2b3c: ; 2b3c call Function1d7d call Functiond90 jr Function2b5c -; 2b4c +; 2b4d -Function2b4c: ; 2b4c +Function2b4d: ; 2b4d call WhiteBGMap call Function1d7d call Function2bae @@ -6296,32 +6309,35 @@ Function321c: ; 321c and a jr z, .asm_322e ld a, [$c2ce] - cp $0 + cp 0 jr z, .asm_322e - ld a, $1 + ld a, 1 ld [hBGMapMode], a - jr .asm_323d + jr Function323d .asm_322e - ld a, $1 + ld a, 1 ld [hBGMapMode], a - ld c, $4 + ld c, 4 call DelayFrames ret +; 3238 +Function3238: ; 3238 ld a, [hCGB] and a jr z, WaitBGMap -.asm_323d - jr .asm_3246 +Function323d: ; 323d + jr Function3246 +; 323f - ld a, $41 - ld hl, $4000 - rst FarCall +Function323f: ; 323f + callba Function104000 ret +; 3246 -.asm_3246 +Function3246: ; 3246 ld a, [hBGMapMode] push af xor a @@ -7196,14 +7212,16 @@ CheckTrainerBattle: ; 360d ld [CurFruit], a ld a, c ld [MartPointer], a - jr .asm_367e + jr Function367e +; 3674 +Function3674: ; 3674 ld a, $1 ld [CurFruit], a ld a, $ff ld [MartPointer], a -.asm_367e +Function367e: ; 367e call GetMapEventBank ld [EngineBuffer1], a ld a, [$ffe0] @@ -7442,6 +7460,8 @@ DrawHPBar: ; 3750 Function3786: ; 3786 ld a, $1 ld [$c2c6], a + +Function378b: ; 378b ld a, [CurPartySpecies] call Function3741 jr c, .asm_37ad @@ -7579,21 +7599,22 @@ PrintLevel: ; 382d ; How many digits? ld c, 2 cp 100 - jr c, .print + jr c, Function3842 ; 3-digit numbers overwrite the :L. dec hl inc c - jr .print + jr Function3842 +; 383d -; -------- -; Unused: print :L and all 3 digits +Function383d: ; 383d +; Print :L and all 3 digits ld [hl], $6e inc hl ld c, 3 -; -------- +; 3842 -.print +Function3842: ; 3842 ld [$d265], a ld de, $d265 ld b, %01000001 ; flags @@ -7906,6 +7927,8 @@ UpdateBattleMonInParty: ; 399c ; Update level, status, current HP ld a, [CurBattleMon] + +Function399f: ; 399f ld hl, PartyMon1Level call GetPartyLocation @@ -9080,11 +9103,11 @@ Function3f47: ; 3f47 pop bc .asm_3f4c push bc - call $3f68 + call Function3f68 pop bc dec b jr nz, .asm_3f4c - call $3f60 + call Function3f60 ret ; 3f58 @@ -9092,18 +9115,20 @@ Function3f58: ; 3f58 ld a, $63 ld d, $62 ld e, $64 - jr .asm_3f6e + jr Function3f6e +Function3f60: ; 3f60 ld a, $68 ld d, $67 ld e, $69 - jr .asm_3f6e + jr Function3f6e +Function3f68: ; 3f68 ld a, $7f ld d, $65 ld e, $66 -.asm_3f6e +Function3f6e: ; 3f6e push hl ld [hl], d inc hl @@ -11152,7 +11177,7 @@ Function4c5d: ; 4c5d inc [hl] ld a, [hl] ld d, $60 - call $1b11 + call Function1b11 ld a, h sub $60 ld hl, $001a @@ -11225,7 +11250,7 @@ Function4cc9: ; 4cc9 inc [hl] ld a, [hl] ld d, $60 - call $1b11 + call Function1b11 ld a, h sub $60 ld hl, $001a @@ -11316,7 +11341,7 @@ Function4d4f: ; 4d4f inc [hl] ld a, [hl] ld d, $60 - call $1b11 + call Function1b11 ld a, h sub $60 ld hl, $001a @@ -13765,8 +13790,8 @@ OakSpeech: ; 0x5f99 ld de, MUSIC_ROUTE_30 call StartMusic - call $04a3 - call $04b6 + call Function4a3 + call Function4b6 xor a ld [CurPartySpecies], a ld a, POKEMON_PROF @@ -13779,7 +13804,7 @@ OakSpeech: ; 0x5f99 ld hl, OakText1 call PrintText - call $04b6 + call Function4b6 call ClearTileMap ld a, $c2 @@ -13802,7 +13827,7 @@ OakSpeech: ; 0x5f99 call PrintText ld hl, OakText4 call PrintText - call $04b6 + call Function4b6 call ClearTileMap xor a @@ -13817,7 +13842,7 @@ OakSpeech: ; 0x5f99 ld hl, OakText5 call PrintText - call $04b6 + call Function4b6 call ClearTileMap xor a @@ -13888,7 +13913,7 @@ NamePlayer: ; 0x6074 ld hl, $56c1 rst FarCall - call $04b6 + call Function4b6 call ClearTileMap call Functione5f @@ -17022,14 +17047,14 @@ Function84d9: ; 84d9 Function84ef: ; 84ef ld e, a ld a, d - ld d, $0 + ld d, 0 ld hl, $450b add hl, de add hl, de ld e, [hl] inc hl ld d, [hl] - ld hl, $0000 + ld hl, 0 .asm_84fe srl a jr nc, .asm_8503 @@ -22035,7 +22060,7 @@ Functione3de: ; e3de ld de, StringBuffer1 call InitName ld a, $4 - ld hl, $2b4d + ld hl, Function2b4d rst FarCall ret ; e3fd @@ -22125,7 +22150,7 @@ Functione6ce: ; e6ce ld hl, $4000 rst FarCall ld bc, $0e07 - call $1dd2 + call Function1dd2 ret c .asm_e6ea @@ -23647,7 +23672,7 @@ StartMenu: ; 125cd call .DrawBugContestStatus call Function1ad2 call Functiond90 - call $2b5c + call Function2b5c ret ; 126d3 @@ -24011,7 +24036,7 @@ StartMenu_Pack: ; 1295b ld a, 0 ret .asm_12970 - call $2b4d + call Function2b4d ld a, 4 ret ; 12976 @@ -24068,7 +24093,7 @@ StartMenu_Pokemon: ; 12976 .quit ld a, b push af - call $2b4d + call Function2b4d pop af ret ; 129d5 @@ -24249,7 +24274,7 @@ GiveTakePartyMonItem: ; 12b60 call ClearPalettes call Function12ba9 call ClearPalettes - call $0e58 + call Functione58 call Function1c07 ld a, 0 ret @@ -25322,7 +25347,7 @@ SelectMenu: ; 13327 ld b, BANK(ItemMayBeRegisteredText) ld hl, ItemMayBeRegisteredText call Function269a - call $0a46 + call Functiona46 jp Function2dcf ; 13340 @@ -29190,7 +29215,7 @@ Function15cef: ; 15cef call Function15ffa ld a, $4 call Function15c7d - call $0a36 + call Functiona36 .asm_15d68 call SpeechTextBox @@ -29204,14 +29229,14 @@ Function15cef: ; 15cef .asm_15d6f ld a, $3 call Function15c7d - call $0a36 + call Functiona36 and a ret .asm_15d79 ld a, $2 call Function15c7d - call $0a36 + call Functiona36 and a ret ; 15d83 @@ -29273,7 +29298,7 @@ Function15da5: ; 15da5 .asm_15dd8 ld a, $5 call Function15c7d - call $0a36 + call Functiona36 scf ret ; 15de2 @@ -29394,7 +29419,7 @@ Function15efd: ; 15efd ld a, $9 ld hl, $4af0 rst FarCall - call $0a36 + call Functiona36 .asm_15f6e call Function1c07 @@ -29440,7 +29465,7 @@ Function15fc3: ; 15fc3 Function15fcd: ; 15fcd call Function1d4f - call $0a36 + call Functiona36 call Function1c07 ret ; 15fd7 @@ -32149,7 +32174,7 @@ Function24be7: ; 24be7 ld l, c inc hl ld c, $3 - call $3842 + call Function3842 .asm_24c3e pop af @@ -32928,7 +32953,7 @@ ProfOaksPC: ; 0x265d3 .shutdown ld hl, OakPCText4 call PrintText - call $0a36 + call Functiona36 call Function1c07 ret ; 0x265ee @@ -32938,7 +32963,7 @@ ProfOaksPCBoot ; 0x265ee call PrintText call Rate call StartSFX ; sfx loaded by previous Rate function call - call $0a36 + call Functiona36 call WaitSFX ret ; 0x26601 @@ -32950,7 +32975,7 @@ Function26601: ; 0x26601 call StartMusic pop de call StartSFX - call $0a36 + call Functiona36 call WaitSFX ret ; 0x26616 @@ -32970,7 +32995,7 @@ Rate: ; 0x26616 call ClearOakRatingBuffers ld hl, OakPCText3 call PrintText - call $0a36 + call Functiona36 ld a, [$d003] ld hl, OakRatings call FindOakRating @@ -38967,7 +38992,7 @@ Function3d1f8: ; 3d1f8 call FarBattleTextBox .asm_3d20a ld bc, $0107 - call $1dd2 + call Function1dd2 ld a, [$cfa9] jr c, .asm_3d217 and a @@ -39227,7 +39252,7 @@ LostBattle: ; 3d38e ld a, $47 ld hl, $4000 rst FarCall - call $0a80 + call Functiona80 call ClearTileMap call WhiteBGMap ret @@ -39780,7 +39805,7 @@ Function3d74b: ; 3d74b ld hl, BattleText_0x80aca call FarBattleTextBox ld bc, $0107 - call $1dd2 + call Function1dd2 ld a, [$cfa9] dec a jr nz, .asm_3d79a @@ -40482,7 +40507,7 @@ Function3dc5b: ; 3dc5b and a jr z, .asm_3dcc0 ld a, [$c71a] - call $399f + call Function399f ld hl, BattleMonHP ld a, [hli] or [hl] @@ -50468,7 +50493,7 @@ Function4e881: ; 4e881 call ClearSprites call DisableLCD call Functione51 - call $0e58 + call Functione58 ld hl, VBGMap0 ld bc, VBlank5 ld a, $7f @@ -50497,7 +50522,7 @@ Function4e8c2: ; 4e8c2 call ClearSprites call DisableLCD call Functione51 - call $0e58 + call Functione58 ld hl, VBGMap0 ld bc, VBlank5 ld a, $7f @@ -50908,7 +50933,7 @@ Function5003f: ; 5003f ; 5004f Function5004f: ; 5004f - call $0e58 + call Functione58 ld hl, $4ad1 ld a, $2 rst FarCall @@ -54743,7 +54768,7 @@ Function864c3: ; 864c3 call Function86810 ld a, $4 ld [MusicFade], a - call $04b6 + call Function4b6 ld c, $8 call DelayFrames ret @@ -54898,7 +54923,7 @@ Function865b5: ; 865b5 ld a, $7f call ByteFill ld hl, $c50a - call $378b + call Function378b call WaitBGMap xor a ld [hBGMapMode], a @@ -54999,7 +55024,7 @@ Function86748: ; 86748 xor a ld [$c2c6], a ld hl, $c50a - call $378b + call Function378b ld a, [CurPartySpecies] cp $fd jr z, .asm_867f8 @@ -56378,7 +56403,7 @@ Function8ca0c: ; 8ca0c INCBIN "baserom.gbc", $8ca1b, $8cf4f - $8ca1b Function8cf4f: ; 8cf4f - call $3238 + call Function3238 ret ; 8cf53 @@ -59077,14 +59102,14 @@ TryObjectEvent: ; 969b5 ld de, EngineBuffer1 ld bc, 2 call FarCopyBytes - ld a, $3 + ld a, 3 scf ret ; 96a29 .two ; 96a29 - call $3674 - ld a, $2 + call Function3674 + ld a, 2 scf ret ; 96a30 @@ -62742,7 +62767,7 @@ Functioncc000: ; cc000 call WhiteBGMap call ClearTileMap call ClearSprites - call $0e58 + call Functione58 ld hl, Options ld a, [hl] push af @@ -70449,7 +70474,7 @@ Function117c4a: add hl, de dec c jr nz, .asm_117c71 ; 0x117c7b $f4 - call $04b6 + call Function4b6 pop af ld [rSVBK], a ld a, $80 From c4a764ce1073e5cfc3b2045282c83beda314ca91 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 23:20:09 -0400 Subject: [PATCH 56/96] use more bank 0 labels in engine/scripting.asm --- engine/scripting.asm | 118 +++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index 0676c8681..3bd652ea0 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -308,7 +308,7 @@ Script_2writetext: ; 0x96e9b ld h, a ld a, [ScriptBank] ld b, a - call $269a + call Function269a ret ; 0x96eab @@ -323,7 +323,7 @@ Script_3writetext: ; 0x96eab ld l, a call GetScriptByte ld h, a - call $269a + call Function269a ret ; 0x96ebb @@ -348,7 +348,7 @@ Script_repeattext: ; 0x96ebb ld a, [hli] ld h, [hl] ld l, a - call $269a + call Function269a ret .asm_96ed8 ret @@ -357,7 +357,7 @@ Script_repeattext: ; 0x96ebb Script_closetext: ; 0x96ed9 ; script command 0x54 - jp $0a46 + jp Functiona46 ; 0x96edc Script_keeptextopen: ; 0x96edc @@ -367,8 +367,8 @@ Script_keeptextopen: ; 0x96edc push af ld a, $1 ld [$ffd8], a - call $31f6 - call $0aaf + call WaitBGMap + call Functionaaf pop af ld [$ffd8], a ret @@ -377,7 +377,7 @@ Script_keeptextopen: ; 0x96edc Script_yesorno: ; 0x96eed ; script command 0x4e - call $1dcf + call Function1dcf ld a, $0 jr c, .asm_96ef6 ; 0x96ef2 $2 ld a, $1 @@ -397,16 +397,16 @@ Script_loadmenudata: ; 0x96efa ld h, a ld de, $1d35 ld a, [ScriptBank] - call $26b7 - call $1ad2 + call Function26b7 + call Function1ad2 ret ; 0x96f0f Script_writebackup: ; 0x96f0f ; script command 0x50 - call $1c17 - call $1ad2 + call Function1c17 + call Function1ad2 ret ; 0x96f16 @@ -470,7 +470,7 @@ Script_storetext: ; 0x96f52 ; pointer (PointerLabelBeforeBank) ; memory (SingleByteParam) - call $106c + call Function106c call GetScriptByte ld c, a ld a, $47 @@ -539,7 +539,7 @@ Script_verbosegiveitem2: ; 0x96f8e ld a, [de] ld [$d10c], a ld hl, $d892 - call $2f66 + call Function2f66 ld a, $1 jr c, .asm_96fb0 ; 0x96fad $1 xor a @@ -561,7 +561,7 @@ Script_itemnotify: ; 0x96fc6 call CurItemName ld b, BANK(PutItemInPocketText) ld hl, PutItemInPocketText - call $269a + call Function269a ret ; 0x96fd5 @@ -572,7 +572,7 @@ Script_pocketisfull: ; 0x96fd5 call CurItemName ld b, BANK(PocketIsFullText) ld hl, PocketIsFullText - call $269a + call Function269a ret ; 0x96fe4 @@ -732,7 +732,7 @@ Script_askforphonenumber: ; 0x970be ; parameters: ; number (SingleByteParam) - call $1dcf + call Function1dcf jr c, .asm_970d6 ; 0x970c1 $13 call GetScriptByte ld c, a @@ -814,7 +814,7 @@ Script_trainertext: ; 0x9710f ld l, a ld a, [$d03e] ld b, a - call $269a + call Function269a ret ; 0x97125 @@ -907,7 +907,7 @@ Script_playrammusic: ; 0x9717a Script_playmapmusic: ; 0x97185 ; script command 0x82 - call $3cdf + call Function3cdf ret ; 0x97189 @@ -988,7 +988,7 @@ Script_cry: ; 0x971d1 jr nz, .asm_971df ; 0x971da $3 ld a, [$c2dd] .asm_971df - call $37ce + call Function37ce ret ; 0x971e3 @@ -1039,7 +1039,7 @@ Function971fa: ; 971fa ld h, a ld a, [ScriptBank] ld b, a - call $26c7 + call Function26c7 ret c ld a, SCRIPT_WAIT_MOVEMENT ld [ScriptMode], a @@ -1145,13 +1145,13 @@ Script_spriteface: ; 0x97274 Unknown_0x9728b: ; 0x9728b ld a, d push de - call $18de + call Function18de jr c, .asm_972b9 ; 0x97290 $27 ld hl, $0000 add hl, bc ld a, [hl] push bc - call $1836 + call Function1836 pop bc jr c, .asm_972b9 ; 0x9729c $1b ld hl, $0004 @@ -1160,13 +1160,13 @@ Unknown_0x9728b: ; 0x9728b jr nz, .asm_972b9 ; 0x972a4 $13 pop de ld a, e - call $1af8 + call Function1af8 ld hl, $d0ed bit 6, [hl] jr nz, .asm_972b5 ; 0x972b0 $3 call Unknown_0x972bc .asm_972b5 - call $1ad2 + call Function1ad2 ret .asm_972b9 pop de @@ -1175,7 +1175,7 @@ Unknown_0x9728b: ; 0x9728b ; 0x972bc Unknown_0x972bc: ; 0x972bc - call $217a + call Function217a ld hl, TileMap ld bc, $0168 .asm_972c5 @@ -1211,7 +1211,7 @@ Script_appear: ; 0x972dd call GetScriptByte call Unknown_0x971e3 - call $1956 + call Function1956 ld a, [$ffaf] ld b, $0 call Unknown_0x9730b @@ -1229,7 +1229,7 @@ Script_disappear: ; 0x972ee jr nz, .asm_972fa ; 0x972f6 $2 ld a, [$ffe0] .asm_972fa - call $199f + call Function199f ld a, [$ffaf] ld b, $1 call Unknown_0x9730b @@ -1241,7 +1241,7 @@ Script_disappear: ; 0x972ee Unknown_0x9730b: ; 0x9730b push bc - call $18d2 + call GetMapObject ld hl, $000c add hl, bc pop bc @@ -1513,7 +1513,7 @@ Script_catchtutorial: ; 0x97447 call GetScriptByte ld [$d230], a - call $2879 + call Function2879 ld a, $13 ld hl, $6554 rst $8 @@ -1559,7 +1559,7 @@ Script_reloadmap: ; 0x97491 ld a, $f3 ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret ; 0x974a2 @@ -1835,7 +1835,7 @@ Script_priorityjump: ; 0x975aa Script_checktriggers: ; 0x975c2 ; script command 0x13 - call $211b + call Function211b jr z, .asm_975cb ; 0x975c5 $4 ld [$c2dd], a ret @@ -1855,7 +1855,7 @@ Script_checkmaptriggers: ; 0x975d1 ld b, a call GetScriptByte ld c, a - call $2147 + call Function2147 ld a, d or e jr z, .asm_975e5 ; 0x975de $5 @@ -1894,7 +1894,7 @@ Script_domaptrigger: ; 0x975f5 ; fallthrough Unknown_975fd: ; 0x975fd - call $2147 + call Function2147 ld a, d or e jr z, .asm_97608 ; 0x97602 $4 @@ -1988,7 +1988,7 @@ Script_random: ; 0x97640 ld b, a .asm_97653 push bc - call $2f8c + call RNG pop bc ld a, [$ffe1] cp b @@ -1996,7 +1996,7 @@ Script_random: ; 0x97640 jr .asm_97666 ; 0x9765d $7 .asm_9765f push bc - call $2f8c + call RNG pop bc ld a, [$ffe1] .asm_97666 @@ -2004,7 +2004,7 @@ Script_random: ; 0x97640 ld a, [$c2dd] ld c, a pop af - call $3110 + call SimpleDivide ld [$c2dd], a ret ; 0x97673 @@ -2091,7 +2091,7 @@ Script_pokenamemem: ; 0x976ae ld a, [$c2dd] .asm_976b7 ld [$d265], a - call $343b + call GetPokemonName ld de, StringBuffer1 Unknown_976c0: ; 0x976c0 @@ -2205,7 +2205,7 @@ Script_readmoney: ; 0x97732 call Unknown_0x97861 ld hl, StringBuffer1 ld bc, $4306 - call $3198 + call PrintNum ld de, StringBuffer1 jp Unknown_976c0 ; 0x97747 @@ -2219,7 +2219,7 @@ Script_readcoins: ; 0x97747 ld hl, StringBuffer1 ld de, $d855 ld bc, $4206 - call $3198 + call PrintNum ld de, StringBuffer1 jp Unknown_976c0 ; 0x9775c @@ -2233,7 +2233,7 @@ Script_RAM2MEM: ; 0x9775c ld de, $c2dd ld hl, StringBuffer1 ld bc, $4103 - call $3198 + call PrintNum ld de, StringBuffer1 jp Unknown_976c0 ; 0x97771 @@ -2320,7 +2320,7 @@ Script_giveitem: ; 0x977ca call GetScriptByte ld [$d10c], a ld hl, $d892 - call $2f66 + call Function2f66 jr nc, .asm_977eb ; 0x977e3 $6 ld a, $1 ld [$c2dd], a @@ -2346,7 +2346,7 @@ Script_takeitem: ; 0x977f0 ld a, $ff ld [$d107], a ld hl, $d892 - call $2f53 + call Function2f53 ret nc ld a, $1 ld [$c2dd], a @@ -2363,7 +2363,7 @@ Script_checkitem: ; 0x97812 call GetScriptByte ld [$d106], a ld hl, $d892 - call $2f79 + call Function2f79 ret nc ld a, $1 ld [$c2dd], a @@ -2839,7 +2839,7 @@ Script_warp: ; 0x97a1d ld a, $f1 ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret .asm_97a4a @@ -2851,7 +2851,7 @@ Script_warp: ; 0x97a1d ld a, $fb ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret ; 0x97a65 @@ -2935,8 +2935,8 @@ Script_changemap: ; 0x97ab3 ld [$d1a1], a call GetScriptByte ld [$d1a2], a - call $24e4 - call $2879 + call Function24e4 + call Function2879 ret ; 0x97acc @@ -2953,10 +2953,10 @@ Script_changeblock: ; 0x97acc call GetScriptByte add $4 ld e, a - call $2a66 + call Function2a66 call GetScriptByte ld [hl], a - call $2879 + call Function2879 ret ; 0x97ae3 @@ -2965,19 +2965,19 @@ Script_reloadmappart: ; 0x97ae3 xor a ld [$ffd4], a - call $2173 - call $2914 + call Function2173 + call Function2914 ld a, $41 ld hl, $4061 rst $8 - call $1ad2 + call Function1ad2 ret ; 0x97af6 Script_warpcheck: ; 0x97af6 ; script command 0x8e - call $224a + call Function224a ret nc callba Function966d0 ret @@ -2996,7 +2996,7 @@ Script_newloadmap: ; 0x97b08 call GetScriptByte ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret ; 0x97b16 @@ -3011,7 +3011,7 @@ Script_reloadandreturn: ; 0x97b16 Script_loadfont: ; 0x97b1c ; script command 0x47 - call $2e08 + call Function2e08 ret ; 0x97b20 @@ -3020,7 +3020,7 @@ Script_refreshscreen: ; 0x97b20 ; parameters: ; dummy (SingleByteParam) - call $2dba + call ResetWindow call GetScriptByte ret ; 0x97b27 @@ -3043,8 +3043,8 @@ LoadMoveSpritesScript: ; 97b2e Script_loadmovesprites: ; 0x97b2f ; script command 0x49 - call $2e20 - call $2dcf + call Function2e20 + call Function2dcf ret ; 0x97b36 @@ -3206,7 +3206,7 @@ Script_credits: ; 0x97bf3 DisplayCredits: call Script_resetfuncs ld a, $3 - call $261b + call Function261b call StopScript ret ; 0x97c05 From 7201ea8f0ac0e3dd742fde251a351c4fdc8cc395 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 23:26:01 -0400 Subject: [PATCH 57/96] move GiveOddEgg into odd_eggs.asm --- main.asm | 99 +--------------------------------------------- stats/odd_eggs.asm | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 98 deletions(-) diff --git a/main.asm b/main.asm index 1f0be9632..ac1e6f873 100644 --- a/main.asm +++ b/main.asm @@ -72885,104 +72885,7 @@ BattleTowerMons: ; 1f8450 INCLUDE "stats/battle_tower.asm" ; 1fb4b6 - -GiveOddEgg: ; 1fb4b6 - -; Figure out which egg to give. - call RNG - ld hl, .Probabilities - ld c, 0 - ld b, c -.next - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - ld a, d - cp $ff - jr nz, .first - ld a, e - cp $ff - jr z, .done -.first - ld a, [hRandomSub] - cp d - jr c, .done - jr z, .second - jr .good -.second - ld a, [hRandomAdd] - cp e - jr c, .done - jr z, .done -.good - inc bc - jr .next -.done - - ld hl, OddEggs - ld a, OddEgg2 - OddEgg1 - call AddNTimes - ld de, EnemyMoveAnimation - ld bc, $0046 - call CopyBytes - ld a, EGG_TICKET - ld [CurItem], a - ld a, $1 - ld [$d10c], a - ld a, $ff - ld [$d107], a - ld hl, NumItems - call Function2f53 - ld a, EGG - ld [$cd2a], a - ld a, $29 - ld [$cd20], a - ld a, $cd - ld [$cd21], a - ld a, $8 - ld [$cd22], a - ld a, $c6 - ld [$cd23], a - - ld hl, .Odd - ld de, $cd2b - ld bc, $000b - call CopyBytes - - ld a, $2b - ld [$cd24], a - ld a, $cd - ld [$cd25], a - ld a, $38 - ld [$cd26], a - ld a, $c6 - ld [$cd27], a - callba Function11b98f - ret -; 1fb546 - -.Odd - db "ODD@@@@@@@@@" - -.Probabilities - dw $147a ; 92% -> 8% - dw $170a ; 91% -> 1% - dw $3fff ; 75% -> 16% - dw $47ad ; 72% -> 3% - dw $70a3 ; 56% -> 16% - dw $7851 ; 53% -> 3% - dw $9c28 ; 39% -> 14% - dw $a147 ; 37% -> 2% - dw $bae0 ; 27% -> 10% - dw $bfff ; 25% -> 2% - dw $deb7 ; 13% -> 12% - dw $e3d6 ; 11% -> 2% - dw $fd6f ; 1% -> 10% - dw $ffff ; 0% -> 1% -; 1fb56e - -OddEggs: ; 1fb56e +; 1fb4b6 INCLUDE "stats/odd_eggs.asm" ; 1fb8a8 diff --git a/stats/odd_eggs.asm b/stats/odd_eggs.asm index bab41be71..243f77434 100644 --- a/stats/odd_eggs.asm +++ b/stats/odd_eggs.asm @@ -1,3 +1,102 @@ +GiveOddEgg: ; 1fb4b6 + +; Figure out which egg to give. + call RNG + ld hl, .Probabilities + ld c, 0 + ld b, c +.next + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, d + cp $ff + jr nz, .first + ld a, e + cp $ff + jr z, .done +.first + ld a, [hRandomSub] + cp d + jr c, .done + jr z, .second + jr .good +.second + ld a, [hRandomAdd] + cp e + jr c, .done + jr z, .done +.good + inc bc + jr .next +.done + + ld hl, OddEggs + ld a, OddEgg2 - OddEgg1 + call AddNTimes + ld de, EnemyMoveAnimation + ld bc, $0046 + call CopyBytes + ld a, EGG_TICKET + ld [CurItem], a + ld a, $1 + ld [$d10c], a + ld a, $ff + ld [$d107], a + ld hl, NumItems + call Function2f53 + ld a, EGG + ld [$cd2a], a + ld a, $29 + ld [$cd20], a + ld a, $cd + ld [$cd21], a + ld a, $8 + ld [$cd22], a + ld a, $c6 + ld [$cd23], a + + ld hl, .Odd + ld de, $cd2b + ld bc, $000b + call CopyBytes + + ld a, $2b + ld [$cd24], a + ld a, $cd + ld [$cd25], a + ld a, $38 + ld [$cd26], a + ld a, $c6 + ld [$cd27], a + callba Function11b98f + ret +; 1fb546 + +.Odd + db "ODD@@@@@@@@@" + +.Probabilities + dw $147a ; 92% -> 8% + dw $170a ; 91% -> 1% + dw $3fff ; 75% -> 16% + dw $47ad ; 72% -> 3% + dw $70a3 ; 56% -> 16% + dw $7851 ; 53% -> 3% + dw $9c28 ; 39% -> 14% + dw $a147 ; 37% -> 2% + dw $bae0 ; 27% -> 10% + dw $bfff ; 25% -> 2% + dw $deb7 ; 13% -> 12% + dw $e3d6 ; 11% -> 2% + dw $fd6f ; 1% -> 10% + dw $ffff ; 0% -> 1% +; 1fb56e + + +OddEggs: ; 1fb56e + OddEgg1: db PICHU db NO_ITEM From fd74b4d3791b71e80e95634a6da1580014a9a4ef Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 23:27:17 -0400 Subject: [PATCH 58/96] move battle tower mon handling asm into battle_tower.asm --- main.asm | 251 +---------------------------------------- stats/battle_tower.asm | 250 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 251 insertions(+), 250 deletions(-) diff --git a/main.asm b/main.asm index ac1e6f873..fce8c96ed 100644 --- a/main.asm +++ b/main.asm @@ -72632,256 +72632,7 @@ INCBIN "baserom.gbc", $1f4018, $1f636a - $1f4018 SECTION "bank7E",ROMX,BANK[$7E] -Function1f8000: ; 1f8000 - ld a, [rSVBK] - push af - ld a, $3 - ld [rSVBK], a - xor a - ld hl, $d100 - ld bc, $00e0 - call ByteFill - ld a, $ff - ld [$d10c], a - ld [$d147], a - ld [$d182], a - ld de, $d100 - ld a, [hRandomAdd] - ld b, a -.asm_1f8022 - call RNG - ld a, [hRandomAdd] - add b - ld b, a - and $1f - cp $15 - jr nc, .asm_1f8022 - ld b, a - ld a, $1 - call GetSRAMBank - ld c, $7 - ld hl, $be48 -.asm_1f803a - ld a, [hli] - cp b - jr z, .asm_1f8022 - dec c - jr nz, .asm_1f803a - ld hl, $be48 - ld a, [$be46] - ld c, a - ld a, b - ld b, 0 - add hl, bc - ld [hl], a - call CloseSRAM - push af - ld hl, BattleTowerTrainers - ld bc, 11 - call AddNTimes - ld bc, 11 - call CopyBytes - call Function1f8081 - pop af - ld hl, Function1f8000 - ld bc, $0024 - call AddNTimes - ld bc, $0024 -.asm_1f8070 - ld a, $7c - call GetFarByte - ld [de], a - inc hl - inc de - dec bc - ld a, b - or c - jr nz, .asm_1f8070 - pop af - ld [rSVBK], a - ret -; 1f8081 - -Function1f8081: ; 1f8081 - ld c, $3 - push bc - ld a, $1 - call GetSRAMBank -.asm_1f8089 - ld a, [$d800] - dec a - ld hl, BattleTowerMons - ld bc, BattleTowerMons2 - BattleTowerMons1 - call AddNTimes - - ld a, [hRandomAdd] - ld b, a -.asm_1f8099 - call RNG - ld a, [hRandomAdd] - add b - ld b, a - and $1f - cp (BattleTowerMons2 - BattleTowerMons1) / ($3b) - jr nc, .asm_1f8099 - - ld bc, $3b - call AddNTimes - ld a, [hli] - ld b, a - ld a, [hld] - ld c, a - ld a, [$d10b] - cp b - jr z, .asm_1f8089 - ld a, [$d10c] - cp c - jr z, .asm_1f8089 - ld a, [$d146] - cp b - jr z, .asm_1f8089 - ld a, [$d147] - cp c - jr z, .asm_1f8089 - ld a, [$d181] - cp b - jr z, .asm_1f8089 - ld a, [$d182] - cp c - jr z, .asm_1f8089 - ld a, [$be51] - cp b - jr z, .asm_1f8089 - ld a, [$be52] - cp b - jr z, .asm_1f8089 - ld a, [$be53] - cp b - jr z, .asm_1f8089 - ld a, [$be54] - cp b - jr z, .asm_1f8089 - ld a, [$be55] - cp b - jr z, .asm_1f8089 - ld a, [$be56] - cp b - jr z, .asm_1f8089 - - ld bc, $3b - call CopyBytes - ld a, [$d265] - push af - push de - ld hl, -$3b - add hl, de - ld a, [hl] - ld [$d265], a - ld bc, $0030 - add hl, bc - push hl - call GetPokemonName - ld h, d - ld l, e - pop de - ld bc, $000b - call CopyBytes - pop de - pop af - ld [$d265], a - pop bc - dec c - jp nz, $4083 - ld a, [$be51] - ld [$be54], a - ld a, [$be52] - ld [$be55], a - ld a, [$be53] - ld [$be56], a - ld a, [$d10b] - ld [$be51], a - ld a, [$d146] - ld [$be52], a - ld a, [$d181] - ld [$be53], a - call CloseSRAM - ret -; 1f814e - -BattleTowerTrainers: ; 1f814e - db "HANSON@@@@", FISHER - db "SAWYER@@@@", POKEMANIAC - db "MASUDA@@@@", GUITARIST - db "NICKEL@@@@", SCIENTIST - db "OLSON@@@@@", POKEFANM - db "ZABOROWSKI", LASS - db "WRIGHT@@@@", YOUNGSTER - db "ALEXANDER@", HIKER - db "KAWAKAMI@@", TEACHER - db "BICKETT@@@", POKEFANM - db "SAITO@@@@@", KIMONO_GIRL - db "CRAWFORD@@", BOARDER - db "DIAZ@@@@@@", PICNICKER - db "ERICKSON@@", BIKER - db "FAIRFIELD@", JUGGLER - db "HUNTER@@@@", POKEFANF - db "HILL@@@@@@", FIREBREATHER - db "JAVIER@@@@", SWIMMERF - db "KAUFMAN@@@", SWIMMERM - db "LANCASTER@", SKIER - db "McMAHILL@@", CAMPER - db "OBRIEN@@@@", GENTLEMAN - db "FROST@@@@@", BEAUTY - db "MORSE@@@@@", SUPER_NERD - db "YUFUNE@@@@", BLACKBELT_T - db "RAJAN@@@@@", COOLTRAINERF - db "RODRIGUEZ@", OFFICER - db "SANTIAGO@@", PSYCHIC_T - db "STOCK@@@@@", POKEFANM - db "THURMAN@@@", SCIENTIST - db "VALENTINO@", BEAUTY - db "WAGNER@@@@", CAMPER - db "YATES@@@@@", BIRD_KEEPER - db "ANDREWS@@@", PICNICKER - db "BAHN@@@@@@", POKEMANIAC - db "MORI@@@@@@", SCIENTIST - db "BUCKMAN@@@", SAGE - db "COBB@@@@@@", SCHOOLBOY - db "HUGHES@@@@", FISHER - db "ARITA@@@@@", KIMONO_GIRL - db "EASTON@@@@", PSYCHIC_T - db "FREEMAN@@@", CAMPER - db "GIESE@@@@@", LASS - db "HATCHER@@@", GENTLEMAN - db "JACKSON@@@", POKEFANF - db "KAHN@@@@@@", POKEMANIAC - db "LEONG@@@@@", YOUNGSTER - db "MARINO@@@@", TEACHER - db "NEWMAN@@@@", SAILOR - db "NGUYEN@@@@", BLACKBELT_T - db "OGDEN@@@@@", SUPER_NERD - db "PARK@@@@@@", COOLTRAINERF - db "RAINE@@@@@", SWIMMERM - db "SELLS@@@@@", BIRD_KEEPER - db "ROCKWELL@@", BOARDER - db "THORNTON@@", LASS - db "TURNER@@@@", OFFICER - db "VAN DYKE@@", SKIER - db "WALKER@@@@", SCHOOLBOY - db "MEYER@@@@@", SWIMMERF - db "JOHNSON@@@", YOUNGSTER - db "ADAMS@@@@@", GUITARIST - db "SMITH@@@@@", BUG_CATCHER - db "TAJIRI@@@@", BUG_CATCHER - db "BAKER@@@@@", POKEMANIAC - db "COLLINS@@@", SCIENTIST - db "SMART@@@@@", SUPER_NERD - db "DYKSTRA@@@", SWIMMERF - db "EATON@@@@@", BIKER - db "WONG@@@@@@", FIREBREATHER -; 1f8450 - -BattleTowerMons: ; 1f8450 +; 1fc000 INCLUDE "stats/battle_tower.asm" ; 1fb4b6 diff --git a/stats/battle_tower.asm b/stats/battle_tower.asm index 4a74fe0f5..cda7195da 100644 --- a/stats/battle_tower.asm +++ b/stats/battle_tower.asm @@ -1,4 +1,254 @@ +Function1f8000: ; 1f8000 + ld a, [rSVBK] + push af + ld a, $3 + ld [rSVBK], a + xor a + ld hl, $d100 + ld bc, $00e0 + call ByteFill + ld a, $ff + ld [$d10c], a + ld [$d147], a + ld [$d182], a + ld de, $d100 + ld a, [hRandomAdd] + ld b, a +.asm_1f8022 + call RNG + ld a, [hRandomAdd] + add b + ld b, a + and $1f + cp $15 + jr nc, .asm_1f8022 + ld b, a + ld a, $1 + call GetSRAMBank + ld c, $7 + ld hl, $be48 +.asm_1f803a + ld a, [hli] + cp b + jr z, .asm_1f8022 + dec c + jr nz, .asm_1f803a + ld hl, $be48 + ld a, [$be46] + ld c, a + ld a, b + ld b, 0 + add hl, bc + ld [hl], a + call CloseSRAM + push af + ld hl, BattleTowerTrainers + ld bc, 11 + call AddNTimes + ld bc, 11 + call CopyBytes + call Function1f8081 + pop af + ld hl, Function1f8000 + ld bc, $0024 + call AddNTimes + ld bc, $0024 +.asm_1f8070 + ld a, $7c + call GetFarByte + ld [de], a + inc hl + inc de + dec bc + ld a, b + or c + jr nz, .asm_1f8070 + pop af + ld [rSVBK], a + ret +; 1f8081 +Function1f8081: ; 1f8081 + ld c, $3 + push bc + ld a, $1 + call GetSRAMBank +.asm_1f8089 + ld a, [$d800] + dec a + ld hl, BattleTowerMons + ld bc, BattleTowerMons2 - BattleTowerMons1 + call AddNTimes + + ld a, [hRandomAdd] + ld b, a +.asm_1f8099 + call RNG + ld a, [hRandomAdd] + add b + ld b, a + and $1f + cp (BattleTowerMons2 - BattleTowerMons1) / ($3b) + jr nc, .asm_1f8099 + + ld bc, $3b + call AddNTimes + ld a, [hli] + ld b, a + ld a, [hld] + ld c, a + ld a, [$d10b] + cp b + jr z, .asm_1f8089 + ld a, [$d10c] + cp c + jr z, .asm_1f8089 + ld a, [$d146] + cp b + jr z, .asm_1f8089 + ld a, [$d147] + cp c + jr z, .asm_1f8089 + ld a, [$d181] + cp b + jr z, .asm_1f8089 + ld a, [$d182] + cp c + jr z, .asm_1f8089 + ld a, [$be51] + cp b + jr z, .asm_1f8089 + ld a, [$be52] + cp b + jr z, .asm_1f8089 + ld a, [$be53] + cp b + jr z, .asm_1f8089 + ld a, [$be54] + cp b + jr z, .asm_1f8089 + ld a, [$be55] + cp b + jr z, .asm_1f8089 + ld a, [$be56] + cp b + jr z, .asm_1f8089 + + ld bc, $3b + call CopyBytes + ld a, [$d265] + push af + push de + ld hl, -$3b + add hl, de + ld a, [hl] + ld [$d265], a + ld bc, $0030 + add hl, bc + push hl + call GetPokemonName + ld h, d + ld l, e + pop de + ld bc, $000b + call CopyBytes + pop de + pop af + ld [$d265], a + pop bc + dec c + jp nz, $4083 + ld a, [$be51] + ld [$be54], a + ld a, [$be52] + ld [$be55], a + ld a, [$be53] + ld [$be56], a + ld a, [$d10b] + ld [$be51], a + ld a, [$d146] + ld [$be52], a + ld a, [$d181] + ld [$be53], a + call CloseSRAM + ret +; 1f814e + +BattleTowerTrainers: ; 1f814e + db "HANSON@@@@", FISHER + db "SAWYER@@@@", POKEMANIAC + db "MASUDA@@@@", GUITARIST + db "NICKEL@@@@", SCIENTIST + db "OLSON@@@@@", POKEFANM + db "ZABOROWSKI", LASS + db "WRIGHT@@@@", YOUNGSTER + db "ALEXANDER@", HIKER + db "KAWAKAMI@@", TEACHER + db "BICKETT@@@", POKEFANM + db "SAITO@@@@@", KIMONO_GIRL + db "CRAWFORD@@", BOARDER + db "DIAZ@@@@@@", PICNICKER + db "ERICKSON@@", BIKER + db "FAIRFIELD@", JUGGLER + db "HUNTER@@@@", POKEFANF + db "HILL@@@@@@", FIREBREATHER + db "JAVIER@@@@", SWIMMERF + db "KAUFMAN@@@", SWIMMERM + db "LANCASTER@", SKIER + db "McMAHILL@@", CAMPER + db "OBRIEN@@@@", GENTLEMAN + db "FROST@@@@@", BEAUTY + db "MORSE@@@@@", SUPER_NERD + db "YUFUNE@@@@", BLACKBELT_T + db "RAJAN@@@@@", COOLTRAINERF + db "RODRIGUEZ@", OFFICER + db "SANTIAGO@@", PSYCHIC_T + db "STOCK@@@@@", POKEFANM + db "THURMAN@@@", SCIENTIST + db "VALENTINO@", BEAUTY + db "WAGNER@@@@", CAMPER + db "YATES@@@@@", BIRD_KEEPER + db "ANDREWS@@@", PICNICKER + db "BAHN@@@@@@", POKEMANIAC + db "MORI@@@@@@", SCIENTIST + db "BUCKMAN@@@", SAGE + db "COBB@@@@@@", SCHOOLBOY + db "HUGHES@@@@", FISHER + db "ARITA@@@@@", KIMONO_GIRL + db "EASTON@@@@", PSYCHIC_T + db "FREEMAN@@@", CAMPER + db "GIESE@@@@@", LASS + db "HATCHER@@@", GENTLEMAN + db "JACKSON@@@", POKEFANF + db "KAHN@@@@@@", POKEMANIAC + db "LEONG@@@@@", YOUNGSTER + db "MARINO@@@@", TEACHER + db "NEWMAN@@@@", SAILOR + db "NGUYEN@@@@", BLACKBELT_T + db "OGDEN@@@@@", SUPER_NERD + db "PARK@@@@@@", COOLTRAINERF + db "RAINE@@@@@", SWIMMERM + db "SELLS@@@@@", BIRD_KEEPER + db "ROCKWELL@@", BOARDER + db "THORNTON@@", LASS + db "TURNER@@@@", OFFICER + db "VAN DYKE@@", SKIER + db "WALKER@@@@", SCHOOLBOY + db "MEYER@@@@@", SWIMMERF + db "JOHNSON@@@", YOUNGSTER + db "ADAMS@@@@@", GUITARIST + db "SMITH@@@@@", BUG_CATCHER + db "TAJIRI@@@@", BUG_CATCHER + db "BAKER@@@@@", POKEMANIAC + db "COLLINS@@@", SCIENTIST + db "SMART@@@@@", SUPER_NERD + db "DYKSTRA@@@", SWIMMERF + db "EATON@@@@@", BIKER + db "WONG@@@@@@", FIREBREATHER +; 1f8450 + + +BattleTowerMons: ; 1f8450 BattleTowerMons1: From 2f169fd2f9859ec3bcaacc26dc132c9b29e561cd Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 29 Aug 2013 23:27:57 -0400 Subject: [PATCH 59/96] clean up bank 7e includes --- main.asm | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/main.asm b/main.asm index fce8c96ed..8a3fe57e7 100644 --- a/main.asm +++ b/main.asm @@ -72632,13 +72632,8 @@ INCBIN "baserom.gbc", $1f4018, $1f636a - $1f4018 SECTION "bank7E",ROMX,BANK[$7E] -; 1fc000 - INCLUDE "stats/battle_tower.asm" -; 1fb4b6 - -; 1fb4b6 - INCLUDE "stats/odd_eggs.asm" -; 1fb8a8 +INCLUDE "stats/battle_tower.asm" +INCLUDE "stats/odd_eggs.asm" SECTION "bank7F",ROMX,BANK[$7F] From 320142fdda96d153d0fbb4d6de68aecdd50609dc Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 00:07:51 -0400 Subject: [PATCH 60/96] PCItems in wram --- wram.asm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wram.asm b/wram.asm index 74927ca7c..e4ffd2fdb 100644 --- a/wram.asm +++ b/wram.asm @@ -1742,7 +1742,12 @@ NumBalls: ; d8d7 Balls: ; d8d8 ds 25 BallsEnd - + +PCItems: ; d8f1 + ds 101 +PCItemsEnd + + SECTION "overworld",WRAMX[$d95b],BANK[1] WhichRegisteredItem: ; d95b REGISTERED_POCKET EQU %11000000 From 79bcda11ad25d7363a4fcfa1df71e5cdf4d1b2b0 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 04:57:32 -0400 Subject: [PATCH 61/96] PCItems and game init formatting --- main.asm | 63 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/main.asm b/main.asm index 8a3fe57e7..b14eb9995 100644 --- a/main.asm +++ b/main.asm @@ -740,6 +740,8 @@ Function1836: ; 1836 ret ; 184a + + Function184a: ; 184a ld a, [StandingTile] call GetTileCollision @@ -757,7 +759,6 @@ Function1852: ; 1852 ; 185d - GetTileCollision: ; 185d ; Get the collision type of tile a. @@ -2449,11 +2450,11 @@ AskSerial: ; 2063 ; 208a -Function208a: ; 208a +ResetGameTime: ; 208a xor a ld [GameTimeCap], a ld [GameTimeHours], a - ld [$d4c5], a + ld [GameTimeHours + 1], a ld [GameTimeMinutes], a ld [GameTimeSeconds], a ld [GameTimeFrames], a @@ -13222,64 +13223,80 @@ Function5ba7: ; 5ba7 ; 5bae Function5bae: ; 5bae + ld hl, Sprites ld bc, $0bcc xor a call ByteFill + ld hl, $d000 ld bc, $047b xor a call ByteFill + ld hl, PlayerID ld bc, $0b7a xor a call ByteFill + ld a, [rLY] ld [$ffe3], a call DelayFrame ld a, [hRandomSub] ld [PlayerID], a + ld a, [rLY] ld [$ffe3], a call DelayFrame ld a, [hRandomAdd] ld [PlayerID + 1], a + call RNG ld [$d84a], a call DelayFrame call RNG ld [$d84b], a + ld hl, PartyCount call Function5ca1 + xor a ld [$db72], a ld [$d4b4], a + call Function5ca6 - ld a, $1 + + ld a, 1 call GetSRAMBank ld hl, BoxCount call Function5ca1 call CloseSRAM + ld hl, NumItems call Function5ca1 + ld hl, NumKeyItems call Function5ca1 + ld hl, NumBalls call Function5ca1 - ld hl, $d8f1 + + ld hl, PCItems call Function5ca1 + xor a ld [RoamMon1Species], a ld [RoamMon2Species], a ld [RoamMon3Species], a - ld a, $ff + ld a, -1 ld [RoamMon1MapGroup], a ld [RoamMon2MapGroup], a ld [RoamMon3MapGroup], a ld [RoamMon1MapNumber], a ld [RoamMon2MapNumber], a ld [RoamMon3MapNumber], a - ld a, $0 + + ld a, 0 call GetSRAMBank ld hl, $abe2 xor a @@ -13287,38 +13304,50 @@ Function5bae: ; 5bae dec a ld [hl], a call CloseSRAM + call Function5d33 call Function5cd3 + xor a ld [MonType], a + ld [JohtoBadges], a ld [KantoBadges], a + ld [$d855], a ld [$d856], a + ld [Money], a - ld a, $b - ld [$d84f], a - ld a, $b8 - ld [$d850], a + ld a, 3000 >> 8 + ld [Money + 1], a + ld a, 3000 & $ff + ld [Money + 2], a + xor a ld [$dc17], a + ld hl, $dc19 ld [hl], $0 inc hl ld [hl], $8 inc hl ld [hl], $fc + call Function5ce9 + ld a, $9 ld hl, $6751 rst FarCall + ld a, $11 ld hl, $4765 rst FarCall + ld a, $41 ld hl, $61c0 rst FarCall - call Function208a + + call ResetGameTime ret ; 5ca1 @@ -28443,7 +28472,7 @@ Function157e9: ; 0x157e9 ld [$d10c], a ld a, [Buffer2] ld [$d107], a - ld hl, $d8f1 + ld hl, PCItems call Function2f53 ld a, $3b call Predef @@ -28484,7 +28513,7 @@ KrisTossItemMenu: ; 0x1585f .asm_15868 call Function15985 jr c, .asm_15878 - ld de, $d8f1 + ld de, PCItems ld a, $4 ld hl, $69f4 rst $8 @@ -28629,7 +28658,7 @@ Function1590a: ; 0x1590a ld [Buffer1], a ld a, [$d107] ld [Buffer2], a - ld hl, $d8f1 + ld hl, PCItems call Function2f66 jr nc, .asm_15965 ld a, [Buffer1] @@ -28763,7 +28792,7 @@ MenuData15a08: ; 0x15a08 db %10110000 db 4, 8 ; rows/cols? db 2 ; horizontal spacing? - dbw 0, $d8f1 + dbw 0, PCItems dbw BANK(Function24ab4), Function24ab4 dbw BANK(Function24ac3), Function24ac3 dbw BANK(Function244c3), Function244c3 @@ -66926,7 +66955,7 @@ Functionfd0c3: ; fd0c3 ld [CurItem], a ld a, $1 ld [$d10c], a - ld hl, $d8f1 + ld hl, PCItems call Function2f66 ret ; fd0eb From 3aabca9baa859b3761235db8cb55b52837b5f5dc Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 14:20:01 -0400 Subject: [PATCH 62/96] remove a section def in the middle of the player struct --- wram.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wram.asm b/wram.asm index e4ffd2fdb..e4e0af723 100644 --- a/wram.asm +++ b/wram.asm @@ -1642,8 +1642,8 @@ PlayerDirection: ; d4de ; $11 right ds 1 + ds 2 -SECTION "MapEngine",WRAMX[$d4e1],BANK[1] PlayerAction: ; d4e1 ; 1 standing ; 2 walking From b86d0da040448f286aa65ff5b2bacb05fff200a8 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 14:21:26 -0400 Subject: [PATCH 63/96] less arbitrary wram clearing in game init --- main.asm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.asm b/main.asm index b14eb9995..9b39ebcc7 100644 --- a/main.asm +++ b/main.asm @@ -13225,17 +13225,17 @@ Function5ba7: ; 5ba7 Function5bae: ; 5bae ld hl, Sprites - ld bc, $0bcc + ld bc, Options - Sprites xor a call ByteFill ld hl, $d000 - ld bc, $047b + ld bc, PlayerID - $d000 xor a call ByteFill ld hl, PlayerID - ld bc, $0b7a + ld bc, $dff5 - PlayerID xor a call ByteFill From 674229228f1be67da568bfb734bacae76bfcc429 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 17:48:59 -0400 Subject: [PATCH 64/96] Coins wram label --- wram.asm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wram.asm b/wram.asm index e4e0af723..14fb8d5a3 100644 --- a/wram.asm +++ b/wram.asm @@ -1712,7 +1712,10 @@ StatusFlags2: ; d84d Money: ; d84e ds 3 - ds 6 + ds 4 + +Coins: ; d855 + ds 2 Badges: JohtoBadges: ; d857 From 7cc320e835497fbf7f7a66d47cc6351b571c32e7 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 17:50:08 -0400 Subject: [PATCH 65/96] Coins in main.asm --- engine/scripting.asm | 2 +- main.asm | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index 3bd652ea0..61ebae935 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -2217,7 +2217,7 @@ Script_readcoins: ; 0x97747 call Unknown_0x97771 ld hl, StringBuffer1 - ld de, $d855 + ld de, Coins ld bc, $4206 call PrintNum ld de, StringBuffer1 diff --git a/main.asm b/main.asm index 9b39ebcc7..cb3a047bd 100644 --- a/main.asm +++ b/main.asm @@ -13314,8 +13314,8 @@ Function5bae: ; 5bae ld [JohtoBadges], a ld [KantoBadges], a - ld [$d855], a - ld [$d856], a + ld [Coins], a + ld [Coins + 1], a ld [Money], a ld a, 3000 >> 8 @@ -29656,7 +29656,7 @@ Function16053: ; 16053 Function1606f: ; 1606f ld a, $2 - ld de, $d855 + ld de, Coins call $6055 ld a, $2 ld bc, $608d @@ -29681,7 +29681,7 @@ INCBIN "baserom.gbc", $1608d, $1608f - $1608d Function1608f: ; 1608f ld a, $2 - ld de, $d855 + ld de, Coins call $6037 jr nc, .asm_1609f xor a @@ -29698,7 +29698,7 @@ Function1608f: ; 1608f Function160a1: ; 160a1 ld a, $2 - ld de, $d855 + ld de, Coins jp $600d ; 160a9 @@ -32087,7 +32087,7 @@ Function24b25: ; 24b25 ld hl, $c4c5 ld de, String24b8e call PlaceString - ld de, $d855 + ld de, Coins ld bc, $0204 ld hl, $c4c1 call PrintNum @@ -32110,7 +32110,7 @@ Function24b4e: ; 24b4e ld de, CoinString call PlaceString ld hl, $c4eb - ld de, $d855 + ld de, Coins ld bc, $0204 call PrintNum ret From 8fe7f4c3a567edbbdc1579dee8f5ffb6afb7df1c Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Fri, 30 Aug 2013 17:23:41 -0500 Subject: [PATCH 66/96] HACK: re-instate the ItemFragment macro hack This is to fix the preprocessor temporarily. Maybe ItemFragment can be removed completely. --- preprocessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor.py b/preprocessor.py index e529fe043..0d55c906f 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -626,7 +626,7 @@ def preprocess(macros, skippable_macros=None, lines=None): macro_table = make_macro_table(list(set(macros + skippable_macros))) # HACK for pokecrystal. Must be after make_macro_table call. - skippable_macros += ["TextEndingCommand"] + skippable_macros += ["TextEndingCommand", "ItemFragment"] if not lines: # read each line from stdin From 4983c46a26ff2c165c67a78cebc0c686a23f9cda Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 18:57:31 -0400 Subject: [PATCH 67/96] use callab/callba macros for known FarCalls --- main.asm | 100 ++++++++++++++++++------------------------------------- 1 file changed, 33 insertions(+), 67 deletions(-) diff --git a/main.asm b/main.asm index cb3a047bd..ab5dc4f19 100644 --- a/main.asm +++ b/main.asm @@ -1574,9 +1574,7 @@ Function1c07: ; 0x1c07 ret Function1c10: ; 0x1c10 - ld hl, $446d - ld a, $9 - rst $8 + callab Function2446d ret Function1c17: ; 0x1c17 @@ -4630,9 +4628,7 @@ Function2b74: ; 0x2b74 call Function3200 ld b, $9 call GetSGBLayout - ld a, $12 - ld hl, $5409 - rst $8 + callba Function49409 call Function485 call DelayFrame ld a, $1 @@ -19499,7 +19495,7 @@ Functioncbd8: ; cbd8 ld a, [Buffer2] cp $2 jr nz, .asm_cbf7 - ld hl, $4c35 + ld hl, UnknownScript_0xcc35 call Function31cd ld a, $81 ret @@ -23576,9 +23572,7 @@ StartMenu: ; 125cd call .DrawBugContestStatusBox call Function2e31 call Function2e20 - ld a, $1 - ld hl, $64bf - rst $8 + callba Function64bf call .DrawBugContestStatus call Function485 jr .Select @@ -28453,9 +28447,7 @@ Function157e9: ; 0x157e9 .askquantity ld hl, .HowManyText call Function1d4f - ld a, $9 - ld hl, $4fbf - rst $8 + callba Function24fbf call Function1c07 call Function1c07 jr c, .done @@ -28550,20 +28542,14 @@ KrisDepositItemMenu: ; 0x1588b jr c, .asm_158b6 call Function2ed3 call Function1d6e - ld a, $4 - ld hl, $46a5 - rst $8 + callba Function106a5 .asm_1589c - ld a, $4 - ld hl, $46be - rst $8 + callba Function106be ld a, [$cf66] and a jr z, .asm_158b3 call Function158cc - ld a, $4 - ld hl, CheckRegisteredItem - rst $8 + callba CheckRegisteredItem jr .asm_1589c .asm_158b3 @@ -28595,9 +28581,7 @@ Function158cc: ; 0x158cc push af ld a, $0 ld [$c2ce], a - ld a, $3 - ld hl, $5453 - rst $8 + callba CheckItemMenu ld a, [$d142] ld hl, JumpTable158e7 rst JumpTable @@ -28631,9 +28615,7 @@ JumpTable158e7: ; 0x158e7 ; 0x1590a Function1590a: ; 0x1590a - ld a, $3 - ld hl, $5427 - rst $8 + callba _CheckTossableItem ld a, [$d142] and a jr z, .asm_1591d @@ -28644,9 +28626,7 @@ Function1590a: ; 0x1590a .asm_1591d ld hl, .HowManyText call Function1d4f - ld a, $9 - ld hl, $4fbf - rst $8 + callba Function24fbf push af call Function1c07 call Function1c07 @@ -28698,9 +28678,7 @@ Function1590a: ; 0x1590a KrisMailBoxMenu: ; 0x1597d - ld a, $11 - ld hl, $47a0 - rst $8 + callba _KrisMailBoxMenu xor a ret ; 0x15985 @@ -47638,27 +47616,15 @@ Function4484a: ; 0x4484a ld [PartyMenuActionText], a call WhiteBGMap .asm_448dc - ld a, $14 - ld hl, $404f - rst $8 - ld a, $14 - ld hl, $4405 - rst $8 - ld a, $14 - ld hl, $43e0 - rst $8 - ld a, $14 - ld hl, PickedFruitTree - rst $8 - ld a, $14 - ld hl, $449a - rst $8 + callba Function5004f + callba Function50405 + callba Function503e0 + callba WritePartyMenuTilemap + callba PrintPartyMenuText call WaitBGMap call Function32f9 call DelayFrame - ld a, $14 - ld hl, $4457 - rst $8 + callba PartyMenuSelect jr c, .asm_44939 ld a, [CurPartySpecies] cp $fd @@ -56192,7 +56158,7 @@ GetTimePalFade: ; 8c17c Function8c20f: ; 8c20f - call $426d + call Function8c26d ld a, [rBGP] ld [$cfc7], a ld a, [rOBP0] @@ -56208,7 +56174,7 @@ Function8c20f: ; 8c20f ld a, [$cf63] bit 7, a jr nz, .asm_8c23a - call $4314 + call Function8c314 call DelayFrame jr .asm_8c22b @@ -56247,12 +56213,12 @@ Function8c26d: ; 8c26d callba Function6454 call Function1ad2 call DelayFrame - call $42a0 - call $4f4f + call Function8c2a0 + call Function8cf4f jr .asm_8c28b .asm_8c288 - call $42aa + call Function8c2aa .asm_8c28b ld a, $90 @@ -56265,14 +56231,14 @@ Function8c26d: ; 8c26d ld [hli], a ld [hli], a ld [hl], a - call $46d8 + call Function8c6d8 ret ; 8c2a0 Function8c2a0: ; 8c2a0 - call $42aa + call Function8c2aa ld hl, VBGMap0 - call $42cf + call Function8c2cf ret ; 8c2aa @@ -56344,9 +56310,9 @@ Function8c6d8: ; 8c6d8 ld a, $5 ld [rSVBK], a ld hl, $d100 - call $46ef + call Function8c6ef ld hl, $d200 - call $46ef + call Function8c6ef pop af ld [rSVBK], a ret @@ -56378,7 +56344,7 @@ Function8c940: ; 8c940 ld a, e and $1 ld [$cf63], a - call $496d + call Function8c96d call WaitSFX ld de, $001e call StartSFX @@ -56388,10 +56354,10 @@ Function8c940: ; 8c940 jr nz, .asm_8c96c ld a, $90 ld [$c3b5], a - ld hl, $4f7a + ld hl, Function8cf7a ld a, $23 rst FarCall - call $4a0c + call Function8ca0c call DelayFrame jr .asm_8c952 @@ -56400,7 +56366,7 @@ Function8c940: ; 8c940 ; 8c96d Function8c96d: ; 8c96d - ld hl, $4f53 + ld hl, Function8cf53 ld a, $23 rst FarCall ld de, $49cc @@ -64197,7 +64163,7 @@ Options_Sound: ; e43dd Options_Print: ; e4424 - call $4491 + call Functione4491 ld a, [hJoyPressed] bit 5, a jr nz, .asm_e443c From f4572ecd4dc8effb26c2a14de30f0ba58c317078 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 19:14:04 -0400 Subject: [PATCH 68/96] use more egg constants in main --- main.asm | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/main.asm b/main.asm index ab5dc4f19..fc1aaee33 100644 --- a/main.asm +++ b/main.asm @@ -7377,7 +7377,7 @@ Function3718: ; 3718 Function3741: ; 3741 and a jr z, .asm_374c - cp $fd + cp EGG jr z, .asm_374e cp $fc jr c, .asm_374e @@ -24912,7 +24912,7 @@ INCBIN "baserom.gbc", $12f5b, $12fba - $12f5b Function12fba: ; 12fba ld a, [CurPartySpecies] - cp $fd + cp EGG jr z, .asm_12fd2 ld hl, Options ld a, [hl] @@ -25025,13 +25025,13 @@ Function1308f: ; 1308f inc a ld [CurPartyMon], a ld c, a - ld b, $0 + ld b, 0 ld hl, PartySpecies add hl, bc ld a, [hl] cp $ff jr z, .asm_130a7 - cp $fd + cp EGG ret nz jr .asm_1308f @@ -25044,11 +25044,11 @@ Function1308f: ; 1308f dec a ld [CurPartyMon], a ld c, a - ld b, $0 + ld b, 0 ld hl, PartySpecies add hl, bc ld a, [hl] - cp $fd + cp EGG ret nz ld a, [CurPartyMon] and a @@ -25302,14 +25302,14 @@ Function132da: ; 132da ret z ld c, a ld e, a - ld d, $0 + ld d, 0 ld hl, PartyCount add hl, de .asm_132e7 ld a, [hl] and a jr z, .asm_132f3 - cp $fd + cp EGG jr z, .asm_132f3 cp $fc jr c, .asm_132f8 @@ -25334,7 +25334,7 @@ Function132fe: ; 132fe cp c ret z ld e, c - ld d, $0 + ld d, 0 ld hl, PartySpecies add hl, de .asm_1330f @@ -25343,7 +25343,7 @@ Function132fe: ; 132fe ret z and a jr z, .asm_1331e - cp $fd + cp EGG jr z, .asm_1331e cp $fc jr c, .asm_13321 @@ -25353,8 +25353,8 @@ Function132fe: ; 132fe jr .asm_1330f .asm_13321 - ld hl, $c4b2 - ld [hl], $ed + hlcoord 18, 0 + ld [hl], "▶" ret ; 13327 @@ -34860,7 +34860,7 @@ Function2c7fb: ; 2c7fb callba PartyMenuSelect push af ld a, [CurPartySpecies] - cp $fd + cp EGG pop bc jr z, .asm_2c854 push bc @@ -39983,10 +39983,10 @@ Function3d887: ; 3d887 ld hl, PartySpecies ld a, [CurPartyMon] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hl] - cp $fd + cp EGG ld hl, BattleText_0x80b26 jr z, .asm_3d8ae ld hl, BattleText_0x80b0b @@ -47627,9 +47627,9 @@ Function4484a: ; 0x4484a callba PartyMenuSelect jr c, .asm_44939 ld a, [CurPartySpecies] - cp $fd + cp EGG jr z, .asm_44923 - ld a, $1 + ld a, PartyMon1Item - PartyMon1 call GetPartyParamLocation ld a, [hl] and a @@ -51404,14 +51404,14 @@ INCBIN "baserom.gbc", $5036b, $50389 - $5036b Function50389: ; 50389 - ld a, $d8 + ld a, PartySpecies & $ff add b ld e, a - ld a, $dc - adc $0 + ld a, PartySpecies >> 8 + adc 0 ld d, a ld a, [de] - cp $fd + cp EGG ret ; 50396 @@ -51422,7 +51422,7 @@ Function50396: ; 50396 ld a, [PartyMenuActionText] and $f ld e, a - ld d, $0 + ld d, 0 ld hl, $43b2 add hl, de add hl, de @@ -54798,12 +54798,12 @@ Function8653f: ; 8653f ld [de], a inc de ld hl, PartySpecies - ld c, $0 + ld c, 0 .asm_86556 ld a, [hli] cp $ff jr z, .asm_865b1 - cp $fd + cp EGG jr nz, .asm_86562 inc c jr .asm_86556 @@ -55021,7 +55021,7 @@ Function86748: ; 86748 ld hl, $c50a call Function378b ld a, [CurPartySpecies] - cp $fd + cp EGG jr z, .asm_867f8 ld hl, $c5a5 ld a, $74 From 69adf48a54a6182f1168fb5bf73f892afc2c6ad4 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Fri, 30 Aug 2013 18:26:07 -0500 Subject: [PATCH 69/96] remove "skippable_macros" from preprocessor The preprocessor no longer has the concept of skippable_macros and now always skips any line that starts with "db" or "dw" because neither of these should be treated as macros. fixes #178 --- preprocessor.py | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index 0d55c906f..6bed4ad80 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -39,9 +39,6 @@ show_original_lines = False # helpful for debugging macros do_macro_sanity_check = False -class SkippableMacro(object): - macro_name = "db" - chars = { "ガ": 0x05, "ギ": 0x06, @@ -418,11 +415,14 @@ def macro_test(asm, macro_table): """ # macros are determined by the first symbol on the line token = extract_token(asm) - # check against all names - if token in macro_table: - return (macro_table[token], token) - else: - return (None, None) + + # skip db and dw since rgbasm handles those and they aren't macros + if token not in ["db", "dw"]: + # check against all names + if token in macro_table: + return (macro_table[token], token) + + return (None, None) def is_based_on(something, base): """ @@ -436,7 +436,7 @@ def is_based_on(something, base): options += [something.__name__] return (base in options) -def macro_translator(macro, token, line, skippable_macros): +def macro_translator(macro, token, line): """ Converts a line with a macro into a rgbasm-compatible line. """ @@ -475,10 +475,9 @@ def macro_translator(macro, token, line, skippable_macros): if show_original_lines: sys.stdout.write("; original_line: " + original_line) - # "db" is a macro because of SkippableMacro - # rgbasm can handle "db" so no preprocessing is required - # (don't check its param count) - if macro.__name__ in skippable_macros or (macro.macro_name == "db" and macro in skippable_macros): + # rgbasm can handle "db" so no preprocessing is required, plus this wont be + # reached because of earlier checks in macro_test. + if macro.macro_name in ["db", "dw"]: sys.stdout.write(original_line) return @@ -584,7 +583,7 @@ def macro_translator(macro, token, line, skippable_macros): sys.stdout.write(output) -def read_line(l, skippable_macros, macro_table): +def read_line(l, macro_table): """Preprocesses a given line of asm.""" # strip comments from asm @@ -612,21 +611,15 @@ def read_line(l, skippable_macros, macro_table): else: macro, token = macro_test(asm, macro_table) if macro: - macro_translator(macro, token, asm, skippable_macros) + macro_translator(macro, token, asm) else: sys.stdout.write(asm) if comment: sys.stdout.write(comment) -def preprocess(macros, skippable_macros=None, lines=None): +def preprocess(macros, lines=None): """Main entry point for the preprocessor.""" - if skippable_macros == None: - skippable_macros = [SkippableMacro] - - macro_table = make_macro_table(list(set(macros + skippable_macros))) - - # HACK for pokecrystal. Must be after make_macro_table call. - skippable_macros += ["TextEndingCommand", "ItemFragment"] + macro_table = make_macro_table(macros) if not lines: # read each line from stdin @@ -636,7 +629,7 @@ def preprocess(macros, skippable_macros=None, lines=None): lines = lines.split("\n") for l in lines: - read_line(l, skippable_macros, macro_table) + read_line(l, macro_table) # only run against stdin when not included as a module if __name__ == "__main__": From 5e70ac56eae93a723820172b6c271e8104182665 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Fri, 30 Aug 2013 18:31:17 -0500 Subject: [PATCH 70/96] remove ItemFragment from preprocessor It's not required. see #178 --- preprocessor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index 6bed4ad80..c4a93000a 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -10,7 +10,6 @@ from extras.pokemontools.crystal import ( Signpost, PeopleEvent, DataByteWordMacro, - ItemFragment, text_command_classes, movement_command_classes, music_classes, @@ -23,7 +22,6 @@ even_more_macros = [ Signpost, PeopleEvent, DataByteWordMacro, - ItemFragment, ] macros = command_classes From 17f25691db80b7bd577d401a53eecb913a0b8860 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 19:17:32 -0400 Subject: [PATCH 71/96] Function378b is IsAPokemon --- main.asm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.asm b/main.asm index fc1aaee33..d506d9854 100644 --- a/main.asm +++ b/main.asm @@ -7374,19 +7374,20 @@ Function3718: ; 3718 -Function3741: ; 3741 +IsAPokemon: ; 3741 +; Return carry if species a is not a Pokemon. and a - jr z, .asm_374c + jr z, .NotAPokemon cp EGG - jr z, .asm_374e + jr z, .Pokemon cp $fc - jr c, .asm_374e + jr c, .Pokemon -.asm_374c +.NotAPokemon scf ret -.asm_374e +.Pokemon and a ret ; 3750 @@ -7460,7 +7461,7 @@ Function3786: ; 3786 Function378b: ; 378b ld a, [CurPartySpecies] - call Function3741 + call IsAPokemon jr c, .asm_37ad push hl ld de, VTiles2 From 5342f8d6300898faa312d9b5dec248cfe0cfb757 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 22:07:37 -0400 Subject: [PATCH 72/96] NUM_POKEMON constant before we were just using CELEBI, but there's no way that's gonna pan out --- constants/pokemon_constants.asm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/constants/pokemon_constants.asm b/constants/pokemon_constants.asm index 40b450b85..29739ed46 100644 --- a/constants/pokemon_constants.asm +++ b/constants/pokemon_constants.asm @@ -1,3 +1,5 @@ +NUM_POKEMON EQU 251 + BULBASAUR EQU 1 IVYSAUR EQU 2 VENUSAUR EQU 3 From 21248effe489af1624d3b43cc2abbe3c7849865a Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 22:25:50 -0400 Subject: [PATCH 73/96] NUM_POKEMON in main.asm --- main.asm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.asm b/main.asm index d506d9854..ed9fe4464 100644 --- a/main.asm +++ b/main.asm @@ -7380,7 +7380,7 @@ IsAPokemon: ; 3741 jr z, .NotAPokemon cp EGG jr z, .Pokemon - cp $fc + cp NUM_POKEMON + 1 jr c, .Pokemon .NotAPokemon @@ -25312,7 +25312,7 @@ Function132da: ; 132da jr z, .asm_132f3 cp EGG jr z, .asm_132f3 - cp $fc + cp NUM_POKEMON + 1 jr c, .asm_132f8 .asm_132f3 @@ -25346,7 +25346,7 @@ Function132fe: ; 132fe jr z, .asm_1331e cp EGG jr z, .asm_1331e - cp $fc + cp NUM_POKEMON + 1 jr c, .asm_13321 .asm_1331e @@ -46769,7 +46769,7 @@ GetPreEvolution: ; 42581 .asm_425a2 inc c ld a, c - cp CELEBI + cp NUM_POKEMON jr c, .asm_42583 and a ret @@ -56572,9 +56572,9 @@ INCBIN "baserom.gbc", $8d03d, $8d04c - $8d03d Function8d04c: ; 8d04c call Function8d0ec call Function8d132 - cp $fd + cp EGG jr z, .asm_8d0b9 - cp $fc + cp NUM_POKEMON + 1 jr z, .asm_8d0b6 call Function8d1a2 ld a, [$c3ba] @@ -63320,9 +63320,9 @@ INCBIN "baserom.gbc", $cc9c4, $cca09 - $cc9c4 Functioncca09: ; cca09 call Functionccaaa call Functionce7d1 - cp $fd + cp EGG jp z, $4aa5 - cp $fc + cp NUM_POKEMON + 1 jp z, $4aa2 push af ld hl, $d419 From 523abc2d0e72891a216cb61d7de5edaabff34b00 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 22:46:28 -0400 Subject: [PATCH 74/96] formatting in oak speech --- main.asm | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/main.asm b/main.asm index ed9fe4464..2b8a67311 100644 --- a/main.asm +++ b/main.asm @@ -13993,42 +13993,54 @@ Function60fa: ; 60fa ; 610f Function610f: ; 610f + ld a, [hROMBank] push af - ld a, $20 + + ld a, 0 << 7 | 32 ; fade out ld [MusicFade], a ld de, MUSIC_NONE ld a, e ld [MusicFadeIDLo], a ld a, d ld [MusicFadeIDHi], a + ld de, SFX_ESCAPE_ROPE call StartSFX pop af rst Bankswitch - ld c, $8 + ld c, 8 call DelayFrames + ld hl, $5249 ld b, $13 call Function61b4 - ld c, $8 + + ld c, 8 call DelayFrames + ld hl, $52d9 ld b, $13 call Function61b4 - ld c, $8 + + ld c, 8 call DelayFrames + ld hl, $c50a - ld b, $7 - ld c, $7 + ld b, 7 + ld c, 7 call ClearBox - ld c, $3 + + ld c, 3 call DelayFrames + call Function61cd call Functione5f - ld c, $32 + + ld c, 50 call DelayFrames + call Function4b6 call ClearTileMap ret @@ -14036,11 +14048,11 @@ Function610f: ; 610f Function616a: ; 616a ld hl, IntroFadePalettes - ld b, $6 + ld b, IntroFadePalettesEnd - IntroFadePalettes .asm_616f ld a, [hli] call DmgToCgbBGPals - ld c, $a + ld c, 10 call DelayFrames dec b jr nz, .asm_616f @@ -14054,6 +14066,7 @@ IntroFadePalettes: ; 0x617c db %11111000 db %11110100 db %11100100 +IntroFadePalettesEnd ; 6182 Function6182: ; 6182 @@ -14099,14 +14112,17 @@ Function61b4: ; 61b4 ; 61cd Function61cd: ; 61cd + callba GetPlayerIcon ld c, $c ld hl, VTiles0 call Request2bpp + ld hl, Sprites ld de, .data_61fe ld a, [de] inc de + ld c, a .asm_61e4 ld a, [de] @@ -14118,14 +14134,15 @@ Function61cd: ; 61cd ld a, [de] inc de ld [hli], a - ld b, $0 + + ld b, 0 ld a, [PlayerGender] bit 0, a jr z, .asm_61f8 - ld b, $1 - + ld b, 1 .asm_61f8 ld a, b + ld [hli], a dec c jr nz, .asm_61e4 @@ -14183,7 +14200,6 @@ Function620b: ; 620b cp $5 jr c, .asm_625e xor a - .asm_625e ld e, a ld d, 0 From 70ecde3f78dc9885a04eb002f68681d03cc2d212 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 22:47:20 -0400 Subject: [PATCH 75/96] StartTitleScreen -> TitleScreen also undo "far" naming scheme --- main.asm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.asm b/main.asm index 2b8a67311..18d94ab21 100644 --- a/main.asm +++ b/main.asm @@ -14172,7 +14172,7 @@ Function620b: ; 620b push af ld a, $5 ld [rSVBK], a - call FarStartTitleScreen + call TitleScreen call DelayFrame .asm_6226 call Function627b @@ -14221,8 +14221,8 @@ Function620b: ; 620b ; 6274 -FarStartTitleScreen: ; 6274 - callba StartTitleScreen +TitleScreen: ; 6274 + callba _TitleScreen ret ; 627b @@ -69682,7 +69682,7 @@ SECTION "bank43",ROMX,BANK[$43] INCBIN "baserom.gbc", $10c000, $10ed67 - $10c000 -StartTitleScreen: ; 10ed67 +_TitleScreen: ; 10ed67 call WhiteBGMap call ClearSprites From c9d3881a2ffa4e3bdb5e5c12d98c20c0bba1e400 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 22:59:40 -0400 Subject: [PATCH 76/96] rename RNG to Random also fix 'Far' naming scheme for BattleRandom this was a long time coming --- battle/ai/scoring.asm | 76 ++++++++-------- battle/effect_commands.asm | 98 ++++++++++---------- engine/scripting.asm | 4 +- items/item_effects.asm | 2 +- main.asm | 177 +++++++++++++++++++------------------ stats/battle_tower.asm | 4 +- stats/odd_eggs.asm | 2 +- stats/wild/fish.asm | 4 +- 8 files changed, 184 insertions(+), 183 deletions(-) diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index b48e04bc6..3ad219851 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -129,7 +129,7 @@ AIScoring_RedStatMods: ; 385e0 jr .checkmove .discourage - call RNG + call Random cp 30 jr c, .checkmove inc [hl] @@ -430,7 +430,7 @@ AIScoring_LeechHit: ; 387f7 ret .asm_38815 - call RNG + call Random cp $64 ret c @@ -575,7 +575,7 @@ AIScoring_Explosion: ; 388a6 call AICheckEnemyQuarterHP ret nc - call RNG + call Random cp 20 ret c @@ -588,7 +588,7 @@ AIScoring_Explosion: ; 388a6 AIScoring_DreamEater: ; 388ca - call RNG + call Random cp $19 ret c @@ -612,7 +612,7 @@ AIScoring_EvasionUp: ; 388d4 bit 0, a jr nz, .asm_388ef - call RNG + call Random cp $b2 jr nc, .asm_38911 @@ -628,7 +628,7 @@ AIScoring_EvasionUp: ; 388d4 jr nc, .asm_3890f - call RNG + call Random cp $a jr c, .asm_388ef @@ -683,7 +683,7 @@ AIScoring_EvasionUp: ; 388d4 ret .asm_38938 - call RNG + call Random cp $50 ret c dec [hl] @@ -744,7 +744,7 @@ AIScoring_MirrorMove: ; 3895b call AICompareSpeed ret nc - call RNG + call Random cp $19 ret c @@ -766,7 +766,7 @@ AIScoring_AccuracyDown: ; 38985 bit 0, a jr nz, .asm_3899d - call RNG + call Random cp $b2 jr nc, .asm_389bf @@ -782,7 +782,7 @@ AIScoring_AccuracyDown: ; 38985 jr nc, .asm_389bd - call RNG + call Random cp $a jr c, .asm_3899d @@ -837,7 +837,7 @@ AIScoring_AccuracyDown: ; 38985 ret .asm_389e6 - call RNG + call Random cp $50 ret c dec [hl] @@ -878,7 +878,7 @@ AIScoring_Haze: ; 389f5 .asm_38a12 pop hl - call RNG + call Random cp $28 ret c dec [hl] @@ -894,7 +894,7 @@ AIScoring_Haze: ; 389f5 AIScoring_Bide: ; 38a1e call AICheckEnemyMaxHP ret c - call RNG + call Random cp $19 ret c inc [hl] @@ -926,7 +926,7 @@ AIScoring_Moonlight: ; 38a3a ret .asm_38a45 - call RNG + call Random cp $19 ret c dec [hl] @@ -948,7 +948,7 @@ AIScoring_LightScreen: AIScoring_Reflect: ; 38a54 call AICheckEnemyMaxHP ret c - call RNG + call Random cp $14 ret c inc [hl] @@ -1041,7 +1041,7 @@ AIScoring_Unused2B: ; 38a9c ret c .asm_38acd - call RNG + call Random cp $c8 ret c @@ -1061,7 +1061,7 @@ AIScoring_Unused2B: ; 38a9c AIScoring_Confuse: ; 38adb call AICheckPlayerHalfHP ret c - call RNG + call Random cp $19 jr c, .asm_38ae7 inc [hl] @@ -1156,7 +1156,7 @@ AIScoring_SpeedDownHit: ; 38b40 ret nz call AICompareSpeed ret c - call RNG + call Random cp 30 ret c dec [hl] @@ -1183,7 +1183,7 @@ AIScoring_HyperBeam: ; 38b63 ret .asm_38b72 - call RNG + call Random cp 40 ret c inc [hl] @@ -1334,7 +1334,7 @@ AIScoring_Counter: ; 38bf1 .asm_38c30 - call RNG + call Random cp $64 jr c, .asm_38c38 @@ -1388,7 +1388,7 @@ AIScoring_Encore: ; 38c3b jr nc, .asm_38c81 .asm_38c78 - call RNG + call Random cp $46 ret c dec [hl] @@ -1527,7 +1527,7 @@ AIScoring_Spite: ; 38cd5 cp $f jr nc, .asm_38d0b - call RNG + call Random cp $64 ret nc @@ -1536,7 +1536,7 @@ AIScoring_Spite: ; 38cd5 ret .asm_38d0d - call RNG + call Random cp $64 ret c dec [hl] @@ -1700,7 +1700,7 @@ AIScoring_Conversion2: ; 38d98 ret .asm_38dc9 - call RNG + call Random cp $19 ret c @@ -1722,7 +1722,7 @@ AIScoring_Disable: ; 38dd1 pop hl jr nc, .asm_38dee - call RNG + call Random cp 100 ret c dec [hl] @@ -1734,7 +1734,7 @@ AIScoring_Disable: ; 38dd1 ret nz .asm_38df3 - call RNG + call Random cp 20 ret c inc [hl] @@ -1961,7 +1961,7 @@ AIScoring_Protect: ; 38ed2 inc [hl] .asm_38f14 - call RNG + call Random cp 20 ret c inc [hl] @@ -1985,14 +1985,14 @@ AIScoring_Foresight: ; 38f1d cp GHOST jr z, .asm_38f41 - call RNG + call Random cp 20 ret c inc [hl] ret .asm_38f41 - call RNG + call Random cp 100 ret c dec [hl] @@ -2169,7 +2169,7 @@ AIScoring_Rollout: ; 38fef cp 8 jr nc, .asm_39020 - call RNG + call Random cp 200 ret nc dec [hl] @@ -2196,7 +2196,7 @@ AIScoring_Attract: ; 39026 ret .asm_39032 - call RNG + call Random cp 200 ret nc dec [hl] @@ -2558,7 +2558,7 @@ AIScoring_MirrorCoat: ; 3918b .asm_391ca - call RNG + call Random cp 100 jr c, .asm_391d2 dec [hl] @@ -2634,7 +2634,7 @@ AIScoring_Solarbeam: ; 3920b cp WEATHER_RAIN ret nz - call RNG + call Random cp 25 ; 1/10 ret c @@ -2657,7 +2657,7 @@ AIScoring_Thunder: ; 39225 cp WEATHER_SUN ret nz - call RNG + call Random cp 25 ; 1/10 ret c @@ -3150,7 +3150,7 @@ AIScoring_Cautious: ; 39418 pop hl jr nc, .asm_39425 - call RNG + call Random cp 230 ret nc @@ -3274,7 +3274,7 @@ AIScoring_Risky: ; 394a9 call AICheckEnemyMaxHP jr c, .nextmove - call RNG + call Random cp 200 ; 1/5 jr c, .nextmove @@ -3347,14 +3347,14 @@ AIGetEnemyMove: ; 39508 Function_0x39521: ; 39521 - call RNG + call Random cp 50 ; 1/5 ret ; 39527 Function_0x39527: ; 39527 - call RNG + call Random cp $80 ; 1/2 ret ; 3952d diff --git a/battle/effect_commands.asm b/battle/effect_commands.asm index afe822a16..62c715d40 100644 --- a/battle/effect_commands.asm +++ b/battle/effect_commands.asm @@ -288,7 +288,7 @@ CheckPlayerTurn: call FarPlayBattleAnimation ; 50% chance of hitting itself - call FarBattleRNG + call BattleRandom cp $80 jr nc, .CheckAttract @@ -319,7 +319,7 @@ CheckPlayerTurn: call FarPlayBattleAnimation ; 50% chance of infatuation - call FarBattleRNG + call BattleRandom cp $80 jr c, .CheckDisabledMove @@ -353,7 +353,7 @@ CheckPlayerTurn: ret z ; 25% chance to be fully paralyzed - call FarBattleRNG + call BattleRandom cp $3f ret nc @@ -544,7 +544,7 @@ CheckEnemyTurn: ; 3421f call FarPlayBattleAnimation ; 50% chance of hitting itself - call FarBattleRNG + call BattleRandom cp $80 jr nc, .CheckAttract @@ -598,7 +598,7 @@ CheckEnemyTurn: ; 3421f call FarPlayBattleAnimation ; 50% chance of infatuation - call FarBattleRNG + call BattleRandom cp $80 jr c, .CheckDisabledMove @@ -633,7 +633,7 @@ CheckEnemyTurn: ; 3421f ret z ; 25% chance to be fully paralyzed - call FarBattleRNG + call BattleRandom cp $3f ret nc @@ -808,7 +808,7 @@ BattleCommand02: ; 343db ; Random number from 0 to obedience level + monster level .rand1 - call FarBattleRNG + call BattleRandom swap a cp b jr nc, .rand1 @@ -826,7 +826,7 @@ BattleCommand02: ; 343db ; Another random number from 0 to obedience level + monster level .rand2 - call FarBattleRNG + call BattleRandom cp b jr nc, .rand2 @@ -843,7 +843,7 @@ BattleCommand02: ; 343db ld b, a ; The chance of napping is the difference out of 256. - call FarBattleRNG + call BattleRandom swap a sub b jr c, .Nap @@ -862,7 +862,7 @@ BattleCommand02: ; 343db .Nap - call FarBattleRNG + call BattleRandom add a swap a and 7 @@ -876,7 +876,7 @@ BattleCommand02: ; 343db .DoNothing - call FarBattleRNG + call BattleRandom and 3 ; 'loafing around!' @@ -964,7 +964,7 @@ BattleCommand02: ; 343db .RandomMove - call FarBattleRNG + call BattleRandom and 3 cp b @@ -1324,7 +1324,7 @@ BattleCommand05: ; 34631 ld hl, .Chances ld b, 0 add hl, bc - call FarBattleRNG + call BattleRandom cp [hl] ret nc ld a, 1 @@ -2338,7 +2338,7 @@ BattleCommand08: ; 34cfd ; Multiply by 85-100%... .loop - call FarBattleRNG + call BattleRandom rrca cp $d9 ; 85% jr c, .loop @@ -2423,7 +2423,7 @@ BattleCommand09: ; 34d32 cp $ff jr z, .Hit - call FarBattleRNG + call BattleRandom cp b jr nc, .Miss @@ -2701,7 +2701,7 @@ BattleCommand90: ; 34ecc ld hl, EnemyMoveEffectChance .asm_34ee1 - call FarBattleRNG + call BattleRandom cp [hl] pop hl ret c @@ -2986,7 +2986,7 @@ BattleCommand0e: ; 3505e cp HELD_FOCUS_BAND ld b, $0 jr nz, .asm_3508b ; 3507a $f - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_3508b ; 35080 $9 call BattleCommand4b @@ -4332,7 +4332,7 @@ BattleCommand3f: ; 35726 add b ld b, a .asm_3575d - call FarBattleRNG + call BattleRandom and a jr z, .asm_3575d ; 35761 $fa cp b @@ -4555,7 +4555,7 @@ BattleCommand41: ; 35864 bit 4, [hl] jp nz, Function0x35923 set 4, [hl] - call FarBattleRNG + call BattleRandom and $3 inc a inc a @@ -4782,7 +4782,7 @@ BattleCommand44: ; 359e6 call SwitchTurn .asm_35a13 - call FarBattleRNG + call BattleRandom and $1f cp $a jr c, .asm_35a24 ; 35a1a $8 @@ -5005,7 +5005,7 @@ BattleCommand48: ; 35b33 dec hl .asm_35b62 push hl - call FarBattleRNG + call BattleRandom and $3 ld c, a ld b, $0 @@ -5173,7 +5173,7 @@ BattleCommand4a: ; 35c0f jr z, .asm_35c91 ; 35c46 $49 push bc call GetMoveName - call FarBattleRNG + call BattleRandom and $3 inc a inc a @@ -5576,7 +5576,7 @@ BattleCommand14: ; 35e5c ld b, $3 .asm_35ea4 - call FarBattleRNG + call BattleRandom and b jr z, .asm_35ea4 cp 7 @@ -5625,7 +5625,7 @@ Function0x35ece: ; 35ece bit 5, a jr nz, .asm_35eec - call FarBattleRNG + call BattleRandom cp $40 ret c @@ -5715,7 +5715,7 @@ BattleCommand2f: ; 35f2c ld a, [PlayerSubStatus5] bit 5, a jr nz, .asm_35f89 ; 35f80 $7 - call FarBattleRNG + call BattleRandom cp $40 jr c, .asm_35fb8 ; 35f87 $2f .asm_35f89 @@ -6375,7 +6375,7 @@ BattleCommand1d: ; 362e3 cp EFFECT_ACCURACY_DOWN_HIT jr z, .DidntMiss - call FarBattleRNG + call BattleRandom cp $40 jr c, .Failed @@ -6789,7 +6789,7 @@ BattleCommandac: ; 3658f ; 1/3 chance of each status .loop - call FarBattleRNG + call BattleRandom swap a and 3 jr z, .loop @@ -7043,7 +7043,7 @@ BattleCommand22: ; 366e5 ld [de], a ld [PlayerMoveEffect], a ld [EnemyMoveEffect], a - call FarBattleRNG + call BattleRandom and $1 inc a inc a @@ -7080,7 +7080,7 @@ BattleCommand3e: ; 3671a pop af jr nz, .asm_3674c ; 3673f $b set 7, [hl] - call FarBattleRNG + call BattleRandom and $1 inc a inc a @@ -7110,7 +7110,7 @@ BattleCommand3d: ; 36751 ld a, BATTLE_VARS_SUBSTATUS3 call GetBattleVarPair set 1, [hl] - call FarBattleRNG + call BattleRandom and $1 inc a ld [de], a @@ -7152,7 +7152,7 @@ BattleCommanda0: ; 36778 ld c, a inc c .asm_367ac - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_367ac ; 367b0 $fa srl b @@ -7177,7 +7177,7 @@ BattleCommanda0: ; 36778 ld c, a inc c .asm_367d2 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_367d2 ; 367d6 $fa srl b @@ -7242,7 +7242,7 @@ BattleCommand23: ; 3680f ld c, a inc c .asm_36845 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_36845 ; 36849 $fa srl b @@ -7282,7 +7282,7 @@ BattleCommand23: ; 3680f ld a, [CurOTMon] ld c, a .asm_3689a - call FarBattleRNG + call BattleRandom and $7 cp b jr nc, .asm_3689a ; 368a0 $f8 @@ -7332,7 +7332,7 @@ BattleCommand23: ; 3680f ld c, a inc c .asm_368e6 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_368e6 @@ -7378,7 +7378,7 @@ BattleCommand23: ; 3680f ld a, [CurBattleMon] ld c, a .asm_3693a - call FarBattleRNG + call BattleRandom and $7 cp b jr nc, .asm_3693a @@ -7496,7 +7496,7 @@ BattleCommand24: ; 369b6 cp EFFECT_TRIPLE_KICK jr nz, .asm_36a2b .asm_369ec - call FarBattleRNG + call BattleRandom and $3 jr z, .asm_369ec dec a @@ -7530,11 +7530,11 @@ BattleCommand24: ; 369b6 call BattleCommanda8 jp EndMoveEffect .asm_36a2b - call FarBattleRNG + call BattleRandom and $3 cp $2 jr c, .asm_36a39 ; 36a32 $5 - call FarBattleRNG + call BattleRandom and $3 .asm_36a39 inc a @@ -7670,7 +7670,7 @@ BattleCommand4d: ; 36ac9 ld d, h ld e, l call GetUserItem - call FarBattleRNG + call BattleRandom cp c ret nc call EndRechargeOpp @@ -7917,7 +7917,7 @@ BattleCommand3b: ; 36c2d call CleanGetBattleVarPair bit 4, a ret nz - call FarBattleRNG + call BattleRandom and 3 inc a inc a @@ -8116,7 +8116,7 @@ Function0x36d70: ; 36d70 .asm_36d7b set 7, [hl] - call FarBattleRNG + call BattleRandom and 3 inc a inc a @@ -8196,7 +8196,7 @@ BattleCommand30: ; 36dc7 ld a, [PlayerSubStatus5] bit 5, a jr nz, .asm_36e0e ; 36e05 $7 - call FarBattleRNG + call BattleRandom cp $40 jr c, .asm_36e52 ; 36e0c $44 .asm_36e0e @@ -8558,7 +8558,7 @@ BattleCommand37: ; 36fed and a jr z, .asm_37059 ; 3702c $2b .asm_3702e - call FarBattleRNG + call BattleRandom and $7 jr z, .asm_3702e ; 37033 $f9 inc a @@ -8677,7 +8677,7 @@ BattleCommand1f: ; 3707f call Function0x37e77 jp PrintButItFailed .asm_370d9 - call FarBattleRNG + call BattleRandom and $3 ld c, a ld b, $0 @@ -9235,7 +9235,7 @@ BattleCommand34: ; 37418 call Function0x37e36 .GetMove - call FarBattleRNG + call BattleRandom ; No invalid moves. cp BEAT_UP + 1 @@ -9596,7 +9596,7 @@ Function0x3762c: ; 3762c jr .asm_37665 .asm_37656 - call FarBattleRNG + call BattleRandom and a jr z, .asm_37656 @@ -10029,7 +10029,7 @@ BattleCommand61: ; 37874 and a jp nz, Function0x37e77 push bc - call FarBattleRNG + call BattleRandom ld b, a ld hl, .table_37907 ld c, 0 @@ -10186,7 +10186,7 @@ BattleCommand66: ; 37991 ; getmagnitude push bc - call FarBattleRNG + call BattleRandom ld b, a ld hl, .Magnitudes .asm_37999 diff --git a/engine/scripting.asm b/engine/scripting.asm index 61ebae935..d497f9a4e 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -1988,7 +1988,7 @@ Script_random: ; 0x97640 ld b, a .asm_97653 push bc - call RNG + call Random pop bc ld a, [$ffe1] cp b @@ -1996,7 +1996,7 @@ Script_random: ; 0x97640 jr .asm_97666 ; 0x9765d $7 .asm_9765f push bc - call RNG + call Random pop bc ld a, [$ffe1] .asm_97666 diff --git a/items/item_effects.asm b/items/item_effects.asm index cdca23be0..b060914db 100644 --- a/items/item_effects.asm +++ b/items/item_effects.asm @@ -166,7 +166,7 @@ ParkBall: ; e8a2 .asm_e98e ld b, a ld [MagikarpLength], a - call RNG + call Random cp b ld a, $0 diff --git a/main.asm b/main.asm index 18d94ab21..dfa5ed172 100644 --- a/main.asm +++ b/main.asm @@ -5570,49 +5570,50 @@ Function2f79: ; 2f79 ; 2f8c -RNG: ; 2f8c +Random: ; 2f8c +; A simple hardware-based random number generator (RNG). + ; Two random numbers are generated by adding and subtracting ; the divider to the respective values every time it's called. -; The divider is a value that increments at a rate of 16384Hz. +; The divider is a register that increments at a rate of 16384Hz. ; For comparison, the Game Boy operates at a clock speed of 4.2MHz. -; Additionally, an equivalent function is called every frame. +; Additionally, an equivalent function is executed in VBlank. -; output: -; a: rand2 -; ffe1: rand1 -; ffe2: rand2 +; This leaves a with the value in hRandomSub. push bc -; Added value + ld a, [rDIV] ld b, a ld a, [hRandomAdd] adc b ld [hRandomAdd], a -; Subtracted value + ld a, [rDIV] ld b, a ld a, [hRandomSub] sbc b ld [hRandomSub], a + pop bc ret ; 2f9f -FarBattleRNG: ; 2f9f -; BattleRNG lives in another bank. -; It handles all RNG calls in the battle engine, -; allowing link battles to remain in sync using a shared PRNG. +BattleRandom: ; 2f9f +; _BattleRandom lives in another bank. + +; It handles all RNG calls in the battle engine, allowing +; link battles to remain in sync using a shared PRNG. ; Save bank ld a, [hROMBank] ; bank push af ; Bankswitch - ld a, BANK(BattleRNG) + ld a, BANK(_BattleRandom) rst Bankswitch - call BattleRNG + call _BattleRandom ; Restore bank ld [$cfb6], a pop af @@ -5634,7 +5635,7 @@ Function2fb1: ; 2fb1 ld b, a push bc .asm_2fbb - call RNG + call Random ld a, [hRandomAdd] ld c, a add b @@ -10416,14 +10417,14 @@ Function4821: ; 4821 ; 4822 Function4822: ; 4822 - call RNG + call Random ld a, [hRandomAdd] and 1 jp Function4af0 ; 482c Function482c: ; 482c - call RNG + call Random ld a, [hRandomAdd] and 1 or 2 @@ -10431,14 +10432,14 @@ Function482c: ; 482c ; 4838 Function4838: ; 4838 - call RNG + call Random ld a, [hRandomAdd] and 3 jp Function4af0 ; 4842 Function4842: ; 4842 - call RNG + call Random ld a, [hRandomAdd] and $c ld hl, $0008 @@ -10453,7 +10454,7 @@ Function4851: ; 4851 ld a, [hl] and $c ld d, a - call RNG + call Random ld a, [hRandomAdd] and $c cp d @@ -10956,14 +10957,14 @@ Function4b17: ; 4b17 ; 4b1d Function4b1d: ; 4b1d - call RNG + call Random ld a, [hRandomAdd] and $7f jr Function4b2d ; 4b26 Function4b26: ; 4b26 - call RNG + call Random ld a, [hRandomAdd] and $1f ; fallthrough @@ -13248,10 +13249,10 @@ Function5bae: ; 5bae ld a, [hRandomAdd] ld [PlayerID + 1], a - call RNG + call Random ld [$d84a], a call DelayFrame - call RNG + call Random ld [$d84b], a ld hl, PartyCount @@ -13460,9 +13461,9 @@ Function5d33: ; 5d33 jr z, .asm_5d55 ld a, b ld [$ac68], a - call RNG + call Random ld c, a - call RNG + call Random .asm_5d55 ld [$dc9f], a @@ -15963,7 +15964,7 @@ DaycareStep: ; 7282 dec [hl] ret nz - call RNG + call Random ld [hl], a ld hl, $6e1d ld a, $5 @@ -15983,7 +15984,7 @@ DaycareStep: ; 7282 ld b, $a .asm_72f8 - call RNG + call Random cp b ret nc ld hl, DaycareMan @@ -16180,7 +16181,7 @@ Function7420: ; 7420 call GetCurNick call Function746e pop hl - call RNG + call Random .next sub [hl] jr c, .asm_7444 @@ -20995,9 +20996,9 @@ Functiond88c: ; d88c ld a, [IsInBattle] and a jr nz, .asm_d9f3 - call RNG + call Random ld b, a - call RNG + call Random ld c, a .asm_d9b5 @@ -22024,9 +22025,9 @@ Functione277: ; e277 call GetFarByte ld b, a ld hl, $ad2c - call RNG + call Random ld [hli], a - call RNG + call Random ld [hl], a call CloseSRAM ld a, $13 @@ -33725,7 +33726,7 @@ Function2a103: ; 2a103 call Function2a111 call Function2a124 call Function2a138 - call RNG + call Random cp b ret ; 2a111 @@ -33804,7 +33805,7 @@ Function2a14f: ; 2a14f .asm_2a174 push hl .asm_2a175 - call RNG + call Random cp 100 jr nc, .asm_2a175 inc a @@ -33828,7 +33829,7 @@ Function2a14f: ; 2a14f call Function1852 jr nz, .asm_2a1aa - call RNG + call Random cp 89 jr c, .asm_2a1aa inc b @@ -34073,7 +34074,7 @@ Function2a2ce: ; 2a2ce call Function1852 jr z, .asm_2a30a call Function2a27f - call RNG + call Random cp 100 jr nc, .asm_2a30a and 3 @@ -34182,7 +34183,7 @@ Function2a355: ; 2a355 .asm_2a36e ld h, d ld l, e - call RNG + call Random and $1f jr z, .asm_2a3cd and $3 @@ -34243,7 +34244,7 @@ Function2a355: ; 2a355 .asm_2a3cd ld hl, $640f .asm_2a3d0 - call RNG + call Random and $f cp $10 jr nc, .asm_2a3d0 @@ -34944,7 +34945,7 @@ Function2ed44: ; 2ed44 ld hl, StatusFlags2 bit 6, [hl] ret z - call RNG + call Random ld a, [hRandomAdd] and a ret nz @@ -34954,7 +34955,7 @@ Function2ed44: ; 2ed44 ld a, [PartyCount] ld b, a .asm_2ed70 - call RNG + call Random and $7 cp b jr nc, .asm_2ed70 @@ -34964,7 +34965,7 @@ Function2ed44: ; 2ed44 and $f0 ret nz .asm_2ed82 - call RNG + call Random and a jr z, .asm_2ed82 ld b, a @@ -34984,7 +34985,7 @@ Function2ed44: ; 2ed44 ret .asm_2ed9a - call RNG + call Random cp $55 ret nc ld a, [PartyCount] @@ -34994,7 +34995,7 @@ Function2ed44: ; 2ed44 ld a, b cp $2 jr c, .asm_2edc3 - call RNG + call Random cp $80 jr c, .asm_2edc3 .asm_2edb3 @@ -35047,7 +35048,7 @@ Function2ede6: ; 2ede6 ld hl, StatusFlags2 bit 6, [hl] ret z - call RNG + call Random cp $10 ret nc ld hl, PartyMons @@ -35505,7 +35506,7 @@ Function38045: ; 38045 jp z, Function38041 cp $10 jr nz, .asm_38061 - call RNG + call Random cp $80 jr c, .asm_38077 jp Function38041 @@ -35513,13 +35514,13 @@ Function38045: ; 38045 .asm_38061 cp $20 jr nz, .asm_3806f - call RNG + call Random cp $c8 jr c, .asm_38077 jp Function38041 .asm_3806f - call RNG + call Random cp $a jp c, Function38041 @@ -35538,7 +35539,7 @@ Function38083: ; 38083 jp z, Function38041 cp $10 jr nz, .asm_3809f - call RNG + call Random cp $14 jr c, .asm_380b5 jp Function38041 @@ -35546,13 +35547,13 @@ Function38083: ; 38083 .asm_3809f cp $20 jr nz, .asm_380ad - call RNG + call Random cp $1e jr c, .asm_380b5 jp Function38041 .asm_380ad - call RNG + call Random cp $c8 jp c, Function38041 @@ -35571,7 +35572,7 @@ Function380c1: ; 380c1 jp z, Function38041 cp $10 jr nz, .asm_380dd - call RNG + call Random cp $32 jr c, .asm_380f3 jp Function38041 @@ -35579,13 +35580,13 @@ Function380c1: ; 380c1 .asm_380dd cp $20 jr nz, .asm_380eb - call RNG + call Random cp $80 jr c, .asm_380f3 jp Function38041 .asm_380eb - call RNG + call Random cp $32 jp c, Function38041 @@ -36673,13 +36674,13 @@ Function3c314: ; 3c314 ld a, [$ffcb] cp $2 jr z, .asm_3c341 - call FarBattleRNG + call BattleRandom cp $80 jp c, $43f1 jp Function3c3f3 .asm_3c341 - call FarBattleRNG + call BattleRandom cp $80 jp c, Function3c3f3 jp $43f1 @@ -36711,7 +36712,7 @@ Function3c314: ; 3c314 ld a, b cp $4a jr z, .asm_3c39f - call FarBattleRNG + call BattleRandom cp e jr nc, .asm_3c3c5 jp $43f1 @@ -36720,7 +36721,7 @@ Function3c314: ; 3c314 ld a, b cp $4a jr nz, .asm_3c3c5 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_3c3c5 jp Function3c3f3 @@ -36729,19 +36730,19 @@ Function3c314: ; 3c314 ld a, [$ffcb] cp $2 jr z, .asm_3c3b5 - call FarBattleRNG + call BattleRandom cp c jp c, Function3c3f3 - call FarBattleRNG + call BattleRandom cp e jp c, $43f1 jr .asm_3c3c5 .asm_3c3b5 - call FarBattleRNG + call BattleRandom cp e jp c, $43f1 - call FarBattleRNG + call BattleRandom cp c jp c, Function3c3f3 jr .asm_3c3c5 @@ -36759,13 +36760,13 @@ Function3c314: ; 3c314 ld a, [$ffcb] cp $2 jr z, .asm_3c3e9 - call FarBattleRNG + call BattleRandom cp $80 jp c, $43f1 jp Function3c3f3 .asm_3c3e9 - call FarBattleRNG + call BattleRandom cp $80 jp c, Function3c3f3 scf @@ -36996,7 +36997,7 @@ Function3c543: ; 3c543 call IsInArray jr c, .Flee - call FarBattleRNG + call BattleRandom ld b, a cp $80 jr nc, .Stay @@ -37772,7 +37773,7 @@ Function3ca8f: ; 3ca8f ld a, [$c73f] and a ret nz - call FarBattleRNG + call BattleRandom cp $19 ret nc xor a @@ -37793,7 +37794,7 @@ Function3ca8f: ; 3ca8f ld a, [$c740] and a ret nz - call FarBattleRNG + call BattleRandom cp $19 ret nc xor a @@ -39731,7 +39732,7 @@ Function3d672: ; 3d672 .asm_3d6a7 ld a, [OTPartyCount] ld b, a - call FarBattleRNG + call BattleRandom and $7 cp b jr nc, .asm_3d6a7 @@ -40122,7 +40123,7 @@ Function3d8b3: ; 3d8b3 jr .asm_3d96c .asm_3d97a - call FarBattleRNG + call BattleRandom ld b, a ld a, [$ffb6] cp b @@ -42258,7 +42259,7 @@ Function3e7c1: ; 3e7c1 jr nz, .asm_3e882 .asm_3e855 ld hl, EnemyMonMove1 - call FarBattleRNG + call BattleRandom and $3 ld c, a ld b, $0 @@ -42360,7 +42361,7 @@ LoadEnemyMon: ; 3e8eb ; To do this we pull the species from TempEnemyMonSpecies ; Notes: -; FarBattleRNG is used to ensure sync between Game Boys +; BattleRandom is used to ensure sync between Game Boys ; Clear the whole EnemyMon struct xor a @@ -42419,13 +42420,13 @@ LoadEnemyMon: ; 3e8eb ; 2% Item2 ; 25% chance of getting an item - call FarBattleRNG + call BattleRandom cp a, $c0 ld a, NO_ITEM jr c, .UpdateItem ; From there, an 8% chance for Item2 - call FarBattleRNG + call BattleRandom cp a, $14 ; 8% of 25% = 2% Item2 ld a, [BaseItems] jr nc, .UpdateItem @@ -42505,10 +42506,10 @@ LoadEnemyMon: ; 3e8eb ; (HP is initialized at the end of the battle) call GetRoamMonDVs inc hl - call FarBattleRNG + call BattleRandom ld [hld], a ld c, a - call FarBattleRNG + call BattleRandom ld [hl], a ld b, a ; We're done with DVs @@ -42529,9 +42530,9 @@ LoadEnemyMon: ; 3e8eb .GenerateDVs ; Generate new random DVs - call FarBattleRNG + call BattleRandom ld b, a - call FarBattleRNG + call BattleRandom ld c, a .UpdateDVs @@ -42584,7 +42585,7 @@ LoadEnemyMon: ; 3e8eb jr nz, .CheckMagikarpArea ; 5% chance of skipping size checks - call RNG + call Random cp a, $0c ; / $100 jr c, .CheckMagikarpArea ; Try again if > 1614 @@ -42593,7 +42594,7 @@ LoadEnemyMon: ; 3e8eb jr nc, .GenerateDVs ; 20% chance of skipping this check - call RNG + call Random cp a, $32 ; / $100 jr c, .CheckMagikarpArea ; Try again if > 1598 @@ -42618,7 +42619,7 @@ LoadEnemyMon: ; 3e8eb cp a, MAP_LAKE_OF_RAGE jr z, .Happiness ; 40% chance of not flooring - call RNG + call Random cp a, $64 ; / $100 jr c, .Happiness ; Floor at length 1024 @@ -43389,14 +43390,14 @@ EmptyBattleTextBox: ; 3edd1 ; 3edd8 -BattleRNG: ; 3edd8 +_BattleRandom: ; 3edd8 ; If the normal RNG is used in a link battle it'll desync. ; To circumvent this a shared PRNG is used instead. ; But if we're in a non-link battle we're safe to use it ld a, [InLinkBattle] and a - jp z, RNG + jp z, Random ; The PRNG operates in streams of 10 values. @@ -45208,7 +45209,7 @@ Function3f998: ; 3f998 ret .asm_3f9c4 - call FarBattleRNG + call BattleRandom and $f ret nz @@ -47147,7 +47148,7 @@ AIChooseMove: ; 440ce .asm_44197 ld hl, Buffer1 - call RNG + call Random and 3 ld c, a ld b, 0 @@ -59827,7 +59828,7 @@ Function97d23: ; 97d23 Function97d31: ; 97d31 .asm_97d31 - call RNG + call Random cp 100 << 1 jr nc, .asm_97d31 srl a @@ -59854,7 +59855,7 @@ Function97d31: ; 97d31 .asm_97d54 ld c, a inc c - call RNG + call Random ld a, [hRandomAdd] call SimpleDivide add d @@ -59879,7 +59880,7 @@ Function97d64: ; 97d64 ld a, $a ld hl, $6138 rst FarCall - call RNG + call Random ld a, [hRandomAdd] cp b ret c diff --git a/stats/battle_tower.asm b/stats/battle_tower.asm index cda7195da..044f351f8 100644 --- a/stats/battle_tower.asm +++ b/stats/battle_tower.asm @@ -15,7 +15,7 @@ Function1f8000: ; 1f8000 ld a, [hRandomAdd] ld b, a .asm_1f8022 - call RNG + call Random ld a, [hRandomAdd] add b ld b, a @@ -83,7 +83,7 @@ Function1f8081: ; 1f8081 ld a, [hRandomAdd] ld b, a .asm_1f8099 - call RNG + call Random ld a, [hRandomAdd] add b ld b, a diff --git a/stats/odd_eggs.asm b/stats/odd_eggs.asm index 243f77434..6922a2de7 100644 --- a/stats/odd_eggs.asm +++ b/stats/odd_eggs.asm @@ -1,7 +1,7 @@ GiveOddEgg: ; 1fb4b6 ; Figure out which egg to give. - call RNG + call Random ld hl, .Probabilities ld c, 0 ld b, c diff --git a/stats/wild/fish.asm b/stats/wild/fish.asm index 75f49d6c4..44a30a0b2 100644 --- a/stats/wild/fish.asm +++ b/stats/wild/fish.asm @@ -39,7 +39,7 @@ Fish: ; 9241a ; Fish for monsters with rod b from encounter data in FishGroup at hl. ; Return monster e at level d. - call RNG + call Random ; Got a bite? cp [hl] @@ -59,7 +59,7 @@ Fish: ; 9241a ld l, a ; Encounter chance for this monster: - call RNG + call Random .CheckEncounter cp [hl] From c402a16def99bad3df047d570120d1f1da1abbc3 Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 23:03:15 -0400 Subject: [PATCH 77/96] undo overcommenting in BattleRandom these comments made sense before hram and rst constants were established --- main.asm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.asm b/main.asm index dfa5ed172..64ec02a0c 100644 --- a/main.asm +++ b/main.asm @@ -5607,14 +5607,13 @@ BattleRandom: ; 2f9f ; It handles all RNG calls in the battle engine, allowing ; link battles to remain in sync using a shared PRNG. -; Save bank - ld a, [hROMBank] ; bank + ld a, [hROMBank] push af -; Bankswitch ld a, BANK(_BattleRandom) rst Bankswitch + call _BattleRandom -; Restore bank + ld [$cfb6], a pop af rst Bankswitch From b333b18dbde658cd7e4299f8206d1d52c532b87a Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 30 Aug 2013 23:07:08 -0400 Subject: [PATCH 78/96] Function2f79 is PickUpItem --- engine/scripting.asm | 2 +- main.asm | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index d497f9a4e..5d44d1a8e 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -2363,7 +2363,7 @@ Script_checkitem: ; 0x97812 call GetScriptByte ld [$d106], a ld hl, $d892 - call Function2f79 + call PickUpItem ret nc ld a, $1 ld [$c2dd], a diff --git a/main.asm b/main.asm index 64ec02a0c..0b848c4e0 100644 --- a/main.asm +++ b/main.asm @@ -5549,20 +5549,20 @@ Function2f66: ; 2f66 ret ; 2f79 -Function2f79: ; 2f79 +PickUpItem: ; 2f79 push hl push de push bc ld a, [hROMBank] push af - ld a, BANK(Functiond244) + ld a, BANK(_PickUpItem) rst Bankswitch - call Functiond244 + call _PickUpItem + pop bc ld a, b rst Bankswitch - pop bc pop de pop hl @@ -20275,7 +20275,7 @@ Functiond20d: ; d20d jp Functiond2ff ; d244 -Functiond244: ; d244 +_PickUpItem: ; d244 call Functiond27b jr nz, .asm_d278 push hl @@ -32235,7 +32235,7 @@ Function24c64: ; 24c64 push hl ld [CurItem], a ld hl, NumItems - call Function2f79 + call PickUpItem pop hl jr nc, .asm_24c89 ld a, [hl] @@ -55485,7 +55485,7 @@ Function8adef: ; 8adef ld a, WATER_STONE ld [CurItem], a ld hl, NumItems - call Function2f79 + call PickUpItem jr c, .asm_8ae24 ld a, [PartyCount] From 2acccc3ea5d5ebdd54cddc6cb7a3c888428be286 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 31 Aug 2013 03:54:02 -0400 Subject: [PATCH 79/96] rename FarBattleTextBox to StdBattleTextBox that's it for bad Far usage --- battle/effect_commands.asm | 260 ++++++++++++++++++------------------- items/item_effects.asm | 2 +- main.asm | 118 ++++++++--------- 3 files changed, 191 insertions(+), 189 deletions(-) diff --git a/battle/effect_commands.asm b/battle/effect_commands.asm index 62c715d40..94b54c0bd 100644 --- a/battle/effect_commands.asm +++ b/battle/effect_commands.asm @@ -154,7 +154,7 @@ CheckPlayerTurn: ; 'must recharge!' ld hl, MustRechargeText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -179,7 +179,7 @@ CheckPlayerTurn: .WokeUp ; 'woke up!' ld hl, WokeUpText - call FarBattleTextBox + call StdBattleTextBox call CantMove call UpdateBattleMonInParty @@ -195,7 +195,7 @@ CheckPlayerTurn: .FastAsleep ; 'fast asleep!' ld hl, FastAsleepText - call FarBattleTextBox + call StdBattleTextBox ; Snore and Sleep Talk bypass sleep. ld a, [CurPlayerMove] @@ -221,7 +221,7 @@ CheckPlayerTurn: ; 'frozen solid!' ld hl, FrozenSolidText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -236,7 +236,7 @@ CheckPlayerTurn: ; 'flinched!' ld hl, FlinchedText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -256,7 +256,7 @@ CheckPlayerTurn: ; 'disabled no more!' ld hl, DisabledNoMoreText - call FarBattleTextBox + call StdBattleTextBox .CheckConfused @@ -272,7 +272,7 @@ CheckPlayerTurn: ; 'confused no more!' ld hl, ConfusedNoMoreText - call FarBattleTextBox + call StdBattleTextBox jr .CheckAttract @@ -280,7 +280,7 @@ CheckPlayerTurn: .Confused ; 'confused!' ld hl, IsConfusedText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -310,7 +310,7 @@ CheckPlayerTurn: ; 'in love with' ld hl, InLoveWithText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -325,7 +325,7 @@ CheckPlayerTurn: ; 'infatuation kept it from attacking!' ld hl, InfatuationText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -359,7 +359,7 @@ CheckPlayerTurn: ; 'fully paralyzed!' ld hl, FullyParalyzedText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 ; 341f0 @@ -412,7 +412,7 @@ CheckEnemyTurn: ; 3421f ; 'must recharge!' ld hl, MustRechargeText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -429,7 +429,7 @@ CheckEnemyTurn: ; 3421f ; 'fast asleep!' ld hl, FastAsleepText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a ld de, ANIM_SLEEP @@ -440,7 +440,7 @@ CheckEnemyTurn: ; 3421f .WokeUp ; 'woke up!' ld hl, WokeUpText - call FarBattleTextBox + call StdBattleTextBox call CantMove call UpdateEnemyMonInParty ld hl, $6036 @@ -475,7 +475,7 @@ CheckEnemyTurn: ; 3421f ; 'frozen solid!' ld hl, FrozenSolidText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -489,7 +489,7 @@ CheckEnemyTurn: ; 3421f ; 'flinched!' ld hl, FlinchedText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -511,7 +511,7 @@ CheckEnemyTurn: ; 3421f ; 'disabled no more!' ld hl, DisabledNoMoreText - call FarBattleTextBox + call StdBattleTextBox .CheckConfused @@ -528,7 +528,7 @@ CheckEnemyTurn: ; 3421f ; 'confused no more!' ld hl, ConfusedNoMoreText - call FarBattleTextBox + call StdBattleTextBox jr .CheckAttract @@ -536,7 +536,7 @@ CheckEnemyTurn: ; 3421f .Confused ; 'confused!' ld hl, IsConfusedText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -555,7 +555,7 @@ CheckEnemyTurn: ; 3421f ; 'hurt itself in its confusion!' ld hl, HurtItselfText - call FarBattleTextBox + call StdBattleTextBox call Function0x355dd @@ -589,7 +589,7 @@ CheckEnemyTurn: ; 3421f ; 'in love with' ld hl, InLoveWithText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -604,7 +604,7 @@ CheckEnemyTurn: ; 3421f ; 'infatuation kept it from attacking!' ld hl, InfatuationText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -639,7 +639,7 @@ CheckEnemyTurn: ; 3421f ; 'fully paralyzed!' ld hl, FullyParalyzedText - call FarBattleTextBox + call StdBattleTextBox call CantMove @@ -668,7 +668,7 @@ MoveDisabled: ; 3438d ; 'disabled!' ld hl, DisabledMoveText - jp FarBattleTextBox + jp StdBattleTextBox ; 343a5 @@ -676,7 +676,7 @@ HitConfusion: ; 343a5 ; 'hurt itself in its confusion!' ld hl, HurtItselfText - call FarBattleTextBox + call StdBattleTextBox xor a ld [CriticalHit], a @@ -854,7 +854,7 @@ BattleCommand02: ; 343db ; 'won't obey!' ld hl, WontObeyText - call FarBattleTextBox + call StdBattleTextBox call HitConfusion @@ -898,7 +898,7 @@ BattleCommand02: ; 343db ld hl, IgnoredOrdersText .Print - call FarBattleTextBox + call StdBattleTextBox jp Function0x3450c @@ -1043,7 +1043,7 @@ IgnoreSleepOnly: ; 3451f ; 'ignored orders…sleeping!' ld hl, IgnoredSleepingText - call FarBattleTextBox + call StdBattleTextBox call EndMoveEffect @@ -1192,7 +1192,7 @@ BattleCommand04: ; 34555 ; 'but no pp is left for the move' ld hl, NoPPLeftText .print - call FarBattleTextBox + call StdBattleTextBox ld b, 1 ret ; 34602 @@ -2471,7 +2471,7 @@ BattleCommand09: ; 34d32 ; 'protecting itself!' ld hl, ProtectingItselfText - call FarBattleTextBox + call StdBattleTextBox ld c, 40 call DelayFrames @@ -3014,7 +3014,7 @@ BattleCommand0e: ; 3505e dec a jr nz, .asm_350ab ; 350a3 $6 ld hl, EnduredText - jp FarBattleTextBox + jp StdBattleTextBox .asm_350ab call GetOpponentItem @@ -3023,7 +3023,7 @@ BattleCommand0e: ; 3505e call GetItemName ld hl, HungOnText - jp FarBattleTextBox + jp StdBattleTextBox .asm_50bb ld a, BATTLE_VARS_SUBSTATUS4_OPP @@ -3105,7 +3105,7 @@ Function0x350e4: ; 350e4 ld [hl], a .asm_3513e ld hl, CrashedText - call FarBattleTextBox + call StdBattleTextBox ld a, $1 ld [$c689], a call Function0x37e36 @@ -3123,7 +3123,7 @@ Function0x35157: ; 35157 ld h, d ld l, e .asm_35162 - jp FarBattleTextBox + jp StdBattleTextBox ; 35165 @@ -3157,7 +3157,7 @@ BattleCommand0f: ; 35175 ld a, [hli] ld h, [hl] ld l, a - call FarBattleTextBox + call StdBattleTextBox xor a ld [CriticalHit], a @@ -3211,7 +3211,7 @@ BattleCommand10: ; 351ad jr nc, .print ld hl, NotVeryEffectiveText ; 'not very effective' .print - jp FarBattleTextBox + jp StdBattleTextBox ; 351c0 @@ -3237,7 +3237,7 @@ BattleCommand11: ; 351c0 jr z, .asm_35231 ld hl, TookDownWithItText - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a @@ -3332,7 +3332,7 @@ BattleCommand12: ; 35250 call SwitchTurn ld hl, RageBuildingText - call FarBattleTextBox + call StdBattleTextBox jp SwitchTurn ; 3527b @@ -3822,7 +3822,7 @@ BattleCommanda1: ; 35461 ld a, $1 ld [$c72d], a ld hl, BeatUpAttackText - call FarBattleTextBox + call StdBattleTextBox ld a, [EnemyMonSpecies] ld [CurSpecies], a call $3856 @@ -3923,11 +3923,11 @@ BattleCommanda1: ; 35461 ld [$d265], a call $343b ld hl, BeatUpAttackText - call FarBattleTextBox + call StdBattleTextBox jp EnemyAttackDamage .asm_3557d ld hl, BeatUpAttackText - call FarBattleTextBox + call StdBattleTextBox ld a, [BattleMonSpecies] ld [CurSpecies], a call GetBaseData @@ -4626,7 +4626,7 @@ BattleCommand41: ; 35864 call Function0x37e01 ld hl, GotAnEncoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 35923 @@ -4673,7 +4673,7 @@ BattleCommand42: ; 35926 rst FarCall ld hl, SharedPainText - jp FarBattleTextBox + jp StdBattleTextBox .asm_3597d ld a, [hld] @@ -4815,7 +4815,7 @@ BattleCommand44: ; 359e6 ld a, $29 call Predef ld hl, $5452 - jp FarBattleTextBox + jp StdBattleTextBox .asm_35a50 jp Function0x37354 ; 35a53 @@ -4835,7 +4835,7 @@ BattleCommand45: ; 35a53 call Function0x37e01 ld hl, TookAimText - jp FarBattleTextBox + jp StdBattleTextBox .asm_35a6e call Function0x37e77 @@ -4938,7 +4938,7 @@ BattleCommand46: ; 35a74 call Function0x37e01 ld hl, SketchedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_35b10 call Function0x37e77 @@ -5131,7 +5131,7 @@ BattleCommand49: ; 35bff set 6, [hl] call Function0x37e01 ld hl, DestinyBondEffectText - jp FarBattleTextBox + jp StdBattleTextBox ; 35c0f @@ -5216,7 +5216,7 @@ BattleCommand4a: ; 35c0f ld a, d ld [$d265], a ld hl, SpiteEffectText - jp FarBattleTextBox + jp StdBattleTextBox .asm_35c91 jp PrintDidntAffect2 ; 35c94 @@ -5294,7 +5294,7 @@ BattleCommand4c: ; 35cc9 call Function0x37e01 ld hl, BellChimedText - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a @@ -5452,7 +5452,7 @@ Function0x35d7e: ; 35d7e Function0x35de0: ; 35de0 ld hl, SubTookDamageText - call FarBattleTextBox + call StdBattleTextBox ld de, $c6e0 ld a, [hBattleTurn] @@ -5479,7 +5479,7 @@ Function0x35de0: ; 35de0 res 4, [hl] ld hl, SubFadedText - call FarBattleTextBox + call StdBattleTextBox call SwitchTurn call BattleCommanda7 @@ -5587,7 +5587,7 @@ BattleCommand14: ; 35e5c call RefreshBattleHuds ld hl, FellAsleepText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -5600,7 +5600,7 @@ BattleCommand14: ; 35e5c push hl call Function0x37e77 pop hl - jp FarBattleTextBox + jp StdBattleTextBox ; 35ece @@ -5664,7 +5664,7 @@ BattleCommand13: ; 35eee call RefreshBattleHuds ld hl, WasPoisonedText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -5729,7 +5729,7 @@ BattleCommand2f: ; 35f2c call Function0x35fc0 ld hl, WasPoisonedText - call FarBattleTextBox + call StdBattleTextBox jr .asm_35fb1 ; 35fa2 $d .asm_35fa4 @@ -5739,7 +5739,7 @@ BattleCommand2f: ; 35f2c call Function0x35fc0 ld hl, BadlyPoisonedText - call FarBattleTextBox + call StdBattleTextBox .asm_35fb1 ld a, $f @@ -5751,7 +5751,7 @@ BattleCommand2f: ; 35f2c push hl call Function0x37e77 pop hl - jp FarBattleTextBox + jp StdBattleTextBox ; 35fc0 @@ -5807,7 +5807,7 @@ BattleCommand15: ; 35fff ; draintarget call Function0x36011 ld hl, SuckedHealthText - jp FarBattleTextBox + jp StdBattleTextBox ; 36008 @@ -5815,7 +5815,7 @@ BattleCommand16: ; 36008 ; eatdream call Function0x36011 ld hl, DreamEatenText - jp FarBattleTextBox + jp StdBattleTextBox ; 36011 @@ -5938,7 +5938,7 @@ BattleCommand17: ; 3608c call RefreshBattleHuds ld hl, WasBurnedText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -5970,7 +5970,7 @@ Defrost: ; 360dd call UpdateOpponentInParty ld hl, DefrostedOpponentText - jp FarBattleTextBox + jp StdBattleTextBox ; 36102 @@ -6011,7 +6011,7 @@ BattleCommand18: ; 36102 call RefreshBattleHuds ld hl, WasFrozenText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -6596,7 +6596,7 @@ BattleCommand8e: ; 3644c inc b call GetStatName ld hl, WontRiseAnymoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 3646a @@ -6612,14 +6612,14 @@ BattleCommand8f: ; 3646a jp z, TryPrintButItFailed dec a ld hl, ProtectedByMistText - jp z, FarBattleTextBox + jp z, StdBattleTextBox ld a, [LoweredStat] and $f ld b, a inc b call GetStatName ld hl, WontDropAnymoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 3648f @@ -6972,7 +6972,7 @@ BattleCommand21: ; 36671 res 0, [hl] ld hl, UnleashedEnergyText - call FarBattleTextBox + call StdBattleTextBox ld a, BATTLE_VARS_MOVE_POWER call GetBattleVarPair @@ -7018,7 +7018,7 @@ BattleCommand21: ; 36671 .asm_366dc ld hl, StoringEnergyText - call FarBattleTextBox + call StdBattleTextBox jp EndMoveEffect ; 366e5 @@ -7199,7 +7199,7 @@ BattleCommanda0: ; 36778 call Function0x36804 ld hl, FledFromBattleText - jp FarBattleTextBox + jp StdBattleTextBox ; 36804 @@ -7305,7 +7305,7 @@ BattleCommand23: ; 3680f rst FarCall ld hl, DraggedOutText - call FarBattleTextBox + call StdBattleTextBox ld hl, $5c23 jp CallBankF @@ -7402,7 +7402,7 @@ BattleCommand23: ; 3680f call CallBankF ld hl, DraggedOutText - call FarBattleTextBox + call StdBattleTextBox ld hl, $5c23 jp CallBankF @@ -7428,7 +7428,7 @@ BattleCommand23: ; 3680f jr z, .asm_36991 ld hl, BlownAwayText .asm_36991 - jp FarBattleTextBox + jp StdBattleTextBox ; 36994 @@ -7569,7 +7569,7 @@ BattleCommand24: ; 369b6 call CleanGetBattleVarPair cp EFFECT_BEAT_UP jr z, .asm_36a67 - call FarBattleTextBox + call StdBattleTextBox .asm_36a67 pop bc @@ -7767,7 +7767,7 @@ BattleCommand39: ; 36b4d ld hl, IgnoredOrders2Text ld a, [AlreadyDisobeyed] and a - call nz, FarBattleTextBox + call nz, StdBattleTextBox call BattleCommand0a xor a @@ -7941,7 +7941,7 @@ BattleCommand3b: ; 36c2d ld a, [hli] ld h, [hl] ld l, a - jp FarBattleTextBox + jp StdBattleTextBox .Traps dbw BIND, UsedBindText ; 'used BIND on' @@ -7962,7 +7962,7 @@ BattleCommand28: ; 36c7e set 1, [hl] call Function0x37e01 ld hl, MistText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36c92 call Function0x37e77 jp PrintButItFailed @@ -7979,7 +7979,7 @@ BattleCommand29: ; 36c98 set 2, [hl] call Function0x37e01 ld hl, GettingPumpedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36cac call Function0x37e77 jp PrintButItFailed @@ -8048,7 +8048,7 @@ BattleCommand27: ; 36cb2 call Predef call RefreshBattleHuds ld hl, RecoilText - jp FarBattleTextBox + jp StdBattleTextBox ; 36d1d @@ -8085,7 +8085,7 @@ BattleCommand2a: ; 36d3b call GetItemName call Function0x37e77 ld hl, ProtectedByText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36d53 ld a, BATTLE_VARS_SUBSTATUS3_OPP @@ -8094,7 +8094,7 @@ BattleCommand2a: ; 36d3b jr z, .asm_36d65 call Function0x37e77 ld hl, AlreadyConfusedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36d65 call CheckSubstituteOpp @@ -8137,7 +8137,7 @@ Function0x36d70: ; 36d70 call Function0x37e54 ld hl, BecameConfusedText - call FarBattleTextBox + call StdBattleTextBox call GetOpponentItem ld a, b @@ -8182,7 +8182,7 @@ BattleCommand30: ; 36dc7 call GetItemName call Function0x37e77 ld hl, ProtectedByText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36def ld a, [hBattleTurn] and a @@ -8227,7 +8227,7 @@ BattleCommand30: ; 36dc7 .asm_36e49 call Function0x37e77 ld hl, AlreadyParalyzedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36e52 jp PrintDidntAffect2 .asm_36e55 @@ -8338,7 +8338,7 @@ BattleCommand31: ; 36e7c call BattleCommanda6 .asm_36eeb ld hl, MadeSubstituteText - call FarBattleTextBox + call StdBattleTextBox jp RefreshBattleHuds .asm_36ef4 call Function0x34548 @@ -8350,7 +8350,7 @@ BattleCommand31: ; 36e7c call nz, BattleCommand0c ld hl, TooWeakSubText .asm_36f08 - jp FarBattleTextBox + jp StdBattleTextBox ; 36f0b BattleCommand32: ; 36f0b @@ -8463,7 +8463,7 @@ BattleCommand33: ; 36f46 call GetMoveName call Function0x37e01 ld hl, LearnedMoveText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36f9a jp Function0x37357 ; 36f9d @@ -8496,14 +8496,14 @@ BattleCommand35: ; 36f9d set 7, [hl] call Function0x37e01 ld hl, WasSeededText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36fd2 call Function0x37e77 jp PrintDoesntAffect .asm_36fd8 call Function0x37e77 ld hl, EvadedText - jp FarBattleTextBox + jp StdBattleTextBox ; 36fe1 @@ -8579,7 +8579,7 @@ BattleCommand37: ; 36fed ld [$d265], a call GetMoveName ld hl, WasDisabledText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37059 jp Function0x37354 ; 3705c @@ -8608,7 +8608,7 @@ BattleCommand1e: ; 3705c inc [hl] .asm_37079 ld hl, CoinsScatteredText - jp FarBattleTextBox + jp StdBattleTextBox ; 3707f @@ -8706,7 +8706,7 @@ BattleCommand1f: ; 3707f rst FarCall call Function0x37e01 ld hl, TransformedTypeText - jp FarBattleTextBox + jp StdBattleTextBox ; 3710e @@ -8733,7 +8733,7 @@ BattleCommand20: ; 3710e call Function0x37e01 ld hl, EliminatedStatsText - jp FarBattleTextBox + jp StdBattleTextBox .Fill ld b, PlayerStatLevelsEnd - PlayerStatLevels @@ -8787,7 +8787,7 @@ BattleCommand2c: ; 3713e jr z, .asm_37186 ; 37181 $3 ld hl, RestedText .asm_37186 - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a jr nz, .asm_37193 ; 3718c $5 @@ -8816,12 +8816,12 @@ BattleCommand2c: ; 3713e call UpdateUserInParty call RefreshBattleHuds ld hl, RegainedHealthText - jp FarBattleTextBox + jp StdBattleTextBox .asm_371c4 call Function0x37e77 ld hl, HPIsFullText - jp FarBattleTextBox + jp StdBattleTextBox ; 371cd @@ -8958,7 +8958,7 @@ BattleCommand2d: ; 371cd ld a, $a4 call nz, Function0x37e44 ld hl, TransformedText - jp FarBattleTextBox + jp StdBattleTextBox ; 372c6 @@ -9056,7 +9056,7 @@ BattleCommand2e: ; 372fc .asm_37331 call Function0x37e01 - jp FarBattleTextBox + jp StdBattleTextBox .asm_37337 call Function0x37e77 @@ -9067,14 +9067,14 @@ BattleCommand2e: ; 372fc PrintDoesntAffect: ; 3733d ; 'it doesn't affect' ld hl, DoesntAffectText - jp FarBattleTextBox + jp StdBattleTextBox ; 37343 PrintNothingHappened: ; 37343 ; 'but nothing happened!' ld hl, NothingHappenedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37349 @@ -9090,7 +9090,7 @@ TryPrintButItFailed: ; 37349 PrintButItFailed: ; 3734e ; 'but it failed!' ld hl, ButItFailedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37354 @@ -9109,7 +9109,7 @@ Function0x37357: ; 37357 PrintDidntAffect: ; 37360 ; 'it didn't affect' ld hl, DidntAffect1Text - jp FarBattleTextBox + jp StdBattleTextBox ; 37366 @@ -9124,7 +9124,7 @@ PrintDidntAffect2: ; 37366 PrintParalyze: ; 37372 ; 'paralyzed! maybe it can't attack!' ld hl, ParalyzedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37378 @@ -9189,7 +9189,7 @@ BattleCommand1b: ; 373c9 .asm_373de call Function0x37e77 ld hl, MirrorMoveFailedText - call FarBattleTextBox + call StdBattleTextBox jp EndMoveEffect .asm_373ea ld a, b @@ -9391,7 +9391,7 @@ BattleCommand50: ; 37492 .asm_374f8 call GetItemName ld hl, StoleText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37501 ld a, 1 @@ -9422,7 +9422,7 @@ BattleCommand51: ; 37517 set 7, [hl] call Function0x37e01 ld hl, CantEscapeNowText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37530 call Function0x37e77 jp PrintButItFailed @@ -9447,7 +9447,7 @@ BattleCommand52: ; 37536 set 0, [hl] call Function0x37e01 ld hl, StartedNightmareText - jp FarBattleTextBox + jp StdBattleTextBox .asm_3755d call Function0x37e77 jp PrintButItFailed @@ -9475,7 +9475,7 @@ BattleCommand53: ; 37563 .asm_3757f call RefreshBattleHuds ld hl, WasDefrostedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37588 @@ -9536,7 +9536,7 @@ BattleCommand54: ; 37588 call CallBankF call UpdateUserInParty ld hl, PutACurseText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37604 call Function0x37e77 jp PrintButItFailed @@ -9545,7 +9545,7 @@ BattleCommand54: ; 37588 call GetStatName call Function0x37e77 ld hl, WontRiseAnymoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 37618 @@ -9559,7 +9559,7 @@ BattleCommand55: ; 37618 set 2, [hl] call Function0x37e01 ld hl, ProtectedItselfText - jp FarBattleTextBox + jp StdBattleTextBox ; 3762c @@ -9631,7 +9631,7 @@ BattleCommand5a: ; 3766f set SUBSTATUS_ENDURE, [hl] call Function0x37e01 ld hl, BracedItselfText - jp FarBattleTextBox + jp StdBattleTextBox ; 37683 @@ -9651,7 +9651,7 @@ BattleCommand56: ; 37683 set 0, [hl] call Function0x37e01 ld hl, SpikesText - jp FarBattleTextBox + jp StdBattleTextBox .failed jp Function0x37354 @@ -9673,7 +9673,7 @@ BattleCommand57: ; 376a0 set SUBSTATUS_IDENTIFIED, [hl] call Function0x37e01 ld hl, IdentifiedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_376bf jp Function0x37354 ; 376c2 @@ -9706,7 +9706,7 @@ BattleCommand58: ; 376c2 .asm_376e9 call Function0x37e01 ld hl, StartPerishText - jp FarBattleTextBox + jp StdBattleTextBox .asm_376f2 call Function0x37e77 jp PrintButItFailed @@ -9725,7 +9725,7 @@ BattleCommand59: ; 376f8 ld [WeatherCount], a call Function0x37e01 ld hl, SandstormBrewedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37712 call Function0x37e77 jp PrintButItFailed @@ -9911,7 +9911,7 @@ BattleCommand5f: ; 377ce ; 'fell in love!' ld hl, FellInLoveText - jp FarBattleTextBox + jp StdBattleTextBox .asm_377f2 jp Function0x37354 @@ -10071,7 +10071,7 @@ BattleCommand61: ; 37874 call CallBankF call SwitchTurn ld hl, RegainedHealthText - call FarBattleTextBox + call StdBattleTextBox call SwitchTurn call UpdateOpponentInParty jr .asm_37904 ; 378f1 $11 @@ -10081,7 +10081,7 @@ BattleCommand61: ; 37874 jr nc, .asm_37904 ; 378f9 $9 call Function0x37e77 ld hl, RefusedGiftText - call FarBattleTextBox + call StdBattleTextBox .asm_37904 jp EndMoveEffect @@ -10141,7 +10141,7 @@ BattleCommand64: ; 37939 ld [de], a call Function0x37e01 ld hl, CoveredByVeilText - jp FarBattleTextBox + jp StdBattleTextBox .asm_3795c call Function0x37e77 jp PrintButItFailed @@ -10177,7 +10177,7 @@ BattleCommand65: ; 37972 ld [AttackMissed], a call BattleCommandaa ld hl, SafeguardProtectText - call FarBattleTextBox + call StdBattleTextBox jp EndMoveEffect ; 37991 @@ -10204,7 +10204,7 @@ BattleCommand66: ; 37991 ld [$d265], a call BattleCommandaa ld hl, MagnitudeText - call FarBattleTextBox + call StdBattleTextBox pop de pop bc ret @@ -10485,7 +10485,7 @@ BattleCommand69: ; 37b39 jr z, .asm_37b4a ; 37b40 $8 res 7, [hl] ld hl, ShedLeechSeedText - call FarBattleTextBox + call StdBattleTextBox .asm_37b4a ld hl, PlayerScreens ld de, $c730 @@ -10500,7 +10500,7 @@ BattleCommand69: ; 37b39 res 0, [hl] ld hl, BlewSpikesText push de - call FarBattleTextBox + call StdBattleTextBox pop de .asm_37b69 ld a, [de] @@ -10509,7 +10509,7 @@ BattleCommand69: ; 37b39 xor a ld [de], a ld hl, ReleasedByText - jp FarBattleTextBox + jp StdBattleTextBox ; 37b74 @@ -10600,14 +10600,14 @@ BattleCommand6a6c: ; 37b7e ; 'regained health!' ld hl, RegainedHealthText - jp FarBattleTextBox + jp StdBattleTextBox .Full call Function0x37e77 ; 'hp is full!' ld hl, HPIsFullText - jp FarBattleTextBox + jp StdBattleTextBox .Multipliers dw GetEighthMaxHP @@ -10636,7 +10636,7 @@ BattleCommand6e: ; 37bf4 ld [WeatherCount], a call Function0x37e01 ld hl, DownpourText - jp FarBattleTextBox + jp StdBattleTextBox ; 37c07 @@ -10648,7 +10648,7 @@ BattleCommand6f: ; 37c07 ld [WeatherCount], a call Function0x37e01 ld hl, SunGotBrightText - jp FarBattleTextBox + jp StdBattleTextBox ; 37c1a @@ -10685,7 +10685,7 @@ BattleCommand95: ; 37c1a jr nz, .asm_37c41 ; 37c47 $f8 ld hl, BellyDrumText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37c4f call Function0x37e77 jp PrintButItFailed @@ -10735,7 +10735,7 @@ BattleCommand96: ; 37c55 .asm_37c8c call Function0x37e01 ld hl, CopiedStatsText - jp FarBattleTextBox + jp StdBattleTextBox ; 37c95 @@ -10884,7 +10884,7 @@ BattleCommand9c: ; 37d34 call BattleCommand0a call BattleCommandaa ld hl, ForesawAttackText - call FarBattleTextBox + call StdBattleTextBox call BattleCommand0c ld de, $c727 ld a, [hBattleTurn] diff --git a/items/item_effects.asm b/items/item_effects.asm index b060914db..342f61926 100644 --- a/items/item_effects.asm +++ b/items/item_effects.asm @@ -1212,7 +1212,7 @@ BitterBerry: ; f16a call $7789 ld hl, $4d81 - call FarBattleTextBox + call StdBattleTextBox ld a, $0 diff --git a/main.asm b/main.asm index 0b848c4e0..077205a37 100644 --- a/main.asm +++ b/main.asm @@ -8178,24 +8178,25 @@ MobileTextBorder: ; 3ab2 BattleTextBox: ; 3ac3 +; Open a textbox and print text at hl. push hl call SpeechTextBox call MobileTextBorder - call Function1ad2 ; UpdateSprites - call Function321c ; refresh? + call Function1ad2 + call Function321c pop hl call PrintTextBoxText ret ; 3ad5 -FarBattleTextBox: ; 3ad5 -; Open a textbox and print text at 20:hl. +StdBattleTextBox: ; 3ad5 +; Open a textbox and print battle text at 20:hl. ld a, [hROMBank] push af - ld a, $20 + ld a, BANK(BattleText) rst Bankswitch call BattleTextBox @@ -36361,7 +36362,7 @@ Function3c0e5: ; 3c0e5 ld hl, $5863 .asm_3c115 - call FarBattleTextBox + call StdBattleTextBox .asm_3c118 call Function3ceec @@ -36624,7 +36625,7 @@ Function3c27c: ; 3c27c ld [hl], a call GetItemName ld hl, $4bde - call FarBattleTextBox + call StdBattleTextBox callab BattleCommand8c pop af bit 7, a @@ -36635,7 +36636,7 @@ Function3c27c: ; 3c27c call Function3ee0f call Function3c8e4 ld hl, $4d97 - jp FarBattleTextBox + jp StdBattleTextBox ; 3c300 Function3c300: ; 3c300 @@ -36945,7 +36946,7 @@ Function3c4df: ; 3c4df res 4, [hl] call SetEnemyTurn ld hl, $4c8a - jp FarBattleTextBox + jp StdBattleTextBox .asm_3c518 ld hl, EnemySubStatus5 @@ -36969,7 +36970,7 @@ Function3c4df: ; 3c4df res 4, [hl] call SetPlayerTurn ld hl, $4c8a - jp FarBattleTextBox + jp StdBattleTextBox ; 3c543 @@ -37278,7 +37279,7 @@ Function3c716: ; 3c716 .asm_3c733 push de - call FarBattleTextBox + call StdBattleTextBox pop de xor a ld [$cfca], a @@ -37332,7 +37333,7 @@ Function3c716: ; 3c716 ld [hBGMapMode], a call Function3ccef ld hl, $480e - call FarBattleTextBox + call StdBattleTextBox .asm_3c7a1 call Function3c706 @@ -37348,7 +37349,7 @@ Function3c716: ; 3c716 call GetQuarterMaxHP call Function3cc3f ld hl, $4822 - call FarBattleTextBox + call StdBattleTextBox .asm_3c7c5 call Function3c706 @@ -37364,7 +37365,7 @@ Function3c716: ; 3c716 call GetQuarterMaxHP call Function3cc3f ld hl, $4836 - call FarBattleTextBox + call StdBattleTextBox .asm_3c7e9 ld hl, BattleMonHP @@ -37415,7 +37416,7 @@ Function3c801: ; 3c801 ld [$d265], a push af ld hl, $4864 - call FarBattleTextBox + call StdBattleTextBox pop af ret nz ld a, $0 @@ -37510,7 +37511,7 @@ Function3c874: ; 3c874 ld hl, $4df5 .asm_3c8e1 - jp FarBattleTextBox + jp StdBattleTextBox ; 3c8e4 Function3c8e4: ; 3c8e4 @@ -37563,7 +37564,7 @@ Function3c8eb: ; 3c8eb call Function3c8e4 call Function3ccef ld hl, $4880 - jp FarBattleTextBox + jp StdBattleTextBox ; 3c93c Function3c93c: ; 3c93c @@ -37702,7 +37703,7 @@ Function3c93c: ; 3c93c call Function3ddc8 call Function3c8e4 ld hl, $4899 - jp FarBattleTextBox + jp StdBattleTextBox ; 3ca26 Function3ca26: ; 3ca26 @@ -37733,7 +37734,7 @@ Function3ca26: ; 3ca26 cp $1 ret nz ld hl, $48b6 - call FarBattleTextBox + call StdBattleTextBox ld a, $10 call GetBattleVarPair push af @@ -37784,7 +37785,7 @@ Function3ca8f: ; 3ca8f call UpdateBattleHuds call SetEnemyTurn ld hl, $524b - jp FarBattleTextBox + jp StdBattleTextBox .asm_3cac9 ld a, [EnemyMonStatus] @@ -37810,7 +37811,7 @@ Function3ca8f: ; 3ca8f call UpdateBattleHuds call SetPlayerTurn ld hl, $524b - jp FarBattleTextBox + jp StdBattleTextBox ; 3cafb Function3cafb: ; 3cafb @@ -37847,7 +37848,7 @@ Function3cafb: ; 3cafb .asm_3cb2e ld [hBattleTurn], a ld hl, $48d2 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cb36 @@ -37904,7 +37905,7 @@ FadeLightScreen: ; 3cb80 push hl push de ld hl, BattleText_0x808e7 - call FarBattleTextBox + call StdBattleTextBox pop de pop hl ret @@ -37918,7 +37919,7 @@ FadeReflect: ; 3cb91 ret nz res SCREENS_REFLECT, [hl] ld hl, BattleText_0x80905 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cb9e HandleWeather: ; 3cb9e @@ -37991,7 +37992,7 @@ HandleWeather: ; 3cb9e call Function3cc3f ld hl, BattleText_0x8084d - jp FarBattleTextBox + jp StdBattleTextBox .asm_3cc13 ld hl, .WeatherEndedMessages @@ -38010,7 +38011,7 @@ HandleWeather: ; 3cb9e ld a, [hli] ld h, [hl] ld l, a - jp FarBattleTextBox + jp StdBattleTextBox ; 3cc2d .WeatherMessages @@ -38521,7 +38522,7 @@ Function3cef1: ; 3cef1 ld bc, $050b call ClearBox ld hl, BattleText_0x80a75 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cf14 Function3cf14: ; 3cf14 @@ -38535,7 +38536,7 @@ Function3cf14: ; 3cf14 ld bc, $040a call ClearBox ld hl, BattleText_0x809a8 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cf35 Function3cf35: ; 3cf35 @@ -38620,7 +38621,7 @@ Function3cfa4: ; 3cfa4 call z, Function3d0ea callab Function39939 ld hl, BattleText_0x809da - call FarBattleTextBox + call StdBattleTextBox call Function3d2f1 jr z, .asm_3cff5 ld a, [InLinkBattle] @@ -38729,11 +38730,11 @@ Function3d02b: ; 3d02b ld a, [hli] ld h, [hl] ld l, a - jp FarBattleTextBox + jp StdBattleTextBox .asm_3d07b ld hl, BattleText_0x809be - jp FarBattleTextBox + jp StdBattleTextBox ; 3d081 Function3d081: ; 3d081 @@ -39013,7 +39014,7 @@ Function3d1f8: ; 3d1f8 dec a ret nz ld hl, BattleText_0x80a83 - call FarBattleTextBox + call StdBattleTextBox .asm_3d20a ld bc, $0107 call Function1dd2 @@ -39188,7 +39189,7 @@ Function3d34f: ; 3d34f cp [hl] jr nz, .asm_3d360 ld hl, BattleText_0x80c0d - call FarBattleTextBox + call StdBattleTextBox scf ret @@ -39309,7 +39310,7 @@ LostBattle: ; 3d38e jr z, .asm_3d417 .asm_3d412 - call FarBattleTextBox + call StdBattleTextBox .end scf @@ -39827,7 +39828,7 @@ Function3d74b: ; 3d74b push af callab Function39939 ld hl, BattleText_0x80aca - call FarBattleTextBox + call StdBattleTextBox ld bc, $0107 call Function1dd2 ld a, [$cfa9] @@ -39878,7 +39879,7 @@ Function3d7a0: ; 3d7a0 Function3d7b8: ; 3d7b8 callab Function39939 ld hl, BattleText_0x80af8 - call FarBattleTextBox + call StdBattleTextBox jp WaitBGMap ; 3d7c7 @@ -40009,7 +40010,7 @@ Function3d887: ; 3d887 ld hl, BattleText_0x80b0b .asm_3d8ae - call FarBattleTextBox + call StdBattleTextBox .asm_3d8b1 xor a @@ -40063,7 +40064,7 @@ Function3d8b3: ; 3d8b3 call SetPlayerTurn call GetItemName ld hl, BattleText_0x80b89 - call FarBattleTextBox + call StdBattleTextBox jp .asm_3d9a2 .asm_3d916 @@ -40140,7 +40141,7 @@ Function3d8b3: ; 3d8b3 ld hl, BattleText_0x80b49 .asm_3d995 - call FarBattleTextBox + call StdBattleTextBox ld a, $1 ld [$d266], a call Function309d @@ -40183,7 +40184,7 @@ Function3d8b3: ; 3d8b3 pop de call WaitSFX ld hl, BattleText_0x80b77 - call FarBattleTextBox + call StdBattleTextBox call WaitSFX call Function309d scf @@ -40195,7 +40196,7 @@ Function3d8b3: ; 3d8b3 bit 4, [hl] jr nz, .asm_3da05 ld hl, BattleText_0x81863 - call FarBattleTextBox + call StdBattleTextBox .asm_3da05 call WaitSFX @@ -40488,7 +40489,7 @@ Function3dc23: ; 3dc23 ret z push bc ld hl, BattleText_0x80bae - call FarBattleTextBox + call StdBattleTextBox call GetEighthMaxHP call Function3cc39 pop hl @@ -40565,7 +40566,7 @@ Function3dc5b: ; 3dc5b ld hl, BattleText_0x809a8 .asm_3dcdf - call FarBattleTextBox + call StdBattleTextBox scf ret @@ -40701,7 +40702,7 @@ Function3dd2f: ; 3dd2f ld a, $9 rst FarCall ld hl, RecoveredUsingText - jp FarBattleTextBox + jp StdBattleTextBox ; 3ddc8 @@ -40812,7 +40813,7 @@ Function3de51: ; 3de51 call GetItemName call Function3ddc8 ld hl, BattleText_0x80dab - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a jr nz, .asm_3de90 @@ -40892,7 +40893,7 @@ Function3deb1: ; 3deb1 ld [de], a call GetItemName ld hl, BattleText_0x80bde - call FarBattleTextBox + call StdBattleTextBox callab BattleCommand8c ret @@ -41328,7 +41329,7 @@ Function3e19b: ; 3e19b bit 4, [hl] jr nz, .asm_3e1c5 ld hl, $5863 - call FarBattleTextBox + call StdBattleTextBox ld c, $3c call DelayFrames @@ -41391,7 +41392,7 @@ Function3e1c7: ; 3e1c7 Function3e22b: ; 3e22b ld hl, BattleText_0x80bf3 - call FarBattleTextBox + call StdBattleTextBox jp Function3e139 ; 3e234 @@ -41546,7 +41547,7 @@ Function3e358: ; 3e358 cp d jr nz, .asm_3e36b ld hl, BattleText_0x80c0d - call FarBattleTextBox + call StdBattleTextBox jp $6299 .asm_3e36b @@ -41559,7 +41560,7 @@ Function3e358: ; 3e358 .asm_3e378 ld hl, BattleText_0x80c22 - call FarBattleTextBox + call StdBattleTextBox jp $6299 .asm_3e381 @@ -41919,7 +41920,7 @@ Function3e4bc: ; 3e4bc ld hl, Function3cc39 .asm_3e613 - call FarBattleTextBox + call StdBattleTextBox call Function30b4 jp Function3e4bc ; 3e61c @@ -42168,7 +42169,7 @@ Function3e786: ; 3e786 .asm_3e7b4 ld hl, BattleText_0x80c72 - call FarBattleTextBox + call StdBattleTextBox ld c, $3c call DelayFrames xor a @@ -43811,7 +43812,7 @@ Function3ee3b: ; 3ee3b call StartSFX call WaitSFX ld hl, BattleText_0x80c9c - call FarBattleTextBox + call StdBattleTextBox call Function309d .asm_3f057 @@ -44064,7 +44065,7 @@ Function3f136: ; 3f136 rst FarCall call WaitSFX ld hl, BattleText_0x80c9c - call FarBattleTextBox + call StdBattleTextBox pop de inc e ld b, $0 @@ -44353,7 +44354,7 @@ Function3f360: ; 3f360 push hl call Function30b4 pop hl - jp FarBattleTextBox + jp StdBattleTextBox ; 3f390 @@ -44912,7 +44913,7 @@ Function3f71d: ; 3f71d ld de, $d850 call Function3d0be ld hl, BattleText_0x80730 - call FarBattleTextBox + call StdBattleTextBox ld a, [$cfc0] bit 0, a ret z @@ -45752,7 +45753,7 @@ BattleStartMessage: ; 3fc8b ld hl, $4000 rst FarCall pop hl - call FarBattleTextBox + call StdBattleTextBox call Function3f830 ret nz @@ -54111,6 +54112,7 @@ INCLUDE "engine/engine_flags.asm" INCBIN "baserom.gbc", $80648, $80730-$80648 +BattleText: INCLUDE "text/battle.asm" INCBIN "baserom.gbc", $818ac, $81fe3-$818ac @@ -68010,7 +68012,7 @@ Function100bc2: ; 100bc2 ld hl, $4c39 .asm_100c6b - call FarBattleTextBox + call StdBattleTextBox call Function30b4 jp Function100bc2 ; 100c74 From a6237d68257dd3bb963850c205d0ca4a1c46f88a Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:29:54 -0500 Subject: [PATCH 80/96] remove an Exception from preprocessor It wasn't meant to be left in there anyway. --- preprocessor.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index c4a93000a..b6bdfbe7d 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -532,10 +532,7 @@ def macro_translator(macro, token, line): index = 0 while index < len(params): - try: - param_type = macro.param_types[index - correction] - except KeyError as exception: - raise Exception("line is: " + str(line) + " and macro is: " + str(macro)) + param_type = macro.param_types[index - correction] description = param_type["name"] param_klass = param_type["class"] byte_type = param_klass.byte_type # db or dw From 0f28e96e4d42b5fee5e7dec094f61fdf9d46577f Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:37:02 -0500 Subject: [PATCH 81/96] remove the show_original_lines global --- preprocessor.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index b6bdfbe7d..6ddd45539 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -31,9 +31,6 @@ macros += movement_command_classes macros += music_classes macros += effect_classes -# show lines before preprocessing in stdout -show_original_lines = False - # helpful for debugging macros do_macro_sanity_check = False @@ -434,11 +431,12 @@ def is_based_on(something, base): options += [something.__name__] return (base in options) -def macro_translator(macro, token, line): +def macro_translator(macro, token, line, show_original_lines=False): """ Converts a line with a macro into a rgbasm-compatible line. - """ + @param show_original_lines: show lines before preprocessing in stdout + """ assert macro.macro_name == token, "macro/token mismatch" original_line = line From 998fa0b198c19088189634920b2c9829a5324576 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:37:55 -0500 Subject: [PATCH 82/96] remove the do_macro_sanity_check global --- preprocessor.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index 6ddd45539..ae9b5624b 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -31,9 +31,6 @@ macros += movement_command_classes macros += music_classes macros += effect_classes -# helpful for debugging macros -do_macro_sanity_check = False - chars = { "ガ": 0x05, "ギ": 0x06, @@ -431,11 +428,12 @@ def is_based_on(something, base): options += [something.__name__] return (base in options) -def macro_translator(macro, token, line, show_original_lines=False): +def macro_translator(macro, token, line, show_original_lines=False, do_macro_sanity_check=False): """ Converts a line with a macro into a rgbasm-compatible line. @param show_original_lines: show lines before preprocessing in stdout + @param do_macro_sanity_check: helpful for debugging macros """ assert macro.macro_name == token, "macro/token mismatch" From 1ce2bccd3747f5c311f40389fa3895e29dfae21b Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:45:12 -0500 Subject: [PATCH 83/96] generic preprocessor-specific exception classes These are basic python Exception subclasses that can be used to throw more specific errors and exceptions from within the preprocessor. AssertionError is not a good idea. --- preprocessor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/preprocessor.py b/preprocessor.py index b6bdfbe7d..69121747d 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -302,6 +302,16 @@ chars = { "9": 0xFF } +class PreprocessorException(Exception): + """ + There was a problem in the preprocessor. + """ + +class MacroException(PreprocessorException): + """ + There was a problem with a macro. + """ + def separate_comment(l): """ Separates asm and comments on a single line. From ecedde19931bd7d1eb71c59498dab98944639b85 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:46:11 -0500 Subject: [PATCH 84/96] replace an assert in macro_translator Use a MacroException instead of an AssertionError. --- preprocessor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/preprocessor.py b/preprocessor.py index 69121747d..a6a9efd29 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -449,7 +449,8 @@ def macro_translator(macro, token, line): Converts a line with a macro into a rgbasm-compatible line. """ - assert macro.macro_name == token, "macro/token mismatch" + if macro.macro_name != token: + raise MacroException("macro/token mismatch") original_line = line From 2c22d9220c48b2a36550b5a5a2bae1e0988da0d6 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:50:17 -0500 Subject: [PATCH 85/96] fix "raise Exception" formatting in preprocessor --- preprocessor.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index a6a9efd29..905e27533 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -478,7 +478,7 @@ def macro_translator(macro, token, line): # check if there are no params (redundant) if len(params) == 1 and params[0] == "": - raise Exception, "macro has no params?" + raise Exception("macro has no params?") # write out a comment showing the original line if show_original_lines: @@ -519,10 +519,14 @@ def macro_translator(macro, token, line): elif param_klass.size == 3: allowed_length += 2 # bank and label else: - raise Exception, "dunno what to do with a macro param with a size > 3" + raise Exception( + "dunno what to do with a macro param with a size > 3" + ) else: - raise Exception, "dunno what to do with this non db/dw macro param: " + \ - str(param_klass) + " in line: " + original_line + raise Exception( + "dunno what to do with this non db/dw macro param: {klass} in line {line}" + .format(klass=param_klass, line=original_line) + ) # sometimes the allowed length can vary if hasattr(macro, "allowed_lengths"): @@ -577,9 +581,13 @@ def macro_translator(macro, token, line): output += ("db " + param_klass.from_asm(param) + "\n") index += 1 else: - raise Exception, "dunno what to do with this macro " + \ - "param (" + str(param_klass) + ") " + "on this line: " + \ - original_line + raise Exception( + "dunno what to do with this macro param ({klass}) in line: {line}" + .format( + klass=param_klass, + line=original_line, + ) + ) # or just print out the byte else: From 95f7270141cbdb32c7d178a8a89a822e66e3a113 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:51:31 -0500 Subject: [PATCH 86/96] raise MacroException instead of Exception A more specific exception means that error handling can actually work in the future. --- preprocessor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index 905e27533..daed157d4 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -478,7 +478,7 @@ def macro_translator(macro, token, line): # check if there are no params (redundant) if len(params) == 1 and params[0] == "": - raise Exception("macro has no params?") + raise MacroException("macro has no params?") # write out a comment showing the original line if show_original_lines: @@ -519,11 +519,11 @@ def macro_translator(macro, token, line): elif param_klass.size == 3: allowed_length += 2 # bank and label else: - raise Exception( + raise MacroException( "dunno what to do with a macro param with a size > 3" ) else: - raise Exception( + raise MacroException( "dunno what to do with this non db/dw macro param: {klass} in line {line}" .format(klass=param_klass, line=original_line) ) @@ -581,7 +581,7 @@ def macro_translator(macro, token, line): output += ("db " + param_klass.from_asm(param) + "\n") index += 1 else: - raise Exception( + raise MacroException( "dunno what to do with this macro param ({klass}) in line: {line}" .format( klass=param_klass, From 93514b18629fe42c0a2688dac57d90998ea5daaa Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:54:03 -0500 Subject: [PATCH 87/96] convert a macro_translator assert in preprocessor AssertionError -> PreprocessorException --- preprocessor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index daed157d4..c6ae137c4 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -534,9 +534,15 @@ def macro_translator(macro, token, line): else: allowed_lengths = [allowed_length] - assert len(params) in allowed_lengths, \ - "mismatched number of parameters on this line: " + \ - original_line + if len(params) not in allowed_lengths: + raise PreprocessorException( + "mismatched number of parameters ({count}, instead of any of {allowed}) on this line: {line}" + .format( + count=len(params), + allowed=allowed_lengths, + line=original_line, + ) + ) # --- end of ridiculously long sanity check --- From ebb591a7ec624acce35d0378201c641724ac8d4c Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 09:56:24 -0500 Subject: [PATCH 88/96] make a MacroException more verbose in preprocessor --- preprocessor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/preprocessor.py b/preprocessor.py index c6ae137c4..a31386801 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -520,7 +520,8 @@ def macro_translator(macro, token, line): allowed_length += 2 # bank and label else: raise MacroException( - "dunno what to do with a macro param with a size > 3" + "dunno what to do with a macro param with a size > 3 (size={size})" + .format(size=param_klass.size) ) else: raise MacroException( From 63c2dc2f1ffb3ec93f8fb6b97b0b909c36ecc0bf Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 10:03:37 -0500 Subject: [PATCH 89/96] docstring for prequeue.py --- prequeue.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/prequeue.py b/prequeue.py index c9a9a8bcc..ec6cd9e39 100644 --- a/prequeue.py +++ b/prequeue.py @@ -1,8 +1,9 @@ # coding: utf-8 - -# Starting a new python process to preprocess each source file -# creates too much overhead. Instead, a list of files to preprocess -# is fed into a script run from a single process. +""" +Starting a new python process to preprocess each source file creates too much +overhead. Instead, a list of files to preprocess is fed into a script run from +a single process. +""" import os import sys From 5815edf382d586e84db8d08612d5f4d1c2e7ac96 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 10:13:17 -0500 Subject: [PATCH 90/96] refactor preprocessor macros into a function Remove the "macros" global and instead use a function to construct a list of macros. --- preprocessor.py | 36 ++++++++++++++++++++++-------------- prequeue.py | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index b6bdfbe7d..e69089c18 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -16,20 +16,28 @@ from extras.pokemontools.crystal import ( effect_classes, ) -even_more_macros = [ - Warp, - XYTrigger, - Signpost, - PeopleEvent, - DataByteWordMacro, -] +def load_pokecrystal_macros(): + """ + Construct a list of macros that are needed for pokecrystal preprocessing. + """ + ourmacros = [] -macros = command_classes -macros += even_more_macros -macros += [each[1] for each in text_command_classes] -macros += movement_command_classes -macros += music_classes -macros += effect_classes + even_more_macros = [ + Warp, + XYTrigger, + Signpost, + PeopleEvent, + DataByteWordMacro, + ] + + ourmacros += command_classes + ourmacros += even_more_macros + ourmacros += [each[1] for each in text_command_classes] + ourmacros += movement_command_classes + ourmacros += music_classes + ourmacros += effect_classes + + return ourmacros # show lines before preprocessing in stdout show_original_lines = False @@ -628,4 +636,4 @@ def preprocess(macros, lines=None): # only run against stdin when not included as a module if __name__ == "__main__": - preprocess(macros) + preprocess(load_pokecrystal_macros()) diff --git a/prequeue.py b/prequeue.py index ec6cd9e39..2c8f4cf5a 100644 --- a/prequeue.py +++ b/prequeue.py @@ -14,4 +14,4 @@ if __name__ == '__main__': dest = os.path.splitext(source)[0] + '.tx' sys.stdin = open(source, 'r') sys.stdout = open(dest, 'w') - preprocessor.preprocess(preprocessor.macros) + preprocessor.preprocess(preprocessor.load_pokecrystal_macros()) From 2fd792bbdad32891f131b5735f22230d48674954 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 10:39:49 -0500 Subject: [PATCH 91/96] move macro sanity check into separate function This moves out from macro_translator the macro/param length sanity check into a function called check_macro_sanity. --- preprocessor.py | 106 ++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index f5dd205b2..bac8d7020 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -446,6 +446,60 @@ def is_based_on(something, base): options += [something.__name__] return (base in options) +def check_macro_sanity(params, macro, original_line): + """ + Checks whether or not the correct number of arguments are being passed to a + certain macro. There are a number of possibilities based on the types of + parameters that define the macro. + + @param params: a list of parameters given to the macro + @param macro: macro klass + @param original_line: the line being preprocessed + """ + allowed_length = 0 + + for (index, param_type) in macro.param_types.items(): + param_klass = param_type["class"] + + if param_klass.byte_type == "db": + allowed_length += 1 # just one value + elif param_klass.byte_type == "dw": + if param_klass.size == 2: + allowed_length += 1 # just label + elif param_klass.size == 3: + allowed_length += 2 # bank and label + else: + raise MacroException( + "dunno what to do with a macro param with a size > 3 (size={size})" + .format(size=param_klass.size) + ) + else: + raise MacroException( + "dunno what to do with this non db/dw macro param: {klass} in line {line}" + .format(klass=param_klass, line=original_line) + ) + + # sometimes the allowed length can vary + if hasattr(macro, "allowed_lengths"): + allowed_lengths = macro.allowed_lengths + [allowed_length] + else: + allowed_lengths = [allowed_length] + + # used twice, so precompute once + params_len = len(params) + + if params_len not in allowed_lengths: + raise PreprocessorException( + "mismatched number of parameters ({count}, instead of any of {allowed}) on this line: {line}" + .format( + count=params_len, + allowed=allowed_lengths, + line=original_line, + ) + ) + + return True + def macro_translator(macro, token, line, show_original_lines=False, do_macro_sanity_check=False): """ Converts a line with a macro into a rgbasm-compatible line. @@ -500,56 +554,10 @@ def macro_translator(macro, token, line, show_original_lines=False, do_macro_san if not macro.override_byte_check: sys.stdout.write("db ${0:02X}\n".format(macro.id)) - # --- long-winded sanity check goes here --- - + # Does the number of parameters on this line match any allowed number of + # parameters that the macro expects? if do_macro_sanity_check: - - # sanity check... this won't work because PointerLabelBeforeBank shows - # up as two params, so these two lengths will always be different. - #assert len(params) == len(macro.param_types), \ - # "mismatched number of parameters on this line: " + \ - # original_line - - # v2 sanity check :) although it sorta sucks that this loop happens twice? - allowed_length = 0 - for (index, param_type) in macro.param_types.items(): - param_klass = param_type["class"] - - if param_klass.byte_type == "db": - allowed_length += 1 # just one value - elif param_klass.byte_type == "dw": - if param_klass.size == 2: - allowed_length += 1 # just label - elif param_klass.size == 3: - allowed_length += 2 # bank and label - else: - raise MacroException( - "dunno what to do with a macro param with a size > 3 (size={size})" - .format(size=param_klass.size) - ) - else: - raise MacroException( - "dunno what to do with this non db/dw macro param: {klass} in line {line}" - .format(klass=param_klass, line=original_line) - ) - - # sometimes the allowed length can vary - if hasattr(macro, "allowed_lengths"): - allowed_lengths = macro.allowed_lengths + [allowed_length] - else: - allowed_lengths = [allowed_length] - - if len(params) not in allowed_lengths: - raise PreprocessorException( - "mismatched number of parameters ({count}, instead of any of {allowed}) on this line: {line}" - .format( - count=len(params), - allowed=allowed_lengths, - line=original_line, - ) - ) - - # --- end of ridiculously long sanity check --- + check_macro_sanity(params, macro, original_line) # used for storetext correction = 0 From 70be18427b069cae7ffcfb84811ae268fa18afce Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 11:04:27 -0500 Subject: [PATCH 92/96] don't call load_pokecrystal_macros 2000 times Also, don't call make_macro_table 2000 times by only calling it once and passing the result. --- preprocessor.py | 7 ++++--- prequeue.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index f5dd205b2..aef1ff220 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -642,9 +642,8 @@ def read_line(l, macro_table): if comment: sys.stdout.write(comment) -def preprocess(macros, lines=None): +def preprocess(macro_table, lines=None): """Main entry point for the preprocessor.""" - macro_table = make_macro_table(macros) if not lines: # read each line from stdin @@ -658,4 +657,6 @@ def preprocess(macros, lines=None): # only run against stdin when not included as a module if __name__ == "__main__": - preprocess(load_pokecrystal_macros()) + macros = load_pokecrystal_macros() + macro_table = make_macro_table(macros) + preprocess(macro_table) diff --git a/prequeue.py b/prequeue.py index 2c8f4cf5a..58790f702 100644 --- a/prequeue.py +++ b/prequeue.py @@ -9,9 +9,15 @@ import os import sys import preprocessor -if __name__ == '__main__': +def main(): + macros = preprocessor.load_pokecrystal_macros() + macro_table = preprocessor.make_macro_table(macros) + for source in sys.argv[1:]: dest = os.path.splitext(source)[0] + '.tx' sys.stdin = open(source, 'r') sys.stdout = open(dest, 'w') - preprocessor.preprocess(preprocessor.load_pokecrystal_macros()) + preprocessor.preprocess(macro_table) + +if __name__ == '__main__': + main() From 7eaf5bf72656fa84d2aa94a0ea6e534120f40131 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 11:07:49 -0500 Subject: [PATCH 93/96] reset stdout in prequeue.py near end Other output shouldn't be dumped into items/item_attributes.tx by default. --- prequeue.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prequeue.py b/prequeue.py index 58790f702..6efc519d1 100644 --- a/prequeue.py +++ b/prequeue.py @@ -13,11 +13,16 @@ def main(): macros = preprocessor.load_pokecrystal_macros() macro_table = preprocessor.make_macro_table(macros) + stdout = sys.stdout + for source in sys.argv[1:]: dest = os.path.splitext(source)[0] + '.tx' sys.stdin = open(source, 'r') sys.stdout = open(dest, 'w') preprocessor.preprocess(macro_table) + # reset stdout + sys.stdout = stdout + if __name__ == '__main__': main() From 473bd192d9eb5767d5cda2ae21a0aa52552fabf6 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 11:57:01 -0500 Subject: [PATCH 94/96] better read_line performance in preprocessor Jump out of read_line early if the line is an empty string or a newline. --- preprocessor.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index aef1ff220..79fb9224f 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -427,12 +427,10 @@ def macro_test(asm, macro_table): token = extract_token(asm) # skip db and dw since rgbasm handles those and they aren't macros - if token not in ["db", "dw"]: - # check against all names - if token in macro_table: - return (macro_table[token], token) - - return (None, None) + if token is not None and token not in ["db", "dw"] and token in macro_table: + return (macro_table[token], token) + else: + return (None, None) def is_based_on(something, base): """ @@ -611,6 +609,10 @@ def macro_translator(macro, token, line, show_original_lines=False, do_macro_san def read_line(l, macro_table): """Preprocesses a given line of asm.""" + if l in ["\n", ""]: + sys.stdout.write(l) + return # jump out early + # strip comments from asm asm, comment = separate_comment(l) @@ -624,7 +626,7 @@ def read_line(l, macro_table): sys.stdout.write(asm) # ascii string macro preserves the bytes as ascii (skip the translator) - elif len(asm) > 6 and "ascii " == asm[:6] or "\tascii " == asm[:7]: + elif len(asm) > 6 and ("ascii " == asm[:6] or "\tascii " == asm[:7]): asm = asm.replace("ascii", "db", 1) sys.stdout.write(asm) @@ -640,7 +642,8 @@ def read_line(l, macro_table): else: sys.stdout.write(asm) - if comment: sys.stdout.write(comment) + if comment: + sys.stdout.write(comment) def preprocess(macro_table, lines=None): """Main entry point for the preprocessor.""" From a74462bc52ee3050e13680cd35156589e7f45555 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 12:03:48 -0500 Subject: [PATCH 95/96] even better performance for read_line --- preprocessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor.py b/preprocessor.py index 79fb9224f..10e407380 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -609,7 +609,7 @@ def macro_translator(macro, token, line, show_original_lines=False, do_macro_san def read_line(l, macro_table): """Preprocesses a given line of asm.""" - if l in ["\n", ""]: + if l in ["\n", ""] or l[0] == ";": sys.stdout.write(l) return # jump out early From 6191559c539af5b4e6f05254d10c6f52993d0321 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 31 Aug 2013 12:12:09 -0500 Subject: [PATCH 96/96] give preprocessor.py a main() --- preprocessor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/preprocessor.py b/preprocessor.py index 10e407380..a8be0ee76 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -658,8 +658,11 @@ def preprocess(macro_table, lines=None): for l in lines: read_line(l, macro_table) -# only run against stdin when not included as a module -if __name__ == "__main__": +def main(): macros = load_pokecrystal_macros() macro_table = make_macro_table(macros) preprocess(macro_table) + +# only run against stdin when not included as a module +if __name__ == "__main__": + main()