--- /dev/null
+#include <stdio.h>
+#if defined(__linux__) && defined(ARM)
+#include <sys/mman.h>
+#endif
+
+#include "cmn.h"
+
+#ifndef ARM
+unsigned int tcache[SSP_TCACHE_SIZE/4];
+unsigned int *ssp_block_table[0x5090/2];
+unsigned int *ssp_block_table_iram[15][0x800/2];
+char ssp_align[SSP_BLOCKTAB_ALIGN_SIZE];
+#endif
+
+
+void drc_cmn_init(void)
+{
+#if defined(__linux__) && defined(ARM)
+ void *tmp;
+
+ tmp = mmap(tcache, SSP_DRC_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
+ printf("mmap tcache: %p, asked %p\n", tmp, tcache);
+#endif
+
+}
+
+// TODO: add calls in core, possibly to cart.c?
+void drc_cmn_cleanup(void)
+{
+#if defined(__linux__) && defined(ARM)
+ int ret;
+ ret = munmap(tcache, SSP_DRC_SIZE);
+ printf("munmap tcache: %i\n", ret);
+#endif
+}
+
--- /dev/null
+#define SSP_TCACHE_SIZE (512*1024)
+#define SSP_BLOCKTAB_SIZE (0x5090/2*4)
+#define SSP_BLOCKTAB_IRAM_SIZE (15*0x800/2*4)
+#define SSP_BLOCKTAB_ALIGN_SIZE 3808
+#define SSP_DRC_SIZE (SSP_TCACHE_SIZE + SSP_BLOCKTAB_SIZE + SSP_BLOCKTAB_IRAM_SIZE + SSP_BLOCKTAB_ALIGN_SIZE)
+
+extern unsigned int tcache[SSP_TCACHE_SIZE/4];
+extern unsigned int *ssp_block_table[SSP_BLOCKTAB_SIZE/4];
+extern unsigned int *ssp_block_table_iram[15][0x800/2];
+
+void drc_cmn_init(void);
+void drc_cmn_cleanup(void);
+
--- /dev/null
+@ vim:filetype=armasm
+
+.if 0
+#include "cmn.h"
+.endif
+
+.global tcache
+.global ssp_block_table
+.global ssp_block_table_iram
+
+@ translation cache buffer + pointer table
+.data
+.align 12 @ 4096
+@.size tcache, SSP_TCACHE_SIZE
+@.size ssp_block_table, SSP_BLOCKTAB_SIZE
+@.size ssp_block_table_iram, SSP_BLOCKTAB_IRAM_SIZE
+tcache:
+ .space SSP_TCACHE_SIZE
+ssp_block_table:
+ .space SSP_BLOCKTAB_SIZE
+ssp_block_table_iram:
+ .space SSP_BLOCKTAB_IRAM_SIZE
+ .space SSP_BLOCKTAB_ALIGN_SIZE
+
+
--- /dev/null
+#include "../sh2.h"
+
+void sh2_execute(SH2 *sh2, int cycles)
+{
+ unsigned int pc = sh2->pc;
+ int op;
+
+ op = p32x_sh2_read16(pc);
+}
+
*****************************************************************************/\r
\r
//#include "debugger.h"\r
-#include "sh2.h"\r
+//#include "sh2.h"\r
//#include "sh2comn.h"\r
#define INLINE static\r
\r
\r
#define LOG(x) do { if (VERBOSE) logerror x; } while (0)\r
\r
-int sh2_icount;\r
+//int sh2_icount;\r
SH2 *sh2;\r
\r
#if 0\r
-#include <string.h>
+#include "../sh2.h"
// MAME types
typedef signed char INT8;
typedef unsigned short UINT16;
typedef unsigned char UINT8;
-// pico memhandlers
-unsigned int p32x_sh2_read8(unsigned int a, int id);
-unsigned int p32x_sh2_read16(unsigned int a, int id);
-unsigned int p32x_sh2_read32(unsigned int a, int id);
-void p32x_sh2_write8(unsigned int a, unsigned int d, int id);
-void p32x_sh2_write16(unsigned int a, unsigned int d, int id);
-void p32x_sh2_write32(unsigned int a, unsigned int d, int id);
-
#define RB(a) p32x_sh2_read8(a,sh2->is_slave)
#define RW(a) p32x_sh2_read16(a,sh2->is_slave)
#define RL(a) p32x_sh2_read32(a,sh2->is_slave)
#define Rn ((opcode>>8)&15)
#define Rm ((opcode>>4)&15)
-#include "sh2.c"
-
-void sh2_reset(SH2 *sh2)
-{
- sh2->pc = RL(0);
- sh2->r[15] = RL(4);
- sh2->sr = I;
- sh2->vbr = 0;
- sh2->pending_int_irq = 0;
-}
-
-static void sh2_do_irq(SH2 *sh2, int level, int vector)
-{
- sh2->irq_callback(sh2->is_slave, level);
-
- sh2->r[15] -= 4;
- WL(sh2->r[15], sh2->sr); /* push SR onto stack */
- sh2->r[15] -= 4;
- WL(sh2->r[15], sh2->pc); /* push PC onto stack */
-
- /* set I flags in SR */
- sh2->sr = (sh2->sr & ~I) | (level << 4);
+#define sh2_icount sh2->icount
- /* fetch PC */
- sh2->pc = RL(sh2->vbr + vector * 4);
-
- /* 13 cycles at best */
- sh2_icount -= 13;
-}
+#include "sh2.c"
-/* Execute cycles - returns number of cycles actually run */
-int sh2_execute(SH2 *sh2_, int cycles)
+void sh2_execute(SH2 *sh2_, int cycles)
{
sh2 = sh2_;
- sh2_icount = cycles;
sh2->cycles_aim += cycles;
+ sh2->icount = cycles = sh2->cycles_aim - sh2->cycles_done;
+
+ if (sh2->icount <= 0)
+ return;
do
{
sh2_internal_irq(sh2, sh2->pending_int_irq, sh2->pending_int_vector);
sh2->test_irq = 0;
}
- sh2_icount--;
+ sh2->icount--;
}
- while (sh2_icount > 0 || sh2->delay); /* can't interrupt before delay */
-
- return cycles - sh2_icount;
-}
-
-void sh2_init(SH2 *sh2, int is_slave)
-{
- memset(sh2, 0, sizeof(*sh2));
- sh2->is_slave = is_slave;
-}
-
-void sh2_irl_irq(SH2 *sh2, int level)
-{
- sh2->pending_irl = level;
- if (level <= ((sh2->sr >> 4) & 0x0f))
- return;
-
- sh2_do_irq(sh2, level, 64 + level/2);
-}
-
-void sh2_internal_irq(SH2 *sh2, int level, int vector)
-{
- sh2->pending_int_irq = level;
- sh2->pending_int_vector = vector;
- if (level <= ((sh2->sr >> 4) & 0x0f))
- return;
+ while (sh2->icount > 0 || sh2->delay); /* can't interrupt before delay */
- sh2_do_irq(sh2, level, vector);
- sh2->pending_int_irq = 0; // auto-clear
+ sh2->cycles_done += cycles - sh2->icount;
}
--- /dev/null
+#include <string.h>
+#include "sh2.h"
+
+#define I 0xf0
+
+void sh2_init(SH2 *sh2, int is_slave)
+{
+ memset(sh2, 0, sizeof(*sh2));
+ sh2->is_slave = is_slave;
+}
+
+void sh2_reset(SH2 *sh2)
+{
+ sh2->pc = p32x_sh2_read32(0, sh2->is_slave);
+ sh2->r[15] = p32x_sh2_read32(4, sh2->is_slave);
+ sh2->sr = I;
+ sh2->vbr = 0;
+ sh2->pending_int_irq = 0;
+}
+
+static void sh2_do_irq(SH2 *sh2, int level, int vector)
+{
+ sh2->irq_callback(sh2->is_slave, level);
+
+ sh2->r[15] -= 4;
+ p32x_sh2_write32(sh2->r[15], sh2->sr, sh2->is_slave); /* push SR onto stack */
+ sh2->r[15] -= 4;
+ p32x_sh2_write32(sh2->r[15], sh2->pc, sh2->is_slave); /* push PC onto stack */
+
+ /* set I flags in SR */
+ sh2->sr = (sh2->sr & ~I) | (level << 4);
+
+ /* fetch PC */
+ sh2->pc = p32x_sh2_read32(sh2->vbr + vector * 4, sh2->is_slave);
+
+ /* 13 cycles at best */
+ sh2->cycles_done += 13;
+// sh2->icount -= 13;
+}
+
+void sh2_irl_irq(SH2 *sh2, int level)
+{
+ sh2->pending_irl = level;
+ if (level <= ((sh2->sr >> 4) & 0x0f))
+ return;
+
+ sh2_do_irq(sh2, level, 64 + level/2);
+}
+
+void sh2_internal_irq(SH2 *sh2, int level, int vector)
+{
+ sh2->pending_int_irq = level;
+ sh2->pending_int_vector = vector;
+ if (level <= ((sh2->sr >> 4) & 0x0f))
+ return;
+
+ sh2_do_irq(sh2, level, vector);
+ sh2->pending_int_irq = 0; // auto-clear
+}
+
--- /dev/null
+#ifndef __SH2_H__\r
+#define __SH2_H__\r
+\r
+// pico memhandlers\r
+// XXX: move somewhere else\r
+unsigned int p32x_sh2_read8(unsigned int a, int id);\r
+unsigned int p32x_sh2_read16(unsigned int a, int id);\r
+unsigned int p32x_sh2_read32(unsigned int a, int id);\r
+void p32x_sh2_write8(unsigned int a, unsigned int d, int id);\r
+void p32x_sh2_write16(unsigned int a, unsigned int d, int id);\r
+void p32x_sh2_write32(unsigned int a, unsigned int d, int id);\r
+\r
+\r
+typedef struct\r
+{\r
+ unsigned int r[16];\r
+ unsigned int ppc;\r
+ unsigned int pc;\r
+ unsigned int pr;\r
+ unsigned int sr;\r
+ unsigned int gbr, vbr;\r
+ unsigned int mach, macl;\r
+\r
+ unsigned int ea;\r
+ unsigned int delay;\r
+ unsigned int test_irq;\r
+\r
+ int pending_irl;\r
+ int pending_int_irq; // internal irq\r
+ int pending_int_vector;\r
+ void (*irq_callback)(int id, int level);\r
+ int is_slave;\r
+\r
+ int icount; // cycles left in current timeslice\r
+ unsigned int cycles_aim; // subtract sh2_icount to get global counter\r
+ unsigned int cycles_done;\r
+} SH2;\r
+\r
+extern SH2 *sh2; // active sh2\r
+\r
+void sh2_init(SH2 *sh2, int is_slave);\r
+void sh2_reset(SH2 *sh2);\r
+void sh2_irl_irq(SH2 *sh2, int level);\r
+void sh2_internal_irq(SH2 *sh2, int level, int vector);\r
+\r
+void sh2_execute(SH2 *sh2, int cycles);\r
+\r
+#endif /* __SH2_H__ */\r
+++ /dev/null
-/*****************************************************************************\r
- *\r
- * sh2.h\r
- * Portable Hitachi SH-2 (SH7600 family) emulator interface\r
- *\r
- * Copyright Juergen Buchmueller <pullmoll@t-online.de>,\r
- * all rights reserved.\r
- *\r
- * - This source code is released as freeware for non-commercial purposes.\r
- * - You are free to use and redistribute this code in modified or\r
- * unmodified form, provided you list me in the credits.\r
- * - If you modify this source code, you must add a notice to each modified\r
- * source file that it has been changed. If you're a nice person, you\r
- * will clearly mark each change too. :)\r
- * - If you wish to use this for commercial purposes, please contact me at\r
- * pullmoll@t-online.de\r
- * - The author of this copywritten work reserves the right to change the\r
- * terms of its usage and license at any time, including retroactively\r
- * - This entire notice must remain in the source code.\r
- *\r
- * This work is based on <tiraniddo@hotmail.com> C/C++ implementation of\r
- * the SH-2 CPU core and was heavily changed to the MAME CPU requirements.\r
- * Thanks also go to Chuck Mason <chukjr@sundail.net> and Olivier Galibert\r
- * <galibert@pobox.com> for letting me peek into their SEMU code :-)\r
- *\r
- *****************************************************************************/\r
-\r
-#pragma once\r
-\r
-#ifndef __SH2_H__\r
-#define __SH2_H__\r
-\r
-typedef struct\r
-{\r
- unsigned int r[16];\r
- unsigned int ppc;\r
- unsigned int pc;\r
- unsigned int pr;\r
- unsigned int sr;\r
- unsigned int gbr, vbr;\r
- unsigned int mach, macl;\r
-\r
- unsigned int ea;\r
- unsigned int delay;\r
- unsigned int test_irq;\r
-\r
- int pending_irl;\r
- int pending_int_irq; // internal irq\r
- int pending_int_vector;\r
- void (*irq_callback)(int id, int level);\r
- int is_slave;\r
-\r
- unsigned int cycles_aim; // subtract sh2_icount to get global counter\r
-} SH2;\r
-\r
-SH2 *sh2; // active sh2\r
-extern int sh2_icount;\r
-\r
-void sh2_init(SH2 *sh2, int is_slave);\r
-void sh2_reset(SH2 *sh2);\r
-int sh2_execute(SH2 *sh2_, int cycles);\r
-void sh2_irl_irq(SH2 *sh2, int level);\r
-void sh2_internal_irq(SH2 *sh2, int level, int vector);\r
-\r
-#endif /* __SH2_H__ */\r
// Free for non-commercial use.
#include "../../pico_int.h"
+#include "../../../cpu/drc/cmn.h"
#include "compiler.h"
#define u32 unsigned int
#ifndef ARM
#define DUMP_BLOCK 0x0c9a
-u32 tcache[SSP_TCACHE_SIZE/4];
-u32 *ssp_block_table[0x5090/2];
-u32 *ssp_block_table_iram[15][0x800/2];
-char ssp_align[SSP_BLOCKTAB_ALIGN_SIZE];
void ssp_drc_next(void){}
void ssp_drc_next_patch(void){}
void ssp_drc_end(void){}
int ssp1601_dyn_startup(void)
{
+ drc_cmn_init();
+
memset(tcache, 0, SSP_TCACHE_SIZE);
memset(ssp_block_table, 0, sizeof(ssp_block_table));
memset(ssp_block_table_iram, 0, sizeof(ssp_block_table_iram));
-#define SSP_TCACHE_SIZE (512*1024)
-#define SSP_BLOCKTAB_SIZE (0x5090/2*4)
-#define SSP_BLOCKTAB_IRAM_SIZE (15*0x800/2*4)
-#define SSP_BLOCKTAB_ALIGN_SIZE 3808
-#define SSP_DRC_SIZE (SSP_TCACHE_SIZE + SSP_BLOCKTAB_SIZE + SSP_BLOCKTAB_IRAM_SIZE + SSP_BLOCKTAB_ALIGN_SIZE)
-
-extern unsigned int tcache[SSP_TCACHE_SIZE/4];
-extern unsigned int *ssp_block_table[0x5090/2];
-extern unsigned int *ssp_block_table_iram[15][0x800/2];
-
int ssp_drc_entry(int cycles);
void ssp_drc_next(void);
void ssp_drc_next_patch(void);
@ (c) Copyright 2008, Grazvydas "notaz" Ignotas
@ Free for non-commercial use.
-.if 0
-#include "compiler.h"
-.endif
-
-.global tcache
-.global ssp_block_table
-.global ssp_block_table_iram
-
.global ssp_drc_entry
.global ssp_drc_next
.global ssp_drc_next_patch
.global ssp_hle_11_384
.global ssp_hle_11_38a
-@ translation cache buffer + pointer table
-.data
-.align 12 @ 4096
-@.size tcache, SSP_TCACHE_SIZE
-@.size ssp_block_table, SSP_BLOCKTAB_SIZE
-@.size ssp_block_table_iram, SSP_BLOCKTAB_IRAM_SIZE
-tcache:
- .space SSP_TCACHE_SIZE
-ssp_block_table:
- .space SSP_BLOCKTAB_SIZE
-ssp_block_table_iram:
- .space SSP_BLOCKTAB_IRAM_SIZE
- .space SSP_BLOCKTAB_ALIGN_SIZE
-
.text
.align 2
-
@ SSP_GR0, SSP_X, SSP_Y, SSP_A,
@ SSP_ST, SSP_STACK, SSP_PC, SSP_P,
@ SSP_PM0, SSP_PM1, SSP_PM2, SSP_XST,
#include "../../pico_int.h"
#include "compiler.h"
-#if defined(__linux__) && defined(ARM)
-#include <sys/mman.h>
-#endif
svp_t *svp = NULL;
int PicoSVPCycles = 850; // cycles/line, just a guess
void PicoSVPInit(void)
{
-#if defined(__linux__) && defined(ARM)
- int ret;
- ret = munmap(tcache, SSP_DRC_SIZE);
- printf("munmap tcache: %i\n", ret);
-#endif
-}
-
-
-static void PicoSVPShutdown(void)
-{
-#if defined(__linux__) && defined(ARM)
- // also unmap tcache
- PicoSVPInit();
-#endif
}
svp = (void *) ((char *)tmp + 0x200000);
memset(svp, 0, sizeof(*svp));
-#if defined(__linux__) && defined(ARM)
- tmp = mmap(tcache, SSP_DRC_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
- printf("mmap tcache: %p, asked %p\n", tmp, tcache);
-#endif
-
// init SVP compiler
svp_dyn_ready = 0;
#ifndef PSP
- if (PicoOpt&POPT_EN_SVP_DRC) {
- if (ssp1601_dyn_startup()) return;
+ if (PicoOpt & POPT_EN_SVP_DRC) {
+ if (ssp1601_dyn_startup())
+ return;
svp_dyn_ready = 1;
}
#endif
PicoDmaHook = PicoSVPDma;
PicoResetHook = PicoSVPReset;
PicoLineHook = PicoSVPLine;
- PicoCartUnloadHook = PicoSVPShutdown;
// save state stuff
svp_states[0].ptr = svp->iram_rom;
\r
// ----------------------- SH2 CPU -----------------------\r
\r
-#include "cpu/sh2mame/sh2.h"\r
+#include "cpu/sh2/sh2.h"\r
\r
extern SH2 sh2s[2];\r
#define msh2 sh2s[0]\r
#define ssh2 sh2s[1]\r
\r
-#define ash2_end_run(after) if (sh2_icount > (after)) sh2_icount = after\r
-#define ash2_cycles_done() (sh2->cycles_aim - sh2_icount)\r
+#define ash2_end_run(after) if (sh2->icount > (after)) sh2->icount = after\r
+#define ash2_cycles_done() (sh2->cycles_aim - sh2->icount)\r
\r
#define sh2_pc(c) (c) ? ssh2.ppc : msh2.ppc\r
#define sh2_reg(c, x) (c) ? ssh2.r[x] : msh2.r[x]\r
DEFINC += -D_USE_DRZ80\r
OBJS += cpu/DrZ80/drz80.o\r
endif\r
+OBJS += cpu/sh2/sh2.o\r
ifeq "$(use_sh2mame)" "1"\r
-OBJS += cpu/sh2mame/sh2pico.o\r
+OBJS += cpu/sh2/mame/sh2pico.o\r
else\r
endif\r
+OBJS += cpu/drc/cmn.o\r
+OBJS += cpu/drc/cmn_arm.o\r
\r
vpath %.c = ../..\r
vpath %.s = ../..\r
\r
DIRS = platform platform/gp2x platform/linux platform/common pico pico/cd pico/pico pico/32x \\r
pico/sound pico/carthw/svp zlib unzip cpu cpu/musashi cpu/Cyclone/proj cpu/Cyclone/tools \\r
- cpu/mz80 cpu/DrZ80 cpu/sh2mame\r
+ cpu/mz80 cpu/DrZ80 cpu/sh2/mame cpu/drc\r
\r
\r
all: mkdirs PicoDrive\r
use_musashi = 1
#use_fame = 1
#use_mz80 = 1
+#use_sh2drc = 1
#profile = 1
#fake_in_gp2x = 1
OBJS += cpu/cz80/cz80.o
endif
# sh2
-OBJS += cpu/sh2mame/sh2pico.o
+OBJS += cpu/sh2/sh2.o
+ifeq "$(use_sh2drc)" "1"
+else
+OBJS += cpu/sh2/mame/sh2pico.o
+endif
+OBJS += cpu/drc/cmn.o
# misc
ifeq "$(use_fame)" "1"
ifeq "$(use_musashi)" "1"
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 cpu/sh2mame
+ pico/32x zlib unzip cpu cpu/musashi cpu/fame cpu/mz80 cpu/cz80 cpu/sh2/mame cpu/drc
all: mkdirs PicoDrive
clean: tidy