mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
32x: sh2 wip, main SH2 BIOS passes
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@782 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
eaa10a6eb8
commit
acd35d4c08
5 changed files with 283 additions and 34 deletions
|
@ -10,6 +10,12 @@ void Pico32xStartup(void)
|
|||
PicoAHW |= PAHW_32X;
|
||||
PicoMemSetup32x();
|
||||
|
||||
sh2_init(&msh2);
|
||||
sh2_reset(&msh2);
|
||||
|
||||
sh2_init(&ssh2);
|
||||
sh2_reset(&ssh2);
|
||||
|
||||
if (!Pico.m.pal)
|
||||
Pico32x.vdp_regs[0] |= P32XV_nPAL;
|
||||
|
||||
|
@ -77,6 +83,9 @@ static __inline void SekRunM68k(int cyc)
|
|||
}
|
||||
|
||||
#define PICO_32X
|
||||
#define RUN_SH2S \
|
||||
sh2_execute(&msh2, 1000);
|
||||
|
||||
#include "../pico_cmn.c"
|
||||
|
||||
void PicoFrame32x(void)
|
||||
|
|
|
@ -7,7 +7,12 @@ struct Pico32xMem *Pico32xMem;
|
|||
|
||||
static void bank_switch(int b);
|
||||
|
||||
#define MSB8(x) ((x) >> 8)
|
||||
|
||||
// SH2 faking
|
||||
#define FAKE_SH2
|
||||
int p32x_csum_faked;
|
||||
#ifdef FAKE_SH2
|
||||
static const u16 comm_fakevals[] = {
|
||||
0x4d5f, 0x4f4b, // M_OK
|
||||
0x535f, 0x4f4b, // S_OK
|
||||
|
@ -17,17 +22,11 @@ static const u16 comm_fakevals[] = {
|
|||
0x5333, 0x4d33,
|
||||
0x0000, 0x0000, // eq for doom
|
||||
0x0002, // Mortal Kombat
|
||||
0, // pad
|
||||
// 0, // pad
|
||||
};
|
||||
int p32x_csum_faked;
|
||||
|
||||
static u32 p32x_reg_read16(u32 a)
|
||||
static u32 sh2_comm_faker(u32 a)
|
||||
{
|
||||
a &= 0x3e;
|
||||
|
||||
// SH2 faker
|
||||
if ((a & 0x30) == 0x20)
|
||||
{
|
||||
static int f = 0;
|
||||
if (a == 0x28 && !p32x_csum_faked) {
|
||||
p32x_csum_faked = 1;
|
||||
|
@ -36,36 +35,65 @@ static u32 p32x_reg_read16(u32 a)
|
|||
if (f >= sizeof(comm_fakevals) / sizeof(comm_fakevals[0]))
|
||||
f = 0;
|
||||
return comm_fakevals[f++];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static u32 p32x_reg_read16(u32 a)
|
||||
{
|
||||
a &= 0x3e;
|
||||
|
||||
#ifdef FAKE_SH2
|
||||
if ((a & 0x30) == 0x20)
|
||||
return sh2_comm_faker(a);
|
||||
#endif
|
||||
|
||||
return Pico32x.regs[a / 2];
|
||||
}
|
||||
|
||||
static void p32x_reg_write8(u32 a, u32 d)
|
||||
{
|
||||
u16 *r = Pico32x.regs;
|
||||
a &= 0x3f;
|
||||
|
||||
if (a == 1 && !(Pico32x.regs[0] & 1)) {
|
||||
Pico32x.regs[0] |= 1;
|
||||
if (a == 1 && !(r[0] & 1)) {
|
||||
r[0] |= 1;
|
||||
Pico32xStartup();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(Pico32x.regs[0] & 1))
|
||||
if (!(r[0] & 1))
|
||||
return;
|
||||
|
||||
if (a == 5) {
|
||||
switch (a) {
|
||||
case 0:
|
||||
r[0] = (r[0] & 0x83) | ((d << 8) & P32XS_FM);
|
||||
break;
|
||||
case 5:
|
||||
d &= 7;
|
||||
if (Pico32x.regs[4/2] != d) {
|
||||
Pico32x.regs[4/2] = d;
|
||||
if (r[4/2] != d) {
|
||||
r[4/2] = d;
|
||||
bank_switch(d);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void p32x_reg_write16(u32 a, u32 d)
|
||||
{
|
||||
u16 *r = Pico32x.regs;
|
||||
a &= 0x3e;
|
||||
|
||||
switch (a) {
|
||||
case 0:
|
||||
r[0] = (r[0] & 0x83) | (d & P32XS_FM);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((a & 0x30) == 0x20) {
|
||||
r[a / 2] = d;
|
||||
return;
|
||||
}
|
||||
|
||||
p32x_reg_write8(a + 1, d);
|
||||
}
|
||||
|
||||
|
@ -113,6 +141,33 @@ static void p32x_vdp_write16(u32 a, u32 d)
|
|||
p32x_vdp_write8(a | 1, d);
|
||||
}
|
||||
|
||||
// SH2 regs
|
||||
static u32 p32x_sh2reg_read16(u32 a)
|
||||
{
|
||||
a &= 0xff; // ?
|
||||
if (a == 0) {
|
||||
return (Pico32x.regs[0] & P32XS_FM) | P32XS2_ADEN;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void p32x_sh2reg_write8(u32 a, u32 d)
|
||||
{
|
||||
}
|
||||
|
||||
static void p32x_sh2reg_write16(u32 a, u32 d)
|
||||
{
|
||||
a &= 0xff;
|
||||
|
||||
if ((a & 0x30) == 0x20) {
|
||||
Pico32x.regs[a/2] = d;
|
||||
return;
|
||||
}
|
||||
|
||||
p32x_sh2reg_write8(a | 1, d);
|
||||
}
|
||||
|
||||
// default 32x handlers
|
||||
u32 PicoRead8_32x(u32 a)
|
||||
{
|
||||
|
@ -298,6 +353,152 @@ static void bank_switch(int b)
|
|||
elprintf(EL_32X, "bank %06x-%06x -> %06x", 0x900000, 0x900000 + rs - 1, bank);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// SH2
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
u32 pico32x_read8(u32 a)
|
||||
{
|
||||
u32 d = 0;
|
||||
if (a < sizeof(Pico32xMem->sh2_rom_m))
|
||||
return Pico32xMem->sh2_rom_m[a ^ 1];
|
||||
|
||||
if ((a & 0x0ffc0000) == 0x06000000)
|
||||
return Pico32xMem->sdram[(a & 0x3ffff) ^ 1];
|
||||
|
||||
if ((a & 0x0fc00000) == 0x02000000)
|
||||
if ((a & 0x003fffff) < Pico.romsize)
|
||||
return Pico.rom[(a & 0x3fffff) ^ 1];
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4000) {
|
||||
d = p32x_sh2reg_read16(a);
|
||||
goto out_16to8;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4100) {
|
||||
d = p32x_vdp_read16(a);
|
||||
goto out_16to8;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4200) {
|
||||
d = Pico32xMem->pal[(a & 0x1ff) / 2];
|
||||
goto out_16to8;
|
||||
}
|
||||
|
||||
elprintf(EL_UIO, "sh2 unmapped r8 [%08x] %02x @%06x", a, d, ash2_pc());
|
||||
return d;
|
||||
|
||||
out_16to8:
|
||||
if (a & 1)
|
||||
d &= 0xff;
|
||||
else
|
||||
d >>= 8;
|
||||
|
||||
elprintf(EL_32X, "sh2 r8 [%08x] %02x @%06x", a, d, ash2_pc());
|
||||
return d;
|
||||
}
|
||||
|
||||
u32 pico32x_read16(u32 a)
|
||||
{
|
||||
u32 d = 0;
|
||||
if (a < sizeof(Pico32xMem->sh2_rom_m))
|
||||
return *(u16 *)(Pico32xMem->sh2_rom_m + a);
|
||||
|
||||
if ((a & 0x0ffc0000) == 0x06000000)
|
||||
return ((u16 *)Pico32xMem->sdram)[(a & 0x3ffff) / 2];
|
||||
|
||||
if ((a & 0x0fc00000) == 0x02000000)
|
||||
if ((a & 0x003fffff) < Pico.romsize)
|
||||
return ((u16 *)Pico.rom)[(a & 0x3fffff) / 2];
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4000) {
|
||||
d = p32x_sh2reg_read16(a);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4100) {
|
||||
d = p32x_vdp_read16(a);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4200) {
|
||||
d = Pico32xMem->pal[(a & 0x1ff) / 2];
|
||||
goto out;
|
||||
}
|
||||
|
||||
elprintf(EL_UIO, "sh2 unmapped r16 [%08x] %04x @%06x", a, d, ash2_pc());
|
||||
return d;
|
||||
|
||||
out:
|
||||
elprintf(EL_32X, "sh2 r16 [%08x] %04x @%06x", a, d, ash2_pc());
|
||||
return d;
|
||||
}
|
||||
|
||||
u32 pico32x_read32(u32 a)
|
||||
{
|
||||
// elprintf(EL_UIO, "sh2 r32 [%08x] %08x @%06x", a, d, ash2_pc());
|
||||
return (pico32x_read16(a) << 16) | pico32x_read16(a + 2);
|
||||
}
|
||||
|
||||
void pico32x_write8(u32 a, u32 d)
|
||||
{
|
||||
if ((a & 0x0ffffc00) == 0x4000)
|
||||
elprintf(EL_32X, "sh2 w8 [%08x] %02x @%06x", a, d & 0xff, ash2_pc());
|
||||
|
||||
if ((a & 0x0ffc0000) == 0x06000000) {
|
||||
Pico32xMem->sdram[(a & 0x3ffff) ^ 1] = d;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4100) {
|
||||
p32x_vdp_write8(a, d);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4000) {
|
||||
p32x_sh2reg_write8(a, d);
|
||||
return;
|
||||
}
|
||||
|
||||
elprintf(EL_UIO, "sh2 unmapped w8 [%08x] %02x @%06x", a, d & 0xff, ash2_pc());
|
||||
}
|
||||
|
||||
void pico32x_write16(u32 a, u32 d)
|
||||
{
|
||||
if ((a & 0x0ffffc00) == 0x4000)
|
||||
elprintf(EL_32X, "sh2 w16 [%08x] %04x @%06x", a, d & 0xffff, ash2_pc());
|
||||
|
||||
if ((a & 0x0ffc0000) == 0x06000000) {
|
||||
((u16 *)Pico32xMem->sdram)[(a & 0x3ffff) / 2] = d;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4100) {
|
||||
p32x_vdp_write16(a, d);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((a & 0x0ffffe00) == 0x4200) {
|
||||
Pico32xMem->pal[(a & 0x1ff) / 2] = d;
|
||||
Pico32x.dirty_pal = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4000) {
|
||||
p32x_sh2reg_write16(a, d);
|
||||
return;
|
||||
}
|
||||
|
||||
elprintf(EL_UIO, "sh2 unmapped w16 [%08x] %04x @%06x", a, d & 0xffff, ash2_pc());
|
||||
}
|
||||
|
||||
void pico32x_write32(u32 a, u32 d)
|
||||
{
|
||||
// elprintf(EL_UIO, "sh2 w32 [%08x] %08x @%06x", a, d, ash2_pc());
|
||||
pico32x_write16(a, d >> 16);
|
||||
pico32x_write16(a + 2, d);
|
||||
}
|
||||
|
||||
#define HWSWAP(x) (((x) << 16) | ((x) >> 16))
|
||||
void PicoMemSetup32x(void)
|
||||
{
|
||||
|
@ -333,6 +534,24 @@ void PicoMemSetup32x(void)
|
|||
// fill remaining mem with ROM
|
||||
memcpy(Pico32xMem->m68k_rom + 0x100, Pico.rom + 0x100, sizeof(Pico32xMem->m68k_rom) - 0x100);
|
||||
|
||||
// 32X ROM
|
||||
// TODO: move
|
||||
{
|
||||
FILE *f = fopen("32X_M_BIOS.BIN", "rb");
|
||||
int i;
|
||||
if (f == NULL) {
|
||||
printf("missing BIOS\n");
|
||||
exit(1);
|
||||
}
|
||||
fread(Pico32xMem->sh2_rom_m, 1, sizeof(Pico32xMem->sh2_rom_m), f);
|
||||
fclose(f);
|
||||
for (i = 0; i < sizeof(Pico32xMem->sh2_rom_m); i += 2) {
|
||||
int t = Pico32xMem->sh2_rom_m[i];
|
||||
Pico32xMem->sh2_rom_m[i] = Pico32xMem->sh2_rom_m[i + 1];
|
||||
Pico32xMem->sh2_rom_m[i + 1] = t;
|
||||
}
|
||||
}
|
||||
|
||||
// cartridge area becomes unmapped
|
||||
// XXX: we take the easy way and don't unmap ROM,
|
||||
// so that we can avoid handling the RV bit.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// common code for Pico.c and cd/Pico.c
|
||||
// (c) Copyright 2007,2008 Grazvydas "notaz" Ignotas
|
||||
// (c) Copyright 2007-2009 Grazvydas "notaz" Ignotas
|
||||
|
||||
#define CYCLES_M68K_LINE 488 // suitable for both PAL/NTSC
|
||||
#define CYCLES_M68K_VINT_LAG 68
|
||||
|
@ -15,9 +15,16 @@
|
|||
}
|
||||
|
||||
// CPUS_RUN
|
||||
#ifndef RUN_SH2S
|
||||
#define RUN_SH2S
|
||||
#endif
|
||||
|
||||
#ifndef PICO_CD
|
||||
#define CPUS_RUN(m68k_cycles,s68k_cycles) \
|
||||
SekRunM68k(m68k_cycles);
|
||||
{ \
|
||||
SekRunM68k(m68k_cycles); \
|
||||
RUN_SH2S \
|
||||
}
|
||||
#else
|
||||
#define CPUS_RUN(m68k_cycles,s68k_cycles) \
|
||||
{ \
|
||||
|
|
|
@ -226,6 +226,13 @@ extern unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT];
|
|||
typedef unsigned char (z80_read_f)(unsigned short a);
|
||||
typedef void (z80_write_f)(unsigned int a, unsigned char data);
|
||||
|
||||
// ----------------------- SH2 CPU -----------------------
|
||||
|
||||
#include "cpu/sh2mame/sh2.h"
|
||||
|
||||
SH2 msh2, ssh2;
|
||||
#define ash2_pc() msh2.ppc
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
||||
// main oscillator clock which controls timing
|
||||
|
@ -389,6 +396,9 @@ typedef struct
|
|||
#define Pico_mcd ((mcd_state *)Pico.rom)
|
||||
|
||||
// 32X
|
||||
#define P32XS_FM (1<<15)
|
||||
#define P32XS2_ADEN (1<< 9)
|
||||
|
||||
#define P32XV_nPAL (1<<15)
|
||||
#define P32XV_PRI (1<< 7)
|
||||
#define P32XV_Mx (3<< 0)
|
||||
|
@ -413,6 +423,8 @@ struct Pico32xMem
|
|||
unsigned char sdram[0x40000];
|
||||
unsigned short dram[2][0x20000/2]; // AKA fb
|
||||
unsigned char m68k_rom[0x10000]; // 0x100; using M68K_BANK_SIZE
|
||||
unsigned char sh2_rom_m[0x800];
|
||||
unsigned char sh2_rom_s[0x400];
|
||||
unsigned short pal[0x100];
|
||||
unsigned short pal_native[0x100]; // converted to native (for renderer)
|
||||
};
|
||||
|
|
|
@ -71,6 +71,8 @@ else
|
|||
DEFINES += _USE_CZ80
|
||||
OBJS += cpu/cz80/cz80.o
|
||||
endif
|
||||
# sh2
|
||||
OBJS += cpu/sh2mame/sh2pico.o
|
||||
# misc
|
||||
ifeq "$(use_fame)" "1"
|
||||
ifeq "$(use_musashi)" "1"
|
||||
|
@ -83,7 +85,7 @@ CFLAGS += $(addprefix -D,$(DEFINES))
|
|||
vpath %.c = ../..
|
||||
|
||||
DIRS = platform platform/gp2x platform/common pico pico/cd pico/pico pico/sound pico/carthw/svp \
|
||||
pico/32x zlib unzip cpu cpu/musashi cpu/fame cpu/mz80 cpu/cz80
|
||||
pico/32x zlib unzip cpu cpu/musashi cpu/fame cpu/mz80 cpu/cz80 cpu/sh2mame
|
||||
|
||||
all: mkdirs PicoDrive
|
||||
clean: tidy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue