Skip to content

Commit

Permalink
Fix multiple accuracy issues with the SRAM & Flash backup storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arignir committed Feb 15, 2024
1 parent 3b647de commit dd87ae3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
7 changes: 2 additions & 5 deletions accuracy/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
screenshot ./.tests_screenshots/jsmolka_sram.png
''',
screenshot='jsmolka_sram.png',
skip=True,
),
Test(
name="Jsmolka - save/none.gba",
Expand All @@ -82,21 +81,19 @@
name="Jsmolka - save/flash64.gba",
rom='jsmolka-flash64.gba',
code='''
frame 10
frame 110
screenshot ./.tests_screenshots/jsmolka_flash64.png
''',
screenshot='jsmolka_flash64.png',
skip=True,
),
Test(
name="Jsmolka - save/flash128.gba",
rom='jsmolka-flash128.gba',
code='''
frame 10
frame 110
screenshot ./.tests_screenshots/jsmolka_flash128.png
''',
screenshot='jsmolka_flash128.png',
skip=True,
),

# mGBA suite
Expand Down
24 changes: 9 additions & 15 deletions source/gba/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mem_openbus_read(
})

/*
** Wriote a data of type T to memory at the given address.
** Write a data of type T to memory at the given address.
**
** T must be either uint32_t, uint16_t or uint8_t.
*/
Expand Down Expand Up @@ -468,20 +468,14 @@ mem_openbus_read(
}; \
case SRAM_REGION: \
case SRAM_MIRROR_REGION: \
_Generic(val, \
uint32_t: ({ \
mem_backup_storage_write8((gba), (unaligned_addr) + 0, (uint8_t)((val) >> 0)); \
mem_backup_storage_write8((gba), (unaligned_addr) + 1, (uint8_t)((val) >> 8)); \
mem_backup_storage_write8((gba), (unaligned_addr) + 2, (uint8_t)((val) >> 16)); \
mem_backup_storage_write8((gba), (unaligned_addr) + 3, (uint8_t)((val) >> 24)); \
}), \
uint16_t: ({ \
mem_backup_storage_write8((gba), (unaligned_addr) + 0, (uint8_t)((val) >> 0)); \
mem_backup_storage_write8((gba), (unaligned_addr) + 1, (uint8_t)((val) >> 8)); \
}), \
default: ({ \
mem_backup_storage_write8((gba), (unaligned_addr), (val)); \
}) \
/*
** All writes to the backup storage are u8 writes, eventually rotated if the
** address isn't aligned on T.
*/ \
mem_backup_storage_write8( \
(gba), \
(unaligned_addr), \
((val) >> (8 * ((unaligned_addr) % sizeof(T)))) \
); \
break; \
default: { \
Expand Down
12 changes: 4 additions & 8 deletions source/gba/memory/storage/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ mem_flash_write8(
case FLASH_CMD_ENTER_IDENTITY: flash->identity_mode = true; break;
case FLASH_CMD_EXIT_IDENTITY: flash->identity_mode = false; break;
case FLASH_CMD_PREP_ERASE: flash->state = FLASH_STATE_ERASE; break;
case FLASH_CMD_ERASE_CHIP: {
if (flash->state == FLASH_STATE_ERASE) {
memset(gba->shared_data.backup_storage.data, 0xFF, gba->shared_data.backup_storage.size);
gba->shared_data.backup_storage.dirty = true;
}
break;
};
case FLASH_CMD_WRITE: flash->state = FLASH_STATE_WRITE; break;
case FLASH_CMD_SET_BANK: {
if (gba->memory.backup_storage.type == BACKUP_FLASH128) {
Expand All @@ -68,9 +61,12 @@ mem_flash_write8(
break;
};
}
} else if (flash->state == FLASH_STATE_ERASE && addr == 0x5555 && val == FLASH_CMD_ERASE_CHIP) {
memset(gba->shared_data.backup_storage.data, 0xFF, gba->shared_data.backup_storage.size);
gba->shared_data.backup_storage.dirty = true;
flash->state = FLASH_STATE_READY;
} else if (flash->state == FLASH_STATE_ERASE && !(addr & ~0xF000) && val == FLASH_CMD_ERASE_SECTOR) {
// Erase the desired sector

addr &= 0xF000;
memset(gba->shared_data.backup_storage.data + addr + flash->bank * FLASH64_SIZE, 0xFF, 0x1000);
gba->shared_data.backup_storage.dirty = true;
Expand Down

0 comments on commit dd87ae3

Please sign in to comment.