| 1 | // Pico Library - Internal Header File\r |
| 2 | \r |
| 3 | // (c) Copyright 2004 Dave, All rights reserved.\r |
| 4 | // (c) Copyright 2006-2008 Grazvydas "notaz" Ignotas, 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 | #ifndef PICO_INTERNAL_INCLUDED\r |
| 10 | #define PICO_INTERNAL_INCLUDED\r |
| 11 | \r |
| 12 | #include <stdio.h>\r |
| 13 | #include <stdlib.h>\r |
| 14 | #include <string.h>\r |
| 15 | #include "pico.h"\r |
| 16 | #include "carthw/carthw.h"\r |
| 17 | \r |
| 18 | //\r |
| 19 | #define USE_POLL_DETECT\r |
| 20 | \r |
| 21 | #ifndef PICO_INTERNAL\r |
| 22 | #define PICO_INTERNAL\r |
| 23 | #endif\r |
| 24 | #ifndef PICO_INTERNAL_ASM\r |
| 25 | #define PICO_INTERNAL_ASM\r |
| 26 | #endif\r |
| 27 | \r |
| 28 | // to select core, define EMU_C68K, EMU_M68K or EMU_F68K in your makefile or project\r |
| 29 | \r |
| 30 | #ifdef __cplusplus\r |
| 31 | extern "C" {\r |
| 32 | #endif\r |
| 33 | \r |
| 34 | \r |
| 35 | // ----------------------- 68000 CPU -----------------------\r |
| 36 | #ifdef EMU_C68K\r |
| 37 | #include "../cpu/Cyclone/Cyclone.h"\r |
| 38 | extern struct Cyclone PicoCpuCM68k, PicoCpuCS68k;\r |
| 39 | #define SekCyclesLeftNoMCD PicoCpuCM68k.cycles // cycles left for this run\r |
| 40 | #define SekCyclesLeft \\r |
| 41 | (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)\r |
| 42 | #define SekCyclesLeftS68k \\r |
| 43 | ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuCS68k.cycles)\r |
| 44 | #define SekSetCyclesLeftNoMCD(c) PicoCpuCM68k.cycles=c\r |
| 45 | #define SekSetCyclesLeft(c) { \\r |
| 46 | if ((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) SekCycleCnt=SekCycleAim-(c); else SekSetCyclesLeftNoMCD(c); \\r |
| 47 | }\r |
| 48 | #define SekPc (PicoCpuCM68k.pc-PicoCpuCM68k.membase)\r |
| 49 | #define SekPcS68k (PicoCpuCS68k.pc-PicoCpuCS68k.membase)\r |
| 50 | #define SekSetStop(x) { PicoCpuCM68k.state_flags&=~1; if (x) { PicoCpuCM68k.state_flags|=1; PicoCpuCM68k.cycles=0; } }\r |
| 51 | #define SekSetStopS68k(x) { PicoCpuCS68k.state_flags&=~1; if (x) { PicoCpuCS68k.state_flags|=1; PicoCpuCS68k.cycles=0; } }\r |
| 52 | #define SekIsStoppedS68k() (PicoCpuCS68k.state_flags&1)\r |
| 53 | #define SekShouldInterrupt (PicoCpuCM68k.irq > (PicoCpuCM68k.srh&7))\r |
| 54 | \r |
| 55 | #define SekInterrupt(i) PicoCpuCM68k.irq=i\r |
| 56 | \r |
| 57 | #ifdef EMU_M68K\r |
| 58 | #define EMU_CORE_DEBUG\r |
| 59 | #endif\r |
| 60 | #endif\r |
| 61 | \r |
| 62 | #ifdef EMU_F68K\r |
| 63 | #include "../cpu/fame/fame.h"\r |
| 64 | extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k;\r |
| 65 | #define SekCyclesLeftNoMCD PicoCpuFM68k.io_cycle_counter\r |
| 66 | #define SekCyclesLeft \\r |
| 67 | (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)\r |
| 68 | #define SekCyclesLeftS68k \\r |
| 69 | ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuFS68k.io_cycle_counter)\r |
| 70 | #define SekSetCyclesLeftNoMCD(c) PicoCpuFM68k.io_cycle_counter=c\r |
| 71 | #define SekSetCyclesLeft(c) { \\r |
| 72 | if ((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) SekCycleCnt=SekCycleAim-(c); else SekSetCyclesLeftNoMCD(c); \\r |
| 73 | }\r |
| 74 | #define SekPc fm68k_get_pc(&PicoCpuFM68k)\r |
| 75 | #define SekPcS68k fm68k_get_pc(&PicoCpuFS68k)\r |
| 76 | #define SekSetStop(x) { \\r |
| 77 | PicoCpuFM68k.execinfo &= ~FM68K_HALTED; \\r |
| 78 | if (x) { PicoCpuFM68k.execinfo |= FM68K_HALTED; PicoCpuFM68k.io_cycle_counter = 0; } \\r |
| 79 | }\r |
| 80 | #define SekSetStopS68k(x) { \\r |
| 81 | PicoCpuFS68k.execinfo &= ~FM68K_HALTED; \\r |
| 82 | if (x) { PicoCpuFS68k.execinfo |= FM68K_HALTED; PicoCpuFS68k.io_cycle_counter = 0; } \\r |
| 83 | }\r |
| 84 | #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED)\r |
| 85 | #define SekShouldInterrupt fm68k_would_interrupt()\r |
| 86 | \r |
| 87 | #define SekInterrupt(irq) PicoCpuFM68k.interrupts[0]=irq\r |
| 88 | \r |
| 89 | #ifdef EMU_M68K\r |
| 90 | #define EMU_CORE_DEBUG\r |
| 91 | #endif\r |
| 92 | #endif\r |
| 93 | \r |
| 94 | #ifdef EMU_M68K\r |
| 95 | #include "../cpu/musashi/m68kcpu.h"\r |
| 96 | extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k;\r |
| 97 | #ifndef SekCyclesLeft\r |
| 98 | #define SekCyclesLeftNoMCD PicoCpuMM68k.cyc_remaining_cycles\r |
| 99 | #define SekCyclesLeft \\r |
| 100 | (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)\r |
| 101 | #define SekCyclesLeftS68k \\r |
| 102 | ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuMS68k.cyc_remaining_cycles)\r |
| 103 | #define SekSetCyclesLeftNoMCD(c) SET_CYCLES(c)\r |
| 104 | #define SekSetCyclesLeft(c) { \\r |
| 105 | if ((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) SekCycleCnt=SekCycleAim-(c); else SET_CYCLES(c); \\r |
| 106 | }\r |
| 107 | #define SekPc m68k_get_reg(&PicoCpuMM68k, M68K_REG_PC)\r |
| 108 | #define SekPcS68k m68k_get_reg(&PicoCpuMS68k, M68K_REG_PC)\r |
| 109 | #define SekSetStop(x) { \\r |
| 110 | if(x) { SET_CYCLES(0); PicoCpuMM68k.stopped=STOP_LEVEL_STOP; } \\r |
| 111 | else PicoCpuMM68k.stopped=0; \\r |
| 112 | }\r |
| 113 | #define SekSetStopS68k(x) { \\r |
| 114 | if(x) { SET_CYCLES(0); PicoCpuMS68k.stopped=STOP_LEVEL_STOP; } \\r |
| 115 | else PicoCpuMS68k.stopped=0; \\r |
| 116 | }\r |
| 117 | #define SekIsStoppedS68k() (PicoCpuMS68k.stopped==STOP_LEVEL_STOP)\r |
| 118 | #define SekShouldInterrupt (CPU_INT_LEVEL > FLAG_INT_MASK)\r |
| 119 | \r |
| 120 | #define SekInterrupt(irq) { \\r |
| 121 | void *oldcontext = m68ki_cpu_p; \\r |
| 122 | m68k_set_context(&PicoCpuMM68k); \\r |
| 123 | m68k_set_irq(irq); \\r |
| 124 | m68k_set_context(oldcontext); \\r |
| 125 | }\r |
| 126 | \r |
| 127 | #endif\r |
| 128 | #endif\r |
| 129 | \r |
| 130 | extern int SekCycleCnt; // cycles done in this frame\r |
| 131 | extern int SekCycleAim; // cycle aim\r |
| 132 | extern unsigned int SekCycleCntT; // total cycle counter, updated once per frame\r |
| 133 | \r |
| 134 | #define SekCyclesReset() { \\r |
| 135 | SekCycleCntT+=SekCycleAim; \\r |
| 136 | SekCycleCnt-=SekCycleAim; \\r |
| 137 | SekCycleAim=0; \\r |
| 138 | }\r |
| 139 | #define SekCyclesBurn(c) SekCycleCnt+=c\r |
| 140 | #define SekCyclesDone() (SekCycleAim-SekCyclesLeft) // number of cycles done in this frame (can be checked anywhere)\r |
| 141 | #define SekCyclesDoneT() (SekCycleCntT+SekCyclesDone()) // total nuber of cycles done for this rom\r |
| 142 | \r |
| 143 | #define SekEndRun(after) { \\r |
| 144 | SekCycleCnt -= SekCyclesLeft - after; \\r |
| 145 | if(SekCycleCnt < 0) SekCycleCnt = 0; \\r |
| 146 | SekSetCyclesLeft(after); \\r |
| 147 | }\r |
| 148 | \r |
| 149 | extern int SekCycleCntS68k;\r |
| 150 | extern int SekCycleAimS68k;\r |
| 151 | \r |
| 152 | #define SekCyclesResetS68k() { \\r |
| 153 | SekCycleCntS68k-=SekCycleAimS68k; \\r |
| 154 | SekCycleAimS68k=0; \\r |
| 155 | }\r |
| 156 | #define SekCyclesDoneS68k() (SekCycleAimS68k-SekCyclesLeftS68k)\r |
| 157 | \r |
| 158 | #ifdef EMU_CORE_DEBUG\r |
| 159 | extern int dbg_irq_level;\r |
| 160 | #undef SekSetCyclesLeftNoMCD\r |
| 161 | #undef SekSetCyclesLeft\r |
| 162 | #undef SekCyclesBurn\r |
| 163 | #undef SekEndRun\r |
| 164 | #undef SekInterrupt\r |
| 165 | #define SekSetCyclesLeftNoMCD(c)\r |
| 166 | #define SekSetCyclesLeft(c)\r |
| 167 | #define SekCyclesBurn(c) c\r |
| 168 | #define SekEndRun(c)\r |
| 169 | #define SekInterrupt(irq) dbg_irq_level=irq\r |
| 170 | #endif\r |
| 171 | \r |
| 172 | // ----------------------- Z80 CPU -----------------------\r |
| 173 | \r |
| 174 | #if defined(_USE_MZ80)\r |
| 175 | #include "../cpu/mz80/mz80.h"\r |
| 176 | \r |
| 177 | #define z80_run(cycles) { mz80GetElapsedTicks(1); mz80_run(cycles) }\r |
| 178 | #define z80_run_nr(cycles) mz80_run(cycles)\r |
| 179 | #define z80_int() mz80int(0)\r |
| 180 | \r |
| 181 | #elif defined(_USE_DRZ80)\r |
| 182 | #include "../cpu/DrZ80/drz80.h"\r |
| 183 | \r |
| 184 | extern struct DrZ80 drZ80;\r |
| 185 | \r |
| 186 | #define z80_run(cycles) ((cycles) - DrZ80Run(&drZ80, cycles))\r |
| 187 | #define z80_run_nr(cycles) DrZ80Run(&drZ80, cycles)\r |
| 188 | #define z80_int() drZ80.Z80_IRQ = 1\r |
| 189 | \r |
| 190 | #define z80_cyclesLeft drZ80.cycles\r |
| 191 | \r |
| 192 | #elif defined(_USE_CZ80)\r |
| 193 | #include "../cpu/cz80/cz80.h"\r |
| 194 | \r |
| 195 | #define z80_run(cycles) Cz80_Exec(&CZ80, cycles)\r |
| 196 | #define z80_run_nr(cycles) Cz80_Exec(&CZ80, cycles)\r |
| 197 | #define z80_int() Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE)\r |
| 198 | \r |
| 199 | #define z80_cyclesLeft (CZ80.ICount - CZ80.ExtraCycles)\r |
| 200 | \r |
| 201 | #else\r |
| 202 | \r |
| 203 | #define z80_run(cycles) (cycles)\r |
| 204 | #define z80_run_nr(cycles)\r |
| 205 | #define z80_int()\r |
| 206 | \r |
| 207 | #endif\r |
| 208 | \r |
| 209 | extern int z80stopCycle; /* in 68k cycles */\r |
| 210 | extern int z80_cycle_cnt; /* 'done' z80 cycles before z80_run() */\r |
| 211 | extern int z80_cycle_aim;\r |
| 212 | extern int z80_scanline;\r |
| 213 | extern int z80_scanline_cycles; /* cycles done until z80_scanline */\r |
| 214 | \r |
| 215 | #define z80_resetCycles() \\r |
| 216 | z80_cycle_cnt = z80_cycle_aim = z80_scanline = z80_scanline_cycles = 0;\r |
| 217 | \r |
| 218 | #define z80_cyclesDone() \\r |
| 219 | (z80_cycle_aim - z80_cyclesLeft)\r |
| 220 | \r |
| 221 | #define cycles_68k_to_z80(x) ((x)*957 >> 11)\r |
| 222 | \r |
| 223 | // ---------------------------------------------------------\r |
| 224 | \r |
| 225 | // main oscillator clock which controls timing\r |
| 226 | #define OSC_NTSC 53693100\r |
| 227 | // seems to be accurate, see scans from http://www.hot.ee/tmeeco/\r |
| 228 | #define OSC_PAL 53203424\r |
| 229 | \r |
| 230 | struct PicoVideo\r |
| 231 | {\r |
| 232 | unsigned char reg[0x20];\r |
| 233 | unsigned int command; // 32-bit Command\r |
| 234 | unsigned char pending; // 1 if waiting for second half of 32-bit command\r |
| 235 | unsigned char type; // Command type (v/c/vsram read/write)\r |
| 236 | unsigned short addr; // Read/Write address\r |
| 237 | int status; // Status bits\r |
| 238 | unsigned char pending_ints; // pending interrupts: ??VH????\r |
| 239 | signed char lwrite_cnt; // VDP write count during active display line\r |
| 240 | unsigned short v_counter; // V-counter\r |
| 241 | unsigned char pad[0x10];\r |
| 242 | };\r |
| 243 | \r |
| 244 | struct PicoMisc\r |
| 245 | {\r |
| 246 | unsigned char rotate;\r |
| 247 | unsigned char z80Run;\r |
| 248 | unsigned char padTHPhase[2]; // 02 phase of gamepad TH switches\r |
| 249 | unsigned short scanline; // 04 0 to 261||311\r |
| 250 | char dirtyPal; // 06 Is the palette dirty (1 - change @ this frame, 2 - some time before)\r |
| 251 | unsigned char hardware; // 07 Hardware value for country\r |
| 252 | unsigned char pal; // 08 1=PAL 0=NTSC\r |
| 253 | unsigned char sram_reg; // SRAM mode register. bit0: allow read? bit1: deny write? bit2: EEPROM? bit4: detected? (header or by access)\r |
| 254 | unsigned short z80_bank68k; // 0a\r |
| 255 | unsigned short z80_lastaddr; // this is for Z80 faking\r |
| 256 | unsigned char z80_fakeval;\r |
| 257 | unsigned char z80_reset; // z80 reset held\r |
| 258 | unsigned char padDelay[2]; // 10 gamepad phase time outs, so we count a delay\r |
| 259 | unsigned short eeprom_addr; // EEPROM address register\r |
| 260 | unsigned char eeprom_cycle; // EEPROM SRAM cycle number\r |
| 261 | unsigned char eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs\r |
| 262 | unsigned char prot_bytes[2]; // simple protection faking\r |
| 263 | unsigned short dma_xfers; // 18\r |
| 264 | unsigned char pad[2];\r |
| 265 | unsigned int frame_count; // 1c for movies and idle det\r |
| 266 | };\r |
| 267 | \r |
| 268 | // some assembly stuff depend on these, do not touch!\r |
| 269 | struct Pico\r |
| 270 | {\r |
| 271 | unsigned char ram[0x10000]; // 0x00000 scratch ram\r |
| 272 | unsigned short vram[0x8000]; // 0x10000\r |
| 273 | unsigned char zram[0x2000]; // 0x20000 Z80 ram\r |
| 274 | unsigned char ioports[0x10];\r |
| 275 | unsigned int pad[0x3c]; // unused\r |
| 276 | unsigned short cram[0x40]; // 0x22100\r |
| 277 | unsigned short vsram[0x40]; // 0x22180\r |
| 278 | \r |
| 279 | unsigned char *rom; // 0x22200\r |
| 280 | unsigned int romsize; // 0x22204\r |
| 281 | \r |
| 282 | struct PicoMisc m;\r |
| 283 | struct PicoVideo video;\r |
| 284 | };\r |
| 285 | \r |
| 286 | // sram\r |
| 287 | struct PicoSRAM\r |
| 288 | {\r |
| 289 | unsigned char *data; // actual data\r |
| 290 | unsigned int start; // start address in 68k address space\r |
| 291 | unsigned int end;\r |
| 292 | unsigned char unused1; // 0c: unused\r |
| 293 | unsigned char unused2;\r |
| 294 | unsigned char changed;\r |
| 295 | unsigned char eeprom_type; // eeprom type: 0: 7bit (24C01), 2: device with 2 addr words (X24C02+), 3: dev with 3 addr words\r |
| 296 | unsigned char eeprom_abits; // eeprom access must be odd addr for: bit0 ~ cl, bit1 ~ out\r |
| 297 | unsigned char eeprom_bit_cl; // bit number for cl\r |
| 298 | unsigned char eeprom_bit_in; // bit number for in\r |
| 299 | unsigned char eeprom_bit_out; // bit number for out\r |
| 300 | };\r |
| 301 | \r |
| 302 | // MCD\r |
| 303 | #include "cd/cd_sys.h"\r |
| 304 | #include "cd/LC89510.h"\r |
| 305 | #include "cd/gfx_cd.h"\r |
| 306 | \r |
| 307 | struct mcd_pcm\r |
| 308 | {\r |
| 309 | unsigned char control; // reg7\r |
| 310 | unsigned char enabled; // reg8\r |
| 311 | unsigned char cur_ch;\r |
| 312 | unsigned char bank;\r |
| 313 | int pad1;\r |
| 314 | \r |
| 315 | struct pcm_chan // 08, size 0x10\r |
| 316 | {\r |
| 317 | unsigned char regs[8];\r |
| 318 | unsigned int addr; // .08: played sample address\r |
| 319 | int pad;\r |
| 320 | } ch[8];\r |
| 321 | };\r |
| 322 | \r |
| 323 | struct mcd_misc\r |
| 324 | {\r |
| 325 | unsigned short hint_vector;\r |
| 326 | unsigned char busreq;\r |
| 327 | unsigned char s68k_pend_ints;\r |
| 328 | unsigned int state_flags; // 04: emu state: reset_pending, dmna_pending\r |
| 329 | unsigned int counter75hz;\r |
| 330 | unsigned int pad0;\r |
| 331 | int timer_int3; // 10\r |
| 332 | unsigned int timer_stopwatch;\r |
| 333 | unsigned char bcram_reg; // 18: battery-backed RAM cart register\r |
| 334 | unsigned char pad2;\r |
| 335 | unsigned short pad3;\r |
| 336 | int pad[9];\r |
| 337 | };\r |
| 338 | \r |
| 339 | typedef struct\r |
| 340 | {\r |
| 341 | unsigned char bios[0x20000]; // 000000: 128K\r |
| 342 | union { // 020000: 512K\r |
| 343 | unsigned char prg_ram[0x80000];\r |
| 344 | unsigned char prg_ram_b[4][0x20000];\r |
| 345 | };\r |
| 346 | union { // 0a0000: 256K\r |
| 347 | struct {\r |
| 348 | unsigned char word_ram2M[0x40000];\r |
| 349 | unsigned char unused0[0x20000];\r |
| 350 | };\r |
| 351 | struct {\r |
| 352 | unsigned char unused1[0x20000];\r |
| 353 | unsigned char word_ram1M[2][0x20000];\r |
| 354 | };\r |
| 355 | };\r |
| 356 | union { // 100000: 64K\r |
| 357 | unsigned char pcm_ram[0x10000];\r |
| 358 | unsigned char pcm_ram_b[0x10][0x1000];\r |
| 359 | };\r |
| 360 | unsigned char s68k_regs[0x200]; // 110000: GA, not CPU regs\r |
| 361 | unsigned char bram[0x2000]; // 110200: 8K\r |
| 362 | struct mcd_misc m; // 112200: misc\r |
| 363 | struct mcd_pcm pcm; // 112240:\r |
| 364 | _scd_toc TOC; // not to be saved\r |
| 365 | CDD cdd;\r |
| 366 | CDC cdc;\r |
| 367 | _scd scd;\r |
| 368 | Rot_Comp rot_comp;\r |
| 369 | } mcd_state;\r |
| 370 | \r |
| 371 | #define Pico_mcd ((mcd_state *)Pico.rom)\r |
| 372 | \r |
| 373 | \r |
| 374 | // Area.c\r |
| 375 | PICO_INTERNAL void PicoAreaPackCpu(unsigned char *cpu, int is_sub);\r |
| 376 | PICO_INTERNAL void PicoAreaUnpackCpu(unsigned char *cpu, int is_sub);\r |
| 377 | extern void (*PicoLoadStateHook)(void);\r |
| 378 | \r |
| 379 | // cd/Area.c\r |
| 380 | PICO_INTERNAL int PicoCdSaveState(void *file);\r |
| 381 | PICO_INTERNAL int PicoCdLoadState(void *file);\r |
| 382 | \r |
| 383 | typedef struct {\r |
| 384 | int chunk;\r |
| 385 | int size;\r |
| 386 | void *ptr;\r |
| 387 | } carthw_state_chunk;\r |
| 388 | extern carthw_state_chunk *carthw_chunks;\r |
| 389 | #define CHUNK_CARTHW 64\r |
| 390 | \r |
| 391 | // area.c\r |
| 392 | typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file);\r |
| 393 | typedef size_t (areaeof)(void *file);\r |
| 394 | typedef int (areaseek)(void *file, long offset, int whence);\r |
| 395 | typedef int (areaclose)(void *file);\r |
| 396 | extern arearw *areaRead; // external read and write function pointers for\r |
| 397 | extern arearw *areaWrite; // gzip save state ability\r |
| 398 | extern areaeof *areaEof;\r |
| 399 | extern areaseek *areaSeek;\r |
| 400 | extern areaclose *areaClose;\r |
| 401 | \r |
| 402 | // Cart.c\r |
| 403 | extern void (*PicoCartUnloadHook)(void);\r |
| 404 | \r |
| 405 | // Debug.c\r |
| 406 | int CM_compareRun(int cyc, int is_sub);\r |
| 407 | \r |
| 408 | // Draw.c\r |
| 409 | PICO_INTERNAL void PicoFrameStart(void);\r |
| 410 | void PicoDrawSync(int to, int blank_last_line);\r |
| 411 | extern int DrawScanline;\r |
| 412 | #define MAX_LINE_SPRITES 29\r |
| 413 | extern unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES];\r |
| 414 | \r |
| 415 | // Draw2.c\r |
| 416 | PICO_INTERNAL void PicoFrameFull();\r |
| 417 | \r |
| 418 | // Memory.c\r |
| 419 | PICO_INTERNAL void PicoInitPc(unsigned int pc);\r |
| 420 | PICO_INTERNAL unsigned int PicoCheckPc(unsigned int pc);\r |
| 421 | PICO_INTERNAL_ASM unsigned int PicoRead32(unsigned int a);\r |
| 422 | PICO_INTERNAL void PicoMemSetup(void);\r |
| 423 | PICO_INTERNAL_ASM void PicoMemReset(void);\r |
| 424 | PICO_INTERNAL void PicoMemResetHooks(void);\r |
| 425 | PICO_INTERNAL int PadRead(int i);\r |
| 426 | PICO_INTERNAL unsigned char z80_read(unsigned short a);\r |
| 427 | #ifndef _USE_CZ80\r |
| 428 | PICO_INTERNAL_ASM void z80_write(unsigned char data, unsigned short a);\r |
| 429 | PICO_INTERNAL void z80_write16(unsigned short data, unsigned short a);\r |
| 430 | PICO_INTERNAL unsigned short z80_read16(unsigned short a);\r |
| 431 | #else\r |
| 432 | PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data);\r |
| 433 | #endif\r |
| 434 | PICO_INTERNAL int ym2612_write_local(unsigned int a, unsigned int d, int is_from_z80);\r |
| 435 | extern unsigned int (*PicoRead16Hook)(unsigned int a, int realsize);\r |
| 436 | extern void (*PicoWrite8Hook) (unsigned int a,unsigned int d,int realsize);\r |
| 437 | extern void (*PicoWrite16Hook)(unsigned int a,unsigned int d,int realsize);\r |
| 438 | \r |
| 439 | // cd/Memory.c\r |
| 440 | PICO_INTERNAL void PicoMemSetupCD(void);\r |
| 441 | PICO_INTERNAL_ASM void PicoMemResetCD(int r3);\r |
| 442 | PICO_INTERNAL_ASM void PicoMemResetCDdecode(int r3);\r |
| 443 | \r |
| 444 | // Pico/Memory.c\r |
| 445 | PICO_INTERNAL void PicoMemSetupPico(void);\r |
| 446 | PICO_INTERNAL unsigned int ym2612_read_local_68k(void);\r |
| 447 | \r |
| 448 | // Pico.c\r |
| 449 | extern struct Pico Pico;\r |
| 450 | extern struct PicoSRAM SRam;\r |
| 451 | extern int PicoPadInt[2];\r |
| 452 | extern int emustatus;\r |
| 453 | extern void (*PicoResetHook)(void);\r |
| 454 | extern void (*PicoLineHook)(void);\r |
| 455 | PICO_INTERNAL int CheckDMA(void);\r |
| 456 | PICO_INTERNAL void PicoDetectRegion(void);\r |
| 457 | PICO_INTERNAL void PicoSyncZ80(int m68k_cycles_done);\r |
| 458 | \r |
| 459 | // cd/Pico.c\r |
| 460 | PICO_INTERNAL void PicoInitMCD(void);\r |
| 461 | PICO_INTERNAL void PicoExitMCD(void);\r |
| 462 | PICO_INTERNAL void PicoPowerMCD(void);\r |
| 463 | PICO_INTERNAL int PicoResetMCD(void);\r |
| 464 | PICO_INTERNAL void PicoFrameMCD(void);\r |
| 465 | \r |
| 466 | // Pico/Pico.c\r |
| 467 | PICO_INTERNAL void PicoInitPico(void);\r |
| 468 | PICO_INTERNAL void PicoReratePico(void);\r |
| 469 | \r |
| 470 | // Pico/xpcm.c\r |
| 471 | PICO_INTERNAL void PicoPicoPCMUpdate(short *buffer, int length, int stereo);\r |
| 472 | PICO_INTERNAL void PicoPicoPCMReset(void);\r |
| 473 | PICO_INTERNAL void PicoPicoPCMRerate(int xpcm_rate);\r |
| 474 | \r |
| 475 | // Sek.c\r |
| 476 | PICO_INTERNAL void SekInit(void);\r |
| 477 | PICO_INTERNAL int SekReset(void);\r |
| 478 | PICO_INTERNAL void SekState(int *data);\r |
| 479 | PICO_INTERNAL void SekSetRealTAS(int use_real);\r |
| 480 | void SekStepM68k(void);\r |
| 481 | void SekInitIdleDet(void);\r |
| 482 | void SekFinishIdleDet(void);\r |
| 483 | \r |
| 484 | // cd/Sek.c\r |
| 485 | PICO_INTERNAL void SekInitS68k(void);\r |
| 486 | PICO_INTERNAL int SekResetS68k(void);\r |
| 487 | PICO_INTERNAL int SekInterruptS68k(int irq);\r |
| 488 | \r |
| 489 | // sound/sound.c\r |
| 490 | PICO_INTERNAL void cdda_start_play();\r |
| 491 | extern short cdda_out_buffer[2*1152];\r |
| 492 | extern int PsndLen_exc_cnt;\r |
| 493 | extern int PsndLen_exc_add;\r |
| 494 | extern int timer_a_next_oflow, timer_a_step; // in z80 cycles\r |
| 495 | extern int timer_b_next_oflow, timer_b_step;\r |
| 496 | \r |
| 497 | void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new);\r |
| 498 | void ym2612_pack_state(void);\r |
| 499 | void ym2612_unpack_state(void);\r |
| 500 | \r |
| 501 | #define TIMER_NO_OFLOW 0x70000000\r |
| 502 | // tA = 72 * (1024 - NA) / M\r |
| 503 | #define TIMER_A_TICK_ZCYCLES 17203\r |
| 504 | // tB = 1152 * (256 - NA) / M\r |
| 505 | #define TIMER_B_TICK_ZCYCLES 262800 // 275251 broken, see Dai Makaimura\r |
| 506 | \r |
| 507 | #define timers_cycle() \\r |
| 508 | if (timer_a_next_oflow > 0 && timer_a_next_oflow < TIMER_NO_OFLOW) \\r |
| 509 | timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \\r |
| 510 | if (timer_b_next_oflow > 0 && timer_b_next_oflow < TIMER_NO_OFLOW) \\r |
| 511 | timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \\r |
| 512 | ym2612_sync_timers(0, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode);\r |
| 513 | \r |
| 514 | #define timers_reset() \\r |
| 515 | timer_a_next_oflow = timer_b_next_oflow = TIMER_NO_OFLOW; \\r |
| 516 | timer_a_step = TIMER_A_TICK_ZCYCLES * 1024; \\r |
| 517 | timer_b_step = TIMER_B_TICK_ZCYCLES * 256;\r |
| 518 | \r |
| 519 | \r |
| 520 | // VideoPort.c\r |
| 521 | PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d);\r |
| 522 | PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a);\r |
| 523 | PICO_INTERNAL_ASM unsigned int PicoVideoRead8(unsigned int a);\r |
| 524 | extern int (*PicoDmaHook)(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp);\r |
| 525 | \r |
| 526 | // Misc.c\r |
| 527 | PICO_INTERNAL void SRAMWriteEEPROM(unsigned int d);\r |
| 528 | PICO_INTERNAL void SRAMUpdPending(unsigned int a, unsigned int d);\r |
| 529 | PICO_INTERNAL_ASM unsigned int SRAMReadEEPROM(void);\r |
| 530 | PICO_INTERNAL_ASM void memcpy16(unsigned short *dest, unsigned short *src, int count);\r |
| 531 | PICO_INTERNAL_ASM void memcpy16bswap(unsigned short *dest, void *src, int count);\r |
| 532 | PICO_INTERNAL_ASM void memcpy32(int *dest, int *src, int count); // 32bit word count\r |
| 533 | PICO_INTERNAL_ASM void memset32(int *dest, int c, int count);\r |
| 534 | \r |
| 535 | // cd/Misc.c\r |
| 536 | PICO_INTERNAL_ASM void wram_2M_to_1M(unsigned char *m);\r |
| 537 | PICO_INTERNAL_ASM void wram_1M_to_2M(unsigned char *m);\r |
| 538 | \r |
| 539 | // cd/buffering.c\r |
| 540 | PICO_INTERNAL void PicoCDBufferRead(void *dest, int lba);\r |
| 541 | \r |
| 542 | // sound/sound.c\r |
| 543 | PICO_INTERNAL void PsndReset(void);\r |
| 544 | PICO_INTERNAL void PsndDoDAC(int line_to);\r |
| 545 | PICO_INTERNAL void PsndClear(void);\r |
| 546 | PICO_INTERNAL void PsndGetSamples(int y);\r |
| 547 | // z80 functionality wrappers\r |
| 548 | PICO_INTERNAL void z80_init(void);\r |
| 549 | PICO_INTERNAL void z80_pack(unsigned char *data);\r |
| 550 | PICO_INTERNAL void z80_unpack(unsigned char *data);\r |
| 551 | PICO_INTERNAL void z80_reset(void);\r |
| 552 | PICO_INTERNAL void z80_exit(void);\r |
| 553 | extern int PsndDacLine;\r |
| 554 | \r |
| 555 | // emulation event logging\r |
| 556 | #ifndef EL_LOGMASK\r |
| 557 | #define EL_LOGMASK 0\r |
| 558 | #endif\r |
| 559 | \r |
| 560 | #define EL_HVCNT 0x00000001 /* hv counter reads */\r |
| 561 | #define EL_SR 0x00000002 /* SR reads */\r |
| 562 | #define EL_INTS 0x00000004 /* ints and acks */\r |
| 563 | #define EL_YMTIMER 0x00000008 /* ym2612 timer stuff */\r |
| 564 | #define EL_INTSW 0x00000010 /* log irq switching on/off */\r |
| 565 | #define EL_ASVDP 0x00000020 /* VDP accesses during active scan */\r |
| 566 | #define EL_VDPDMA 0x00000040 /* VDP DMA transfers and their timing */\r |
| 567 | #define EL_BUSREQ 0x00000080 /* z80 busreq r/w or reset w */\r |
| 568 | #define EL_Z80BNK 0x00000100 /* z80 i/o through bank area */\r |
| 569 | #define EL_SRAMIO 0x00000200 /* sram i/o */\r |
| 570 | #define EL_EEPROM 0x00000400 /* eeprom debug */\r |
| 571 | #define EL_UIO 0x00000800 /* unmapped i/o */\r |
| 572 | #define EL_IO 0x00001000 /* all i/o */\r |
| 573 | #define EL_CDPOLL 0x00002000 /* MCD: log poll detection */\r |
| 574 | #define EL_SVP 0x00004000 /* SVP stuff */\r |
| 575 | #define EL_PICOHW 0x00008000 /* Pico stuff */\r |
| 576 | #define EL_IDLE 0x00010000 /* idle loop det. */\r |
| 577 | \r |
| 578 | #define EL_STATUS 0x40000000 /* status messages */\r |
| 579 | #define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */\r |
| 580 | \r |
| 581 | #if EL_LOGMASK\r |
| 582 | extern void lprintf(const char *fmt, ...);\r |
| 583 | #define elprintf(w,f,...) \\r |
| 584 | { \\r |
| 585 | if ((w) & EL_LOGMASK) \\r |
| 586 | lprintf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__); \\r |
| 587 | }\r |
| 588 | #elif defined(_MSC_VER)\r |
| 589 | #define elprintf\r |
| 590 | #else\r |
| 591 | #define elprintf(w,f,...)\r |
| 592 | #endif\r |
| 593 | \r |
| 594 | #ifdef _MSC_VER\r |
| 595 | #define cdprintf\r |
| 596 | #else\r |
| 597 | #define cdprintf(x...)\r |
| 598 | #endif\r |
| 599 | \r |
| 600 | #ifdef __cplusplus\r |
| 601 | } // End of extern "C"\r |
| 602 | #endif\r |
| 603 | \r |
| 604 | #endif // PICO_INTERNAL_INCLUDED\r |
| 605 | \r |