Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit 68ae4b7

Browse files
committed
GBA: Fix writing file smaller than 4MB
1 parent 8d99ac5 commit 68ae4b7

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Cart_Reader/GBA.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,9 @@ void erase369in1(byte blockNumber) {
26132613
unsigned long lastBlock = 0x2000000;
26142614
if (fileSize < lastBlock)
26152615
lastBlock = startBlock + fileSize;
2616+
unsigned long lastSector = 0x400000;
2617+
if (fileSize < lastSector)
2618+
lastSector = fileSize;
26162619

26172620
//Initialize progress bar
26182621
uint32_t processedProgressBar = 0;
@@ -2626,7 +2629,7 @@ void erase369in1(byte blockNumber) {
26262629
// Set-up 369-in-1 mapper
26272630
mapBlock369in1((currBank + currBlock) / 1024 / 1024);
26282631
// 256KB flashrom sector size
2629-
for (unsigned long currSector = 0; currSector < 0x400000; currSector += 0x40000) {
2632+
for (unsigned long currSector = 0; currSector < lastSector; currSector += 0x40000) {
26302633
// Unlock Sector
26312634
writeWord_GBA(currBlock + currSector, 0x60);
26322635
writeWord_GBA(currBlock + currSector, 0xD0);
@@ -2659,6 +2662,9 @@ void write369in1(byte blockNumber) {
26592662
unsigned long lastBlock = 0x2000000;
26602663
if (fileSize < lastBlock)
26612664
lastBlock = startBlock + fileSize;
2665+
unsigned long lastSector = 0x400000;
2666+
if (fileSize < lastSector)
2667+
lastSector = fileSize;
26622668

26632669
//Initialize progress bar
26642670
uint32_t processedProgressBar = 0;
@@ -2674,7 +2680,7 @@ void write369in1(byte blockNumber) {
26742680
mapBlock369in1((currBank + currBlock) / 1024 / 1024);
26752681

26762682
// 256KB flashrom sector size
2677-
for (unsigned long currSector = 0; currSector < 0x400000; currSector += 0x40000) {
2683+
for (unsigned long currSector = 0; currSector < lastSector; currSector += 0x40000) {
26782684
// Unlock Sector
26792685
//writeWord_GBA(currBlock + currSector, 0x60);
26802686
//writeWord_GBA(currBlock + currSector, 0xD0);

0 commit comments

Comments
 (0)