void af_rtc_read_command(struct af_rtc* rtc, uint8_t* cmd) { const struct tm *rtc_time; /* read RTC block (cmd[3]: block number) */ switch (cmd[3]) { case 0: cmd[4] = 0x00; cmd[5] = 0x02; cmd[12] = 0x00; break; case 1: DebugMessage(M64MSG_ERROR, "AF-RTC read command: cannot read block 1"); break; case 2: rtc_time = af_rtc_get_time(rtc); cmd[4] = byte2bcd(rtc_time->tm_sec); cmd[5] = byte2bcd(rtc_time->tm_min); cmd[6] = 0x80 + byte2bcd(rtc_time->tm_hour); cmd[7] = byte2bcd(rtc_time->tm_mday); cmd[8] = byte2bcd(rtc_time->tm_wday); cmd[9] = byte2bcd(rtc_time->tm_mon + 1); cmd[10] = byte2bcd(rtc_time->tm_year); cmd[11] = byte2bcd(rtc_time->tm_year / 100); cmd[12] = 0x00; // status break; } }
void CEeprom::EepromCommand(uint8_t * Command) { time_t curtime_time; struct tm curtime; if (g_System->m_SaveUsing == SaveChip_Auto) { g_System->m_SaveUsing = SaveChip_Eeprom_4K; } switch (Command[2]) { case 0: // check if (g_System->m_SaveUsing != SaveChip_Eeprom_4K && g_System->m_SaveUsing != SaveChip_Eeprom_16K) { Command[1] |= 0x80; break; } if (Command[1] != 3) { Command[1] |= 0x40; if ((Command[1] & 3) > 0) { Command[3] = 0x00; } if ((Command[1] & 3) > 1) { Command[4] = (g_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0; } if ((Command[1] & 3) > 2) { Command[5] = 0x00; } } else { Command[3] = 0x00; Command[4] = g_System->m_SaveUsing == SaveChip_Eeprom_4K ? 0x80 : 0xC0; Command[5] = 0x00; } break; case 4: // Read from Eeprom if (Command[0] != 2 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } if (Command[1] != 8 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } ReadFrom(&Command[4], Command[3]); break; case 5: //Write to Eeprom if (Command[0] != 10 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } if (Command[1] != 1 && bHaveDebugger()) { g_Notify->DisplayError("What am I meant to do with this Eeprom Command"); } WriteTo(&Command[4], Command[3]); break; case 6: //RTC Status query Command[3] = 0x00; Command[4] = 0x10; Command[5] = 0x00; break; case 7: //Read RTC block switch (Command[3]) { case 0: //Block number Command[4] = 0x00; Command[5] = 0x02; Command[12] = 0x00; break; case 1: //read block, Command[2], Unimplemented break; case 2: //Set RTC Time time(&curtime_time); memcpy(&curtime, localtime(&curtime_time), sizeof(curtime)); // fd's fix Command[4] = byte2bcd(curtime.tm_sec); Command[5] = byte2bcd(curtime.tm_min); Command[6] = 0x80 + byte2bcd(curtime.tm_hour); Command[7] = byte2bcd(curtime.tm_mday); Command[8] = byte2bcd(curtime.tm_wday); Command[9] = byte2bcd(curtime.tm_mon + 1); Command[10] = byte2bcd(curtime.tm_year); Command[11] = byte2bcd(curtime.tm_year / 100); Command[12] = 0x00; // status break; } break; case 8: //Write RTC, unimplemented if (g_Settings->LoadDword(Debugger_ShowPifErrors)) { g_Notify->DisplayError("Write RTC, unimplemented"); } break; default: if (g_Settings->LoadDword(Debugger_ShowPifErrors)) { g_Notify->DisplayError(stdstr_f("Unknown EepromCommand %d", Command[2]).c_str()); } } }