diff --git a/src/armv5.c b/src/armv5.c index 5ceac09..dc0c21f 100755 --- a/src/armv5.c +++ b/src/armv5.c @@ -6,6 +6,7 @@ #include "memoryAccess.h" #include "portability.h" #include "armv5/CPU.h" +#include "m68k/m68k.h" #define ARMV5_CYCLES_PER_OPCODE 2 @@ -17,90 +18,48 @@ static ArmCpu armv5Cpu; static Boolean armv5MemoryAccess(ArmCpu* cpu, void* buf, UInt32 vaddr, UInt8 size, Boolean write, Boolean privileged, UInt8* fsr){ - //ARM only has access to RAM, the OS 4 ROM has no data important to it and it would be wrong to access 68k registers from ARM - vaddr &= chips[CHIP_DX_RAM].mask; + //just gonna have ARM and m68k share the same bus for now, ARM may want fonts/bitmaps from ROM -#if !defined(EMU_NO_SAFETY) - if(size & (size - 1) || vaddr & (size - 1))//size is not a power of two or address isnt aligned to size - return false; -#endif + //no safety check is needed, they are done in the m68k memory accessors called from here -#if defined(EMU_BIG_ENDIAN) if(write){ switch(size){ case 1: - *(uint8_t*)(palmRam + vaddr) = *(uint8_t*)buf; + m68k_write_memory_8(vaddr, *(uint8_t*)buf); return true; case 2: - *(uint16_t*)(palmRam + vaddr) = SWAP_16(*(uint16_t*)buf); + m68k_write_memory_16(vaddr, SWAP_16(*(uint16_t*)buf)); return true; case 4: - *(uint32_t*)(palmRam + vaddr) = SWAP_32(*(uint32_t*)buf); + m68k_write_memory_32(vaddr, SWAP_32(*(uint32_t*)buf)); return true; default: + debugLog("Invalid ARMv5 write: address:0x%08X, size:%d\n", vaddr, size * 8); return false; } } else{ switch(size){ case 1: - *(uint8_t*)buf = *(uint8_t*)(palmRam + vaddr); + *(uint8_t*)buf = m68k_read_memory_8(vaddr); return true; case 2: - *(uint16_t*)buf = SWAP_16(*(uint16_t*)(palmRam + vaddr)); + *(uint16_t*)buf = SWAP_16(m68k_read_memory_16(vaddr)); return true; case 4: - *(uint32_t*)buf = SWAP_32(*(uint32_t*)(palmRam + vaddr)); + *(uint32_t*)buf = SWAP_32(m68k_read_memory_32(vaddr)); return true; default: + debugLog("Invalid ARMv5 read: address:0x%08X, size:%d\n", vaddr, size * 8); return false; } } -#else - if(write){ - switch(size){ - case 1: - *(uint8_t*)(palmRam + (vaddr ^ 1)) = *(uint8_t*)buf; - return true; - - case 2: - *(uint16_t*)(palmRam + vaddr) = SWAP_16(*(uint16_t*)buf); - return true; - - case 4: - *(uint16_t*)(palmRam + vaddr) = SWAP_16(*(uint32_t*)buf & 0xFFFF); - *(uint16_t*)(palmRam + vaddr + 2) = SWAP_16(*(uint32_t*)buf >> 16); - return true; - - default: - return false; - } - } - else{ - switch(size){ - case 1: - *(uint8_t*)buf = *(uint8_t*)(palmRam + (vaddr ^ 1)); - return true; - - case 2: - *(uint16_t*)buf = SWAP_16(*(uint16_t*)(palmRam + vaddr)); - return true; - - case 4: - *(uint32_t*)buf = SWAP_16(*(uint16_t*)(palmRam + vaddr + 2)) << 16 | SWAP_16(*(uint16_t*)(palmRam + vaddr)); - return true; - - default: - return false; - } - } -#endif } static Boolean armv5Hypercall(ArmCpu* cpu){ diff --git a/tools/palm/muExpansionDriver/make.sh b/tools/palm/muExpansionDriver/make.sh index e020e51..99b7c73 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" "hires" "armv5" "soundDriver" "globals" "gui" "traps" "config" "debug" "memalign") +declare -a FILES=("muExpDriver" "patcher" "hires" "armv5" "soundDriver" "globals" "gui" "traps" "config" "debug") CFLAGS="-palmos4 -O3" if [ "$1" = "debug" ]; then diff --git a/tools/palm/muExpansionDriver/memalign.c b/tools/palm/muExpansionDriver/memalign.c deleted file mode 100644 index ad020ce..0000000 --- a/tools/palm/muExpansionDriver/memalign.c +++ /dev/null @@ -1,29 +0,0 @@ -/*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 deleted file mode 100644 index e997c80..0000000 --- a/tools/palm/muExpansionDriver/memalign.h +++ /dev/null @@ -1,10 +0,0 @@ -/*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 dbe7245..7e2b31d 100644 --- a/tools/palm/muExpansionDriver/patcher.c +++ b/tools/palm/muExpansionDriver/patcher.c @@ -7,7 +7,7 @@ #include "armv5.h" #include "hires.h" #include "globals.h" -#include "memalign.h" +#include "palmOsPriv.h" #include "palmGlobalDefines.h" #include "specs/emuFeatureRegisterSpec.h" @@ -115,11 +115,11 @@ static void installPceNativeCallHandler(uint32_t armStackSize){ SysSetTrapAddress(sysTrapPceNativeCall, (void*)emuPceNativeCall); if(oldArmStack) - memalign_free(oldArmStack); + MemChunkFree(oldArmStack); /*must have 32 bit aligned size and start*/ armStackSize &= 0xFFFFFFFC; - armStackStart = memalign_alloc(sizeof(uint32_t), armStackSize); + armStackStart = MemChunkNew(0, armStackSize, memNewChunkFlagPreLock | memNewChunkFlagNonMovable | memNewChunkFlagAllowLarge); armv5SetStack(armStackStart, armStackSize); setGlobalVar(ARM_STACK_START, (uint32_t)armStackStart); }