skip reprogramming flash with identical content

this is a terrible workaround: the disabled interrupts of flash copy(?)
cause USB HID input to break. with this change, I can play Kirby
merely by selecting it from the menu, resetting once I reach the
title screen, then selecting it from the menu a second time.
This commit is contained in:
Jeff Epler 2025-03-05 11:18:56 -06:00
parent eb646218f5
commit 94381019f4

View file

@ -2,6 +2,8 @@
RP2350 flash driver RP2350 flash driver
*/ */
#include <string.h>
#include "flash_t.h" #include "flash_t.h"
#include "hardware/flash.h" #include "hardware/flash.h"
@ -24,6 +26,7 @@ int flash_load(const char * filename)
if (f) { if (f) {
while ( (offset < (HW_FLASH_STORAGE_TOP-FLASH_SECTOR_SIZE)) && (n = emu_FileRead(cache,FLASH_SECTOR_SIZE,f) ) ) { while ( (offset < (HW_FLASH_STORAGE_TOP-FLASH_SECTOR_SIZE)) && (n = emu_FileRead(cache,FLASH_SECTOR_SIZE,f) ) ) {
//memcpy(cache, (unsigned char *)offset, n); //memcpy(cache, (unsigned char *)offset, n);
if (memcmp(cache, (unsigned char*)XIP_BASE + offset, n)) {
uint32_t ints = save_and_disable_interrupts(); uint32_t ints = save_and_disable_interrupts();
flash_range_erase(offset, FLASH_SECTOR_SIZE); flash_range_erase(offset, FLASH_SECTOR_SIZE);
flash_range_program(offset, (const uint8_t *)&cache[0], FLASH_SECTOR_SIZE); flash_range_program(offset, (const uint8_t *)&cache[0], FLASH_SECTOR_SIZE);
@ -35,6 +38,7 @@ int flash_load(const char * filename)
//emu_printi(pt[1]); //emu_printi(pt[1]);
//emu_printi(pt[2]); //emu_printi(pt[2]);
//emu_printi(pt[3]); //emu_printi(pt[3]);
}
offset += FLASH_SECTOR_SIZE; offset += FLASH_SECTOR_SIZE;
size += n; size += n;
} }