1.10 release
[picodrive.git] / Pico / PicoInt.h
1 // Pico Library - Header File\r
2 \r
3 // (c) Copyright 2004 Dave, All rights reserved.\r
4 // (c) Copyright 2006 notaz, All rights reserved.\r
5 // Free for non-commercial use.\r
6 \r
7 // For commercial use, separate licencing terms must be obtained.\r
8 \r
9 \r
10 #include <stdio.h>\r
11 #include <stdlib.h>\r
12 #include <string.h>\r
13 #include "Pico.h"\r
14 \r
15 \r
16 // to select core, define EMU_C68K, EMU_M68K or EMU_A68K in your makefile or project\r
17 \r
18 #ifdef __cplusplus\r
19 extern "C" {\r
20 #endif\r
21 \r
22 \r
23 // ----------------------- 68000 CPU -----------------------\r
24 #ifdef EMU_C68K\r
25 #include "../cpu/Cyclone/Cyclone.h"\r
26 extern struct Cyclone PicoCpu, PicoCpuS68k;\r
27 #define SekCyclesLeft PicoCpu.cycles // cycles left for this run\r
28 #define SekSetCyclesLeft(c) PicoCpu.cycles=c\r
29 #define SekPc (PicoCpu.pc-PicoCpu.membase)\r
30 #define SekPcS68k (PicoCpuS68k.pc-PicoCpuS68k.membase)\r
31 #endif\r
32 \r
33 #ifdef EMU_A68K\r
34 void __cdecl M68000_RUN();\r
35 // The format of the data in a68k.asm (at the _M68000_regs location)\r
36 struct A68KContext\r
37 {\r
38   unsigned int d[8],a[8];\r
39   unsigned int isp,srh,ccr,xc,pc,irq,sr;\r
40   int (*IrqCallback) (int nIrq);\r
41   unsigned int ppc;\r
42   void *pResetCallback;\r
43   unsigned int sfc,dfc,usp,vbr;\r
44   unsigned int AsmBank,CpuVersion;\r
45 };\r
46 struct A68KContext M68000_regs;\r
47 extern int m68k_ICount;\r
48 #define SekCyclesLeft m68k_ICount\r
49 #define SekSetCyclesLeft(c) m68k_ICount=c\r
50 #define SekPc M68000_regs.pc\r
51 #endif\r
52 \r
53 #ifdef EMU_M68K\r
54 #include "../cpu/musashi/m68kcpu.h"\r
55 extern m68ki_cpu_core PicoM68kCPU; // MD's CPU\r
56 extern m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU\r
57 #ifndef SekCyclesLeft\r
58 #define SekCyclesLeft m68k_cycles_remaining()\r
59 #define SekSetCyclesLeft(c) SET_CYCLES(c)\r
60 #define SekPc m68k_get_reg(&PicoM68kCPU, M68K_REG_PC)\r
61 #define SekPcS68k m68k_get_reg(&PicoS68kCPU, M68K_REG_PC)\r
62 #endif\r
63 #endif\r
64 \r
65 extern int SekCycleCnt; // cycles done in this frame\r
66 extern int SekCycleAim; // cycle aim\r
67 extern unsigned int SekCycleCntT; // total cycle counter, updated once per frame\r
68 \r
69 #define SekCyclesReset() {SekCycleCntT+=SekCycleCnt;SekCycleCnt=SekCycleAim=0;}\r
70 #define SekCyclesBurn(c)  SekCycleCnt+=c\r
71 #define SekCyclesDone()  (SekCycleAim-SekCyclesLeft)    // nuber of cycles done in this frame (can be checked anywhere)\r
72 #define SekCyclesDoneT() (SekCycleCntT+SekCyclesDone()) // total nuber of cycles done for this rom\r
73 \r
74 #define SekEndRun(after) { \\r
75         SekCycleCnt -= SekCyclesLeft - after; \\r
76         if(SekCycleCnt < 0) SekCycleCnt = 0; \\r
77         SekSetCyclesLeft(after); \\r
78 }\r
79 \r
80 extern int SekCycleCntS68k;\r
81 extern int SekCycleAimS68k;\r
82 \r
83 #define SekCyclesResetS68k() {SekCycleCntS68k=SekCycleAimS68k=0;}\r
84 \r
85 // does not work as expected\r
86 //extern int z80ExtraCycles; // extra z80 cycles, used when z80 is [en|dis]abled\r
87 \r
88 extern int PicoMCD;\r
89 \r
90 // ---------------------------------------------------------\r
91 \r
92 // main oscillator clock which controls timing\r
93 #define OSC_NTSC 53693100\r
94 #define OSC_PAL  53203424 // not accurate\r
95 \r
96 struct PicoVideo\r
97 {\r
98   unsigned char reg[0x20];\r
99   unsigned int command; // 32-bit Command\r
100   unsigned char pending; // 1 if waiting for second half of 32-bit command\r
101   unsigned char type; // Command type (v/c/vsram read/write)\r
102   unsigned short addr; // Read/Write address\r
103   int status; // Status bits\r
104   unsigned char pending_ints; // pending interrupts: ??VH????\r
105   unsigned char pad[0x13];\r
106 };\r
107 \r
108 struct PicoMisc\r
109 {\r
110   unsigned char rotate;\r
111   unsigned char z80Run;\r
112   unsigned char padTHPhase[2]; // phase of gamepad TH switches\r
113   short scanline; // 0 to 261||311; -1 in fast mode\r
114   char dirtyPal; // Is the palette dirty (1 - change @ this frame, 2 - some time before)\r
115   unsigned char hardware; // Hardware value for country\r
116   unsigned char pal; // 1=PAL 0=NTSC\r
117   unsigned char sram_reg; // SRAM mode register. bit0: allow read? bit1: deny write? bit2: EEPROM?\r
118   unsigned short z80_bank68k;\r
119   unsigned short z80_lastaddr; // this is for Z80 faking\r
120   unsigned char  z80_fakeval;\r
121   unsigned char  pad0;\r
122   unsigned char  padDelay[2];  // gamepad phase time outs, so we count a delay\r
123   unsigned short sram_addr;  // EEPROM address register\r
124   unsigned char sram_cycle;  // EEPROM SRAM cycle number\r
125   unsigned char sram_slave;  // EEPROM slave word for X24C02 and better SRAMs\r
126   unsigned char prot_bytes[2]; // simple protection fakeing\r
127   unsigned short dma_bytes;  //\r
128   unsigned char pad[2];\r
129   unsigned int  frame_count; // mainly for movies\r
130 };\r
131 \r
132 // some assembly stuff depend on these, do not touch!\r
133 struct Pico\r
134 {\r
135   unsigned char ram[0x10000];  // 0x00000 scratch ram\r
136   unsigned short vram[0x8000]; // 0x10000\r
137   unsigned char zram[0x2000];  // 0x20000 Z80 ram\r
138   unsigned char ioports[0x10];\r
139   unsigned int pad[0x3c];      // unused\r
140   unsigned short cram[0x40];   // 0x22100\r
141   unsigned short vsram[0x40];  // 0x22180\r
142 \r
143   unsigned char *rom;          // 0x22200\r
144   unsigned int romsize;        // 0x22204\r
145 \r
146   struct PicoMisc m;\r
147   struct PicoVideo video;\r
148 };\r
149 \r
150 // sram\r
151 struct PicoSRAM\r
152 {\r
153   unsigned char *data; // actual data\r
154   unsigned int start;  // start address in 68k address space\r
155   unsigned int end;\r
156   unsigned char resize; // 1=SRAM size changed and needs to be reallocated on PicoReset\r
157   unsigned char reg_back; // copy of Pico.m.sram_reg to set after reset\r
158   unsigned char changed;\r
159   unsigned char pad;\r
160 };\r
161 \r
162 // MCD\r
163 #include "cd/cd_sys.h"\r
164 #include "cd/LC89510.h"\r
165 #include "cd/gfx_cd.h"\r
166 \r
167 struct mcd_misc\r
168 {\r
169         unsigned short hint_vector;\r
170         unsigned char  busreq;\r
171         unsigned char  pad0;\r
172 \r
173 };\r
174 \r
175 typedef struct\r
176 {\r
177         unsigned char bios[0x20000];                    // 128K\r
178         union {\r
179                 unsigned char prg_ram[0x80000];         // 512K\r
180                 unsigned char prg_ram_b[4][0x20000];\r
181         };\r
182         unsigned char word_ram[0x40000];                // 256K\r
183         unsigned char bram[0x2000];                     // 8K\r
184         unsigned char s68k_regs[0x200];\r
185         CDD  cdd;\r
186         CDC  cdc;\r
187         _scd scd;\r
188         Rot_Comp rot_comp;\r
189         struct mcd_misc m;\r
190 } mcd_state;\r
191 \r
192 #define Pico_mcd ((mcd_state *)Pico.rom)\r
193 \r
194 \r
195 // Draw.c\r
196 int PicoLine(int scan);\r
197 void PicoFrameStart();\r
198 \r
199 // Draw2.c\r
200 void PicoFrameFull();\r
201 \r
202 // Memory.c\r
203 int PicoInitPc(unsigned int pc);\r
204 unsigned int CPU_CALL PicoRead32(unsigned int a);\r
205 void PicoMemSetup();\r
206 void PicoMemReset();\r
207 //void PicoDasm(int start,int len);\r
208 unsigned char z80_read(unsigned short a);\r
209 unsigned short z80_read16(unsigned short a);\r
210 void z80_write(unsigned char data, unsigned short a);\r
211 void z80_write16(unsigned short data, unsigned short a);\r
212 \r
213 // cd/Memory.c\r
214 void PicoMemSetupCD();\r
215 unsigned char  PicoReadCD8 (unsigned int a);\r
216 unsigned short PicoReadCD16(unsigned int a);\r
217 unsigned int   PicoReadCD32(unsigned int a);\r
218 void PicoWriteCD8 (unsigned int a, unsigned char d);\r
219 void PicoWriteCD16(unsigned int a, unsigned short d);\r
220 void PicoWriteCD32(unsigned int a, unsigned int d);\r
221 \r
222 // Pico.c\r
223 extern struct Pico Pico;\r
224 extern struct PicoSRAM SRam;\r
225 extern int emustatus;\r
226 int CheckDMA(void);\r
227 \r
228 // cd/Pico.c\r
229 int  PicoInitMCD(void);\r
230 void PicoExitMCD(void);\r
231 int  PicoResetMCD(int hard);\r
232 \r
233 // Sek.c\r
234 int SekInit(void);\r
235 int SekReset(void);\r
236 int SekInterrupt(int irq);\r
237 void SekState(unsigned char *data);\r
238 \r
239 // cd/Sek.c\r
240 int SekInitS68k(void);\r
241 int SekResetS68k(void);\r
242 int SekInterruptS68k(int irq);\r
243 \r
244 // VideoPort.c\r
245 void PicoVideoWrite(unsigned int a,unsigned short d);\r
246 unsigned int PicoVideoRead(unsigned int a);\r
247 \r
248 // Misc.c\r
249 void SRAMWriteEEPROM(unsigned int d);\r
250 unsigned int SRAMReadEEPROM();\r
251 void SRAMUpdPending(unsigned int a, unsigned int d);\r
252 \r
253 \r
254 #ifdef __cplusplus\r
255 } // End of extern "C"\r
256 #endif\r