fixes for big endian (mostly mcd)

This commit is contained in:
kub 2021-04-22 23:23:54 +02:00
parent 567c41ff2a
commit 0d8d97f87c
4 changed files with 13 additions and 11 deletions

View file

@ -187,7 +187,7 @@ zip_failed:
else if (strcasecmp(ext, "cso") == 0) else if (strcasecmp(ext, "cso") == 0)
{ {
cso_struct *cso = NULL, *tmp = NULL; cso_struct *cso = NULL, *tmp = NULL;
int size; int i, size;
f = fopen(path, "rb"); f = fopen(path, "rb");
if (f == NULL) if (f == NULL)
goto cso_failed; goto cso_failed;
@ -229,6 +229,8 @@ zip_failed:
elprintf(EL_STATUS, "cso: premature EOF"); elprintf(EL_STATUS, "cso: premature EOF");
goto cso_failed; goto cso_failed;
} }
for (i = 0; i < size/4; i++)
cso->index[i] = CPU_LE4(cso->index[i]);
// all ok // all ok
cso->fpos_in = ftell(f); cso->fpos_in = ftell(f);
@ -280,7 +282,7 @@ cso_failed:
chd->file.file = chd; chd->file.file = chd;
chd->file.type = PMT_CHD; chd->file.type = PMT_CHD;
// subchannel data is skipped, remove it from total size // subchannel data is skipped, remove it from total size
chd->file.size = chd_get_header(cf)->logicalbytes / CD_FRAME_SIZE * CD_MAX_SECTOR_DATA; chd->file.size = head->logicalbytes / CD_FRAME_SIZE * CD_MAX_SECTOR_DATA;
strncpy(chd->file.ext, ext, sizeof(chd->file.ext) - 1); strncpy(chd->file.ext, ext, sizeof(chd->file.ext) - 1);
return &chd->file; return &chd->file;
@ -359,7 +361,7 @@ static size_t _pm_read_chd(void *ptr, size_t bytes, pm_file *stream, int is_audi
if (len > bytes) if (len > bytes)
len = bytes; len = bytes;
#ifdef CPU_IS_LE #if CPU_IS_LE
if (is_audio) { if (is_audio) {
// convert big endian audio samples // convert big endian audio samples
u16 *dst = ptr, v; u16 *dst = ptr, v;
@ -1309,7 +1311,7 @@ static void PicoCartDetect(const char *carthw_cfg)
// Unusual region 'code' // Unusual region 'code'
if (rom_strcmp(0x1f0, "EUROPE") == 0 || rom_strcmp(0x1f0, "Europe") == 0) if (rom_strcmp(0x1f0, "EUROPE") == 0 || rom_strcmp(0x1f0, "Europe") == 0)
*(int *) (Pico.rom + 0x1f0) = 0x20204520; *(u32 *) (Pico.rom + 0x1f0) = CPU_LE4(0x20204520);
} }
// vim:shiftwidth=2:expandtab // vim:shiftwidth=2:expandtab

View file

@ -205,10 +205,10 @@ void m68k_reg_write8(u32 a, u32 d)
goto write_comm; goto write_comm;
case 6: case 6:
Pico_mcd->bios[0x72 + 1] = d; // simple hint vector changer Pico_mcd->bios[MEM_BE2(0x72)] = d; // simple hint vector changer
return; return;
case 7: case 7:
Pico_mcd->bios[0x72] = d; Pico_mcd->bios[MEM_BE2(0x73)] = d;
elprintf(EL_CDREGS, "hint vector set to %04x%04x", elprintf(EL_CDREGS, "hint vector set to %04x%04x",
((u16 *)Pico_mcd->bios)[0x70/2], ((u16 *)Pico_mcd->bios)[0x72/2]); ((u16 *)Pico_mcd->bios)[0x70/2], ((u16 *)Pico_mcd->bios)[0x72/2]);
return; return;
@ -277,7 +277,7 @@ u32 s68k_poll_detect(u32 a, u32 d)
#define READ_FONT_DATA(basemask) \ #define READ_FONT_DATA(basemask) \
{ \ { \
unsigned int fnt = *(unsigned int *)(Pico_mcd->s68k_regs + 0x4c); \ unsigned int fnt = CPU_LE4(*(u32 *)(Pico_mcd->s68k_regs + 0x4c)); \
unsigned int col0 = (fnt >> 8) & 0x0f, col1 = (fnt >> 12) & 0x0f; \ unsigned int col0 = (fnt >> 8) & 0x0f, col1 = (fnt >> 12) & 0x0f; \
if (fnt & (basemask << 0)) d = col1 ; else d = col0; \ if (fnt & (basemask << 0)) d = col1 ; else d = col0; \
if (fnt & (basemask << 1)) d |= col1 << 4; else d |= col0 << 4; \ if (fnt & (basemask << 1)) d |= col1 << 4; else d |= col0 << 4; \

View file

@ -88,7 +88,7 @@ void pcd_pcm_sync(unsigned int to)
} }
addr = ch->addr; addr = ch->addr;
inc = *(unsigned short *)&ch->regs[2]; inc = ch->regs[2] + (ch->regs[3]<<8);
mul_l = ((int)ch->regs[0] * (ch->regs[1] & 0xf)) >> (5+1); mul_l = ((int)ch->regs[0] * (ch->regs[1] & 0xf)) >> (5+1);
mul_r = ((int)ch->regs[0] * (ch->regs[1] >> 4)) >> (5+1); mul_r = ((int)ch->regs[0] * (ch->regs[1] >> 4)) >> (5+1);
@ -99,7 +99,7 @@ void pcd_pcm_sync(unsigned int to)
// test for loop signal // test for loop signal
if (smp == 0xff) if (smp == 0xff)
{ {
addr = *(unsigned short *)&ch->regs[4]; // loop_addr addr = ch->regs[4] + (ch->regs[5]<<8); // loop_addr
smp = Pico_mcd->pcm_ram[addr]; smp = Pico_mcd->pcm_ram[addr];
addr <<= PCM_STEP_SHIFT; addr <<= PCM_STEP_SHIFT;
if (smp == 0xff) if (smp == 0xff)

View file

@ -57,7 +57,7 @@
#define MEM_LE2(a) (a) #define MEM_LE2(a) (a)
#define MEM_LE4(a) (a) #define MEM_LE4(a) (a)
// swapping // swapping
#define CPU_BE2(v) ((u32)((u64)(v)<<16)|((v)>>16)) #define CPU_BE2(v) ((u32)((u64)(v)<<16)|((u32)(v)>>16))
#define CPU_BE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \ #define CPU_BE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \
(((v)<<8)&0xff0000)|(u32)((v)<<24)) (((v)<<8)&0xff0000)|(u32)((v)<<24))
#define CPU_LE2(v) (v) // swap of 2*u16 in u32 #define CPU_LE2(v) (v) // swap of 2*u16 in u32
@ -71,7 +71,7 @@
// swapping // swapping
#define CPU_BE2(v) (v) #define CPU_BE2(v) (v)
#define CPU_BE4(v) (v) #define CPU_BE4(v) (v)
#define CPU_LE2(v) ((u32)((u64)(v)<<16)|((v)>>16)) #define CPU_LE2(v) ((u32)((u64)(v)<<16)|((u32)(v)>>16))
#define CPU_LE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \ #define CPU_LE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \
(((v)<<8)&0xff0000)|(u32)((v)<<24)) (((v)<<8)&0xff0000)|(u32)((v)<<24))
#endif #endif