ref: 58af27eaebea219df4773980a95d21c3f36c29cb
parent: ace57ec8274b846af6092f5924f00b1f94119526
author: yenatch <[email protected]>
date: Fri Dec 27 00:56:23 EST 2013
label overworld loop functions
--- a/engine/events.asm
+++ b/engine/events.asm
@@ -3,23 +3,23 @@
SECTION "Events", ROMX, BANK[EVENTS]
-Function966b0: ; 966b0
+OverworldLoop: ; 966b0
xor a
- ld [$d432], a
-.asm_966b4
- ld a, [$d432]
- ld hl, .pointers
+ ld [MapStatus], a
+.loop
+ ld a, [MapStatus]
+ ld hl, .jumps
rst JumpTable
- ld a, [$d432]
+ ld a, [MapStatus]
cp 3 ; done
- jr nz, .asm_966b4
+ jr nz, .loop
.done
ret
-.pointers
- dw Function96724
- dw Function9673e
- dw Function96773
+.jumps
+ dw StartMap
+ dw EnterMap
+ dw HandleMap
dw .done
; 966cb
@@ -115,12 +115,12 @@
; 96724
-Function96724: ; 96724
+StartMap: ; 96724
xor a
ld [ScriptVar], a
xor a
ld [ScriptRunning], a
- ld hl, $d432
+ ld hl, MapStatus
ld bc, $3e
call ByteFill
callba Function113e5
@@ -129,7 +129,7 @@
; 9673e
-Function9673e: ; 9673e
+EnterMap: ; 9673e
xor a
ld [$d453], a
ld [$d454], a
@@ -136,11 +136,13 @@
call Function968d1
callba Function15363
call Function966cb
+
ld a, [$ff9f]
cp $f7
jr nz, .asm_9675a
call Function966d0
.asm_9675a
+
ld a, [$ff9f]
cp $f3
jr nz, .asm_96764
@@ -147,10 +149,11 @@
xor a
ld [PoisonStepCount], a
.asm_96764
+
xor a
ld [$ff9f], a
- ld a, $2
- ld [$d432], a
+ ld a, 2 ; HandleMap
+ ld [MapStatus], a
ret
; 9676d
@@ -162,14 +165,17 @@
; 96773
-Function96773: ; 96773
+HandleMap: ; 96773
call ResetOverworldDelay
call Function967c1
callba Function97e08
- call DoEvents
- ld a, [$d432]
- cp 2
+ call MapEvents
+
+; Not immediately entering a connected map will cause problems.
+ ld a, [MapStatus]
+ cp 2 ; HandleMap
ret nz
+
call Function967d1
call NextOverworldFrame
call Function967e1
@@ -178,18 +184,18 @@
; 96795
-DoEvents: ; 96795
- ld a, [$d433]
- ld hl, .pointers
+MapEvents: ; 96795
+ ld a, [MapEventStatus]
+ ld hl, .jumps
rst JumpTable
ret
-.pointers
- dw Function967a1
- dw Function967ae
+.jumps
+ dw .events
+ dw .no_events
; 967a1
-Function967a1: ; 967a1
+.events ; 967a1
call PlayerEvents
call Function966cb
callba ScriptEvents
@@ -196,7 +202,7 @@
ret
; 967ae
-Function967ae: ; 967ae
+.no_events ; 967ae
ret
; 967af
@@ -220,11 +226,11 @@
ret
; 967c1
-
Function967c1: ; 967c1
- ld a, [$d433]
- cp 1
+ ld a, [MapEventStatus]
+ cp 1 ; no events
ret z
+
call UpdateTime
call GetJoypad
call TimeOfDayPals
@@ -256,13 +262,13 @@
call Function966d0
.asm_96806
- ld a, $0
- ld [$d433], a
+ ld a, 0 ; events
+ ld [MapEventStatus], a
ret
.asm_9680c
- ld a, $1
- ld [$d433], a
+ ld a, 1 ; no events
+ ld [MapEventStatus], a
ret
; 96812
@@ -270,8 +276,8 @@
ld hl, $d150
bit 6, [hl]
ret z
- callba Function81ca
+ callba Function81ca
ret
; 9681f
@@ -335,6 +341,7 @@
nop
call CheckTrainerBattle2
jr nc, .asm_96872
+
ld a, 1
scf
ret
--- a/main.asm
+++ b/main.asm
@@ -4189,7 +4189,7 @@
res 7, [hl]
ld hl, $d83e
set 1, [hl]
- callba Function966b0
+ callba OverworldLoop
ld a, [$d4b5]
cp $2
jr z, .asm_5e80
--- a/wram.asm
+++ b/wram.asm
@@ -1561,7 +1561,12 @@
OTPartyMon6Nickname: ; d421
ds 11
-SECTION "Scripting",WRAMX[$d434],BANK[1]
+SECTION "Map Events", WRAMX[$d432], BANK[1]
+MapStatus: ; d432
+ ds 1
+MapEventStatus: ; d433
+ ds 1
+
ScriptFlags: ; d434
ds 1
ScriptFlags2: ; d435