From fb9b06e37d816e427417a25778a01414206406d3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 5 Nov 2018 21:38:39 +0100 Subject: [PATCH 1/2] CalculateBlocksizeForOffset -> CalculateBlockIndexForOffset --- main.cpp | 10 +++++----- xbit.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 9dc0dd4..b17ba2e 100644 --- a/main.cpp +++ b/main.cpp @@ -504,7 +504,7 @@ bool XbitFlasher::EraseBank(int bank) int res = 0; int bank_size = GetSizeForBank(this->memory_layout_id, bank); int current_block = GetStartblockForBank(this->memory_layout_id, bank); - int block_count = CalculateBlocksizeForOffset(bank_size); + int block_count = CalculateBlockIndexForOffset(bank_size); if(IsDeviceWriteprotected()){ printf("Modchip is write-protected?!?! Try resetting it by replugging USB cable..\n"); @@ -539,7 +539,7 @@ bool XbitFlasher::FlashBank(int bank, uchar *input_data, int data_length) int res = 0; int bank_size = GetSizeForBank(this->memory_layout_id, bank); int start_block = GetStartblockForBank(this->memory_layout_id, bank); - int block_count = CalculateBlocksizeForOffset(bank_size); + int block_count = CalculateBlockIndexForOffset(bank_size); if(bank_size != data_length){ printf("BIOS size %i does not match bank size %i\n", data_length, bank_size); @@ -593,7 +593,7 @@ bool XbitFlasher::ReadBank(int bank, uchar *output_data, int *num_bytes_read) int res; int bank_size = GetSizeForBank(this->memory_layout_id, bank); int start_block = GetStartblockForBank(this->memory_layout_id, bank); - int block_count = CalculateBlocksizeForOffset(bank_size); + int block_count = CalculateBlockIndexForOffset(bank_size); if(IsDeviceWriteprotected()){ printf("Modchip is write-protected?!?! Try resetting it by replugging USB cable..\n"); @@ -661,7 +661,7 @@ bool XbitFlasher::VerifyBank(int bank, uchar *input_data, int data_length) return true; } -uchar XbitFlasher::CalculateBlocksizeForOffset(int offset) +uchar XbitFlasher::CalculateBlockIndexForOffset(int offset) { if(offset == 0){ return 0; @@ -679,7 +679,7 @@ int XbitFlasher::GetStartblockForBank(int layout, int bank) for(int i=1; i <= bank; i++){ offset += GetSizeForBank(layout, i); } - return CalculateBlocksizeForOffset(offset); + return CalculateBlockIndexForOffset(offset); } int XbitFlasher::GetSizeForBank(int layout, int bank) diff --git a/xbit.h b/xbit.h index ca494b8..e15927c 100644 --- a/xbit.h +++ b/xbit.h @@ -155,7 +155,7 @@ class XbitFlasher bool WriteFlash(uchar flash, uchar sector, uint16 offset, uchar *buffer, uint16 nBytes); bool EraseBlock(int flash, int sector); - uchar CalculateBlocksizeForOffset(int offset); + uchar CalculateBlockIndexForOffset(int offset); int GetStartblockForBank(int layout, int bank); int GetSizeForBank(int layout, int bank); }; From 821c82117acc9ac4f472ac44ae3fb5c472df83e1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 5 Nov 2018 21:41:12 +0100 Subject: [PATCH 2/2] Fix off-by-one in GetStartblockForBank --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index b17ba2e..579dd6f 100644 --- a/main.cpp +++ b/main.cpp @@ -676,7 +676,7 @@ uchar XbitFlasher::CalculateBlockIndexForOffset(int offset) int XbitFlasher::GetStartblockForBank(int layout, int bank) { int offset = 0; - for(int i=1; i <= bank; i++){ + for(int i=1; i < bank; i++){ offset += GetSizeForBank(layout, i); } return CalculateBlockIndexForOffset(offset);