pico_int.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. /*
  2. * PicoDrive - Internal Header File
  3. * (c) Copyright Dave, 2004
  4. * (C) notaz, 2006-2010
  5. *
  6. * This work is licensed under the terms of MAME license.
  7. * See COPYING file in the top-level directory.
  8. */
  9. #ifndef PICO_INTERNAL_INCLUDED
  10. #define PICO_INTERNAL_INCLUDED
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "pico_types.h"
  14. #include "pico_port.h"
  15. #include "pico.h"
  16. #include "carthw/carthw.h"
  17. //
  18. #define USE_POLL_DETECT
  19. #ifndef PICO_INTERNAL
  20. #define PICO_INTERNAL
  21. #endif
  22. #ifndef PICO_INTERNAL_ASM
  23. #define PICO_INTERNAL_ASM
  24. #endif
  25. // to select core, define EMU_C68K, EMU_M68K or EMU_F68K in your makefile or project
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. // ----------------------- 68000 CPU -----------------------
  30. #ifdef EMU_C68K
  31. #include <cpu/cyclone/Cyclone.h>
  32. extern struct Cyclone PicoCpuCM68k, PicoCpuCS68k;
  33. #define SekCyclesLeft PicoCpuCM68k.cycles // cycles left for this run
  34. #define SekCyclesLeftS68k PicoCpuCS68k.cycles
  35. #define SekPc (PicoCpuCM68k.pc-PicoCpuCM68k.membase)
  36. #define SekPcS68k (PicoCpuCS68k.pc-PicoCpuCS68k.membase)
  37. #define SekDar(x) (x < 8 ? PicoCpuCM68k.d[x] : PicoCpuCM68k.a[x - 8])
  38. #define SekDarS68k(x) (x < 8 ? PicoCpuCS68k.d[x] : PicoCpuCS68k.a[x - 8])
  39. #define SekSr CycloneGetSr(&PicoCpuCM68k)
  40. #define SekSrS68k CycloneGetSr(&PicoCpuCS68k)
  41. #define SekSetStop(x) { PicoCpuCM68k.state_flags&=~1; if (x) { PicoCpuCM68k.state_flags|=1; PicoCpuCM68k.cycles=0; } }
  42. #define SekSetStopS68k(x) { PicoCpuCS68k.state_flags&=~1; if (x) { PicoCpuCS68k.state_flags|=1; PicoCpuCS68k.cycles=0; } }
  43. #define SekIsStoppedM68k() (PicoCpuCM68k.state_flags&1)
  44. #define SekIsStoppedS68k() (PicoCpuCS68k.state_flags&1)
  45. #define SekShouldInterrupt() (PicoCpuCM68k.irq > (PicoCpuCM68k.srh&7))
  46. #define SekNotPolling PicoCpuCM68k.not_pol
  47. #define SekNotPollingS68k PicoCpuCS68k.not_pol
  48. #define SekInterrupt(i) PicoCpuCM68k.irq=i
  49. #define SekIrqLevel PicoCpuCM68k.irq
  50. #endif
  51. #ifdef EMU_F68K
  52. #include <cpu/fame/fame.h>
  53. extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k;
  54. #define SekCyclesLeft PicoCpuFM68k.io_cycle_counter
  55. #define SekCyclesLeftS68k PicoCpuFS68k.io_cycle_counter
  56. #define SekPc fm68k_get_pc(&PicoCpuFM68k)
  57. #define SekPcS68k fm68k_get_pc(&PicoCpuFS68k)
  58. #define SekDar(x) (x < 8 ? PicoCpuFM68k.dreg[x].D : PicoCpuFM68k.areg[x - 8].D)
  59. #define SekDarS68k(x) (x < 8 ? PicoCpuFS68k.dreg[x].D : PicoCpuFS68k.areg[x - 8].D)
  60. #define SekSr PicoCpuFM68k.sr
  61. #define SekSrS68k PicoCpuFS68k.sr
  62. #define SekSetStop(x) { \
  63. PicoCpuFM68k.execinfo &= ~FM68K_HALTED; \
  64. if (x) { PicoCpuFM68k.execinfo |= FM68K_HALTED; PicoCpuFM68k.io_cycle_counter = 0; } \
  65. }
  66. #define SekSetStopS68k(x) { \
  67. PicoCpuFS68k.execinfo &= ~FM68K_HALTED; \
  68. if (x) { PicoCpuFS68k.execinfo |= FM68K_HALTED; PicoCpuFS68k.io_cycle_counter = 0; } \
  69. }
  70. #define SekIsStoppedM68k() (PicoCpuFM68k.execinfo&FM68K_HALTED)
  71. #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED)
  72. #define SekShouldInterrupt() fm68k_would_interrupt(&PicoCpuFM68k)
  73. #define SekNotPolling PicoCpuFM68k.not_polling
  74. #define SekNotPollingS68k PicoCpuFS68k.not_polling
  75. #define SekInterrupt(irq) PicoCpuFM68k.interrupts[0]=irq
  76. #define SekIrqLevel PicoCpuFM68k.interrupts[0]
  77. #endif
  78. #ifdef EMU_M68K
  79. #include <cpu/musashi/m68kcpu.h>
  80. extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k;
  81. #ifndef SekCyclesLeft
  82. #define SekCyclesLeft PicoCpuMM68k.cyc_remaining_cycles
  83. #define SekCyclesLeftS68k PicoCpuMS68k.cyc_remaining_cycles
  84. #define SekPc m68k_get_reg(&PicoCpuMM68k, M68K_REG_PC)
  85. #define SekPcS68k m68k_get_reg(&PicoCpuMS68k, M68K_REG_PC)
  86. #define SekDar(x) PicoCpuMM68k.dar[x]
  87. #define SekDarS68k(x) PicoCpuMS68k.dar[x]
  88. #define SekSr m68k_get_reg(&PicoCpuMM68k, M68K_REG_SR)
  89. #define SekSrS68k m68k_get_reg(&PicoCpuMS68k, M68K_REG_SR)
  90. #define SekSetStop(x) { \
  91. if(x) { PicoCpuMM68k.cyc_remaining_cycles = 0; PicoCpuMM68k.stopped=STOP_LEVEL_STOP; } \
  92. else PicoCpuMM68k.stopped=0; \
  93. }
  94. #define SekSetStopS68k(x) { \
  95. if(x) { PicoCpuMS68k.cyc_remaining_cycles = 0; PicoCpuMS68k.stopped=STOP_LEVEL_STOP; } \
  96. else PicoCpuMS68k.stopped=0; \
  97. }
  98. #define SekIsStoppedM68k() (PicoCpuMM68k.stopped==STOP_LEVEL_STOP)
  99. #define SekIsStoppedS68k() (PicoCpuMS68k.stopped==STOP_LEVEL_STOP)
  100. #define SekShouldInterrupt() (PicoCpuMM68k.int_level > PicoCpuMM68k.int_mask)
  101. #define SekNotPolling PicoCpuMM68k.not_polling
  102. #define SekNotPollingS68k PicoCpuMS68k.not_polling
  103. // avoid m68k_set_irq() for delaying to work
  104. #define SekInterrupt(irq) PicoCpuMM68k.int_level = (irq) << 8
  105. #define SekIrqLevel (PicoCpuMM68k.int_level >> 8)
  106. #endif
  107. #endif // EMU_M68K
  108. // number of cycles done (can be checked anywhere)
  109. #define SekCyclesDone() (Pico.t.m68c_cnt - SekCyclesLeft)
  110. // burn cycles while not in SekRun() and while in
  111. #define SekCyclesBurn(c) Pico.t.m68c_cnt += c
  112. #define SekCyclesBurnRun(c) SekCyclesLeft -= c
  113. // note: sometimes may extend timeslice to delay an irq
  114. #define SekEndRun(after) { \
  115. Pico.t.m68c_cnt -= SekCyclesLeft - (after); \
  116. SekCyclesLeft = after; \
  117. }
  118. extern unsigned int SekCycleCntS68k;
  119. extern unsigned int SekCycleAimS68k;
  120. #define SekEndRunS68k(after) { \
  121. if (SekCyclesLeftS68k > (after)) { \
  122. SekCycleCntS68k -= SekCyclesLeftS68k - (after); \
  123. SekCyclesLeftS68k = after; \
  124. } \
  125. }
  126. #define SekCyclesDoneS68k() (SekCycleCntS68k - SekCyclesLeftS68k)
  127. // compare cycles, handling overflows
  128. // check if a > b
  129. #define CYCLES_GT(a, b) \
  130. ((int)((a) - (b)) > 0)
  131. // check if a >= b
  132. #define CYCLES_GE(a, b) \
  133. ((int)((a) - (b)) >= 0)
  134. // ----------------------- Z80 CPU -----------------------
  135. #if defined(_USE_DRZ80)
  136. #include <cpu/DrZ80/drz80.h>
  137. extern struct DrZ80 drZ80;
  138. #define z80_run(cycles) ((cycles) - DrZ80Run(&drZ80, cycles))
  139. #define z80_run_nr(cycles) DrZ80Run(&drZ80, cycles)
  140. #define z80_int() drZ80.Z80_IRQ = 1
  141. #define z80_int_assert(a) drZ80.Z80_IRQ = (a)
  142. #define z80_nmi() drZ80.Z80IF |= 8
  143. #define z80_cyclesLeft drZ80.cycles
  144. #define z80_subCLeft(c) drZ80.cycles -= c
  145. #define z80_pc() (drZ80.Z80PC - drZ80.Z80PC_BASE)
  146. #elif defined(_USE_CZ80)
  147. #include <cpu/cz80/cz80.h>
  148. #define z80_run(cycles) Cz80_Exec(&CZ80, cycles)
  149. #define z80_run_nr(cycles) Cz80_Exec(&CZ80, cycles)
  150. #define z80_int() Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE)
  151. #define z80_int_assert(a) Cz80_Set_IRQ(&CZ80, 0, (a) ? ASSERT_LINE : CLEAR_LINE)
  152. #define z80_nmi() Cz80_Set_IRQ(&CZ80, IRQ_LINE_NMI, 0)
  153. #define z80_cyclesLeft (CZ80.ICount - CZ80.ExtraCycles)
  154. #define z80_subCLeft(c) CZ80.ICount -= c
  155. #define z80_pc() Cz80_Get_Reg(&CZ80, CZ80_PC)
  156. #else
  157. #define z80_run(cycles) (cycles)
  158. #define z80_run_nr(cycles)
  159. #define z80_int()
  160. #define z80_int_assert(a)
  161. #define z80_nmi()
  162. #endif
  163. #define Z80_STATE_SIZE 0x60
  164. #define z80_resetCycles() \
  165. Pico.t.z80c_cnt = Pico.t.z80c_aim = Pico.t.z80_scanline = 0
  166. #define z80_cyclesDone() \
  167. (Pico.t.z80c_aim - z80_cyclesLeft)
  168. #define cycles_68k_to_z80(x) ((x) * 3822 >> 13)
  169. // ----------------------- SH2 CPU -----------------------
  170. #include <cpu/sh2/sh2.h>
  171. extern SH2 sh2s[2];
  172. #define msh2 sh2s[0]
  173. #define ssh2 sh2s[1]
  174. #ifndef DRC_SH2
  175. # define sh2_end_run(sh2, after_) do { \
  176. if ((sh2)->icount > (after_)) { \
  177. (sh2)->cycles_timeslice -= (sh2)->icount - (after_); \
  178. (sh2)->icount = after_; \
  179. } \
  180. } while (0)
  181. # define sh2_cycles_left(sh2) (sh2)->icount
  182. # define sh2_burn_cycles(sh2, n) (sh2)->icount -= n
  183. # define sh2_pc(sh2) (sh2)->ppc
  184. # define sh2_not_polling(sh2) (sh2)->no_polling
  185. # define sh2_set_polling(sh2) (sh2)->no_polling = 0
  186. #else
  187. # define sh2_end_run(sh2, after_) do { \
  188. int left_ = ((signed int)(sh2)->sr >> 12) - (after_); \
  189. if (left_ > 0) { \
  190. (sh2)->cycles_timeslice -= left_; \
  191. (sh2)->sr -= (left_ << 12); \
  192. } \
  193. } while (0)
  194. # define sh2_cycles_left(sh2) ((signed int)(sh2)->sr >> 12)
  195. # define sh2_burn_cycles(sh2, n) (sh2)->sr -= ((n) << 12)
  196. # define sh2_pc(sh2) (sh2)->pc
  197. # define sh2_not_polling(sh2) ((sh2)->sr & SH2_NO_POLLING)
  198. # define sh2_set_polling(sh2) ((sh2)->sr &= ~SH2_NO_POLLING)
  199. #endif
  200. #define sh2_cycles_done(sh2) (unsigned)((int)(sh2)->cycles_timeslice - sh2_cycles_left(sh2))
  201. #define sh2_cycles_done_t(sh2) \
  202. (unsigned)(C_M68K_TO_SH2(sh2, (sh2)->m68krcycles_done) + sh2_cycles_done(sh2))
  203. #define sh2_cycles_done_m68k(sh2) \
  204. (unsigned)((sh2)->m68krcycles_done + C_SH2_TO_M68K(sh2, sh2_cycles_done(sh2)))
  205. #define sh2_reg(c, x) ((c) ? ssh2.r[x] : msh2.r[x])
  206. #define sh2_gbr(c) ((c) ? ssh2.gbr : msh2.gbr)
  207. #define sh2_vbr(c) ((c) ? ssh2.vbr : msh2.vbr)
  208. #define sh2_sr(c) (((c) ? ssh2.sr : msh2.sr) & 0xfff)
  209. #define sh2_set_gbr(c, v) \
  210. { if (c) ssh2.gbr = v; else msh2.gbr = v; }
  211. #define sh2_set_vbr(c, v) \
  212. { if (c) ssh2.vbr = v; else msh2.vbr = v; }
  213. #define elprintf_sh2(sh2, w, f, ...) \
  214. elprintf(w,"%csh2 "f,(sh2)->is_slave?'s':'m',##__VA_ARGS__)
  215. // ---------------------------------------------------------
  216. // main oscillator clock which controls timing
  217. #define OSC_NTSC 53693100
  218. #define OSC_PAL 53203424
  219. // PicoVideo.debug_p
  220. #define PVD_KILL_A (1 << 0)
  221. #define PVD_KILL_B (1 << 1)
  222. #define PVD_KILL_S_LO (1 << 2)
  223. #define PVD_KILL_S_HI (1 << 3)
  224. #define PVD_KILL_32X (1 << 4)
  225. #define PVD_FORCE_A (1 << 5)
  226. #define PVD_FORCE_B (1 << 6)
  227. #define PVD_FORCE_S (1 << 7)
  228. // PicoVideo.status, not part of real SR
  229. #define SR_PAL (1 << 0)
  230. #define SR_DMA (1 << 1)
  231. #define SR_HB (1 << 2)
  232. #define SR_VB (1 << 3)
  233. #define SR_ODD (1 << 4)
  234. #define SR_C (1 << 5)
  235. #define SR_SOVR (1 << 6)
  236. #define SR_F (1 << 7)
  237. #define SR_FULL (1 << 8)
  238. #define SR_EMPT (1 << 9)
  239. // not part of real SR
  240. #define PVS_ACTIVE (1 << 16)
  241. #define PVS_VB2 (1 << 17) // ignores forced blanking
  242. #define PVS_CPUWR (1 << 18) // CPU write blocked by FIFO full
  243. #define PVS_CPURD (1 << 19) // CPU read blocked by FIFO not empty
  244. #define PVS_DMAFILL (1 << 20) // DMA fill is waiting for fill data
  245. #define PVS_DMABG (1 << 21) // background DMA operation is running
  246. #define PVS_FIFORUN (1 << 22) // FIFO is processing
  247. struct PicoVideo
  248. {
  249. unsigned char reg[0x20];
  250. unsigned int command; // 32-bit Command
  251. unsigned char pending; // 1 if waiting for second half of 32-bit command
  252. unsigned char type; // Command type (v/c/vsram read/write)
  253. unsigned short addr; // Read/Write address
  254. unsigned int status; // Status bits (SR) and extra flags
  255. unsigned char pending_ints; // pending interrupts: ??VH????
  256. signed char pad1; // was VDP write count
  257. unsigned short v_counter; // V-counter
  258. unsigned short debug; // raw debug register
  259. unsigned char debug_p; // ... parsed: PVD_*
  260. unsigned char addr_u; // bit16 of .addr
  261. unsigned char hint_cnt;
  262. unsigned char pad2;
  263. unsigned short hv_latch; // latched hvcounter value
  264. signed int fifo_cnt; // pending xfers for current FIFO queue entry
  265. unsigned char pad[0x04];
  266. };
  267. struct PicoMisc
  268. {
  269. unsigned char rotate;
  270. unsigned char z80Run;
  271. unsigned char padTHPhase[2]; // 02 phase of gamepad TH switches
  272. unsigned short scanline; // 04 0 to 261||311
  273. char dirtyPal; // 06 Is the palette dirty (1 - change @ this frame, 2 - some time before)
  274. unsigned char hardware; // 07 Hardware value for country
  275. unsigned char pal; // 08 1=PAL 0=NTSC
  276. unsigned char sram_reg; // 09 SRAM reg. See SRR_* below
  277. unsigned short z80_bank68k; // 0a
  278. unsigned short pad0;
  279. unsigned char ncart_in; // 0e !cart_in
  280. unsigned char z80_reset; // 0f z80 reset held
  281. unsigned char padDelay[2]; // 10 gamepad phase time outs, so we count a delay
  282. unsigned short eeprom_addr; // EEPROM address register
  283. unsigned char eeprom_cycle; // EEPROM cycle number
  284. unsigned char eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs
  285. unsigned char eeprom_status;
  286. unsigned char pad1; // was ym2612 status
  287. unsigned short dma_xfers; // 18 unused (was VDP DMA transfer count)
  288. unsigned char eeprom_wb[2]; // EEPROM latch/write buffer
  289. unsigned int frame_count; // 1c for movies and idle det
  290. };
  291. struct PicoMS
  292. {
  293. unsigned char carthw[0x10];
  294. unsigned char io_ctl;
  295. unsigned char nmi_state;
  296. unsigned char pad[0x4e];
  297. };
  298. // emu state and data for the asm code
  299. struct PicoEState
  300. {
  301. int DrawScanline;
  302. int rendstatus;
  303. void *DrawLineDest; // draw destination
  304. unsigned char *HighCol;
  305. s32 *HighPreSpr;
  306. struct Pico *Pico;
  307. unsigned short *PicoMem_vram;
  308. unsigned short *PicoMem_cram;
  309. unsigned int *PicoOpt;
  310. unsigned char *Draw2FB;
  311. int Draw2Width;
  312. int Draw2Start;
  313. unsigned short HighPal[0x100];
  314. unsigned short SonicPal[0x100];
  315. int SonicPalCount;
  316. };
  317. struct PicoMem
  318. {
  319. unsigned char ram[0x10000]; // 0x00000 scratch ram
  320. union { // vram is byteswapped for easier reads when drawing
  321. unsigned short vram[0x8000]; // 0x10000
  322. unsigned char vramb[0x4000]; // VRAM in SMS mode
  323. };
  324. unsigned char zram[0x2000]; // 0x20000 Z80 ram
  325. unsigned char ioports[0x10]; // XXX: fix asm and mv
  326. unsigned short cram[0x40]; // 0x22010
  327. unsigned char pad[0x70]; // 0x22050 DrawStripVSRam reads 0 from here
  328. unsigned short vsram[0x40]; // 0x22100
  329. };
  330. // sram
  331. #define SRR_MAPPED (1 << 0)
  332. #define SRR_READONLY (1 << 1)
  333. #define SRF_ENABLED (1 << 0)
  334. #define SRF_EEPROM (1 << 1)
  335. struct PicoCartSave
  336. {
  337. unsigned char *data; // actual data
  338. unsigned int start; // start address in 68k address space
  339. unsigned int end;
  340. unsigned char flags; // 0c: SRF_*
  341. unsigned char unused2;
  342. unsigned char changed;
  343. unsigned char eeprom_type; // eeprom type: 0: 7bit (24C01), 2: 2 addr words (X24C02+), 3: 3 addr words
  344. unsigned char unused3;
  345. unsigned char eeprom_bit_cl; // bit number for cl
  346. unsigned char eeprom_bit_in; // bit number for in
  347. unsigned char eeprom_bit_out; // bit number for out
  348. unsigned int size;
  349. };
  350. struct PicoTiming
  351. {
  352. // while running, cnt represents target of current timeslice
  353. // while not in SekRun(), it's actual cycles done
  354. // (but always use SekCyclesDone() if you need current position)
  355. // _cnt may change if timeslice is ended prematurely or extended,
  356. // so we use _aim for the actual target
  357. unsigned int m68c_cnt;
  358. unsigned int m68c_aim;
  359. unsigned int m68c_frame_start; // m68k cycles
  360. unsigned int m68c_line_start;
  361. unsigned int z80c_cnt; // z80 cycles done (this frame)
  362. unsigned int z80c_aim;
  363. int z80_scanline;
  364. int timer_a_next_oflow, timer_a_step; // in z80 cycles
  365. int timer_b_next_oflow, timer_b_step;
  366. };
  367. struct PicoSound
  368. {
  369. short len; // number of mono samples
  370. short len_use; // adjusted
  371. int len_e_add; // for non-int samples/frame
  372. int len_e_cnt;
  373. unsigned int clkl_mult; // z80 clocks per line in Q20
  374. unsigned int smpl_mult; // samples per line in Q16
  375. short dac_val, dac_val2; // last DAC sample
  376. unsigned int dac_pos; // last DAC position in Q20
  377. unsigned int fm_pos; // last FM position in Q20
  378. unsigned int psg_pos; // last PSG position in Q16
  379. unsigned int ym2413_pos; // last YM2413 position
  380. };
  381. // run tools/mkoffsets pico/pico_int_offs.h if you change these
  382. // careful with savestate compat
  383. struct Pico
  384. {
  385. struct PicoVideo video;
  386. struct PicoMisc m;
  387. struct PicoTiming t;
  388. struct PicoCartSave sv;
  389. struct PicoSound snd;
  390. struct PicoEState est;
  391. struct PicoMS ms;
  392. unsigned char *rom;
  393. unsigned int romsize;
  394. };
  395. // MCD
  396. #define PCM_MIXBUF_LEN ((12500000 / 384) / 50 + 1)
  397. struct mcd_pcm
  398. {
  399. unsigned char control; // reg7
  400. unsigned char enabled; // reg8
  401. unsigned char cur_ch;
  402. unsigned char bank;
  403. unsigned int update_cycles;
  404. struct pcm_chan // 08, size 0x10
  405. {
  406. unsigned char regs[8];
  407. unsigned int addr; // .08: played sample address
  408. int pad;
  409. } ch[8];
  410. };
  411. #define PCD_ST_S68K_RST 1
  412. struct mcd_misc
  413. {
  414. unsigned short hint_vector;
  415. unsigned char busreq; // not s68k_regs[1]
  416. unsigned char s68k_pend_ints;
  417. unsigned int state_flags; // 04
  418. unsigned int stopwatch_base_c;
  419. unsigned short m68k_poll_a;
  420. unsigned short m68k_poll_cnt;
  421. unsigned short s68k_poll_a;
  422. unsigned short s68k_poll_cnt;
  423. unsigned int s68k_poll_clk;
  424. unsigned char bcram_reg; // 18: battery-backed RAM cart register
  425. unsigned char dmna_ret_2m;
  426. unsigned char need_sync;
  427. unsigned char pad3;
  428. unsigned int m68k_poll_clk;
  429. int pad4[8];
  430. };
  431. typedef struct
  432. {
  433. unsigned char bios[0x20000]; // 000000: 128K
  434. union { // 020000: 512K
  435. unsigned char prg_ram[0x80000];
  436. unsigned char prg_ram_b[4][0x20000];
  437. };
  438. union { // 0a0000: 256K
  439. struct {
  440. unsigned char word_ram2M[0x40000];
  441. unsigned char unused0[0x20000];
  442. };
  443. struct {
  444. unsigned char unused1[0x20000];
  445. unsigned char word_ram1M[2][0x20000];
  446. };
  447. };
  448. union { // 100000: 64K
  449. unsigned char pcm_ram[0x10000];
  450. unsigned char pcm_ram_b[0x10][0x1000];
  451. };
  452. unsigned char s68k_regs[0x200]; // 110000: GA, not CPU regs
  453. unsigned char bram[0x2000]; // 110200: 8K
  454. struct mcd_misc m; // 112200: misc
  455. struct mcd_pcm pcm; // 112240:
  456. void *cdda_stream;
  457. int cdda_type;
  458. int pcm_mixbuf[PCM_MIXBUF_LEN * 2];
  459. int pcm_mixpos;
  460. char pcm_mixbuf_dirty;
  461. char pcm_regs_dirty;
  462. } mcd_state;
  463. // XXX: this will need to be reworked for cart+cd support.
  464. #define Pico_mcd ((mcd_state *)Pico.rom)
  465. // 32X
  466. #define P32XS_FM (1<<15)
  467. #define P32XS_nCART (1<< 8)
  468. #define P32XS_REN (1<< 7)
  469. #define P32XS_nRES (1<< 1)
  470. #define P32XS_ADEN (1<< 0)
  471. #define P32XS2_ADEN (1<< 9)
  472. #define P32XS_FULL (1<< 7) // DREQ FIFO full
  473. #define P32XS_68S (1<< 2)
  474. #define P32XS_DMA (1<< 1)
  475. #define P32XS_RV (1<< 0)
  476. #define P32XV_nPAL (1<<15) // VDP
  477. #define P32XV_PRI (1<< 7)
  478. #define P32XV_Mx (3<< 0) // display mode mask
  479. #define P32XV_SFT (1<< 0)
  480. #define P32XV_VBLK (1<<15)
  481. #define P32XV_HBLK (1<<14)
  482. #define P32XV_PEN (1<<13)
  483. #define P32XV_nFEN (1<< 1)
  484. #define P32XV_FS (1<< 0)
  485. #define P32XP_RTP (1<<7) // PWM control
  486. #define P32XP_FULL (1<<15) // PWM pulse
  487. #define P32XP_EMPTY (1<<14)
  488. #define P32XF_68KCPOLL (1 << 0)
  489. #define P32XF_68KVPOLL (1 << 1)
  490. #define P32XF_Z80_32X_IO (1 << 7) // z80 does 32x io
  491. #define P32XF_DRC_ROM_C (1 << 8) // cached code from ROM
  492. #define P32XI_VRES (1 << 14/2) // IRL/2
  493. #define P32XI_VINT (1 << 12/2)
  494. #define P32XI_HINT (1 << 10/2)
  495. #define P32XI_CMD (1 << 8/2)
  496. #define P32XI_PWM (1 << 6/2)
  497. // peripheral reg access (32 bit regs)
  498. #define PREG8(regs,offs) ((unsigned char *)regs)[MEM_BE4(offs)]
  499. #define DMAC_FIFO_LEN (4*2)
  500. #define PWM_BUFF_LEN 1024 // in one channel samples
  501. #define SH2_DRCBLK_RAM_SHIFT 1
  502. #define SH2_DRCBLK_DA_SHIFT 1
  503. #define SH2_READ_SHIFT 25
  504. #define SH2_WRITE_SHIFT 25
  505. struct Pico32x
  506. {
  507. unsigned short regs[0x20];
  508. unsigned short vdp_regs[0x10]; // 0x40
  509. unsigned short sh2_regs[3]; // 0x60
  510. unsigned char pending_fb;
  511. unsigned char dirty_pal;
  512. unsigned int emu_flags;
  513. unsigned char sh2irq_mask[2];
  514. unsigned char sh2irqi[2]; // individual
  515. unsigned int sh2irqs; // common irqs
  516. unsigned short dmac_fifo[DMAC_FIFO_LEN];
  517. unsigned int pad[4];
  518. unsigned int dmac0_fifo_ptr;
  519. unsigned short vdp_fbcr_fake;
  520. unsigned short pad2;
  521. unsigned char comm_dirty;
  522. unsigned char pad3; // was comm_dirty_sh2
  523. unsigned char pwm_irq_cnt;
  524. unsigned char pad1;
  525. unsigned short pwm_p[2]; // pwm pos in fifo
  526. unsigned int pwm_cycle_p; // pwm play cursor (32x cycles)
  527. unsigned int reserved[6];
  528. };
  529. struct Pico32xMem
  530. {
  531. unsigned char sdram[0x40000];
  532. #ifdef DRC_SH2
  533. unsigned char drcblk_ram[1 << (18 - SH2_DRCBLK_RAM_SHIFT)];
  534. unsigned char drclit_ram[1 << (18 - SH2_DRCBLK_RAM_SHIFT)];
  535. #endif
  536. unsigned short dram[2][0x20000/2]; // AKA fb
  537. union {
  538. unsigned char m68k_rom[0x100];
  539. unsigned char m68k_rom_bank[0x10000]; // M68K_BANK_SIZE
  540. };
  541. #ifdef DRC_SH2
  542. unsigned char drcblk_da[2][1 << (12 - SH2_DRCBLK_DA_SHIFT)];
  543. unsigned char drclit_da[2][1 << (12 - SH2_DRCBLK_DA_SHIFT)];
  544. #endif
  545. union {
  546. unsigned char b[0x800];
  547. unsigned short w[0x800/2];
  548. } sh2_rom_m;
  549. union {
  550. unsigned char b[0x400];
  551. unsigned short w[0x400/2];
  552. } sh2_rom_s;
  553. unsigned short pal[0x100];
  554. unsigned short pal_native[0x100]; // converted to native (for renderer)
  555. signed short pwm[2*PWM_BUFF_LEN]; // PWM buffer for current frame
  556. unsigned short pwm_fifo[2][4]; // [0] - current raw, others - fifo entries
  557. unsigned pwm_index[2]; // ringbuffer index for pwm_fifo
  558. };
  559. // area.c
  560. extern void (*PicoLoadStateHook)(void);
  561. typedef struct {
  562. int chunk;
  563. int size;
  564. void *ptr;
  565. } carthw_state_chunk;
  566. extern carthw_state_chunk *carthw_chunks;
  567. #define CHUNK_CARTHW 64
  568. // cart.c
  569. extern int PicoCartResize(int newsize);
  570. extern void Byteswap(void *dst, const void *src, int len);
  571. extern void (*PicoCartMemSetup)(void);
  572. extern void (*PicoCartUnloadHook)(void);
  573. // debug.c
  574. int CM_compareRun(int cyc, int is_sub);
  575. // draw.c
  576. void PicoDrawInit(void);
  577. PICO_INTERNAL void PicoFrameStart(void);
  578. void PicoDrawSync(int to, int blank_last_line);
  579. void BackFill(int reg7, int sh, struct PicoEState *est);
  580. void FinalizeLine555(int sh, int line, struct PicoEState *est);
  581. void PicoDrawSetOutBufMD(void *dest, int increment);
  582. extern int (*PicoScanBegin)(unsigned int num);
  583. extern int (*PicoScanEnd)(unsigned int num);
  584. #define MAX_LINE_SPRITES 27 // +1 last sprite width, +4 hdr; total 32
  585. extern unsigned char HighLnSpr[240][4+MAX_LINE_SPRITES+1];
  586. extern unsigned char *HighColBase;
  587. extern int HighColIncrement;
  588. extern void *DrawLineDestBase;
  589. extern int DrawLineDestIncrement;
  590. extern u32 VdpSATCache[128];
  591. // draw2.c
  592. void PicoDraw2SetOutBuf(void *dest, int incr);
  593. void PicoDraw2Init(void);
  594. PICO_INTERNAL void PicoFrameFull();
  595. // mode4.c
  596. void PicoFrameStartMode4(void);
  597. void PicoLineMode4(int line);
  598. void PicoDoHighPal555M4(void);
  599. void PicoDrawSetOutputMode4(pdso_t which);
  600. // memory.c
  601. PICO_INTERNAL void PicoMemSetup(void);
  602. u32 PicoRead8_io(u32 a);
  603. u32 PicoRead16_io(u32 a);
  604. void PicoWrite8_io(u32 a, u32 d);
  605. void PicoWrite16_io(u32 a, u32 d);
  606. // pico/memory.c
  607. PICO_INTERNAL void PicoMemSetupPico(void);
  608. // cd/cdc.c
  609. void cdc_init(void);
  610. void cdc_reset(void);
  611. int cdc_context_save(unsigned char *state);
  612. int cdc_context_load(unsigned char *state);
  613. int cdc_context_load_old(unsigned char *state);
  614. void cdc_dma_update(void);
  615. int cdc_decoder_update(unsigned char header[4]);
  616. void cdc_reg_w(unsigned char data);
  617. unsigned char cdc_reg_r(void);
  618. unsigned short cdc_host_r(void);
  619. // cd/cdd.c
  620. void cdd_reset(void);
  621. int cdd_context_save(unsigned char *state);
  622. int cdd_context_load(unsigned char *state);
  623. int cdd_context_load_old(unsigned char *state);
  624. void cdd_read_data(unsigned char *dst);
  625. void cdd_read_audio(unsigned int samples);
  626. void cdd_update(void);
  627. void cdd_process(void);
  628. // cd/cd_image.c
  629. int load_cd_image(const char *cd_img_name, int *type);
  630. // cd/gfx.c
  631. void gfx_init(void);
  632. void gfx_start(u32 base);
  633. void gfx_update(unsigned int cycles);
  634. int gfx_context_save(unsigned char *state);
  635. int gfx_context_load(const unsigned char *state);
  636. // cd/gfx_dma.c
  637. void DmaSlowCell(u32 source, u32 a, int len, unsigned char inc);
  638. // cd/memory.c
  639. PICO_INTERNAL void PicoMemSetupCD(void);
  640. u32 PicoRead8_mcd_io(u32 a);
  641. u32 PicoRead16_mcd_io(u32 a);
  642. void PicoWrite8_mcd_io(u32 a, u32 d);
  643. void PicoWrite16_mcd_io(u32 a, u32 d);
  644. void pcd_state_loaded_mem(void);
  645. // pico.c
  646. extern struct Pico Pico;
  647. extern struct PicoMem PicoMem;
  648. extern void (*PicoResetHook)(void);
  649. extern void (*PicoLineHook)(void);
  650. PICO_INTERNAL int CheckDMA(int cycles);
  651. PICO_INTERNAL void PicoDetectRegion(void);
  652. PICO_INTERNAL void PicoSyncZ80(unsigned int m68k_cycles_done);
  653. // cd/mcd.c
  654. #define PCDS_IEN1 (1<<1)
  655. #define PCDS_IEN2 (1<<2)
  656. #define PCDS_IEN3 (1<<3)
  657. #define PCDS_IEN4 (1<<4)
  658. #define PCDS_IEN5 (1<<5)
  659. #define PCDS_IEN6 (1<<6)
  660. PICO_INTERNAL void PicoInitMCD(void);
  661. PICO_INTERNAL void PicoExitMCD(void);
  662. PICO_INTERNAL void PicoPowerMCD(void);
  663. PICO_INTERNAL int PicoResetMCD(void);
  664. PICO_INTERNAL void PicoFrameMCD(void);
  665. enum pcd_event {
  666. PCD_EVENT_CDC,
  667. PCD_EVENT_TIMER3,
  668. PCD_EVENT_GFX,
  669. PCD_EVENT_DMA,
  670. PCD_EVENT_COUNT,
  671. };
  672. extern unsigned int pcd_event_times[PCD_EVENT_COUNT];
  673. void pcd_event_schedule(unsigned int now, enum pcd_event event, int after);
  674. void pcd_event_schedule_s68k(enum pcd_event event, int after);
  675. void pcd_prepare_frame(void);
  676. unsigned int pcd_cycles_m68k_to_s68k(unsigned int c);
  677. void pcd_irq_s68k(int irq, int state);
  678. int pcd_sync_s68k(unsigned int m68k_target, int m68k_poll_sync);
  679. void pcd_run_cpus(int m68k_cycles);
  680. void pcd_soft_reset(void);
  681. void pcd_state_loaded(void);
  682. // cd/pcm.c
  683. void pcd_pcm_sync(unsigned int to);
  684. void pcd_pcm_update(s32 *buffer, int length, int stereo);
  685. void pcd_pcm_write(unsigned int a, unsigned int d);
  686. unsigned int pcd_pcm_read(unsigned int a);
  687. // pico/pico.c
  688. PICO_INTERNAL void PicoInitPico(void);
  689. PICO_INTERNAL void PicoReratePico(void);
  690. // pico/xpcm.c
  691. PICO_INTERNAL void PicoPicoPCMUpdate(short *buffer, int length, int stereo);
  692. PICO_INTERNAL void PicoPicoPCMReset(void);
  693. PICO_INTERNAL void PicoPicoPCMRerate(int xpcm_rate);
  694. // sek.c
  695. PICO_INTERNAL void SekInit(void);
  696. PICO_INTERNAL int SekReset(void);
  697. PICO_INTERNAL void SekState(int *data);
  698. PICO_INTERNAL void SekSetRealTAS(int use_real);
  699. PICO_INTERNAL void SekPackCpu(unsigned char *cpu, int is_sub);
  700. PICO_INTERNAL void SekUnpackCpu(const unsigned char *cpu, int is_sub);
  701. void SekStepM68k(void);
  702. void SekInitIdleDet(void);
  703. void SekFinishIdleDet(void);
  704. #if defined(CPU_CMP_R) || defined(CPU_CMP_W)
  705. void SekTrace(int is_s68k);
  706. #else
  707. #define SekTrace(x)
  708. #endif
  709. // cd/sek.c
  710. PICO_INTERNAL void SekInitS68k(void);
  711. PICO_INTERNAL int SekResetS68k(void);
  712. PICO_INTERNAL int SekInterruptS68k(int irq);
  713. void SekInterruptClearS68k(int irq);
  714. // sound/sound.c
  715. extern short cdda_out_buffer[2*1152];
  716. void cdda_start_play(int lba_base, int lba_offset, int lb_len);
  717. void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new);
  718. void ym2612_pack_state(void);
  719. void ym2612_unpack_state(void);
  720. #define TIMER_NO_OFLOW 0x70000000
  721. // tA = 72 * (1024 - NA) / M, with M = mclock/2 -> tick = 72 * 2/mclock
  722. #define TIMER_A_TICK_ZCYCLES 17203 // zcycles = Q8*tick*zclock = Q8*77*2*7/15
  723. // tB = 1152 * (256 - NA) / M,
  724. #define TIMER_B_TICK_ZCYCLES 275251 // zcycles = Q8*1152*2*7/15
  725. #define timers_cycle() \
  726. if (Pico.t.timer_a_next_oflow > 0 && Pico.t.timer_a_next_oflow < TIMER_NO_OFLOW) \
  727. Pico.t.timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
  728. if (Pico.t.timer_b_next_oflow > 0 && Pico.t.timer_b_next_oflow < TIMER_NO_OFLOW) \
  729. Pico.t.timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
  730. ym2612_sync_timers(0, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode);
  731. #define timers_reset() \
  732. Pico.t.timer_a_next_oflow = Pico.t.timer_b_next_oflow = TIMER_NO_OFLOW; \
  733. Pico.t.timer_a_step = TIMER_A_TICK_ZCYCLES * 1024; \
  734. Pico.t.timer_b_step = TIMER_B_TICK_ZCYCLES * 256; \
  735. ym2612.OPN.ST.status &= ~3;
  736. // videoport.c
  737. extern u32 SATaddr, SATmask;
  738. static __inline void UpdateSAT(u32 a, u32 d)
  739. {
  740. unsigned num = (a^SATaddr) >> 3;
  741. Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;
  742. if (!(a & 4) && num < 128) {
  743. ((u16 *)&VdpSATCache[num])[(a&3) >> 1] = d;
  744. }
  745. }
  746. static __inline void VideoWriteVRAM(u32 a, u16 d)
  747. {
  748. PicoMem.vram [(u16)a >> 1] = d;
  749. if (((a^SATaddr) & SATmask) == 0)
  750. UpdateSAT(a, d);
  751. }
  752. PICO_INTERNAL_ASM void PicoVideoWrite(u32 a,unsigned short d);
  753. PICO_INTERNAL_ASM u32 PicoVideoRead(u32 a);
  754. unsigned char PicoVideoRead8DataH(int is_from_z80);
  755. unsigned char PicoVideoRead8DataL(int is_from_z80);
  756. unsigned char PicoVideoRead8CtlH(int is_from_z80);
  757. unsigned char PicoVideoRead8CtlL(int is_from_z80);
  758. unsigned char PicoVideoRead8HV_H(int is_from_z80);
  759. unsigned char PicoVideoRead8HV_L(int is_from_z80);
  760. extern int (*PicoDmaHook)(u32 source, int len, unsigned short **base, u32 *mask);
  761. void PicoVideoFIFOSync(int cycles);
  762. int PicoVideoFIFOHint(void);
  763. void PicoVideoFIFOMode(int active, int h40);
  764. int PicoVideoFIFOWrite(int count, int byte_p, unsigned sr_mask, unsigned sr_flags);
  765. void PicoVideoInit(void);
  766. void PicoVideoSave(void);
  767. void PicoVideoLoad(void);
  768. void PicoVideoCacheSAT(void);
  769. // misc.c
  770. PICO_INTERNAL_ASM void memcpy16bswap(unsigned short *dest, void *src, int count);
  771. PICO_INTERNAL_ASM void memset32(void *dest, int c, int count);
  772. // eeprom.c
  773. void EEPROM_write8(unsigned int a, unsigned int d);
  774. void EEPROM_write16(unsigned int d);
  775. unsigned int EEPROM_read(void);
  776. // z80 functionality wrappers
  777. PICO_INTERNAL void z80_init(void);
  778. PICO_INTERNAL void z80_pack(void *data);
  779. PICO_INTERNAL int z80_unpack(const void *data);
  780. PICO_INTERNAL void z80_reset(void);
  781. PICO_INTERNAL void z80_exit(void);
  782. // cd/misc.c
  783. PICO_INTERNAL_ASM void wram_2M_to_1M(unsigned char *m);
  784. PICO_INTERNAL_ASM void wram_1M_to_2M(unsigned char *m);
  785. // sound/sound.c
  786. PICO_INTERNAL void PsndInit(void);
  787. PICO_INTERNAL void PsndExit(void);
  788. PICO_INTERNAL void PsndReset(void);
  789. PICO_INTERNAL void PsndStartFrame(void);
  790. PICO_INTERNAL void PsndDoDAC(int cycle_to);
  791. PICO_INTERNAL void PsndDoPSG(int line_to);
  792. PICO_INTERNAL void PsndDoYM2413(int line_to);
  793. PICO_INTERNAL void PsndDoFM(int line_to);
  794. PICO_INTERNAL void PsndClear(void);
  795. PICO_INTERNAL void PsndGetSamples(int y);
  796. PICO_INTERNAL void PsndGetSamplesMS(int y);
  797. // sms.c
  798. #ifndef NO_SMS
  799. void PicoPowerMS(void);
  800. void PicoResetMS(void);
  801. void PicoMemSetupMS(void);
  802. void PicoStateLoadedMS(void);
  803. void PicoFrameMS(void);
  804. void PicoFrameDrawOnlyMS(void);
  805. #else
  806. #define PicoPowerMS()
  807. #define PicoResetMS()
  808. #define PicoMemSetupMS()
  809. #define PicoStateLoadedMS()
  810. #define PicoFrameMS()
  811. #define PicoFrameDrawOnlyMS()
  812. #endif
  813. // 32x/32x.c
  814. #ifndef NO_32X
  815. extern struct Pico32x Pico32x;
  816. enum p32x_event {
  817. P32X_EVENT_PWM,
  818. P32X_EVENT_FILLEND,
  819. P32X_EVENT_HINT,
  820. P32X_EVENT_COUNT,
  821. };
  822. extern unsigned int p32x_event_times[P32X_EVENT_COUNT];
  823. void Pico32xInit(void);
  824. void PicoPower32x(void);
  825. void PicoReset32x(void);
  826. void Pico32xStartup(void);
  827. void PicoUnload32x(void);
  828. void PicoFrame32x(void);
  829. void Pico32xStateLoaded(int is_early);
  830. void p32x_sync_sh2s(unsigned int m68k_target);
  831. void p32x_sync_other_sh2(SH2 *sh2, unsigned int m68k_target);
  832. void p32x_update_irls(SH2 *active_sh2, unsigned int m68k_cycles);
  833. void p32x_trigger_irq(SH2 *sh2, unsigned int m68k_cycles, unsigned int mask);
  834. void p32x_update_cmd_irq(SH2 *sh2, unsigned int m68k_cycles);
  835. void p32x_reset_sh2s(void);
  836. void p32x_event_schedule(unsigned int now, enum p32x_event event, int after);
  837. void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after);
  838. void p32x_schedule_hint(SH2 *sh2, unsigned int m68k_cycles);
  839. #define p32x_sh2_ready(sh2, cycles) \
  840. (CYCLES_GT(cycles,sh2->m68krcycles_done) && \
  841. !(sh2->state&(SH2_STATE_CPOLL|SH2_STATE_VPOLL|SH2_STATE_RPOLL)))
  842. // 32x/memory.c
  843. extern struct Pico32xMem *Pico32xMem;
  844. u32 PicoRead8_32x(u32 a);
  845. u32 PicoRead16_32x(u32 a);
  846. void PicoWrite8_32x(u32 a, u32 d);
  847. void PicoWrite16_32x(u32 a, u32 d);
  848. void PicoMemSetup32x(void);
  849. void Pico32xSwapDRAM(int b);
  850. void Pico32xMemStateLoaded(void);
  851. void p32x_update_banks(void);
  852. void p32x_m68k_poll_event(u32 flags);
  853. u32 REGPARM(3) p32x_sh2_poll_memory8(u32 a, u32 d, SH2 *sh2);
  854. u32 REGPARM(3) p32x_sh2_poll_memory16(u32 a, u32 d, SH2 *sh2);
  855. u32 REGPARM(3) p32x_sh2_poll_memory32(u32 a, u32 d, SH2 *sh2);
  856. void *p32x_sh2_get_mem_ptr(u32 a, u32 *mask, SH2 *sh2);
  857. void p32x_sh2_poll_detect(u32 a, SH2 *sh2, u32 flags, int maxcnt);
  858. void p32x_sh2_poll_event(SH2 *sh2, u32 flags, u32 m68k_cycles);
  859. int p32x_sh2_memcpy(u32 dst, u32 src, int count, int size, SH2 *sh2);
  860. // 32x/draw.c
  861. void PicoDrawSetOutFormat32x(pdso_t which, int use_32x_line_mode);
  862. void PicoDrawSetOutBuf32X(void *dest, int increment);
  863. void FinalizeLine32xRGB555(int sh, int line, struct PicoEState *est);
  864. void PicoDraw32xLayer(int offs, int lines, int mdbg);
  865. void PicoDraw32xLayerMdOnly(int offs, int lines);
  866. extern int (*PicoScan32xBegin)(unsigned int num);
  867. extern int (*PicoScan32xEnd)(unsigned int num);
  868. enum {
  869. PDM32X_OFF,
  870. PDM32X_32X_ONLY,
  871. PDM32X_BOTH,
  872. };
  873. extern int Pico32xDrawMode;
  874. // 32x/pwm.c
  875. unsigned int p32x_pwm_read16(u32 a, SH2 *sh2, unsigned int m68k_cycles);
  876. void p32x_pwm_write16(u32 a, unsigned int d, SH2 *sh2, unsigned int m68k_cycles);
  877. void p32x_pwm_update(int *buf32, int length, int stereo);
  878. void p32x_pwm_ctl_changed(void);
  879. void p32x_pwm_schedule(unsigned int m68k_now);
  880. void p32x_pwm_schedule_sh2(SH2 *sh2);
  881. void p32x_pwm_sync_to_sh2(SH2 *sh2);
  882. void p32x_pwm_irq_event(unsigned int m68k_now);
  883. void p32x_pwm_state_loaded(void);
  884. // 32x/sh2soc.c
  885. void p32x_dreq0_trigger(void);
  886. void p32x_dreq1_trigger(void);
  887. void p32x_timers_recalc(void);
  888. void p32x_timer_do(SH2 *sh2, unsigned int m68k_slice);
  889. void sh2_peripheral_reset(SH2 *sh2);
  890. u32 REGPARM(2) sh2_peripheral_read8(u32 a, SH2 *sh2);
  891. u32 REGPARM(2) sh2_peripheral_read16(u32 a, SH2 *sh2);
  892. u32 REGPARM(2) sh2_peripheral_read32(u32 a, SH2 *sh2);
  893. void REGPARM(3) sh2_peripheral_write8(u32 a, u32 d, SH2 *sh2);
  894. void REGPARM(3) sh2_peripheral_write16(u32 a, u32 d, SH2 *sh2);
  895. void REGPARM(3) sh2_peripheral_write32(u32 a, u32 d, SH2 *sh2);
  896. #else
  897. #define Pico32xInit()
  898. #define PicoPower32x()
  899. #define PicoReset32x()
  900. #define PicoFrame32x()
  901. #define PicoUnload32x()
  902. #define Pico32xStateLoaded()
  903. #define FinalizeLine32xRGB555 NULL
  904. #define p32x_pwm_update(...)
  905. #define p32x_timers_recalc()
  906. #endif
  907. /* avoid dependency on newer glibc */
  908. static __inline int isspace_(int c)
  909. {
  910. return (0x09 <= c && c <= 0x0d) || c == ' ';
  911. }
  912. #ifndef ARRAY_SIZE
  913. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  914. #endif
  915. // emulation event logging
  916. #ifndef EL_LOGMASK
  917. # ifdef __x86_64__ // HACK
  918. # define EL_LOGMASK (EL_STATUS|EL_ANOMALY)
  919. # else
  920. # define EL_LOGMASK (EL_STATUS)
  921. # endif
  922. #endif
  923. #define EL_HVCNT 0x00000001 /* hv counter reads */
  924. #define EL_SR 0x00000002 /* SR reads */
  925. #define EL_INTS 0x00000004 /* ints and acks */
  926. #define EL_YMTIMER 0x00000008 /* ym2612 timer stuff */
  927. #define EL_INTSW 0x00000010 /* log irq switching on/off */
  928. #define EL_ASVDP 0x00000020 /* VDP accesses during active scan */
  929. #define EL_VDPDMA 0x00000040 /* VDP DMA transfers and their timing */
  930. #define EL_BUSREQ 0x00000080 /* z80 busreq r/w or reset w */
  931. #define EL_Z80BNK 0x00000100 /* z80 i/o through bank area */
  932. #define EL_SRAMIO 0x00000200 /* sram i/o */
  933. #define EL_EEPROM 0x00000400 /* eeprom debug */
  934. #define EL_UIO 0x00000800 /* unmapped i/o */
  935. #define EL_IO 0x00001000 /* all i/o */
  936. #define EL_CDPOLL 0x00002000 /* MCD: log poll detection */
  937. #define EL_SVP 0x00004000 /* SVP stuff */
  938. #define EL_PICOHW 0x00008000 /* Pico stuff */
  939. #define EL_IDLE 0x00010000 /* idle loop det. */
  940. #define EL_CDREGS 0x00020000 /* MCD: register access */
  941. #define EL_CDREG3 0x00040000 /* MCD: register 3 only */
  942. #define EL_32X 0x00080000
  943. #define EL_PWM 0x00100000 /* 32X PWM stuff (LOTS of output) */
  944. #define EL_32XP 0x00200000 /* 32X peripherals */
  945. #define EL_CD 0x00400000 /* MCD */
  946. #define EL_STATUS 0x40000000 /* status messages */
  947. #define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */
  948. #if EL_LOGMASK
  949. #define elprintf(w,f,...) \
  950. do { \
  951. if ((w) & EL_LOGMASK) \
  952. lprintf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__); \
  953. } while (0)
  954. #elif defined(_MSC_VER)
  955. #define elprintf
  956. #else
  957. #define elprintf(w,f,...)
  958. #endif
  959. // profiling
  960. #ifdef PPROF
  961. #include <platform/linux/pprof.h>
  962. #else
  963. #define pprof_init()
  964. #define pprof_finish()
  965. #define pprof_start(x)
  966. #define pprof_end(...)
  967. #define pprof_end_sub(...)
  968. #endif
  969. #ifdef EVT_LOG
  970. enum evt {
  971. EVT_FRAME_START,
  972. EVT_NEXT_LINE,
  973. EVT_RUN_START,
  974. EVT_RUN_END,
  975. EVT_POLL_START,
  976. EVT_POLL_END,
  977. EVT_CNT
  978. };
  979. enum evt_cpu {
  980. EVT_M68K,
  981. EVT_S68K,
  982. EVT_MSH2,
  983. EVT_SSH2,
  984. EVT_CPU_CNT
  985. };
  986. void pevt_log(unsigned int cycles, enum evt_cpu c, enum evt e);
  987. void pevt_dump(void);
  988. #define pevt_log_m68k(e) \
  989. pevt_log(SekCyclesDone(), EVT_M68K, e)
  990. #define pevt_log_m68k_o(e) \
  991. pevt_log(SekCyclesDone(), EVT_M68K, e)
  992. #define pevt_log_sh2(sh2, e) \
  993. pevt_log(sh2_cycles_done_m68k(sh2), EVT_MSH2 + (sh2)->is_slave, e)
  994. #define pevt_log_sh2_o(sh2, e) \
  995. pevt_log((sh2)->m68krcycles_done, EVT_MSH2 + (sh2)->is_slave, e)
  996. #else
  997. #define pevt_log(c, e)
  998. #define pevt_log_m68k(e)
  999. #define pevt_log_m68k_o(e)
  1000. #define pevt_log_sh2(sh2, e)
  1001. #define pevt_log_sh2_o(sh2, e)
  1002. #define pevt_dump()
  1003. #endif
  1004. #ifdef __cplusplus
  1005. } // End of extern "C"
  1006. #endif
  1007. #endif // PICO_INTERNAL_INCLUDED
  1008. // vim:shiftwidth=2:ts=2:expandtab