-// Pico Library - Internal Header File\r
-\r
-// (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006-2009 Grazvydas "notaz" Ignotas, all rights reserved.\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
+/*\r
+ * PicoDrive - Internal Header File\r
+ * (c) Copyright Dave, 2004\r
+ * (C) notaz, 2006-2010\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
\r
#ifndef PICO_INTERNAL_INCLUDED\r
#define PICO_INTERNAL_INCLUDED\r
\r
// ----------------------- 68000 CPU -----------------------\r
#ifdef EMU_C68K\r
-#include "../cpu/Cyclone/Cyclone.h"\r
+#include "../cpu/cyclone/Cyclone.h"\r
extern struct Cyclone PicoCpuCM68k, PicoCpuCS68k;\r
#define SekCyclesLeftNoMCD PicoCpuCM68k.cycles // cycles left for this run\r
#define SekCyclesLeft \\r
#define SekEndTimesliceS68k(after) PicoCpuCS68k.cycles=after\r
#define SekPc (PicoCpuCM68k.pc-PicoCpuCM68k.membase)\r
#define SekPcS68k (PicoCpuCS68k.pc-PicoCpuCS68k.membase)\r
-#define SekDar(x) PicoCpuCM68k.d[x]\r
+#define SekDar(x) (x < 8 ? PicoCpuCM68k.d[x] : PicoCpuCM68k.a[x - 8])\r
#define SekSr CycloneGetSr(&PicoCpuCM68k)\r
#define SekSetStop(x) { PicoCpuCM68k.state_flags&=~1; if (x) { PicoCpuCM68k.state_flags|=1; PicoCpuCM68k.cycles=0; } }\r
#define SekSetStopS68k(x) { PicoCpuCS68k.state_flags&=~1; if (x) { PicoCpuCS68k.state_flags|=1; PicoCpuCS68k.cycles=0; } }\r
+#define SekIsStoppedM68k() (PicoCpuCM68k.state_flags&1)\r
#define SekIsStoppedS68k() (PicoCpuCS68k.state_flags&1)\r
#define SekShouldInterrupt (PicoCpuCM68k.irq > (PicoCpuCM68k.srh&7))\r
\r
#define SekEndTimesliceS68k(after) PicoCpuFS68k.io_cycle_counter=after\r
#define SekPc fm68k_get_pc(&PicoCpuFM68k)\r
#define SekPcS68k fm68k_get_pc(&PicoCpuFS68k)\r
-#define SekDar(x) PicoCpuFM68k.dreg[x].D\r
+#define SekDar(x) (x < 8 ? PicoCpuFM68k.dreg[x].D : PicoCpuFM68k.areg[x - 8].D)\r
#define SekSr PicoCpuFM68k.sr\r
#define SekSetStop(x) { \\r
PicoCpuFM68k.execinfo &= ~FM68K_HALTED; \\r
PicoCpuFS68k.execinfo &= ~FM68K_HALTED; \\r
if (x) { PicoCpuFS68k.execinfo |= FM68K_HALTED; PicoCpuFS68k.io_cycle_counter = 0; } \\r
}\r
+#define SekIsStoppedM68k() (PicoCpuFM68k.execinfo&FM68K_HALTED)\r
#define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED)\r
#define SekShouldInterrupt fm68k_would_interrupt()\r
\r
if(x) { SET_CYCLES(0); PicoCpuMS68k.stopped=STOP_LEVEL_STOP; } \\r
else PicoCpuMS68k.stopped=0; \\r
}\r
+#define SekIsStoppedM68k() (PicoCpuMM68k.stopped==STOP_LEVEL_STOP)\r
#define SekIsStoppedS68k() (PicoCpuMS68k.stopped==STOP_LEVEL_STOP)\r
#define SekShouldInterrupt (CPU_INT_LEVEL > FLAG_INT_MASK)\r
\r
#define SekCyclesBurn(c) SekCycleCnt+=c\r
#define SekCyclesDone() (SekCycleAim-SekCyclesLeft) // number of cycles done in this frame (can be checked anywhere)\r
#define SekCyclesDoneT() (SekCycleCntT+SekCyclesDone()) // total nuber of cycles done for this rom\r
+#define SekCyclesDoneT2() (SekCycleCntT + SekCycleCnt) // same as above but not from memhandlers\r
\r
#define SekEndRun(after) { \\r
SekCycleCnt -= SekCyclesLeft - (after); \\r
\r
// ----------------------- Z80 CPU -----------------------\r
\r
-#if defined(_USE_MZ80)\r
-#include "../cpu/mz80/mz80.h"\r
-\r
-#define z80_run(cycles) { mz80GetElapsedTicks(1); mz80_run(cycles) }\r
-#define z80_run_nr(cycles) mz80_run(cycles)\r
-#define z80_int() mz80int(0)\r
-\r
-#elif defined(_USE_DRZ80)\r
+#if defined(_USE_DRZ80)\r
#include "../cpu/DrZ80/drz80.h"\r
\r
extern struct DrZ80 drZ80;\r
\r
#endif\r
\r
+#define Z80_STATE_SIZE 0x60\r
+\r
extern int z80stopCycle; /* in 68k cycles */\r
extern int z80_cycle_cnt; /* 'done' z80 cycles before z80_run() */\r
extern int z80_cycle_aim;\r
\r
#define cycles_68k_to_z80(x) ((x)*957 >> 11)\r
\r
-#define Z80_MEM_SHIFT 13\r
-extern unsigned long z80_read_map [0x10000 >> Z80_MEM_SHIFT];\r
-extern unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT];\r
-typedef unsigned char (z80_read_f)(unsigned short a);\r
-typedef void (z80_write_f)(unsigned int a, unsigned char data);\r
-\r
// ----------------------- SH2 CPU -----------------------\r
\r
#include "cpu/sh2/sh2.h"\r
#define ssh2 sh2s[1]\r
\r
#ifndef DRC_SH2\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 sh2_end_run(sh2, after_) do { \\r
+ if ((sh2)->icount > (after_)) { \\r
+ (sh2)->cycles_timeslice -= (sh2)->icount; \\r
+ (sh2)->icount = after_; \\r
+ } \\r
+} while (0)\r
+# define sh2_cycles_left(sh2) (sh2)->icount\r
+# define sh2_pc(c) (c) ? ssh2.ppc : msh2.ppc\r
#else\r
-# define ash2_end_run(after) { \\r
- if ((sh2->sr >> 12) > (after)) \\r
- { sh2->sr &= 0xfff; sh2->sr |= (after) << 12; } \\r
-}\r
-# define ash2_cycles_done() (sh2->cycles_aim - (sh2->sr >> 12))\r
+# define sh2_end_run(sh2, after_) do { \\r
+ int left_ = (signed int)(sh2)->sr >> 12; \\r
+ if (left_ > (after_)) { \\r
+ (sh2)->cycles_timeslice -= left_; \\r
+ (sh2)->sr &= 0xfff; \\r
+ (sh2)->sr |= (after_) << 12; \\r
+ } \\r
+} while (0)\r
+# define sh2_cycles_left(sh2) ((signed int)(sh2)->sr >> 12)\r
+# define sh2_pc(c) (c) ? ssh2.pc : msh2.pc\r
#endif\r
\r
-//#define sh2_pc(c) (c) ? ssh2.ppc : msh2.ppc\r
-#define sh2_pc(c) (c) ? ssh2.pc : msh2.pc\r
+#define sh2_cycles_done(sh2) ((int)(sh2)->cycles_timeslice - sh2_cycles_left(sh2))\r
+#define sh2_cycles_done_m68k(sh2) \\r
+ ((sh2)->m68krcycles_done + (sh2_cycles_done(sh2) / 3))\r
+\r
#define sh2_reg(c, x) (c) ? ssh2.r[x] : msh2.r[x]\r
#define sh2_gbr(c) (c) ? ssh2.gbr : msh2.gbr\r
#define sh2_vbr(c) (c) ? ssh2.vbr : msh2.vbr\r
-#define sh2_sr(c) (c) ? ssh2.sr : msh2.sr\r
+#define sh2_sr(c) (((c) ? ssh2.sr : msh2.sr) & 0xfff)\r
\r
#define sh2_set_gbr(c, v) \\r
{ if (c) ssh2.gbr = v; else msh2.gbr = v; }\r
unsigned int frame_count; // 1c for movies and idle det\r
};\r
\r
+struct PicoMS\r
+{\r
+ unsigned char carthw[0x10];\r
+ unsigned char io_ctl;\r
+ unsigned char pad[0x4f];\r
+};\r
+\r
// some assembly stuff depend on these, do not touch!\r
struct Pico\r
{\r
unsigned char vramb[0x4000]; // VRAM in SMS mode\r
};\r
unsigned char zram[0x2000]; // 0x20000 Z80 ram\r
- unsigned char ioports[0x10];\r
- unsigned char sms_io_ctl;\r
- unsigned char pad[0xef]; // unused\r
+ unsigned char ioports[0x10]; // XXX: fix asm and mv\r
+ unsigned char pad[0xf0]; // unused\r
unsigned short cram[0x40]; // 0x22100\r
unsigned short vsram[0x40]; // 0x22180\r
\r
\r
struct PicoMisc m;\r
struct PicoVideo video;\r
+ struct PicoMS ms;\r
};\r
\r
// sram\r
#define P32XV_PRI (1<< 7)\r
#define P32XV_Mx (3<< 0) // display mode mask\r
\r
+#define P32XV_SFT (1<< 0)\r
+\r
#define P32XV_VBLK (1<<15)\r
#define P32XV_HBLK (1<<14)\r
#define P32XV_PEN (1<<13)\r
#define P32XP_FULL (1<<15) // PWM\r
#define P32XP_EMPTY (1<<14)\r
\r
-#define P32XF_68KPOLL (1 << 0)\r
-#define P32XF_MSH2POLL (1 << 1)\r
-#define P32XF_SSH2POLL (1 << 2)\r
-#define P32XF_68KVPOLL (1 << 3)\r
-#define P32XF_MSH2VPOLL (1 << 4)\r
-#define P32XF_SSH2VPOLL (1 << 5)\r
+#define P32XF_68KCPOLL (1 << 0)\r
+#define P32XF_68KVPOLL (1 << 1)\r
+#define P32XF_PWM_PEND (1 << 6)\r
\r
#define P32XI_VRES (1 << 14/2) // IRL/2\r
#define P32XI_VINT (1 << 12/2)\r
#define DMAC_FIFO_LEN (4*4)\r
#define PWM_BUFF_LEN 1024 // in one channel samples\r
\r
+#define SH2_DRCBLK_RAM_SHIFT 1\r
+#define SH2_DRCBLK_DA_SHIFT 1\r
+\r
+#define SH2_WRITE_SHIFT 25\r
+\r
struct Pico32x\r
{\r
unsigned short regs[0x20];\r
- unsigned short vdp_regs[0x10];\r
- unsigned short sh2_regs[3];\r
+ unsigned short vdp_regs[0x10]; // 0x40\r
+ unsigned short sh2_regs[3]; // 0x60\r
unsigned char pending_fb;\r
unsigned char dirty_pal;\r
unsigned int emu_flags;\r
unsigned short dmac_fifo[DMAC_FIFO_LEN];\r
unsigned int dmac_ptr;\r
unsigned int pwm_irq_sample_cnt;\r
+ unsigned char comm_dirty_68k;\r
+ unsigned char comm_dirty_sh2;\r
+ unsigned short pad;\r
+ unsigned int reserved[8];\r
};\r
\r
struct Pico32xMem\r
{\r
unsigned char sdram[0x40000];\r
+#ifdef DRC_SH2\r
+ unsigned short drcblk_ram[1 << (18 - SH2_DRCBLK_RAM_SHIFT)];\r
+#endif\r
unsigned short dram[2][0x20000/2]; // AKA fb\r
- unsigned char m68k_rom[0x10000]; // 0x100; using M68K_BANK_SIZE\r
+ union {\r
+ unsigned char m68k_rom[0x100];\r
+ unsigned char m68k_rom_bank[0x10000]; // M68K_BANK_SIZE\r
+ };\r
unsigned char data_array[2][0x1000]; // cache in SH2s (can be used as RAM)\r
+#ifdef DRC_SH2\r
+ unsigned short drcblk_da[2][1 << (12 - SH2_DRCBLK_DA_SHIFT)];\r
+#endif\r
unsigned char sh2_rom_m[0x800];\r
unsigned char sh2_rom_s[0x400];\r
unsigned short pal[0x100];\r
};\r
\r
// area.c\r
-PICO_INTERNAL void PicoAreaPackCpu(unsigned char *cpu, int is_sub);\r
-PICO_INTERNAL void PicoAreaUnpackCpu(unsigned char *cpu, int is_sub);\r
extern void (*PicoLoadStateHook)(void);\r
\r
-// cd/area.c\r
-PICO_INTERNAL int PicoCdSaveState(void *file);\r
-PICO_INTERNAL int PicoCdLoadState(void *file);\r
-\r
typedef struct {\r
int chunk;\r
int size;\r
extern carthw_state_chunk *carthw_chunks;\r
#define CHUNK_CARTHW 64\r
\r
-// area.c\r
-typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file);\r
-typedef size_t (areaeof)(void *file);\r
-typedef int (areaseek)(void *file, long offset, int whence);\r
-typedef int (areaclose)(void *file);\r
-extern arearw *areaRead; // external read and write function pointers for\r
-extern arearw *areaWrite; // gzip save state ability\r
-extern areaeof *areaEof;\r
-extern areaseek *areaSeek;\r
-extern areaclose *areaClose;\r
-\r
// cart.c\r
-void Byteswap(void *dst, const void *src, int len);\r
+extern int PicoCartResize(int newsize);\r
+extern void Byteswap(void *dst, const void *src, int len);\r
extern void (*PicoCartMemSetup)(void);\r
extern void (*PicoCartUnloadHook)(void);\r
\r
PICO_INTERNAL void PicoFrameStart(void);\r
void PicoDrawSync(int to, int blank_last_line);\r
void BackFill(int reg7, int sh);\r
-void FinalizeLineRGB555(int sh, int line);\r
+void FinalizeLine555(int sh, int line);\r
+extern int (*PicoScanBegin)(unsigned int num);\r
+extern int (*PicoScanEnd)(unsigned int num);\r
extern int DrawScanline;\r
#define MAX_LINE_SPRITES 29\r
extern unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES];\r
+extern void *DrawLineDestBase;\r
+extern int DrawLineDestIncrement;\r
\r
// draw2.c\r
PICO_INTERNAL void PicoFrameFull();\r
void PicoFrameStartMode4(void);\r
void PicoLineMode4(int line);\r
void PicoDoHighPal555M4(void);\r
-void PicoDrawSetColorFormatMode4(int which);\r
+void PicoDrawSetOutputMode4(pdso_t which);\r
\r
// memory.c\r
PICO_INTERNAL void PicoMemSetup(void);\r
PICO_INTERNAL int SekReset(void);\r
PICO_INTERNAL void SekState(int *data);\r
PICO_INTERNAL void SekSetRealTAS(int use_real);\r
+PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub);\r
+PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub);\r
void SekStepM68k(void);\r
void SekInitIdleDet(void);\r
void SekFinishIdleDet(void);\r
\r
// z80 functionality wrappers\r
PICO_INTERNAL void z80_init(void);\r
-PICO_INTERNAL void z80_pack(unsigned char *data);\r
-PICO_INTERNAL void z80_unpack(unsigned char *data);\r
+PICO_INTERNAL void z80_pack(void *data);\r
+PICO_INTERNAL int z80_unpack(const void *data);\r
PICO_INTERNAL void z80_reset(void);\r
PICO_INTERNAL void z80_exit(void);\r
\r
extern int PsndDacLine;\r
\r
// sms.c\r
+#ifndef NO_SMS\r
void PicoPowerMS(void);\r
void PicoResetMS(void);\r
void PicoMemSetupMS(void);\r
+void PicoStateLoadedMS(void);\r
void PicoFrameMS(void);\r
void PicoFrameDrawOnlyMS(void);\r
+#else\r
+#define PicoPowerMS()\r
+#define PicoResetMS()\r
+#define PicoMemSetupMS()\r
+#define PicoStateLoadedMS()\r
+#define PicoFrameMS()\r
+#define PicoFrameDrawOnlyMS()\r
+#endif\r
\r
// 32x/32x.c\r
+#ifndef NO_32X\r
extern struct Pico32x Pico32x;\r
+enum p32x_event {\r
+ P32X_EVENT_PWM,\r
+ P32X_EVENT_FILLEND,\r
+ P32X_EVENT_COUNT,\r
+};\r
+extern unsigned int event_times[P32X_EVENT_COUNT];\r
+\r
void Pico32xInit(void);\r
void PicoPower32x(void);\r
void PicoReset32x(void);\r
void Pico32xStartup(void);\r
void PicoUnload32x(void);\r
void PicoFrame32x(void);\r
-void p32x_update_irls(void);\r
+void Pico32xStateLoaded(int is_early);\r
+void p32x_sync_sh2s(unsigned int m68k_target);\r
+void p32x_sync_other_sh2(SH2 *sh2, unsigned int m68k_target);\r
+void p32x_update_irls(SH2 *active_sh2);\r
void p32x_reset_sh2s(void);\r
+void p32x_event_schedule(unsigned int now, enum p32x_event event, int after);\r
+void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after);\r
\r
// 32x/memory.c\r
struct Pico32xMem *Pico32xMem;\r
void PicoWrite16_32x(unsigned int a, unsigned int d);\r
void PicoMemSetup32x(void);\r
void Pico32xSwapDRAM(int b);\r
-void p32x_poll_event(int cpu_mask, int is_vdp);\r
+void Pico32xMemStateLoaded(void);\r
+void p32x_m68k_poll_event(unsigned int flags);\r
+void p32x_sh2_poll_event(SH2 *sh2, unsigned int flags, unsigned int m68k_cycles);\r
\r
// 32x/draw.c\r
+void PicoDrawSetOutFormat32x(pdso_t which, int use_32x_line_mode);\r
void FinalizeLine32xRGB555(int sh, int line);\r
+void PicoDraw32xLayer(int offs, int lines, int mdbg);\r
+void PicoDraw32xLayerMdOnly(int offs, int lines);\r
+extern int (*PicoScan32xBegin)(unsigned int num);\r
+extern int (*PicoScan32xEnd)(unsigned int num);\r
+enum {\r
+ PDM32X_OFF,\r
+ PDM32X_32X_ONLY,\r
+ PDM32X_BOTH,\r
+};\r
+extern int Pico32xDrawMode;\r
\r
// 32x/pwm.c\r
unsigned int p32x_pwm_read16(unsigned int a);\r
void p32x_pwm_write16(unsigned int a, unsigned int d);\r
void p32x_pwm_update(int *buf32, int length, int stereo);\r
-void p32x_timers_do(int new_line);\r
+void p32x_timers_do(unsigned int cycles);\r
void p32x_timers_recalc(void);\r
-extern int pwm_frame_smp_cnt;\r
+void p32x_pwm_schedule(unsigned int now);\r
+void p32x_pwm_schedule_sh2(SH2 *sh2);\r
+#else\r
+#define Pico32xInit()\r
+#define PicoPower32x()\r
+#define PicoReset32x()\r
+#define PicoFrame32x()\r
+#define PicoUnload32x()\r
+#define Pico32xStateLoaded()\r
+#define FinalizeLine32xRGB555 NULL\r
+#define p32x_pwm_update(...)\r
+#define p32x_timers_recalc()\r
+#endif\r
\r
/* avoid dependency on newer glibc */\r
static __inline int isspace_(int c)\r
return (0x09 <= c && c <= 0x0d) || c == ' ';\r
}\r
\r
+#ifndef ARRAY_SIZE\r
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))\r
+#endif\r
+\r
// emulation event logging\r
#ifndef EL_LOGMASK\r
-#define EL_LOGMASK 0\r
+# ifdef __x86_64__ // HACK\r
+# define EL_LOGMASK (EL_STATUS|EL_IDLE|EL_ANOMALY)\r
+# else\r
+# define EL_LOGMASK (EL_STATUS|EL_IDLE)\r
+# endif\r
#endif\r
\r
#define EL_HVCNT 0x00000001 /* hv counter reads */\r
#define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */\r
\r
#if EL_LOGMASK\r
-extern void lprintf(const char *fmt, ...);\r
#define elprintf(w,f,...) \\r
-{ \\r
+do { \\r
if ((w) & EL_LOGMASK) \\r
lprintf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__); \\r
-}\r
+} while (0)\r
#elif defined(_MSC_VER)\r
#define elprintf\r
#else\r
#define elprintf(w,f,...)\r
#endif\r
\r
+// profiling\r
+#ifdef PPROF\r
+#include <platform/linux/pprof.h>\r
+#else\r
+#define pprof_init()\r
+#define pprof_finish()\r
+#define pprof_start(x)\r
+#define pprof_end(...)\r
+#define pprof_end_sub(...)\r
+#endif\r
+\r
+#ifdef EVT_LOG\r
+enum evt {\r
+ EVT_FRAME_START,\r
+ EVT_NEXT_LINE,\r
+ EVT_RUN_START,\r
+ EVT_RUN_END,\r
+ EVT_POLL_START,\r
+ EVT_POLL_END,\r
+ EVT_CNT\r
+};\r
+\r
+enum evt_cpu {\r
+ EVT_M68K,\r
+ EVT_S68K,\r
+ EVT_MSH2,\r
+ EVT_SSH2,\r
+ EVT_CPU_CNT\r
+};\r
+\r
+void pevt_log(unsigned int cycles, enum evt_cpu c, enum evt e);\r
+void pevt_dump(void);\r
+\r
+#define pevt_log_m68k(e) \\r
+ pevt_log(SekCyclesDoneT(), EVT_M68K, e)\r
+#define pevt_log_m68k_o(e) \\r
+ pevt_log(SekCyclesDoneT2(), EVT_M68K, e)\r
+#define pevt_log_sh2(sh2, e) \\r
+ pevt_log(sh2_cycles_done_m68k(sh2), EVT_MSH2 + (sh2)->is_slave, e)\r
+#define pevt_log_sh2_o(sh2, e) \\r
+ pevt_log((sh2)->m68krcycles_done, EVT_MSH2 + (sh2)->is_slave, e)\r
+#else\r
+#define pevt_log(c, e)\r
+#define pevt_log_m68k(e)\r
+#define pevt_log_m68k_o(e)\r
+#define pevt_log_sh2(sh2, e)\r
+#define pevt_log_sh2_o(sh2, e)\r
+#define pevt_dump()\r
+#endif\r
+\r
+// misc\r
#ifdef _MSC_VER\r
#define cdprintf\r
#else\r
#define cdprintf(x...)\r
#endif\r
\r
-#if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3\r
-#define MEMH_FUNC __attribute__((aligned(4)))\r
+#ifdef __i386__\r
+#define REGPARM(x) __attribute__((regparm(x)))\r
#else\r
-#define MEMH_FUNC\r
+#define REGPARM(x)\r
#endif\r
\r
#ifdef __GNUC__\r