Skip to content

Commit

Permalink
fix warnings in arm7 readUserSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
fincs committed Jan 8, 2022
1 parent f2bb1f1 commit 7e8902a
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions source/arm7/userSettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,40 @@
void readUserSettings() {
//---------------------------------------------------------------------------------

PERSONAL_DATA slot1;
PERSONAL_DATA slot2;
PERSONAL_DATA slots[2];

short slot1count, slot2count;
short slot1CRC, slot2CRC;

uint32 userSettingsBase;
readFirmware( 0x20, &userSettingsBase,2);

uint32 slot1Address = userSettingsBase * 8;
uint32 slot2Address = userSettingsBase * 8 + 0x100;
readFirmware( slot1Address , &slot1, sizeof(PERSONAL_DATA));
readFirmware( slot2Address , &slot2, sizeof(PERSONAL_DATA));

readFirmware( slot1Address , &slots[0], sizeof(PERSONAL_DATA));
readFirmware( slot2Address , &slots[1], sizeof(PERSONAL_DATA));
readFirmware( slot1Address + 0x70, &slot1count, 2);
readFirmware( slot2Address + 0x70, &slot2count, 2);
readFirmware( slot1Address + 0x72, &slot1CRC, 2);
readFirmware( slot2Address + 0x72, &slot2CRC, 2);

// default to slot 1 user Settings
void *currentSettings = &slot1;
short calc1CRC = swiCRC16( 0xffff, &slot1, sizeof(PERSONAL_DATA));
short calc2CRC = swiCRC16( 0xffff, &slot2, sizeof(PERSONAL_DATA));
int currentSettingsSlot = 0;

short calc1CRC = swiCRC16( 0xffff, &slots[0], sizeof(PERSONAL_DATA));
short calc2CRC = swiCRC16( 0xffff, &slots[1], sizeof(PERSONAL_DATA));

// bail out if neither slot is valid
if ( calc1CRC != slot1CRC && calc2CRC != slot2CRC) return;

// if both slots are valid pick the most recent
if ( calc1CRC == slot1CRC && calc2CRC == slot2CRC ) {
currentSettings = (slot2count == (( slot1count + 1 ) & 0x7f) ? &slot2 : &slot1);
if ( calc1CRC == slot1CRC && calc2CRC == slot2CRC ) {
currentSettingsSlot = (slot2count == (( slot1count + 1 ) & 0x7f) ? 1 : 0);
} else {
if ( calc2CRC == slot2CRC )
currentSettings = &slot2;
currentSettingsSlot = 1;
}
memcpy ( PersonalData, currentSettings, sizeof(PERSONAL_DATA));
*PersonalData = slots[currentSettingsSlot];

}

0 comments on commit 7e8902a

Please sign in to comment.