save.asm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. LoadSAV:
  2. ;(if carry -> write
  3. ;"the file data is destroyed")
  4. call ClearScreen
  5. call LoadFontTilePatterns
  6. call LoadTextBoxTilePatterns
  7. call LoadSAV0
  8. jr c, .badsum
  9. call LoadSAV1
  10. jr c, .badsum
  11. call LoadSAV2
  12. jr c, .badsum
  13. ld a, $2 ; good checksum
  14. jr .goodsum
  15. .badsum
  16. ld hl, wd730
  17. push hl
  18. set 6, [hl]
  19. ld hl, FileDataDestroyedText
  20. call PrintText
  21. ld c, 100
  22. call DelayFrames
  23. pop hl
  24. res 6, [hl]
  25. ld a, $1 ; bad checksum
  26. .goodsum
  27. ld [wSaveFileStatus], a
  28. ret
  29. FileDataDestroyedText:
  30. TX_FAR _FileDataDestroyedText
  31. db "@"
  32. LoadSAV0:
  33. ld a, SRAM_ENABLE
  34. ld [MBC1SRamEnable], a
  35. ld a, $1
  36. ld [MBC1SRamBankingMode], a
  37. ld [MBC1SRamBank], a
  38. ld hl, sPlayerName ; hero name located in SRAM
  39. ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
  40. call SAVCheckSum
  41. ld c, a
  42. ld a, [sMainDataCheckSum] ; SAV's checksum
  43. cp c
  44. jp z, .checkSumsMatched
  45. ; If the computed checksum didn't match the saved on, try again.
  46. ld hl, sPlayerName
  47. ld bc, sMainDataCheckSum - sPlayerName
  48. call SAVCheckSum
  49. ld c, a
  50. ld a, [sMainDataCheckSum] ; SAV's checksum
  51. cp c
  52. jp nz, SAVBadCheckSum
  53. .checkSumsMatched
  54. ld hl, sPlayerName
  55. ld de, wPlayerName
  56. ld bc, NAME_LENGTH
  57. call CopyData
  58. ld hl, sMainData
  59. ld de, wMainDataStart
  60. ld bc, wMainDataEnd - wMainDataStart
  61. call CopyData
  62. ld hl, wCurMapTileset
  63. set 7, [hl]
  64. ld hl, sSpriteData
  65. ld de, wSpriteDataStart
  66. ld bc, wSpriteDataEnd - wSpriteDataStart
  67. call CopyData
  68. ld a, [sTilesetType]
  69. ld [hTilesetType], a
  70. ld hl, sCurBoxData
  71. ld de, wBoxDataStart
  72. ld bc, wBoxDataEnd - wBoxDataStart
  73. call CopyData
  74. and a
  75. jp SAVGoodChecksum
  76. LoadSAV1:
  77. ld a, SRAM_ENABLE
  78. ld [MBC1SRamEnable], a
  79. ld a, $1
  80. ld [MBC1SRamBankingMode], a
  81. ld [MBC1SRamBank], a
  82. ld hl, sPlayerName ; hero name located in SRAM
  83. ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
  84. call SAVCheckSum
  85. ld c, a
  86. ld a, [sMainDataCheckSum] ; SAV's checksum
  87. cp c
  88. jr nz, SAVBadCheckSum
  89. ld hl, sCurBoxData
  90. ld de, wBoxDataStart
  91. ld bc, wBoxDataEnd - wBoxDataStart
  92. call CopyData
  93. and a
  94. jp SAVGoodChecksum
  95. LoadSAV2:
  96. ld a, SRAM_ENABLE
  97. ld [MBC1SRamEnable], a
  98. ld a, $1
  99. ld [MBC1SRamBankingMode], a
  100. ld [MBC1SRamBank], a
  101. ld hl, sPlayerName ; hero name located in SRAM
  102. ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
  103. call SAVCheckSum
  104. ld c, a
  105. ld a, [sMainDataCheckSum] ; SAV's checksum
  106. cp c
  107. jp nz, SAVBadCheckSum
  108. ld hl, sPartyData
  109. ld de, wPartyDataStart
  110. ld bc, wPartyDataEnd - wPartyDataStart
  111. call CopyData
  112. ld hl, sMainData
  113. ld de, wPokedexOwned
  114. ld bc, wPokedexSeenEnd - wPokedexOwned
  115. call CopyData
  116. and a
  117. jp SAVGoodChecksum
  118. SAVBadCheckSum:
  119. scf
  120. SAVGoodChecksum:
  121. ld a, $0
  122. ld [MBC1SRamBankingMode], a
  123. ld [MBC1SRamEnable], a
  124. ret
  125. LoadSAVIgnoreBadCheckSum:
  126. ; unused function that loads save data and ignores bad checksums
  127. call LoadSAV0
  128. call LoadSAV1
  129. jp LoadSAV2
  130. SaveSAV:
  131. callba PrintSaveScreenText
  132. ld hl, WouldYouLikeToSaveText
  133. call SaveSAVConfirm
  134. and a ;|0 = Yes|1 = No|
  135. ret nz
  136. ld a, [wSaveFileStatus]
  137. dec a
  138. jr z, .save
  139. call SAVCheckRandomID
  140. jr z, .save
  141. ld hl, OlderFileWillBeErasedText
  142. call SaveSAVConfirm
  143. and a
  144. ret nz
  145. .save
  146. call SaveSAVtoSRAM
  147. coord hl, 1, 13
  148. lb bc, 4, 18
  149. call ClearScreenArea
  150. coord hl, 1, 14
  151. ld de, NowSavingString
  152. call PlaceString
  153. ld c, 120
  154. call DelayFrames
  155. ld hl, GameSavedText
  156. call PrintText
  157. ld a, SFX_SAVE
  158. call PlaySoundWaitForCurrent
  159. call WaitForSoundToFinish
  160. ld c, 30
  161. jp DelayFrames
  162. NowSavingString:
  163. db "Now saving...@"
  164. SaveSAVConfirm:
  165. call PrintText
  166. coord hl, 0, 7
  167. lb bc, 8, 1
  168. ld a, TWO_OPTION_MENU
  169. ld [wTextBoxID], a
  170. call DisplayTextBoxID ; yes/no menu
  171. ld a, [wCurrentMenuItem]
  172. ret
  173. WouldYouLikeToSaveText:
  174. TX_FAR _WouldYouLikeToSaveText
  175. db "@"
  176. GameSavedText:
  177. TX_FAR _GameSavedText
  178. db "@"
  179. OlderFileWillBeErasedText:
  180. TX_FAR _OlderFileWillBeErasedText
  181. db "@"
  182. SaveSAVtoSRAM0:
  183. ld a, SRAM_ENABLE
  184. ld [MBC1SRamEnable], a
  185. ld a, $1
  186. ld [MBC1SRamBankingMode], a
  187. ld [MBC1SRamBank], a
  188. ld hl, wPlayerName
  189. ld de, sPlayerName
  190. ld bc, NAME_LENGTH
  191. call CopyData
  192. ld hl, wMainDataStart
  193. ld de, sMainData
  194. ld bc, wMainDataEnd - wMainDataStart
  195. call CopyData
  196. ld hl, wSpriteDataStart
  197. ld de, sSpriteData
  198. ld bc, wSpriteDataEnd - wSpriteDataStart
  199. call CopyData
  200. ld hl, wBoxDataStart
  201. ld de, sCurBoxData
  202. ld bc, wBoxDataEnd - wBoxDataStart
  203. call CopyData
  204. ld a, [hTilesetType]
  205. ld [sTilesetType], a
  206. ld hl, sPlayerName
  207. ld bc, sMainDataCheckSum - sPlayerName
  208. call SAVCheckSum
  209. ld [sMainDataCheckSum], a
  210. xor a
  211. ld [MBC1SRamBankingMode], a
  212. ld [MBC1SRamEnable], a
  213. ret
  214. SaveSAVtoSRAM1:
  215. ; stored pokémon
  216. ld a, SRAM_ENABLE
  217. ld [MBC1SRamEnable], a
  218. ld a, $1
  219. ld [MBC1SRamBankingMode], a
  220. ld [MBC1SRamBank], a
  221. ld hl, wBoxDataStart
  222. ld de, sCurBoxData
  223. ld bc, wBoxDataEnd - wBoxDataStart
  224. call CopyData
  225. ld hl, sPlayerName
  226. ld bc, sMainDataCheckSum - sPlayerName
  227. call SAVCheckSum
  228. ld [sMainDataCheckSum], a
  229. xor a
  230. ld [MBC1SRamBankingMode], a
  231. ld [MBC1SRamEnable], a
  232. ret
  233. SaveSAVtoSRAM2:
  234. ld a, SRAM_ENABLE
  235. ld [MBC1SRamEnable], a
  236. ld a, $1
  237. ld [MBC1SRamBankingMode], a
  238. ld [MBC1SRamBank], a
  239. ld hl, wPartyDataStart
  240. ld de, sPartyData
  241. ld bc, wPartyDataEnd - wPartyDataStart
  242. call CopyData
  243. ld hl, wPokedexOwned ; pokédex only
  244. ld de, sMainData
  245. ld bc, wPokedexSeenEnd - wPokedexOwned
  246. call CopyData
  247. ld hl, sPlayerName
  248. ld bc, sMainDataCheckSum - sPlayerName
  249. call SAVCheckSum
  250. ld [sMainDataCheckSum], a
  251. xor a
  252. ld [MBC1SRamBankingMode], a
  253. ld [MBC1SRamEnable], a
  254. ret
  255. SaveSAVtoSRAM:
  256. ld a, $2
  257. ld [wSaveFileStatus], a
  258. call SaveSAVtoSRAM0
  259. call SaveSAVtoSRAM1
  260. jp SaveSAVtoSRAM2
  261. SAVCheckSum:
  262. ;Check Sum (result[1 byte] is complemented)
  263. ld d, 0
  264. .loop
  265. ld a, [hli]
  266. add d
  267. ld d, a
  268. dec bc
  269. ld a, b
  270. or c
  271. jr nz, .loop
  272. ld a, d
  273. cpl
  274. ret
  275. CalcIndividualBoxCheckSums:
  276. ld hl, sBox1 ; sBox7
  277. ld de, sBank2IndividualBoxChecksums ; sBank3IndividualBoxChecksums
  278. ld b, NUM_BOXES / 2
  279. .loop
  280. push bc
  281. push de
  282. ld bc, wBoxDataEnd - wBoxDataStart
  283. call SAVCheckSum
  284. pop de
  285. ld [de], a
  286. inc de
  287. pop bc
  288. dec b
  289. jr nz, .loop
  290. ret
  291. GetBoxSRAMLocation:
  292. ; in: a = box num
  293. ; out: b = box SRAM bank, hl = pointer to start of box
  294. ld hl, BoxSRAMPointerTable
  295. ld a, [wCurrentBoxNum]
  296. and $7f
  297. cp NUM_BOXES / 2
  298. ld b, 2
  299. jr c, .next
  300. inc b
  301. sub NUM_BOXES / 2
  302. .next
  303. ld e, a
  304. ld d, 0
  305. add hl, de
  306. add hl, de
  307. ld a, [hli]
  308. ld h, [hl]
  309. ld l, a
  310. ret
  311. BoxSRAMPointerTable:
  312. dw sBox1 ; sBox7
  313. dw sBox2 ; sBox8
  314. dw sBox3 ; sBox9
  315. dw sBox4 ; sBox10
  316. dw sBox5 ; sBox11
  317. dw sBox6 ; sBox12
  318. ChangeBox::
  319. ld hl, WhenYouChangeBoxText
  320. call PrintText
  321. call YesNoChoice
  322. ld a, [wCurrentMenuItem]
  323. and a
  324. ret nz ; return if No was chosen
  325. ld hl, wCurrentBoxNum
  326. bit 7, [hl] ; is it the first time player is changing the box?
  327. call z, EmptyAllSRAMBoxes ; if so, empty all boxes in SRAM
  328. call DisplayChangeBoxMenu
  329. call UpdateSprites
  330. ld hl, hFlags_0xFFF6
  331. set 1, [hl]
  332. call HandleMenuInput
  333. ld hl, hFlags_0xFFF6
  334. res 1, [hl]
  335. bit 1, a ; pressed b
  336. ret nz
  337. call GetBoxSRAMLocation
  338. ld e, l
  339. ld d, h
  340. ld hl, wBoxDataStart
  341. call CopyBoxToOrFromSRAM ; copy old box from WRAM to SRAM
  342. ld a, [wCurrentMenuItem]
  343. set 7, a
  344. ld [wCurrentBoxNum], a
  345. call GetBoxSRAMLocation
  346. ld de, wBoxDataStart
  347. call CopyBoxToOrFromSRAM ; copy new box from SRAM to WRAM
  348. ld hl, wMapTextPtr
  349. ld de, wChangeBoxSavedMapTextPointer
  350. ld a, [hli]
  351. ld [de], a
  352. inc de
  353. ld a, [hl]
  354. ld [de], a
  355. call RestoreMapTextPointer
  356. call SaveSAVtoSRAM
  357. ld hl, wChangeBoxSavedMapTextPointer
  358. call SetMapTextPointer
  359. ld a, SFX_SAVE
  360. call PlaySoundWaitForCurrent
  361. call WaitForSoundToFinish
  362. ret
  363. WhenYouChangeBoxText:
  364. TX_FAR _WhenYouChangeBoxText
  365. db "@"
  366. CopyBoxToOrFromSRAM:
  367. ; copy an entire box from hl to de with b as the SRAM bank
  368. push hl
  369. ld a, SRAM_ENABLE
  370. ld [MBC1SRamEnable], a
  371. ld a, $1
  372. ld [MBC1SRamBankingMode], a
  373. ld a, b
  374. ld [MBC1SRamBank], a
  375. ld bc, wBoxDataEnd - wBoxDataStart
  376. call CopyData
  377. pop hl
  378. ; mark the memory that the box was copied from as am empty box
  379. xor a
  380. ld [hli], a
  381. dec a
  382. ld [hl], a
  383. ld hl, sBox1 ; sBox7
  384. ld bc, sBank2AllBoxesChecksum - sBox1
  385. call SAVCheckSum
  386. ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum
  387. call CalcIndividualBoxCheckSums
  388. xor a
  389. ld [MBC1SRamBankingMode], a
  390. ld [MBC1SRamEnable], a
  391. ret
  392. DisplayChangeBoxMenu:
  393. xor a
  394. ld [H_AUTOBGTRANSFERENABLED], a
  395. ld a, A_BUTTON | B_BUTTON
  396. ld [wMenuWatchedKeys], a
  397. ld a, 11
  398. ld [wMaxMenuItem], a
  399. ld a, 1
  400. ld [wTopMenuItemY], a
  401. ld a, 12
  402. ld [wTopMenuItemX], a
  403. xor a
  404. ld [wMenuWatchMovingOutOfBounds], a
  405. ld a, [wCurrentBoxNum]
  406. and $7f
  407. ld [wCurrentMenuItem], a
  408. ld [wLastMenuItem], a
  409. coord hl, 0, 0
  410. ld b, 2
  411. ld c, 9
  412. call TextBoxBorder
  413. ld hl, ChooseABoxText
  414. call PrintText
  415. coord hl, 11, 0
  416. ld b, 12
  417. ld c, 7
  418. call TextBoxBorder
  419. ld hl, hFlags_0xFFF6
  420. set 2, [hl]
  421. ld de, BoxNames
  422. coord hl, 13, 1
  423. call PlaceString
  424. ld hl, hFlags_0xFFF6
  425. res 2, [hl]
  426. ld a, [wCurrentBoxNum]
  427. and $7f
  428. cp 9
  429. jr c, .singleDigitBoxNum
  430. sub 9
  431. coord hl, 8, 2
  432. ld [hl], "1"
  433. add "0"
  434. jr .next
  435. .singleDigitBoxNum
  436. add "1"
  437. .next
  438. Coorda 9, 2
  439. coord hl, 1, 2
  440. ld de, BoxNoText
  441. call PlaceString
  442. call GetMonCountsForAllBoxes
  443. coord hl, 18, 1
  444. ld de, wBoxMonCounts
  445. ld bc, SCREEN_WIDTH
  446. ld a, $c
  447. .loop
  448. push af
  449. ld a, [de]
  450. and a ; is the box empty?
  451. jr z, .skipPlacingPokeball
  452. ld [hl], $78 ; place pokeball tile next to box name if box not empty
  453. .skipPlacingPokeball
  454. add hl, bc
  455. inc de
  456. pop af
  457. dec a
  458. jr nz, .loop
  459. ld a, 1
  460. ld [H_AUTOBGTRANSFERENABLED], a
  461. ret
  462. ChooseABoxText:
  463. TX_FAR _ChooseABoxText
  464. db "@"
  465. BoxNames:
  466. db "BOX 1"
  467. next "BOX 2"
  468. next "BOX 3"
  469. next "BOX 4"
  470. next "BOX 5"
  471. next "BOX 6"
  472. next "BOX 7"
  473. next "BOX 8"
  474. next "BOX 9"
  475. next "BOX10"
  476. next "BOX11"
  477. next "BOX12@"
  478. BoxNoText:
  479. db "BOX No.@"
  480. EmptyAllSRAMBoxes:
  481. ; marks all boxes in SRAM as empty (initialisation for the first time the
  482. ; player changes the box)
  483. ld a, SRAM_ENABLE
  484. ld [MBC1SRamEnable], a
  485. ld a, $1
  486. ld [MBC1SRamBankingMode], a
  487. ld a, 2
  488. ld [MBC1SRamBank], a
  489. call EmptySRAMBoxesInBank
  490. ld a, 3
  491. ld [MBC1SRamBank], a
  492. call EmptySRAMBoxesInBank
  493. xor a
  494. ld [MBC1SRamBankingMode], a
  495. ld [MBC1SRamEnable], a
  496. ret
  497. EmptySRAMBoxesInBank:
  498. ; marks every box in the current SRAM bank as empty
  499. ld hl, sBox1 ; sBox7
  500. call EmptySRAMBox
  501. ld hl, sBox2 ; sBox8
  502. call EmptySRAMBox
  503. ld hl, sBox3 ; sBox9
  504. call EmptySRAMBox
  505. ld hl, sBox4 ; sBox10
  506. call EmptySRAMBox
  507. ld hl, sBox5 ; sBox11
  508. call EmptySRAMBox
  509. ld hl, sBox6 ; sBox12
  510. call EmptySRAMBox
  511. ld hl, sBox1 ; sBox7
  512. ld bc, sBank2AllBoxesChecksum - sBox1
  513. call SAVCheckSum
  514. ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum
  515. call CalcIndividualBoxCheckSums
  516. ret
  517. EmptySRAMBox:
  518. xor a
  519. ld [hli], a
  520. dec a
  521. ld [hl], a
  522. ret
  523. GetMonCountsForAllBoxes:
  524. ld hl, wBoxMonCounts
  525. push hl
  526. ld a, SRAM_ENABLE
  527. ld [MBC1SRamEnable], a
  528. ld a, $1
  529. ld [MBC1SRamBankingMode], a
  530. ld a, $2
  531. ld [MBC1SRamBank], a
  532. call GetMonCountsForBoxesInBank
  533. ld a, $3
  534. ld [MBC1SRamBank], a
  535. call GetMonCountsForBoxesInBank
  536. xor a
  537. ld [MBC1SRamBankingMode], a
  538. ld [MBC1SRamEnable], a
  539. pop hl
  540. ; copy the count for the current box from WRAM
  541. ld a, [wCurrentBoxNum]
  542. and $7f
  543. ld c, a
  544. ld b, 0
  545. add hl, bc
  546. ld a, [wNumInBox]
  547. ld [hl], a
  548. ret
  549. GetMonCountsForBoxesInBank:
  550. ld a, [sBox1] ; sBox7
  551. ld [hli], a
  552. ld a, [sBox2] ; sBox8
  553. ld [hli], a
  554. ld a, [sBox3] ; sBox9
  555. ld [hli], a
  556. ld a, [sBox4] ; sBox10
  557. ld [hli], a
  558. ld a, [sBox5] ; sBox11
  559. ld [hli], a
  560. ld a, [sBox6] ; sBox12
  561. ld [hli], a
  562. ret
  563. SAVCheckRandomID:
  564. ;checks if Sav file is the same by checking player's name 1st letter ($a598)
  565. ; and the two random numbers generated at game beginning
  566. ;(which are stored at wPlayerID)s
  567. ld a, $0a
  568. ld [MBC1SRamEnable], a
  569. ld a, $01
  570. ld [MBC1SRamBankingMode], a
  571. ld [MBC1SRamBank], a
  572. ld a, [sPlayerName]
  573. and a
  574. jr z, .next
  575. ld hl, sPlayerName
  576. ld bc, sMainDataCheckSum - sPlayerName
  577. call SAVCheckSum
  578. ld c, a
  579. ld a, [sMainDataCheckSum]
  580. cp c
  581. jr nz, .next
  582. ld hl, sMainData + (wPlayerID - wMainDataStart) ; player ID
  583. ld a, [hli]
  584. ld h, [hl]
  585. ld l, a
  586. ld a, [wPlayerID]
  587. cp l
  588. jr nz, .next
  589. ld a, [wPlayerID + 1]
  590. cp h
  591. .next
  592. ld a, $00
  593. ld [MBC1SRamBankingMode], a
  594. ld [MBC1SRamEnable], a
  595. ret
  596. SaveHallOfFameTeams:
  597. ld a, [wNumHoFTeams]
  598. dec a
  599. cp HOF_TEAM_CAPACITY
  600. jr nc, .shiftHOFTeams
  601. ld hl, sHallOfFame
  602. ld bc, HOF_TEAM
  603. call AddNTimes
  604. ld e, l
  605. ld d, h
  606. ld hl, wHallOfFame
  607. ld bc, HOF_TEAM
  608. jr HallOfFame_Copy
  609. .shiftHOFTeams
  610. ; if the space designated for HOF teams is full, then shift all HOF teams to the next slot, making space for the new HOF team
  611. ; this deletes the last HOF team though
  612. ld hl, sHallOfFame + HOF_TEAM
  613. ld de, sHallOfFame
  614. ld bc, HOF_TEAM * (HOF_TEAM_CAPACITY - 1)
  615. call HallOfFame_Copy
  616. ld hl, wHallOfFame
  617. ld de, sHallOfFame + HOF_TEAM * (HOF_TEAM_CAPACITY - 1)
  618. ld bc, HOF_TEAM
  619. jr HallOfFame_Copy
  620. LoadHallOfFameTeams:
  621. ld hl, sHallOfFame
  622. ld bc, HOF_TEAM
  623. ld a, [wHoFTeamIndex]
  624. call AddNTimes
  625. ld de, wHallOfFame
  626. ld bc, HOF_TEAM
  627. ; fallthrough
  628. HallOfFame_Copy:
  629. ld a, SRAM_ENABLE
  630. ld [MBC1SRamEnable], a
  631. ld a, $1
  632. ld [MBC1SRamBankingMode], a
  633. xor a
  634. ld [MBC1SRamBank], a
  635. call CopyData
  636. xor a
  637. ld [MBC1SRamBankingMode], a
  638. ld [MBC1SRamEnable], a
  639. ret
  640. ClearSAV:
  641. ld a, SRAM_ENABLE
  642. ld [MBC1SRamEnable], a
  643. ld a, $1
  644. ld [MBC1SRamBankingMode], a
  645. xor a
  646. call PadSRAM_FF
  647. ld a, $1
  648. call PadSRAM_FF
  649. ld a, $2
  650. call PadSRAM_FF
  651. ld a, $3
  652. call PadSRAM_FF
  653. xor a
  654. ld [MBC1SRamBankingMode], a
  655. ld [MBC1SRamEnable], a
  656. ret
  657. PadSRAM_FF:
  658. ld [MBC1SRamBank], a
  659. ld hl, $a000
  660. ld bc, $2000
  661. ld a, $ff
  662. jp FillMemory