Skip to content

Commit

Permalink
FIX: Adding retry logic for EZFO
Browse files Browse the repository at this point in the history
  • Loading branch information
afska committed May 9, 2024
1 parent 4c176d9 commit 4a50c84
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/utils/flashcartio/ezflashomega/io_ezfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

// [!] Some small optimizations were made for piuGBA

static void EWRAM_CODE delay(u32 R0) {
int volatile i;

for (i = R0; i; --i)
;
return;
}

// --------------------------------------------------------------------
inline __attribute__((always_inline)) void SetSDControl(u16 control) {
*(vu16*)0x9fe0000 = 0xd200;
Expand Down Expand Up @@ -59,9 +67,11 @@ inline __attribute__((always_inline)) u32 Read_SD_sectors(u32 address,
u16 i;
u16 blocks;
u32 res;
u32 times = 2;
for (i = 0; i < count; i += 4) {
blocks = (count - i > 4) ? 4 : (count - i);

read_again:
*(vu16*)0x9fe0000 = 0xd200;
*(vu16*)0x8000000 = 0x1500;
*(vu16*)0x8020000 = 0xd200;
Expand All @@ -74,8 +84,11 @@ inline __attribute__((always_inline)) u32 Read_SD_sectors(u32 address,
res = Wait_SD_Response();
SD_Enable();
if (res == 1) {
SD_Disable();
return 1;
times--;
if (times) {
delay(5000);
goto read_again;
}
}

dmaCopy((void*)0x9E00000, SDbuffer + i * 512, blocks * 512);
Expand Down

0 comments on commit 4a50c84

Please sign in to comment.