diff --git a/bugs/shadowTheifBug/Screenshot_20190426-220702.png b/bugs/shadowTheifBug/Screenshot_20190426-220702.png new file mode 100644 index 0000000..71c5331 Binary files /dev/null and b/bugs/shadowTheifBug/Screenshot_20190426-220702.png differ diff --git a/bugs/shadowTheifBug/text.txt b/bugs/shadowTheifBug/text.txt new file mode 100644 index 0000000..d4934fa --- /dev/null +++ b/bugs/shadowTheifBug/text.txt @@ -0,0 +1,4 @@ +Whenever I register ShadowThief, this happens: + +It happens on any version of Mu +PHEM/ST is fine \ No newline at end of file diff --git a/qtBuildSystem/Mu/Mu.pro b/qtBuildSystem/Mu/Mu.pro index c1f5611..e2b6441 100644 --- a/qtBuildSystem/Mu/Mu.pro +++ b/qtBuildSystem/Mu/Mu.pro @@ -204,6 +204,7 @@ CONFIG += c++11 INCLUDEPATH += $$PWD/qt-common/include SOURCES += \ + ../../src/dbvz.c \ debugviewer.cpp \ emuwrapper.cpp \ main.cpp \ @@ -227,10 +228,10 @@ SOURCES += \ ../../src/m68k/m68kopnz.c \ ../../src/m68k/m68kops.c \ ../../src/expansionHardware.c \ - ../../src/m515Bus.c \ - ../../src/dbvzRegisters.c + ../../src/m515Bus.c HEADERS += \ + ../../src/dbvz.h \ debugviewer.h \ emuwrapper.h \ mainwindow.h \ @@ -266,7 +267,6 @@ HEADERS += \ ../../src/m515Bus.h \ ../../src/dbvzRegisterAccessors.c.h \ ../../src/dbvzTiming.c.h \ - ../../src/dbvzRegisters.h \ FORMS += \ mainwindow.ui \ diff --git a/src/ads7846.c b/src/ads7846.c index f753b42..f3d16eb 100644 --- a/src/ads7846.c +++ b/src/ads7846.c @@ -3,7 +3,7 @@ #include "emulator.h" #include "portability.h" -#include "dbvzRegisters.h" +#include "dbvz.h" bool ads7846PenIrqEnabled; diff --git a/src/dbvzRegisters.c b/src/dbvz.c similarity index 77% rename from src/dbvzRegisters.c rename to src/dbvz.c index b9c81d6..1d24717 100644 --- a/src/dbvzRegisters.c +++ b/src/dbvz.c @@ -4,7 +4,7 @@ #include "emulator.h" #include "specs/dragonballVzRegisterSpec.h" -#include "dbvzRegisters.h" +#include "dbvz.h" #include "m515Bus.h" #include "portability.h" #include "flx68000.h" @@ -13,7 +13,7 @@ #include "audio/blip_buf.h" #include "debug/sandbox.h" - +uint8_t dbvzReg[DBVZ_REG_SIZE]; dbvz_chip_t dbvzChipSelects[DBVZ_CHIP_END]; double dbvzSysclksPerClk32;//how many SYSCLK cycles before toggling the 32.768 kHz crystal uint32_t dbvzFrameClk32s;//how many CLK32s have happened in the current frame @@ -1007,11 +1007,11 @@ void dbvzSetRegister32(uint32_t address, uint32_t value){ } } -void dbvzResetRegisters(void){ +void dbvzReset(void){ uint32_t oldRtc = registerArrayRead32(RTCTIME);//preserve RTCTIME uint16_t oldDayr = registerArrayRead16(DAYR);//preserve DAYR - memset(palmReg, 0x00, DBVZ_REG_SIZE - DBVZ_BOOTLOADER_SIZE); + memset(dbvzReg, 0x00, DBVZ_REG_SIZE - DBVZ_BOOTLOADER_SIZE); dbvzSysclksPerClk32 = 0.0; clk32Counter = 0; pctlrCpuClockDivider = 1.0; @@ -1157,9 +1157,269 @@ void dbvzResetRegisters(void){ updateBacklightAmplifierStatus(); dbvzSysclksPerClk32 = sysclksPerClk32(); + + dbvzResetAddressSpace(); + flx68000Reset(); +} + +uint32_t dbvzStateSize(void){ + uint32_t size = 0; + + size += flx68000StateSize(); + size += DBVZ_REG_SIZE;//hardware registers + size += DBVZ_TOTAL_MEMORY_BANKS; + size += sizeof(uint32_t) * 4 * DBVZ_CHIP_END;//chip select states + size += sizeof(uint8_t) * 5 * DBVZ_CHIP_END;//chip select states + size += sizeof(uint64_t) * 5;//32.32 fixed point double, timerXCycleCounter and CPU cycle timers + size += sizeof(int8_t);//pllSleepWait + size += sizeof(int8_t);//pllWakeWait + size += sizeof(uint32_t);//clk32Counter + size += sizeof(uint64_t);//pctlrCpuClockDivider + size += sizeof(uint16_t) * 2;//timerStatusReadAcknowledge + size += sizeof(uint8_t);//portDInterruptLastValue + size += sizeof(uint16_t) * 9;//RX 8 * 16 SPI1 FIFO, 1 index is for FIFO full + size += sizeof(uint16_t) * 9;//TX 8 * 16 SPI1 FIFO, 1 index is for FIFO full + size += sizeof(uint8_t) * 5;//spi1(R/T)x(Read/Write)Position / spi1RxOverflowed + size += sizeof(int32_t);//pwm1ClocksToNextSample + size += sizeof(uint8_t) * 6;//pwm1Fifo[6] + size += sizeof(uint8_t) * 2;//pwm1(Read/Write) + + //debugLog("size is:%d\n", size); + + return size; +} + +void dbvzSaveState(uint8_t* data){ + uint32_t offset = 0; + uint8_t index; + + //CPU core + flx68000SaveState(data + offset); + offset += flx68000StateSize(); + + //memory + memcpy(data + offset, dbvzReg, DBVZ_REG_SIZE); + swap16BufferIfLittle(data + offset, DBVZ_REG_SIZE / sizeof(uint16_t)); + offset += DBVZ_REG_SIZE; + memcpy(data + offset, dbvzBankType, DBVZ_TOTAL_MEMORY_BANKS); + offset += DBVZ_TOTAL_MEMORY_BANKS; + for(index = DBVZ_CHIP_BEGIN; index < DBVZ_CHIP_END; index++){ + writeStateValue8(data + offset, dbvzChipSelects[index].enable); + offset += sizeof(uint8_t); + writeStateValue32(data + offset, dbvzChipSelects[index].start); + offset += sizeof(uint32_t); + writeStateValue32(data + offset, dbvzChipSelects[index].lineSize); + offset += sizeof(uint32_t); + writeStateValue32(data + offset, dbvzChipSelects[index].mask); + offset += sizeof(uint32_t); + writeStateValue8(data + offset, dbvzChipSelects[index].inBootMode); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, dbvzChipSelects[index].readOnly); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, dbvzChipSelects[index].readOnlyForProtectedMemory); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, dbvzChipSelects[index].supervisorOnlyProtectedMemory); + offset += sizeof(uint8_t); + writeStateValue32(data + offset, dbvzChipSelects[index].unprotectedSize); + offset += sizeof(uint32_t); + } + + //timing + writeStateValueDouble(data + offset, dbvzSysclksPerClk32); + offset += sizeof(uint64_t); + writeStateValueDouble(data + offset, palmCycleCounter); + offset += sizeof(uint64_t); + writeStateValueDouble(data + offset, palmClockMultiplier); + offset += sizeof(uint64_t); + writeStateValue8(data + offset, pllSleepWait); + offset += sizeof(int8_t); + writeStateValue8(data + offset, pllWakeWait); + offset += sizeof(int8_t); + writeStateValue32(data + offset, clk32Counter); + offset += sizeof(uint32_t); + writeStateValueDouble(data + offset, pctlrCpuClockDivider); + offset += sizeof(uint64_t); + writeStateValueDouble(data + offset, timerCycleCounter[0]); + offset += sizeof(uint64_t); + writeStateValueDouble(data + offset, timerCycleCounter[1]); + offset += sizeof(uint64_t); + writeStateValue16(data + offset, timerStatusReadAcknowledge[0]); + offset += sizeof(uint16_t); + writeStateValue16(data + offset, timerStatusReadAcknowledge[1]); + offset += sizeof(uint16_t); + writeStateValue8(data + offset, portDInterruptLastValue); + offset += sizeof(uint8_t); + + //SPI1 + for(index = 0; index < 9; index++){ + writeStateValue16(data + offset, spi1RxFifo[index]); + offset += sizeof(uint16_t); + } + for(index = 0; index < 9; index++){ + writeStateValue16(data + offset, spi1TxFifo[index]); + offset += sizeof(uint16_t); + } + writeStateValue8(data + offset, spi1RxReadPosition); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, spi1RxWritePosition); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, spi1RxOverflowed); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, spi1TxReadPosition); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, spi1TxWritePosition); + offset += sizeof(uint8_t); + + //PWM1, audio + writeStateValue32(data + offset, pwm1ClocksToNextSample); + offset += sizeof(int32_t); + for(index = 0; index < 6; index++){ + writeStateValue8(data + offset, pwm1Fifo[index]); + offset += sizeof(uint8_t); + } + writeStateValue8(data + offset, pwm1ReadPosition); + offset += sizeof(uint8_t); + writeStateValue8(data + offset, pwm1WritePosition); + offset += sizeof(uint8_t); + + //debugLog("save offset is:%d\n", offset); +} + +void dbvzLoadState(uint8_t* data){ + uint32_t offset = 0; + uint8_t index; + + //CPU core + flx68000LoadState(data + offset); + offset += flx68000StateSize(); + + //memory + memcpy(dbvzReg, data + offset, DBVZ_REG_SIZE); + swap16BufferIfLittle(dbvzReg, DBVZ_REG_SIZE / sizeof(uint16_t)); + offset += DBVZ_REG_SIZE; + memcpy(dbvzBankType, data + offset, DBVZ_TOTAL_MEMORY_BANKS); + offset += DBVZ_TOTAL_MEMORY_BANKS; + for(index = DBVZ_CHIP_BEGIN; index < DBVZ_CHIP_END; index++){ + dbvzChipSelects[index].enable = readStateValue8(data + offset); + offset += sizeof(uint8_t); + dbvzChipSelects[index].start = readStateValue32(data + offset); + offset += sizeof(uint32_t); + dbvzChipSelects[index].lineSize = readStateValue32(data + offset); + offset += sizeof(uint32_t); + dbvzChipSelects[index].mask = readStateValue32(data + offset); + offset += sizeof(uint32_t); + dbvzChipSelects[index].inBootMode = readStateValue8(data + offset); + offset += sizeof(uint8_t); + dbvzChipSelects[index].readOnly = readStateValue8(data + offset); + offset += sizeof(uint8_t); + dbvzChipSelects[index].readOnlyForProtectedMemory = readStateValue8(data + offset); + offset += sizeof(uint8_t); + dbvzChipSelects[index].supervisorOnlyProtectedMemory = readStateValue8(data + offset); + offset += sizeof(uint8_t); + dbvzChipSelects[index].unprotectedSize = readStateValue32(data + offset); + offset += sizeof(uint32_t); + } + + //timing + dbvzSysclksPerClk32 = readStateValueDouble(data + offset); + offset += sizeof(uint64_t); + palmCycleCounter = readStateValueDouble(data + offset); + offset += sizeof(uint64_t); + palmClockMultiplier = readStateValueDouble(data + offset); + offset += sizeof(uint64_t); + pllSleepWait = readStateValue8(data + offset); + offset += sizeof(int8_t); + pllWakeWait = readStateValue8(data + offset); + offset += sizeof(int8_t); + clk32Counter = readStateValue32(data + offset); + offset += sizeof(uint32_t); + pctlrCpuClockDivider = readStateValueDouble(data + offset); + offset += sizeof(uint64_t); + timerCycleCounter[0] = readStateValueDouble(data + offset); + offset += sizeof(uint64_t); + timerCycleCounter[1] = readStateValueDouble(data + offset); + offset += sizeof(uint64_t); + timerStatusReadAcknowledge[0] = readStateValue16(data + offset); + offset += sizeof(uint16_t); + timerStatusReadAcknowledge[1] = readStateValue16(data + offset); + offset += sizeof(uint16_t); + portDInterruptLastValue = readStateValue8(data + offset); + offset += sizeof(uint8_t); + + //SPI1 + for(index = 0; index < 9; index++){ + spi1RxFifo[index] = readStateValue16(data + offset); + offset += sizeof(uint16_t); + } + for(index = 0; index < 9; index++){ + spi1TxFifo[index] = readStateValue16(data + offset); + offset += sizeof(uint16_t); + } + spi1RxReadPosition = readStateValue8(data + offset); + offset += sizeof(uint8_t); + spi1RxWritePosition = readStateValue8(data + offset); + offset += sizeof(uint8_t); + spi1RxOverflowed = readStateValue8(data + offset); + offset += sizeof(uint8_t); + spi1TxReadPosition = readStateValue8(data + offset); + offset += sizeof(uint8_t); + spi1TxWritePosition = readStateValue8(data + offset); + offset += sizeof(uint8_t); + + //PWM1, audio + pwm1ClocksToNextSample = readStateValue32(data + offset); + offset += sizeof(int32_t); + for(index = 0; index < 6; index++){ + pwm1Fifo[index] = readStateValue8(data + offset); + offset += sizeof(uint8_t); + } + pwm1ReadPosition = readStateValue8(data + offset); + offset += sizeof(uint8_t); + pwm1WritePosition = readStateValue8(data + offset); + offset += sizeof(uint8_t); + + //debugLog("load offset is:%d\n", offset); +} + +void dbvzLoadStateFinished(void){ + flx68000LoadStateFinished(); +} + +void dbvzLoadBootloader(uint8_t* data, uint32_t size){ + uint16_t index; + + if(!data) + size = 0; + + size = u32Min(size, DBVZ_BOOTLOADER_SIZE); + for(index = 0; index < size; index++) + registerArrayWrite8(DBVZ_REG_SIZE - DBVZ_BOOTLOADER_SIZE + index, data[index]); + for(index = size; index < DBVZ_BOOTLOADER_SIZE; index++) + registerArrayWrite8(DBVZ_REG_SIZE - DBVZ_BOOTLOADER_SIZE + index, 0x00); } void dbvzSetRtc(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds){ registerArrayWrite32(RTCTIME, hours << 24 & 0x1F000000 | minutes << 16 & 0x003F0000 | seconds & 0x0000003F); registerArrayWrite16(DAYR, days & 0x01FF); } + +void dbvzExecute(void){ + uint32_t samples; + + //I/O + m515RefreshInputState(); + + //CPU + dbvzFrameClk32s = 0; + for(; palmCycleCounter < (double)M515_CRYSTAL_FREQUENCY / EMU_FPS; palmCycleCounter += 1.0){ + flx68000Execute(); + dbvzFrameClk32s++; + } + palmCycleCounter -= (double)M515_CRYSTAL_FREQUENCY / EMU_FPS; + + //audio + blip_end_frame(palmAudioResampler, blip_clocks_needed(palmAudioResampler, AUDIO_SAMPLES_PER_FRAME)); + blip_read_samples(palmAudioResampler, palmAudio, AUDIO_SAMPLES_PER_FRAME, true); + MULTITHREAD_LOOP(samples) for(samples = 0; samples < AUDIO_SAMPLES_PER_FRAME * 2; samples += 2) + palmAudio[samples + 1] = palmAudio[samples]; +} diff --git a/src/dbvzRegisters.h b/src/dbvz.h similarity index 93% rename from src/dbvzRegisters.h rename to src/dbvz.h index 0b46e81..9b5de01 100644 --- a/src/dbvzRegisters.h +++ b/src/dbvz.h @@ -1,5 +1,5 @@ -#ifndef DBVZ_REGISTERS_H -#define DBVZ_REGISTERS_H +#ifndef DBVZ_H +#define DBVZ_H #include #include @@ -64,6 +64,7 @@ typedef struct{ }dbvz_chip_t; //variables +extern uint8_t dbvzReg[]; extern dbvz_chip_t dbvzChipSelects[]; extern double dbvzSysclksPerClk32; extern uint32_t dbvzFrameClk32s; @@ -116,7 +117,15 @@ void dbvzSetRegister16(uint32_t address, uint16_t value); void dbvzSetRegister32(uint32_t address, uint32_t value); //config -void dbvzResetRegisters(void); +void dbvzReset(void); +uint32_t dbvzStateSize(void); +void dbvzSaveState(uint8_t* data); +void dbvzLoadState(uint8_t* data); +void dbvzLoadStateFinished(void); + +void dbvzLoadBootloader(uint8_t* data, uint32_t size); void dbvzSetRtc(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds); +void dbvzExecute(void); + #endif diff --git a/src/dbvzRegisterAccessors.c.h b/src/dbvzRegisterAccessors.c.h index b09a8ba..3919b6e 100644 --- a/src/dbvzRegisterAccessors.c.h +++ b/src/dbvzRegisterAccessors.c.h @@ -11,12 +11,12 @@ static uint8_t getPortKValue(void); static uint8_t getPortMValue(void); //basic accessors -static uint8_t registerArrayRead8(uint32_t address){return M68K_BUFFER_READ_8(palmReg, address, 0xFFF);} -static uint16_t registerArrayRead16(uint32_t address){return M68K_BUFFER_READ_16(palmReg, address, 0xFFF);} -static uint32_t registerArrayRead32(uint32_t address){return M68K_BUFFER_READ_32(palmReg, address, 0xFFF);} -static void registerArrayWrite8(uint32_t address, uint8_t value){M68K_BUFFER_WRITE_8(palmReg, address, 0xFFF, value);} -static void registerArrayWrite16(uint32_t address, uint16_t value){M68K_BUFFER_WRITE_16(palmReg, address, 0xFFF, value);} -static void registerArrayWrite32(uint32_t address, uint32_t value){M68K_BUFFER_WRITE_32(palmReg, address, 0xFFF, value);} +static uint8_t registerArrayRead8(uint32_t address){return M68K_BUFFER_READ_8(dbvzReg, address, 0xFFF);} +static uint16_t registerArrayRead16(uint32_t address){return M68K_BUFFER_READ_16(dbvzReg, address, 0xFFF);} +static uint32_t registerArrayRead32(uint32_t address){return M68K_BUFFER_READ_32(dbvzReg, address, 0xFFF);} +static void registerArrayWrite8(uint32_t address, uint8_t value){M68K_BUFFER_WRITE_8(dbvzReg, address, 0xFFF, value);} +static void registerArrayWrite16(uint32_t address, uint16_t value){M68K_BUFFER_WRITE_16(dbvzReg, address, 0xFFF, value);} +static void registerArrayWrite32(uint32_t address, uint32_t value){M68K_BUFFER_WRITE_32(dbvzReg, address, 0xFFF, value);} //interrupt setters, used for setting an interrupt with masking by IMR and logging in IPR static void setIprIsrBit(uint32_t interruptBit){ diff --git a/src/debug/sandbox.c b/src/debug/sandbox.c index 2a4192b..d037747 100644 --- a/src/debug/sandbox.c +++ b/src/debug/sandbox.c @@ -14,7 +14,7 @@ #include "../m68k/m68kcpu.h" #include "../emulator.h" #include "../ads7846.h" -#include "../dbvzRegisters.h" +#include "../dbvz.h" #include "../portability.h" #include "../specs/emuFeatureRegisterSpec.h" #include "sandbox.h" diff --git a/src/emulator.c b/src/emulator.c index cfa83bb..17d0122 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -4,9 +4,8 @@ #include #include "audio/blip_buf.h" -#include "flx68000.h" #include "emulator.h" -#include "dbvzRegisters.h" +#include "dbvz.h" #include "expansionHardware.h" #include "m515Bus.h" #include "sed1376.h" @@ -50,7 +49,6 @@ bool palmEmulatingTungstenC; #endif uint8_t* palmRam; uint8_t* palmRom; -uint8_t* palmReg; input_t palmInput; sd_card_t palmSdCard; misc_hw_t palmMisc; @@ -66,31 +64,16 @@ double palmClockMultiplier;//used by the emulator to overclock the emulated P #if defined(EMU_SUPPORT_PALM_OS5) static void emulatorTungstenCFrame(void){ + //CPU pxa255Execute(); } #endif static void emulatorM515Frame(void){ - uint32_t samples; - - //I/O - m515RefreshInputState(); - //CPU - dbvzFrameClk32s = 0; - for(; palmCycleCounter < (double)M515_CRYSTAL_FREQUENCY / EMU_FPS; palmCycleCounter += 1.0){ - flx68000Execute(); - dbvzFrameClk32s++; - } - palmCycleCounter -= (double)M515_CRYSTAL_FREQUENCY / EMU_FPS; + dbvzExecute(); - //audio - blip_end_frame(palmAudioResampler, blip_clocks_needed(palmAudioResampler, AUDIO_SAMPLES_PER_FRAME)); - blip_read_samples(palmAudioResampler, palmAudio, AUDIO_SAMPLES_PER_FRAME, true); - MULTITHREAD_LOOP(samples) for(samples = 0; samples < AUDIO_SAMPLES_PER_FRAME * 2; samples += 2) - palmAudio[samples + 1] = palmAudio[samples]; - - //video + //LCD controller sed1376Render(); } @@ -159,14 +142,12 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t enab //allocate buffers, add 4 to memory regions to prevent SIGSEGV from accessing off the end palmRom = malloc(M515_ROM_SIZE + 4); palmRam = malloc(M515_RAM_SIZE + 4); - palmReg = malloc(DBVZ_REG_SIZE + 4); palmFramebuffer = malloc(160 * 220 * sizeof(uint16_t)); palmAudio = malloc(AUDIO_SAMPLES_PER_FRAME * 2 * sizeof(int16_t)); palmAudioResampler = blip_new(AUDIO_SAMPLE_RATE);//have 1 second of samples - if(!palmRom || !palmRam || !palmReg || !palmFramebuffer || !palmAudio || !palmAudioResampler){ + if(!palmRom || !palmRam || !palmFramebuffer || !palmAudio || !palmAudioResampler){ free(palmRom); free(palmRam); - free(palmReg); free(palmFramebuffer); free(palmAudio); blip_delete(palmAudioResampler); @@ -179,15 +160,7 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t enab memset(palmRom + palmRomDump.size, 0x00, M515_ROM_SIZE - palmRomDump.size); swap16BufferIfLittle(palmRom, M515_ROM_SIZE / sizeof(uint16_t)); memset(palmRam, 0x00, M515_RAM_SIZE); - if(palmBootDump.data){ - memcpy(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE, palmBootDump.data, u32Min(palmBootDump.size, DBVZ_BOOTLOADER_SIZE)); - if(palmBootDump.size < DBVZ_BOOTLOADER_SIZE) - memset(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE + palmBootDump.size, 0x00, DBVZ_BOOTLOADER_SIZE - palmBootDump.size); - swap16BufferIfLittle(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE, DBVZ_BOOTLOADER_SIZE / sizeof(uint16_t)); - } - else{ - memset(palmReg + DBVZ_REG_SIZE - 1 - DBVZ_BOOTLOADER_SIZE, 0x00, DBVZ_BOOTLOADER_SIZE); - } + dbvzLoadBootloader(palmBootDump.data, palmBootDump.size); memcpy(palmFramebuffer + 160 * 160, silkscreen160x60, 160 * 60 * sizeof(uint16_t)); memset(palmAudio, 0x00, AUDIO_SAMPLES_PER_FRAME * 2/*channels*/ * sizeof(int16_t)); memset(&palmInput, 0x00, sizeof(palmInput)); @@ -203,7 +176,6 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t enab //initialize components blip_set_rates(palmAudioResampler, AUDIO_CLOCK_RATE, AUDIO_SAMPLE_RATE); - flx68000Init(); sandboxInit(); //reset everything @@ -225,7 +197,6 @@ void emulatorExit(void){ #endif free(palmRom); free(palmRam); - free(palmReg); #if defined(EMU_SUPPORT_PALM_OS5) } #endif @@ -278,7 +249,7 @@ void emulatorSoftReset(void){ ads7846Reset(); pdiUsbD12Reset(); expansionHardwareReset(); - flx68000Reset(); + dbvzReset(); sandboxReset(); //sdCardReset() should not be called here, the SD card does not have a reset line and should only be reset by a power cycle #if defined(EMU_SUPPORT_PALM_OS5) @@ -302,30 +273,24 @@ uint32_t emulatorGetStateSize(void){ size += sizeof(uint32_t);//palmEmuFeatures.info size += sizeof(uint64_t);//palmSdCard.flashChip.size, needs to be done first to verify the malloc worked size += sizeof(uint16_t) * 2;//palmFramebuffer(Width/Height) - size += flx68000StateSize(); - size += sed1376StateSize(); - size += ads7846StateSize(); - size += pdiUsbD12StateSize(); - size += expansionHardwareStateSize(); +#if defined(EMU_SUPPORT_PALM_OS5) + if(palmEmulatingTungstenC){ + size += pxa255StateSize(); + size += expansionHardwareStateSize(); + size += TUNGSTEN_C_RAM_SIZE;//system RAM buffer + } + else{ +#endif + size += dbvzStateSize(); + size += sed1376StateSize(); + size += ads7846StateSize(); + size += pdiUsbD12StateSize(); + size += expansionHardwareStateSize(); + size += M515_RAM_SIZE;//system RAM buffer +#if defined(EMU_SUPPORT_PALM_OS5) + } +#endif size += sandboxStateSize(); - size += M515_RAM_SIZE;//system RAM buffer - size += DBVZ_REG_SIZE;//hardware registers - size += DBVZ_TOTAL_MEMORY_BANKS;//bank handlers - size += sizeof(uint32_t) * 4 * DBVZ_CHIP_END;//chip select states - size += sizeof(uint8_t) * 5 * DBVZ_CHIP_END;//chip select states - size += sizeof(uint64_t) * 5;//32.32 fixed point double, timerXCycleCounter and CPU cycle timers - size += sizeof(int8_t);//pllSleepWait - size += sizeof(int8_t);//pllWakeWait - size += sizeof(uint32_t);//clk32Counter - size += sizeof(uint64_t);//pctlrCpuClockDivider - size += sizeof(uint16_t) * 2;//timerStatusReadAcknowledge - size += sizeof(uint8_t);//portDInterruptLastValue - size += sizeof(uint16_t) * 9;//RX 8 * 16 SPI1 FIFO, 1 index is for FIFO full - size += sizeof(uint16_t) * 9;//TX 8 * 16 SPI1 FIFO, 1 index is for FIFO full - size += sizeof(uint8_t) * 5;//spi1(R/T)x(Read/Write)Position / spi1RxOverflowed - size += sizeof(int32_t);//pwm1ClocksToNextSample - size += sizeof(uint8_t) * 6;//pwm1Fifo[6] - size += sizeof(uint8_t) * 2;//pwm1(Read/Write) size += sizeof(uint8_t) * 7;//palmMisc size += sizeof(uint32_t) * 4;//palmEmuFeatures.(src/dst/size/value) size += sizeof(uint64_t);//palmSdCard.command @@ -352,7 +317,11 @@ bool emulatorSaveState(buffer_t buffer){ return false;//state cant fit //state validation, wont load states that are not from the same state version +#if defined(EMU_SUPPORT_PALM_OS5) + writeStateValue32(buffer.data + offset, SAVE_STATE_VERSION | (palmEmulatingTungstenC ? SAVE_STATE_FOR_TUNGSTEN_C : 0)); +#else writeStateValue32(buffer.data + offset, SAVE_STATE_VERSION); +#endif offset += sizeof(uint32_t); //features, hotpluging emulated hardware is not supported @@ -369,110 +338,45 @@ bool emulatorSaveState(buffer_t buffer){ writeStateValue16(buffer.data + offset, palmFramebufferHeight); offset += sizeof(uint16_t); - //chips - flx68000SaveState(buffer.data + offset); - offset += flx68000StateSize(); - sed1376SaveState(buffer.data + offset); - offset += sed1376StateSize(); - ads7846SaveState(buffer.data + offset); - offset += ads7846StateSize(); - pdiUsbD12SaveState(buffer.data + offset); - offset += pdiUsbD12StateSize(); - expansionHardwareSaveState(buffer.data + offset); - offset += expansionHardwareStateSize(); +#if defined(EMU_SUPPORT_PALM_OS5) + if(palmEmulatingTungstenC){ + //chips + pxa255SaveState(buffer.data + offset); + offset += pxa255StateSize(); + expansionHardwareSaveState(buffer.data + offset); + offset += expansionHardwareStateSize(); + + //memory + memcpy(buffer.data + offset, palmRam, TUNGSTEN_C_RAM_SIZE); + swap16BufferIfLittle(buffer.data + offset, TUNGSTEN_C_RAM_SIZE / sizeof(uint16_t)); + offset += TUNGSTEN_C_RAM_SIZE; + } + else{ +#endif + //chips + dbvzSaveState(buffer.data + offset); + offset += dbvzStateSize(); + sed1376SaveState(buffer.data + offset); + offset += sed1376StateSize(); + ads7846SaveState(buffer.data + offset); + offset += ads7846StateSize(); + pdiUsbD12SaveState(buffer.data + offset); + offset += pdiUsbD12StateSize(); + expansionHardwareSaveState(buffer.data + offset); + offset += expansionHardwareStateSize(); + + //memory + memcpy(buffer.data + offset, palmRam, M515_RAM_SIZE); + swap16BufferIfLittle(buffer.data + offset, M515_RAM_SIZE / sizeof(uint16_t)); + offset += M515_RAM_SIZE; +#if defined(EMU_SUPPORT_PALM_OS5) + } +#endif //sandbox, does nothing when disabled sandboxSaveState(buffer.data + offset); offset += sandboxStateSize(); - //memory - memcpy(buffer.data + offset, palmRam, M515_RAM_SIZE); - swap16BufferIfLittle(buffer.data + offset, M515_RAM_SIZE / sizeof(uint16_t)); - offset += M515_RAM_SIZE; - memcpy(buffer.data + offset, palmReg, DBVZ_REG_SIZE); - swap16BufferIfLittle(buffer.data + offset, DBVZ_REG_SIZE / sizeof(uint16_t)); - offset += DBVZ_REG_SIZE; - memcpy(buffer.data + offset, dbvzBankType, DBVZ_TOTAL_MEMORY_BANKS); - offset += DBVZ_TOTAL_MEMORY_BANKS; - for(index = DBVZ_CHIP_BEGIN; index < DBVZ_CHIP_END; index++){ - writeStateValue8(buffer.data + offset, dbvzChipSelects[index].enable); - offset += sizeof(uint8_t); - writeStateValue32(buffer.data + offset, dbvzChipSelects[index].start); - offset += sizeof(uint32_t); - writeStateValue32(buffer.data + offset, dbvzChipSelects[index].lineSize); - offset += sizeof(uint32_t); - writeStateValue32(buffer.data + offset, dbvzChipSelects[index].mask); - offset += sizeof(uint32_t); - writeStateValue8(buffer.data + offset, dbvzChipSelects[index].inBootMode); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, dbvzChipSelects[index].readOnly); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, dbvzChipSelects[index].readOnlyForProtectedMemory); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, dbvzChipSelects[index].supervisorOnlyProtectedMemory); - offset += sizeof(uint8_t); - writeStateValue32(buffer.data + offset, dbvzChipSelects[index].unprotectedSize); - offset += sizeof(uint32_t); - } - - //timing - writeStateValueDouble(buffer.data + offset, dbvzSysclksPerClk32); - offset += sizeof(uint64_t); - writeStateValueDouble(buffer.data + offset, palmCycleCounter); - offset += sizeof(uint64_t); - writeStateValueDouble(buffer.data + offset, palmClockMultiplier); - offset += sizeof(uint64_t); - writeStateValue8(buffer.data + offset, pllSleepWait); - offset += sizeof(int8_t); - writeStateValue8(buffer.data + offset, pllWakeWait); - offset += sizeof(int8_t); - writeStateValue32(buffer.data + offset, clk32Counter); - offset += sizeof(uint32_t); - writeStateValueDouble(buffer.data + offset, pctlrCpuClockDivider); - offset += sizeof(uint64_t); - writeStateValueDouble(buffer.data + offset, timerCycleCounter[0]); - offset += sizeof(uint64_t); - writeStateValueDouble(buffer.data + offset, timerCycleCounter[1]); - offset += sizeof(uint64_t); - writeStateValue16(buffer.data + offset, timerStatusReadAcknowledge[0]); - offset += sizeof(uint16_t); - writeStateValue16(buffer.data + offset, timerStatusReadAcknowledge[1]); - offset += sizeof(uint16_t); - writeStateValue8(buffer.data + offset, portDInterruptLastValue); - offset += sizeof(uint8_t); - - //SPI1 - for(index = 0; index < 9; index++){ - writeStateValue16(buffer.data + offset, spi1RxFifo[index]); - offset += sizeof(uint16_t); - } - for(index = 0; index < 9; index++){ - writeStateValue16(buffer.data + offset, spi1TxFifo[index]); - offset += sizeof(uint16_t); - } - writeStateValue8(buffer.data + offset, spi1RxReadPosition); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, spi1RxWritePosition); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, spi1RxOverflowed); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, spi1TxReadPosition); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, spi1TxWritePosition); - offset += sizeof(uint8_t); - - //PWM1, audio - writeStateValue32(buffer.data + offset, pwm1ClocksToNextSample); - offset += sizeof(int32_t); - for(index = 0; index < 6; index++){ - writeStateValue8(buffer.data + offset, pwm1Fifo[index]); - offset += sizeof(uint8_t); - } - writeStateValue8(buffer.data + offset, pwm1ReadPosition); - offset += sizeof(uint8_t); - writeStateValue8(buffer.data + offset, pwm1WritePosition); - offset += sizeof(uint8_t); - //misc writeStateValue8(buffer.data + offset, palmMisc.powerButtonLed); offset += sizeof(uint8_t); @@ -553,8 +457,13 @@ bool emulatorLoadState(buffer_t buffer){ uint8_t* stateSdCardBuffer; //state validation, wont load states that are not from the same state version +#if defined(EMU_SUPPORT_PALM_OS5) + if(readStateValue32(buffer.data + offset) != (SAVE_STATE_VERSION | (palmEmulatingTungstenC ? SAVE_STATE_FOR_TUNGSTEN_C : 0))) + return false; +#else if(readStateValue32(buffer.data + offset) != SAVE_STATE_VERSION) return false; +#endif offset += sizeof(uint32_t); //features, hotpluging emulated hardware is not supported @@ -575,110 +484,45 @@ bool emulatorLoadState(buffer_t buffer){ palmFramebufferHeight = readStateValue16(buffer.data + offset); offset += sizeof(uint16_t); - //chips - flx68000LoadState(buffer.data + offset); - offset += flx68000StateSize(); - sed1376LoadState(buffer.data + offset); - offset += sed1376StateSize(); - ads7846LoadState(buffer.data + offset); - offset += ads7846StateSize(); - pdiUsbD12LoadState(buffer.data + offset); - offset += pdiUsbD12StateSize(); - expansionHardwareLoadState(buffer.data + offset); - offset += expansionHardwareStateSize(); +#if defined(EMU_SUPPORT_PALM_OS5) + if(palmEmulatingTungstenC){ + //chips + pxa255LoadState(buffer.data + offset); + offset += pxa255StateSize(); + expansionHardwareLoadState(buffer.data + offset); + offset += expansionHardwareStateSize(); + + //memory + memcpy(palmRam, buffer.data + offset, TUNGSTEN_C_RAM_SIZE); + swap16BufferIfLittle(palmRam, TUNGSTEN_C_RAM_SIZE / sizeof(uint16_t)); + offset += TUNGSTEN_C_RAM_SIZE; + } + else{ +#endif + //chips + dbvzLoadState(buffer.data + offset); + offset += dbvzStateSize(); + sed1376LoadState(buffer.data + offset); + offset += sed1376StateSize(); + ads7846LoadState(buffer.data + offset); + offset += ads7846StateSize(); + pdiUsbD12LoadState(buffer.data + offset); + offset += pdiUsbD12StateSize(); + expansionHardwareLoadState(buffer.data + offset); + offset += expansionHardwareStateSize(); + + //memory + memcpy(palmRam, buffer.data + offset, M515_RAM_SIZE); + swap16BufferIfLittle(palmRam, M515_RAM_SIZE / sizeof(uint16_t)); + offset += M515_RAM_SIZE; +#if defined(EMU_SUPPORT_PALM_OS5) + } +#endif //sandbox, does nothing when disabled sandboxLoadState(buffer.data + offset); offset += sandboxStateSize(); - //memory - memcpy(palmRam, buffer.data + offset, M515_RAM_SIZE); - swap16BufferIfLittle(palmRam, M515_RAM_SIZE / sizeof(uint16_t)); - offset += M515_RAM_SIZE; - memcpy(palmReg, buffer.data + offset, DBVZ_REG_SIZE); - swap16BufferIfLittle(palmReg, DBVZ_REG_SIZE / sizeof(uint16_t)); - offset += DBVZ_REG_SIZE; - memcpy(dbvzBankType, buffer.data + offset, DBVZ_TOTAL_MEMORY_BANKS); - offset += DBVZ_TOTAL_MEMORY_BANKS; - for(index = DBVZ_CHIP_BEGIN; index < DBVZ_CHIP_END; index++){ - dbvzChipSelects[index].enable = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - dbvzChipSelects[index].start = readStateValue32(buffer.data + offset); - offset += sizeof(uint32_t); - dbvzChipSelects[index].lineSize = readStateValue32(buffer.data + offset); - offset += sizeof(uint32_t); - dbvzChipSelects[index].mask = readStateValue32(buffer.data + offset); - offset += sizeof(uint32_t); - dbvzChipSelects[index].inBootMode = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - dbvzChipSelects[index].readOnly = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - dbvzChipSelects[index].readOnlyForProtectedMemory = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - dbvzChipSelects[index].supervisorOnlyProtectedMemory = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - dbvzChipSelects[index].unprotectedSize = readStateValue32(buffer.data + offset); - offset += sizeof(uint32_t); - } - - //timing - dbvzSysclksPerClk32 = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); - palmCycleCounter = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); - palmClockMultiplier = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); - pllSleepWait = readStateValue8(buffer.data + offset); - offset += sizeof(int8_t); - pllWakeWait = readStateValue8(buffer.data + offset); - offset += sizeof(int8_t); - clk32Counter = readStateValue32(buffer.data + offset); - offset += sizeof(uint32_t); - pctlrCpuClockDivider = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); - timerCycleCounter[0] = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); - timerCycleCounter[1] = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); - timerStatusReadAcknowledge[0] = readStateValue16(buffer.data + offset); - offset += sizeof(uint16_t); - timerStatusReadAcknowledge[1] = readStateValue16(buffer.data + offset); - offset += sizeof(uint16_t); - portDInterruptLastValue = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - - //SPI1 - for(index = 0; index < 9; index++){ - spi1RxFifo[index] = readStateValue16(buffer.data + offset); - offset += sizeof(uint16_t); - } - for(index = 0; index < 9; index++){ - spi1TxFifo[index] = readStateValue16(buffer.data + offset); - offset += sizeof(uint16_t); - } - spi1RxReadPosition = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - spi1RxWritePosition = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - spi1RxOverflowed = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - spi1TxReadPosition = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - spi1TxWritePosition = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - - //PWM1, audio - pwm1ClocksToNextSample = readStateValue32(buffer.data + offset); - offset += sizeof(int32_t); - for(index = 0; index < 6; index++){ - pwm1Fifo[index] = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - } - pwm1ReadPosition = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - pwm1WritePosition = readStateValue8(buffer.data + offset); - offset += sizeof(uint8_t); - //misc palmMisc.powerButtonLed = readStateValue8(buffer.data + offset); offset += sizeof(uint8_t); @@ -754,7 +598,7 @@ bool emulatorLoadState(buffer_t buffer){ offset += stateSdCardSize; //some modules depend on all the state memory being loaded before certian required actions can occur(refreshing cached data, freeing memory blocks) - flx68000LoadStateFinished(); + dbvzLoadStateFinished(); return true; } diff --git a/src/emulator.h b/src/emulator.h index 1271cb6..96fb9b5 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -53,7 +53,11 @@ static void debugLog(char* str, ...){}; #define SD_CARD_BLOCK_DATA_PACKET_SIZE (1 + SD_CARD_BLOCK_SIZE + 2) #define SD_CARD_RESPONSE_FIFO_SIZE (SD_CARD_BLOCK_DATA_PACKET_SIZE * 3) #define SD_CARD_NCR_BYTES 1//how many 0xFF bytes come before the R1 response -#define SAVE_STATE_VERSION 0 +#define SAVE_STATE_VERSION 0x00000001 +#if defined(EMU_SUPPORT_PALM_OS5) +#define SAVE_STATE_FOR_TUNGSTEN_C 0x80000000 +#endif + //system constants #define M515_CRYSTAL_FREQUENCY 32768 @@ -155,7 +159,6 @@ extern bool palmEmulatingTungstenC;//read allowed, but not advised #endif extern uint8_t* palmRom;//dont touch extern uint8_t* palmRam;//access allowed to read save RAM without allocating a giant buffer, but endianness must be taken into account -extern uint8_t* palmReg;//dont touch extern input_t palmInput;//write allowed extern sd_card_t palmSdCard;//dont touch extern misc_hw_t palmMisc;//read/write allowed diff --git a/src/expansionHardware.c b/src/expansionHardware.c index d632362..e278be8 100644 --- a/src/expansionHardware.c +++ b/src/expansionHardware.c @@ -6,7 +6,7 @@ #include "portability.h" #include "specs/emuFeatureRegisterSpec.h" #include "m515Bus.h" -#include "dbvzRegisters.h" +#include "dbvz.h" #include "silkscreen.h" #include "sed1376.h" #include "flx68000.h" diff --git a/src/flx68000.c b/src/flx68000.c index 38656e3..2a9d1ce 100755 --- a/src/flx68000.c +++ b/src/flx68000.c @@ -3,7 +3,7 @@ #include "emulator.h" #include "portability.h" -#include "dbvzRegisters.h" +#include "dbvz.h" #include "m515Bus.h" #include "m68k/m68kcpu.h" @@ -79,7 +79,7 @@ uint32_t m68k_read_pcrelative_32(uint32_t address){ #endif #endif -void flx68000Init(void){ +void flx68000Reset(void){ static bool inited = false; if(!inited){ @@ -90,11 +90,7 @@ void flx68000Init(void){ inited = true; } -} -void flx68000Reset(void){ - dbvzResetRegisters(); - dbvzResetAddressSpace();//address space must be reset after hardware registers because it is dependent on them m68k_pulse_reset(); } diff --git a/src/flx68000.h b/src/flx68000.h index 21bea00..73a9a1b 100755 --- a/src/flx68000.h +++ b/src/flx68000.h @@ -4,7 +4,6 @@ #include #include -void flx68000Init(void); void flx68000Reset(void); uint32_t flx68000StateSize(void); void flx68000SaveState(uint8_t* data); diff --git a/src/m515Bus.c b/src/m515Bus.c index 256a70e..2a67124 100644 --- a/src/m515Bus.c +++ b/src/m515Bus.c @@ -2,7 +2,7 @@ #include #include "emulator.h" -#include "dbvzRegisters.h" +#include "dbvz.h" #include "expansionHardware.h" #include "m515Bus.h" #include "portability.h" diff --git a/src/makefile.all b/src/makefile.all index 34746f9..b25b225 100644 --- a/src/makefile.all +++ b/src/makefile.all @@ -1,7 +1,7 @@ EMU_DEFINES := EMU_SOURCES_C := $(EMU_PATH)/emulator.c \ $(EMU_PATH)/m515Bus.c \ - $(EMU_PATH)/dbvzRegisters.c \ + $(EMU_PATH)/dbvz.c \ $(EMU_PATH)/flx68000.c \ $(EMU_PATH)/sed1376.c \ $(EMU_PATH)/ads7846.c \ diff --git a/src/sed1376.c b/src/sed1376.c index 3a82565..dea1cdc 100644 --- a/src/sed1376.c +++ b/src/sed1376.c @@ -3,7 +3,7 @@ #include "emulator.h" #include "portability.h" -#include "dbvzRegisters.h" +#include "dbvz.h" #include "flx68000.h"//for flx68000GetPc() #include "specs/sed1376RegisterSpec.h"