mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 07:17:45 -04:00
add big endian platform support
This commit is contained in:
parent
b053cb2044
commit
57c5a5e505
21 changed files with 224 additions and 178 deletions
|
@ -21,36 +21,38 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pico/pico_port.h>
|
||||
|
||||
/******************************/
|
||||
/* Compiler dependant defines */
|
||||
/******************************/
|
||||
|
||||
#ifndef UINT8
|
||||
#define UINT8 unsigned char
|
||||
#define UINT8 u8
|
||||
#endif
|
||||
|
||||
#ifndef INT8
|
||||
#define INT8 signed char
|
||||
#define INT8 s8
|
||||
#endif
|
||||
|
||||
#ifndef UINT16
|
||||
#define UINT16 unsigned short
|
||||
#define UINT16 u16
|
||||
#endif
|
||||
|
||||
#ifndef INT16
|
||||
#define INT16 signed short
|
||||
#define INT16 s16
|
||||
#endif
|
||||
|
||||
#ifndef UINT32
|
||||
#define UINT32 unsigned int
|
||||
#define UINT32 u32
|
||||
#endif
|
||||
|
||||
#ifndef INT32
|
||||
#define INT32 signed int
|
||||
#define INT32 s32
|
||||
#endif
|
||||
|
||||
#ifndef FPTR
|
||||
#define FPTR uintptr_t
|
||||
#define FPTR uptr
|
||||
#endif
|
||||
|
||||
/*************************************/
|
||||
|
@ -62,16 +64,16 @@ extern "C" {
|
|||
#define CZ80_FETCH_SFT (16 - CZ80_FETCH_BITS)
|
||||
#define CZ80_FETCH_BANK (1 << CZ80_FETCH_BITS)
|
||||
|
||||
#define PICODRIVE_HACKS 1
|
||||
#define CZ80_LITTLE_ENDIAN 1
|
||||
#define PICODRIVE_HACKS 1
|
||||
#define CZ80_LITTLE_ENDIAN CPU_IS_LE
|
||||
#define CZ80_USE_JUMPTABLE 1
|
||||
#define CZ80_BIG_FLAGS_ARRAY 1
|
||||
#define CZ80_BIG_FLAGS_ARRAY 1
|
||||
//#ifdef BUILD_CPS1PSP
|
||||
//#define CZ80_ENCRYPTED_ROM 1
|
||||
//#else
|
||||
#define CZ80_ENCRYPTED_ROM 0
|
||||
//#endif
|
||||
#define CZ80_EMULATE_R_EXACTLY 1
|
||||
#define CZ80_EMULATE_R_EXACTLY 1
|
||||
|
||||
#define zR8(A) (*CPU->pzR8[A])
|
||||
#define zR16(A) (CPU->pzR16[A]->W)
|
||||
|
|
|
@ -48,11 +48,7 @@
|
|||
#define READ_OP() GET_OP(); PC++
|
||||
|
||||
#define READ_ARG() (*(UINT8 *)PC++)
|
||||
#if CZ80_LITTLE_ENDIAN
|
||||
#define READ_ARG16() (*(UINT8 *)PC | (*(UINT8 *)(PC + 1) << 8)); PC += 2
|
||||
#else
|
||||
#define READ_ARG16() (*(UINT8 *)(PC + 1) | (*(UINT8 *)PC << 8)); PC += 2
|
||||
#endif
|
||||
|
||||
//#ifndef BUILD_CPS1PSP
|
||||
//#define READ_MEM8(A) memory_region_cpu2[(A)]
|
||||
|
@ -63,11 +59,7 @@
|
|||
#define READ_MEM8(A) CPU->Read_Byte(A)
|
||||
#endif
|
||||
//#endif
|
||||
#if CZ80_LITTLE_ENDIAN
|
||||
#define READ_MEM16(A) (READ_MEM8(A) | (READ_MEM8((A) + 1) << 8))
|
||||
#else
|
||||
#define READ_MEM16(A) ((READ_MEM8(A) << 8) | READ_MEM8((A) + 1))
|
||||
#endif
|
||||
|
||||
#if PICODRIVE_HACKS
|
||||
#define WRITE_MEM8(A, D) { \
|
||||
|
@ -82,11 +74,7 @@
|
|||
#else
|
||||
#define WRITE_MEM8(A, D) CPU->Write_Byte(A, D);
|
||||
#endif
|
||||
#if CZ80_LITTLE_ENDIAN
|
||||
#define WRITE_MEM16(A, D) { WRITE_MEM8(A, D); WRITE_MEM8((A) + 1, (D) >> 8); }
|
||||
#else
|
||||
#define WRITE_MEM16(A, D) { WRITE_MEM8((A) + 1, D); WRITE_MEM8(A, (D) >> 8); }
|
||||
#endif
|
||||
|
||||
#define PUSH_16(A) { UINT32 sp; zSP -= 2; sp = zSP; WRITE_MEM16(sp, A); }
|
||||
#define POP_16(A) { UINT32 sp; sp = zSP; A = READ_MEM16(sp); zSP = sp + 2; }
|
||||
|
|
|
@ -98,44 +98,7 @@ extern "C" {
|
|||
/* Data definition */
|
||||
/*******************/
|
||||
|
||||
#include <pico/pico_types.h>
|
||||
/*
|
||||
#ifdef u8
|
||||
#undef u8
|
||||
#endif
|
||||
|
||||
#ifdef s8
|
||||
#undef s8
|
||||
#endif
|
||||
|
||||
#ifdef u16
|
||||
#undef u16
|
||||
#endif
|
||||
|
||||
#ifdef s16
|
||||
#undef s16
|
||||
#endif
|
||||
|
||||
#ifdef u32
|
||||
#undef u32
|
||||
#endif
|
||||
|
||||
#ifdef s32
|
||||
#undef s32
|
||||
#endif
|
||||
|
||||
#ifdef uptr
|
||||
#undef uptr
|
||||
#endif
|
||||
|
||||
#define u8 unsigned char
|
||||
#define s8 signed char
|
||||
#define u16 unsigned short
|
||||
#define s16 signed short
|
||||
#define u32 unsigned int
|
||||
#define s32 signed int
|
||||
#define uptr uintptr_t
|
||||
*/
|
||||
#include <pico/pico_port.h>
|
||||
|
||||
/*
|
||||
typedef unsigned char u8;
|
||||
|
@ -148,10 +111,10 @@ typedef signed int s32;
|
|||
|
||||
typedef union
|
||||
{
|
||||
u8 B;
|
||||
s8 SB;
|
||||
u16 W;
|
||||
s16 SW;
|
||||
u8 B[4];
|
||||
s8 SB[4];
|
||||
u16 W[2];
|
||||
s16 SW[2];
|
||||
u32 D;
|
||||
s32 SD;
|
||||
} famec_union32;
|
||||
|
|
|
@ -183,19 +183,22 @@
|
|||
// internals core macros
|
||||
/////////////////////////
|
||||
|
||||
#define XB MEM_LE4(0)
|
||||
#define XW MEM_LE2(0)
|
||||
|
||||
#define DREG(X) (ctx->dreg[(X)].D)
|
||||
#define DREGu32(X) (ctx->dreg[(X)].D)
|
||||
#define DREGs32(X) (ctx->dreg[(X)].SD)
|
||||
#define DREGu16(X) (ctx->dreg[(X)].W)
|
||||
#define DREGs16(X) (ctx->dreg[(X)].SW)
|
||||
#define DREGu8(X) (ctx->dreg[(X)].B)
|
||||
#define DREGs8(X) (ctx->dreg[(X)].SB)
|
||||
#define DREGu16(X) (ctx->dreg[(X)].W[XW])
|
||||
#define DREGs16(X) (ctx->dreg[(X)].SW[XW])
|
||||
#define DREGu8(X) (ctx->dreg[(X)].B[XB])
|
||||
#define DREGs8(X) (ctx->dreg[(X)].SB[XB])
|
||||
|
||||
#define AREG(X) (ctx->areg[(X)].D)
|
||||
#define AREGu32(X) (ctx->areg[(X)].D)
|
||||
#define AREGs32(X) (ctx->areg[(X)].SD)
|
||||
#define AREGu16(X) (ctx->areg[(X)].W)
|
||||
#define AREGs16(X) (ctx->areg[(X)].SW)
|
||||
#define AREGu16(X) (ctx->areg[(X)].W[XW])
|
||||
#define AREGs16(X) (ctx->areg[(X)].SW[XW])
|
||||
|
||||
#define ASP (ctx->asp)
|
||||
|
||||
|
|
|
@ -2568,6 +2568,28 @@ static void rcache_init(void)
|
|||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
// swap 32 bit value read from mem in generated code (same as CPU_BE2)
|
||||
static void emit_le_swap(int cond, int r)
|
||||
{
|
||||
#if CPU_IS_LE
|
||||
if (cond == -1)
|
||||
emith_ror(r, r, 16);
|
||||
else
|
||||
emith_ror_c(cond, r, r, 16);
|
||||
#endif
|
||||
}
|
||||
|
||||
// fix memory byte ptr in generated code (same as MEM_BE2)
|
||||
static void emit_le_ptr8(int cond, int r)
|
||||
{
|
||||
#if CPU_IS_LE
|
||||
if (cond == -1)
|
||||
emith_eor_r_imm_ptr(r, 1);
|
||||
else
|
||||
emith_eor_r_imm_ptr_c(cond, r, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
// NB may return either REG or TEMP
|
||||
static int emit_get_rbase_and_offs(SH2 *sh2, sh2_reg_e r, int rmode, u32 *offs)
|
||||
{
|
||||
|
@ -2608,14 +2630,16 @@ static int emit_get_rbase_and_offs(SH2 *sh2, sh2_reg_e r, int rmode, u32 *offs)
|
|||
|
||||
// if r is in rcache or needed soon anyway, and offs is relative to region,
|
||||
// and address translation fits in add_ptr_imm (s32), then use rcached const
|
||||
if (la == (s32)la && !(*offs & ~mask) && rcache_is_cached(r)) {
|
||||
u32 odd = a & 1; // need to fix odd address for correct byte addressing
|
||||
la -= (s32)((a & ~mask) - *offs - odd); // diff between reg and memory
|
||||
if (la == (s32)la && !(((a & mask) + *offs) & ~mask) && rcache_is_cached(r)) {
|
||||
#if CPU_IS_LE // need to fix odd address for correct byte addressing
|
||||
if (a & 1) *offs += (*offs&1) ? 2 : -2;
|
||||
#endif
|
||||
la -= (s32)((a & ~mask) - *offs); // diff between reg and memory
|
||||
hr = hr2 = rcache_get_reg(r, rmode, NULL);
|
||||
if ((s32)a < 0) emith_uext_ptr(hr2);
|
||||
if ((la & ~omask) - odd) {
|
||||
if (la & ~omask) {
|
||||
hr = rcache_get_tmp();
|
||||
emith_add_r_r_ptr_imm(hr, hr2, (la & ~omask) - odd);
|
||||
emith_add_r_r_ptr_imm(hr, hr2, la & ~omask);
|
||||
rcache_free(hr2);
|
||||
}
|
||||
*offs = (la & omask);
|
||||
|
@ -2792,9 +2816,9 @@ static int emit_memhandler_read_rr(SH2 *sh2, sh2_reg_e rd, sh2_reg_e rs, u32 off
|
|||
else
|
||||
hr2 = rcache_get_reg(rd, RC_GR_WRITE, NULL);
|
||||
switch (size & MF_SIZEMASK) {
|
||||
case 0: emith_read8s_r_r_offs(hr2, hr, offs ^ 1); break; // 8
|
||||
case 1: emith_read16s_r_r_offs(hr2, hr, offs); break; // 16
|
||||
case 2: emith_read_r_r_offs(hr2, hr, offs); emith_ror(hr2, hr2, 16); break;
|
||||
case 0: emith_read8s_r_r_offs(hr2, hr, MEM_BE2(offs)); break; // 8
|
||||
case 1: emith_read16s_r_r_offs(hr2, hr, offs); break; // 16
|
||||
case 2: emith_read_r_r_offs(hr2, hr, offs); emit_le_swap(-1, hr2); break;
|
||||
}
|
||||
rcache_free(hr);
|
||||
if (size & MF_POSTINCR)
|
||||
|
@ -5174,7 +5198,7 @@ static void sh2_generate_utils(void)
|
|||
emith_sh2_rcall(arg0, arg1, arg2, arg3);
|
||||
EMITH_SJMP_START(DCOND_CS);
|
||||
emith_and_r_r_c(DCOND_CC, arg0, arg3);
|
||||
emith_eor_r_imm_ptr_c(DCOND_CC, arg0, 1);
|
||||
emit_le_ptr8(DCOND_CC, arg0);
|
||||
emith_read8s_r_r_r_c(DCOND_CC, RET_REG, arg2, arg0);
|
||||
emith_ret_c(DCOND_CC);
|
||||
EMITH_SJMP_END(DCOND_CS);
|
||||
|
@ -5204,7 +5228,7 @@ static void sh2_generate_utils(void)
|
|||
EMITH_SJMP_START(DCOND_CS);
|
||||
emith_and_r_r_c(DCOND_CC, arg0, arg3);
|
||||
emith_read_r_r_r_c(DCOND_CC, RET_REG, arg2, arg0);
|
||||
emith_ror_c(DCOND_CC, RET_REG, RET_REG, 16);
|
||||
emit_le_swap(DCOND_CC, RET_REG);
|
||||
emith_ret_c(DCOND_CC);
|
||||
EMITH_SJMP_END(DCOND_CS);
|
||||
emith_move_r_r_ptr(arg1, CONTEXT_REG);
|
||||
|
@ -5221,7 +5245,7 @@ static void sh2_generate_utils(void)
|
|||
emith_abijump_reg_c(DCOND_CS, arg2);
|
||||
EMITH_SJMP_END(DCOND_CC);
|
||||
emith_and_r_r_r(arg1, arg0, arg3);
|
||||
emith_eor_r_imm_ptr(arg1, 1);
|
||||
emit_le_ptr8(-1, arg1);
|
||||
emith_read8s_r_r_r(arg1, arg2, arg1);
|
||||
emith_push_ret(arg1);
|
||||
emith_move_r_r_ptr(arg2, CONTEXT_REG);
|
||||
|
@ -5257,7 +5281,7 @@ static void sh2_generate_utils(void)
|
|||
EMITH_SJMP_END(DCOND_CC);
|
||||
emith_and_r_r_r(arg1, arg0, arg3);
|
||||
emith_read_r_r_r(arg1, arg2, arg1);
|
||||
emith_ror(arg1, arg1, 16);
|
||||
emit_le_swap(-1, arg1);
|
||||
emith_push_ret(arg1);
|
||||
emith_move_r_r_ptr(arg2, CONTEXT_REG);
|
||||
emith_abicall(p32x_sh2_poll_memory32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue