FAME + some random stuff added
[picodrive.git] / Pico / PicoInt.h
index f495bb6..a6fceff 100644 (file)
@@ -24,7 +24,7 @@
 #define PICO_INTERNAL_ASM\r
 #endif\r
 \r
-// to select core, define EMU_C68K, EMU_M68K or EMU_A68K in your makefile or project\r
+// to select core, define EMU_C68K, EMU_M68K or EMU_F68K in your makefile or project\r
 \r
 #ifdef __cplusplus\r
 extern "C" {\r
@@ -50,24 +50,28 @@ extern struct Cyclone PicoCpu, PicoCpuS68k;
 #define SekSetStopS68k(x) { PicoCpuS68k.state_flags&=~1; if (x) { PicoCpuS68k.state_flags|=1; PicoCpuS68k.cycles=0; } }\r
 #endif\r
 \r
-#ifdef EMU_A68K\r
-void __cdecl M68000_RUN();\r
-// The format of the data in a68k.asm (at the _M68000_regs location)\r
-struct A68KContext\r
-{\r
-  unsigned int d[8],a[8];\r
-  unsigned int isp,srh,ccr,xc,pc,irq,sr;\r
-  int (*IrqCallback) (int nIrq);\r
-  unsigned int ppc;\r
-  void *pResetCallback;\r
-  unsigned int sfc,dfc,usp,vbr;\r
-  unsigned int AsmBank,CpuVersion;\r
-};\r
-struct A68KContext M68000_regs;\r
-extern int m68k_ICount;\r
-#define SekCyclesLeft m68k_ICount\r
-#define SekSetCyclesLeft(c) m68k_ICount=c\r
-#define SekPc M68000_regs.pc\r
+#ifdef EMU_F68K\r
+#include "../cpu/fame/fame.h"\r
+M68K_CONTEXT PicoCpuM68k, PicoCpuS68k;\r
+#define SekCyclesLeftNoMCD PicoCpuM68k.io_cycle_counter\r
+#define SekCyclesLeft \\r
+       (((PicoMCD&1) && (PicoOpt & 0x2000)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)\r
+#define SekCyclesLeftS68k \\r
+       ((PicoOpt & 0x2000) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuS68k.io_cycle_counter)\r
+#define SekSetCyclesLeftNoMCD(c) PicoCpuM68k.io_cycle_counter=c\r
+#define SekSetCyclesLeft(c) { \\r
+       if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCycleCnt=SekCycleAim-(c); else SekSetCyclesLeftNoMCD(c); \\r
+}\r
+#define SekPc     m68k_get_pc(&PicoCpuM68k)\r
+#define SekPcS68k m68k_get_pc(&PicoCpuS68k)\r
+#define SekSetStop(x) { \\r
+       PicoCpuM68k.execinfo &= ~M68K_HALTED; \\r
+       if (x) { PicoCpuM68k.execinfo |= M68K_HALTED; PicoCpuM68k.io_cycle_counter = 0; } \\r
+}\r
+#define SekSetStopS68k(x) { \\r
+       PicoCpuS68k.execinfo &= ~M68K_HALTED; \\r
+       if (x) { PicoCpuS68k.execinfo |= M68K_HALTED; PicoCpuS68k.io_cycle_counter = 0; } \\r
+}\r
 #endif\r
 \r
 #ifdef EMU_M68K\r
@@ -101,7 +105,11 @@ extern int SekCycleCnt; // cycles done in this frame
 extern int SekCycleAim; // cycle aim\r
 extern unsigned int SekCycleCntT; // total cycle counter, updated once per frame\r
 \r
-#define SekCyclesReset() {SekCycleCntT+=SekCycleCnt;SekCycleCnt=SekCycleAim=0;}\r
+#define SekCyclesReset() { \\r
+       SekCycleCntT+=SekCycleAim; \\r
+       SekCycleCnt-=SekCycleAim; \\r
+       SekCycleAim=0; \\r
+}\r
 #define SekCyclesBurn(c)  SekCycleCnt+=c\r
 #define SekCyclesDone()  (SekCycleAim-SekCyclesLeft)    // nuber of cycles done in this frame (can be checked anywhere)\r
 #define SekCyclesDoneT() (SekCycleCntT+SekCyclesDone()) // total nuber of cycles done for this rom\r
@@ -115,7 +123,10 @@ extern unsigned int SekCycleCntT; // total cycle counter, updated once per frame
 extern int SekCycleCntS68k;\r
 extern int SekCycleAimS68k;\r
 \r
-#define SekCyclesResetS68k() {SekCycleCntS68k=SekCycleAimS68k=0;}\r
+#define SekCyclesResetS68k() { \\r
+       SekCycleCntS68k-=SekCycleAimS68k; \\r
+       SekCycleAimS68k=0; \\r
+}\r
 #define SekCyclesDoneS68k()  (SekCycleAimS68k-SekCyclesLeftS68k)\r
 \r
 // debug cyclone\r
@@ -130,46 +141,48 @@ extern int SekCycleAimS68k;
 #define SekEndRun(c)\r
 #endif\r
 \r
-extern int PicoMCD;\r
-\r
 // ---------------------------------------------------------\r
 \r
+extern int PicoMCD;\r
+\r
 // main oscillator clock which controls timing\r
 #define OSC_NTSC 53693100\r
-#define OSC_PAL  53203424 // not accurate\r
+// seems to be accurate, see scans from http://www.hot.ee/tmeeco/\r
+#define OSC_PAL  53203424\r
 \r
 struct PicoVideo\r
 {\r
   unsigned char reg[0x20];\r
-  unsigned int command; // 32-bit Command\r
-  unsigned char pending; // 1 if waiting for second half of 32-bit command\r
-  unsigned char type; // Command type (v/c/vsram read/write)\r
-  unsigned short addr; // Read/Write address\r
-  int status; // Status bits\r
+  unsigned int command;       // 32-bit Command\r
+  unsigned char pending;      // 1 if waiting for second half of 32-bit command\r
+  unsigned char type;         // Command type (v/c/vsram read/write)\r
+  unsigned short addr;        // Read/Write address\r
+  int status;                 // Status bits\r
   unsigned char pending_ints; // pending interrupts: ??VH????\r
-  unsigned char pad[0x13];\r
+  signed char lwrite_cnt;     // VDP write count during active display line\r
+  unsigned char pad[0x12];\r
 };\r
 \r
 struct PicoMisc\r
 {\r
   unsigned char rotate;\r
   unsigned char z80Run;\r
-  unsigned char padTHPhase[2]; // phase of gamepad TH switches\r
-  short scanline; // 0 to 261||311; -1 in fast mode\r
-  char dirtyPal; // Is the palette dirty (1 - change @ this frame, 2 - some time before)\r
-  unsigned char hardware; // Hardware value for country\r
-  unsigned char pal; // 1=PAL 0=NTSC\r
-  unsigned char sram_reg; // SRAM mode register. bit0: allow read? bit1: deny write? bit2: EEPROM? bit4: detected? (header or by access)\r
-  unsigned short z80_bank68k;\r
+  unsigned char padTHPhase[2]; // 02 phase of gamepad TH switches\r
+  short scanline;              // 04 0 to 261||311; -1 in fast mode\r
+  char dirtyPal;               // 06 Is the palette dirty (1 - change @ this frame, 2 - some time before)\r
+  unsigned char hardware;      // 07 Hardware value for country\r
+  unsigned char pal;           // 08 1=PAL 0=NTSC\r
+  unsigned char sram_reg;      // SRAM mode register. bit0: allow read? bit1: deny write? bit2: EEPROM? bit4: detected? (header or by access)\r
+  unsigned short z80_bank68k;  // 0a\r
   unsigned short z80_lastaddr; // this is for Z80 faking\r
   unsigned char  z80_fakeval;\r
   unsigned char  pad0;\r
-  unsigned char  padDelay[2];  // gamepad phase time outs, so we count a delay\r
-  unsigned short sram_addr;  // EEPROM address register\r
-  unsigned char sram_cycle;  // EEPROM SRAM cycle number\r
-  unsigned char sram_slave;  // EEPROM slave word for X24C02 and better SRAMs\r
+  unsigned char  padDelay[2];  // 10 gamepad phase time outs, so we count a delay\r
+  unsigned short eeprom_addr;  // EEPROM address register\r
+  unsigned char  eeprom_cycle; // EEPROM SRAM cycle number\r
+  unsigned char  eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs\r
   unsigned char prot_bytes[2]; // simple protection faking\r
-  unsigned short dma_bytes;  //\r
+  unsigned short dma_xfers;\r
   unsigned char pad[2];\r
   unsigned int  frame_count; // mainly for movies\r
 };\r
@@ -198,10 +211,14 @@ struct PicoSRAM
   unsigned char *data;         // actual data\r
   unsigned int start;          // start address in 68k address space\r
   unsigned int end;\r
-  unsigned char resize;                // 0c: 1=SRAM size changed and needs to be reallocated on PicoReset\r
-  unsigned char reg_back;      // copy of Pico.m.sram_reg to set after reset\r
+  unsigned char unused1;       // 0c: unused\r
+  unsigned char unused2;\r
   unsigned char changed;\r
-  unsigned char pad;\r
+  unsigned char eeprom_type;    // eeprom type: 0: 7bit (24C01), 2: device with 2 addr words (X24C02+), 3: dev with 3 addr words\r
+  unsigned char eeprom_abits;  // eeprom access must be odd addr for: bit0 ~ cl, bit1 ~ out\r
+  unsigned char eeprom_bit_cl; // bit number for cl\r
+  unsigned char eeprom_bit_in;  // bit number for in\r
+  unsigned char eeprom_bit_out; // bit number for out\r
 };\r
 \r
 // MCD\r
@@ -285,6 +302,9 @@ PICO_INTERNAL int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub);
 PICO_INTERNAL int PicoCdSaveState(void *file);\r
 PICO_INTERNAL int PicoCdLoadState(void *file);\r
 \r
+// Cart.c\r
+PICO_INTERNAL void PicoCartDetect(void);\r
+\r
 // Draw.c\r
 PICO_INTERNAL int PicoLine(int scan);\r
 PICO_INTERNAL void PicoFrameStart(void);\r
@@ -297,6 +317,7 @@ PICO_INTERNAL int PicoInitPc(unsigned int pc);
 PICO_INTERNAL_ASM unsigned int CPU_CALL PicoRead32(unsigned int a);\r
 PICO_INTERNAL void PicoMemSetup(void);\r
 PICO_INTERNAL_ASM void PicoMemReset(void);\r
+PICO_INTERNAL int PadRead(int i);\r
 PICO_INTERNAL unsigned char z80_read(unsigned short a);\r
 PICO_INTERNAL unsigned short z80_read16(unsigned short a);\r
 PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a);\r
@@ -315,7 +336,8 @@ extern int z80startCycle, z80stopCycle; // in 68k cycles
 PICO_INTERNAL int CheckDMA(void);\r
 \r
 // cd/Pico.c\r
-PICO_INTERNAL int PicoInitMCD(void);\r
+PICO_INTERNAL int  PicoInitMCD(void);\r
+PICO_INTERNAL void PicoExitMCD(void);\r
 PICO_INTERNAL int PicoResetMCD(int hard);\r
 PICO_INTERNAL int PicoFrameMCD(void);\r
 \r
@@ -375,5 +397,37 @@ PICO_INTERNAL void z80_exit(void);
 } // End of extern "C"\r
 #endif\r
 \r
+// emulation event logging\r
+#ifndef EL_LOGMASK\r
+#define EL_LOGMASK 0\r
+#endif\r
+\r
+#define EL_HVCNT   0x0001 /* hv counter reads */\r
+#define EL_SR      0x0002 /* SR reads */\r
+#define EL_INTS    0x0004 /* ints and acks */\r
+#define EL_YM2612R 0x0008 /* 68k ym2612 reads */\r
+#define EL_INTSW   0x0010 /* log irq switching on/off */\r
+#define EL_ASVDP   0x0020 /* VDP accesses during active scan */\r
+#define EL_VDPDMA  0x0040 /* VDP DMA transfers and their timing */\r
+#define EL_BUSREQ  0x0080 /* z80 busreq r/w or reset w */\r
+#define EL_Z80BNK  0x0100 /* z80 i/o through bank area */\r
+#define EL_SRAMIO  0x0200 /* sram i/o */\r
+#define EL_EEPROM  0x0400 /* eeprom debug */\r
+#define EL_UIO     0x0800 /* unmapped i/o */\r
+#define EL_IO      0x1000 /* all i/o (TODO) */\r
+\r
+#define EL_STATUS  0x4000 /* status messages */\r
+#define EL_ANOMALY 0x8000 /* some unexpected conditions */\r
+\r
+#if EL_LOGMASK\r
+#define elprintf(w,f,...) \\r
+{ \\r
+       if ((w) & EL_LOGMASK) \\r
+               printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__); \\r
+}\r
+#else\r
+#define elprintf(w,f,...)\r
+#endif\r
+\r
 #endif // PICO_INTERNAL_INCLUDED\r
 \r