mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-14 08:55:06 +01:00
GBA.ino: Get rid of calcChecksumStr as a global
Frees 150 bytes of program space and 5 bytes of global ram space.
This commit is contained in:
parent
3bb63d77e3
commit
d4c5f6ec5b
@ -6,7 +6,6 @@
|
|||||||
/******************************************
|
/******************************************
|
||||||
Variables
|
Variables
|
||||||
*****************************************/
|
*****************************************/
|
||||||
char calcChecksumStr[5];
|
|
||||||
boolean readType;
|
boolean readType;
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
@ -569,6 +568,16 @@ void writeByte_GBA(unsigned long myAddress, byte myData) {
|
|||||||
/******************************************
|
/******************************************
|
||||||
GBA ROM Functions
|
GBA ROM Functions
|
||||||
*****************************************/
|
*****************************************/
|
||||||
|
// Compute the checksum of rom header
|
||||||
|
// "header" must contain at least the rom's first 188 bytes
|
||||||
|
byte checksumHeader_GBA(const byte *header) {
|
||||||
|
byte result = 0x00;
|
||||||
|
for (byte n = 0xA0; n < 0xBD; n++) {
|
||||||
|
result -= header[n];
|
||||||
|
}
|
||||||
|
return result - 0x19;
|
||||||
|
}
|
||||||
|
|
||||||
// Read info out of rom header
|
// Read info out of rom header
|
||||||
void getCartInfo_GBA() {
|
void getCartInfo_GBA() {
|
||||||
char saveTypeStr[14];
|
char saveTypeStr[14];
|
||||||
@ -760,22 +769,21 @@ void getCartInfo_GBA() {
|
|||||||
// Get ROM version
|
// Get ROM version
|
||||||
romVersion = sdBuffer[0xBC];
|
romVersion = sdBuffer[0xBC];
|
||||||
|
|
||||||
// Get Checksum as string
|
// Calculate Checksum
|
||||||
|
byte calcChecksum = checksumHeader_GBA(sdBuffer);
|
||||||
|
|
||||||
|
// Convert checksum from header into string
|
||||||
|
// (used in compare_checksum_GBA... it should just exchange an integer
|
||||||
|
// instead)
|
||||||
sprintf(checksumStr, "%02X", sdBuffer[0xBD]);
|
sprintf(checksumStr, "%02X", sdBuffer[0xBD]);
|
||||||
|
|
||||||
// Calculate Checksum
|
|
||||||
int calcChecksum = 0x00;
|
|
||||||
for (int n = 0xA0; n < 0xBD; n++) {
|
|
||||||
calcChecksum -= sdBuffer[n];
|
|
||||||
}
|
|
||||||
calcChecksum = (calcChecksum - 0x19) & 0xFF;
|
|
||||||
// Turn into string
|
|
||||||
sprintf(calcChecksumStr, "%02X", calcChecksum);
|
|
||||||
|
|
||||||
// Compare checksum
|
// Compare checksum
|
||||||
if (strcmp(calcChecksumStr, checksumStr) != 0) {
|
if (sdBuffer[0xBD] != calcChecksum) {
|
||||||
|
char calcChecksumStr[3];
|
||||||
display_Clear();
|
display_Clear();
|
||||||
print_Msg(F("Result: "));
|
print_Msg(F("Result: "));
|
||||||
|
// Turn into string
|
||||||
|
sprintf(calcChecksumStr, "%02X", calcChecksum);
|
||||||
println_Msg(calcChecksumStr);
|
println_Msg(calcChecksumStr);
|
||||||
print_Error(F("Checksum Error"), false);
|
print_Error(F("Checksum Error"), false);
|
||||||
println_Msg(F(""));
|
println_Msg(F(""));
|
||||||
@ -912,15 +920,9 @@ boolean compare_checksum_GBA() {
|
|||||||
myFile.read(sdBuffer, 512);
|
myFile.read(sdBuffer, 512);
|
||||||
myFile.close();
|
myFile.close();
|
||||||
|
|
||||||
// Calculate Checksum
|
// Calculate Checksum and turn into string
|
||||||
int calcChecksum = 0x00;
|
char calcChecksumStr[3];
|
||||||
for (int n = 0xA0; n < 0xBD; n++) {
|
sprintf(calcChecksumStr, "%02X", checksumHeader_GBA(sdBuffer));
|
||||||
calcChecksum -= sdBuffer[n];
|
|
||||||
}
|
|
||||||
calcChecksum = (calcChecksum - 0x19) & 0xFF;
|
|
||||||
|
|
||||||
// Turn into string
|
|
||||||
sprintf(calcChecksumStr, "%02X", calcChecksum);
|
|
||||||
print_Msg(calcChecksumStr);
|
print_Msg(calcChecksumStr);
|
||||||
|
|
||||||
if (strcmp(calcChecksumStr, checksumStr) == 0) {
|
if (strcmp(calcChecksumStr, checksumStr) == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user