Skip to content

Commit

Permalink
Merge pull request #3 from srett/fix-bank-offset
Browse files Browse the repository at this point in the history
Fix bank offset calculation
  • Loading branch information
tuxuser authored Nov 6, 2018
2 parents eb3b3ba + 821c821 commit f58f1e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -676,10 +676,10 @@ uchar XbitFlasher::CalculateBlocksizeForOffset(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 CalculateBlocksizeForOffset(offset);
return CalculateBlockIndexForOffset(offset);
}

int XbitFlasher::GetSizeForBank(int layout, int bank)
Expand Down
2 changes: 1 addition & 1 deletion xbit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit f58f1e1

Please sign in to comment.