Can now detect actual hardware, but crashes on emu when emu features is disabled

This commit is contained in:
meepingsnesroms
2018-10-06 14:17:10 -07:00
parent f41a81b7f7
commit 76d3cc1371
6 changed files with 57 additions and 31 deletions

View File

@@ -258,7 +258,7 @@ void MainWindow::on_right_released(){
void MainWindow::on_ctrlBtn_clicked(){
if(!emu.isInited()){
QString sysDir = settings->value("resourceDirectory", "").toString();
uint32_t error = emu.init(sysDir + "/palmos41-en-m515.rom", QFile(sysDir + "/bootloader-en-m515.rom").exists() ? sysDir + "/bootloader-en-m515.rom" : "", sysDir + "/userdata-en-m515.ram", sysDir + "/sd-en-m515.img", FEATURE_DEBUG);
uint32_t error = emu.init(sysDir + "/palmos41-en-m515.rom", QFile(sysDir + "/bootloader-en-m515.rom").exists() ? sysDir + "/bootloader-en-m515.rom" : "", sysDir + "/userdata-en-m515.ram", sysDir + "/sd-en-m515.img", /*FEATURE_DEBUG*/ FEATURE_ACCURATE);
if(error == EMU_ERROR_NONE){
ui->calendar->setEnabled(true);
ui->addressBook->setEnabled(true);

View File

@@ -103,7 +103,7 @@ void setPrivilegeViolation(uint32_t address, bool isWrite){
debugLog("Privilege violation, PC:0x%08X\n", m68k_get_reg(NULL, M68K_REG_PPC));
registerArrayWrite8(SCR, scr | 0x20);
if(scr & 0x10)
m68328BusError(address, isWrite);
m68328PrivilegeViolation();
}
void setWriteProtectViolation(uint32_t address){
@@ -111,7 +111,7 @@ void setWriteProtectViolation(uint32_t address){
debugLog("Write protect violation, PC:0x%08X\n", m68k_get_reg(NULL, M68K_REG_PPC));
registerArrayWrite8(SCR, scr | 0x40);
if(scr & 0x10)
m68328BusError(address, true);
m68328PrivilegeViolation();
}
static void recalculateCpuSpeed(){

View File

@@ -187,4 +187,9 @@ void m68328BusError(uint32_t address, bool isWrite){
m68ki_push_16((isWrite ? MODE_WRITE : MODE_READ) | CPU_INSTR_MODE | FLAG_S | m68ki_get_address_space());
m68ki_jump_vector(EXCEPTION_BUS_ERROR);
USE_CYCLES(CYC_EXCEPTION[EXCEPTION_BUS_ERROR] - CYC_INSTRUCTION[REG_IR]);
}
void m68328PrivilegeViolation(){
m68ki_exception_privilege_violation();
}

View File

@@ -10,3 +10,4 @@ void m68328SaveState(uint8_t* data);
void m68328LoadState(uint8_t* data);
void m68328BusError(uint32_t address, bool isWrite);
void m68328PrivilegeViolation();

View File

@@ -13,35 +13,55 @@ enum{
};
static const uint16_t* skipBusError = {
0x5C8F,/*addq.l #6,sp ; remove error info from stack*/
0x54AF,/*addq.l #2,2(sp) ; skip over the invalid access, what ever was in the variable before the read should still be there*/
0x0002,/* ; displacement for above*/
0x4E73/*rte ; return*/
static const uint16_t attemptBusError[4] = {
0x2039,/*move.l 0xFFFC0000, d0 ; move EMU_INFO to d0*/
EMU_REG_ADDR(EMU_INFO) >> 16,/* ; location word 1 for above*/
EMU_REG_ADDR(EMU_INFO) & 0xFFFF,/* ; location word 2 for above*/
0x4E75/*rts ; return*/
};
static const uint16_t skipBusError[5] = {
0x5C8F,/*addq.l #6,sp ; remove error info from stack*/
0x548F,/*addq.l #2,sp ; remove error info from stack*/
0x54AF,/*addq.l #2,2(sp) ; skip over the invalid access, what ever was in the variable before the read should still be there*/
0x0002,/* ; displacement for above*/
0x4E73/*rte ; return*/
};
Boolean isEmulator(){
static uint8_t emuStatus = EMU_STATE_UNTESTED;
uint32_t osVer;
/*test if first call, else return cached value since testing is intensive*/
if(emuStatus == EMU_STATE_UNTESTED){
uint32_t oldBusErrorHandler = readArbitraryMemory32(2 * sizeof(uint32_t));/*EXCEPTION_BUS_ERROR vector*/
uint8_t oldScr = readArbitraryMemory8(HW_REG_ADDR(SCR));
uint32_t palmSpecialFeatures;
writeArbitraryMemory8(HW_REG_ADDR(SCR), 0xF0);/*enable bus error timeout, clear current invalid accesses*/
writeArbitraryMemory32(2 * sizeof(uint32_t), skipBusError);/*set EXCEPTION_BUS_ERROR vector*/
/*set fallback value, will be the returned value if bus error timeout occurs*/
palmSpecialFeatures = FEATURE_INVALID;
/*everything is setup, now try to read invalid memory, success == its an emu*/
palmSpecialFeatures = readArbitraryMemory32(EMU_REG_ADDR(EMU_INFO));
if(palmSpecialFeatures == FEATURE_INVALID)
emuStatus = EMU_STATE_FALSE;
else
emuStatus = EMU_STATE_TRUE;
FtrGet(sysFtrCreator, sysFtrNumROMVersion, &osVer);
if(osVer >= PalmOS50){
/*writing to interrupt handlers wont work on OS5+*/
emuStatus = EMU_STATE_FALSE;
}
else{
/*test if first call, else return cached value since testing is intensive*/
if(emuStatus == EMU_STATE_UNTESTED){
uint32_t oldBusErrorHandler = readArbitraryMemory32(2 * sizeof(uint32_t));/*EXCEPTION_BUS_ERROR vector*/
uint8_t oldScr = readArbitraryMemory8(HW_REG_ADDR(SCR));
volatile uint32_t palmSpecialFeatures;/*must be declared volatile since its modifyed by bus error behavior*/
writeArbitraryMemory8(HW_REG_ADDR(SCR), 0xF0);/*enable bus error timeout, clear current invalid accesses*/
writeArbitraryMemory32(2 * sizeof(uint32_t), (uint32_t)skipBusError);/*set EXCEPTION_BUS_ERROR vector*/
/*set fallback value, will be the returned value if bus error timeout occurs*/
palmSpecialFeatures = FEATURE_INVALID;
/*everything is setup, now try to read invalid memory, success == its an emu*/
palmSpecialFeatures = readArbitraryMemory32(EMU_REG_ADDR(EMU_INFO));/*((uint32_t(*)())attemptBusError)();*/
if(palmSpecialFeatures == FEATURE_INVALID)
emuStatus = EMU_STATE_FALSE;
else
emuStatus = EMU_STATE_TRUE;
/*restore original state*/
writeArbitraryMemory8(HW_REG_ADDR(SCR), 0xE0 | oldScr);
writeArbitraryMemory32(2 * sizeof(uint32_t), oldBusErrorHandler);
}
}
return emuStatus == EMU_STATE_TRUE;

View File

@@ -275,6 +275,10 @@ void resetFunctionViewer(){
hwTests[totalHwTests].testFunction = getTrapAddress;
totalHwTests++;
StrNCopy(hwTests[totalHwTests].name, "Get CPU Info", TEST_NAME_LENGTH);
hwTests[totalHwTests].testFunction = getCpuInfo;
totalHwTests++;
StrNCopy(hwTests[totalHwTests].name, "Get Device Info", TEST_NAME_LENGTH);
hwTests[totalHwTests].testFunction = getDeviceInfo;
totalHwTests++;
@@ -324,10 +328,6 @@ void resetFunctionViewer(){
hwTests[totalHwTests].testFunction = getClk32Frequency;
totalHwTests++;
StrNCopy(hwTests[totalHwTests].name, "Get CPU Info", TEST_NAME_LENGTH);
hwTests[totalHwTests].testFunction = getCpuInfo;
totalHwTests++;
StrNCopy(hwTests[totalHwTests].name, "Get Interrupt Info", TEST_NAME_LENGTH);
hwTests[totalHwTests].testFunction = getInterruptInfo;
totalHwTests++;