mirror of
https://github.com/pret/pokeyellow.git
synced 2026-10-02 06:09:20 -05:00
EOL Windows->UNIX
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,440 +1,440 @@
|
||||
; Loads tile patterns for map's sprites.
|
||||
; For outside maps, it loads one of several fixed sets of sprites.
|
||||
; For inside maps, it loads each sprite picture ID used in the map header.
|
||||
; This is also called after displaying text because loading
|
||||
; text tile patterns overwrites half of the sprite tile pattern data.
|
||||
; Note on notation:
|
||||
; $C1X* and $C2X* are used to denote wSpriteStateData1-wSpriteStateData1 + $ff and wSpriteStateData2 + $00-wSpriteStateData2 + $ff sprite slot
|
||||
; 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)
|
||||
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)
|
||||
ld hl,wSpriteStateData1
|
||||
ld de,wSpriteStateData2 + $0d
|
||||
; Loop to copy picture ID's from $C1X0 to $C2XD for LoadMapSpriteTilePatterns.
|
||||
.copyPictureIDLoop
|
||||
ld a,[hl] ; $C1X0 (picture ID)
|
||||
ld [de],a ; $C2XD
|
||||
ld a,$10
|
||||
add e
|
||||
ld e,a
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
jr nz,.copyPictureIDLoop
|
||||
|
||||
; This is used for both inside and outside maps, since it is called by
|
||||
; InitOutsideMapSprites.
|
||||
; Loads tile pattern data for sprites into VRAM.
|
||||
LoadMapSpriteTilePatterns: ; 17871 (5:7871)
|
||||
ld a,[W_NUMSPRITES]
|
||||
and a ; are there any sprites?
|
||||
jr nz,.spritesExist
|
||||
ret
|
||||
.spritesExist
|
||||
ld c,a ; c = [W_NUMSPRITES]
|
||||
ld b,$10 ; number of sprite slots
|
||||
ld hl,wSpriteStateData2 + $0d
|
||||
xor a
|
||||
ld [$ff8e],a ; 4-tile sprite counter
|
||||
.copyPictureIDLoop ; loop to copy picture ID from $C2XD to $C2XE
|
||||
ld a,[hli] ; $C2XD (sprite picture ID)
|
||||
ld [hld],a ; $C2XE
|
||||
ld a,l
|
||||
add a,$10
|
||||
ld l,a
|
||||
dec b
|
||||
jr nz,.copyPictureIDLoop
|
||||
ld hl,wSpriteStateData2 + $1e
|
||||
.loadTilePatternLoop
|
||||
ld de,wSpriteStateData2 + $1d
|
||||
; Check if the current picture ID has already had its tile patterns loaded.
|
||||
; This done by looping through the previous sprite slots and seeing if any of
|
||||
; their picture ID's match that of the current sprite slot.
|
||||
.checkIfAlreadyLoadedLoop
|
||||
ld a,e
|
||||
and a,$f0
|
||||
ld b,a ; b = offset of the wSpriteStateData2 sprite slot being checked against
|
||||
ld a,l
|
||||
and a,$f0 ; a = offset of current wSpriteStateData2 sprite slot
|
||||
cp b ; done checking all previous sprite slots?
|
||||
jr z,.notAlreadyLoaded
|
||||
ld a,[de] ; picture ID of the wSpriteStateData2 sprite slot being checked against
|
||||
cp [hl] ; do the picture ID's match?
|
||||
jp z,.alreadyLoaded
|
||||
ld a,e
|
||||
add a,$10
|
||||
ld e,a
|
||||
jr .checkIfAlreadyLoadedLoop
|
||||
.notAlreadyLoaded
|
||||
ld de,wSpriteStateData2 + $0e
|
||||
ld b,$01
|
||||
; loop to find the highest tile pattern VRAM slot (among the first 10 slots) used by a previous sprite slot
|
||||
; this is done in order to find the first free VRAM slot available
|
||||
.findNextVRAMSlotLoop
|
||||
ld a,e
|
||||
add a,$10
|
||||
ld e,a
|
||||
ld a,l
|
||||
cp e ; reached current slot?
|
||||
jr z,.foundNextVRAMSlot
|
||||
ld a,[de] ; $C2YE (VRAM slot)
|
||||
cp a,11 ; is it one of the first 10 slots?
|
||||
jr nc,.findNextVRAMSlotLoop
|
||||
cp b ; compare the slot being checked to the current max
|
||||
jr c,.findNextVRAMSlotLoop ; if the slot being checked is less than the current max
|
||||
; if the slot being checked is greater than or equal to the current max
|
||||
ld b,a ; store new max VRAM slot
|
||||
jr .findNextVRAMSlotLoop
|
||||
.foundNextVRAMSlot
|
||||
inc b ; increment previous max value to get next VRAM tile pattern slot
|
||||
ld a,b ; a = next VRAM tile pattern slot
|
||||
push af
|
||||
ld a,[hl] ; $C2XE (sprite picture ID)
|
||||
ld b,a ; b = current sprite picture ID
|
||||
cp a,SPRITE_BALL ; is it a 4-tile sprite?
|
||||
jr c,.notFourTileSprite
|
||||
pop af
|
||||
ld a,[$ff8e] ; 4-tile sprite counter
|
||||
add a,11
|
||||
jr .storeVRAMSlot
|
||||
.notFourTileSprite
|
||||
pop af
|
||||
.storeVRAMSlot
|
||||
ld [hl],a ; store VRAM slot at $C2XE
|
||||
ld [$ff8d],a ; used to determine if it's 4-tile sprite later
|
||||
ld a,b ; a = current sprite picture ID
|
||||
dec a
|
||||
add a
|
||||
add a
|
||||
push bc
|
||||
push hl
|
||||
ld hl,SpriteSheetPointerTable
|
||||
jr nc,.noCarry
|
||||
inc h
|
||||
.noCarry
|
||||
add l
|
||||
ld l,a
|
||||
jr nc,.noCarry2
|
||||
inc h
|
||||
.noCarry2
|
||||
push hl
|
||||
call ReadSpriteSheetData
|
||||
push af
|
||||
push de
|
||||
push bc
|
||||
ld hl,vNPCSprites ; VRAM base address
|
||||
ld bc,$c0 ; number of bytes per VRAM slot
|
||||
ld a,[$ff8d]
|
||||
cp a,11 ; is it a 4-tile sprite?
|
||||
jr nc,.fourTileSpriteVRAMAddr
|
||||
ld d,a
|
||||
dec d
|
||||
; Equivalent to multiplying $C0 (number of bytes in 12 tiles) times the VRAM
|
||||
; slot and adding the result to $8000 (the VRAM base address).
|
||||
.calculateVRAMAddrLoop
|
||||
add hl,bc
|
||||
dec d
|
||||
jr nz,.calculateVRAMAddrLoop
|
||||
jr .loadStillTilePattern
|
||||
.fourTileSpriteVRAMAddr
|
||||
ld hl,vSprites + $7c0 ; address for second 4-tile sprite
|
||||
ld a,[$ff8e] ; 4-tile sprite counter
|
||||
and a ; is it the first 4-tile sprite?
|
||||
jr nz,.loadStillTilePattern
|
||||
; if it's the first 4-tile sprite
|
||||
ld hl,vSprites + $780 ; address for first 4-tile sprite
|
||||
inc a
|
||||
ld [$ff8e],a ; 4-tile sprite counter
|
||||
.loadStillTilePattern
|
||||
pop bc
|
||||
pop de
|
||||
pop af
|
||||
push hl
|
||||
push hl
|
||||
ld h,d
|
||||
ld l,e
|
||||
pop de
|
||||
ld b,a
|
||||
ld a,[wFontLoaded]
|
||||
bit 0,a ; reloading upper half of tile patterns after displaying text?
|
||||
jr nz,.skipFirstLoad ; if so, skip loading data into the lower half
|
||||
ld a,b
|
||||
ld b,0
|
||||
call FarCopyData2 ; load tile pattern data for sprite when standing still
|
||||
.skipFirstLoad
|
||||
pop de
|
||||
pop hl
|
||||
ld a,[$ff8d]
|
||||
cp a,11 ; is it a 4-tile sprite?
|
||||
jr nc,.skipSecondLoad ; if so, there is no second block
|
||||
push de
|
||||
call ReadSpriteSheetData
|
||||
push af
|
||||
ld a,$c0
|
||||
add e
|
||||
ld e,a
|
||||
jr nc,.noCarry3
|
||||
inc d
|
||||
.noCarry3
|
||||
ld a,[wFontLoaded]
|
||||
bit 0,a ; reloading upper half of tile patterns after displaying text?
|
||||
jr nz,.loadWhileLCDOn
|
||||
pop af
|
||||
pop hl
|
||||
set 3,h ; add $800 to hl
|
||||
push hl
|
||||
ld h,d
|
||||
ld l,e
|
||||
pop de
|
||||
call FarCopyData2 ; load tile pattern data for sprite when walking
|
||||
jr .skipSecondLoad
|
||||
; When reloading the upper half of tile patterns after diplaying text, the LCD
|
||||
; will be on, so CopyVideoData (which writes to VRAM only during V-blank) must
|
||||
; be used instead of FarCopyData2.
|
||||
.loadWhileLCDOn
|
||||
pop af
|
||||
pop hl
|
||||
set 3,h ; add $800 to hl
|
||||
ld b,a
|
||||
swap c
|
||||
call CopyVideoData ; load tile pattern data for sprite when walking
|
||||
.skipSecondLoad
|
||||
pop hl
|
||||
pop bc
|
||||
jr .nextSpriteSlot
|
||||
.alreadyLoaded ; if the current picture ID has already had its tile patterns loaded
|
||||
inc de
|
||||
ld a,[de] ; a = VRAM slot for the current picture ID (from $C2YE)
|
||||
ld [hl],a ; store VRAM slot in current wSpriteStateData2 sprite slot (at $C2XE)
|
||||
.nextSpriteSlot
|
||||
ld a,l
|
||||
add a,$10
|
||||
ld l,a
|
||||
dec c
|
||||
jp nz,.loadTilePatternLoop
|
||||
ld hl,wSpriteStateData2 + $0d
|
||||
ld b,$10
|
||||
; the pictures ID's stored at $C2XD are no longer needed, so zero them
|
||||
.zeroStoredPictureIDLoop
|
||||
xor a
|
||||
ld [hl],a ; $C2XD
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
dec b
|
||||
jr nz,.zeroStoredPictureIDLoop
|
||||
ret
|
||||
|
||||
; reads data from SpriteSheetPointerTable
|
||||
; INPUT:
|
||||
; hl = address of sprite sheet entry
|
||||
; OUTPUT:
|
||||
; de = pointer to sprite sheet
|
||||
; bc = length in bytes
|
||||
; a = ROM bank
|
||||
ReadSpriteSheetData: ; 17971 (5:7971)
|
||||
ld a,[hli]
|
||||
ld e,a
|
||||
ld a,[hli]
|
||||
ld d,a
|
||||
ld a,[hli]
|
||||
ld c,a
|
||||
xor a
|
||||
ld b,a
|
||||
ld a,[hli]
|
||||
ret
|
||||
|
||||
; Loads sprite set for outside maps (cities and routes) and sets VRAM slots.
|
||||
; sets carry if the map is a city or route, unsets carry if not
|
||||
InitOutsideMapSprites: ; 1797b (5:797b)
|
||||
ld a,[W_CURMAP]
|
||||
cp a,REDS_HOUSE_1F ; is the map a city or a route (map ID less than $25)?
|
||||
ret nc ; if not, return
|
||||
ld hl,MapSpriteSets
|
||||
add l
|
||||
ld l,a
|
||||
jr nc,.noCarry
|
||||
inc h
|
||||
.noCarry
|
||||
ld a,[hl] ; a = spriteSetID
|
||||
cp a,$f0 ; does the map have 2 sprite sets?
|
||||
call nc,GetSplitMapSpriteSetID ; if so, choose the appropriate one
|
||||
ld b,a ; b = spriteSetID
|
||||
ld a,[wFontLoaded]
|
||||
bit 0,a ; reloading upper half of tile patterns after displaying text?
|
||||
jr nz,.loadSpriteSet ; if so, forcibly reload the sprite set
|
||||
ld a,[W_SPRITESETID]
|
||||
cp b ; has the sprite set ID changed?
|
||||
jr z,.skipLoadingSpriteSet ; if not, don't load it again
|
||||
.loadSpriteSet
|
||||
ld a,b
|
||||
ld [W_SPRITESETID],a
|
||||
dec a
|
||||
ld b,a
|
||||
sla a
|
||||
ld c,a
|
||||
sla a
|
||||
sla a
|
||||
add c
|
||||
add b ; a = (spriteSetID - 1) * 11
|
||||
ld de,SpriteSets
|
||||
; add a to de to get offset of sprite set
|
||||
add e
|
||||
ld e,a
|
||||
jr nc,.noCarry2
|
||||
inc d
|
||||
.noCarry2
|
||||
ld hl,wSpriteStateData2 + $0d
|
||||
ld a,SPRITE_RED
|
||||
ld [hl],a
|
||||
ld bc,W_SPRITESET
|
||||
; Load the sprite set into RAM.
|
||||
; This loop also fills $C2XD (sprite picture ID) where X is from $0 to $A
|
||||
; with picture ID's. This is done so that LoadMapSpriteTilePatterns will
|
||||
; load tile patterns for all sprite pictures in the sprite set.
|
||||
.loadSpriteSetLoop
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
ld a,[de] ; sprite picture ID from sprite set
|
||||
ld [hl],a ; $C2XD (sprite picture ID)
|
||||
ld [bc],a
|
||||
inc de
|
||||
inc bc
|
||||
ld a,l
|
||||
cp a,$bd ; reached 11th sprite slot?
|
||||
jr nz,.loadSpriteSetLoop
|
||||
ld b,4 ; 4 remaining sprite slots
|
||||
.zeroRemainingSlotsLoop ; loop to zero the picture ID's of the remaining sprite slots
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
xor a
|
||||
ld [hl],a ; $C2XD (sprite picture ID)
|
||||
dec b
|
||||
jr nz,.zeroRemainingSlotsLoop
|
||||
ld a,[W_NUMSPRITES]
|
||||
push af ; save number of sprites
|
||||
ld a,11 ; 11 sprites in sprite set
|
||||
ld [W_NUMSPRITES],a
|
||||
call LoadMapSpriteTilePatterns
|
||||
pop af
|
||||
ld [W_NUMSPRITES],a ; restore number of sprites
|
||||
ld hl,wSpriteStateData2 + $1e
|
||||
ld b,$0f
|
||||
; The VRAM tile pattern slots that LoadMapSpriteTilePatterns set are in the
|
||||
; order of the map's sprite set, not the order of the actual sprites loaded
|
||||
; for the current map. So, they are not needed and are zeroed by this loop.
|
||||
.zeroVRAMSlotsLoop
|
||||
xor a
|
||||
ld [hl],a ; $C2XE (VRAM slot)
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
dec b
|
||||
jr nz,.zeroVRAMSlotsLoop
|
||||
.skipLoadingSpriteSet
|
||||
ld hl,wSpriteStateData1 + $10
|
||||
; This loop stores the correct VRAM tile pattern slots according the sprite
|
||||
; data from the map's header. Since the VRAM tile pattern slots are filled in
|
||||
; the order of the sprite set, in order to find the VRAM tile pattern slot
|
||||
; for a sprite slot, the picture ID for the sprite is looked up within the
|
||||
; sprite set. The index of the picture ID within the sprite set plus one
|
||||
; (since the Red sprite always has the first VRAM tile pattern slot) is the
|
||||
; VRAM tile pattern slot.
|
||||
.storeVRAMSlotsLoop
|
||||
ld c,0
|
||||
ld a,[hl] ; $C1X0 (picture ID) (zero if sprite slot is not used)
|
||||
and a ; is the sprite slot used?
|
||||
jr z,.skipGettingPictureIndex ; if the sprite slot is not used
|
||||
ld b,a ; b = picture ID
|
||||
ld de,W_SPRITESET
|
||||
; Loop to find the index of the sprite's picture ID within the sprite set.
|
||||
.getPictureIndexLoop
|
||||
inc c
|
||||
ld a,[de]
|
||||
inc de
|
||||
cp b ; does the picture ID match?
|
||||
jr nz,.getPictureIndexLoop
|
||||
inc c
|
||||
.skipGettingPictureIndex
|
||||
push hl
|
||||
inc h
|
||||
ld a,$0e
|
||||
add l
|
||||
ld l,a
|
||||
ld a,c ; a = VRAM slot (zero if sprite slot is not used)
|
||||
ld [hl],a ; $C2XE (VRAM slot)
|
||||
pop hl
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
and a
|
||||
jr nz,.storeVRAMSlotsLoop
|
||||
scf
|
||||
ret
|
||||
|
||||
; Chooses the correct sprite set ID depending on the player's position within
|
||||
; the map for maps with two sprite sets.
|
||||
GetSplitMapSpriteSetID: ; 17a1a (5:7a1a)
|
||||
cp a,$f8
|
||||
jr z,.route20
|
||||
ld hl,SplitMapSpriteSets
|
||||
and a,$0f
|
||||
dec a
|
||||
sla a
|
||||
sla a
|
||||
add l
|
||||
ld l,a
|
||||
jr nc,.noCarry
|
||||
inc h
|
||||
.noCarry
|
||||
ld a,[hli] ; determines whether the map is split East/West or North/South
|
||||
cp a,$01
|
||||
ld a,[hli] ; position of dividing line
|
||||
ld b,a
|
||||
jr z,.eastWestDivide
|
||||
.northSouthDivide
|
||||
ld a,[W_YCOORD]
|
||||
jr .compareCoord
|
||||
.eastWestDivide
|
||||
ld a,[W_XCOORD]
|
||||
.compareCoord
|
||||
cp b
|
||||
jr c,.loadSpriteSetID
|
||||
; if in the East side or South side
|
||||
inc hl
|
||||
.loadSpriteSetID
|
||||
ld a,[hl]
|
||||
ret
|
||||
; Uses sprite set $01 for West side and $0A for East side.
|
||||
; Route 20 is a special case because the two map sections have a more complex
|
||||
; shape instead of the map simply being split horizontally or vertically.
|
||||
.route20
|
||||
ld hl,W_XCOORD
|
||||
ld a,[hl]
|
||||
cp a,$2b
|
||||
ld a,$01
|
||||
ret c
|
||||
ld a,[hl]
|
||||
cp a,$3e
|
||||
ld a,$0a
|
||||
ret nc
|
||||
ld a,[hl]
|
||||
cp a,$37
|
||||
ld b,$08
|
||||
jr nc,.next
|
||||
ld b,$0d
|
||||
.next
|
||||
ld a,[W_YCOORD]
|
||||
cp b
|
||||
ld a,$0a
|
||||
ret c
|
||||
ld a,$01
|
||||
ret
|
||||
|
||||
INCLUDE "data/sprite_sets.asm"
|
||||
; Loads tile patterns for map's sprites.
|
||||
; For outside maps, it loads one of several fixed sets of sprites.
|
||||
; For inside maps, it loads each sprite picture ID used in the map header.
|
||||
; This is also called after displaying text because loading
|
||||
; text tile patterns overwrites half of the sprite tile pattern data.
|
||||
; Note on notation:
|
||||
; $C1X* and $C2X* are used to denote wSpriteStateData1-wSpriteStateData1 + $ff and wSpriteStateData2 + $00-wSpriteStateData2 + $ff sprite slot
|
||||
; 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)
|
||||
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)
|
||||
ld hl,wSpriteStateData1
|
||||
ld de,wSpriteStateData2 + $0d
|
||||
; Loop to copy picture ID's from $C1X0 to $C2XD for LoadMapSpriteTilePatterns.
|
||||
.copyPictureIDLoop
|
||||
ld a,[hl] ; $C1X0 (picture ID)
|
||||
ld [de],a ; $C2XD
|
||||
ld a,$10
|
||||
add e
|
||||
ld e,a
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
jr nz,.copyPictureIDLoop
|
||||
|
||||
; This is used for both inside and outside maps, since it is called by
|
||||
; InitOutsideMapSprites.
|
||||
; Loads tile pattern data for sprites into VRAM.
|
||||
LoadMapSpriteTilePatterns: ; 17871 (5:7871)
|
||||
ld a,[W_NUMSPRITES]
|
||||
and a ; are there any sprites?
|
||||
jr nz,.spritesExist
|
||||
ret
|
||||
.spritesExist
|
||||
ld c,a ; c = [W_NUMSPRITES]
|
||||
ld b,$10 ; number of sprite slots
|
||||
ld hl,wSpriteStateData2 + $0d
|
||||
xor a
|
||||
ld [$ff8e],a ; 4-tile sprite counter
|
||||
.copyPictureIDLoop ; loop to copy picture ID from $C2XD to $C2XE
|
||||
ld a,[hli] ; $C2XD (sprite picture ID)
|
||||
ld [hld],a ; $C2XE
|
||||
ld a,l
|
||||
add a,$10
|
||||
ld l,a
|
||||
dec b
|
||||
jr nz,.copyPictureIDLoop
|
||||
ld hl,wSpriteStateData2 + $1e
|
||||
.loadTilePatternLoop
|
||||
ld de,wSpriteStateData2 + $1d
|
||||
; Check if the current picture ID has already had its tile patterns loaded.
|
||||
; This done by looping through the previous sprite slots and seeing if any of
|
||||
; their picture ID's match that of the current sprite slot.
|
||||
.checkIfAlreadyLoadedLoop
|
||||
ld a,e
|
||||
and a,$f0
|
||||
ld b,a ; b = offset of the wSpriteStateData2 sprite slot being checked against
|
||||
ld a,l
|
||||
and a,$f0 ; a = offset of current wSpriteStateData2 sprite slot
|
||||
cp b ; done checking all previous sprite slots?
|
||||
jr z,.notAlreadyLoaded
|
||||
ld a,[de] ; picture ID of the wSpriteStateData2 sprite slot being checked against
|
||||
cp [hl] ; do the picture ID's match?
|
||||
jp z,.alreadyLoaded
|
||||
ld a,e
|
||||
add a,$10
|
||||
ld e,a
|
||||
jr .checkIfAlreadyLoadedLoop
|
||||
.notAlreadyLoaded
|
||||
ld de,wSpriteStateData2 + $0e
|
||||
ld b,$01
|
||||
; loop to find the highest tile pattern VRAM slot (among the first 10 slots) used by a previous sprite slot
|
||||
; this is done in order to find the first free VRAM slot available
|
||||
.findNextVRAMSlotLoop
|
||||
ld a,e
|
||||
add a,$10
|
||||
ld e,a
|
||||
ld a,l
|
||||
cp e ; reached current slot?
|
||||
jr z,.foundNextVRAMSlot
|
||||
ld a,[de] ; $C2YE (VRAM slot)
|
||||
cp a,11 ; is it one of the first 10 slots?
|
||||
jr nc,.findNextVRAMSlotLoop
|
||||
cp b ; compare the slot being checked to the current max
|
||||
jr c,.findNextVRAMSlotLoop ; if the slot being checked is less than the current max
|
||||
; if the slot being checked is greater than or equal to the current max
|
||||
ld b,a ; store new max VRAM slot
|
||||
jr .findNextVRAMSlotLoop
|
||||
.foundNextVRAMSlot
|
||||
inc b ; increment previous max value to get next VRAM tile pattern slot
|
||||
ld a,b ; a = next VRAM tile pattern slot
|
||||
push af
|
||||
ld a,[hl] ; $C2XE (sprite picture ID)
|
||||
ld b,a ; b = current sprite picture ID
|
||||
cp a,SPRITE_BALL ; is it a 4-tile sprite?
|
||||
jr c,.notFourTileSprite
|
||||
pop af
|
||||
ld a,[$ff8e] ; 4-tile sprite counter
|
||||
add a,11
|
||||
jr .storeVRAMSlot
|
||||
.notFourTileSprite
|
||||
pop af
|
||||
.storeVRAMSlot
|
||||
ld [hl],a ; store VRAM slot at $C2XE
|
||||
ld [$ff8d],a ; used to determine if it's 4-tile sprite later
|
||||
ld a,b ; a = current sprite picture ID
|
||||
dec a
|
||||
add a
|
||||
add a
|
||||
push bc
|
||||
push hl
|
||||
ld hl,SpriteSheetPointerTable
|
||||
jr nc,.noCarry
|
||||
inc h
|
||||
.noCarry
|
||||
add l
|
||||
ld l,a
|
||||
jr nc,.noCarry2
|
||||
inc h
|
||||
.noCarry2
|
||||
push hl
|
||||
call ReadSpriteSheetData
|
||||
push af
|
||||
push de
|
||||
push bc
|
||||
ld hl,vNPCSprites ; VRAM base address
|
||||
ld bc,$c0 ; number of bytes per VRAM slot
|
||||
ld a,[$ff8d]
|
||||
cp a,11 ; is it a 4-tile sprite?
|
||||
jr nc,.fourTileSpriteVRAMAddr
|
||||
ld d,a
|
||||
dec d
|
||||
; Equivalent to multiplying $C0 (number of bytes in 12 tiles) times the VRAM
|
||||
; slot and adding the result to $8000 (the VRAM base address).
|
||||
.calculateVRAMAddrLoop
|
||||
add hl,bc
|
||||
dec d
|
||||
jr nz,.calculateVRAMAddrLoop
|
||||
jr .loadStillTilePattern
|
||||
.fourTileSpriteVRAMAddr
|
||||
ld hl,vSprites + $7c0 ; address for second 4-tile sprite
|
||||
ld a,[$ff8e] ; 4-tile sprite counter
|
||||
and a ; is it the first 4-tile sprite?
|
||||
jr nz,.loadStillTilePattern
|
||||
; if it's the first 4-tile sprite
|
||||
ld hl,vSprites + $780 ; address for first 4-tile sprite
|
||||
inc a
|
||||
ld [$ff8e],a ; 4-tile sprite counter
|
||||
.loadStillTilePattern
|
||||
pop bc
|
||||
pop de
|
||||
pop af
|
||||
push hl
|
||||
push hl
|
||||
ld h,d
|
||||
ld l,e
|
||||
pop de
|
||||
ld b,a
|
||||
ld a,[wFontLoaded]
|
||||
bit 0,a ; reloading upper half of tile patterns after displaying text?
|
||||
jr nz,.skipFirstLoad ; if so, skip loading data into the lower half
|
||||
ld a,b
|
||||
ld b,0
|
||||
call FarCopyData2 ; load tile pattern data for sprite when standing still
|
||||
.skipFirstLoad
|
||||
pop de
|
||||
pop hl
|
||||
ld a,[$ff8d]
|
||||
cp a,11 ; is it a 4-tile sprite?
|
||||
jr nc,.skipSecondLoad ; if so, there is no second block
|
||||
push de
|
||||
call ReadSpriteSheetData
|
||||
push af
|
||||
ld a,$c0
|
||||
add e
|
||||
ld e,a
|
||||
jr nc,.noCarry3
|
||||
inc d
|
||||
.noCarry3
|
||||
ld a,[wFontLoaded]
|
||||
bit 0,a ; reloading upper half of tile patterns after displaying text?
|
||||
jr nz,.loadWhileLCDOn
|
||||
pop af
|
||||
pop hl
|
||||
set 3,h ; add $800 to hl
|
||||
push hl
|
||||
ld h,d
|
||||
ld l,e
|
||||
pop de
|
||||
call FarCopyData2 ; load tile pattern data for sprite when walking
|
||||
jr .skipSecondLoad
|
||||
; When reloading the upper half of tile patterns after diplaying text, the LCD
|
||||
; will be on, so CopyVideoData (which writes to VRAM only during V-blank) must
|
||||
; be used instead of FarCopyData2.
|
||||
.loadWhileLCDOn
|
||||
pop af
|
||||
pop hl
|
||||
set 3,h ; add $800 to hl
|
||||
ld b,a
|
||||
swap c
|
||||
call CopyVideoData ; load tile pattern data for sprite when walking
|
||||
.skipSecondLoad
|
||||
pop hl
|
||||
pop bc
|
||||
jr .nextSpriteSlot
|
||||
.alreadyLoaded ; if the current picture ID has already had its tile patterns loaded
|
||||
inc de
|
||||
ld a,[de] ; a = VRAM slot for the current picture ID (from $C2YE)
|
||||
ld [hl],a ; store VRAM slot in current wSpriteStateData2 sprite slot (at $C2XE)
|
||||
.nextSpriteSlot
|
||||
ld a,l
|
||||
add a,$10
|
||||
ld l,a
|
||||
dec c
|
||||
jp nz,.loadTilePatternLoop
|
||||
ld hl,wSpriteStateData2 + $0d
|
||||
ld b,$10
|
||||
; the pictures ID's stored at $C2XD are no longer needed, so zero them
|
||||
.zeroStoredPictureIDLoop
|
||||
xor a
|
||||
ld [hl],a ; $C2XD
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
dec b
|
||||
jr nz,.zeroStoredPictureIDLoop
|
||||
ret
|
||||
|
||||
; reads data from SpriteSheetPointerTable
|
||||
; INPUT:
|
||||
; hl = address of sprite sheet entry
|
||||
; OUTPUT:
|
||||
; de = pointer to sprite sheet
|
||||
; bc = length in bytes
|
||||
; a = ROM bank
|
||||
ReadSpriteSheetData: ; 17971 (5:7971)
|
||||
ld a,[hli]
|
||||
ld e,a
|
||||
ld a,[hli]
|
||||
ld d,a
|
||||
ld a,[hli]
|
||||
ld c,a
|
||||
xor a
|
||||
ld b,a
|
||||
ld a,[hli]
|
||||
ret
|
||||
|
||||
; Loads sprite set for outside maps (cities and routes) and sets VRAM slots.
|
||||
; sets carry if the map is a city or route, unsets carry if not
|
||||
InitOutsideMapSprites: ; 1797b (5:797b)
|
||||
ld a,[W_CURMAP]
|
||||
cp a,REDS_HOUSE_1F ; is the map a city or a route (map ID less than $25)?
|
||||
ret nc ; if not, return
|
||||
ld hl,MapSpriteSets
|
||||
add l
|
||||
ld l,a
|
||||
jr nc,.noCarry
|
||||
inc h
|
||||
.noCarry
|
||||
ld a,[hl] ; a = spriteSetID
|
||||
cp a,$f0 ; does the map have 2 sprite sets?
|
||||
call nc,GetSplitMapSpriteSetID ; if so, choose the appropriate one
|
||||
ld b,a ; b = spriteSetID
|
||||
ld a,[wFontLoaded]
|
||||
bit 0,a ; reloading upper half of tile patterns after displaying text?
|
||||
jr nz,.loadSpriteSet ; if so, forcibly reload the sprite set
|
||||
ld a,[W_SPRITESETID]
|
||||
cp b ; has the sprite set ID changed?
|
||||
jr z,.skipLoadingSpriteSet ; if not, don't load it again
|
||||
.loadSpriteSet
|
||||
ld a,b
|
||||
ld [W_SPRITESETID],a
|
||||
dec a
|
||||
ld b,a
|
||||
sla a
|
||||
ld c,a
|
||||
sla a
|
||||
sla a
|
||||
add c
|
||||
add b ; a = (spriteSetID - 1) * 11
|
||||
ld de,SpriteSets
|
||||
; add a to de to get offset of sprite set
|
||||
add e
|
||||
ld e,a
|
||||
jr nc,.noCarry2
|
||||
inc d
|
||||
.noCarry2
|
||||
ld hl,wSpriteStateData2 + $0d
|
||||
ld a,SPRITE_RED
|
||||
ld [hl],a
|
||||
ld bc,W_SPRITESET
|
||||
; Load the sprite set into RAM.
|
||||
; This loop also fills $C2XD (sprite picture ID) where X is from $0 to $A
|
||||
; with picture ID's. This is done so that LoadMapSpriteTilePatterns will
|
||||
; load tile patterns for all sprite pictures in the sprite set.
|
||||
.loadSpriteSetLoop
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
ld a,[de] ; sprite picture ID from sprite set
|
||||
ld [hl],a ; $C2XD (sprite picture ID)
|
||||
ld [bc],a
|
||||
inc de
|
||||
inc bc
|
||||
ld a,l
|
||||
cp a,$bd ; reached 11th sprite slot?
|
||||
jr nz,.loadSpriteSetLoop
|
||||
ld b,4 ; 4 remaining sprite slots
|
||||
.zeroRemainingSlotsLoop ; loop to zero the picture ID's of the remaining sprite slots
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
xor a
|
||||
ld [hl],a ; $C2XD (sprite picture ID)
|
||||
dec b
|
||||
jr nz,.zeroRemainingSlotsLoop
|
||||
ld a,[W_NUMSPRITES]
|
||||
push af ; save number of sprites
|
||||
ld a,11 ; 11 sprites in sprite set
|
||||
ld [W_NUMSPRITES],a
|
||||
call LoadMapSpriteTilePatterns
|
||||
pop af
|
||||
ld [W_NUMSPRITES],a ; restore number of sprites
|
||||
ld hl,wSpriteStateData2 + $1e
|
||||
ld b,$0f
|
||||
; The VRAM tile pattern slots that LoadMapSpriteTilePatterns set are in the
|
||||
; order of the map's sprite set, not the order of the actual sprites loaded
|
||||
; for the current map. So, they are not needed and are zeroed by this loop.
|
||||
.zeroVRAMSlotsLoop
|
||||
xor a
|
||||
ld [hl],a ; $C2XE (VRAM slot)
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
dec b
|
||||
jr nz,.zeroVRAMSlotsLoop
|
||||
.skipLoadingSpriteSet
|
||||
ld hl,wSpriteStateData1 + $10
|
||||
; This loop stores the correct VRAM tile pattern slots according the sprite
|
||||
; data from the map's header. Since the VRAM tile pattern slots are filled in
|
||||
; the order of the sprite set, in order to find the VRAM tile pattern slot
|
||||
; for a sprite slot, the picture ID for the sprite is looked up within the
|
||||
; sprite set. The index of the picture ID within the sprite set plus one
|
||||
; (since the Red sprite always has the first VRAM tile pattern slot) is the
|
||||
; VRAM tile pattern slot.
|
||||
.storeVRAMSlotsLoop
|
||||
ld c,0
|
||||
ld a,[hl] ; $C1X0 (picture ID) (zero if sprite slot is not used)
|
||||
and a ; is the sprite slot used?
|
||||
jr z,.skipGettingPictureIndex ; if the sprite slot is not used
|
||||
ld b,a ; b = picture ID
|
||||
ld de,W_SPRITESET
|
||||
; Loop to find the index of the sprite's picture ID within the sprite set.
|
||||
.getPictureIndexLoop
|
||||
inc c
|
||||
ld a,[de]
|
||||
inc de
|
||||
cp b ; does the picture ID match?
|
||||
jr nz,.getPictureIndexLoop
|
||||
inc c
|
||||
.skipGettingPictureIndex
|
||||
push hl
|
||||
inc h
|
||||
ld a,$0e
|
||||
add l
|
||||
ld l,a
|
||||
ld a,c ; a = VRAM slot (zero if sprite slot is not used)
|
||||
ld [hl],a ; $C2XE (VRAM slot)
|
||||
pop hl
|
||||
ld a,$10
|
||||
add l
|
||||
ld l,a
|
||||
and a
|
||||
jr nz,.storeVRAMSlotsLoop
|
||||
scf
|
||||
ret
|
||||
|
||||
; Chooses the correct sprite set ID depending on the player's position within
|
||||
; the map for maps with two sprite sets.
|
||||
GetSplitMapSpriteSetID: ; 17a1a (5:7a1a)
|
||||
cp a,$f8
|
||||
jr z,.route20
|
||||
ld hl,SplitMapSpriteSets
|
||||
and a,$0f
|
||||
dec a
|
||||
sla a
|
||||
sla a
|
||||
add l
|
||||
ld l,a
|
||||
jr nc,.noCarry
|
||||
inc h
|
||||
.noCarry
|
||||
ld a,[hli] ; determines whether the map is split East/West or North/South
|
||||
cp a,$01
|
||||
ld a,[hli] ; position of dividing line
|
||||
ld b,a
|
||||
jr z,.eastWestDivide
|
||||
.northSouthDivide
|
||||
ld a,[W_YCOORD]
|
||||
jr .compareCoord
|
||||
.eastWestDivide
|
||||
ld a,[W_XCOORD]
|
||||
.compareCoord
|
||||
cp b
|
||||
jr c,.loadSpriteSetID
|
||||
; if in the East side or South side
|
||||
inc hl
|
||||
.loadSpriteSetID
|
||||
ld a,[hl]
|
||||
ret
|
||||
; Uses sprite set $01 for West side and $0A for East side.
|
||||
; Route 20 is a special case because the two map sections have a more complex
|
||||
; shape instead of the map simply being split horizontally or vertically.
|
||||
.route20
|
||||
ld hl,W_XCOORD
|
||||
ld a,[hl]
|
||||
cp a,$2b
|
||||
ld a,$01
|
||||
ret c
|
||||
ld a,[hl]
|
||||
cp a,$3e
|
||||
ld a,$0a
|
||||
ret nc
|
||||
ld a,[hl]
|
||||
cp a,$37
|
||||
ld b,$08
|
||||
jr nc,.next
|
||||
ld b,$0d
|
||||
.next
|
||||
ld a,[W_YCOORD]
|
||||
cp b
|
||||
ld a,$0a
|
||||
ret c
|
||||
ld a,$01
|
||||
ret
|
||||
|
||||
INCLUDE "data/sprite_sets.asm"
|
||||
|
||||
372
home/audio.asm
372
home/audio.asm
@@ -1,186 +1,186 @@
|
||||
PlayDefaultMusic:: ; 2307 (0:2307)
|
||||
call WaitForSoundToFinish
|
||||
xor a
|
||||
ld c, a
|
||||
ld d, a
|
||||
ld [wcfca], a
|
||||
jr asm_2324
|
||||
|
||||
Func_2312:: ; 2312 (0:2312)
|
||||
ld c, $a
|
||||
ld d, $0
|
||||
ld a, [wd72e]
|
||||
bit 5, a
|
||||
jr z, asm_2324
|
||||
xor a
|
||||
ld [wcfca], a
|
||||
ld c, $8
|
||||
ld d, c
|
||||
asm_2324:: ; 2324 (0:2324)
|
||||
ld a, [wWalkBikeSurfState]
|
||||
and a
|
||||
jr z, .asm_2343
|
||||
cp $2
|
||||
jr z, .asm_2332
|
||||
ld a, MUSIC_BIKE_RIDING
|
||||
jr .asm_2334
|
||||
.asm_2332
|
||||
ld a, MUSIC_SURFING
|
||||
.asm_2334
|
||||
ld b, a
|
||||
ld a, d
|
||||
and a
|
||||
ld a, BANK(Music_BikeRiding)
|
||||
jr nz, .asm_233e
|
||||
ld [wc0ef], a
|
||||
.asm_233e
|
||||
ld [wc0f0], a
|
||||
jr .asm_234c
|
||||
.asm_2343
|
||||
ld a, [wd35b]
|
||||
ld b, a
|
||||
call Func_2385
|
||||
jr c, .asm_2351
|
||||
.asm_234c
|
||||
ld a, [wcfca]
|
||||
cp b
|
||||
ret z
|
||||
.asm_2351
|
||||
ld a, c
|
||||
ld [wMusicHeaderPointer], a
|
||||
ld a, b
|
||||
ld [wcfca], a
|
||||
ld [wc0ee], a
|
||||
jp PlaySound
|
||||
|
||||
Func_235f:: ; 235f (0:235f)
|
||||
ld a, [wc0ef]
|
||||
ld b, a
|
||||
cp BANK(Music2_UpdateMusic)
|
||||
jr nz, .checkForBank08
|
||||
.bank02
|
||||
ld hl, Music2_UpdateMusic
|
||||
jr .asm_2378
|
||||
.checkForBank08
|
||||
cp BANK(Music8_UpdateMusic)
|
||||
jr nz, .bank1F
|
||||
.bank08
|
||||
ld hl, Music8_UpdateMusic
|
||||
jr .asm_2378
|
||||
.bank1F
|
||||
ld hl, Music1f_UpdateMusic
|
||||
.asm_2378
|
||||
ld c, $6
|
||||
.asm_237a
|
||||
push bc
|
||||
push hl
|
||||
call Bankswitch
|
||||
pop hl
|
||||
pop bc
|
||||
dec c
|
||||
jr nz, .asm_237a
|
||||
ret
|
||||
|
||||
Func_2385:: ; 2385 (0:2385)
|
||||
ld a, [wd35c]
|
||||
ld e, a
|
||||
ld a, [wc0ef]
|
||||
cp e
|
||||
jr nz, .asm_2394
|
||||
ld [wc0f0], a
|
||||
and a
|
||||
ret
|
||||
.asm_2394
|
||||
ld a, c
|
||||
and a
|
||||
ld a, e
|
||||
jr nz, .asm_239c
|
||||
ld [wc0ef], a
|
||||
.asm_239c
|
||||
ld [wc0f0], a
|
||||
scf
|
||||
ret
|
||||
|
||||
PlayMusic:: ; 23a1 (0:23a1)
|
||||
ld b, a
|
||||
ld [wc0ee], a
|
||||
xor a
|
||||
ld [wMusicHeaderPointer], a
|
||||
ld a, c
|
||||
ld [wc0ef], a
|
||||
ld [wc0f0], a
|
||||
ld a, b
|
||||
|
||||
StopAllMusic:: ; 2233 (0:2233)
|
||||
ld a,$FF
|
||||
ld [wc0ee],a
|
||||
; plays music specified by a. If value is $ff, music is stopped
|
||||
PlaySound:: ; 23b1 (0:23b1)
|
||||
push hl
|
||||
push de
|
||||
push bc
|
||||
ld b, a
|
||||
ld a, [wc0ee]
|
||||
and a
|
||||
jr z, .asm_23c8
|
||||
xor a
|
||||
ld [wc02a], a
|
||||
ld [wc02b], a
|
||||
ld [wc02c], a
|
||||
ld [wc02d], a
|
||||
.asm_23c8
|
||||
ld a, [wMusicHeaderPointer]
|
||||
and a
|
||||
jr z, .asm_23e3
|
||||
ld a, [wc0ee]
|
||||
and a
|
||||
jr z, .asm_2425
|
||||
xor a
|
||||
ld [wc0ee], a
|
||||
ld a, [wcfca]
|
||||
cp $ff
|
||||
jr nz, .asm_2414
|
||||
xor a
|
||||
ld [wMusicHeaderPointer], a
|
||||
.asm_23e3
|
||||
xor a
|
||||
ld [wc0ee], a
|
||||
ld a, [H_LOADEDROMBANK]
|
||||
ld [$ffb9], a
|
||||
ld a, [wc0ef]
|
||||
ld [H_LOADEDROMBANK], a
|
||||
ld [$2000], a
|
||||
cp BANK(Func_9876)
|
||||
jr nz, .checkForBank08
|
||||
.bank02
|
||||
ld a, b
|
||||
call Func_9876
|
||||
jr .asm_240b
|
||||
.checkForBank08
|
||||
cp BANK(Func_22035)
|
||||
jr nz, .bank1F
|
||||
.bank08
|
||||
ld a, b
|
||||
call Func_22035
|
||||
jr .asm_240b
|
||||
.bank1F
|
||||
ld a, b
|
||||
call Func_7d8ea
|
||||
.asm_240b
|
||||
ld a, [$ffb9]
|
||||
ld [H_LOADEDROMBANK], a
|
||||
ld [$2000], a
|
||||
jr .asm_2425
|
||||
.asm_2414
|
||||
ld a, b
|
||||
ld [wcfca], a
|
||||
ld a, [wMusicHeaderPointer]
|
||||
ld [wcfc8], a
|
||||
ld [wcfc9], a
|
||||
ld a, b
|
||||
ld [wMusicHeaderPointer], a
|
||||
.asm_2425
|
||||
pop bc
|
||||
pop de
|
||||
pop hl
|
||||
ret
|
||||
PlayDefaultMusic:: ; 2307 (0:2307)
|
||||
call WaitForSoundToFinish
|
||||
xor a
|
||||
ld c, a
|
||||
ld d, a
|
||||
ld [wcfca], a
|
||||
jr asm_2324
|
||||
|
||||
Func_2312:: ; 2312 (0:2312)
|
||||
ld c, $a
|
||||
ld d, $0
|
||||
ld a, [wd72e]
|
||||
bit 5, a
|
||||
jr z, asm_2324
|
||||
xor a
|
||||
ld [wcfca], a
|
||||
ld c, $8
|
||||
ld d, c
|
||||
asm_2324:: ; 2324 (0:2324)
|
||||
ld a, [wWalkBikeSurfState]
|
||||
and a
|
||||
jr z, .asm_2343
|
||||
cp $2
|
||||
jr z, .asm_2332
|
||||
ld a, MUSIC_BIKE_RIDING
|
||||
jr .asm_2334
|
||||
.asm_2332
|
||||
ld a, MUSIC_SURFING
|
||||
.asm_2334
|
||||
ld b, a
|
||||
ld a, d
|
||||
and a
|
||||
ld a, BANK(Music_BikeRiding)
|
||||
jr nz, .asm_233e
|
||||
ld [wc0ef], a
|
||||
.asm_233e
|
||||
ld [wc0f0], a
|
||||
jr .asm_234c
|
||||
.asm_2343
|
||||
ld a, [wd35b]
|
||||
ld b, a
|
||||
call Func_2385
|
||||
jr c, .asm_2351
|
||||
.asm_234c
|
||||
ld a, [wcfca]
|
||||
cp b
|
||||
ret z
|
||||
.asm_2351
|
||||
ld a, c
|
||||
ld [wMusicHeaderPointer], a
|
||||
ld a, b
|
||||
ld [wcfca], a
|
||||
ld [wc0ee], a
|
||||
jp PlaySound
|
||||
|
||||
Func_235f:: ; 235f (0:235f)
|
||||
ld a, [wc0ef]
|
||||
ld b, a
|
||||
cp BANK(Music2_UpdateMusic)
|
||||
jr nz, .checkForBank08
|
||||
.bank02
|
||||
ld hl, Music2_UpdateMusic
|
||||
jr .asm_2378
|
||||
.checkForBank08
|
||||
cp BANK(Music8_UpdateMusic)
|
||||
jr nz, .bank1F
|
||||
.bank08
|
||||
ld hl, Music8_UpdateMusic
|
||||
jr .asm_2378
|
||||
.bank1F
|
||||
ld hl, Music1f_UpdateMusic
|
||||
.asm_2378
|
||||
ld c, $6
|
||||
.asm_237a
|
||||
push bc
|
||||
push hl
|
||||
call Bankswitch
|
||||
pop hl
|
||||
pop bc
|
||||
dec c
|
||||
jr nz, .asm_237a
|
||||
ret
|
||||
|
||||
Func_2385:: ; 2385 (0:2385)
|
||||
ld a, [wd35c]
|
||||
ld e, a
|
||||
ld a, [wc0ef]
|
||||
cp e
|
||||
jr nz, .asm_2394
|
||||
ld [wc0f0], a
|
||||
and a
|
||||
ret
|
||||
.asm_2394
|
||||
ld a, c
|
||||
and a
|
||||
ld a, e
|
||||
jr nz, .asm_239c
|
||||
ld [wc0ef], a
|
||||
.asm_239c
|
||||
ld [wc0f0], a
|
||||
scf
|
||||
ret
|
||||
|
||||
PlayMusic:: ; 23a1 (0:23a1)
|
||||
ld b, a
|
||||
ld [wc0ee], a
|
||||
xor a
|
||||
ld [wMusicHeaderPointer], a
|
||||
ld a, c
|
||||
ld [wc0ef], a
|
||||
ld [wc0f0], a
|
||||
ld a, b
|
||||
|
||||
StopAllMusic:: ; 2233 (0:2233)
|
||||
ld a,$FF
|
||||
ld [wc0ee],a
|
||||
; plays music specified by a. If value is $ff, music is stopped
|
||||
PlaySound:: ; 23b1 (0:23b1)
|
||||
push hl
|
||||
push de
|
||||
push bc
|
||||
ld b, a
|
||||
ld a, [wc0ee]
|
||||
and a
|
||||
jr z, .asm_23c8
|
||||
xor a
|
||||
ld [wc02a], a
|
||||
ld [wc02b], a
|
||||
ld [wc02c], a
|
||||
ld [wc02d], a
|
||||
.asm_23c8
|
||||
ld a, [wMusicHeaderPointer]
|
||||
and a
|
||||
jr z, .asm_23e3
|
||||
ld a, [wc0ee]
|
||||
and a
|
||||
jr z, .asm_2425
|
||||
xor a
|
||||
ld [wc0ee], a
|
||||
ld a, [wcfca]
|
||||
cp $ff
|
||||
jr nz, .asm_2414
|
||||
xor a
|
||||
ld [wMusicHeaderPointer], a
|
||||
.asm_23e3
|
||||
xor a
|
||||
ld [wc0ee], a
|
||||
ld a, [H_LOADEDROMBANK]
|
||||
ld [$ffb9], a
|
||||
ld a, [wc0ef]
|
||||
ld [H_LOADEDROMBANK], a
|
||||
ld [$2000], a
|
||||
cp BANK(Func_9876)
|
||||
jr nz, .checkForBank08
|
||||
.bank02
|
||||
ld a, b
|
||||
call Func_9876
|
||||
jr .asm_240b
|
||||
.checkForBank08
|
||||
cp BANK(Func_22035)
|
||||
jr nz, .bank1F
|
||||
.bank08
|
||||
ld a, b
|
||||
call Func_22035
|
||||
jr .asm_240b
|
||||
.bank1F
|
||||
ld a, b
|
||||
call Func_7d8ea
|
||||
.asm_240b
|
||||
ld a, [$ffb9]
|
||||
ld [H_LOADEDROMBANK], a
|
||||
ld [$2000], a
|
||||
jr .asm_2425
|
||||
.asm_2414
|
||||
ld a, b
|
||||
ld [wcfca], a
|
||||
ld a, [wMusicHeaderPointer]
|
||||
ld [wcfc8], a
|
||||
ld [wcfc9], a
|
||||
ld a, b
|
||||
ld [wMusicHeaderPointer], a
|
||||
.asm_2425
|
||||
pop bc
|
||||
pop de
|
||||
pop hl
|
||||
ret
|
||||
|
||||
272
home/init.asm
272
home/init.asm
@@ -1,136 +1,136 @@
|
||||
SoftReset::
|
||||
call StopAllSounds
|
||||
call GBPalWhiteOut
|
||||
ld c, $20
|
||||
call DelayFrames
|
||||
; fallthrough
|
||||
|
||||
Init::
|
||||
; Program init.
|
||||
|
||||
rLCDC_DEFAULT EQU %11100011
|
||||
; * LCD enabled
|
||||
; * Window tile map at $9C00
|
||||
; * Window display enabled
|
||||
; * BG and window tile data at $8800
|
||||
; * BG tile map at $9800
|
||||
; * 8x8 OBJ size
|
||||
; * OBJ display enabled
|
||||
; * BG display enabled
|
||||
|
||||
di
|
||||
|
||||
xor a
|
||||
ld [rIF], a
|
||||
ld [rIE], a
|
||||
ld [$ff43], a
|
||||
ld [$ff42], a
|
||||
ld [rSB], a
|
||||
ld [rSC], a
|
||||
ld [$ff4b], a
|
||||
ld [$ff4a], a
|
||||
ld [$ff06], a
|
||||
ld [$ff07], a
|
||||
ld [$ff47], a
|
||||
ld [$ff48], a
|
||||
ld [$ff49], a
|
||||
|
||||
ld a, rLCDC_ENABLE_MASK
|
||||
ld [rLCDC], a
|
||||
call DisableLCD
|
||||
|
||||
ld sp, wStack
|
||||
|
||||
ld hl, $c000 ; start of WRAM
|
||||
ld bc, $2000 ; size of WRAM
|
||||
.loop
|
||||
ld [hl], 0
|
||||
inc hl
|
||||
dec bc
|
||||
ld a, b
|
||||
or c
|
||||
jr nz, .loop
|
||||
|
||||
call ClearVram
|
||||
|
||||
ld hl, $ff80
|
||||
ld bc, $ffff - $ff80
|
||||
call FillMemory
|
||||
|
||||
call ClearSprites
|
||||
|
||||
ld a, Bank(WriteDMACodeToHRAM)
|
||||
ld [H_LOADEDROMBANK], a
|
||||
ld [MBC1RomBank], a
|
||||
call WriteDMACodeToHRAM
|
||||
|
||||
xor a
|
||||
ld [hTilesetType], a
|
||||
ld [$ff41], a
|
||||
ld [hSCX], a
|
||||
ld [hSCY], a
|
||||
ld [$ff0f], a
|
||||
ld a, 1 << VBLANK + 1 << TIMER + 1 << SERIAL
|
||||
ld [rIE], a
|
||||
|
||||
ld a, 144 ; move the window off-screen
|
||||
ld [hWY], a
|
||||
ld [rWY], a
|
||||
ld a, 7
|
||||
ld [rWX], a
|
||||
|
||||
ld a, CONNECTION_NOT_ESTABLISHED
|
||||
ld [hSerialConnectionStatus], a
|
||||
|
||||
ld h, vBGMap0 / $100
|
||||
call ClearBgMap
|
||||
ld h, vBGMap1 / $100
|
||||
call ClearBgMap
|
||||
|
||||
ld a, rLCDC_DEFAULT
|
||||
ld [rLCDC], a
|
||||
ld a, 16
|
||||
ld [hSoftReset], a
|
||||
call StopAllSounds
|
||||
|
||||
ei
|
||||
|
||||
predef LoadSGB
|
||||
|
||||
ld a, BANK(SFX_1f_67)
|
||||
ld [wc0ef], a
|
||||
ld [wc0f0], a
|
||||
ld a, $9c
|
||||
ld [$ffbd], a
|
||||
xor a
|
||||
ld [$ffbc], a
|
||||
dec a
|
||||
ld [wUpdateSpritesEnabled], a
|
||||
|
||||
predef PlayIntro
|
||||
|
||||
call DisableLCD
|
||||
call ClearVram
|
||||
call GBPalNormal
|
||||
call ClearSprites
|
||||
ld a, rLCDC_DEFAULT
|
||||
ld [rLCDC], a
|
||||
|
||||
jp SetDefaultNamesBeforeTitlescreen
|
||||
|
||||
ClearVram:
|
||||
ld hl, $8000
|
||||
ld bc, $2000
|
||||
xor a
|
||||
jp FillMemory
|
||||
|
||||
|
||||
StopAllSounds::
|
||||
ld a, BANK(Music2_UpdateMusic)
|
||||
ld [wc0ef], a
|
||||
ld [wc0f0], a
|
||||
xor a
|
||||
ld [wMusicHeaderPointer], a
|
||||
ld [wc0ee], a
|
||||
ld [wcfca], a
|
||||
jp StopAllMusic
|
||||
SoftReset::
|
||||
call StopAllSounds
|
||||
call GBPalWhiteOut
|
||||
ld c, $20
|
||||
call DelayFrames
|
||||
; fallthrough
|
||||
|
||||
Init::
|
||||
; Program init.
|
||||
|
||||
rLCDC_DEFAULT EQU %11100011
|
||||
; * LCD enabled
|
||||
; * Window tile map at $9C00
|
||||
; * Window display enabled
|
||||
; * BG and window tile data at $8800
|
||||
; * BG tile map at $9800
|
||||
; * 8x8 OBJ size
|
||||
; * OBJ display enabled
|
||||
; * BG display enabled
|
||||
|
||||
di
|
||||
|
||||
xor a
|
||||
ld [rIF], a
|
||||
ld [rIE], a
|
||||
ld [$ff43], a
|
||||
ld [$ff42], a
|
||||
ld [rSB], a
|
||||
ld [rSC], a
|
||||
ld [$ff4b], a
|
||||
ld [$ff4a], a
|
||||
ld [$ff06], a
|
||||
ld [$ff07], a
|
||||
ld [$ff47], a
|
||||
ld [$ff48], a
|
||||
ld [$ff49], a
|
||||
|
||||
ld a, rLCDC_ENABLE_MASK
|
||||
ld [rLCDC], a
|
||||
call DisableLCD
|
||||
|
||||
ld sp, wStack
|
||||
|
||||
ld hl, $c000 ; start of WRAM
|
||||
ld bc, $2000 ; size of WRAM
|
||||
.loop
|
||||
ld [hl], 0
|
||||
inc hl
|
||||
dec bc
|
||||
ld a, b
|
||||
or c
|
||||
jr nz, .loop
|
||||
|
||||
call ClearVram
|
||||
|
||||
ld hl, $ff80
|
||||
ld bc, $ffff - $ff80
|
||||
call FillMemory
|
||||
|
||||
call ClearSprites
|
||||
|
||||
ld a, Bank(WriteDMACodeToHRAM)
|
||||
ld [H_LOADEDROMBANK], a
|
||||
ld [MBC1RomBank], a
|
||||
call WriteDMACodeToHRAM
|
||||
|
||||
xor a
|
||||
ld [hTilesetType], a
|
||||
ld [$ff41], a
|
||||
ld [hSCX], a
|
||||
ld [hSCY], a
|
||||
ld [$ff0f], a
|
||||
ld a, 1 << VBLANK + 1 << TIMER + 1 << SERIAL
|
||||
ld [rIE], a
|
||||
|
||||
ld a, 144 ; move the window off-screen
|
||||
ld [hWY], a
|
||||
ld [rWY], a
|
||||
ld a, 7
|
||||
ld [rWX], a
|
||||
|
||||
ld a, CONNECTION_NOT_ESTABLISHED
|
||||
ld [hSerialConnectionStatus], a
|
||||
|
||||
ld h, vBGMap0 / $100
|
||||
call ClearBgMap
|
||||
ld h, vBGMap1 / $100
|
||||
call ClearBgMap
|
||||
|
||||
ld a, rLCDC_DEFAULT
|
||||
ld [rLCDC], a
|
||||
ld a, 16
|
||||
ld [hSoftReset], a
|
||||
call StopAllSounds
|
||||
|
||||
ei
|
||||
|
||||
predef LoadSGB
|
||||
|
||||
ld a, BANK(SFX_1f_67)
|
||||
ld [wc0ef], a
|
||||
ld [wc0f0], a
|
||||
ld a, $9c
|
||||
ld [$ffbd], a
|
||||
xor a
|
||||
ld [$ffbc], a
|
||||
dec a
|
||||
ld [wUpdateSpritesEnabled], a
|
||||
|
||||
predef PlayIntro
|
||||
|
||||
call DisableLCD
|
||||
call ClearVram
|
||||
call GBPalNormal
|
||||
call ClearSprites
|
||||
ld a, rLCDC_DEFAULT
|
||||
ld [rLCDC], a
|
||||
|
||||
jp SetDefaultNamesBeforeTitlescreen
|
||||
|
||||
ClearVram:
|
||||
ld hl, $8000
|
||||
ld bc, $2000
|
||||
xor a
|
||||
jp FillMemory
|
||||
|
||||
|
||||
StopAllSounds::
|
||||
ld a, BANK(Music2_UpdateMusic)
|
||||
ld [wc0ef], a
|
||||
ld [wc0f0], a
|
||||
xor a
|
||||
ld [wMusicHeaderPointer], a
|
||||
ld [wc0ee], a
|
||||
ld [wcfca], a
|
||||
jp StopAllMusic
|
||||
|
||||
4584
home/overworld.asm
4584
home/overworld.asm
File diff suppressed because it is too large
Load Diff
1220
macros.asm
1220
macros.asm
File diff suppressed because it is too large
Load Diff
@@ -1,242 +1,242 @@
|
||||
_AdvancePlayerSprite:: ; f010c (3c:410c)
|
||||
ld a,[wSpriteStateData1 + 3] ; delta Y
|
||||
ld b,a
|
||||
ld a,[wSpriteStateData1 + 5] ; delta X
|
||||
ld c,a
|
||||
ld hl,wWalkCounter ; walking animation counter
|
||||
dec [hl]
|
||||
jr nz,.afterUpdateMapCoords
|
||||
; if it's the end of the animation, update the player's map coordinates
|
||||
ld a,[W_YCOORD]
|
||||
add b
|
||||
ld [W_YCOORD],a
|
||||
ld a,[W_XCOORD]
|
||||
add c
|
||||
ld [W_XCOORD],a
|
||||
.afterUpdateMapCoords
|
||||
ld a,[wWalkCounter] ; walking animation counter
|
||||
cp a,$07
|
||||
jp nz,.scrollBackgroundAndSprites
|
||||
; if this is the first iteration of the animation
|
||||
ld a,c
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingWest
|
||||
; moving east
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
ld e,a
|
||||
and a,$e0
|
||||
ld d,a
|
||||
ld a,e
|
||||
add a,$02
|
||||
and a,$1f
|
||||
or d
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr .adjustXCoordWithinBlock
|
||||
.checkIfMovingWest
|
||||
cp a,$ff
|
||||
jr nz,.checkIfMovingSouth
|
||||
; moving west
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
ld e,a
|
||||
and a,$e0
|
||||
ld d,a
|
||||
ld a,e
|
||||
sub a,$02
|
||||
and a,$1f
|
||||
or d
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr .adjustXCoordWithinBlock
|
||||
.checkIfMovingSouth
|
||||
ld a,b
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingNorth
|
||||
; moving south
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
add a,$40
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr nc,.adjustXCoordWithinBlock
|
||||
ld a,[wMapViewVRAMPointer + 1]
|
||||
inc a
|
||||
and a,$03
|
||||
or a,$98
|
||||
ld [wMapViewVRAMPointer + 1],a
|
||||
jr .adjustXCoordWithinBlock
|
||||
.checkIfMovingNorth
|
||||
cp a,$ff
|
||||
jr nz,.adjustXCoordWithinBlock
|
||||
; moving north
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
sub a,$40
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr nc,.adjustXCoordWithinBlock
|
||||
ld a,[wMapViewVRAMPointer + 1]
|
||||
dec a
|
||||
and a,$03
|
||||
or a,$98
|
||||
ld [wMapViewVRAMPointer + 1],a
|
||||
.adjustXCoordWithinBlock
|
||||
ld a,c
|
||||
and a
|
||||
jr z,.pointlessJump ; mistake?
|
||||
.pointlessJump
|
||||
ld hl,W_XBLOCKCOORD
|
||||
ld a,[hl]
|
||||
add c
|
||||
ld [hl],a
|
||||
cp a,$02
|
||||
jr nz,.checkForMoveToWestBlock
|
||||
; moved into the tile block to the east
|
||||
xor a
|
||||
ld [hl],a
|
||||
ld hl,wXOffsetSinceLastSpecialWarp
|
||||
inc [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
call MoveTileBlockMapPointerEast
|
||||
jr .updateMapView
|
||||
.checkForMoveToWestBlock
|
||||
cp a,$ff
|
||||
jr nz,.adjustYCoordWithinBlock
|
||||
; moved into the tile block to the west
|
||||
ld a,$01
|
||||
ld [hl],a
|
||||
ld hl,wXOffsetSinceLastSpecialWarp
|
||||
dec [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
call MoveTileBlockMapPointerWest
|
||||
jr .updateMapView
|
||||
.adjustYCoordWithinBlock
|
||||
ld hl,W_YBLOCKCOORD
|
||||
ld a,[hl]
|
||||
add b
|
||||
ld [hl],a
|
||||
cp a,$02
|
||||
jr nz,.checkForMoveToNorthBlock
|
||||
; moved into the tile block to the south
|
||||
xor a
|
||||
ld [hl],a
|
||||
ld hl,wYOffsetSinceLastSpecialWarp
|
||||
inc [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
ld a,[W_CURMAPWIDTH]
|
||||
call MoveTileBlockMapPointerSouth
|
||||
jr .updateMapView
|
||||
.checkForMoveToNorthBlock
|
||||
cp a,$ff
|
||||
jr nz,.updateMapView
|
||||
; moved into the tile block to the north
|
||||
ld a,$01
|
||||
ld [hl],a
|
||||
ld hl,wYOffsetSinceLastSpecialWarp
|
||||
dec [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
ld a,[W_CURMAPWIDTH]
|
||||
call MoveTileBlockMapPointerNorth
|
||||
.updateMapView
|
||||
call LoadCurrentMapView
|
||||
ld a,[wSpriteStateData1 + 3] ; delta Y
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingNorth2
|
||||
; if moving south
|
||||
call ScheduleSouthRowRedraw
|
||||
jr .scrollBackgroundAndSprites
|
||||
.checkIfMovingNorth2
|
||||
cp a,$ff
|
||||
jr nz,.checkIfMovingEast2
|
||||
; if moving north
|
||||
call ScheduleNorthRowRedraw
|
||||
jr .scrollBackgroundAndSprites
|
||||
.checkIfMovingEast2
|
||||
ld a,[wSpriteStateData1 + 5] ; delta X
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingWest2
|
||||
; if moving east
|
||||
call ScheduleEastColumnRedraw
|
||||
jr .scrollBackgroundAndSprites
|
||||
.checkIfMovingWest2
|
||||
cp a,$ff
|
||||
jr nz,.scrollBackgroundAndSprites
|
||||
; if moving west
|
||||
call ScheduleWestColumnRedraw
|
||||
.scrollBackgroundAndSprites
|
||||
ld a,[wSpriteStateData1 + 3] ; delta Y
|
||||
ld b,a
|
||||
ld a,[wSpriteStateData1 + 5] ; delta X
|
||||
ld c,a
|
||||
sla b
|
||||
sla c
|
||||
ld a,[hSCY]
|
||||
add b
|
||||
ld [hSCY],a ; update background scroll Y
|
||||
ld a,[hSCX]
|
||||
add c
|
||||
ld [hSCX],a ; update background scroll X
|
||||
; shift all the sprites in the direction opposite of the player's motion
|
||||
; so that the player appears to move relative to them
|
||||
ld hl,wSpriteStateData1 + $14
|
||||
ld a,[W_NUMSPRITES] ; number of sprites
|
||||
and a ; are there any sprites?
|
||||
jr z,.done
|
||||
ld e,a
|
||||
.spriteShiftLoop
|
||||
ld a,[hl]
|
||||
sub b
|
||||
ld [hli],a
|
||||
inc l
|
||||
ld a,[hl]
|
||||
sub c
|
||||
ld [hl],a
|
||||
ld a,$0e
|
||||
add l
|
||||
ld l,a
|
||||
dec e
|
||||
jr nz,.spriteShiftLoop
|
||||
.done
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerEast:: ; 0e65 (0:0e65)
|
||||
ld a,[de]
|
||||
add a,$01
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
inc a
|
||||
ld [de],a
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
|
||||
ld a,[de]
|
||||
sub a,$01
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
dec a
|
||||
ld [de],a
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
|
||||
add a,$06
|
||||
ld b,a
|
||||
ld a,[de]
|
||||
add b
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
inc a
|
||||
ld [de],a
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
|
||||
add a,$06
|
||||
ld b,a
|
||||
ld a,[de]
|
||||
sub b
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
dec a
|
||||
ld [de],a
|
||||
_AdvancePlayerSprite:: ; f010c (3c:410c)
|
||||
ld a,[wSpriteStateData1 + 3] ; delta Y
|
||||
ld b,a
|
||||
ld a,[wSpriteStateData1 + 5] ; delta X
|
||||
ld c,a
|
||||
ld hl,wWalkCounter ; walking animation counter
|
||||
dec [hl]
|
||||
jr nz,.afterUpdateMapCoords
|
||||
; if it's the end of the animation, update the player's map coordinates
|
||||
ld a,[W_YCOORD]
|
||||
add b
|
||||
ld [W_YCOORD],a
|
||||
ld a,[W_XCOORD]
|
||||
add c
|
||||
ld [W_XCOORD],a
|
||||
.afterUpdateMapCoords
|
||||
ld a,[wWalkCounter] ; walking animation counter
|
||||
cp a,$07
|
||||
jp nz,.scrollBackgroundAndSprites
|
||||
; if this is the first iteration of the animation
|
||||
ld a,c
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingWest
|
||||
; moving east
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
ld e,a
|
||||
and a,$e0
|
||||
ld d,a
|
||||
ld a,e
|
||||
add a,$02
|
||||
and a,$1f
|
||||
or d
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr .adjustXCoordWithinBlock
|
||||
.checkIfMovingWest
|
||||
cp a,$ff
|
||||
jr nz,.checkIfMovingSouth
|
||||
; moving west
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
ld e,a
|
||||
and a,$e0
|
||||
ld d,a
|
||||
ld a,e
|
||||
sub a,$02
|
||||
and a,$1f
|
||||
or d
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr .adjustXCoordWithinBlock
|
||||
.checkIfMovingSouth
|
||||
ld a,b
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingNorth
|
||||
; moving south
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
add a,$40
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr nc,.adjustXCoordWithinBlock
|
||||
ld a,[wMapViewVRAMPointer + 1]
|
||||
inc a
|
||||
and a,$03
|
||||
or a,$98
|
||||
ld [wMapViewVRAMPointer + 1],a
|
||||
jr .adjustXCoordWithinBlock
|
||||
.checkIfMovingNorth
|
||||
cp a,$ff
|
||||
jr nz,.adjustXCoordWithinBlock
|
||||
; moving north
|
||||
ld a,[wMapViewVRAMPointer]
|
||||
sub a,$40
|
||||
ld [wMapViewVRAMPointer],a
|
||||
jr nc,.adjustXCoordWithinBlock
|
||||
ld a,[wMapViewVRAMPointer + 1]
|
||||
dec a
|
||||
and a,$03
|
||||
or a,$98
|
||||
ld [wMapViewVRAMPointer + 1],a
|
||||
.adjustXCoordWithinBlock
|
||||
ld a,c
|
||||
and a
|
||||
jr z,.pointlessJump ; mistake?
|
||||
.pointlessJump
|
||||
ld hl,W_XBLOCKCOORD
|
||||
ld a,[hl]
|
||||
add c
|
||||
ld [hl],a
|
||||
cp a,$02
|
||||
jr nz,.checkForMoveToWestBlock
|
||||
; moved into the tile block to the east
|
||||
xor a
|
||||
ld [hl],a
|
||||
ld hl,wXOffsetSinceLastSpecialWarp
|
||||
inc [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
call MoveTileBlockMapPointerEast
|
||||
jr .updateMapView
|
||||
.checkForMoveToWestBlock
|
||||
cp a,$ff
|
||||
jr nz,.adjustYCoordWithinBlock
|
||||
; moved into the tile block to the west
|
||||
ld a,$01
|
||||
ld [hl],a
|
||||
ld hl,wXOffsetSinceLastSpecialWarp
|
||||
dec [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
call MoveTileBlockMapPointerWest
|
||||
jr .updateMapView
|
||||
.adjustYCoordWithinBlock
|
||||
ld hl,W_YBLOCKCOORD
|
||||
ld a,[hl]
|
||||
add b
|
||||
ld [hl],a
|
||||
cp a,$02
|
||||
jr nz,.checkForMoveToNorthBlock
|
||||
; moved into the tile block to the south
|
||||
xor a
|
||||
ld [hl],a
|
||||
ld hl,wYOffsetSinceLastSpecialWarp
|
||||
inc [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
ld a,[W_CURMAPWIDTH]
|
||||
call MoveTileBlockMapPointerSouth
|
||||
jr .updateMapView
|
||||
.checkForMoveToNorthBlock
|
||||
cp a,$ff
|
||||
jr nz,.updateMapView
|
||||
; moved into the tile block to the north
|
||||
ld a,$01
|
||||
ld [hl],a
|
||||
ld hl,wYOffsetSinceLastSpecialWarp
|
||||
dec [hl]
|
||||
ld de,wCurrentTileBlockMapViewPointer
|
||||
ld a,[W_CURMAPWIDTH]
|
||||
call MoveTileBlockMapPointerNorth
|
||||
.updateMapView
|
||||
call LoadCurrentMapView
|
||||
ld a,[wSpriteStateData1 + 3] ; delta Y
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingNorth2
|
||||
; if moving south
|
||||
call ScheduleSouthRowRedraw
|
||||
jr .scrollBackgroundAndSprites
|
||||
.checkIfMovingNorth2
|
||||
cp a,$ff
|
||||
jr nz,.checkIfMovingEast2
|
||||
; if moving north
|
||||
call ScheduleNorthRowRedraw
|
||||
jr .scrollBackgroundAndSprites
|
||||
.checkIfMovingEast2
|
||||
ld a,[wSpriteStateData1 + 5] ; delta X
|
||||
cp a,$01
|
||||
jr nz,.checkIfMovingWest2
|
||||
; if moving east
|
||||
call ScheduleEastColumnRedraw
|
||||
jr .scrollBackgroundAndSprites
|
||||
.checkIfMovingWest2
|
||||
cp a,$ff
|
||||
jr nz,.scrollBackgroundAndSprites
|
||||
; if moving west
|
||||
call ScheduleWestColumnRedraw
|
||||
.scrollBackgroundAndSprites
|
||||
ld a,[wSpriteStateData1 + 3] ; delta Y
|
||||
ld b,a
|
||||
ld a,[wSpriteStateData1 + 5] ; delta X
|
||||
ld c,a
|
||||
sla b
|
||||
sla c
|
||||
ld a,[hSCY]
|
||||
add b
|
||||
ld [hSCY],a ; update background scroll Y
|
||||
ld a,[hSCX]
|
||||
add c
|
||||
ld [hSCX],a ; update background scroll X
|
||||
; shift all the sprites in the direction opposite of the player's motion
|
||||
; so that the player appears to move relative to them
|
||||
ld hl,wSpriteStateData1 + $14
|
||||
ld a,[W_NUMSPRITES] ; number of sprites
|
||||
and a ; are there any sprites?
|
||||
jr z,.done
|
||||
ld e,a
|
||||
.spriteShiftLoop
|
||||
ld a,[hl]
|
||||
sub b
|
||||
ld [hli],a
|
||||
inc l
|
||||
ld a,[hl]
|
||||
sub c
|
||||
ld [hl],a
|
||||
ld a,$0e
|
||||
add l
|
||||
ld l,a
|
||||
dec e
|
||||
jr nz,.spriteShiftLoop
|
||||
.done
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerEast:: ; 0e65 (0:0e65)
|
||||
ld a,[de]
|
||||
add a,$01
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
inc a
|
||||
ld [de],a
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
|
||||
ld a,[de]
|
||||
sub a,$01
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
dec a
|
||||
ld [de],a
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
|
||||
add a,$06
|
||||
ld b,a
|
||||
ld a,[de]
|
||||
add b
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
inc a
|
||||
ld [de],a
|
||||
ret
|
||||
|
||||
MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
|
||||
add a,$06
|
||||
ld b,a
|
||||
ld a,[de]
|
||||
sub b
|
||||
ld [de],a
|
||||
ret nc
|
||||
inc de
|
||||
ld a,[de]
|
||||
dec a
|
||||
ld [de],a
|
||||
ret
|
||||
@@ -1,15 +1,15 @@
|
||||
SECTION "bank3d",ROMX[$67DC],BANK[$3D]
|
||||
|
||||
Random_::
|
||||
; Generate a random 16-bit value.
|
||||
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
|
||||
ret
|
||||
SECTION "bank3d",ROMX[$67DC],BANK[$3D]
|
||||
|
||||
Random_::
|
||||
; Generate a random 16-bit value.
|
||||
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
|
||||
ret
|
||||
|
||||
@@ -1,217 +1,217 @@
|
||||
INCLUDE "yellow/bank3f/data/map_songs.asm"
|
||||
INCLUDE "yellow/bank3f/data/map_header_pointers.asm"
|
||||
INCLUDE "yellow/bank3f/data/map_header_banks.asm"
|
||||
|
||||
Func_fc4dd:: ; fc4dd (3f:44dd)
|
||||
; possibly to test if pika should be out?
|
||||
ld a,[wd430]
|
||||
bit 5,a
|
||||
jr nz,.asm_fc4f8 ; 3f:44f8
|
||||
ld a,[wd430]
|
||||
bit 7,a
|
||||
jr nz,.asm_fc4f8
|
||||
call Func_fcdb8
|
||||
jr nc,.asm_fc4f8
|
||||
ld a,[wWalkBikeSurfState]
|
||||
and a
|
||||
jr nz,.asm_fc4f8
|
||||
scf
|
||||
ret
|
||||
.asm_fc4f8
|
||||
and a
|
||||
ret
|
||||
|
||||
Func_fc5fa:: ; fc5fa (3f:44fa)
|
||||
ld hl,wd430
|
||||
bit 4,[hl]
|
||||
res 4,[hl]
|
||||
jr nz,.asm_fc515
|
||||
call Func_1542
|
||||
call Func_fc523
|
||||
ld a,$ff
|
||||
ld [wSpriteStateData1 + $f2],a
|
||||
call Func_fcb84
|
||||
call Func_fc5bc
|
||||
ret
|
||||
|
||||
.asm_fc515
|
||||
call Func_fc53f
|
||||
xor a
|
||||
ld [wd431],a
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
|
||||
Func_fc523:: ; fc523 (3f:4523)
|
||||
ld hl,wSpriteStateData1 + $f0
|
||||
call Func_fc52c
|
||||
ld hl,wSpriteStateData2 + $f0
|
||||
Func_fc52c:: ; fc52c (3f:4523)
|
||||
ld bc,$10
|
||||
xor a
|
||||
call FillMemory
|
||||
ret
|
||||
|
||||
Func_fc534:: ; fc534 (3f:4534)
|
||||
call Func_fc53f
|
||||
call Func_fc5bc
|
||||
xor a
|
||||
ld [wd431],a
|
||||
ret
|
||||
|
||||
Func_fc53f:: ; fc53f (3f:453f)
|
||||
ld bc,wSpriteStateData1 + $10
|
||||
ld a,[W_YCOORD]
|
||||
add $4
|
||||
ld e,a
|
||||
ld a,[W_XCOORD]
|
||||
add $4
|
||||
ld d,a
|
||||
ld a,[wd431]
|
||||
and a
|
||||
jr z,.asm_fc5aa
|
||||
cp $1
|
||||
jr z,.asm_fc59e
|
||||
cp $2
|
||||
jr z,.asm_fc584
|
||||
cp $3
|
||||
jr z,.asm_fc5aa
|
||||
cp $4
|
||||
jr z,.asm_fc5a4
|
||||
cp $5
|
||||
jr z,.asm_fc5a7
|
||||
cp $6
|
||||
jr z,.asm_fc5a1
|
||||
cp $7
|
||||
jr z,.asm_fc572
|
||||
jr .asm_fc59e
|
||||
|
||||
.asm_fc572
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a ; SPRITE_FACING_DOWN
|
||||
jr z,.asm_fc5a4
|
||||
cp SPRITE_FACING_UP
|
||||
jr z,.asm_fc5a7
|
||||
cp SPRITE_FACING_LEFT
|
||||
jr z,.asm_fc5a1
|
||||
cp SPRITE_FACING_RIGHT
|
||||
jr z,.asm_fc59e
|
||||
.asm_fc584
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a
|
||||
jr nz,.asm_fc58d
|
||||
dec e
|
||||
jr .asm_fc5aa
|
||||
.asm_fc58d
|
||||
cp SPRITE_FACING_UP
|
||||
jr nz,.asm_fc594
|
||||
inc e
|
||||
jr .asm_fc5aa
|
||||
.asm_fc594
|
||||
cp SPRITE_FACING_LEFT
|
||||
jr nz,.asm_fc59b
|
||||
inc d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc59b
|
||||
dec d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc59e
|
||||
inc d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc5a1
|
||||
dec d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc5a4
|
||||
inc e
|
||||
jr .asm_fc5aa
|
||||
.asm_fc5a7
|
||||
dec e
|
||||
jr .asm_fc5aa ; useless jr
|
||||
.asm_fc5aa
|
||||
ld hl,$104
|
||||
add hl,bc
|
||||
ld [hl],e
|
||||
inc hl
|
||||
ld [hl],d
|
||||
inc hl
|
||||
Func_fc4b2:: ; fc4b2 (3f:44b2)
|
||||
ld [hl],$fe
|
||||
push hl
|
||||
ld hl,wd472
|
||||
set 5,[hl]
|
||||
pop hl
|
||||
ret
|
||||
|
||||
Func_fc5bc:: ; fc5bc (3f:45bc)
|
||||
ld a,$49
|
||||
ld [wSpriteStateData1 + $f0],a
|
||||
ld a,$ff
|
||||
ld [wSpriteStateData1 + $f2],a
|
||||
ld a,[wd431]
|
||||
and a
|
||||
jr z,.asm_fc5e4
|
||||
cp $1
|
||||
jr z,.asm_fc5e4
|
||||
cp $3
|
||||
jr z,.asm_fc5eb
|
||||
cp $4
|
||||
jr z,.asm_fc5e4
|
||||
cp $6
|
||||
jr z,.asm_fc5e4
|
||||
cp $7
|
||||
jr z,.asm_fc5f1
|
||||
call Func_fc4b2
|
||||
ret
|
||||
|
||||
.asm_fc5e4
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
.asm_fc5eb
|
||||
ld a,$0
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
.asm_fc5f1
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
xor $4
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
|
||||
Func_fc5fa:: ; fc5fa (3f:45fa)
|
||||
ld a,[W_CURMAP]
|
||||
cp OAKS_LAB
|
||||
jr z,.asm_fc63d
|
||||
cp ROUTE_22_GATE
|
||||
jr z,.asm_fc62d
|
||||
cp MT_MOON_2
|
||||
jr z,.asm_fc635
|
||||
cp ROCK_TUNNEL_1
|
||||
jr z,.asm_fc645
|
||||
ld a,[W_CURMAP]
|
||||
ld hl,Pointer_fc46b
|
||||
call Func_1568 ; similar to IsInArray, but not the same
|
||||
jr c,.asm_fc639
|
||||
ld a,[W_CURMAP]
|
||||
ld hl,Pointer_fc653
|
||||
call Func_1568
|
||||
jr nc,.asm_fc641
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a
|
||||
jr nz,.asm_fc641
|
||||
ld a,$3
|
||||
jr .asm_fc647
|
||||
|
||||
.asm_fc62d
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a
|
||||
jr z,.asm_fc645
|
||||
jr .asm_fc641
|
||||
.asm_fc635
|
||||
|
||||
Func_fc65b:: ; fc65b (3f:465b)
|
||||
|
||||
Func_fc69a:: ; fc69a (3f:469a)
|
||||
|
||||
Func_fcc08:: ; fcc08 (3f:4c08)
|
||||
|
||||
Func_fcf0c:: ; fcf0c (3f:4f0c)
|
||||
INCLUDE "yellow/bank3f/data/map_songs.asm"
|
||||
INCLUDE "yellow/bank3f/data/map_header_pointers.asm"
|
||||
INCLUDE "yellow/bank3f/data/map_header_banks.asm"
|
||||
|
||||
Func_fc4dd:: ; fc4dd (3f:44dd)
|
||||
; possibly to test if pika should be out?
|
||||
ld a,[wd430]
|
||||
bit 5,a
|
||||
jr nz,.asm_fc4f8 ; 3f:44f8
|
||||
ld a,[wd430]
|
||||
bit 7,a
|
||||
jr nz,.asm_fc4f8
|
||||
call Func_fcdb8
|
||||
jr nc,.asm_fc4f8
|
||||
ld a,[wWalkBikeSurfState]
|
||||
and a
|
||||
jr nz,.asm_fc4f8
|
||||
scf
|
||||
ret
|
||||
.asm_fc4f8
|
||||
and a
|
||||
ret
|
||||
|
||||
Func_fc5fa:: ; fc5fa (3f:44fa)
|
||||
ld hl,wd430
|
||||
bit 4,[hl]
|
||||
res 4,[hl]
|
||||
jr nz,.asm_fc515
|
||||
call Func_1542
|
||||
call Func_fc523
|
||||
ld a,$ff
|
||||
ld [wSpriteStateData1 + $f2],a
|
||||
call Func_fcb84
|
||||
call Func_fc5bc
|
||||
ret
|
||||
|
||||
.asm_fc515
|
||||
call Func_fc53f
|
||||
xor a
|
||||
ld [wd431],a
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
|
||||
Func_fc523:: ; fc523 (3f:4523)
|
||||
ld hl,wSpriteStateData1 + $f0
|
||||
call Func_fc52c
|
||||
ld hl,wSpriteStateData2 + $f0
|
||||
Func_fc52c:: ; fc52c (3f:4523)
|
||||
ld bc,$10
|
||||
xor a
|
||||
call FillMemory
|
||||
ret
|
||||
|
||||
Func_fc534:: ; fc534 (3f:4534)
|
||||
call Func_fc53f
|
||||
call Func_fc5bc
|
||||
xor a
|
||||
ld [wd431],a
|
||||
ret
|
||||
|
||||
Func_fc53f:: ; fc53f (3f:453f)
|
||||
ld bc,wSpriteStateData1 + $10
|
||||
ld a,[W_YCOORD]
|
||||
add $4
|
||||
ld e,a
|
||||
ld a,[W_XCOORD]
|
||||
add $4
|
||||
ld d,a
|
||||
ld a,[wd431]
|
||||
and a
|
||||
jr z,.asm_fc5aa
|
||||
cp $1
|
||||
jr z,.asm_fc59e
|
||||
cp $2
|
||||
jr z,.asm_fc584
|
||||
cp $3
|
||||
jr z,.asm_fc5aa
|
||||
cp $4
|
||||
jr z,.asm_fc5a4
|
||||
cp $5
|
||||
jr z,.asm_fc5a7
|
||||
cp $6
|
||||
jr z,.asm_fc5a1
|
||||
cp $7
|
||||
jr z,.asm_fc572
|
||||
jr .asm_fc59e
|
||||
|
||||
.asm_fc572
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a ; SPRITE_FACING_DOWN
|
||||
jr z,.asm_fc5a4
|
||||
cp SPRITE_FACING_UP
|
||||
jr z,.asm_fc5a7
|
||||
cp SPRITE_FACING_LEFT
|
||||
jr z,.asm_fc5a1
|
||||
cp SPRITE_FACING_RIGHT
|
||||
jr z,.asm_fc59e
|
||||
.asm_fc584
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a
|
||||
jr nz,.asm_fc58d
|
||||
dec e
|
||||
jr .asm_fc5aa
|
||||
.asm_fc58d
|
||||
cp SPRITE_FACING_UP
|
||||
jr nz,.asm_fc594
|
||||
inc e
|
||||
jr .asm_fc5aa
|
||||
.asm_fc594
|
||||
cp SPRITE_FACING_LEFT
|
||||
jr nz,.asm_fc59b
|
||||
inc d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc59b
|
||||
dec d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc59e
|
||||
inc d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc5a1
|
||||
dec d
|
||||
jr .asm_fc5aa
|
||||
.asm_fc5a4
|
||||
inc e
|
||||
jr .asm_fc5aa
|
||||
.asm_fc5a7
|
||||
dec e
|
||||
jr .asm_fc5aa ; useless jr
|
||||
.asm_fc5aa
|
||||
ld hl,$104
|
||||
add hl,bc
|
||||
ld [hl],e
|
||||
inc hl
|
||||
ld [hl],d
|
||||
inc hl
|
||||
Func_fc4b2:: ; fc4b2 (3f:44b2)
|
||||
ld [hl],$fe
|
||||
push hl
|
||||
ld hl,wd472
|
||||
set 5,[hl]
|
||||
pop hl
|
||||
ret
|
||||
|
||||
Func_fc5bc:: ; fc5bc (3f:45bc)
|
||||
ld a,$49
|
||||
ld [wSpriteStateData1 + $f0],a
|
||||
ld a,$ff
|
||||
ld [wSpriteStateData1 + $f2],a
|
||||
ld a,[wd431]
|
||||
and a
|
||||
jr z,.asm_fc5e4
|
||||
cp $1
|
||||
jr z,.asm_fc5e4
|
||||
cp $3
|
||||
jr z,.asm_fc5eb
|
||||
cp $4
|
||||
jr z,.asm_fc5e4
|
||||
cp $6
|
||||
jr z,.asm_fc5e4
|
||||
cp $7
|
||||
jr z,.asm_fc5f1
|
||||
call Func_fc4b2
|
||||
ret
|
||||
|
||||
.asm_fc5e4
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
.asm_fc5eb
|
||||
ld a,$0
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
.asm_fc5f1
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
xor $4
|
||||
ld [wSpriteStateData1 + $f9],a
|
||||
ret
|
||||
|
||||
Func_fc5fa:: ; fc5fa (3f:45fa)
|
||||
ld a,[W_CURMAP]
|
||||
cp OAKS_LAB
|
||||
jr z,.asm_fc63d
|
||||
cp ROUTE_22_GATE
|
||||
jr z,.asm_fc62d
|
||||
cp MT_MOON_2
|
||||
jr z,.asm_fc635
|
||||
cp ROCK_TUNNEL_1
|
||||
jr z,.asm_fc645
|
||||
ld a,[W_CURMAP]
|
||||
ld hl,Pointer_fc46b
|
||||
call Func_1568 ; similar to IsInArray, but not the same
|
||||
jr c,.asm_fc639
|
||||
ld a,[W_CURMAP]
|
||||
ld hl,Pointer_fc653
|
||||
call Func_1568
|
||||
jr nc,.asm_fc641
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a
|
||||
jr nz,.asm_fc641
|
||||
ld a,$3
|
||||
jr .asm_fc647
|
||||
|
||||
.asm_fc62d
|
||||
ld a,[wSpriteStateData1 + $9]
|
||||
and a
|
||||
jr z,.asm_fc645
|
||||
jr .asm_fc641
|
||||
.asm_fc635
|
||||
|
||||
Func_fc65b:: ; fc65b (3f:465b)
|
||||
|
||||
Func_fc69a:: ; fc69a (3f:469a)
|
||||
|
||||
Func_fcc08:: ; fcc08 (3f:4c08)
|
||||
|
||||
Func_fcf0c:: ; fcf0c (3f:4f0c)
|
||||
|
||||
Reference in New Issue
Block a user