From 6d5d7791cb07fa33d7e5e6882cf935bb14584c73 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Fri, 30 Mar 2018 10:49:53 -0700 Subject: [PATCH] Check if sed1376 clock is connected before reading or writing its addresses Also start boot loader dumper --- src/emulator.c | 2 +- src/emulator.h | 3 +- src/hardwareRegisters.c | 5 ++ src/hardwareRegisters.h | 3 +- src/memoryAccess.c | 28 +++---- .../bootloaderExtractor/Makefile | 48 ++++++++++++ .../bootloaderExtractor/bootloaderExtractor.c | 71 ++++++++++++++++++ tests/{ => oldRegisterTests}/HwRegTest1.txt | 0 tests/{ => oldRegisterTests}/HwRegTest10.txt | 0 tests/{ => oldRegisterTests}/HwRegTest11.txt | 0 tests/{ => oldRegisterTests}/HwRegTest12.txt | 0 tests/{ => oldRegisterTests}/HwRegTest13.txt | 0 tests/{ => oldRegisterTests}/HwRegTest2.txt | 0 tests/{ => oldRegisterTests}/HwRegTest3.txt | 0 tests/{ => oldRegisterTests}/HwRegTest4.txt | 0 tests/{ => oldRegisterTests}/HwRegTest5.txt | 0 tests/{ => oldRegisterTests}/HwRegTest6.txt | 0 tests/{ => oldRegisterTests}/HwRegTest7.txt | 0 tests/{ => oldRegisterTests}/HwRegTest8.txt | 0 tests/{ => oldRegisterTests}/HwRegTest9.txt | 0 .../{ => oldRegisterTests}/PersianTree.state | Bin 21 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 tests/hardwareTests/bootloaderExtractor/Makefile create mode 100644 tests/hardwareTests/bootloaderExtractor/bootloaderExtractor.c rename tests/{ => oldRegisterTests}/HwRegTest1.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest10.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest11.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest12.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest13.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest2.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest3.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest4.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest5.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest6.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest7.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest8.txt (100%) rename tests/{ => oldRegisterTests}/HwRegTest9.txt (100%) rename tests/{ => oldRegisterTests}/PersianTree.state (100%) diff --git a/src/emulator.c b/src/emulator.c index 27273ea..f18e6e5 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -78,7 +78,7 @@ void emulatorInit(uint8_t* palmRomDump, uint16_t specialFeatures){ palmMisc.batteryLevel = 100; //config - palmClockMultiplier = 1.0;//Overclock disabled + palmClockMultiplier = (specialFeatures & INACCURATE_FAST_CPU) ? 2.0 : 1.0;//Overclock disabled //start running m68k_pulse_reset(); diff --git a/src/emulator.h b/src/emulator.h index 5994ce6..ccd9c0a 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -41,13 +41,14 @@ typedef struct{ uint8_t batteryLevel; }misc_hw_t; -//special features, these make the emulator inaccurate in a good way, but still inaccurate and are therefore optional, they dont do anything yet +//special features, these make the emulator inaccurate in a good way, but still inaccurate and are therefore optional #define ACCURATE 0x0000//no hacks/addons #define INACCURATE_RAM_HUGE 0x0001//128 mb ram #define INACCURATE_FAST_CPU 0x0002//doubles cpu speed #define INACCURATE_HYBRID_CPU 0x0004//allows running arm opcodes in an OS 4 enviroment #define INACCURATE_320x320 0x0008//creates a 320x320 frambuffer for hires mode, the 320x320 framebuffer is a transparent overlay over the 160x160 one and covers it where its pixels are enabled #define INACCURATE_SYNCED_RTC 0x0010//rtc always equals host system time +#define INACCURATE_HLE_APIS 0x0020//memcpy, memcmp, wait on timer will be replaced with the hosts function //config options #define EMU_FPS 60.0 diff --git a/src/hardwareRegisters.c b/src/hardwareRegisters.c index 0a1e950..9fc2ef6 100644 --- a/src/hardwareRegisters.c +++ b/src/hardwareRegisters.c @@ -658,6 +658,11 @@ int interruptAcknowledge(int intLevel){ return vector; } +bool sed1376ClockConnected(){ + //this is the clock output pin for the sed1376, if its disabled so is the lcd controller + return !(registerArrayRead8(PFSEL) & 0x04); +} + unsigned int getHwRegister8(unsigned int address){ switch(address){ diff --git a/src/hardwareRegisters.h b/src/hardwareRegisters.h index 72cfaa0..82ae1e3 100644 --- a/src/hardwareRegisters.h +++ b/src/hardwareRegisters.h @@ -46,7 +46,8 @@ void clk32();//also checks all interrupts //cpu bool cpuIsOn(); -int interruptAcknowledge(int intLevel); +int interruptAcknowledge(int intLevel); +bool sed1376ClockConnected(); //config void resetHwRegisters(); diff --git a/src/memoryAccess.c b/src/memoryAccess.c index a4113f1..9086b2c 100644 --- a/src/memoryAccess.c +++ b/src/memoryAccess.c @@ -16,9 +16,9 @@ unsigned int m68k_read_memory_8(unsigned int address){ return palmRom[address - ROM_START_ADDRESS]; else if(address >= REG_START_ADDRESS && address < REG_START_ADDRESS + REG_SIZE) return getHwRegister8(address - REG_START_ADDRESS); - else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE) + else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE && sed1376ClockConnected()) return sed1376GetRegister(address - SED1376_REG_START_ADDRESS); - else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE) + else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE && sed1376ClockConnected()) printf("Attempted 8 bit read on sed1376 framebuffer at 0x%08X.\n", address - SED1376_FB_START_ADDRESS); //printf("Invalid 8 bit read at 0x%08X.\n", address); @@ -33,9 +33,9 @@ unsigned int m68k_read_memory_16(unsigned int address){ return palmRom[address - ROM_START_ADDRESS] << 8 | palmRom[address - ROM_START_ADDRESS + 1]; else if(address >= REG_START_ADDRESS && address < REG_START_ADDRESS + REG_SIZE) return getHwRegister16(address - REG_START_ADDRESS); - else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE) + else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE && sed1376ClockConnected()) return sed1376GetRegister(address - SED1376_REG_START_ADDRESS); - else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE) + else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE && sed1376ClockConnected()) printf("Attempted 16 bit read on sed1376 framebuffer at 0x%08X.\n", address - SED1376_FB_START_ADDRESS); //printf("Invalid 16 bit read at 0x%08X.\n", address); @@ -50,9 +50,9 @@ unsigned int m68k_read_memory_32(unsigned int address){ return palmRom[address - ROM_START_ADDRESS] << 24 | palmRom[address - ROM_START_ADDRESS + 1] << 16 | palmRom[address - ROM_START_ADDRESS + 2] << 8 | palmRom[address - ROM_START_ADDRESS + 3]; else if(address >= REG_START_ADDRESS && address < REG_START_ADDRESS + REG_SIZE) return getHwRegister32(address - REG_START_ADDRESS); - else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE) + else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE && sed1376ClockConnected()) return sed1376GetRegister(address - SED1376_REG_START_ADDRESS); - else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE) + else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE && sed1376ClockConnected()) printf("Attempted 32 bit read on sed1376 framebuffer at 0x%08X.\n", address - SED1376_FB_START_ADDRESS); //printf("Invalid 32 bit read at 0x%08X.\n", address); @@ -72,10 +72,10 @@ void m68k_write_memory_8(unsigned int address, unsigned int value){ else if(address >= REG_START_ADDRESS && address < REG_START_ADDRESS + REG_SIZE){ setHwRegister8(address - REG_START_ADDRESS, value); } - else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE){ + else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE && sed1376ClockConnected()){ sed1376SetRegister(address - SED1376_REG_START_ADDRESS, value); } - else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE){ + else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE && sed1376ClockConnected()){ printf("Attempted 8 bit write on sed1376 framebuffer at 0x%08X with value of 0x%02X.\n", address - SED1376_FB_START_ADDRESS, value); } else{ @@ -95,10 +95,10 @@ void m68k_write_memory_16(unsigned int address, unsigned int value){ else if(address >= REG_START_ADDRESS && address < REG_START_ADDRESS + REG_SIZE){ setHwRegister16(address - REG_START_ADDRESS, value); } - else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE){ + else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE && sed1376ClockConnected()){ sed1376SetRegister(address - SED1376_REG_START_ADDRESS, value & 0xFF); } - else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE){ + else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE && sed1376ClockConnected()){ printf("Attempted 16 bit write on sed1376 framebuffer at 0x%08X with value of 0x%04X.\n", address - SED1376_FB_START_ADDRESS, value); } else{ @@ -120,10 +120,10 @@ void m68k_write_memory_32(unsigned int address, unsigned int value){ else if(address >= REG_START_ADDRESS && address < REG_START_ADDRESS + REG_SIZE){ setHwRegister32(address - REG_START_ADDRESS, value); } - else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE){ + else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE && sed1376ClockConnected()){ sed1376SetRegister(address - SED1376_REG_START_ADDRESS, value & 0xFF); } - else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE){ + else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE && sed1376ClockConnected()){ printf("Attempted 32 bit write on sed1376 framebuffer at 0x%08X with value of 0x%08X.\n", address - SED1376_FB_START_ADDRESS, value); } else{ @@ -149,11 +149,11 @@ void m68k_write_memory_32_pd(unsigned int address, unsigned int value){ //I dont know the interaction between the hw registers and the malformed opcode printf("Possibly fatal error: Predecrement swaped 32bit write to hw register: 0x%08X, at PC: 0x%08X\n", address, m68k_get_reg(NULL, M68K_REG_PC)); } - else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE){ + else if(address >= SED1376_REG_START_ADDRESS && address < SED1376_REG_START_ADDRESS + SED1376_REG_SIZE && sed1376ClockConnected()){ //I dont know the interaction between sed1376 registers and the malformed opcode printf("Predecrement swapped 32 bit write at sed1376 register 0x%08X with value of 0x%08X.\n", address - SED1376_REG_START_ADDRESS, value); } - else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE){ + else if(address >= SED1376_FB_START_ADDRESS && address < SED1376_FB_START_ADDRESS + SED1376_FB_SIZE && sed1376ClockConnected()){ printf("Attempted 32 bit predecrement swapped write on sed1376 framebuffer at 0x%08X with value of 0x%08X.\n", address - SED1376_FB_START_ADDRESS, value); } else{ diff --git a/tests/hardwareTests/bootloaderExtractor/Makefile b/tests/hardwareTests/bootloaderExtractor/Makefile new file mode 100644 index 0000000..e82aa5e --- /dev/null +++ b/tests/hardwareTests/bootloaderExtractor/Makefile @@ -0,0 +1,48 @@ +APPNAME = BootExtract +ICONTEXT = "VZBootEX" +APPID = Bdmp + +SRCS = bootloaderExtractor.c + +# Tool locations +CC = m68k-palmos-gcc -palmos3.5 +BUILDPRC = build-prc +PILRC = pilrc +OBJRES = m68k-palmos-obj-res + +# File names +RESFILE = $(APPNAME).rcp +PRC = ../$(APPNAME).prc +OBJS = $(SRCS:.c=.o) + +# Compile options +DEFINES = -DHW_TEST +CSFLAGS = -O2 -S $(DEFINES) $(INCLUDES) +CFLAGS = -O2 -g $(DEFINES) $(INCLUDES) + +# Makefile targets + +all: + +.S.o: + $(CC) $(TARGETFLAGS) -c $< + +.c.s: + $(CC) $(CSFLAGS) $< + +$(PRC): code.stamp bin.stamp + $(BUILDPRC) $@ $(ICONTEXT) $(APPID) *.grc *.bin + +code.stamp: $(APPNAME) + $(OBJRES) $(APPNAME) + touch code.stamp + +bin.stamp: $(RESFILE) + $(PILRC) $(RESFILE) + touch bin.stamp + +$(APPNAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@ + +clean:: + rm -rf *.[oa] $(APPNAME) *.bin *.stamp *.grc *~ \ No newline at end of file diff --git a/tests/hardwareTests/bootloaderExtractor/bootloaderExtractor.c b/tests/hardwareTests/bootloaderExtractor/bootloaderExtractor.c new file mode 100644 index 0000000..925e3b6 --- /dev/null +++ b/tests/hardwareTests/bootloaderExtractor/bootloaderExtractor.c @@ -0,0 +1,71 @@ +#include +//#include +//#include + + +static Boolean StartApplication(void); +static void EventLoop(void); + + +static Boolean MyHandleEvent(EventType* event){ + + return false; +} + + +///////////////////////// +// EventLoop +///////////////////////// + +static void EventLoop(void){ + EventType event; + Word error; + + do{ + EvtGetEvent(&event, 1); + + if(!SysHandleEvent(&event)){ + if(!MenuHandleEvent(0, &event, &error)){ + if(!MyHandleEvent(&event)){ + FrmDispatchEvent(&event); + } + } + } + + } + while(event.eType != appStopEvent); +} + +/************************************************************/ +/** global init and cleanup */ +static Boolean StartApplication(void) { + + /* Mask hardware keys */ + KeySetMask(~(keyBitPageUp | keyBitPageDown | + keyBitHard1 | keyBitHard2 | + keyBitHard3 | keyBitHard4 )); + + SysRandom(TimGetTicks()); + + return true; +} + +static void StopApplication(void){ + + +} + +///////////////////////// +// PilotMain +///////////////////////// + +DWord PilotMain(Word cmd, Ptr cmdBPB, Word launchFlags){ + if (cmd == sysAppLaunchCmdNormalLaunch){ + if(StartApplication()){ + EventLoop(); + StopApplication(); + } + } + return(0); +} + diff --git a/tests/HwRegTest1.txt b/tests/oldRegisterTests/HwRegTest1.txt similarity index 100% rename from tests/HwRegTest1.txt rename to tests/oldRegisterTests/HwRegTest1.txt diff --git a/tests/HwRegTest10.txt b/tests/oldRegisterTests/HwRegTest10.txt similarity index 100% rename from tests/HwRegTest10.txt rename to tests/oldRegisterTests/HwRegTest10.txt diff --git a/tests/HwRegTest11.txt b/tests/oldRegisterTests/HwRegTest11.txt similarity index 100% rename from tests/HwRegTest11.txt rename to tests/oldRegisterTests/HwRegTest11.txt diff --git a/tests/HwRegTest12.txt b/tests/oldRegisterTests/HwRegTest12.txt similarity index 100% rename from tests/HwRegTest12.txt rename to tests/oldRegisterTests/HwRegTest12.txt diff --git a/tests/HwRegTest13.txt b/tests/oldRegisterTests/HwRegTest13.txt similarity index 100% rename from tests/HwRegTest13.txt rename to tests/oldRegisterTests/HwRegTest13.txt diff --git a/tests/HwRegTest2.txt b/tests/oldRegisterTests/HwRegTest2.txt similarity index 100% rename from tests/HwRegTest2.txt rename to tests/oldRegisterTests/HwRegTest2.txt diff --git a/tests/HwRegTest3.txt b/tests/oldRegisterTests/HwRegTest3.txt similarity index 100% rename from tests/HwRegTest3.txt rename to tests/oldRegisterTests/HwRegTest3.txt diff --git a/tests/HwRegTest4.txt b/tests/oldRegisterTests/HwRegTest4.txt similarity index 100% rename from tests/HwRegTest4.txt rename to tests/oldRegisterTests/HwRegTest4.txt diff --git a/tests/HwRegTest5.txt b/tests/oldRegisterTests/HwRegTest5.txt similarity index 100% rename from tests/HwRegTest5.txt rename to tests/oldRegisterTests/HwRegTest5.txt diff --git a/tests/HwRegTest6.txt b/tests/oldRegisterTests/HwRegTest6.txt similarity index 100% rename from tests/HwRegTest6.txt rename to tests/oldRegisterTests/HwRegTest6.txt diff --git a/tests/HwRegTest7.txt b/tests/oldRegisterTests/HwRegTest7.txt similarity index 100% rename from tests/HwRegTest7.txt rename to tests/oldRegisterTests/HwRegTest7.txt diff --git a/tests/HwRegTest8.txt b/tests/oldRegisterTests/HwRegTest8.txt similarity index 100% rename from tests/HwRegTest8.txt rename to tests/oldRegisterTests/HwRegTest8.txt diff --git a/tests/HwRegTest9.txt b/tests/oldRegisterTests/HwRegTest9.txt similarity index 100% rename from tests/HwRegTest9.txt rename to tests/oldRegisterTests/HwRegTest9.txt diff --git a/tests/PersianTree.state b/tests/oldRegisterTests/PersianTree.state similarity index 100% rename from tests/PersianTree.state rename to tests/oldRegisterTests/PersianTree.state