mirror of
https://github.com/libretro/Mu.git
synced 2026-09-22 22:56:12 +00:00
Fix libretro big endian platforms and other possible alignment errors
This commit is contained in:
@@ -130,7 +130,7 @@ else ifeq ($(platform), osx)
|
||||
TARGET := $(TARGET_NAME)_libretro.$(EXT)
|
||||
fpic := -fPIC
|
||||
ifeq ($(arch),ppc)
|
||||
CFLAGS += -D__ppc__ -DMSB_FIRST
|
||||
CFLAGS += -D__ppc__ -DEMU_BIG_ENDIAN
|
||||
endif
|
||||
OSXVER = $(shell sw_vers -productVersion | cut -d. -f 2)
|
||||
OSX_GT_MOJAVE = $(shell (( $(OSXVER) >= 14)) && echo "YES")
|
||||
@@ -197,7 +197,7 @@ else ifeq ($(platform), ps3)
|
||||
TARGET := $(TARGET_NAME)_libretro_ps3.$(EXT)
|
||||
CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe
|
||||
AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe
|
||||
CFLAGS += -D__ppc__ -DMSB_FIRST
|
||||
CFLAGS += -D__ppc__ -DEMU_BIG_ENDIAN
|
||||
STATIC_LINKING=1
|
||||
STATIC_LINKING_LINK=1
|
||||
|
||||
@@ -207,7 +207,7 @@ else ifeq ($(platform), sncps3)
|
||||
TARGET := $(TARGET_NAME)_libretro_ps3.$(EXT)
|
||||
CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
|
||||
AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe
|
||||
CFLAGS += -D__ppc__ -DMSB_FIRST
|
||||
CFLAGS += -D__ppc__ -DEMU_BIG_ENDIAN
|
||||
STATIC_LINKING=1
|
||||
STATIC_LINKING_LINK=1
|
||||
|
||||
@@ -217,7 +217,7 @@ else ifeq ($(platform), psl1ght)
|
||||
TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT)
|
||||
CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
|
||||
AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT)
|
||||
CFLAGS += -D__ppc__ -DMSB_FIRST
|
||||
CFLAGS += -D__ppc__ -DEMU_BIG_ENDIAN
|
||||
STATIC_LINKING=1
|
||||
STATIC_LINKING_LINK=1
|
||||
|
||||
@@ -311,7 +311,7 @@ else ifeq ($(platform), ngc)
|
||||
TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT)
|
||||
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
|
||||
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
|
||||
CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST
|
||||
CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DEMU_BIG_ENDIAN
|
||||
CFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
|
||||
STATIC_LINKING=1
|
||||
STATIC_LINKING_LINK=1
|
||||
@@ -322,7 +322,7 @@ else ifeq ($(platform), wii)
|
||||
TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT)
|
||||
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
|
||||
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
|
||||
CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST
|
||||
CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DEMU_BIG_ENDIAN
|
||||
CFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
|
||||
STATIC_LINKING=1
|
||||
STATIC_LINKING_LINK=1
|
||||
@@ -333,7 +333,7 @@ else ifeq ($(platform), wiiu)
|
||||
TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT)
|
||||
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
|
||||
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
|
||||
CFLAGS += -DGEKKO -DHW_RVL -mwup -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST
|
||||
CFLAGS += -DGEKKO -DHW_RVL -mwup -mcpu=750 -meabi -mhard-float -D__ppc__ -DEMU_BIG_ENDIAN
|
||||
CFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
|
||||
STATIC_LINKING=1
|
||||
STATIC_LINKING_LINK=1
|
||||
|
||||
@@ -363,7 +363,7 @@ bool retro_load_game(const struct retro_game_info *info){
|
||||
if(saveRamFile){
|
||||
if(filestream_get_size(saveRamFile) == emulatorGetRamSize()){
|
||||
filestream_read(saveRamFile, palmRam, emulatorGetRamSize());
|
||||
swap16_buffer_if_little(palmRam, emulatorGetRamSize() / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(palmRam, emulatorGetRamSize() / sizeof(uint16_t));
|
||||
}
|
||||
filestream_close(saveRamFile);
|
||||
}
|
||||
@@ -395,7 +395,7 @@ void retro_unload_game(void){
|
||||
saveRamFile = filestream_open(saveRamPath, RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
|
||||
if(saveRamFile){
|
||||
swap16_buffer_if_little(palmRam, emulatorGetRamSize() / sizeof(uint16_t));//this will no longer be used, so its ok to destroy it when swapping
|
||||
swap16BufferIfLittle(palmRam, emulatorGetRamSize() / sizeof(uint16_t));//this will no longer be used, so its ok to destroy it when swapping
|
||||
filestream_write(saveRamFile, palmRam, emulatorGetRamSize());
|
||||
filestream_close(saveRamFile);
|
||||
}
|
||||
|
||||
@@ -89,12 +89,12 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t spec
|
||||
memcpy(palmRom, palmRomDump.data, uMin(palmRomDump.size, ROM_SIZE));
|
||||
if(palmRomDump.size < ROM_SIZE)
|
||||
memset(palmRom + palmRomDump.size, 0x00, ROM_SIZE - palmRomDump.size);
|
||||
swap16_buffer_if_little(palmRom, ROM_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(palmRom, ROM_SIZE / sizeof(uint16_t));
|
||||
if(palmBootDump.data){
|
||||
memcpy(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE, palmBootDump.data, uMin(palmBootDump.size, BOOTLOADER_SIZE));
|
||||
if(palmBootDump.size < BOOTLOADER_SIZE)
|
||||
memset(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE + palmBootDump.size, 0x00, BOOTLOADER_SIZE - palmBootDump.size);
|
||||
swap16_buffer_if_little(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE, BOOTLOADER_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE, BOOTLOADER_SIZE / sizeof(uint16_t));
|
||||
}
|
||||
else{
|
||||
memset(palmReg + REG_SIZE - 1 - BOOTLOADER_SIZE, 0x00, BOOTLOADER_SIZE);
|
||||
@@ -233,16 +233,16 @@ bool emulatorSaveState(buffer_t buffer){
|
||||
//memory
|
||||
if(palmSpecialFeatures & FEATURE_RAM_HUGE){
|
||||
memcpy(buffer.data + offset, palmRam, SUPERMASSIVE_RAM_SIZE);
|
||||
swap16_buffer_if_little(buffer.data + offset, SUPERMASSIVE_RAM_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(buffer.data + offset, SUPERMASSIVE_RAM_SIZE / sizeof(uint16_t));
|
||||
offset += SUPERMASSIVE_RAM_SIZE;
|
||||
}
|
||||
else{
|
||||
memcpy(buffer.data + offset, palmRam, RAM_SIZE);
|
||||
swap16_buffer_if_little(buffer.data + offset, RAM_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(buffer.data + offset, RAM_SIZE / sizeof(uint16_t));
|
||||
offset += RAM_SIZE;
|
||||
}
|
||||
memcpy(buffer.data + offset, palmReg, REG_SIZE);
|
||||
swap16_buffer_if_little(buffer.data + offset, REG_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(buffer.data + offset, REG_SIZE / sizeof(uint16_t));
|
||||
offset += REG_SIZE;
|
||||
memcpy(buffer.data + offset, bankType, TOTAL_MEMORY_BANKS);
|
||||
offset += TOTAL_MEMORY_BANKS;
|
||||
@@ -389,16 +389,16 @@ bool emulatorLoadState(buffer_t buffer){
|
||||
//memory
|
||||
if(palmSpecialFeatures & FEATURE_RAM_HUGE){
|
||||
memcpy(palmRam, buffer.data + offset, SUPERMASSIVE_RAM_SIZE);
|
||||
swap16_buffer_if_little(palmRam, SUPERMASSIVE_RAM_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(palmRam, SUPERMASSIVE_RAM_SIZE / sizeof(uint16_t));
|
||||
offset += SUPERMASSIVE_RAM_SIZE;
|
||||
}
|
||||
else{
|
||||
memcpy(palmRam, buffer.data + offset, RAM_SIZE);
|
||||
swap16_buffer_if_little(palmRam, RAM_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(palmRam, RAM_SIZE / sizeof(uint16_t));
|
||||
offset += RAM_SIZE;
|
||||
}
|
||||
memcpy(palmReg, buffer.data + offset, REG_SIZE);
|
||||
swap16_buffer_if_little(palmReg, REG_SIZE / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(palmReg, REG_SIZE / sizeof(uint16_t));
|
||||
offset += REG_SIZE;
|
||||
memcpy(bankType, buffer.data + offset, TOTAL_MEMORY_BANKS);
|
||||
offset += TOTAL_MEMORY_BANKS;
|
||||
@@ -527,7 +527,7 @@ bool emulatorSaveRam(buffer_t buffer){
|
||||
return false;
|
||||
|
||||
memcpy(buffer.data, palmRam, size);
|
||||
swap16_buffer_if_little(buffer.data, size / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(buffer.data, size / sizeof(uint16_t));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -539,7 +539,7 @@ bool emulatorLoadRam(buffer_t buffer){
|
||||
return false;
|
||||
|
||||
memcpy(palmRam, buffer.data, size);
|
||||
swap16_buffer_if_little(palmRam, size / sizeof(uint16_t));
|
||||
swap16BufferIfLittle(palmRam, size / sizeof(uint16_t));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,21 +3,19 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
//endian
|
||||
#define SWAP16(x) ((uint16_t)( \
|
||||
(((uint16_t)(x) & 0x00ff) << 8) | \
|
||||
(((uint16_t)(x) & 0xff00) >> 8) \
|
||||
))
|
||||
|
||||
static inline void swap16_buffer_if_little(uint16_t* buffer, uint64_t count){
|
||||
static inline void swap16BufferIfLittle(uint8_t* buffer, uint64_t count){
|
||||
#if !defined(EMU_BIG_ENDIAN)
|
||||
for(uint64_t index = 0; index < count; index++)
|
||||
buffer[index] = SWAP16(buffer[index]);
|
||||
//count specifys the number of uint16_t's that need to be swapped, the uint8_t* is because of alignment restrictions that crash on some platforms
|
||||
count *= sizeof(uint16_t);
|
||||
for(uint64_t index = 0; index < count; index += 2){
|
||||
uint8_t temp = buffer[index];
|
||||
buffer[index] = buffer[index + 1];
|
||||
buffer[index + 1] = temp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//threads
|
||||
#if defined(EMU_MULTITHREADED)
|
||||
#define MULTITHREAD_LOOP _Pragma("omp parallel for")
|
||||
@@ -27,7 +25,6 @@ static inline void swap16_buffer_if_little(uint16_t* buffer, uint64_t count){
|
||||
#define MULTITHREAD_DOUBLE_LOOP
|
||||
#endif
|
||||
|
||||
|
||||
static inline const char* boolString(bool boo){
|
||||
return boo ? "true" : "false";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user