summaryrefslogtreecommitdiff
path: root/main.asm
diff options
context:
space:
mode:
Diffstat (limited to 'main.asm')
-rw-r--r--main.asm387
1 files changed, 49 insertions, 338 deletions
diff --git a/main.asm b/main.asm
index e134d11ed..38d1b9cd5 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"
@@ -543,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
@@ -768,32 +677,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
@@ -802,193 +716,12 @@ 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
+INCLUDE "common/item.asm"
-Function2f53: ; 2f53
- push hl
- push de
- push bc
- ld a, [hROMBank]
- push af
- ld a, $3
- rst Bankswitch
+INCLUDE "common/random.asm"
- call $520d
- pop bc
- ld a, b
- rst Bankswitch
-
- pop bc
- pop de
- pop hl
- ret
-; 2f66
-
-Function2f66: ; 2f66
- push bc
- ld a, [hROMBank]
- push af
- ld a, $3
- rst Bankswitch
-
- push hl
- push de
- call $51d5
- pop de
- pop hl
- pop bc
- ld a, b
- rst Bankswitch
-
- pop bc
- ret
-; 2f79
-
-PickUpItem: ; 2f79
- push hl
- push de
- push bc
- ld a, [hROMBank]
- push af
- ld a, BANK(_PickUpItem)
- rst Bankswitch
-
- call _PickUpItem
-
- pop bc
- ld a, b
- rst Bankswitch
- pop bc
- pop de
- pop hl
- ret
-; 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 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
-; 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
@@ -1003,29 +736,7 @@ _de_: ; 2fed
; 2fef
-Function2fef: ; 2fef
- ld hl, rKEY1
- bit 7, [hl]
- jr z, Function2ffd
- ret
-; 2ff7
-
-Function2ff7: ; 2ff7
- ld hl, rKEY1
- bit 7, [hl]
- ret z
-; 2ffd
-
-Function2ffd: ; 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
@@ -14133,7 +13844,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
@@ -14233,7 +13944,7 @@ Functionc3ae: ; c3ae
ld a, $36
ld [CurItem], a
ld hl, NumItems
- call PickUpItem
+ call CheckItem
jr nc, .asm_c3c9
and a
ret
@@ -16266,7 +15977,7 @@ UnknownText_0xd1d0: ; 0xd1d0
; 0xd1d5
-Functiond1d5: ; d1d5
+_ReceiveItem: ; d1d5
call Functiond27b
jp nz, Functiond29c
push hl
@@ -16313,7 +16024,7 @@ Functiond201: ; d201
; d20d
-Functiond20d: ; d20d
+_TossItem: ; d20d
call Functiond27b
jr nz, .asm_d241
push hl
@@ -16361,7 +16072,7 @@ Functiond20d: ; d20d
jp Functiond2ff
; d244
-_PickUpItem: ; d244
+_CheckItem: ; d244
call Functiond27b
jr nz, .asm_d278
push hl
@@ -16419,7 +16130,7 @@ Functiond27b: ; d27b
; d283
Functiond283: ; d283
- ld c, $14
+ ld c, 20
ld a, e
cp TMsHMsEnd % $100
jr nz, .asm_d28e
@@ -16428,7 +16139,7 @@ Functiond283: ; d283
ret z
.asm_d28e
- ld c, $32
+ ld c, 50
ld a, e
cp BallsEnd % $100
jr nz, .asm_d299
@@ -19464,7 +19175,7 @@ Functionf795: ; f795
ld hl, NumItems
ld a, $1
ld [$d10c], a
- jp Function2f53
+ jp TossItem
; f7a0
Functionf7a0: ; f7a0
@@ -22291,7 +22002,7 @@ Function12cdf: ; 12cdf
ld a, $1
ld [$d10c], a
ld hl, NumItems
- jp Function2f66
+ jp ReceiveItem
; 12cea
INCBIN "baserom.gbc", $12cea, $12cf5 - $12cea
@@ -27029,14 +26740,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
@@ -27210,14 +26921,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
@@ -27785,7 +27496,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
@@ -28003,7 +27714,7 @@ Function15efd: ; 15efd
call Function15fd7
ld a, [$d107]
ld hl, NumItems
- call Function2f53
+ call TossItem
ld a, $3b
call Predef
ld hl, $c5b9
@@ -31292,7 +31003,7 @@ Function24c64: ; 24c64
push hl
ld [CurItem], a
ld hl, NumItems
- call PickUpItem
+ call CheckItem
pop hl
jr nc, .asm_24c89
ld a, [hl]
@@ -36055,7 +35766,7 @@ Function2a200: ; 2a200
jr .asm_2a27a
.asm_2a235
- call Function2f17
+ call IsInJohto
and a
ret z
ld h, d
@@ -50161,7 +49872,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
@@ -51575,12 +51286,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
@@ -60616,7 +60327,7 @@ Function88211: ; 88211
ld hl, NumItems
ld a, b
ld [$d10c], a
- call Function2f53
+ call TossItem
pop bc
ld a, c
sub b
@@ -62456,7 +62167,7 @@ Function8adef: ; 8adef
ld a, WATER_STONE
ld [CurItem], a
ld hl, NumItems
- call PickUpItem
+ call CheckItem
jr c, .asm_8ae24
ld a, [PartyCount]
@@ -62776,7 +62487,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]
@@ -76550,7 +76261,7 @@ Functionfd0c3: ; fd0c3
ld a, $1
ld [$d10c], a
ld hl, PCItems
- call Function2f66
+ call ReceiveItem
ret
; fd0eb
@@ -76671,7 +76382,7 @@ Function1000a4: ; 1000a4
ld [$ffe9], a
xor a
ld [$ff9e], a
- call Function2ff7
+ call NormalSpeed
xor a
ld [rIF], a
ld a, [BGMapBuffer]
@@ -82123,7 +81834,7 @@ Function1183cb: ; 1183cb
di
ld a, [rIE]
ld [$cd32], a
- call Function2fef
+ call DoubleSpeed
xor a
ld [rIF], a
ld [$c300], a
@@ -82172,7 +81883,7 @@ Function118452: ; 118452
ld [$ffc9], a
ld [$ffe9], a
ld [$ff9e], a
- call Function2ff7
+ call NormalSpeed
xor a
ld [rIF], a
ld a, [$cd32]