rearrange globals
[picodrive.git] / pico / pico_int.h
index 89cccc7..fa7979c 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
+#include "pico_port.h"\r
 #include "pico.h"\r
 #include "carthw/carthw.h"\r
 \r
@@ -80,7 +81,7 @@ extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k;
 }\r
 #define SekIsStoppedM68k() (PicoCpuFM68k.execinfo&FM68K_HALTED)\r
 #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED)\r
-#define SekShouldInterrupt() fm68k_would_interrupt()\r
+#define SekShouldInterrupt() fm68k_would_interrupt(&PicoCpuFM68k)\r
 \r
 #define SekNotPolling     PicoCpuFM68k.not_polling\r
 #define SekNotPollingS68k PicoCpuFS68k.not_polling\r
@@ -117,37 +118,25 @@ extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k;
 #define SekNotPolling     PicoCpuMM68k.not_polling\r
 #define SekNotPollingS68k PicoCpuMS68k.not_polling\r
 \r
-#define SekInterrupt(irq) { \\r
-       void *oldcontext = m68ki_cpu_p; \\r
-       m68k_set_context(&PicoCpuMM68k); \\r
-       m68k_set_irq(irq); \\r
-       m68k_set_context(oldcontext); \\r
-}\r
-#define SekIrqLevel (PicoCpuMM68k.int_level >> 8)\r
+// avoid m68k_set_irq() for delaying to work\r
+#define SekInterrupt(irq)  PicoCpuMM68k.int_level = (irq) << 8\r
+#define SekIrqLevel        (PicoCpuMM68k.int_level >> 8)\r
 \r
 #endif\r
 #endif // EMU_M68K\r
 \r
-// while running, cnt represents target of current timeslice\r
-// while not in SekRun(), it's actual cycles done\r
-// (but always use SekCyclesDone() if you need current position)\r
-// cnt may change if timeslice is ended prematurely or extended,\r
-// so we use SekCycleAim for the actual target\r
-extern unsigned int SekCycleCnt;\r
-extern unsigned int SekCycleAim;\r
-\r
 // number of cycles done (can be checked anywhere)\r
-#define SekCyclesDone()  (SekCycleCnt - SekCyclesLeft)\r
+#define SekCyclesDone()  (Pico.t.m68c_cnt - SekCyclesLeft)\r
 \r
 // burn cycles while not in SekRun() and while in\r
-#define SekCyclesBurn(c)    SekCycleCnt += c\r
+#define SekCyclesBurn(c)    Pico.t.m68c_cnt += c\r
 #define SekCyclesBurnRun(c) { \\r
   SekCyclesLeft -= c; \\r
 }\r
 \r
 // note: sometimes may extend timeslice to delay an irq\r
 #define SekEndRun(after) { \\r
-  SekCycleCnt -= SekCyclesLeft - (after); \\r
+  Pico.t.m68c_cnt -= SekCyclesLeft - (after); \\r
   SekCyclesLeft = after; \\r
 }\r
 \r
@@ -212,10 +201,10 @@ extern struct DrZ80 drZ80;
 #define Z80_STATE_SIZE 0x60\r
 \r
 #define z80_resetCycles() \\r
-  timing.z80c_cnt = timing.z80c_aim = timing.z80_scanline = 0\r
+  Pico.t.z80c_cnt = Pico.t.z80c_aim = Pico.t.z80_scanline = 0\r
 \r
 #define z80_cyclesDone() \\r
-  (timing.z80c_aim - z80_cyclesLeft)\r
+  (Pico.t.z80c_aim - z80_cyclesLeft)\r
 \r
 #define cycles_68k_to_z80(x) ((x) * 3823 >> 13)\r
 \r
@@ -299,6 +288,7 @@ extern SH2 sh2s[2];
 #define SR_EMPT       (1 << 9)\r
 // not part of real SR\r
 #define PVS_ACTIVE    (1 << 16)\r
+#define PVS_VB2       (1 << 17) // ignores forced blanking\r
 \r
 struct PicoVideo\r
 {\r
@@ -337,7 +327,7 @@ struct PicoMisc
   unsigned char  eeprom_cycle; // EEPROM cycle number\r
   unsigned char  eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs\r
   unsigned char  eeprom_status;\r
-  unsigned char  pad2;\r
+  unsigned char  status;       // rapid_ym2612, multi_ym_updates\r
   unsigned short dma_xfers;    // 18\r
   unsigned char  eeprom_wb[2]; // EEPROM latch/write buffer\r
   unsigned int  frame_count;   // 1c for movies and idle det\r
@@ -359,15 +349,15 @@ struct PicoEState
   void *DrawLineDest;          // draw destination\r
   unsigned char *HighCol;\r
   int *HighPreSpr;\r
-  void *Pico_video;\r
-  void *Pico_vram;\r
-  int  *PicoOpt;\r
+  struct Pico *Pico;\r
+  void *PicoMem_vram;\r
+  void *PicoMem_cram;\r
+  unsigned int  *PicoOpt;\r
   unsigned char *Draw2FB;\r
   unsigned short HighPal[0x100];\r
 };\r
 \r
-// some assembly stuff depend on these, do not touch!\r
-struct Pico\r
+struct PicoMem\r
 {\r
   unsigned char ram[0x10000];  // 0x00000 scratch ram\r
   union {                      // vram is byteswapped for easier reads when drawing\r
@@ -376,17 +366,9 @@ struct Pico
   };\r
   unsigned char zram[0x2000];  // 0x20000 Z80 ram\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
-  unsigned char *rom;          // 0x22200\r
-  unsigned int romsize;        // 0x22204 (on 32bits)\r
-\r
-  struct PicoMisc m;\r
-  struct PicoVideo video;\r
-  struct PicoMS ms;\r
-  struct PicoEState est;\r
+  unsigned short cram[0x40];   // 0x22010\r
+  unsigned char pad[0x70];     // 0x22050 DrawStripVSRam reads 0 from here\r
+  unsigned short vsram[0x40];  // 0x22100\r
 };\r
 \r
 // sram\r
@@ -396,7 +378,7 @@ struct Pico
 #define SRF_ENABLED  (1 << 0)\r
 #define SRF_EEPROM   (1 << 1)\r
 \r
-struct PicoSRAM\r
+struct PicoCartSave\r
 {\r
   unsigned char *data;         // actual data\r
   unsigned int start;          // start address in 68k address space\r
@@ -412,6 +394,38 @@ struct PicoSRAM
   unsigned int size;\r
 };\r
 \r
+struct PicoTiming\r
+{\r
+  // while running, cnt represents target of current timeslice\r
+  // while not in SekRun(), it's actual cycles done\r
+  // (but always use SekCyclesDone() if you need current position)\r
+  // _cnt may change if timeslice is ended prematurely or extended,\r
+  // so we use _aim for the actual target\r
+  unsigned int m68c_cnt;\r
+  unsigned int m68c_aim;\r
+  unsigned int m68c_frame_start;        // m68k cycles\r
+  unsigned int m68c_line_start;\r
+\r
+  unsigned int z80c_cnt;                // z80 cycles done (this frame)\r
+  unsigned int z80c_aim;\r
+  int z80_scanline;\r
+};\r
+\r
+// run tools/mkoffsets pico/pico_int_o32.h if you change these\r
+// careful with savestate compat\r
+struct Pico\r
+{\r
+  struct PicoVideo video;\r
+  struct PicoMisc m;\r
+  struct PicoTiming t;\r
+  struct PicoCartSave sv;\r
+  struct PicoEState est;\r
+  struct PicoMS ms;\r
+\r
+  unsigned char *rom;\r
+  unsigned int romsize;\r
+};\r
+\r
 // MCD\r
 #define PCM_MIXBUF_LEN ((12500000 / 384) / 50 + 1)\r
 \r
@@ -592,15 +606,6 @@ struct Pico32xMem
   unsigned short pwm_fifo[2][4];        // [0] - current raw, others - fifo entries\r
 };\r
 \r
-struct PicoTiming\r
-{\r
-  unsigned int m68c_frame_start;        // m68k cycles\r
-  unsigned int z80c_cnt;                // z80 cycles done (this frame)\r
-  unsigned int z80c_aim;\r
-  int z80_scanline;\r
-};\r
-extern struct PicoTiming timing;\r
-\r
 // area.c\r
 extern void (*PicoLoadStateHook)(void);\r
 \r
@@ -699,9 +704,7 @@ void pcd_state_loaded_mem(void);
 \r
 // pico.c\r
 extern struct Pico Pico;\r
-extern struct PicoSRAM SRam;\r
-extern int PicoPadInt[2];\r
-extern int emustatus;\r
+extern struct PicoMem PicoMem;\r
 extern void (*PicoResetHook)(void);\r
 extern void (*PicoLineHook)(void);\r
 PICO_INTERNAL int  CheckDMA(void);\r
@@ -809,7 +812,6 @@ void ym2612_unpack_state(void);
 \r
 \r
 // videoport.c\r
-extern int line_base_cycles;\r
 PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d);\r
 PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a);\r
 unsigned char PicoVideoRead8DataH(void);\r
@@ -821,9 +823,7 @@ unsigned char PicoVideoRead8HV_L(void);
 extern int (*PicoDmaHook)(unsigned int source, int len, unsigned short **base, unsigned int *mask);\r
 \r
 // misc.c\r
-PICO_INTERNAL_ASM void memcpy16(unsigned short *dest, unsigned short *src, int count);\r
 PICO_INTERNAL_ASM void memcpy16bswap(unsigned short *dest, void *src, int count);\r
-PICO_INTERNAL_ASM void memcpy32(void *dest, const void *src, int count); // 32bit word count\r
 PICO_INTERNAL_ASM void memset32(void *dest, int c, int count);\r
 \r
 // eeprom.c\r
@@ -898,7 +898,7 @@ void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after);
 void p32x_schedule_hint(SH2 *sh2, int m68k_cycles);\r
 \r
 // 32x/memory.c\r
-struct Pico32xMem *Pico32xMem;\r
+extern struct Pico32xMem *Pico32xMem;\r
 unsigned int PicoRead8_32x(unsigned int a);\r
 unsigned int PicoRead16_32x(unsigned int a);\r
 void PicoWrite8_32x(unsigned int a, unsigned int d);\r
@@ -1069,25 +1069,6 @@ void pevt_dump(void);
 #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__) && defined(__i386__)\r
-#define REGPARM(x) __attribute__((regparm(x)))\r
-#else\r
-#define REGPARM(x)\r
-#endif\r
-\r
-#ifdef __GNUC__\r
-#define NOINLINE __attribute__((noinline))\r
-#else\r
-#define NOINLINE\r
-#endif\r
-\r
 #ifdef __cplusplus\r
 } // End of extern "C"\r
 #endif\r