pico_int.h 37 KB

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