1 // Pico Library - Internal Header File
\r
3 // (c) Copyright 2004 Dave, All rights reserved.
\r
4 // (c) Copyright 2006-2009 Grazvydas "notaz" Ignotas, all rights reserved.
\r
5 // Free for non-commercial use.
\r
7 // For commercial use, separate licencing terms must be obtained.
\r
9 #ifndef PICO_INTERNAL_INCLUDED
\r
10 #define PICO_INTERNAL_INCLUDED
\r
16 #include "carthw/carthw.h"
\r
19 #define USE_POLL_DETECT
\r
21 #ifndef PICO_INTERNAL
\r
22 #define PICO_INTERNAL
\r
24 #ifndef PICO_INTERNAL_ASM
\r
25 #define PICO_INTERNAL_ASM
\r
28 // to select core, define EMU_C68K, EMU_M68K or EMU_F68K in your makefile or project
\r
35 // ----------------------- 68000 CPU -----------------------
\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 SekEndTimeslice(after) PicoCpuCM68k.cycles=after
\r
45 #define SekEndTimesliceS68k(after) PicoCpuCS68k.cycles=after
\r
46 #define SekPc (PicoCpuCM68k.pc-PicoCpuCM68k.membase)
\r
47 #define SekPcS68k (PicoCpuCS68k.pc-PicoCpuCS68k.membase)
\r
48 #define SekDar(x) PicoCpuCM68k.d[x]
\r
49 #define SekSr CycloneGetSr(&PicoCpuCM68k)
\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
55 #define SekInterrupt(i) PicoCpuCM68k.irq=i
\r
56 #define SekIrqLevel PicoCpuCM68k.irq
\r
59 #define EMU_CORE_DEBUG
\r
64 #include "../cpu/fame/fame.h"
\r
65 extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k;
\r
66 #define SekCyclesLeftNoMCD PicoCpuFM68k.io_cycle_counter
\r
67 #define SekCyclesLeft \
\r
68 (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)
\r
69 #define SekCyclesLeftS68k \
\r
70 ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuFS68k.io_cycle_counter)
\r
71 #define SekEndTimeslice(after) PicoCpuFM68k.io_cycle_counter=after
\r
72 #define SekEndTimesliceS68k(after) PicoCpuFS68k.io_cycle_counter=after
\r
73 #define SekPc fm68k_get_pc(&PicoCpuFM68k)
\r
74 #define SekPcS68k fm68k_get_pc(&PicoCpuFS68k)
\r
75 #define SekDar(x) PicoCpuFM68k.dreg[x].D
\r
76 #define SekSr PicoCpuFM68k.sr
\r
77 #define SekSetStop(x) { \
\r
78 PicoCpuFM68k.execinfo &= ~FM68K_HALTED; \
\r
79 if (x) { PicoCpuFM68k.execinfo |= FM68K_HALTED; PicoCpuFM68k.io_cycle_counter = 0; } \
\r
81 #define SekSetStopS68k(x) { \
\r
82 PicoCpuFS68k.execinfo &= ~FM68K_HALTED; \
\r
83 if (x) { PicoCpuFS68k.execinfo |= FM68K_HALTED; PicoCpuFS68k.io_cycle_counter = 0; } \
\r
85 #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED)
\r
86 #define SekShouldInterrupt fm68k_would_interrupt()
\r
88 #define SekInterrupt(irq) PicoCpuFM68k.interrupts[0]=irq
\r
89 #define SekIrqLevel PicoCpuFM68k.interrupts[0]
\r
92 #define EMU_CORE_DEBUG
\r
97 #include "../cpu/musashi/m68kcpu.h"
\r
98 extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k;
\r
99 #ifndef SekCyclesLeft
\r
100 #define SekCyclesLeftNoMCD PicoCpuMM68k.cyc_remaining_cycles
\r
101 #define SekCyclesLeft \
\r
102 (((PicoAHW&1) && (PicoOpt & POPT_EN_MCD_PSYNC)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)
\r
103 #define SekCyclesLeftS68k \
\r
104 ((PicoOpt & POPT_EN_MCD_PSYNC) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuMS68k.cyc_remaining_cycles)
\r
105 #define SekEndTimeslice(after) SET_CYCLES(after)
\r
106 #define SekEndTimesliceS68k(after) PicoCpuMS68k.cyc_remaining_cycles=after
\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 SekDar(x) PicoCpuMM68k.dar[x]
\r
110 #define SekSr m68k_get_reg(&PicoCpuMM68k, M68K_REG_SR)
\r
111 #define SekSetStop(x) { \
\r
112 if(x) { SET_CYCLES(0); PicoCpuMM68k.stopped=STOP_LEVEL_STOP; } \
\r
113 else PicoCpuMM68k.stopped=0; \
\r
115 #define SekSetStopS68k(x) { \
\r
116 if(x) { SET_CYCLES(0); PicoCpuMS68k.stopped=STOP_LEVEL_STOP; } \
\r
117 else PicoCpuMS68k.stopped=0; \
\r
119 #define SekIsStoppedS68k() (PicoCpuMS68k.stopped==STOP_LEVEL_STOP)
\r
120 #define SekShouldInterrupt (CPU_INT_LEVEL > FLAG_INT_MASK)
\r
122 #define SekInterrupt(irq) { \
\r
123 void *oldcontext = m68ki_cpu_p; \
\r
124 m68k_set_context(&PicoCpuMM68k); \
\r
125 m68k_set_irq(irq); \
\r
126 m68k_set_context(oldcontext); \
\r
128 #define SekIrqLevel (PicoCpuMM68k.int_level >> 8)
\r
133 extern int SekCycleCnt; // cycles done in this frame
\r
134 extern int SekCycleAim; // cycle aim
\r
135 extern unsigned int SekCycleCntT; // total cycle counter, updated once per frame
\r
137 #define SekCyclesReset() { \
\r
138 SekCycleCntT+=SekCycleAim; \
\r
139 SekCycleCnt-=SekCycleAim; \
\r
142 #define SekCyclesBurn(c) SekCycleCnt+=c
\r
143 #define SekCyclesDone() (SekCycleAim-SekCyclesLeft) // number of cycles done in this frame (can be checked anywhere)
\r
144 #define SekCyclesDoneT() (SekCycleCntT+SekCyclesDone()) // total nuber of cycles done for this rom
\r
146 #define SekEndRun(after) { \
\r
147 SekCycleCnt -= SekCyclesLeft - (after); \
\r
148 if (SekCycleCnt < 0) SekCycleCnt = 0; \
\r
149 SekEndTimeslice(after); \
\r
152 #define SekEndRunS68k(after) { \
\r
153 SekCycleCntS68k -= SekCyclesLeftS68k - (after); \
\r
154 if (SekCycleCntS68k < 0) SekCycleCntS68k = 0; \
\r
155 SekEndTimesliceS68k(after); \
\r
158 extern int SekCycleCntS68k;
\r
159 extern int SekCycleAimS68k;
\r
161 #define SekCyclesResetS68k() { \
\r
162 SekCycleCntS68k-=SekCycleAimS68k; \
\r
163 SekCycleAimS68k=0; \
\r
165 #define SekCyclesDoneS68k() (SekCycleAimS68k-SekCyclesLeftS68k)
\r
167 #ifdef EMU_CORE_DEBUG
\r
168 extern int dbg_irq_level;
\r
169 #undef SekEndTimeslice
\r
170 #undef SekCyclesBurn
\r
172 #undef SekInterrupt
\r
173 #define SekEndTimeslice(c)
\r
174 #define SekCyclesBurn(c) c
\r
175 #define SekEndRun(c)
\r
176 #define SekInterrupt(irq) dbg_irq_level=irq
\r
179 // ----------------------- Z80 CPU -----------------------
\r
181 #if defined(_USE_DRZ80)
\r
182 #include "../cpu/DrZ80/drz80.h"
\r
184 extern struct DrZ80 drZ80;
\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
190 #define z80_cyclesLeft drZ80.cycles
\r
191 #define z80_pc() (drZ80.Z80PC - drZ80.Z80PC_BASE)
\r
193 #elif defined(_USE_CZ80)
\r
194 #include "../cpu/cz80/cz80.h"
\r
196 #define z80_run(cycles) Cz80_Exec(&CZ80, cycles)
\r
197 #define z80_run_nr(cycles) Cz80_Exec(&CZ80, cycles)
\r
198 #define z80_int() Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE)
\r
200 #define z80_cyclesLeft (CZ80.ICount - CZ80.ExtraCycles)
\r
201 #define z80_pc() Cz80_Get_Reg(&CZ80, CZ80_PC)
\r
205 #define z80_run(cycles) (cycles)
\r
206 #define z80_run_nr(cycles)
\r
211 #define Z80_STATE_SIZE 0x60
\r
213 extern int z80stopCycle; /* in 68k cycles */
\r
214 extern int z80_cycle_cnt; /* 'done' z80 cycles before z80_run() */
\r
215 extern int z80_cycle_aim;
\r
216 extern int z80_scanline;
\r
217 extern int z80_scanline_cycles; /* cycles done until z80_scanline */
\r
219 #define z80_resetCycles() \
\r
220 z80_cycle_cnt = z80_cycle_aim = z80_scanline = z80_scanline_cycles = 0;
\r
222 #define z80_cyclesDone() \
\r
223 (z80_cycle_aim - z80_cyclesLeft)
\r
225 #define cycles_68k_to_z80(x) ((x)*957 >> 11)
\r
227 // ----------------------- SH2 CPU -----------------------
\r
229 #include "cpu/sh2/sh2.h"
\r
231 extern SH2 sh2s[2];
\r
232 #define msh2 sh2s[0]
\r
233 #define ssh2 sh2s[1]
\r
236 # define ash2_end_run(after) if (sh2->icount > (after)) sh2->icount = after
\r
237 # define ash2_cycles_done() (sh2->cycles_aim - sh2->icount)
\r
239 # define ash2_end_run(after) { \
\r
240 if ((sh2->sr >> 12) > (after)) \
\r
241 { sh2->sr &= 0xfff; sh2->sr |= (after) << 12; } \
\r
243 # define ash2_cycles_done() (sh2->cycles_aim - (sh2->sr >> 12))
\r
246 //#define sh2_pc(c) (c) ? ssh2.ppc : msh2.ppc
\r
247 #define sh2_pc(c) (c) ? ssh2.pc : msh2.pc
\r
248 #define sh2_reg(c, x) (c) ? ssh2.r[x] : msh2.r[x]
\r
249 #define sh2_gbr(c) (c) ? ssh2.gbr : msh2.gbr
\r
250 #define sh2_vbr(c) (c) ? ssh2.vbr : msh2.vbr
\r
251 #define sh2_sr(c) (((c) ? ssh2.sr : msh2.sr) & 0xfff)
\r
253 #define sh2_set_gbr(c, v) \
\r
254 { if (c) ssh2.gbr = v; else msh2.gbr = v; }
\r
255 #define sh2_set_vbr(c, v) \
\r
256 { if (c) ssh2.vbr = v; else msh2.vbr = v; }
\r
258 // ---------------------------------------------------------
\r
260 // main oscillator clock which controls timing
\r
261 #define OSC_NTSC 53693100
\r
262 #define OSC_PAL 53203424
\r
266 unsigned char reg[0x20];
\r
267 unsigned int command; // 32-bit Command
\r
268 unsigned char pending; // 1 if waiting for second half of 32-bit command
\r
269 unsigned char type; // Command type (v/c/vsram read/write)
\r
270 unsigned short addr; // Read/Write address
\r
271 int status; // Status bits
\r
272 unsigned char pending_ints; // pending interrupts: ??VH????
\r
273 signed char lwrite_cnt; // VDP write count during active display line
\r
274 unsigned short v_counter; // V-counter
\r
275 unsigned char pad[0x10];
\r
280 unsigned char rotate;
\r
281 unsigned char z80Run;
\r
282 unsigned char padTHPhase[2]; // 02 phase of gamepad TH switches
\r
283 unsigned short scanline; // 04 0 to 261||311
\r
284 char dirtyPal; // 06 Is the palette dirty (1 - change @ this frame, 2 - some time before)
\r
285 unsigned char hardware; // 07 Hardware value for country
\r
286 unsigned char pal; // 08 1=PAL 0=NTSC
\r
287 unsigned char sram_reg; // 09 SRAM reg. See SRR_* below
\r
288 unsigned short z80_bank68k; // 0a
\r
289 unsigned short pad0;
\r
290 unsigned char pad1;
\r
291 unsigned char z80_reset; // 0f z80 reset held
\r
292 unsigned char padDelay[2]; // 10 gamepad phase time outs, so we count a delay
\r
293 unsigned short eeprom_addr; // EEPROM address register
\r
294 unsigned char eeprom_cycle; // EEPROM cycle number
\r
295 unsigned char eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs
\r
296 unsigned char eeprom_status;
\r
297 unsigned char pad2;
\r
298 unsigned short dma_xfers; // 18
\r
299 unsigned char eeprom_wb[2]; // EEPROM latch/write buffer
\r
300 unsigned int frame_count; // 1c for movies and idle det
\r
305 unsigned char carthw[0x10];
\r
306 unsigned char io_ctl;
\r
307 unsigned char pad[0x4f];
\r
310 // some assembly stuff depend on these, do not touch!
\r
313 unsigned char ram[0x10000]; // 0x00000 scratch ram
\r
314 union { // vram is byteswapped for easier reads when drawing
\r
315 unsigned short vram[0x8000]; // 0x10000
\r
316 unsigned char vramb[0x4000]; // VRAM in SMS mode
\r
318 unsigned char zram[0x2000]; // 0x20000 Z80 ram
\r
319 unsigned char ioports[0x10]; // XXX: fix asm and mv
\r
320 unsigned char pad[0xf0]; // unused
\r
321 unsigned short cram[0x40]; // 0x22100
\r
322 unsigned short vsram[0x40]; // 0x22180
\r
324 unsigned char *rom; // 0x22200
\r
325 unsigned int romsize; // 0x22204
\r
328 struct PicoVideo video;
\r
333 #define SRR_MAPPED (1 << 0)
\r
334 #define SRR_READONLY (1 << 1)
\r
336 #define SRF_ENABLED (1 << 0)
\r
337 #define SRF_EEPROM (1 << 1)
\r
341 unsigned char *data; // actual data
\r
342 unsigned int start; // start address in 68k address space
\r
344 unsigned char flags; // 0c: SRF_*
\r
345 unsigned char unused2;
\r
346 unsigned char changed;
\r
347 unsigned char eeprom_type; // eeprom type: 0: 7bit (24C01), 2: 2 addr words (X24C02+), 3: 3 addr words
\r
348 unsigned char unused3;
\r
349 unsigned char eeprom_bit_cl; // bit number for cl
\r
350 unsigned char eeprom_bit_in; // bit number for in
\r
351 unsigned char eeprom_bit_out; // bit number for out
\r
356 #include "cd/cd_sys.h"
\r
357 #include "cd/LC89510.h"
\r
358 #include "cd/gfx_cd.h"
\r
362 unsigned char control; // reg7
\r
363 unsigned char enabled; // reg8
\r
364 unsigned char cur_ch;
\r
365 unsigned char bank;
\r
368 struct pcm_chan // 08, size 0x10
\r
370 unsigned char regs[8];
\r
371 unsigned int addr; // .08: played sample address
\r
378 unsigned short hint_vector;
\r
379 unsigned char busreq;
\r
380 unsigned char s68k_pend_ints;
\r
381 unsigned int state_flags; // 04: emu state: reset_pending
\r
382 unsigned int counter75hz;
\r
384 int timer_int3; // 10
\r
385 unsigned int timer_stopwatch;
\r
386 unsigned char bcram_reg; // 18: battery-backed RAM cart register
\r
387 unsigned char pad2;
\r
388 unsigned short pad3;
\r
394 unsigned char bios[0x20000]; // 000000: 128K
\r
395 union { // 020000: 512K
\r
396 unsigned char prg_ram[0x80000];
\r
397 unsigned char prg_ram_b[4][0x20000];
\r
399 union { // 0a0000: 256K
\r
401 unsigned char word_ram2M[0x40000];
\r
402 unsigned char unused0[0x20000];
\r
405 unsigned char unused1[0x20000];
\r
406 unsigned char word_ram1M[2][0x20000];
\r
409 union { // 100000: 64K
\r
410 unsigned char pcm_ram[0x10000];
\r
411 unsigned char pcm_ram_b[0x10][0x1000];
\r
413 unsigned char s68k_regs[0x200]; // 110000: GA, not CPU regs
\r
414 unsigned char bram[0x2000]; // 110200: 8K
\r
415 struct mcd_misc m; // 112200: misc
\r
416 struct mcd_pcm pcm; // 112240:
\r
417 _scd_toc TOC; // not to be saved
\r
424 // XXX: this will need to be reworked for cart+cd support.
\r
425 #define Pico_mcd ((mcd_state *)Pico.rom)
\r
428 #define P32XS_FM (1<<15)
\r
429 #define P32XS_REN (1<< 7)
\r
430 #define P32XS_nRES (1<< 1)
\r
431 #define P32XS_ADEN (1<< 0)
\r
432 #define P32XS2_ADEN (1<< 9)
\r
433 #define P32XS_FULL (1<< 7) // DREQ FIFO full
\r
434 #define P32XS_68S (1<< 2)
\r
435 #define P32XS_DMA (1<< 1)
\r
436 #define P32XS_RV (1<< 0)
\r
438 #define P32XV_nPAL (1<<15) // VDP
\r
439 #define P32XV_PRI (1<< 7)
\r
440 #define P32XV_Mx (3<< 0) // display mode mask
\r
442 #define P32XV_SFT (1<< 0)
\r
444 #define P32XV_VBLK (1<<15)
\r
445 #define P32XV_HBLK (1<<14)
\r
446 #define P32XV_PEN (1<<13)
\r
447 #define P32XV_nFEN (1<< 1)
\r
448 #define P32XV_FS (1<< 0)
\r
450 #define P32XP_FULL (1<<15) // PWM
\r
451 #define P32XP_EMPTY (1<<14)
\r
453 #define P32XF_68KPOLL (1 << 0)
\r
454 #define P32XF_MSH2POLL (1 << 1)
\r
455 #define P32XF_SSH2POLL (1 << 2)
\r
456 #define P32XF_68KVPOLL (1 << 3)
\r
457 #define P32XF_MSH2VPOLL (1 << 4)
\r
458 #define P32XF_SSH2VPOLL (1 << 5)
\r
460 #define P32XI_VRES (1 << 14/2) // IRL/2
\r
461 #define P32XI_VINT (1 << 12/2)
\r
462 #define P32XI_HINT (1 << 10/2)
\r
463 #define P32XI_CMD (1 << 8/2)
\r
464 #define P32XI_PWM (1 << 6/2)
\r
466 // peripheral reg access
\r
467 #define PREG8(regs,offs) ((unsigned char *)regs)[offs ^ 3]
\r
469 // real one is 4*2, but we use more because we don't lockstep
\r
470 #define DMAC_FIFO_LEN (4*4)
\r
471 #define PWM_BUFF_LEN 1024 // in one channel samples
\r
473 #define SH2_DRCBLK_RAM_SHIFT 1
\r
474 #define SH2_DRCBLK_DA_SHIFT 1
\r
476 #define SH2_WRITE_SHIFT 25
\r
480 unsigned short regs[0x20];
\r
481 unsigned short vdp_regs[0x10]; // 0x40
\r
482 unsigned short sh2_regs[3]; // 0x60
\r
483 unsigned char pending_fb;
\r
484 unsigned char dirty_pal;
\r
485 unsigned int emu_flags;
\r
486 unsigned char sh2irq_mask[2];
\r
487 unsigned char sh2irqi[2]; // individual
\r
488 unsigned int sh2irqs; // common irqs
\r
489 unsigned short dmac_fifo[DMAC_FIFO_LEN];
\r
490 unsigned int dmac_ptr;
\r
491 unsigned int pwm_irq_sample_cnt;
\r
492 unsigned int reserved[9];
\r
497 unsigned char sdram[0x40000];
\r
499 unsigned short drcblk_ram[1 << (18 - SH2_DRCBLK_RAM_SHIFT)];
\r
501 unsigned short dram[2][0x20000/2]; // AKA fb
\r
503 unsigned char m68k_rom[0x100];
\r
504 unsigned char m68k_rom_bank[0x10000]; // M68K_BANK_SIZE
\r
506 unsigned char data_array[2][0x1000]; // cache in SH2s (can be used as RAM)
\r
508 unsigned short drcblk_da[2][1 << (12 - SH2_DRCBLK_DA_SHIFT)];
\r
510 unsigned char sh2_rom_m[0x800];
\r
511 unsigned char sh2_rom_s[0x400];
\r
512 unsigned short pal[0x100];
\r
513 unsigned short pal_native[0x100]; // converted to native (for renderer)
\r
514 unsigned int sh2_peri_regs[2][0x200/4]; // periphereal regs of SH2s
\r
515 signed short pwm[2*PWM_BUFF_LEN]; // PWM buffer for current frame
\r
519 extern void (*PicoLoadStateHook)(void);
\r
525 } carthw_state_chunk;
\r
526 extern carthw_state_chunk *carthw_chunks;
\r
527 #define CHUNK_CARTHW 64
\r
530 extern int PicoCartResize(int newsize);
\r
531 extern void Byteswap(void *dst, const void *src, int len);
\r
532 extern void (*PicoCartMemSetup)(void);
\r
533 extern void (*PicoCartUnloadHook)(void);
\r
536 int CM_compareRun(int cyc, int is_sub);
\r
539 PICO_INTERNAL void PicoFrameStart(void);
\r
540 void PicoDrawSync(int to, int blank_last_line);
\r
541 void BackFill(int reg7, int sh);
\r
542 void FinalizeLine555(int sh, int line);
\r
543 extern int DrawScanline;
\r
544 #define MAX_LINE_SPRITES 29
\r
545 extern unsigned char HighLnSpr[240][3 + MAX_LINE_SPRITES];
\r
546 extern void *DrawLineDestBase;
\r
547 extern int DrawLineDestIncrement;
\r
550 PICO_INTERNAL void PicoFrameFull();
\r
553 void PicoFrameStartMode4(void);
\r
554 void PicoLineMode4(int line);
\r
555 void PicoDoHighPal555M4(void);
\r
556 void PicoDrawSetOutputMode4(pdso_t which);
\r
559 PICO_INTERNAL void PicoMemSetup(void);
\r
560 unsigned int PicoRead8_io(unsigned int a);
\r
561 unsigned int PicoRead16_io(unsigned int a);
\r
562 void PicoWrite8_io(unsigned int a, unsigned int d);
\r
563 void PicoWrite16_io(unsigned int a, unsigned int d);
\r
566 PICO_INTERNAL void PicoMemSetupPico(void);
\r
569 PICO_INTERNAL void PicoMemSetupCD(void);
\r
570 void PicoMemStateLoaded(void);
\r
573 extern struct Pico Pico;
\r
574 extern struct PicoSRAM SRam;
\r
575 extern int PicoPadInt[2];
\r
576 extern int emustatus;
\r
577 extern int scanlines_total;
\r
578 extern void (*PicoResetHook)(void);
\r
579 extern void (*PicoLineHook)(void);
\r
580 PICO_INTERNAL int CheckDMA(void);
\r
581 PICO_INTERNAL void PicoDetectRegion(void);
\r
582 PICO_INTERNAL void PicoSyncZ80(int m68k_cycles_done);
\r
585 PICO_INTERNAL void PicoInitMCD(void);
\r
586 PICO_INTERNAL void PicoExitMCD(void);
\r
587 PICO_INTERNAL void PicoPowerMCD(void);
\r
588 PICO_INTERNAL int PicoResetMCD(void);
\r
589 PICO_INTERNAL void PicoFrameMCD(void);
\r
592 PICO_INTERNAL void PicoInitPico(void);
\r
593 PICO_INTERNAL void PicoReratePico(void);
\r
596 PICO_INTERNAL void PicoPicoPCMUpdate(short *buffer, int length, int stereo);
\r
597 PICO_INTERNAL void PicoPicoPCMReset(void);
\r
598 PICO_INTERNAL void PicoPicoPCMRerate(int xpcm_rate);
\r
601 PICO_INTERNAL void SekInit(void);
\r
602 PICO_INTERNAL int SekReset(void);
\r
603 PICO_INTERNAL void SekState(int *data);
\r
604 PICO_INTERNAL void SekSetRealTAS(int use_real);
\r
605 PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub);
\r
606 PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub);
\r
607 void SekStepM68k(void);
\r
608 void SekInitIdleDet(void);
\r
609 void SekFinishIdleDet(void);
\r
612 PICO_INTERNAL void SekInitS68k(void);
\r
613 PICO_INTERNAL int SekResetS68k(void);
\r
614 PICO_INTERNAL int SekInterruptS68k(int irq);
\r
617 PICO_INTERNAL void cdda_start_play();
\r
618 extern short cdda_out_buffer[2*1152];
\r
619 extern int PsndLen_exc_cnt;
\r
620 extern int PsndLen_exc_add;
\r
621 extern int timer_a_next_oflow, timer_a_step; // in z80 cycles
\r
622 extern int timer_b_next_oflow, timer_b_step;
\r
624 void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new);
\r
625 void ym2612_pack_state(void);
\r
626 void ym2612_unpack_state(void);
\r
628 #define TIMER_NO_OFLOW 0x70000000
\r
629 // tA = 72 * (1024 - NA) / M
\r
630 #define TIMER_A_TICK_ZCYCLES 17203
\r
631 // tB = 1152 * (256 - NA) / M
\r
632 #define TIMER_B_TICK_ZCYCLES 262800 // 275251 broken, see Dai Makaimura
\r
634 #define timers_cycle() \
\r
635 if (timer_a_next_oflow > 0 && timer_a_next_oflow < TIMER_NO_OFLOW) \
\r
636 timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
\r
637 if (timer_b_next_oflow > 0 && timer_b_next_oflow < TIMER_NO_OFLOW) \
\r
638 timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
\r
639 ym2612_sync_timers(0, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode);
\r
641 #define timers_reset() \
\r
642 timer_a_next_oflow = timer_b_next_oflow = TIMER_NO_OFLOW; \
\r
643 timer_a_step = TIMER_A_TICK_ZCYCLES * 1024; \
\r
644 timer_b_step = TIMER_B_TICK_ZCYCLES * 256;
\r
648 PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d);
\r
649 PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a);
\r
650 PICO_INTERNAL_ASM unsigned int PicoVideoRead8(unsigned int a);
\r
651 extern int (*PicoDmaHook)(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp);
\r
654 PICO_INTERNAL_ASM void memcpy16(unsigned short *dest, unsigned short *src, int count);
\r
655 PICO_INTERNAL_ASM void memcpy16bswap(unsigned short *dest, void *src, int count);
\r
656 PICO_INTERNAL_ASM void memcpy32(int *dest, int *src, int count); // 32bit word count
\r
657 PICO_INTERNAL_ASM void memset32(int *dest, int c, int count);
\r
660 void EEPROM_write8(unsigned int a, unsigned int d);
\r
661 void EEPROM_write16(unsigned int d);
\r
662 unsigned int EEPROM_read(void);
\r
664 // z80 functionality wrappers
\r
665 PICO_INTERNAL void z80_init(void);
\r
666 PICO_INTERNAL void z80_pack(void *data);
\r
667 PICO_INTERNAL int z80_unpack(const void *data);
\r
668 PICO_INTERNAL void z80_reset(void);
\r
669 PICO_INTERNAL void z80_exit(void);
\r
672 PICO_INTERNAL_ASM void wram_2M_to_1M(unsigned char *m);
\r
673 PICO_INTERNAL_ASM void wram_1M_to_2M(unsigned char *m);
\r
676 PICO_INTERNAL void PicoCDBufferRead(void *dest, int lba);
\r
679 PICO_INTERNAL void PsndReset(void);
\r
680 PICO_INTERNAL void PsndDoDAC(int line_to);
\r
681 PICO_INTERNAL void PsndClear(void);
\r
682 PICO_INTERNAL void PsndGetSamples(int y);
\r
683 PICO_INTERNAL void PsndGetSamplesMS(void);
\r
684 extern int PsndDacLine;
\r
688 void PicoPowerMS(void);
\r
689 void PicoResetMS(void);
\r
690 void PicoMemSetupMS(void);
\r
691 void PicoStateLoadedMS(void);
\r
692 void PicoFrameMS(void);
\r
693 void PicoFrameDrawOnlyMS(void);
\r
695 #define PicoPowerMS()
\r
696 #define PicoResetMS()
\r
697 #define PicoMemSetupMS()
\r
698 #define PicoStateLoadedMS()
\r
699 #define PicoFrameMS()
\r
700 #define PicoFrameDrawOnlyMS()
\r
705 extern struct Pico32x Pico32x;
\r
706 void Pico32xInit(void);
\r
707 void PicoPower32x(void);
\r
708 void PicoReset32x(void);
\r
709 void Pico32xStartup(void);
\r
710 void PicoUnload32x(void);
\r
711 void PicoFrame32x(void);
\r
712 void p32x_update_irls(int nested_call);
\r
713 void p32x_reset_sh2s(void);
\r
716 struct Pico32xMem *Pico32xMem;
\r
717 unsigned int PicoRead8_32x(unsigned int a);
\r
718 unsigned int PicoRead16_32x(unsigned int a);
\r
719 void PicoWrite8_32x(unsigned int a, unsigned int d);
\r
720 void PicoWrite16_32x(unsigned int a, unsigned int d);
\r
721 void PicoMemSetup32x(void);
\r
722 void Pico32xSwapDRAM(int b);
\r
723 void Pico32xStateLoaded(void);
\r
724 void p32x_poll_event(int cpu_mask, int is_vdp);
\r
727 void FinalizeLine32xRGB555(int sh, int line);
\r
728 void PicoDraw32xLayer(int offs, int lines, int mdbg);
\r
729 void PicoDraw32xLayerMdOnly(int offs, int lines);
\r
735 extern int Pico32xDrawMode;
\r
738 unsigned int p32x_pwm_read16(unsigned int a);
\r
739 void p32x_pwm_write16(unsigned int a, unsigned int d);
\r
740 void p32x_pwm_update(int *buf32, int length, int stereo);
\r
741 void p32x_timers_do(int line_call);
\r
742 void p32x_timers_recalc(void);
\r
743 extern int pwm_frame_smp_cnt;
\r
745 #define Pico32xInit()
\r
746 #define PicoPower32x()
\r
747 #define PicoReset32x()
\r
748 #define PicoFrame32x()
\r
749 #define PicoUnload32x()
\r
750 #define Pico32xStateLoaded()
\r
751 #define PicoDraw32xSetFrameMode(...)
\r
752 #define FinalizeLine32xRGB555 NULL
\r
753 #define p32x_pwm_update(...)
\r
754 #define p32x_timers_recalc()
\r
757 /* avoid dependency on newer glibc */
\r
758 static __inline int isspace_(int c)
\r
760 return (0x09 <= c && c <= 0x0d) || c == ' ';
\r
764 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
\r
767 // emulation event logging
\r
769 #define EL_LOGMASK 0
\r
772 #define EL_HVCNT 0x00000001 /* hv counter reads */
\r
773 #define EL_SR 0x00000002 /* SR reads */
\r
774 #define EL_INTS 0x00000004 /* ints and acks */
\r
775 #define EL_YMTIMER 0x00000008 /* ym2612 timer stuff */
\r
776 #define EL_INTSW 0x00000010 /* log irq switching on/off */
\r
777 #define EL_ASVDP 0x00000020 /* VDP accesses during active scan */
\r
778 #define EL_VDPDMA 0x00000040 /* VDP DMA transfers and their timing */
\r
779 #define EL_BUSREQ 0x00000080 /* z80 busreq r/w or reset w */
\r
780 #define EL_Z80BNK 0x00000100 /* z80 i/o through bank area */
\r
781 #define EL_SRAMIO 0x00000200 /* sram i/o */
\r
782 #define EL_EEPROM 0x00000400 /* eeprom debug */
\r
783 #define EL_UIO 0x00000800 /* unmapped i/o */
\r
784 #define EL_IO 0x00001000 /* all i/o */
\r
785 #define EL_CDPOLL 0x00002000 /* MCD: log poll detection */
\r
786 #define EL_SVP 0x00004000 /* SVP stuff */
\r
787 #define EL_PICOHW 0x00008000 /* Pico stuff */
\r
788 #define EL_IDLE 0x00010000 /* idle loop det. */
\r
789 #define EL_CDREGS 0x00020000 /* MCD: register access */
\r
790 #define EL_CDREG3 0x00040000 /* MCD: register 3 only */
\r
791 #define EL_32X 0x00080000
\r
792 #define EL_PWM 0x00100000 /* 32X PWM stuff (LOTS of output) */
\r
794 #define EL_STATUS 0x40000000 /* status messages */
\r
795 #define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */
\r
798 extern void lprintf(const char *fmt, ...);
\r
799 #define elprintf(w,f,...) \
\r
801 if ((w) & EL_LOGMASK) \
\r
802 lprintf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__); \
\r
804 #elif defined(_MSC_VER)
\r
807 #define elprintf(w,f,...)
\r
812 #include <platform/linux/pprof.h>
\r
814 #define pprof_init()
\r
815 #define pprof_finish()
\r
816 #define pprof_start(x)
\r
817 #define pprof_end(...)
\r
818 #define pprof_end_sub(...)
\r
825 #define cdprintf(x...)
\r
829 #define REGPARM(x) __attribute__((regparm(x)))
\r
835 #define NOINLINE __attribute__((noinline))
\r
841 } // End of extern "C"
\r
844 #endif // PICO_INTERNAL_INCLUDED
\r