2 * PicoDrive - Internal Header File
\r
3 * (c) Copyright Dave, 2004
\r
4 * (C) notaz, 2006-2010
\r
6 * This work is licensed under the terms of MAME license.
\r
7 * See COPYING file in the top-level directory.
\r
10 #ifndef PICO_INTERNAL_INCLUDED
\r
11 #define PICO_INTERNAL_INCLUDED
\r
17 #include "carthw/carthw.h"
\r
20 #define USE_POLL_DETECT
\r
22 #ifndef PICO_INTERNAL
\r
23 #define PICO_INTERNAL
\r
25 #ifndef PICO_INTERNAL_ASM
\r
26 #define PICO_INTERNAL_ASM
\r
29 // to select core, define EMU_C68K, EMU_M68K or EMU_F68K in your makefile or project
\r
36 // ----------------------- 68000 CPU -----------------------
\r
38 #include "../cpu/cyclone/Cyclone.h"
\r
39 extern struct Cyclone PicoCpuCM68k, PicoCpuCS68k;
\r
40 #define SekCyclesLeftNoMCD PicoCpuCM68k.cycles // cycles left for this run
\r
41 #define SekCyclesLeft \
\r
42 (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)
\r
43 #define SekCyclesLeftS68k \
\r
44 ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuCS68k.cycles)
\r
45 #define SekEndTimeslice(after) PicoCpuCM68k.cycles=after
\r
46 #define SekEndTimesliceS68k(after) PicoCpuCS68k.cycles=after
\r
47 #define SekPc (PicoCpuCM68k.pc-PicoCpuCM68k.membase)
\r
48 #define SekPcS68k (PicoCpuCS68k.pc-PicoCpuCS68k.membase)
\r
49 #define SekDar(x) (x < 8 ? PicoCpuCM68k.d[x] : PicoCpuCM68k.a[x - 8])
\r
50 #define SekSr CycloneGetSr(&PicoCpuCM68k)
\r
51 #define SekSetStop(x) { PicoCpuCM68k.state_flags&=~1; if (x) { PicoCpuCM68k.state_flags|=1; PicoCpuCM68k.cycles=0; } }
\r
52 #define SekSetStopS68k(x) { PicoCpuCS68k.state_flags&=~1; if (x) { PicoCpuCS68k.state_flags|=1; PicoCpuCS68k.cycles=0; } }
\r
53 #define SekIsStoppedM68k() (PicoCpuCM68k.state_flags&1)
\r
54 #define SekIsStoppedS68k() (PicoCpuCS68k.state_flags&1)
\r
55 #define SekShouldInterrupt (PicoCpuCM68k.irq > (PicoCpuCM68k.srh&7))
\r
57 #define SekInterrupt(i) PicoCpuCM68k.irq=i
\r
58 #define SekIrqLevel PicoCpuCM68k.irq
\r
61 #define EMU_CORE_DEBUG
\r
66 #include "../cpu/fame/fame.h"
\r
67 extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k;
\r
68 #define SekCyclesLeftNoMCD PicoCpuFM68k.io_cycle_counter
\r
69 #define SekCyclesLeft \
\r
70 (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)
\r
71 #define SekCyclesLeftS68k \
\r
72 ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuFS68k.io_cycle_counter)
\r
73 #define SekEndTimeslice(after) PicoCpuFM68k.io_cycle_counter=after
\r
74 #define SekEndTimesliceS68k(after) PicoCpuFS68k.io_cycle_counter=after
\r
75 #define SekPc fm68k_get_pc(&PicoCpuFM68k)
\r
76 #define SekPcS68k fm68k_get_pc(&PicoCpuFS68k)
\r
77 #define SekDar(x) (x < 8 ? PicoCpuFM68k.dreg[x].D : PicoCpuFM68k.areg[x - 8].D)
\r
78 #define SekSr PicoCpuFM68k.sr
\r
79 #define SekSetStop(x) { \
\r
80 PicoCpuFM68k.execinfo &= ~FM68K_HALTED; \
\r
81 if (x) { PicoCpuFM68k.execinfo |= FM68K_HALTED; PicoCpuFM68k.io_cycle_counter = 0; } \
\r
83 #define SekSetStopS68k(x) { \
\r
84 PicoCpuFS68k.execinfo &= ~FM68K_HALTED; \
\r
85 if (x) { PicoCpuFS68k.execinfo |= FM68K_HALTED; PicoCpuFS68k.io_cycle_counter = 0; } \
\r
87 #define SekIsStoppedM68k() (PicoCpuFM68k.execinfo&FM68K_HALTED)
\r
88 #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED)
\r
89 #define SekShouldInterrupt fm68k_would_interrupt()
\r
91 #define SekInterrupt(irq) PicoCpuFM68k.interrupts[0]=irq
\r
92 #define SekIrqLevel PicoCpuFM68k.interrupts[0]
\r
95 #define EMU_CORE_DEBUG
\r
100 #include "../cpu/musashi/m68kcpu.h"
\r
101 extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k;
\r
102 #ifndef SekCyclesLeft
\r
103 #define SekCyclesLeftNoMCD PicoCpuMM68k.cyc_remaining_cycles
\r
104 #define SekCyclesLeft \
\r
105 (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)
\r
106 #define SekCyclesLeftS68k \
\r
107 ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuMS68k.cyc_remaining_cycles)
\r
108 #define SekEndTimeslice(after) SET_CYCLES(after)
\r
109 #define SekEndTimesliceS68k(after) PicoCpuMS68k.cyc_remaining_cycles=after
\r
110 #define SekPc m68k_get_reg(&PicoCpuMM68k, M68K_REG_PC)
\r
111 #define SekPcS68k m68k_get_reg(&PicoCpuMS68k, M68K_REG_PC)
\r
112 #define SekDar(x) PicoCpuMM68k.dar[x]
\r
113 #define SekSr m68k_get_reg(&PicoCpuMM68k, M68K_REG_SR)
\r
114 #define SekSetStop(x) { \
\r
115 if(x) { SET_CYCLES(0); PicoCpuMM68k.stopped=STOP_LEVEL_STOP; } \
\r
116 else PicoCpuMM68k.stopped=0; \
\r
118 #define SekSetStopS68k(x) { \
\r
119 if(x) { SET_CYCLES(0); PicoCpuMS68k.stopped=STOP_LEVEL_STOP; } \
\r
120 else PicoCpuMS68k.stopped=0; \
\r
122 #define SekIsStoppedM68k() (PicoCpuMM68k.stopped==STOP_LEVEL_STOP)
\r
123 #define SekIsStoppedS68k() (PicoCpuMS68k.stopped==STOP_LEVEL_STOP)
\r
124 #define SekShouldInterrupt (CPU_INT_LEVEL > FLAG_INT_MASK)
\r
126 #define SekInterrupt(irq) { \
\r
127 void *oldcontext = m68ki_cpu_p; \
\r
128 m68k_set_context(&PicoCpuMM68k); \
\r
129 m68k_set_irq(irq); \
\r
130 m68k_set_context(oldcontext); \
\r
132 #define SekIrqLevel (PicoCpuMM68k.int_level >> 8)
\r
137 extern int SekCycleCnt; // cycles done in this frame
\r
138 extern int SekCycleAim; // cycle aim
\r
139 extern unsigned int SekCycleCntT; // total cycle counter, updated once per frame
\r
141 #define SekCyclesReset() { \
\r
142 SekCycleCntT+=SekCycleAim; \
\r
143 SekCycleCnt-=SekCycleAim; \
\r
146 #define SekCyclesBurn(c) SekCycleCnt+=c
\r
147 #define SekCyclesDone() (SekCycleAim-SekCyclesLeft) // number of cycles done in this frame (can be checked anywhere)
\r
148 #define SekCyclesDoneT() (SekCycleCntT+SekCyclesDone()) // total nuber of cycles done for this rom
\r
149 #define SekCyclesDoneT2() (SekCycleCntT + SekCycleCnt) // same as above but not from memhandlers
\r
151 #define SekEndRun(after) { \
\r
152 SekCycleCnt -= SekCyclesLeft - (after); \
\r
153 if (SekCycleCnt < 0) SekCycleCnt = 0; \
\r
154 SekEndTimeslice(after); \
\r
157 #define SekEndRunS68k(after) { \
\r
158 SekCycleCntS68k -= SekCyclesLeftS68k - (after); \
\r
159 if (SekCycleCntS68k < 0) SekCycleCntS68k = 0; \
\r
160 SekEndTimesliceS68k(after); \
\r
163 extern int SekCycleCntS68k;
\r
164 extern int SekCycleAimS68k;
\r
166 #define SekCyclesResetS68k() { \
\r
167 SekCycleCntS68k-=SekCycleAimS68k; \
\r
168 SekCycleAimS68k=0; \
\r
170 #define SekCyclesDoneS68k() (SekCycleAimS68k-SekCyclesLeftS68k)
\r
172 #ifdef EMU_CORE_DEBUG
\r
173 extern int dbg_irq_level;
\r
174 #undef SekEndTimeslice
\r
175 #undef SekCyclesBurn
\r
177 #undef SekInterrupt
\r
178 #define SekEndTimeslice(c)
\r
179 #define SekCyclesBurn(c) c
\r
180 #define SekEndRun(c)
\r
181 #define SekInterrupt(irq) dbg_irq_level=irq
\r
184 // ----------------------- Z80 CPU -----------------------
\r
186 #if defined(_USE_DRZ80)
\r
187 #include "../cpu/DrZ80/drz80.h"
\r
189 extern struct DrZ80 drZ80;
\r
191 #define z80_run(cycles) ((cycles) - DrZ80Run(&drZ80, cycles))
\r
192 #define z80_run_nr(cycles) DrZ80Run(&drZ80, cycles)
\r
193 #define z80_int() drZ80.Z80_IRQ = 1
\r
195 #define z80_cyclesLeft drZ80.cycles
\r
196 #define z80_pc() (drZ80.Z80PC - drZ80.Z80PC_BASE)
\r
198 #elif defined(_USE_CZ80)
\r
199 #include "../cpu/cz80/cz80.h"
\r
201 #define z80_run(cycles) Cz80_Exec(&CZ80, cycles)
\r
202 #define z80_run_nr(cycles) Cz80_Exec(&CZ80, cycles)
\r
203 #define z80_int() Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE)
\r
205 #define z80_cyclesLeft (CZ80.ICount - CZ80.ExtraCycles)
\r
206 #define z80_pc() Cz80_Get_Reg(&CZ80, CZ80_PC)
\r
210 #define z80_run(cycles) (cycles)
\r
211 #define z80_run_nr(cycles)
\r
216 #define Z80_STATE_SIZE 0x60
\r
218 extern int z80stopCycle; /* in 68k cycles */
\r
219 extern int z80_cycle_cnt; /* 'done' z80 cycles before z80_run() */
\r
220 extern int z80_cycle_aim;
\r
221 extern int z80_scanline;
\r
222 extern int z80_scanline_cycles; /* cycles done until z80_scanline */
\r
224 #define z80_resetCycles() \
\r
225 z80_cycle_cnt = z80_cycle_aim = z80_scanline = z80_scanline_cycles = 0;
\r
227 #define z80_cyclesDone() \
\r
228 (z80_cycle_aim - z80_cyclesLeft)
\r
230 #define cycles_68k_to_z80(x) ((x)*957 >> 11)
\r
232 // ----------------------- SH2 CPU -----------------------
\r
234 #include "cpu/sh2/sh2.h"
\r
236 extern SH2 sh2s[2];
\r
237 #define msh2 sh2s[0]
\r
238 #define ssh2 sh2s[1]
\r
241 # define sh2_end_run(sh2, after_) do { \
\r
242 if ((sh2)->icount > (after_)) { \
\r
243 (sh2)->cycles_timeslice -= (sh2)->icount; \
\r
244 (sh2)->icount = after_; \
\r
247 # define sh2_cycles_left(sh2) (sh2)->icount
\r
248 # define sh2_pc(c) (c) ? ssh2.ppc : msh2.ppc
\r
250 # define sh2_end_run(sh2, after_) do { \
\r
251 int left_ = (signed int)(sh2)->sr >> 12; \
\r
252 if (left_ > (after_)) { \
\r
253 (sh2)->cycles_timeslice -= left_; \
\r
254 (sh2)->sr &= 0xfff; \
\r
255 (sh2)->sr |= (after_) << 12; \
\r
258 # define sh2_cycles_left(sh2) ((signed int)(sh2)->sr >> 12)
\r
259 # define sh2_pc(c) (c) ? ssh2.pc : msh2.pc
\r
262 #define sh2_cycles_done(sh2) ((int)(sh2)->cycles_timeslice - sh2_cycles_left(sh2))
\r
263 #define sh2_cycles_done_m68k(sh2) \
\r
264 ((sh2)->m68krcycles_done + (sh2_cycles_done(sh2) / 3))
\r
266 #define sh2_reg(c, x) (c) ? ssh2.r[x] : msh2.r[x]
\r
267 #define sh2_gbr(c) (c) ? ssh2.gbr : msh2.gbr
\r
268 #define sh2_vbr(c) (c) ? ssh2.vbr : msh2.vbr
\r
269 #define sh2_sr(c) (((c) ? ssh2.sr : msh2.sr) & 0xfff)
\r
271 #define sh2_set_gbr(c, v) \
\r
272 { if (c) ssh2.gbr = v; else msh2.gbr = v; }
\r
273 #define sh2_set_vbr(c, v) \
\r
274 { if (c) ssh2.vbr = v; else msh2.vbr = v; }
\r
276 // ---------------------------------------------------------
\r
278 // main oscillator clock which controls timing
\r
279 #define OSC_NTSC 53693100
\r
280 #define OSC_PAL 53203424
\r
284 unsigned char reg[0x20];
\r
285 unsigned int command; // 32-bit Command
\r
286 unsigned char pending; // 1 if waiting for second half of 32-bit command
\r
287 unsigned char type; // Command type (v/c/vsram read/write)
\r
288 unsigned short addr; // Read/Write address
\r
289 int status; // Status bits
\r
290 unsigned char pending_ints; // pending interrupts: ??VH????
\r
291 signed char lwrite_cnt; // VDP write count during active display line
\r
292 unsigned short v_counter; // V-counter
\r
293 unsigned char pad[0x10];
\r
298 unsigned char rotate;
\r
299 unsigned char z80Run;
\r
300 unsigned char padTHPhase[2]; // 02 phase of gamepad TH switches
\r
301 unsigned short scanline; // 04 0 to 261||311
\r
302 char dirtyPal; // 06 Is the palette dirty (1 - change @ this frame, 2 - some time before)
\r
303 unsigned char hardware; // 07 Hardware value for country
\r
304 unsigned char pal; // 08 1=PAL 0=NTSC
\r
305 unsigned char sram_reg; // 09 SRAM reg. See SRR_* below
\r
306 unsigned short z80_bank68k; // 0a
\r
307 unsigned short pad0;
\r
308 unsigned char pad1;
\r
309 unsigned char z80_reset; // 0f z80 reset held
\r
310 unsigned char padDelay[2]; // 10 gamepad phase time outs, so we count a delay
\r
311 unsigned short eeprom_addr; // EEPROM address register
\r
312 unsigned char eeprom_cycle; // EEPROM cycle number
\r
313 unsigned char eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs
\r
314 unsigned char eeprom_status;
\r
315 unsigned char pad2;
\r
316 unsigned short dma_xfers; // 18
\r
317 unsigned char eeprom_wb[2]; // EEPROM latch/write buffer
\r
318 unsigned int frame_count; // 1c for movies and idle det
\r
323 unsigned char carthw[0x10];
\r
324 unsigned char io_ctl;
\r
325 unsigned char pad[0x4f];
\r
328 // some assembly stuff depend on these, do not touch!
\r
331 unsigned char ram[0x10000]; // 0x00000 scratch ram
\r
332 union { // vram is byteswapped for easier reads when drawing
\r
333 unsigned short vram[0x8000]; // 0x10000
\r
334 unsigned char vramb[0x4000]; // VRAM in SMS mode
\r
336 unsigned char zram[0x2000]; // 0x20000 Z80 ram
\r
337 unsigned char ioports[0x10]; // XXX: fix asm and mv
\r
338 unsigned char pad[0xf0]; // unused
\r
339 unsigned short cram[0x40]; // 0x22100
\r
340 unsigned short vsram[0x40]; // 0x22180
\r
342 unsigned char *rom; // 0x22200
\r
343 unsigned int romsize; // 0x22204
\r
346 struct PicoVideo video;
\r
351 #define SRR_MAPPED (1 << 0)
\r
352 #define SRR_READONLY (1 << 1)
\r
354 #define SRF_ENABLED (1 << 0)
\r
355 #define SRF_EEPROM (1 << 1)
\r
359 unsigned char *data; // actual data
\r
360 unsigned int start; // start address in 68k address space
\r
362 unsigned char flags; // 0c: SRF_*
\r
363 unsigned char unused2;
\r
364 unsigned char changed;
\r
365 unsigned char eeprom_type; // eeprom type: 0: 7bit (24C01), 2: 2 addr words (X24C02+), 3: 3 addr words
\r
366 unsigned char unused3;
\r
367 unsigned char eeprom_bit_cl; // bit number for cl
\r
368 unsigned char eeprom_bit_in; // bit number for in
\r
369 unsigned char eeprom_bit_out; // bit number for out
\r
374 #include "cd/cd_sys.h"
\r
375 #include "cd/LC89510.h"
\r
376 #include "cd/gfx_cd.h"
\r
380 unsigned char control; // reg7
\r
381 unsigned char enabled; // reg8
\r
382 unsigned char cur_ch;
\r
383 unsigned char bank;
\r
386 struct pcm_chan // 08, size 0x10
\r
388 unsigned char regs[8];
\r
389 unsigned int addr; // .08: played sample address
\r
396 unsigned short hint_vector;
\r
397 unsigned char busreq;
\r
398 unsigned char s68k_pend_ints;
\r
399 unsigned int state_flags; // 04: emu state: reset_pending
\r
400 unsigned int counter75hz;
\r
402 int timer_int3; // 10
\r
403 unsigned int timer_stopwatch;
\r
404 unsigned char bcram_reg; // 18: battery-backed RAM cart register
\r
405 unsigned char pad2;
\r
406 unsigned short pad3;
\r
412 unsigned char bios[0x20000]; // 000000: 128K
\r
413 union { // 020000: 512K
\r
414 unsigned char prg_ram[0x80000];
\r
415 unsigned char prg_ram_b[4][0x20000];
\r
417 union { // 0a0000: 256K
\r
419 unsigned char word_ram2M[0x40000];
\r
420 unsigned char unused0[0x20000];
\r
423 unsigned char unused1[0x20000];
\r
424 unsigned char word_ram1M[2][0x20000];
\r
427 union { // 100000: 64K
\r
428 unsigned char pcm_ram[0x10000];
\r
429 unsigned char pcm_ram_b[0x10][0x1000];
\r
431 unsigned char s68k_regs[0x200]; // 110000: GA, not CPU regs
\r
432 unsigned char bram[0x2000]; // 110200: 8K
\r
433 struct mcd_misc m; // 112200: misc
\r
434 struct mcd_pcm pcm; // 112240:
\r
435 _scd_toc TOC; // not to be saved
\r
442 // XXX: this will need to be reworked for cart+cd support.
\r
443 #define Pico_mcd ((mcd_state *)Pico.rom)
\r
446 #define P32XS_FM (1<<15)
\r
447 #define P32XS_REN (1<< 7)
\r
448 #define P32XS_nRES (1<< 1)
\r
449 #define P32XS_ADEN (1<< 0)
\r
450 #define P32XS2_ADEN (1<< 9)
\r
451 #define P32XS_FULL (1<< 7) // DREQ FIFO full
\r
452 #define P32XS_68S (1<< 2)
\r
453 #define P32XS_DMA (1<< 1)
\r
454 #define P32XS_RV (1<< 0)
\r
456 #define P32XV_nPAL (1<<15) // VDP
\r
457 #define P32XV_PRI (1<< 7)
\r
458 #define P32XV_Mx (3<< 0) // display mode mask
\r
460 #define P32XV_SFT (1<< 0)
\r
462 #define P32XV_VBLK (1<<15)
\r
463 #define P32XV_HBLK (1<<14)
\r
464 #define P32XV_PEN (1<<13)
\r
465 #define P32XV_nFEN (1<< 1)
\r
466 #define P32XV_FS (1<< 0)
\r
468 #define P32XP_FULL (1<<15) // PWM
\r
469 #define P32XP_EMPTY (1<<14)
\r
471 #define P32XF_68KCPOLL (1 << 0)
\r
472 #define P32XF_68KVPOLL (1 << 1)
\r
473 #define P32XF_PWM_PEND (1 << 6)
\r
475 #define P32XI_VRES (1 << 14/2) // IRL/2
\r
476 #define P32XI_VINT (1 << 12/2)
\r
477 #define P32XI_HINT (1 << 10/2)
\r
478 #define P32XI_CMD (1 << 8/2)
\r
479 #define P32XI_PWM (1 << 6/2)
\r
481 // peripheral reg access
\r
482 #define PREG8(regs,offs) ((unsigned char *)regs)[offs ^ 3]
\r
484 // real one is 4*2, but we use more because we don't lockstep
\r
485 #define DMAC_FIFO_LEN (4*4)
\r
486 #define PWM_BUFF_LEN 1024 // in one channel samples
\r
488 #define SH2_DRCBLK_RAM_SHIFT 1
\r
489 #define SH2_DRCBLK_DA_SHIFT 1
\r
491 #define SH2_WRITE_SHIFT 25
\r
495 unsigned short regs[0x20];
\r
496 unsigned short vdp_regs[0x10]; // 0x40
\r
497 unsigned short sh2_regs[3]; // 0x60
\r
498 unsigned char pending_fb;
\r
499 unsigned char dirty_pal;
\r
500 unsigned int emu_flags;
\r
501 unsigned char sh2irq_mask[2];
\r
502 unsigned char sh2irqi[2]; // individual
\r
503 unsigned int sh2irqs; // common irqs
\r
504 unsigned short dmac_fifo[DMAC_FIFO_LEN];
\r
505 unsigned int dmac_ptr;
\r
506 unsigned int pwm_irq_sample_cnt;
\r
507 unsigned char comm_dirty_68k;
\r
508 unsigned char comm_dirty_sh2;
\r
509 unsigned short pad;
\r
510 unsigned int reserved[8];
\r
515 unsigned char sdram[0x40000];
\r
517 unsigned short drcblk_ram[1 << (18 - SH2_DRCBLK_RAM_SHIFT)];
\r
519 unsigned short dram[2][0x20000/2]; // AKA fb
\r
521 unsigned char m68k_rom[0x100];
\r
522 unsigned char m68k_rom_bank[0x10000]; // M68K_BANK_SIZE
\r
524 unsigned char data_array[2][0x1000]; // cache in SH2s (can be used as RAM)
\r
526 unsigned short drcblk_da[2][1 << (12 - SH2_DRCBLK_DA_SHIFT)];
\r
528 unsigned char sh2_rom_m[0x800];
\r
529 unsigned char sh2_rom_s[0x400];
\r
530 unsigned short pal[0x100];
\r
531 unsigned short pal_native[0x100]; // converted to native (for renderer)
\r
532 unsigned int sh2_peri_regs[2][0x200/4]; // periphereal regs of SH2s
\r
533 signed short pwm[2*PWM_BUFF_LEN]; // PWM buffer for current frame
\r
537 extern void (*PicoLoadStateHook)(void);
\r
543 } carthw_state_chunk;
\r
544 extern carthw_state_chunk *carthw_chunks;
\r
545 #define CHUNK_CARTHW 64
\r
548 extern int PicoCartResize(int newsize);
\r
549 extern void Byteswap(void *dst, const void *src, int len);
\r
550 extern void (*PicoCartMemSetup)(void);
\r
551 extern void (*PicoCartUnloadHook)(void);
\r
554 int CM_compareRun(int cyc, int is_sub);
\r
557 PICO_INTERNAL void PicoFrameStart(void);
\r
558 void PicoDrawSync(int to, int blank_last_line);
\r
559 void BackFill(int reg7, int sh);
\r
560 void FinalizeLine555(int sh, int line);
\r
561 extern int (*PicoScanBegin)(unsigned int num);
\r
562 extern int (*PicoScanEnd)(unsigned int num);
\r
563 extern int DrawScanline;
\r
564 #define MAX_LINE_SPRITES 29
\r
565 extern unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES];
\r
566 extern void *DrawLineDestBase;
\r
567 extern int DrawLineDestIncrement;
\r
570 PICO_INTERNAL void PicoFrameFull();
\r
573 void PicoFrameStartMode4(void);
\r
574 void PicoLineMode4(int line);
\r
575 void PicoDoHighPal555M4(void);
\r
576 void PicoDrawSetOutputMode4(pdso_t which);
\r
579 PICO_INTERNAL void PicoMemSetup(void);
\r
580 unsigned int PicoRead8_io(unsigned int a);
\r
581 unsigned int PicoRead16_io(unsigned int a);
\r
582 void PicoWrite8_io(unsigned int a, unsigned int d);
\r
583 void PicoWrite16_io(unsigned int a, unsigned int d);
\r
586 PICO_INTERNAL void PicoMemSetupPico(void);
\r
589 PICO_INTERNAL void PicoMemSetupCD(void);
\r
590 void PicoMemStateLoaded(void);
\r
593 extern struct Pico Pico;
\r
594 extern struct PicoSRAM SRam;
\r
595 extern int PicoPadInt[2];
\r
596 extern int emustatus;
\r
597 extern int scanlines_total;
\r
598 extern void (*PicoResetHook)(void);
\r
599 extern void (*PicoLineHook)(void);
\r
600 PICO_INTERNAL int CheckDMA(void);
\r
601 PICO_INTERNAL void PicoDetectRegion(void);
\r
602 PICO_INTERNAL void PicoSyncZ80(int m68k_cycles_done);
\r
605 PICO_INTERNAL void PicoInitMCD(void);
\r
606 PICO_INTERNAL void PicoExitMCD(void);
\r
607 PICO_INTERNAL void PicoPowerMCD(void);
\r
608 PICO_INTERNAL int PicoResetMCD(void);
\r
609 PICO_INTERNAL void PicoFrameMCD(void);
\r
612 PICO_INTERNAL void PicoInitPico(void);
\r
613 PICO_INTERNAL void PicoReratePico(void);
\r
616 PICO_INTERNAL void PicoPicoPCMUpdate(short *buffer, int length, int stereo);
\r
617 PICO_INTERNAL void PicoPicoPCMReset(void);
\r
618 PICO_INTERNAL void PicoPicoPCMRerate(int xpcm_rate);
\r
621 PICO_INTERNAL void SekInit(void);
\r
622 PICO_INTERNAL int SekReset(void);
\r
623 PICO_INTERNAL void SekState(int *data);
\r
624 PICO_INTERNAL void SekSetRealTAS(int use_real);
\r
625 PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub);
\r
626 PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub);
\r
627 void SekStepM68k(void);
\r
628 void SekInitIdleDet(void);
\r
629 void SekFinishIdleDet(void);
\r
632 PICO_INTERNAL void SekInitS68k(void);
\r
633 PICO_INTERNAL int SekResetS68k(void);
\r
634 PICO_INTERNAL int SekInterruptS68k(int irq);
\r
637 PICO_INTERNAL void cdda_start_play();
\r
638 extern short cdda_out_buffer[2*1152];
\r
639 extern int PsndLen_exc_cnt;
\r
640 extern int PsndLen_exc_add;
\r
641 extern int timer_a_next_oflow, timer_a_step; // in z80 cycles
\r
642 extern int timer_b_next_oflow, timer_b_step;
\r
644 void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new);
\r
645 void ym2612_pack_state(void);
\r
646 void ym2612_unpack_state(void);
\r
648 #define TIMER_NO_OFLOW 0x70000000
\r
649 // tA = 72 * (1024 - NA) / M
\r
650 #define TIMER_A_TICK_ZCYCLES 17203
\r
651 // tB = 1152 * (256 - NA) / M
\r
652 #define TIMER_B_TICK_ZCYCLES 262800 // 275251 broken, see Dai Makaimura
\r
654 #define timers_cycle() \
\r
655 if (timer_a_next_oflow > 0 && timer_a_next_oflow < TIMER_NO_OFLOW) \
\r
656 timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
\r
657 if (timer_b_next_oflow > 0 && timer_b_next_oflow < TIMER_NO_OFLOW) \
\r
658 timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
\r
659 ym2612_sync_timers(0, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode);
\r
661 #define timers_reset() \
\r
662 timer_a_next_oflow = timer_b_next_oflow = TIMER_NO_OFLOW; \
\r
663 timer_a_step = TIMER_A_TICK_ZCYCLES * 1024; \
\r
664 timer_b_step = TIMER_B_TICK_ZCYCLES * 256;
\r
668 PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d);
\r
669 PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a);
\r
670 PICO_INTERNAL_ASM unsigned int PicoVideoRead8(unsigned int a);
\r
671 extern int (*PicoDmaHook)(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp);
\r
674 PICO_INTERNAL_ASM void memcpy16(unsigned short *dest, unsigned short *src, int count);
\r
675 PICO_INTERNAL_ASM void memcpy16bswap(unsigned short *dest, void *src, int count);
\r
676 PICO_INTERNAL_ASM void memcpy32(int *dest, int *src, int count); // 32bit word count
\r
677 PICO_INTERNAL_ASM void memset32(int *dest, int c, int count);
\r
680 void EEPROM_write8(unsigned int a, unsigned int d);
\r
681 void EEPROM_write16(unsigned int d);
\r
682 unsigned int EEPROM_read(void);
\r
684 // z80 functionality wrappers
\r
685 PICO_INTERNAL void z80_init(void);
\r
686 PICO_INTERNAL void z80_pack(void *data);
\r
687 PICO_INTERNAL int z80_unpack(const void *data);
\r
688 PICO_INTERNAL void z80_reset(void);
\r
689 PICO_INTERNAL void z80_exit(void);
\r
692 PICO_INTERNAL_ASM void wram_2M_to_1M(unsigned char *m);
\r
693 PICO_INTERNAL_ASM void wram_1M_to_2M(unsigned char *m);
\r
696 PICO_INTERNAL void PicoCDBufferRead(void *dest, int lba);
\r
699 PICO_INTERNAL void PsndReset(void);
\r
700 PICO_INTERNAL void PsndDoDAC(int line_to);
\r
701 PICO_INTERNAL void PsndClear(void);
\r
702 PICO_INTERNAL void PsndGetSamples(int y);
\r
703 PICO_INTERNAL void PsndGetSamplesMS(void);
\r
704 extern int PsndDacLine;
\r
708 void PicoPowerMS(void);
\r
709 void PicoResetMS(void);
\r
710 void PicoMemSetupMS(void);
\r
711 void PicoStateLoadedMS(void);
\r
712 void PicoFrameMS(void);
\r
713 void PicoFrameDrawOnlyMS(void);
\r
715 #define PicoPowerMS()
\r
716 #define PicoResetMS()
\r
717 #define PicoMemSetupMS()
\r
718 #define PicoStateLoadedMS()
\r
719 #define PicoFrameMS()
\r
720 #define PicoFrameDrawOnlyMS()
\r
725 extern struct Pico32x Pico32x;
\r
728 P32X_EVENT_FILLEND,
\r
731 extern unsigned int event_times[P32X_EVENT_COUNT];
\r
733 void Pico32xInit(void);
\r
734 void PicoPower32x(void);
\r
735 void PicoReset32x(void);
\r
736 void Pico32xStartup(void);
\r
737 void PicoUnload32x(void);
\r
738 void PicoFrame32x(void);
\r
739 void Pico32xStateLoaded(int is_early);
\r
740 void p32x_sync_sh2s(unsigned int m68k_target);
\r
741 void p32x_sync_other_sh2(SH2 *sh2, unsigned int m68k_target);
\r
742 void p32x_update_irls(SH2 *active_sh2);
\r
743 void p32x_reset_sh2s(void);
\r
744 void p32x_event_schedule(unsigned int now, enum p32x_event event, int after);
\r
745 void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after);
\r
748 struct Pico32xMem *Pico32xMem;
\r
749 unsigned int PicoRead8_32x(unsigned int a);
\r
750 unsigned int PicoRead16_32x(unsigned int a);
\r
751 void PicoWrite8_32x(unsigned int a, unsigned int d);
\r
752 void PicoWrite16_32x(unsigned int a, unsigned int d);
\r
753 void PicoMemSetup32x(void);
\r
754 void Pico32xSwapDRAM(int b);
\r
755 void Pico32xMemStateLoaded(void);
\r
756 void p32x_m68k_poll_event(unsigned int flags);
\r
757 void p32x_sh2_poll_event(SH2 *sh2, unsigned int flags, unsigned int m68k_cycles);
\r
760 void PicoDrawSetOutFormat32x(pdso_t which, int use_32x_line_mode);
\r
761 void FinalizeLine32xRGB555(int sh, int line);
\r
762 void PicoDraw32xLayer(int offs, int lines, int mdbg);
\r
763 void PicoDraw32xLayerMdOnly(int offs, int lines);
\r
764 extern int (*PicoScan32xBegin)(unsigned int num);
\r
765 extern int (*PicoScan32xEnd)(unsigned int num);
\r
771 extern int Pico32xDrawMode;
\r
774 unsigned int p32x_pwm_read16(unsigned int a);
\r
775 void p32x_pwm_write16(unsigned int a, unsigned int d);
\r
776 void p32x_pwm_update(int *buf32, int length, int stereo);
\r
777 void p32x_timers_do(unsigned int cycles);
\r
778 void p32x_timers_recalc(void);
\r
779 void p32x_pwm_schedule(unsigned int now);
\r
780 void p32x_pwm_schedule_sh2(SH2 *sh2);
\r
782 #define Pico32xInit()
\r
783 #define PicoPower32x()
\r
784 #define PicoReset32x()
\r
785 #define PicoFrame32x()
\r
786 #define PicoUnload32x()
\r
787 #define Pico32xStateLoaded()
\r
788 #define FinalizeLine32xRGB555 NULL
\r
789 #define p32x_pwm_update(...)
\r
790 #define p32x_timers_recalc()
\r
793 /* avoid dependency on newer glibc */
\r
794 static __inline int isspace_(int c)
\r
796 return (0x09 <= c && c <= 0x0d) || c == ' ';
\r
800 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
\r
803 // emulation event logging
\r
805 # ifdef __x86_64__ // HACK
\r
806 # define EL_LOGMASK (EL_STATUS|EL_IDLE|EL_ANOMALY)
\r
808 # define EL_LOGMASK (EL_STATUS)
\r
812 #define EL_HVCNT 0x00000001 /* hv counter reads */
\r
813 #define EL_SR 0x00000002 /* SR reads */
\r
814 #define EL_INTS 0x00000004 /* ints and acks */
\r
815 #define EL_YMTIMER 0x00000008 /* ym2612 timer stuff */
\r
816 #define EL_INTSW 0x00000010 /* log irq switching on/off */
\r
817 #define EL_ASVDP 0x00000020 /* VDP accesses during active scan */
\r
818 #define EL_VDPDMA 0x00000040 /* VDP DMA transfers and their timing */
\r
819 #define EL_BUSREQ 0x00000080 /* z80 busreq r/w or reset w */
\r
820 #define EL_Z80BNK 0x00000100 /* z80 i/o through bank area */
\r
821 #define EL_SRAMIO 0x00000200 /* sram i/o */
\r
822 #define EL_EEPROM 0x00000400 /* eeprom debug */
\r
823 #define EL_UIO 0x00000800 /* unmapped i/o */
\r
824 #define EL_IO 0x00001000 /* all i/o */
\r
825 #define EL_CDPOLL 0x00002000 /* MCD: log poll detection */
\r
826 #define EL_SVP 0x00004000 /* SVP stuff */
\r
827 #define EL_PICOHW 0x00008000 /* Pico stuff */
\r
828 #define EL_IDLE 0x00010000 /* idle loop det. */
\r
829 #define EL_CDREGS 0x00020000 /* MCD: register access */
\r
830 #define EL_CDREG3 0x00040000 /* MCD: register 3 only */
\r
831 #define EL_32X 0x00080000
\r
832 #define EL_PWM 0x00100000 /* 32X PWM stuff (LOTS of output) */
\r
834 #define EL_STATUS 0x40000000 /* status messages */
\r
835 #define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */
\r
838 #define elprintf(w,f,...) \
\r
840 if ((w) & EL_LOGMASK) \
\r
841 lprintf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__); \
\r
843 #elif defined(_MSC_VER)
\r
846 #define elprintf(w,f,...)
\r
851 #include <platform/linux/pprof.h>
\r
853 #define pprof_init()
\r
854 #define pprof_finish()
\r
855 #define pprof_start(x)
\r
856 #define pprof_end(...)
\r
857 #define pprof_end_sub(...)
\r
879 void pevt_log(unsigned int cycles, enum evt_cpu c, enum evt e);
\r
880 void pevt_dump(void);
\r
882 #define pevt_log_m68k(e) \
\r
883 pevt_log(SekCyclesDoneT(), EVT_M68K, e)
\r
884 #define pevt_log_m68k_o(e) \
\r
885 pevt_log(SekCyclesDoneT2(), EVT_M68K, e)
\r
886 #define pevt_log_sh2(sh2, e) \
\r
887 pevt_log(sh2_cycles_done_m68k(sh2), EVT_MSH2 + (sh2)->is_slave, e)
\r
888 #define pevt_log_sh2_o(sh2, e) \
\r
889 pevt_log((sh2)->m68krcycles_done, EVT_MSH2 + (sh2)->is_slave, e)
\r
891 #define pevt_log(c, e)
\r
892 #define pevt_log_m68k(e)
\r
893 #define pevt_log_m68k_o(e)
\r
894 #define pevt_log_sh2(sh2, e)
\r
895 #define pevt_log_sh2_o(sh2, e)
\r
896 #define pevt_dump()
\r
903 #define cdprintf(x...)
\r
907 #define REGPARM(x) __attribute__((regparm(x)))
\r
913 #define NOINLINE __attribute__((noinline))
\r
919 } // End of extern "C"
\r
922 #endif // PICO_INTERNAL_INCLUDED
\r