From 025ca2461cc60ac28eb9d5be3247287c68b2280d Mon Sep 17 00:00:00 2001 From: splash5 <2173030+splash5@users.noreply.github.com> Date: Thu, 17 Oct 2019 12:37:33 +0800 Subject: [PATCH] Fix wrong block address --- Cart_Reader/FLASH.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index c3f05f0..4af769a 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -1425,6 +1425,7 @@ void writeFlashE28FXXXJ3A() { } uint32_t block_addr; + uint32_t block_addr_mask = ~(sectorSize - 1); // Fill sdBuffer for (uint32_t currByte = 0; currByte < fileSize; currByte += 512) { @@ -1434,7 +1435,7 @@ void writeFlashE28FXXXJ3A() { if (currByte % 2048 == 0) PORTB ^= (1 << 4); - block_addr = currByte / sectorSize; + block_addr = currByte & block_addr_mask; for (uint32_t c = 0; c < 512; c += bufferSize) { // write to buffer start