summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rwxr-xr-xengine/items/items.asm34
-rw-r--r--engine/joypad.asm37
-rwxr-xr-xengine/overworld/map_sprites.asm2
-rw-r--r--engine/overworld/oam.asm16
-rwxr-xr-xengine/play_time.asm61
-rwxr-xr-xengine/random.asm2
-rwxr-xr-xengine/save.asm116
7 files changed, 132 insertions, 136 deletions
diff --git a/engine/items/items.asm b/engine/items/items.asm
index 21e6e924..c6f098dc 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -2740,31 +2740,35 @@ IsNextTileShoreOrWater: ; e8b8 (3:68b8)
ld a, [W_CURMAPTILESET]
ld hl, WaterTilesets
ld de,1
- call IsInArray
- jr nc, .notShoreOrWater
+ call IsInArray ; does the current map allow surfing?
+ ret nc ; if not, return
+ ld hl,WaterTile
ld a, [W_CURMAPTILESET]
cp SHIP_PORT ; Vermilion Dock tileset
- ld a, [wTileInFrontOfPlayer] ; tile in front of player
jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset
- cp $48 ; eastern shore tile in Safari Zone
- jr z, .shoreOrWater
- cp $32 ; usual eastern shore tile
- jr z, .shoreOrWater
+ cp GYM ; eastern shore tile in Safari Zone
+ jr z, .skipShoreTiles
+ cp DOJO ; usual eastern shore tile
+ jr z, .skipShoreTiles
+ ld hl,ShoreTiles
.skipShoreTiles
- cp $14 ; water tile
- jr z, .shoreOrWater
-.notShoreOrWater
- scf
- ret
-.shoreOrWater
- and a
+ ld a,[wTileInFrontOfPlayer]
+ ld de,$1
+ call IsInArray
ret
; tilesets with water
-WaterTilesets: ; e8e0 (3:68e0)
+WaterTilesets: ; e834 (3:6834)
db OVERWORLD, FOREST, DOJO, GYM, SHIP, SHIP_PORT, CAVERN, FACILITY, PLATEAU
db $ff ; terminator
+; shore tiles
+ShoreTiles: ; e83e (3:683e)
+ db $48, $32
+WaterTile: ; e840 (3:6840)
+ db $14
+ db $ff ; terminator
+
ReadSuperRodData: ; e8ea (3:68ea)
; return e = 2 if no fish on this map
; return e = 1 if a bite, bc = level,species
diff --git a/engine/joypad.asm b/engine/joypad.asm
index 31e197e2..791056ca 100644
--- a/engine/joypad.asm
+++ b/engine/joypad.asm
@@ -1,8 +1,43 @@
-_Joypad::
+ReadJoypad_:: ; c000 (3:4000)
+; Poll joypad input.
+; Unlike the hardware register, button
+; presses are indicated by a set bit.
+
+ ld a, 1 << 5 ; select direction keys
+ ld c, 0
+
+ ld [rJOYP], a
+ rept 6
+ ld a, [rJOYP]
+ endr
+ cpl
+ and %1111
+ swap a
+ ld b, a
+
+ ld a, 1 << 4 ; select button keys
+ ld [rJOYP], a
+ rept 10
+ ld a, [rJOYP]
+ endr
+ cpl
+ and %1111
+ or b
+
+ ld [hJoyInput], a
+
+ ld a, 1 << 4 + 1 << 5 ; deselect keys
+ ld [rJOYP], a
+ ret
+
+
+_Joypad:: ; c02d (3:402d)
; hJoyReleased: (hJoyLast ^ hJoyInput) & hJoyLast
; hJoyPressed: (hJoyLast ^ hJoyInput) & hJoyInput
ld a, [hJoyInput]
+ ld b,a
+ and $4F
cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
jp z, TrySoftReset
diff --git a/engine/overworld/map_sprites.asm b/engine/overworld/map_sprites.asm
index df39d112..747a0a45 100755
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -8,7 +8,7 @@
; fields, respectively, within loops. The X is the loop index.
; If there is an inner loop, Y is the inner loop index, i.e. $C1Y* and $C2Y*
; denote fields of the sprite slots interated over in the inner loop.
-InitMapSprites: ; 1785b (5:785b)
+_InitMapSprites: ; 1785b (5:785b)
call InitOutsideMapSprites
ret c ; return if the map is an outside map (already handled by above call)
; if the map is an inside map (i.e. mapID >= $25)
diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm
index b4247257..71eb297c 100644
--- a/engine/overworld/oam.asm
+++ b/engine/overworld/oam.asm
@@ -176,3 +176,19 @@ Func_4bd1: ; 4bd1 (1:4bd1)
and $f0
ld [de], a ; c1xb (x)
ret
+
+_IsTilePassable:: ; 4aaa (1:4aaa)
+ ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a ; hl now points to passable tiles
+.loop
+ ld a,[hli]
+ cp a,$ff
+ jr z,.tileNotPassable
+ cp c
+ ret z
+ jr .loop
+.tileNotPassable
+ scf
+ ret \ No newline at end of file
diff --git a/engine/play_time.asm b/engine/play_time.asm
deleted file mode 100755
index 74da9c59..00000000
--- a/engine/play_time.asm
+++ /dev/null
@@ -1,61 +0,0 @@
-TrackPlayTime: ; 18dee (6:4dee)
- call CountDownIgnoreInputBitReset
- ld a, [wd732]
- bit 0, a
- ret z
- ld a, [W_PLAYTIMEMINUTES]
- and a
- ret nz
- ld a, [W_PLAYTIMEFRAMES]
- inc a
- ld [W_PLAYTIMEFRAMES], a
- cp 60
- ret nz
- xor a
- ld [W_PLAYTIMEFRAMES], a
- ld a, [W_PLAYTIMESECONDS]
- inc a
- ld [W_PLAYTIMESECONDS], a
- cp 60
- ret nz
- xor a
- ld [W_PLAYTIMESECONDS], a
- ld a, [W_PLAYTIMEMINUTES + 1]
- inc a
- ld [W_PLAYTIMEMINUTES + 1], a
- cp 60
- ret nz
- xor a
- ld [W_PLAYTIMEMINUTES + 1], a
- ld a, [W_PLAYTIMEHOURS + 1]
- inc a
- ld [W_PLAYTIMEHOURS + 1], a
- cp $ff
- ret nz
- ld a, $ff
- ld [W_PLAYTIMEMINUTES], a
- ret
-
-CountDownIgnoreInputBitReset: ; 18e36 (6:4e36)
- ld a, [wIgnoreInputCounter]
- and a
- jr nz, .asm_18e40
- ld a, $ff
- jr .asm_18e41
-.asm_18e40
- dec a
-.asm_18e41
- ld [wIgnoreInputCounter], a
- and a
- ret nz
- ld a, [wd730]
- res 1, a
- res 2, a
- bit 5, a
- res 5, a
- ld [wd730], a
- ret z
- xor a
- ld [hJoyPressed], a
- ld [hJoyHeld], a
- ret
diff --git a/engine/random.asm b/engine/random.asm
index 2fc83f6f..b7fb0edd 100755
--- a/engine/random.asm
+++ b/engine/random.asm
@@ -1,3 +1,5 @@
+SECTION "bank3d",ROMX[$67DC],BANK[$3D]
+
Random_::
; Generate a random 16-bit value.
ld a, [rDIV]
diff --git a/engine/save.asm b/engine/save.asm
index d3127f04..93b70be4 100755
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -37,39 +37,39 @@ LoadSAVCheckSum: ; 73623 (1c:7623)
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
+ ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM
ld bc, $f8b ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jp z, .Func_73652
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jp nz, SAVBadCheckSum
.Func_73652 ; 73652 (1c:7652)
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld de, wPlayerName ; wd158
ld bc, $b
call CopyData
- ld hl, $a5a3
+ ld hl, S_SAVEDMAINDATA
ld de, wPokedexOwned
ld bc, $789
call CopyData
ld hl, W_CURMAPTILESET
set 7, [hl]
- ld hl, $ad2c
+ ld hl, S_SAVEDSPRITEDATA
ld de, wSpriteStateData1
ld bc, $200
call CopyData
- ld a, [$b522]
+ ld a, [S_SAVEDhTilesetType]
ld [hTilesetType], a
- ld hl, $b0c0
+ ld hl, S_SAVEDCURBOXDATA
ld de, W_NUMINBOX
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
@@ -82,14 +82,14 @@ LoadSAVCheckSum1: ; 73690 (1c:7690)
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
+ ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM
ld bc, $f8b ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jr nz, SAVBadCheckSum
- ld hl, $b0c0
+ ld hl, S_SAVEDCURBOXDATA
ld de, W_NUMINBOX
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
@@ -102,18 +102,18 @@ LoadSAVCheckSum2: ; 736bd (1c:76bd)
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
+ ld hl, S_SAVEDPLAYERNAME ; hero name located in SRAM
ld bc, $f8b ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [S_SAVEDMAINDATACHECKSUM] ; SAV's checksum
cp c
jp nz, SAVBadCheckSum
- ld hl, $af2c
+ ld hl, S_SAVEDPARTYDATA
ld de, wPartyCount ; wPartyCount
- ld bc, $194
+ ld bc, wPokedexOwned - wPartyCount
call CopyData
- ld hl, $a5a3
+ ld hl, S_SAVEDMAINDATA
ld de, wPokedexOwned ; wPokedexOwned
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
@@ -199,27 +199,27 @@ SaveSAVtoSRAM0: ; 7378c (1c:778c)
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wPlayerName
- ld de, $a598
+ ld de, S_SAVEDPLAYERNAME
ld bc, $b
call CopyData
ld hl, wPokedexOwned
- ld de, $a5a3
+ ld de, S_SAVEDMAINDATA
ld bc, W_NUMINBOX - wPokedexOwned
call CopyData
ld hl, wSpriteStateData1
- ld de, $ad2c
+ ld de, S_SAVEDSPRITEDATA
ld bc, $200
call CopyData
ld hl, W_NUMINBOX
- ld de, $b0c0
+ ld de, S_SAVEDCURBOXDATA
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
ld a, [hTilesetType]
- ld [$b522], a
- ld hl, $a598
+ ld [S_SAVEDhTilesetType], a
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
- ld [$b523], a
+ ld [S_SAVEDMAINDATACHECKSUM], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
@@ -233,13 +233,13 @@ SaveSAVtoSRAM1: ; 737e2 (1c:77e2)
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, W_NUMINBOX
- ld de, $b0c0
+ ld de, S_SAVEDCURBOXDATA
ld bc, wBoxMonNicksEnd - W_NUMINBOX
call CopyData
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
- ld [$b523], a
+ ld [S_SAVEDMAINDATACHECKSUM], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
@@ -252,17 +252,17 @@ SaveSAVtoSRAM2: ; 7380f (1c:780f)
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wPartyCount
- ld de, $af2c
+ ld de, S_SAVEDPARTYDATA
ld bc, wPokedexOwned - wPartyCount
call CopyData
ld hl, wPokedexOwned ; pokédex only
- ld de, $a5a3
+ ld de, S_SAVEDMAINDATA
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
- ld hl, $a598
+ ld hl, S_SAVEDPLAYERNAME
ld bc, $f8b
call SAVCheckSum
- ld [$b523], a
+ ld [S_SAVEDMAINDATACHECKSUM], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
@@ -292,7 +292,7 @@ SAVCheckSum: ; 73856 (1c:7856)
Func_73863: ; 73863 (1c:7863)
ld hl, $a000
- ld de, $ba4d
+ ld de, S_SAVEDBOXESCHECKSUM2 ; $ba4d
ld b, $6
.asm_7386b
push bc
@@ -327,12 +327,12 @@ Func_7387b: ; 7387b (1c:787b)
ret
PointerTable_73895: ; 73895 (1c:7895)
- dw $A000
- dw $A462
- dw $A8C4
- dw $AD26
- dw $B188
- dw $B5EA
+ dw S_SAVEDBOX1
+ dw S_SAVEDBOX2
+ dw S_SAVEDBOX3
+ dw S_SAVEDBOX4
+ dw S_SAVEDBOX5
+ dw S_SAVEDBOX6
ChangeBox:: ; 738a1 (1c:78a1)
ld hl, WhenYouChangeBoxText
@@ -402,7 +402,7 @@ Func_7390e: ; 7390e (1c:790e)
ld hl, $a000
ld bc, $1a4c
call SAVCheckSum
- ld [$ba4c], a
+ ld [S_SAVEDBOXESCHECKSUM], a
call Func_73863
xor a
ld [MBC1SRamBankingMode], a
@@ -518,22 +518,22 @@ Func_73a29: ; 73a29 (1c:7a29)
ret
Func_73a4b: ; 73a4b (1c:7a4b)
- ld hl, $a000
+ ld hl, S_SAVEDBOX1
call Func_73a7f
- ld hl, $a462
+ ld hl, S_SAVEDBOX2
call Func_73a7f
- ld hl, $a8c4
+ ld hl, S_SAVEDBOX3
call Func_73a7f
- ld hl, $ad26
+ ld hl, S_SAVEDBOX4
call Func_73a7f
- ld hl, $b188
+ ld hl, S_SAVEDBOX5
call Func_73a7f
- ld hl, $b5ea
+ ld hl, S_SAVEDBOX6
call Func_73a7f
- ld hl, $a000
- ld bc, $1a4c
+ ld hl, S_SAVEDBOX1
+ ld bc, $6 * (S_SAVEDBOX2 - S_SAVEDBOX1) ; $1a4c
call SAVCheckSum
- ld [$ba4c], a
+ ld [S_SAVEDBOXESCHECKSUM], a
call Func_73863
ret
@@ -571,17 +571,17 @@ Func_73a84: ; 73a84 (1c:7a84)
ret
Func_73ab8: ; 73ab8 (1c:7ab8)
- ld a, [$a000]
+ ld a, [S_SAVEDBOX1]
ld [hli], a
- ld a, [$a462]
+ ld a, [S_SAVEDBOX2]
ld [hli], a
- ld a, [$a8c4]
+ ld a, [S_SAVEDBOX3]
ld [hli], a
- ld a, [$ad26]
+ ld a, [S_SAVEDBOX4]
ld [hli], a
- ld a, [$b188]
+ ld a, [S_SAVEDBOX5]
ld [hli], a
- ld a, [$b5ea]
+ ld a, [S_SAVEDBOX6]
ld [hli], a
ret
@@ -594,17 +594,17 @@ SAVCheckRandomID: ;$7ad1
ld a,$01
ld [MBC1SRamBankingMode],a
ld [MBC1SRamBank],a
- ld a,[$a598]
+ ld a,[S_SAVEDPLAYERNAME]
and a
jr z,.next
- ld hl,$a598
+ ld hl,S_SAVEDPLAYERNAME
ld bc,$0f8b
call SAVCheckSum
ld c,a
- ld a,[$b523]
+ ld a,[S_SAVEDMAINDATACHECKSUM]
cp c
jr nz,.next
- ld hl,$a605
+ ld hl,S_SAVEDMAINDATA + 98 ; player ID
ld a,[hli]
ld h,[hl]
ld l,a