From 7e8902ac2a9ae3a983fa0519b4f7026d04d7d0fd Mon Sep 17 00:00:00 2001 From: fincs Date: Fri, 31 Dec 2021 13:19:14 +0100 Subject: [PATCH] fix warnings in arm7 readUserSettings --- source/arm7/userSettings.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/source/arm7/userSettings.c b/source/arm7/userSettings.c index 7e0271f6..6e0b27cb 100644 --- a/source/arm7/userSettings.c +++ b/source/arm7/userSettings.c @@ -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]; + }