Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
add flash_ prefix to flasher functions; flash_erase_slot() function e…
Browse files Browse the repository at this point in the history
…rases the gallery in the slot.
  • Loading branch information
untoxa authored and HerrZatacke committed Jun 28, 2022
1 parent e51390a commit 40012eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
7 changes: 4 additions & 3 deletions include/flasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <stdint.h>

uint8_t check_gallery_exist(uint8_t slot) NONBANKED;
uint8_t load_gallery_from_slot(uint8_t slot) BANKED;
uint8_t save_gallery_to_slot(uint8_t slot) BANKED;
uint8_t flash_check_gallery_exist(uint8_t slot) NONBANKED;
uint8_t flash_load_gallery_from_slot(uint8_t slot) BANKED;
uint8_t flash_save_gallery_to_slot(uint8_t slot) BANKED;
uint8_t flash_erase_slot(uint8_t slot) BANKED;

#endif
19 changes: 15 additions & 4 deletions src/flasher.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inline uint8_t slot_to_bank(uint8_t slot, uint8_t ofs) {
return (((slot + 2) << 1) + ofs) << 2;
}

uint8_t check_gallery_exist(uint8_t slot) NONBANKED {
uint8_t flash_check_gallery_exist(uint8_t slot) NONBANKED {
uint8_t _save = _current_bank, result;
SWITCH_ROM(slot_to_bank(slot, 0));
result = ((saved_game_data.magic[0] == 'M') &&
Expand All @@ -41,13 +41,17 @@ void restore_sram_bank(uint8_t bank) NONBANKED {
SWITCH_ROM(_save);
}

uint8_t load_gallery_from_slot(uint8_t slot) BANKED {
uint8_t flash_load_gallery_from_slot(uint8_t slot) BANKED {
// check saved gallery exist
if (!flash_check_gallery_exist(slot)) return FALSE;
// read 8 SRAM banks from the flash sector
save_rom_bank = slot_to_bank(slot, 0);
save_sram_bank_offset = FIRST_HALF_OFS;
for (uint8_t i = 0; i < FIRST_HALF_LEN; i++) {
SWITCH_RAM(i + FIRST_HALF_OFS);
restore_sram_bank(i);
}
// read the next 8 SRAM banks from the next flash sector
save_rom_bank = slot_to_bank(slot, 1);
save_sram_bank_offset = SECOND_HALF_OFS;
for (uint8_t i = 0; i < SECOND_HALF_LEN; i++) {
Expand All @@ -60,7 +64,7 @@ uint8_t load_gallery_from_slot(uint8_t slot) BANKED {
extern uint8_t erase_flash() OLDCALL; // erases FLASH sector: 64K or 4 banks
extern uint8_t save_sram_banks(uint8_t count) OLDCALL; // copies up to count SRAM banks to FLASH

uint8_t save_gallery_to_slot(uint8_t slot) BANKED {
uint8_t flash_save_gallery_to_slot(uint8_t slot) BANKED {
// erase the sector and save first 8 SRAM banks
save_sram_bank_offset = FIRST_HALF_OFS;
save_rom_bank = slot_to_bank(slot, 0);
Expand All @@ -71,4 +75,11 @@ uint8_t save_gallery_to_slot(uint8_t slot) BANKED {
save_rom_bank = slot_to_bank(slot, 1);
if (!erase_flash()) return FALSE;
return save_sram_banks(SECOND_HALF_LEN); // update offset
}
}

uint8_t flash_erase_slot(uint8_t slot) BANKED {
save_rom_bank = slot_to_bank(slot, 0);
if (!erase_flash()) return FALSE;
save_rom_bank = slot_to_bank(slot, 1);
return erase_flash();
}

0 comments on commit 40012eb

Please sign in to comment.