pokecrystal-board/engine/save.asm

1204 lines
20 KiB
NASM
Raw Normal View History

2015-11-17 14:56:49 -08:00
SaveMenu: ; 14a1a
2015-11-11 13:11:08 -08:00
call LoadStandardMenuDataHeader
2015-11-20 08:47:52 -08:00
callba DisplaySaveInfoOnSave
2015-08-19 10:13:48 -07:00
call SpeechTextBox
call UpdateSprites
2015-11-20 08:47:52 -08:00
callba SaveMenu_LoadEDTile
ld hl, Text_WouldYouLikeToSaveTheGame
2015-08-19 10:13:48 -07:00
call SaveTheGame_yesorno
jr nz, .refused
2015-11-17 20:29:14 -08:00
call AskOverwriteSaveFile
2015-08-19 10:13:48 -07:00
jr c, .refused
call PauseGameLogic
2015-08-19 10:13:48 -07:00
call _SavingDontTurnOffThePower
call ResumeGameLogic
2015-08-19 10:13:48 -07:00
call ExitMenu
and a
ret
2015-11-17 20:29:14 -08:00
2015-08-19 10:13:48 -07:00
.refused
call ExitMenu
2015-12-09 08:38:40 -08:00
call ret_d90
2015-11-20 08:47:52 -08:00
callba SaveMenu_LoadEDTile
2015-08-19 10:13:48 -07:00
scf
ret
SaveAfterLinkTrade: ; 14a58
call PauseGameLogic
2015-11-17 20:29:14 -08:00
callba StageRTCTimeForSave
callba BackupMysteryGift
2015-08-19 21:14:15 -07:00
call SavePokemonData
2015-11-17 20:29:14 -08:00
call SaveChecksum
2015-08-19 21:14:15 -07:00
call SaveBackupPokemonData
call SaveBackupChecksum
2015-11-17 14:56:49 -08:00
callba BackupPartyMonMail
2015-11-17 20:29:14 -08:00
callba SaveRTC
call ResumeGameLogic
2015-08-19 10:13:48 -07:00
ret
; 14a83
2015-11-17 20:29:14 -08:00
ChangeBoxSaveGame: ; 14a83 (5:4a83)
2015-08-19 10:13:48 -07:00
push de
ld hl, Text_SaveOnBoxSwitch
2015-08-19 10:13:48 -07:00
call MenuTextBox
call YesNoBox
call ExitMenu
jr c, .refused
2015-11-17 20:29:14 -08:00
call AskOverwriteSaveFile
2015-08-19 10:13:48 -07:00
jr c, .refused
call PauseGameLogic
2015-08-19 10:13:48 -07:00
call SavingDontTurnOffThePower
2015-08-19 21:14:15 -07:00
call SaveBox
2015-08-19 10:13:48 -07:00
pop de
ld a, e
ld [wCurBox], a
2015-08-19 21:14:15 -07:00
call LoadBox
2015-08-19 10:13:48 -07:00
call SavedTheGame
call ResumeGameLogic
2015-08-19 10:13:48 -07:00
and a
ret
.refused
pop de
ret
2015-11-17 20:29:14 -08:00
Link_SaveGame: ; 14ab2
call AskOverwriteSaveFile
2015-08-19 10:13:48 -07:00
jr c, .refused
call PauseGameLogic
2015-08-19 10:13:48 -07:00
call _SavingDontTurnOffThePower
call ResumeGameLogic
2015-08-19 10:13:48 -07:00
and a
.refused
ret
; 14ac2
2015-11-17 20:29:14 -08:00
MovePkmnWOMail_SaveGame: ; 14ac2
call PauseGameLogic
2015-08-19 10:13:48 -07:00
push de
2015-08-19 21:14:15 -07:00
call SaveBox
2015-08-19 10:13:48 -07:00
pop de
ld a, e
ld [wCurBox], a
2015-08-19 21:14:15 -07:00
call LoadBox
call ResumeGameLogic
2015-08-19 10:13:48 -07:00
ret
; 14ad5
MovePkmnWOMail_InsertMon_SaveGame: ; 14ad5
call PauseGameLogic
2015-08-19 10:13:48 -07:00
push de
2015-08-19 21:14:15 -07:00
call SaveBox
2015-08-19 10:13:48 -07:00
pop de
ld a, e
ld [wCurBox], a
ld a, $1
2015-11-17 20:29:14 -08:00
ld [wSaveFileExists], a
callba StageRTCTimeForSave
callba BackupMysteryGift
2015-08-19 21:14:15 -07:00
call ValidateSave
call SaveOptions
2015-08-19 10:13:48 -07:00
call SavePlayerData
2015-08-19 21:14:15 -07:00
call SavePokemonData
2015-11-17 20:29:14 -08:00
call SaveChecksum
2015-08-19 21:14:15 -07:00
call ValidateBackupSave
call SaveBackupOptions
call SaveBackupPlayerData
call SaveBackupPokemonData
call SaveBackupChecksum
2015-11-17 14:56:49 -08:00
callba BackupPartyMonMail
2015-11-05 11:06:03 -08:00
callba BackupMobileEventIndex
2015-11-17 20:29:14 -08:00
callba SaveRTC
2015-08-19 21:14:15 -07:00
call LoadBox
call ResumeGameLogic
2015-08-19 10:13:48 -07:00
ld de, SFX_SAVE
call PlaySFX
2015-11-17 20:29:14 -08:00
ld c, 24
2015-08-19 10:13:48 -07:00
call DelayFrames
ret
; 14b34
2015-11-17 20:29:14 -08:00
StartMovePkmnWOMail_SaveGame: ; 14b34
ld hl, Text_SaveOnMovePkmnWOMail
2015-08-19 10:13:48 -07:00
call MenuTextBox
call YesNoBox
call ExitMenu
2015-11-17 20:29:14 -08:00
jr c, .refused
call AskOverwriteSaveFile
jr c, .refused
call PauseGameLogic
2015-08-19 10:13:48 -07:00
call _SavingDontTurnOffThePower
call ResumeGameLogic
2015-08-19 10:13:48 -07:00
and a
ret
2015-11-17 20:29:14 -08:00
.refused
2015-08-19 10:13:48 -07:00
scf
ret
; 14b54
PauseGameLogic: ; 14b54
2015-08-19 10:13:48 -07:00
ld a, $1
ld [wGameLogicPaused], a
2015-08-19 10:13:48 -07:00
ret
; 14b5a
ResumeGameLogic: ; 14b5a
2015-08-19 10:13:48 -07:00
xor a
ld [wGameLogicPaused], a
2015-08-19 10:13:48 -07:00
ret
; 14b5f
2015-08-19 21:14:15 -07:00
AddHallOfFameEntry: ; 14b5f
ld a, BANK(sHallOfFame)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sHallOfFame + HOF_LENGTH * (NUM_HOF_TEAMS - 1) - 1
ld de, sHallOfFame + HOF_LENGTH * NUM_HOF_TEAMS - 1
ld bc, HOF_LENGTH * (NUM_HOF_TEAMS - 1)
2015-08-19 10:13:48 -07:00
.loop
ld a, [hld]
ld [de], a
dec de
dec bc
ld a, c
or b
jr nz, .loop
ld hl, OverworldMap
2015-08-19 21:14:15 -07:00
ld de, sHallOfFame
ld bc, HOF_LENGTH
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ret
; 14b85
2015-08-19 21:14:15 -07:00
SaveGameData: ; 14b85
call SaveGameData_
2015-08-19 10:13:48 -07:00
ret
; 14b89
2015-11-17 20:29:14 -08:00
AskOverwriteSaveFile: ; 14b89
ld a, [wSaveFileExists]
2015-08-19 10:13:48 -07:00
and a
2015-08-19 21:14:15 -07:00
jr z, .erase
2015-11-26 18:05:32 -08:00
call CompareLoadedAndSavedPlayerID
2015-08-19 10:13:48 -07:00
jr z, .yoursavefile
ld hl, Text_AnotherSaveFile
2015-08-19 10:13:48 -07:00
call SaveTheGame_yesorno
jr nz, .refused
2015-08-19 21:14:15 -07:00
jr .erase
2015-08-19 10:13:48 -07:00
.yoursavefile
ld hl, Text_AlreadyASaveFile
2015-08-19 10:13:48 -07:00
call SaveTheGame_yesorno
jr nz, .refused
jr .ok
2015-08-19 21:14:15 -07:00
.erase
call ErasePreviousSave
2015-08-19 10:13:48 -07:00
.ok
and a
ret
.refused
scf
ret
; 14baf
SaveTheGame_yesorno: ; 14baf
ld b, BANK(Text_WouldYouLikeToSaveTheGame)
2015-08-19 10:13:48 -07:00
call MapTextbox
call LoadMenuTextBox
lb bc, 0, 7
call PlaceYesNoBox
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2015-08-19 10:13:48 -07:00
dec a
call CloseWindow
2015-08-19 10:13:48 -07:00
push af
2015-12-09 08:38:40 -08:00
call ret_d90
2015-08-19 10:13:48 -07:00
pop af
and a
ret
; 14bcb
2015-11-26 18:05:32 -08:00
CompareLoadedAndSavedPlayerID: ; 14bcb
2015-08-19 21:14:15 -07:00
ld a, BANK(sPlayerData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sPlayerData + (PlayerID - wPlayerData)
2015-08-19 10:13:48 -07:00
ld a, [hli]
ld c, [hl]
ld b, a
call CloseSRAM
ld a, [PlayerID]
cp b
ret nz
ld a, [PlayerID + 1]
cp c
ret
; 14be3
_SavingDontTurnOffThePower: ; 14be3
call SavingDontTurnOffThePower
SavedTheGame: ; 14be6
2015-08-19 21:14:15 -07:00
call SaveGameData_
2015-08-19 10:13:48 -07:00
; wait 32 frames
ld c, $20
call DelayFrames
; copy the original text speed setting to the stack
ld a, [Options]
push af
; set text speed super slow
ld a, 3
ld [Options], a
; <PLAYER> saved the game!
ld hl, Text_PlayerSavedTheGame
2015-08-19 10:13:48 -07:00
call PrintText
; restore the original text speed setting
pop af
ld [Options], a
ld de, SFX_SAVE
call WaitPlaySFX
call WaitSFX
; wait 30 frames
ld c, $1e
call DelayFrames
ret
; 14c10
2015-08-19 21:14:15 -07:00
SaveGameData_: ; 14c10
2015-08-19 10:13:48 -07:00
ld a, 1
2015-11-17 20:29:14 -08:00
ld [wSaveFileExists], a
callba StageRTCTimeForSave
callba BackupMysteryGift
2015-08-19 21:14:15 -07:00
call ValidateSave
call SaveOptions
2015-08-19 10:13:48 -07:00
call SavePlayerData
2015-08-19 21:14:15 -07:00
call SavePokemonData
call SaveBox
2015-11-17 20:29:14 -08:00
call SaveChecksum
2015-08-19 21:14:15 -07:00
call ValidateBackupSave
call SaveBackupOptions
call SaveBackupPlayerData
call SaveBackupPokemonData
call SaveBackupChecksum
call UpdateStackTop
2015-11-17 14:56:49 -08:00
callba BackupPartyMonMail
2015-11-05 11:06:03 -08:00
callba BackupMobileEventIndex
2015-11-17 20:29:14 -08:00
callba SaveRTC
ld a, BANK(sBattleTowerChallengeState)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
ld a, [sBattleTowerChallengeState]
2015-11-26 18:05:32 -08:00
cp BATTLETOWER_RECEIVED_REWARD
2015-08-19 21:14:15 -07:00
jr nz, .ok
2015-08-19 10:13:48 -07:00
xor a
ld [sBattleTowerChallengeState], a
2015-08-19 21:14:15 -07:00
.ok
2015-08-19 10:13:48 -07:00
call CloseSRAM
ret
; 14c6b
2015-08-19 21:14:15 -07:00
UpdateStackTop: ; 14c6b
; sStackTop appears to be unused.
; It could have been used to debug stack overflow during saving.
call FindStackTop
ld a, BANK(sStackTop)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld a, [sStackTop + 0]
2015-08-19 10:13:48 -07:00
ld e, a
2015-08-19 21:14:15 -07:00
ld a, [sStackTop + 1]
2015-08-19 10:13:48 -07:00
ld d, a
or e
2015-08-19 21:14:15 -07:00
jr z, .update
2015-08-19 10:13:48 -07:00
ld a, e
sub l
ld a, d
sbc h
2015-08-19 21:14:15 -07:00
jr c, .done
2015-08-19 10:13:48 -07:00
2015-08-19 21:14:15 -07:00
.update
2015-08-19 10:13:48 -07:00
ld a, l
2015-08-19 21:14:15 -07:00
ld [sStackTop + 0], a
2015-08-19 10:13:48 -07:00
ld a, h
2015-08-19 21:14:15 -07:00
ld [sStackTop + 1], a
2015-08-19 10:13:48 -07:00
2015-08-19 21:14:15 -07:00
.done
2015-08-19 10:13:48 -07:00
call CloseSRAM
ret
; 14c90
2015-08-19 21:14:15 -07:00
FindStackTop: ; 14c90
; Find the furthest point that sp has traversed to.
; This is distinct from the current value of sp.
ld hl, Stack - $ff
.loop
2015-08-19 10:13:48 -07:00
ld a, [hl]
or a
ret nz
inc hl
2015-08-19 21:14:15 -07:00
jr .loop
2015-08-19 10:13:48 -07:00
; 14c99
SavingDontTurnOffThePower: ; 14c99
; Prevent joypad interrupts
xor a
ld [hJoypadReleased], a
ld [hJoypadPressed], a
ld [hJoypadSum], a
ld [hJoypadDown], a
; Save the text speed setting to the stack
ld a, [Options]
push af
; Set the text speed to super slow
ld a, $3
ld [Options], a
; SAVING... DON'T TURN OFF THE POWER.
ld hl, Text_SavingDontTurnOffThePower
2015-08-19 10:13:48 -07:00
call PrintText
; Restore the text speed setting
pop af
ld [Options], a
; Wait for 16 frames
ld c, $10
call DelayFrames
ret
; 14cbb
2015-08-19 21:14:15 -07:00
ErasePreviousSave: ; 14cbb
call EraseBoxes
call EraseHallOfFame
call EraseLinkBattleStats
call EraseMysteryGift
2015-11-17 20:29:14 -08:00
call SaveData
2015-11-26 18:05:32 -08:00
call EraseBattleTowerStatus
2015-08-19 21:14:15 -07:00
ld a, BANK(sStackTop)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
xor a
2015-08-19 21:14:15 -07:00
ld [sStackTop + 0], a
ld [sStackTop + 1], a
2015-08-19 10:13:48 -07:00
call CloseSRAM
ld a, $1
2015-10-16 10:35:43 -07:00
ld [wSavedAtLeastOnce], a
2015-08-19 10:13:48 -07:00
ret
; 14ce2
2015-08-19 21:14:15 -07:00
EraseLinkBattleStats: ; 14ce2
ld a, BANK(sLinkBattleStats)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sLinkBattleStats
ld bc, sLinkBattleStatsEnd - sLinkBattleStats
2015-08-19 10:13:48 -07:00
xor a
call ByteFill
jp CloseSRAM
; 14cf4
2015-08-19 21:14:15 -07:00
EraseMysteryGift: ; 14cf4
2015-11-17 20:29:14 -08:00
ld a, BANK(sBackupMysteryGiftItem)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-11-17 20:29:14 -08:00
ld hl, sBackupMysteryGiftItem
ld bc, sBackupMysteryGiftItemEnd - sBackupMysteryGiftItem
2015-08-19 10:13:48 -07:00
xor a
call ByteFill
jp CloseSRAM
; 14d06
2015-08-19 21:14:15 -07:00
EraseHallOfFame: ; 14d06
ld a, BANK(sHallOfFame)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sHallOfFame
ld bc, sHallOfFameEnd - sHallOfFame
2015-08-19 10:13:48 -07:00
xor a
call ByteFill
jp CloseSRAM
; 14d18
Function14d18: ; 14d18
; XXX
; copy .Data to SRA4:a007
2015-08-19 10:13:48 -07:00
ld a, $4
call GetSRAMBank
ld hl, .Data
2015-08-19 10:13:48 -07:00
ld de, $a007
ld bc, .DataEnd - .Data
2015-08-19 10:13:48 -07:00
call CopyBytes
jp CloseSRAM
; 14d2c
.Data: ; 14d2c
2015-08-19 10:13:48 -07:00
db $0d, $02, $00, $05, $00, $00
db $22, $02, $01, $05, $00, $00
db $03, $04, $05, $08, $03, $05
db $0e, $06, $03, $02, $00, $00
db $39, $07, $07, $04, $00, $05
db $04, $07, $01, $05, $00, $00
db $0f, $05, $14, $07, $05, $05
db $11, $0c, $0c, $06, $06, $04
; 14d5c
.DataEnd
2015-08-19 10:13:48 -07:00
2015-11-26 18:05:32 -08:00
EraseBattleTowerStatus: ; 14d5c
ld a, BANK(sBattleTowerChallengeState)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
xor a
ld [sBattleTowerChallengeState], a
2015-08-19 10:13:48 -07:00
jp CloseSRAM
; 14d68
2015-11-17 20:29:14 -08:00
SaveData: ; 14d68
call _SaveData
2015-08-19 10:13:48 -07:00
ret
; 14d6c
Function14d6c: ; 14d6c
; XXX
2015-08-19 10:13:48 -07:00
ld a, $4
call GetSRAMBank
ld a, [$a60b]
ld b, $0
and a
jr z, .ok
ld b, $2
.ok
ld a, b
ld [$a60b], a
call CloseSRAM
ret
; 14d83
Function14d83: ; 14d83
; XXX
2015-08-19 10:13:48 -07:00
ld a, $4
call GetSRAMBank
xor a
ld [$a60c], a
ld [$a60d], a
call CloseSRAM
ret
; 14d93
Function14d93: ; 14d93
; XXX
2015-08-19 10:13:48 -07:00
ld a, $7
call GetSRAMBank
xor a
ld [$a000], a
call CloseSRAM
ret
; 14da0
2015-11-26 18:05:32 -08:00
HallOfFame_InitSaveIfNeeded: ; 14da0
2015-10-16 10:35:43 -07:00
ld a, [wSavedAtLeastOnce]
2015-08-19 10:13:48 -07:00
and a
ret nz
2015-08-19 21:14:15 -07:00
call ErasePreviousSave
2015-08-19 10:13:48 -07:00
ret
; 14da9
2015-08-19 21:14:15 -07:00
ValidateSave: ; 14da9
ld a, BANK(s1_a008)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-11-16 08:53:26 -08:00
ld a, 99
2015-08-19 21:14:15 -07:00
ld [s1_a008], a
2015-11-16 08:53:26 -08:00
ld a, " "
2015-08-19 21:14:15 -07:00
ld [s1_ad0f], a
2015-08-19 10:13:48 -07:00
jp CloseSRAM
; 14dbb
2015-08-19 21:14:15 -07:00
SaveOptions: ; 14dbb
ld a, BANK(sOptions)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
ld hl, Options
2015-08-19 21:14:15 -07:00
ld de, sOptions
2015-08-19 10:13:48 -07:00
ld bc, OptionsEnd - Options
call CopyBytes
ld a, [Options]
2015-11-26 18:05:32 -08:00
and $ff ^ (1 << NO_TEXT_SCROLL)
2015-08-19 21:14:15 -07:00
ld [sOptions], a
2015-08-19 10:13:48 -07:00
jp CloseSRAM
; 14dd7
SavePlayerData: ; 14dd7
2015-08-19 21:14:15 -07:00
ld a, BANK(sPlayerData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wPlayerData
ld de, sPlayerData
ld bc, wPlayerDataEnd - wPlayerData
2015-08-19 10:13:48 -07:00
call CopyBytes
2015-08-19 21:14:15 -07:00
ld hl, wMapData
ld de, sMapData
ld bc, wMapDataEnd - wMapData
2015-08-19 10:13:48 -07:00
call CopyBytes
jp CloseSRAM
; 14df7
2015-08-19 21:14:15 -07:00
SavePokemonData: ; 14df7
ld a, BANK(sPokemonData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wPokemonData
ld de, sPokemonData
ld bc, wPokemonDataEnd - wPokemonData
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ret
; 14e0c
2015-08-19 21:14:15 -07:00
SaveBox: ; 14e0c
call GetBoxAddress
call SaveBoxAddress
2015-08-19 10:13:48 -07:00
ret
; 14e13
2015-11-17 20:29:14 -08:00
SaveChecksum: ; 14e13
2015-08-19 21:14:15 -07:00
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
ld a, BANK(sGameData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
call Checksum
2015-08-19 10:13:48 -07:00
ld a, e
2015-08-19 21:14:15 -07:00
ld [sChecksum + 0], a
2015-08-19 10:13:48 -07:00
ld a, d
2015-08-19 21:14:15 -07:00
ld [sChecksum + 1], a
2015-08-19 10:13:48 -07:00
call CloseSRAM
ret
; 14e2d
2015-08-19 21:14:15 -07:00
ValidateBackupSave: ; 14e2d
ld a, BANK(s0_b208)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-11-16 08:53:26 -08:00
ld a, 99
2015-08-19 21:14:15 -07:00
ld [s0_b208], a
2015-11-16 08:53:26 -08:00
ld a, " "
2015-08-19 21:14:15 -07:00
ld [s0_bf0f], a
2015-08-19 10:13:48 -07:00
call CloseSRAM
ret
; 14e40
2015-08-19 21:14:15 -07:00
SaveBackupOptions: ; 14e40
ld a, BANK(sBackupOptions)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
ld hl, Options
2015-08-19 21:14:15 -07:00
ld de, sBackupOptions
2015-08-19 10:13:48 -07:00
ld bc, OptionsEnd - Options
call CopyBytes
call CloseSRAM
ret
; 14e55
2015-08-19 21:14:15 -07:00
SaveBackupPlayerData: ; 14e55
ld a, BANK(sBackupPlayerData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wPlayerData
ld de, sBackupPlayerData
ld bc, wPlayerDataEnd - wPlayerData
2015-08-19 10:13:48 -07:00
call CopyBytes
2015-08-19 21:14:15 -07:00
ld hl, wMapData
ld de, sBackupMapData
ld bc, wMapDataEnd - wMapData
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ret
; 14e76
2015-08-19 21:14:15 -07:00
SaveBackupPokemonData: ; 14e76
ld a, BANK(sBackupPokemonData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wPokemonData
ld de, sBackupPokemonData
ld bc, wPokemonDataEnd - wPokemonData
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ret
; 14e8b
2015-08-19 21:14:15 -07:00
SaveBackupChecksum: ; 14e8b
ld hl, sBackupGameData
ld bc, sBackupGameDataEnd - sBackupGameData
ld a, BANK(sBackupGameData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
call Checksum
2015-08-19 10:13:48 -07:00
ld a, e
2015-08-19 21:14:15 -07:00
ld [sBackupChecksum + 0], a
2015-08-19 10:13:48 -07:00
ld a, d
2015-08-19 21:14:15 -07:00
ld [sBackupChecksum + 1], a
2015-08-19 10:13:48 -07:00
call CloseSRAM
ret
; 14ea5
TryLoadSaveFile: ; 14ea5 (5:4ea5)
2015-08-19 21:14:15 -07:00
call VerifyChecksum
jr nz, .backup
call LoadPlayerData
call LoadPokemonData
call LoadBox
2015-11-17 14:56:49 -08:00
callba RestorePartyMonMail
2015-11-05 11:06:03 -08:00
callba RestoreMobileEventIndex
2015-11-17 20:29:14 -08:00
callba RestoreMysteryGift
2015-08-19 21:14:15 -07:00
call ValidateBackupSave
call SaveBackupOptions
call SaveBackupPlayerData
call SaveBackupPokemonData
call SaveBackupChecksum
2015-08-19 10:13:48 -07:00
and a
ret
2015-08-19 21:14:15 -07:00
.backup
call VerifyBackupChecksum
2015-08-19 10:13:48 -07:00
jr nz, .corrupt
2015-08-19 21:14:15 -07:00
call LoadBackupPlayerData
call LoadBackupPokemonData
call LoadBox
2015-11-17 14:56:49 -08:00
callba RestorePartyMonMail
2015-11-05 11:06:03 -08:00
callba RestoreMobileEventIndex
2015-11-17 20:29:14 -08:00
callba RestoreMysteryGift
2015-08-19 21:14:15 -07:00
call ValidateSave
call SaveOptions
2015-08-19 10:13:48 -07:00
call SavePlayerData
2015-08-19 21:14:15 -07:00
call SavePokemonData
2015-11-17 20:29:14 -08:00
call SaveChecksum
2015-08-19 10:13:48 -07:00
and a
ret
2015-08-19 21:14:15 -07:00
2015-08-19 10:13:48 -07:00
.corrupt
ld a, [Options]
push af
2015-11-16 08:53:26 -08:00
set NO_TEXT_SCROLL, a
2015-08-19 10:13:48 -07:00
ld [Options], a
ld hl, Text_SaveFileCorrupted
2015-08-19 10:13:48 -07:00
call PrintText
pop af
ld [Options], a
scf
ret
2015-11-17 20:29:14 -08:00
TryLoadSaveData: ; 14f1c
2015-08-19 10:13:48 -07:00
xor a
2015-11-17 20:29:14 -08:00
ld [wSaveFileExists], a
call CheckPrimarySaveFile
ld a, [wSaveFileExists]
2015-08-19 10:13:48 -07:00
and a
2015-08-19 21:14:15 -07:00
jr z, .backup
ld a, BANK(sPlayerData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sPlayerData + StartDay - wPlayerData
2015-08-19 10:13:48 -07:00
ld de, StartDay
2015-08-19 21:14:15 -07:00
ld bc, 8
2015-08-19 10:13:48 -07:00
call CopyBytes
2015-08-19 21:14:15 -07:00
ld hl, sPlayerData + StatusFlags - wPlayerData
2015-08-19 10:13:48 -07:00
ld de, StatusFlags
ld a, [hl]
ld [de], a
call CloseSRAM
ret
2015-08-19 21:14:15 -07:00
.backup
2015-11-17 20:29:14 -08:00
call CheckBackupSaveFile
ld a, [wSaveFileExists]
2015-08-19 10:13:48 -07:00
and a
2015-08-19 21:14:15 -07:00
jr z, .corrupt
ld a, BANK(sBackupPlayerData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sBackupPlayerData + StartDay - wPlayerData
2015-08-19 10:13:48 -07:00
ld de, StartDay
ld bc, 8
call CopyBytes
2015-08-19 21:14:15 -07:00
ld hl, sBackupPlayerData + StatusFlags - wPlayerData
2015-08-19 10:13:48 -07:00
ld de, StatusFlags
ld a, [hl]
ld [de], a
call CloseSRAM
ret
2015-08-19 21:14:15 -07:00
.corrupt
2015-08-19 10:13:48 -07:00
ld hl, DefaultOptions
ld de, Options
ld bc, OptionsEnd - Options
call CopyBytes
2015-11-17 20:29:14 -08:00
call PanicResetClock
2015-08-19 10:13:48 -07:00
ret
; 14f7c
INCLUDE "data/default_options.asm"
2015-08-19 10:13:48 -07:00
2015-11-17 20:29:14 -08:00
CheckPrimarySaveFile: ; 14f84
2015-08-19 21:14:15 -07:00
ld a, BANK(s1_a008)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld a, [s1_a008]
2015-11-16 08:53:26 -08:00
cp 99
2015-08-19 10:13:48 -07:00
jr nz, .nope
2015-08-19 21:14:15 -07:00
ld a, [s1_ad0f]
2015-11-16 08:53:26 -08:00
cp " "
2015-08-19 10:13:48 -07:00
jr nz, .nope
2015-08-19 21:14:15 -07:00
ld hl, sOptions
2015-08-19 10:13:48 -07:00
ld de, Options
ld bc, OptionsEnd - Options
call CopyBytes
call CloseSRAM
ld a, $1
2015-11-17 20:29:14 -08:00
ld [wSaveFileExists], a
2015-08-19 10:13:48 -07:00
.nope
call CloseSRAM
ret
; 14faf
2015-11-17 20:29:14 -08:00
CheckBackupSaveFile: ; 14faf
2015-08-19 21:14:15 -07:00
ld a, BANK(s0_b208)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld a, [s0_b208]
2015-11-16 08:53:26 -08:00
cp 99
2015-08-19 10:13:48 -07:00
jr nz, .nope
2015-08-19 21:14:15 -07:00
ld a, [s0_bf0f]
2015-11-16 08:53:26 -08:00
cp " "
2015-08-19 10:13:48 -07:00
jr nz, .nope
2015-08-19 21:14:15 -07:00
ld hl, sBackupOptions
2015-08-19 10:13:48 -07:00
ld de, Options
ld bc, OptionsEnd - Options
call CopyBytes
ld a, $2
2015-11-17 20:29:14 -08:00
ld [wSaveFileExists], a
2015-08-19 10:13:48 -07:00
.nope
call CloseSRAM
ret
; 14fd7
2015-08-19 21:14:15 -07:00
LoadPlayerData: ; 14fd7 (5:4fd7)
ld a, BANK(sPlayerData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sPlayerData
ld de, wPlayerData
ld bc, wPlayerDataEnd - wPlayerData
2015-08-19 10:13:48 -07:00
call CopyBytes
2015-08-19 21:14:15 -07:00
ld hl, sMapData
ld de, wMapData
ld bc, wMapDataEnd - wMapData
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ld a, BANK(sBattleTowerChallengeState)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
ld a, [sBattleTowerChallengeState]
2015-11-26 18:05:32 -08:00
cp BATTLETOWER_RECEIVED_REWARD
2015-11-17 20:29:14 -08:00
jr nz, .not_4
2015-11-26 18:05:32 -08:00
ld a, BATTLETOWER_WON_CHALLENGE
ld [sBattleTowerChallengeState], a
2015-11-17 20:29:14 -08:00
.not_4
2015-08-19 10:13:48 -07:00
call CloseSRAM
ret
2015-08-19 21:14:15 -07:00
LoadPokemonData: ; 1500c
ld a, BANK(sPokemonData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sPokemonData
ld de, wPokemonData
ld bc, wPokemonDataEnd - wPokemonData
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ret
; 15021
2015-08-19 21:14:15 -07:00
LoadBox: ; 15021 (5:5021)
call GetBoxAddress
call LoadBoxAddress
2015-08-19 10:13:48 -07:00
ret
2015-08-19 21:14:15 -07:00
VerifyChecksum: ; 15028 (5:5028)
ld hl, sGameData
ld bc, sGameDataEnd - sGameData
ld a, BANK(sGameData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
call Checksum
ld a, [sChecksum + 0]
2015-08-19 10:13:48 -07:00
cp e
2015-11-17 20:29:14 -08:00
jr nz, .fail
2015-08-19 21:14:15 -07:00
ld a, [sChecksum + 1]
2015-08-19 10:13:48 -07:00
cp d
2015-11-17 20:29:14 -08:00
.fail
2015-08-19 10:13:48 -07:00
push af
call CloseSRAM
pop af
ret
2015-08-19 21:14:15 -07:00
LoadBackupPlayerData: ; 15046 (5:5046)
ld a, BANK(sBackupPlayerData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sBackupPlayerData
ld de, wPlayerData
ld bc, wPlayerDataEnd - wPlayerData
2015-08-19 10:13:48 -07:00
call CopyBytes
2015-08-19 21:14:15 -07:00
ld hl, sBackupMapData
ld de, wMapData
ld bc, wMapDataEnd - wMapData
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ret
2015-08-19 21:14:15 -07:00
LoadBackupPokemonData: ; 15067 (5:5067)
ld a, BANK(sBackupPokemonData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sBackupPokemonData
ld de, wPokemonData
ld bc, wPokemonDataEnd - wPokemonData
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
ret
2015-08-19 21:14:15 -07:00
VerifyBackupChecksum: ; 1507c (5:507c)
ld hl, sBackupGameData
ld bc, sBackupGameDataEnd - sBackupGameData
ld a, BANK(sBackupGameData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
call Checksum
ld a, [sBackupChecksum + 0]
2015-08-19 10:13:48 -07:00
cp e
2015-11-17 20:29:14 -08:00
jr nz, .fail
2015-08-19 21:14:15 -07:00
ld a, [sBackupChecksum + 1]
2015-08-19 10:13:48 -07:00
cp d
2015-11-17 20:29:14 -08:00
.fail
2015-08-19 10:13:48 -07:00
push af
call CloseSRAM
pop af
ret
2015-11-17 20:29:14 -08:00
_SaveData: ; 1509a
2015-08-19 21:14:15 -07:00
ld a, BANK(sCrystalData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wCrystalData
ld de, sCrystalData
ld bc, wCrystalDataEnd - wCrystalData
2015-08-19 10:13:48 -07:00
call CopyBytes
2015-08-19 21:14:15 -07:00
; XXX SRAM bank 7
2015-08-19 10:13:48 -07:00
ld hl, wd479
ld a, [hli]
2015-08-19 21:14:15 -07:00
ld [$a60e + 0], a
2015-08-19 10:13:48 -07:00
ld a, [hli]
2015-08-19 21:14:15 -07:00
ld [$a60e + 1], a
2015-08-19 10:13:48 -07:00
jp CloseSRAM
2015-12-14 17:06:41 -08:00
_LoadData: ; 150b9
2015-08-19 21:14:15 -07:00
ld a, BANK(sCrystalData)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sCrystalData
ld de, wCrystalData
ld bc, wCrystalDataEnd - wCrystalData
2015-08-19 10:13:48 -07:00
call CopyBytes
2015-08-19 21:14:15 -07:00
; XXX SRAM bank 7
2015-08-19 10:13:48 -07:00
ld hl, wd479
2015-08-19 21:14:15 -07:00
ld a, [$a60e + 0]
2015-08-19 10:13:48 -07:00
ld [hli], a
2015-08-19 21:14:15 -07:00
ld a, [$a60e + 1]
2015-08-19 10:13:48 -07:00
ld [hli], a
2015-08-19 21:14:15 -07:00
2015-08-19 10:13:48 -07:00
jp CloseSRAM
2015-08-19 21:14:15 -07:00
GetBoxAddress: ; 150d8
2015-08-19 10:13:48 -07:00
ld a, [wCurBox]
cp NUM_BOXES
2015-08-19 21:14:15 -07:00
jr c, .ok
2015-08-19 10:13:48 -07:00
xor a
ld [wCurBox], a
2015-08-19 21:14:15 -07:00
.ok
2015-08-19 10:13:48 -07:00
ld e, a
ld d, 0
2015-08-19 21:14:15 -07:00
ld hl, BoxAddresses
2015-08-19 10:13:48 -07:00
rept 5
add hl, de
endr
ld a, [hli]
push af
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, [hli]
ld h, [hl]
ld l, a
pop af
ret
; 150f9
2015-08-19 21:14:15 -07:00
SaveBoxAddress: ; 150f9
2015-12-14 17:06:41 -08:00
; Save box via wMisc.
; We do this in three steps because the size of wMisc is less than
; the size of sBox.
2015-08-19 10:13:48 -07:00
push hl
2015-12-14 17:06:41 -08:00
; Load the first part of the active box.
2015-08-19 10:13:48 -07:00
push af
push de
2015-08-19 21:14:15 -07:00
ld a, BANK(sBox)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sBox
ld de, wMisc
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
pop de
pop af
2015-12-14 17:06:41 -08:00
; Save it to the target box.
2015-08-19 10:13:48 -07:00
push af
push de
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wMisc
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
2015-12-14 17:06:41 -08:00
; Load the second part of the active box.
2015-08-19 21:14:15 -07:00
ld a, BANK(sBox)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sBox + (wMiscEnd - wMisc)
ld de, wMisc
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
pop de
pop af
2015-08-19 21:14:15 -07:00
ld hl, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
add hl, de
ld e, l
ld d, h
2015-12-14 17:06:41 -08:00
; Save it to the next part of the target box.
2015-08-19 10:13:48 -07:00
push af
push de
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wMisc
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
2015-12-14 17:06:41 -08:00
; Load the third and final part of the active box.
2015-08-19 21:14:15 -07:00
ld a, BANK(sBox)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, sBox + (wMiscEnd - wMisc) * 2
ld de, wMisc
ld bc, sBoxEnd - (sBox + (wMiscEnd - wMisc) * 2) ; $8e
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
pop de
pop af
2015-08-19 21:14:15 -07:00
ld hl, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
add hl, de
ld e, l
ld d, h
2015-12-14 17:06:41 -08:00
; Save it to the final part of the target box.
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wMisc
ld bc, sBoxEnd - (sBox + (wMiscEnd - wMisc) * 2) ; $8e
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
2015-08-19 21:14:15 -07:00
2015-08-19 10:13:48 -07:00
pop hl
ret
; 1517d
2015-08-19 21:14:15 -07:00
LoadBoxAddress: ; 1517d (5:517d)
2015-12-14 17:06:41 -08:00
; Load box via wMisc.
; We do this in three steps because the size of wMisc is less than
; the size of sBox.
2015-08-19 10:13:48 -07:00
push hl
ld l, e
ld h, d
2015-12-14 17:06:41 -08:00
; Load part 1
2015-08-19 10:13:48 -07:00
push af
push hl
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld de, wMisc
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
2015-08-19 21:14:15 -07:00
ld a, BANK(sBox)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wMisc
ld de, sBox
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
pop hl
pop af
2015-08-19 21:14:15 -07:00
ld de, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
add hl, de
2015-12-14 17:06:41 -08:00
; Load part 2
2015-08-19 10:13:48 -07:00
push af
push hl
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld de, wMisc
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
2015-08-19 21:14:15 -07:00
ld a, BANK(sBox)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wMisc
ld de, sBox + (wMiscEnd - wMisc)
ld bc, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
pop hl
pop af
2015-12-14 17:06:41 -08:00
; Load part 3
2015-08-19 21:14:15 -07:00
ld de, (wMiscEnd - wMisc)
2015-08-19 10:13:48 -07:00
add hl, de
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld de, wMisc
ld bc, sBoxEnd - (sBox + (wMiscEnd - wMisc) * 2) ; $8e
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
2015-08-19 21:14:15 -07:00
ld a, BANK(sBox)
2015-08-19 10:13:48 -07:00
call GetSRAMBank
2015-08-19 21:14:15 -07:00
ld hl, wMisc
ld de, sBox + (wMiscEnd - wMisc) * 2
ld bc, sBoxEnd - (sBox + (wMiscEnd - wMisc) * 2) ; $8e
2015-08-19 10:13:48 -07:00
call CopyBytes
call CloseSRAM
2015-08-19 21:14:15 -07:00
2015-08-19 10:13:48 -07:00
pop hl
ret
2015-08-19 21:14:15 -07:00
EraseBoxes: ; 151fb
ld hl, BoxAddresses
ld c, NUM_BOXES
.next
2015-08-19 10:13:48 -07:00
push bc
ld a, [hli]
call GetSRAMBank
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
xor a
ld [de], a
inc de
ld a, -1
ld [de], a
inc de
2015-08-19 21:14:15 -07:00
ld bc, sBoxEnd - (sBox + 2)
.clear
2015-08-19 10:13:48 -07:00
xor a
ld [de], a
inc de
dec bc
ld a, b
or c
2015-08-19 21:14:15 -07:00
jr nz, .clear
2015-08-19 10:13:48 -07:00
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, -1
ld [de], a
inc de
xor a
ld [de], a
call CloseSRAM
pop bc
dec c
2015-08-19 21:14:15 -07:00
jr nz, .next
2015-08-19 10:13:48 -07:00
ret
; 1522d
2015-08-19 21:14:15 -07:00
BoxAddresses: ; 1522d
2015-08-19 10:13:48 -07:00
; dbww bank, address, address
2015-08-19 21:14:15 -07:00
dbww BANK(sBox1), sBox1, sBox1End
dbww BANK(sBox2), sBox2, sBox2End
dbww BANK(sBox3), sBox3, sBox3End
dbww BANK(sBox4), sBox4, sBox4End
dbww BANK(sBox5), sBox5, sBox5End
dbww BANK(sBox6), sBox6, sBox6End
dbww BANK(sBox7), sBox7, sBox7End
dbww BANK(sBox8), sBox8, sBox8End
dbww BANK(sBox9), sBox9, sBox9End
dbww BANK(sBox10), sBox10, sBox10End
dbww BANK(sBox11), sBox11, sBox11End
dbww BANK(sBox12), sBox12, sBox12End
dbww BANK(sBox13), sBox13, sBox13End
dbww BANK(sBox14), sBox14, sBox14End
2015-08-19 10:13:48 -07:00
; 15273
2015-08-19 21:14:15 -07:00
Checksum: ; 15273
2015-08-19 10:13:48 -07:00
ld de, 0
.loop
ld a, [hli]
add e
ld e, a
ld a, 0
adc d
ld d, a
dec bc
ld a, b
or c
jr nz, .loop
ret
; 15283
Text_WouldYouLikeToSaveTheGame: ; 0x15283
2015-08-19 10:13:48 -07:00
; Would you like to save the game?
text_jump UnknownText_0x1c454b
db "@"
; 0x15288
Text_SavingDontTurnOffThePower: ; 0x15288
2015-08-19 10:13:48 -07:00
; SAVING… DON'T TURN OFF THE POWER.
text_jump UnknownText_0x1c456d
db "@"
; 0x1528d
Text_PlayerSavedTheGame: ; 0x1528d
2015-08-19 10:13:48 -07:00
; saved the game.
text_jump UnknownText_0x1c4590
db "@"
; 0x15292
Text_AlreadyASaveFile: ; 0x15292
2015-08-19 10:13:48 -07:00
; There is already a save file. Is it OK to overwrite?
text_jump UnknownText_0x1c45a3
db "@"
; 0x15297
Text_AnotherSaveFile: ; 0x15297
2015-08-19 10:13:48 -07:00
; There is another save file. Is it OK to overwrite?
text_jump UnknownText_0x1c45d9
db "@"
; 0x1529c
Text_SaveFileCorrupted: ; 0x1529c
2015-08-19 10:13:48 -07:00
; The save file is corrupted!
text_jump UnknownText_0x1c460d
db "@"
; 0x152a1
Text_SaveOnBoxSwitch: ; 0x152a1
2015-08-19 10:13:48 -07:00
; When you change a #MON BOX, data will be saved. OK?
text_jump UnknownText_0x1c462a
db "@"
; 0x152a6
Text_SaveOnMovePkmnWOMail: ; 0x152a6
2015-08-19 10:13:48 -07:00
; Each time you move a #MON, data will be saved. OK?
text_jump UnknownText_0x1c465f
db "@"
; 0x152ab