pico_int.h 36 KB

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