summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZumi Daxuya <daxuya.zumi+code@protonmail.com>2021-05-16 14:19:50 +0700
committerZumi Daxuya <daxuya.zumi+code@protonmail.com>2021-05-16 14:22:32 +0700
commit9b6130052de39c7ce09b899cb495db50bc5b4020 (patch)
tree8ab3c6578a2a75b0a3bf5ee1f532a5fbef9eaeb3
parente7e6b3624829144be2145fc6792790f5cb4dff6c (diff)
Disassemble more OW sprite routines
-rw-r--r--constants/map_data_constants.asm3
-rw-r--r--engine/sprites/sprites.asm191
-rw-r--r--layout.link6
-rw-r--r--ram/wram.asm11
-rwxr-xr-xshim.sym7
5 files changed, 202 insertions, 16 deletions
diff --git a/constants/map_data_constants.asm b/constants/map_data_constants.asm
index cc29753..85be273 100644
--- a/constants/map_data_constants.asm
+++ b/constants/map_data_constants.asm
@@ -72,3 +72,6 @@ NUM_SPAWNS EQU 18
; size of each spawn point data
SPAWN_POINT_SIZE EQU 4
+
+; size of sprite sets (see data/maps/sprite_sets.asm)
+SPRITE_SET_LENGTH EQU 10
diff --git a/engine/sprites/sprites.asm b/engine/sprites/sprites.asm
index f17e68f..87bf7b3 100644
--- a/engine/sprites/sprites.asm
+++ b/engine/sprites/sprites.asm
@@ -1,6 +1,195 @@
INCLUDE "constants.asm"
-SECTION "engine/sprites/sprites.asm@LoadOverworldSprite", ROMX
+SECTION "engine/sprites/sprites.asm@RefreshSprites", ROMX
+
+RefreshSprites:
+ call GetPlayerSprite
+ call CheckInteriorMap
+ jr c, .outdoor
+ call AddIndoorSprites
+ call LoadUsedSpritesGfx
+ ret
+.outdoor
+ call AddOutdoorSprites
+ call LoadUsedSpritesGfx
+ ret
+
+CheckInteriorMap:
+ call GetMapEnvironment
+ cp TOWN
+ jr z, .got_outdoor
+ cp ROUTE
+ jr z, .got_outdoor
+ xor a
+ ret
+.got_outdoor
+ scf
+ ret
+
+AddIndoorSprites:
+ ld hl, wUsedNPCSprites
+ ld bc, SPRITE_SET_LENGTH
+ xor a
+ call ByteFill
+ ld a, [wPlayerObjectSprite]
+ ld [wUsedSprites], a
+ ld hl, wMap2ObjectSprite
+ ld a, 2
+.asm_14070
+ push af
+ ld a, [hl]
+ and a
+ jr z, .asm_1408d
+ ld c, a
+ call IsAnimatedSprite
+ jr nc, .static_sprite
+ ld de, wUsedStaticSprites
+ ld b, 2
+ call Function14099
+ jr .asm_1408d
+.static_sprite
+ ld de, wUsedNPCSprites
+ ld b, 8
+ call Function14099
+.asm_1408d
+ ld de, $10
+ add hl, de
+ pop af
+ inc a
+ cp $10
+ jp nz, .asm_14070
+ ret
+
+Function14099:
+.loop
+ ld a, [de]
+ and a
+ jr z, .asm_140a5
+ cp c
+ ret z
+ dec b
+ jr z, .asm_140a8
+ inc de
+ jr .loop
+
+.asm_140a5
+ ld a, c
+ ld [de], a
+ ret
+
+.asm_140a8
+ scf
+ ret
+
+
+AddOutdoorSprites:
+ ld a, [wPlayerObjectSprite]
+ ld [wUsedSprites], a
+ ld a, [wMapGroup]
+ dec a
+ ld c, a
+ ld b, 0
+ ld hl, MapGroupSpriteSets
+ add hl, bc
+ ld a, [hl]
+ push af
+ dec a
+ ld hl, SpriteSets
+ ld bc, SPRITE_SET_LENGTH
+ call AddNTimes
+ ld de, wUsedNPCSprites
+ ld bc, SPRITE_SET_LENGTH
+ call CopyBytes
+ ld a, [wd642]
+ ld c, a
+ pop af
+ ld [wd642], a
+ ret
+
+Function140d9:
+ ld hl, wcdaf
+ ld a, [hl]
+ push af
+ res 7, [hl]
+ set 6, [hl]
+ call LoadUsedSpritesGfx
+ pop af
+ ld [wcdaf], a
+ ret
+
+Function140ea:
+ ld hl, wcdaf
+ ld a, [hl]
+ push af
+ set 7, [hl]
+ res 6, [hl]
+ call LoadUsedSpritesGfx
+ pop af
+ ld [wcdaf], a
+ ret
+
+LoadUsedSpritesGfx:
+ ld hl, vNPCSprites
+ ld de, wUsedSprites
+ ld b, SPRITE_SET_LENGTH
+ ld c, 0
+.asm_14105
+ push bc
+ push de
+ push hl
+ ld a, [de]
+ and a
+ jr z, .asm_1410f
+ call LoadOverworldSprite
+.asm_1410f
+ pop hl
+ ld bc, $c0
+ add hl, bc
+ pop de
+ inc de
+ pop bc
+ inc c
+ dec b
+ jr nz, .asm_14105
+ ld a, [de]
+ and a
+ jr z, .asm_14127
+ push de
+ ld hl, vNPCSprites + $780
+ call LoadOverworldSprite
+ pop de
+.asm_14127
+ inc de
+ ld a, [de]
+ and a
+ jr z, .asm_14132
+ ld hl, vNPCSprites + $7c0
+ call LoadOverworldSprite
+.asm_14132
+ ret
+
+Function14133:
+ swap b
+ ld a, b
+ and $f0
+ ld e, a
+ ld a, b
+ and $f
+ ld d, a
+ ld hl, vNPCSprites
+ add hl, de
+ ld a, c
+ jr LoadOverworldSprite
+
+Function14144:
+ ld a, c
+ ld hl, vNPCSprites
+ jr LoadOverworldSprite
+
+Function1414a:
+ ld a, c
+ ld hl, vNPCSprites + $c0
+ jr LoadOverworldSprite
LoadOverworldSprite:
push af
diff --git a/layout.link b/layout.link
index b825119..077f313 100644
--- a/layout.link
+++ b/layout.link
@@ -178,11 +178,9 @@ ROMX $04
ROMX $05
org $4000
"engine/overworld/player_movement.asm@_RedrawPlayerSprite"
- org $4150
- "engine/sprites/sprites.asm@LoadOverworldSprite"
- org $4193
+ org $4036
+ "engine/sprites/sprites.asm@RefreshSprites"
"data/maps/sprite_sets.asm"
- org $423b
"data/overworld_sprites.asm"
org $477d
"engine/events/pokecenter_pc.asm"
diff --git a/ram/wram.asm b/ram/wram.asm
index e6c6d34..1ba561b 100644
--- a/ram/wram.asm
+++ b/ram/wram.asm
@@ -1312,16 +1312,19 @@ SECTION "D637", WRAM0[$D637]
wd637:: db ;OW battle state? $3 wild battle, $8 is trainer battle $4 is left battle, $B is load overworld? $0 is in overworld
wd638:: db ;wd637's last written-to value
-SECTION "Used sprites", WRAM0[$D643]
-
+SECTION "Used sprites", WRAM0[$D642]
+wd642:: db
wBGMapAnchor::
dw
wUsedSprites::
- dw ; This is for the player
+ ds 2
wUsedNPCSprites::
- ds 2 * 5 ; This is for the NPCs
+ ds 8
+
+wUsedStaticSprites::
+ ds 2
wUsedSpritesEnd::
diff --git a/shim.sym b/shim.sym
index 5d9261e..a2f9e4e 100755
--- a/shim.sym
+++ b/shim.sym
@@ -1,10 +1,3 @@
-05:4036 RefreshSprites
-05:404C CheckInteriorMap
-05:405B AddIndoorSprites
-05:40AA AddOutdoorSprites
-05:40D9 Function140d9
-05:40EA Function140ea
-05:40FB LoadUsedSpritesGfx ; TODO: maybe there's a better name
05:43B6 InitAllSRAMBanks
05:43E0 Function143e0
05:457A Function1457a