From d05adc4f9881c2d5516a8884740a3c4128c29642 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 00:46:25 -0400 Subject: [PATCH 1/9] Function2f17 -> IsInJohto --- main.asm | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/main.asm b/main.asm index 9a096202f..834679aec 100644 --- a/main.asm +++ b/main.asm @@ -768,32 +768,37 @@ Function2ee4: ; 2ee4 INCLUDE "common/string.asm" -Function2f17: ; 2f17 +IsInJohto: ; 2f17 +; Return 0 if the player is in Johto, and 1 in Kanto. + ld a, [MapGroup] ld b, a ld a, [MapNumber] ld c, a call GetWorldMapLocation - cp $5f - jr z, .asm_2f39 - cp $0 - jr nz, .asm_2f35 + + cp $5f ; SS Aqua + jr z, .Johto + + cp $0 ; Poke Center 2F + jr nz, .CheckRegion + ld a, [BackupMapGroup] ld b, a ld a, [BackupMapNumber] ld c, a call GetWorldMapLocation -.asm_2f35 - cp $2f - jr nc, .asm_2f3b +.CheckRegion + cp $2f ; Pallet Town + jr nc, .Kanto -.asm_2f39 +.Johto xor a ret -.asm_2f3b - ld a, $1 +.Kanto + ld a, 1 ret ; 2f3e @@ -36055,7 +36060,7 @@ Function2a200: ; 2a200 jr .asm_2a27a .asm_2a235 - call Function2f17 + call IsInJohto and a ret z ld h, d From f0cf86777ba012485003a05fb5988a9812051808 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 01:35:10 -0400 Subject: [PATCH 2/9] fix item asm labels CheckItem was called PickUpItem by mistake Also label TossItem and ReceiveItem --- engine/scripting.asm | 8 ++--- main.asm | 70 ++++++++++++++++++++++---------------------- stats/odd_eggs.asm | 2 +- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/engine/scripting.asm b/engine/scripting.asm index e8921a265..12fd14283 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -539,7 +539,7 @@ Script_verbosegiveitem2: ; 0x96f8e ld a, [de] ld [$d10c], a ld hl, $d892 - call Function2f66 + call ReceiveItem ld a, $1 jr c, .asm_96fb0 ; 0x96fad $1 xor a @@ -2320,7 +2320,7 @@ Script_giveitem: ; 0x977ca call GetScriptByte ld [$d10c], a ld hl, $d892 - call Function2f66 + call ReceiveItem 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 Function2f53 + call TossItem ret nc ld a, $1 ld [$c2dd], a @@ -2363,7 +2363,7 @@ Script_checkitem: ; 0x97812 call GetScriptByte ld [$d106], a ld hl, $d892 - call PickUpItem + call CheckItem ret nc ld a, $1 ld [$c2dd], a diff --git a/main.asm b/main.asm index 834679aec..a18461f51 100644 --- a/main.asm +++ b/main.asm @@ -823,56 +823,56 @@ CheckTossableItem: ; 2f46 ret ; 2f53 -Function2f53: ; 2f53 +TossItem: ; 2f53 push hl push de push bc ld a, [hROMBank] push af - ld a, $3 + ld a, BANK(_TossItem) rst Bankswitch - call $520d + call _TossItem + pop bc ld a, b rst Bankswitch - pop bc pop de pop hl ret ; 2f66 -Function2f66: ; 2f66 +ReceiveItem: ; 2f66 push bc ld a, [hROMBank] push af - ld a, $3 + ld a, BANK(_ReceiveItem) rst Bankswitch - push hl push de - call $51d5 + + call _ReceiveItem + pop de pop hl pop bc ld a, b rst Bankswitch - pop bc ret ; 2f79 -PickUpItem: ; 2f79 +CheckItem: ; 2f79 push hl push de push bc ld a, [hROMBank] push af - ld a, BANK(_PickUpItem) + ld a, BANK(_CheckItem) rst Bankswitch - call _PickUpItem + call _CheckItem pop bc ld a, b @@ -14138,7 +14138,7 @@ Functionc309: ; c309 ld a, $1 ld [$d10c], a ld hl, NumItems - call Function2f66 + call ReceiveItem jr nc, .asm_c33d xor a ld [$abe2], a @@ -14238,7 +14238,7 @@ Functionc3ae: ; c3ae ld a, $36 ld [CurItem], a ld hl, NumItems - call PickUpItem + call CheckItem jr nc, .asm_c3c9 and a ret @@ -16271,7 +16271,7 @@ UnknownText_0xd1d0: ; 0xd1d0 ; 0xd1d5 -Functiond1d5: ; d1d5 +_ReceiveItem: ; d1d5 call Functiond27b jp nz, Functiond29c push hl @@ -16318,7 +16318,7 @@ Functiond201: ; d201 ; d20d -Functiond20d: ; d20d +_TossItem: ; d20d call Functiond27b jr nz, .asm_d241 push hl @@ -16366,7 +16366,7 @@ Functiond20d: ; d20d jp Functiond2ff ; d244 -_PickUpItem: ; d244 +_CheckItem: ; d244 call Functiond27b jr nz, .asm_d278 push hl @@ -16424,7 +16424,7 @@ Functiond27b: ; d27b ; d283 Functiond283: ; d283 - ld c, $14 + ld c, 20 ld a, e cp TMsHMsEnd % $100 jr nz, .asm_d28e @@ -16433,7 +16433,7 @@ Functiond283: ; d283 ret z .asm_d28e - ld c, $32 + ld c, 50 ld a, e cp BallsEnd % $100 jr nz, .asm_d299 @@ -19469,7 +19469,7 @@ Functionf795: ; f795 ld hl, NumItems ld a, $1 ld [$d10c], a - jp Function2f53 + jp TossItem ; f7a0 Functionf7a0: ; f7a0 @@ -22296,7 +22296,7 @@ Function12cdf: ; 12cdf ld a, $1 ld [$d10c], a ld hl, NumItems - jp Function2f66 + jp ReceiveItem ; 12cea INCBIN "baserom.gbc", $12cea, $12cf5 - $12cea @@ -27034,14 +27034,14 @@ Function157e9: ; 0x157e9 ld a, [$d107] ld [Buffer2], a ld hl, NumItems - call Function2f66 + call ReceiveItem jr nc, .PackFull ld a, [Buffer1] ld [$d10c], a ld a, [Buffer2] ld [$d107], a ld hl, PCItems - call Function2f53 + call TossItem ld a, $3b call Predef ld hl, .WithdrewText @@ -27215,14 +27215,14 @@ Function1590a: ; 0x1590a ld a, [$d107] ld [Buffer2], a ld hl, PCItems - call Function2f66 + call ReceiveItem jr nc, .asm_15965 ld a, [Buffer1] ld [$d10c], a ld a, [Buffer2] ld [$d107], a ld hl, NumItems - call Function2f53 + call TossItem ld a, $3b call Predef ld hl, .DepositText @@ -27790,7 +27790,7 @@ Function15cef: ; 15cef call Function1600b jr c, .asm_15d79 ld hl, NumItems - call Function2f66 + call ReceiveItem jr nc, .asm_15d6f ld a, [$d107] ld e, a @@ -28008,7 +28008,7 @@ Function15efd: ; 15efd call Function15fd7 ld a, [$d107] ld hl, NumItems - call Function2f53 + call TossItem ld a, $3b call Predef ld hl, $c5b9 @@ -31297,7 +31297,7 @@ Function24c64: ; 24c64 push hl ld [CurItem], a ld hl, NumItems - call PickUpItem + call CheckItem pop hl jr nc, .asm_24c89 ld a, [hl] @@ -50166,7 +50166,7 @@ Function4484a: ; 0x4484a ld a, $1 ld [$d10c], a ld hl, NumItems - call Function2f66 + call ReceiveItem jr c, .asm_4489e ld hl, .PackFullText jp Function1d67 @@ -51580,12 +51580,12 @@ Function4a927: ; 4a927 ld a, [ScriptVar] ld [CurItem], a ld hl, PCItems - call PickUpItem + call CheckItem jr c, .asm_4a948 ld a, [ScriptVar] ld [CurItem], a ld hl, NumItems - call PickUpItem + call CheckItem jr c, .asm_4a948 xor a ld [ScriptVar], a @@ -60621,7 +60621,7 @@ Function88211: ; 88211 ld hl, NumItems ld a, b ld [$d10c], a - call Function2f53 + call TossItem pop bc ld a, c sub b @@ -62461,7 +62461,7 @@ Function8adef: ; 8adef ld a, WATER_STONE ld [CurItem], a ld hl, NumItems - call PickUpItem + call CheckItem jr c, .asm_8ae24 ld a, [PartyCount] @@ -62781,7 +62781,7 @@ Function8afd4: ; 8afd4 ld a, $1 ld [$d10c], a ld hl, NumItems - call Function2f66 + call ReceiveItem pop hl jr nc, .asm_8b04c ld a, [hl] @@ -76543,7 +76543,7 @@ Functionfd0c3: ; fd0c3 ld a, $1 ld [$d10c], a ld hl, PCItems - call Function2f66 + call ReceiveItem ret ; fd0eb diff --git a/stats/odd_eggs.asm b/stats/odd_eggs.asm index 6922a2de7..68062ec3b 100644 --- a/stats/odd_eggs.asm +++ b/stats/odd_eggs.asm @@ -45,7 +45,7 @@ GiveOddEgg: ; 1fb4b6 ld a, $ff ld [$d107], a ld hl, NumItems - call Function2f53 + call TossItem ld a, EGG ld [$cd2a], a ld a, $29 From 3b70005fb07750959a86c464a8a423a94f98f04b Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 01:45:54 -0400 Subject: [PATCH 3/9] split item interfaces into common/item.asm --- common/item.asm | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 75 +----------------------------------------------- 2 files changed, 77 insertions(+), 74 deletions(-) create mode 100644 common/item.asm diff --git a/common/item.asm b/common/item.asm new file mode 100644 index 000000000..0906a19f6 --- /dev/null +++ b/common/item.asm @@ -0,0 +1,76 @@ +DoItemEffect: ; 2f3f + callba _DoItemEffect + ret +; 2f46 + +CheckTossableItem: ; 2f46 + push hl + push de + push bc + callba _CheckTossableItem + pop bc + pop de + pop hl + ret +; 2f53 + +TossItem: ; 2f53 + push hl + push de + push bc + ld a, [hROMBank] + push af + ld a, BANK(_TossItem) + rst Bankswitch + + call _TossItem + + pop bc + ld a, b + rst Bankswitch + pop bc + pop de + pop hl + ret +; 2f66 + +ReceiveItem: ; 2f66 + push bc + ld a, [hROMBank] + push af + ld a, BANK(_ReceiveItem) + rst Bankswitch + push hl + push de + + call _ReceiveItem + + pop de + pop hl + pop bc + ld a, b + rst Bankswitch + pop bc + ret +; 2f79 + +CheckItem: ; 2f79 + push hl + push de + push bc + ld a, [hROMBank] + push af + ld a, BANK(_CheckItem) + rst Bankswitch + + call _CheckItem + + pop bc + ld a, b + rst Bankswitch + pop bc + pop de + pop hl + ret +; 2f8c + diff --git a/main.asm b/main.asm index a18461f51..b514c8fbb 100644 --- a/main.asm +++ b/main.asm @@ -807,81 +807,8 @@ Function2f3e: ; 2f3e ret ; 2f3f -DoItemEffect: ; 2f3f - callba _DoItemEffect - ret -; 2f46 -CheckTossableItem: ; 2f46 - push hl - push de - push bc - callba _CheckTossableItem - pop bc - pop de - pop hl - ret -; 2f53 - -TossItem: ; 2f53 - push hl - push de - push bc - ld a, [hROMBank] - push af - ld a, BANK(_TossItem) - rst Bankswitch - - call _TossItem - - pop bc - ld a, b - rst Bankswitch - pop bc - pop de - pop hl - ret -; 2f66 - -ReceiveItem: ; 2f66 - push bc - ld a, [hROMBank] - push af - ld a, BANK(_ReceiveItem) - rst Bankswitch - push hl - push de - - call _ReceiveItem - - pop de - pop hl - pop bc - ld a, b - rst Bankswitch - pop bc - ret -; 2f79 - -CheckItem: ; 2f79 - push hl - push de - push bc - ld a, [hROMBank] - push af - ld a, BANK(_CheckItem) - rst Bankswitch - - call _CheckItem - - pop bc - ld a, b - rst Bankswitch - pop bc - pop de - pop hl - ret -; 2f8c +INCLUDE "common/item.asm" Random: ; 2f8c From edf939a07be9e0553a3ef91dd66291806dd3ad50 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 02:47:52 -0400 Subject: [PATCH 4/9] split Random into common/random.asm --- common/random.asm | 76 +++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 76 +---------------------------------------------- 2 files changed, 77 insertions(+), 75 deletions(-) create mode 100644 common/random.asm diff --git a/common/random.asm b/common/random.asm new file mode 100644 index 000000000..0f46da9e4 --- /dev/null +++ b/common/random.asm @@ -0,0 +1,76 @@ +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 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 executed in VBlank. + +; This leaves a with the value in hRandomSub. + + push bc + + ld a, [rDIV] + ld b, a + ld a, [hRandomAdd] + adc b + ld [hRandomAdd], a + + ld a, [rDIV] + ld b, a + ld a, [hRandomSub] + sbc b + ld [hRandomSub], a + + pop bc + ret +; 2f9f + +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. + + ld a, [hROMBank] + push af + ld a, BANK(_BattleRandom) + rst Bankswitch + + call _BattleRandom + + ld [$cfb6], a + pop af + rst Bankswitch + ld a, [$cfb6] + ret +; 2fb1 + + +Function2fb1: ; 2fb1 + push bc + ld c, a + xor a + sub c +.asm_2fb5 + sub c + jr nc, .asm_2fb5 + add c + ld b, a + push bc +.asm_2fbb + call Random + ld a, [hRandomAdd] + ld c, a + add b + jr c, .asm_2fbb + ld a, c + pop bc + call SimpleDivide + pop bc + ret +; 2fcb + diff --git a/main.asm b/main.asm index b514c8fbb..1d57996ea 100644 --- a/main.asm +++ b/main.asm @@ -810,82 +810,8 @@ Function2f3e: ; 2f3e INCLUDE "common/item.asm" +INCLUDE "common/random.asm" -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 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 executed in VBlank. - -; This leaves a with the value in hRandomSub. - - push bc - - ld a, [rDIV] - ld b, a - ld a, [hRandomAdd] - adc b - ld [hRandomAdd], a - - ld a, [rDIV] - ld b, a - ld a, [hRandomSub] - sbc b - ld [hRandomSub], a - - pop bc - ret -; 2f9f - -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. - - ld a, [hROMBank] - push af - ld a, BANK(_BattleRandom) - rst Bankswitch - - call _BattleRandom - - ld [$cfb6], a - pop af - rst Bankswitch - ld a, [$cfb6] - ret -; 2fb1 - - -Function2fb1: ; 2fb1 - push bc - ld c, a - xor a - sub c -.asm_2fb5 - sub c - jr nc, .asm_2fb5 - add c - ld b, a - push bc -.asm_2fbb - call Random - ld a, [hRandomAdd] - ld c, a - add b - jr c, .asm_2fbb - ld a, c - pop bc - call SimpleDivide - pop bc - ret -; 2fcb GetSRAMBank: ; 2fcb ; load sram bank a From 844546f8495030b66e79aa30d96405065e2019dd Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 02:50:06 -0400 Subject: [PATCH 5/9] split sram access asm into common/sram.asm --- common/sram.asm | 34 ++++++++++++++++++++++++++++++++++ main.asm | 36 +----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 common/sram.asm diff --git a/common/sram.asm b/common/sram.asm new file mode 100644 index 000000000..3c42e7618 --- /dev/null +++ b/common/sram.asm @@ -0,0 +1,34 @@ +GetSRAMBank: ; 2fcb +; load sram bank a +; if invalid bank, sram is disabled + cp NUM_SRAM_BANKS + jr c, OpenSRAM + jr CloseSRAM +; 2fd1 + +OpenSRAM: ; 2fd1 +; switch to sram bank a + push af +; latch clock data + ld a, 1 + ld [MBC3LatchClock], a +; enable sram/clock write + ld a, SRAM_ENABLE + ld [MBC3SRamEnable], a +; select sram bank + pop af + ld [MBC3SRamBank], a + ret +; 2fe1 + +CloseSRAM: ; 2fe1 + push af + ld a, SRAM_DISABLE +; reset clock latch for next time + ld [MBC3LatchClock], a +; disable sram/clock write + ld [MBC3SRamEnable], a + pop af + ret +; 2fec + diff --git a/main.asm b/main.asm index 1d57996ea..a8660f1a6 100644 --- a/main.asm +++ b/main.asm @@ -812,41 +812,7 @@ INCLUDE "common/item.asm" INCLUDE "common/random.asm" - -GetSRAMBank: ; 2fcb -; load sram bank a -; if invalid bank, sram is disabled - cp NUM_SRAM_BANKS - jr c, OpenSRAM - jr CloseSRAM -; 2fd1 - -OpenSRAM: ; 2fd1 -; switch to sram bank a - push af -; latch clock data - ld a, 1 - ld [MBC3LatchClock], a -; enable sram/clock write - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a -; select sram bank - pop af - ld [MBC3SRamBank], a - ret -; 2fe1 - -CloseSRAM: ; 2fe1 -; preserve a - push af - ld a, SRAM_DISABLE -; reset clock latch for next time - ld [MBC3LatchClock], a -; disable sram/clock write - ld [MBC3SRamEnable], a - pop af - ret -; 2fec +INCLUDE "common/sram.asm" ; Register aliases From 4a04a09a6b7a80f97392563b1b1b115fa1cf6316 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 03:12:48 -0400 Subject: [PATCH 6/9] labels for cgb double speed functions --- common/init.asm | 2 +- main.asm | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/init.asm b/common/init.asm index 3104c416d..ead75975c 100644 --- a/common/init.asm +++ b/common/init.asm @@ -156,7 +156,7 @@ Init: ; 17d ld a, [hCGB] and a jr z, .asm_22b - call Function2ff7 + call NormalSpeed .asm_22b xor a diff --git a/main.asm b/main.asm index a8660f1a6..bf2527f10 100644 --- a/main.asm +++ b/main.asm @@ -827,20 +827,27 @@ _de_: ; 2fed ; 2fef -Function2fef: ; 2fef +; The CGB hardware introduces Double Speed Mode. +; While active, the clock speed is doubled. + +; The hardware can switch between normal speed +; and double speed at any time, but LCD output +; collapses during the switch. + +DoubleSpeed: ; 2fef ld hl, rKEY1 bit 7, [hl] - jr z, Function2ffd + jr z, SwitchSpeed ret ; 2ff7 -Function2ff7: ; 2ff7 +NormalSpeed: ; 2ff7 ld hl, rKEY1 bit 7, [hl] ret z ; 2ffd -Function2ffd: ; 2ffd +SwitchSpeed: ; 2ffd set 0, [hl] xor a ld [rIF], a @@ -76483,7 +76490,7 @@ Function1000a4: ; 1000a4 ld [$ffe9], a xor a ld [$ff9e], a - call Function2ff7 + call NormalSpeed xor a ld [rIF], a ld a, [BGMapBuffer] @@ -81935,7 +81942,7 @@ Function1183cb: ; 1183cb di ld a, [rIE] ld [$cd32], a - call Function2fef + call DoubleSpeed xor a ld [rIF], a ld [$c300], a @@ -81984,7 +81991,7 @@ Function118452: ; 118452 ld [$ffc9], a ld [$ffe9], a ld [$ff9e], a - call Function2ff7 + call NormalSpeed xor a ld [rIF], a ld a, [$cd32] From e7318ed4bc38baebce0f26048b166c76d13c1838 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 03:14:24 -0400 Subject: [PATCH 7/9] move double speed functions into common/double_speed.asm --- common/double_speed.asm | 31 +++++++++++++++++++++++++++++++ main.asm | 31 +------------------------------ 2 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 common/double_speed.asm diff --git a/common/double_speed.asm b/common/double_speed.asm new file mode 100644 index 000000000..fc1234215 --- /dev/null +++ b/common/double_speed.asm @@ -0,0 +1,31 @@ +; The CGB hardware introduces Double Speed Mode. +; While active, the clock speed is doubled. + +; The hardware can switch between normal speed +; and double speed at any time, but LCD output +; collapses during the switch. + +DoubleSpeed: ; 2fef + ld hl, rKEY1 + bit 7, [hl] + jr z, SwitchSpeed + ret +; 2ff7 + +NormalSpeed: ; 2ff7 + ld hl, rKEY1 + bit 7, [hl] + ret z +; 2ffd + +SwitchSpeed: ; 2ffd + set 0, [hl] + xor a + ld [rIF], a + ld [rIE], a + ld a, $30 + ld [rJOYP], a + stop ; rgbasm adds a nop after this instruction by default + ret +; 300b + diff --git a/main.asm b/main.asm index bf2527f10..7213ea3f6 100644 --- a/main.asm +++ b/main.asm @@ -827,36 +827,7 @@ _de_: ; 2fed ; 2fef -; The CGB hardware introduces Double Speed Mode. -; While active, the clock speed is doubled. - -; The hardware can switch between normal speed -; and double speed at any time, but LCD output -; collapses during the switch. - -DoubleSpeed: ; 2fef - ld hl, rKEY1 - bit 7, [hl] - jr z, SwitchSpeed - ret -; 2ff7 - -NormalSpeed: ; 2ff7 - ld hl, rKEY1 - bit 7, [hl] - ret z -; 2ffd - -SwitchSpeed: ; 2ffd - set 0, [hl] - xor a - ld [rIF], a - ld [rIE], a - ld a, $30 - ld [rJOYP], a - stop ; rgbasm adds a nop after this instruction by default - ret -; 300b +INCLUDE "common/double_speed.asm" ClearSprites: ; 300b From 4778276f33c59bb0bc56cb381d4fe1dc8da1f9b8 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 23:53:04 -0400 Subject: [PATCH 8/9] split serial handshake into common/handshake.asm --- common/handshake.asm | 38 ++++++++++++++++++++++++++++++++++++++ main.asm | 40 +--------------------------------------- 2 files changed, 39 insertions(+), 39 deletions(-) create mode 100644 common/handshake.asm diff --git a/common/handshake.asm b/common/handshake.asm new file mode 100644 index 000000000..8ed1473e4 --- /dev/null +++ b/common/handshake.asm @@ -0,0 +1,38 @@ +AskSerial: ; 2063 +; send out a handshake while serial int is off + ld a, [$c2d4] + bit 0, a + ret z + + ld a, [$c2d5] + and a + ret nz + +; once every 6 frames + ld hl, $ca8a + inc [hl] + ld a, [hl] + cp 6 + ret c + + xor a + ld [hl], a + + ld a, $c + ld [$c2d5], a + +; handshake + ld a, $88 + ld [rSB], a + +; switch to internal clock + ld a, %00000001 + ld [rSC], a + +; start transfer + ld a, %10000001 + ld [rSC], a + + ret +; 208a + diff --git a/main.asm b/main.asm index 7213ea3f6..63ac61d41 100644 --- a/main.asm +++ b/main.asm @@ -475,45 +475,7 @@ Function1d19: ; 1d19 INCLUDE "common/menu.asm" - -AskSerial: ; 2063 -; send out a handshake while serial int is off - ld a, [$c2d4] - bit 0, a - ret z - - ld a, [$c2d5] - and a - ret nz - -; once every 6 frames - ld hl, $ca8a - inc [hl] - ld a, [hl] - cp 6 - ret c - - xor a - ld [hl], a - - ld a, $c - ld [$c2d5], a - -; handshake - ld a, $88 - ld [rSB], a - -; switch to internal clock - ld a, %00000001 - ld [rSC], a - -; start transfer - ld a, %10000001 - ld [rSC], a - - ret -; 208a - +INCLUDE "common/handshake.asm" INCLUDE "common/game_time.asm" From abb7f2fa20e49cf56a55c81d4ec86431e3009098 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Sep 2013 23:54:12 -0400 Subject: [PATCH 9/9] split Predef into common/predef.asm --- common/predef.asm | 54 ++++++++++++++++++++++++++++++++++++++++++++++ main.asm | 55 +---------------------------------------------- 2 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 common/predef.asm diff --git a/common/predef.asm b/common/predef.asm new file mode 100644 index 000000000..bd34a87a1 --- /dev/null +++ b/common/predef.asm @@ -0,0 +1,54 @@ +Predef: ; 2d83 +; Call predefined function a. +; Preserves bc, de, hl and f. + + ld [PredefID], a + ld a, [hROMBank] + push af + + ld a, BANK(GetPredefPointer) + rst Bankswitch + call GetPredefPointer ; stores hl in PredefTemp + +; Switch to the new function's bank + rst Bankswitch + +; Instead of directly calling stuff, +; push it to the stack in reverse. + + ld hl, .Return + push hl + +; Call the Predef function + ld a, [PredefAddress] + ld h, a + ld a, [PredefAddress + 1] + ld l, a + push hl + +; Get hl back + ld a, [PredefTemp] + ld h, a + ld a, [PredefTemp + 1] + ld l, a + ret + +.Return +; Clean up after the Predef call + + ld a, h + ld [PredefTemp], a + ld a, l + ld [PredefTemp+1], a + + pop hl + ld a, h + rst Bankswitch + + ld a, [PredefTemp] + ld h, a + ld a, [PredefTemp + 1] + ld l, a + ret +; 2dba + diff --git a/main.asm b/main.asm index 63ac61d41..650732a5e 100644 --- a/main.asm +++ b/main.asm @@ -505,60 +505,7 @@ Function2d43: ; 2d43 INCLUDE "common/farcall.asm" - -Predef: ; 2d83 -; Call predefined function a. -; Preserves bc, de, hl and f. - - ld [PredefID], a - ld a, [hROMBank] - push af - - ld a, BANK(GetPredefPointer) - rst Bankswitch - call GetPredefPointer ; stores hl in PredefTemp - -; Switch to the new function's bank - rst Bankswitch - -; Instead of directly calling stuff, -; push it to the stack in reverse. - - ld hl, .Return - push hl - -; Call the Predef function - ld a, [PredefAddress] - ld h, a - ld a, [PredefAddress + 1] - ld l, a - push hl - -; Get hl back - ld a, [PredefTemp] - ld h, a - ld a, [PredefTemp + 1] - ld l, a - ret - -.Return -; Clean up after the Predef call - - ld a, h - ld [PredefTemp], a - ld a, l - ld [PredefTemp+1], a - - pop hl - ld a, h - rst Bankswitch - - ld a, [PredefTemp] - ld h, a - ld a, [PredefTemp + 1] - ld l, a - ret -; 2dba +INCLUDE "common/predef.asm" ResetWindow: ; 2dba