diff --git a/src/debug/sandbox.c b/src/debug/sandbox.c index 80e9cb7..c9b4c49 100644 --- a/src/debug/sandbox.c +++ b/src/debug/sandbox.c @@ -398,12 +398,23 @@ uint32_t sandboxCommand(uint32_t command, void* data){ //remove ErrDisplayFileLineMsg from HwrIRQ2Handler, device locks on USB polling without this patchOsRom(0x83652, "4E714E71");//nop; nop + //make SysSetTrapAddress/SysGetTrapAddress support traps > ScrDefaultPaletteState 0xA459 + //up to final OS 5.3 trap DmSyncDatabase 0xA476 + //SysSetTrapAddress_1001AE36: + //SysGetTrapAddress_1001AE7C: + patchOsRom(0x1AE42, "0C410477");//cmpi.w 0x477, d1 + patchOsRom(0x1AE8A, "0C42A477");//cmpi.w 0xA477, d2 + //double dynamic heap size, verified working - //HwrCalcDynamicRAMSize_10005CC6 + //HwrCalcDynamicRAMSize_10005CC6: //HwrCalcDynamicRAMSize_10083B0A: patchOsRom(0x5CC6, "203C000800004E75");//move.l 0x80000, d0; rts patchOsRom(0x83B0A, "203C000800004E75");//move.l 0x80000, d0; rts + //patch PrvChunkNew to only allocate in 4 byte intervals + //PrvChunkNew_10020CBC: + //TODO + //set RAM to 32MB //patchOsRom(0x2C5E, "203C020000004E75");//move.l 0x2000000, d0; rts //patchOsRom(0x8442E, "203C020000004E75");//move.l 0x2000000, d0; rts diff --git a/tools/palm/muExpansionDriver/armv5.c b/tools/palm/muExpansionDriver/armv5.c index 471e691..cfc90f3 100644 --- a/tools/palm/muExpansionDriver/armv5.c +++ b/tools/palm/muExpansionDriver/armv5.c @@ -7,13 +7,7 @@ void armv5SetStack(uint8_t* location, uint32_t size){ - uint32_t firstStackEntry = (uint32_t)location + size - 1; - - /*must be 32 bit aligned, m68k only enforces 16 bit aligned even for 32 bit access so MemPtrNew may return a word aligned address*/ - while((firstStackEntry & 0x3) != 0) - firstStackEntry--; - - armv5SetRegister(13, firstStackEntry); + armv5SetRegister(13, (uint32_t)location + size - sizeof(uint32_t)); } void armv5StackPush(uint32_t value){ diff --git a/tools/palm/muExpansionDriver/globals.c b/tools/palm/muExpansionDriver/globals.c index ae41577..ba3a4d3 100644 --- a/tools/palm/muExpansionDriver/globals.c +++ b/tools/palm/muExpansionDriver/globals.c @@ -3,7 +3,7 @@ uint32_t getGlobalVar(uint16_t id){ - uint32_t value; + uint32_t value = 0x00000000; FtrGet('EMUG', id, &value); return value; } diff --git a/tools/palm/muExpansionDriver/make.sh b/tools/palm/muExpansionDriver/make.sh index 08e8c13..6cffa32 100755 --- a/tools/palm/muExpansionDriver/make.sh +++ b/tools/palm/muExpansionDriver/make.sh @@ -11,7 +11,7 @@ if [ "$1" = "clean" ]; then exit fi -declare -a FILES=("muExpDriver" "patcher" "armv5" "soundDriver" "globals" "gui" "traps" "debug") +declare -a FILES=("muExpDriver" "patcher" "armv5" "soundDriver" "globals" "gui" "traps" "debug" "memalign") CFLAGS="-palmos4 -O3" if [ "$1" = "debug" ]; then diff --git a/tools/palm/muExpansionDriver/memalign.c b/tools/palm/muExpansionDriver/memalign.c new file mode 100644 index 0000000..ad020ce --- /dev/null +++ b/tools/palm/muExpansionDriver/memalign.c @@ -0,0 +1,29 @@ +/*modified from libretro-common*/ +#include "sdkPatch/PalmOSPatched.h" +#include + + +void* memalign_alloc(uint32_t boundary, uint32_t size){ + void** place = NULL; + uint32_t addr = 0; + void* ptr = (void*)MemPtrNew(boundary + size + sizeof(uint32_t)); + + if(!ptr) + return NULL; + + addr = ((uint32_t)ptr + sizeof(uint32_t) + boundary) & ~(boundary - 1); + place = (void**)addr; + place[-1] = ptr; + + return (void*)addr; +} + +void memalign_free(void* ptr){ + void** p = NULL; + + if(!ptr) + return; + + p = (void**)ptr; + free(p[-1]); +} diff --git a/tools/palm/muExpansionDriver/memalign.h b/tools/palm/muExpansionDriver/memalign.h new file mode 100644 index 0000000..e997c80 --- /dev/null +++ b/tools/palm/muExpansionDriver/memalign.h @@ -0,0 +1,10 @@ +/*modified from libretro-common*/ +#ifndef MEMALIGN_H +#define MEMALIGN_H + +#include + +void* memalign_alloc(uint32_t boundary, uint32_t size); +void memalign_free(void* ptr); + +#endif diff --git a/tools/palm/muExpansionDriver/patcher.c b/tools/palm/muExpansionDriver/patcher.c index 22149d4..ed87377 100644 --- a/tools/palm/muExpansionDriver/patcher.c +++ b/tools/palm/muExpansionDriver/patcher.c @@ -5,6 +5,7 @@ #include "traps.h" #include "armv5.h" #include "globals.h" +#include "memalign.h" #include "palmGlobalDefines.h" #include "specs/emuFeatureRegisterSpec.h" @@ -37,6 +38,22 @@ static void install128mbRam(uint8_t mbDynamicHeap){ */ } +static void installPceNativeCallHandler(uint32_t armStackSize){ + uint8_t* oldArmStack = (uint8_t*)getGlobalVar(ARM_STACK_START); + uint8_t* armStackStart; + + SysSetTrapAddress(sysTrapPceNativeCall, (void*)emuPceNativeCall); + + if(oldArmStack) + memalign_free(oldArmStack); + + /*must have 32 bit aligned size and start*/ + armStackSize &= 0xFFFFFFFC; + armStackStart = memalign_alloc(sizeof(uint32_t), armStackSize); + armv5SetStack(armStackStart, armStackSize); + setGlobalVar(ARM_STACK_START, (uint32_t)armStackStart); +} + static void setProperDeviceId(uint16_t screenWidth, uint16_t screenHeight, Boolean hasArmCpu, Boolean hasDpad){ uint32_t osVer; uint32_t companyId; @@ -157,16 +174,8 @@ void initBoot(uint32_t* configFile){ if(enabledFeatures & FEATURE_RAM_HUGE) install128mbRam(configFile[EXTRA_RAM_MB_DYNAMIC_HEAP]); - if(enabledFeatures & FEATURE_HYBRID_CPU){ - SysSetTrapAddress(sysTrapPceNativeCall, (void*)emuPceNativeCall); - - if(configFile[ARM_STACK_SIZE] > 0){ - uint8_t* armStackStart = MemPtrNew(configFile[ARM_STACK_SIZE]);/*currently isnt ever freed*/ - - armv5SetStack(armStackStart, configFile[ARM_STACK_SIZE]); - setGlobalVar(ARM_STACK_START, (uint32_t)armStackStart); - } - } + if(enabledFeatures & FEATURE_HYBRID_CPU) + installPceNativeCallHandler(configFile[ARM_STACK_SIZE]); setProperDeviceId(configFile[LCD_WIDTH], configFile[LCD_HEIGHT], !!(enabledFeatures & FEATURE_HYBRID_CPU), !!(enabledFeatures & FEATURE_EXT_KEYS));