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_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. #ifdef UTYPES_DEFINED
  29. typedef uint8_t u8;
  30. typedef int8_t s8;
  31. typedef uint16_t u16;
  32. typedef int16_t s16;
  33. typedef uint32_t u32;
  34. typedef int32_t s32;
  35. #endif
  36. typedef uintptr_t uptr; // unsigned pointer-sized int
  37. // ----------------------- 68000 CPU -----------------------
  38. #ifdef EMU_C68K
  39. #include "../cpu/cyclone/Cyclone.h"
  40. extern struct Cyclone PicoCpuCM68k, PicoCpuCS68k;
  41. #define SekCyclesLeft PicoCpuCM68k.cycles // cycles left for this run
  42. #define SekCyclesLeftS68k PicoCpuCS68k.cycles
  43. #define SekPc (PicoCpuCM68k.pc-PicoCpuCM68k.membase)
  44. #define SekPcS68k (PicoCpuCS68k.pc-PicoCpuCS68k.membase)
  45. #define SekDar(x) (x < 8 ? PicoCpuCM68k.d[x] : PicoCpuCM68k.a[x - 8])
  46. #define SekDarS68k(x) (x < 8 ? PicoCpuCS68k.d[x] : PicoCpuCS68k.a[x - 8])
  47. #define SekSr CycloneGetSr(&PicoCpuCM68k)
  48. #define SekSrS68k CycloneGetSr(&PicoCpuCS68k)
  49. #define SekSetStop(x) { PicoCpuCM68k.state_flags&=~1; if (x) { PicoCpuCM68k.state_flags|=1; PicoCpuCM68k.cycles=0; } }
  50. #define SekSetStopS68k(x) { PicoCpuCS68k.state_flags&=~1; if (x) { PicoCpuCS68k.state_flags|=1; PicoCpuCS68k.cycles=0; } }
  51. #define SekIsStoppedM68k() (PicoCpuCM68k.state_flags&1)
  52. #define SekIsStoppedS68k() (PicoCpuCS68k.state_flags&1)
  53. #define SekShouldInterrupt() (PicoCpuCM68k.irq > (PicoCpuCM68k.srh&7))
  54. #define SekNotPolling PicoCpuCM68k.not_pol
  55. #define SekNotPollingS68k PicoCpuCS68k.not_pol
  56. #define SekInterrupt(i) PicoCpuCM68k.irq=i
  57. #define SekIrqLevel PicoCpuCM68k.irq
  58. #endif
  59. #ifdef EMU_F68K
  60. #include "../cpu/fame/fame.h"
  61. extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k;
  62. #define SekCyclesLeft PicoCpuFM68k.io_cycle_counter
  63. #define SekCyclesLeftS68k PicoCpuFS68k.io_cycle_counter
  64. #define SekPc fm68k_get_pc(&PicoCpuFM68k)
  65. #define SekPcS68k fm68k_get_pc(&PicoCpuFS68k)
  66. #define SekDar(x) (x < 8 ? PicoCpuFM68k.dreg[x].D : PicoCpuFM68k.areg[x - 8].D)
  67. #define SekDarS68k(x) (x < 8 ? PicoCpuFS68k.dreg[x].D : PicoCpuFS68k.areg[x - 8].D)
  68. #define SekSr PicoCpuFM68k.sr
  69. #define SekSrS68k PicoCpuFS68k.sr
  70. #define SekSetStop(x) { \
  71. PicoCpuFM68k.execinfo &= ~FM68K_HALTED; \
  72. if (x) { PicoCpuFM68k.execinfo |= FM68K_HALTED; PicoCpuFM68k.io_cycle_counter = 0; } \
  73. }
  74. #define SekSetStopS68k(x) { \
  75. PicoCpuFS68k.execinfo &= ~FM68K_HALTED; \
  76. if (x) { PicoCpuFS68k.execinfo |= FM68K_HALTED; PicoCpuFS68k.io_cycle_counter = 0; } \
  77. }
  78. #define SekIsStoppedM68k() (PicoCpuFM68k.execinfo&FM68K_HALTED)
  79. #define SekIsStoppedS68k() (PicoCpuFS68k.execinfo&FM68K_HALTED)
  80. #define SekShouldInterrupt() fm68k_would_interrupt(&PicoCpuFM68k)
  81. #define SekNotPolling PicoCpuFM68k.not_polling
  82. #define SekNotPollingS68k PicoCpuFS68k.not_polling
  83. #define SekInterrupt(irq) PicoCpuFM68k.interrupts[0]=irq
  84. #define SekIrqLevel PicoCpuFM68k.interrupts[0]
  85. #endif
  86. #ifdef EMU_M68K
  87. #include "../cpu/musashi/m68kcpu.h"
  88. extern m68ki_cpu_core PicoCpuMM68k, PicoCpuMS68k;
  89. #ifndef SekCyclesLeft
  90. #define SekCyclesLeft PicoCpuMM68k.cyc_remaining_cycles
  91. #define SekCyclesLeftS68k PicoCpuMS68k.cyc_remaining_cycles
  92. #define SekPc m68k_get_reg(&PicoCpuMM68k, M68K_REG_PC)
  93. #define SekPcS68k m68k_get_reg(&PicoCpuMS68k, M68K_REG_PC)
  94. #define SekDar(x) PicoCpuMM68k.dar[x]
  95. #define SekDarS68k(x) PicoCpuMS68k.dar[x]
  96. #define SekSr m68k_get_reg(&PicoCpuMM68k, M68K_REG_SR)
  97. #define SekSrS68k m68k_get_reg(&PicoCpuMS68k, M68K_REG_SR)
  98. #define SekSetStop(x) { \
  99. if(x) { SET_CYCLES(0); PicoCpuMM68k.stopped=STOP_LEVEL_STOP; } \
  100. else PicoCpuMM68k.stopped=0; \
  101. }
  102. #define SekSetStopS68k(x) { \
  103. if(x) { SET_CYCLES(0); PicoCpuMS68k.stopped=STOP_LEVEL_STOP; } \
  104. else PicoCpuMS68k.stopped=0; \
  105. }
  106. #define SekIsStoppedM68k() (PicoCpuMM68k.stopped==STOP_LEVEL_STOP)
  107. #define SekIsStoppedS68k() (PicoCpuMS68k.stopped==STOP_LEVEL_STOP)
  108. #define SekShouldInterrupt() (CPU_INT_LEVEL > FLAG_INT_MASK)
  109. #define SekNotPolling PicoCpuMM68k.not_polling
  110. #define SekNotPollingS68k PicoCpuMS68k.not_polling
  111. // avoid m68k_set_irq() for delaying to work
  112. #define SekInterrupt(irq) PicoCpuMM68k.int_level = (irq) << 8
  113. #define SekIrqLevel (PicoCpuMM68k.int_level >> 8)
  114. #endif
  115. #endif // EMU_M68K
  116. // number of cycles done (can be checked anywhere)
  117. #define SekCyclesDone() (Pico.t.m68c_cnt - SekCyclesLeft)
  118. // burn cycles while not in SekRun() and while in
  119. #define SekCyclesBurn(c) Pico.t.m68c_cnt += c
  120. #define SekCyclesBurnRun(c) SekCyclesLeft -= c
  121. // note: sometimes may extend timeslice to delay an irq
  122. #define SekEndRun(after) { \
  123. Pico.t.m68c_cnt -= SekCyclesLeft - (after); \
  124. SekCyclesLeft = after; \
  125. }
  126. extern unsigned int SekCycleCntS68k;
  127. extern unsigned int SekCycleAimS68k;
  128. #define SekEndRunS68k(after) { \
  129. if (SekCyclesLeftS68k > (after)) { \
  130. SekCycleCntS68k -= SekCyclesLeftS68k - (after); \
  131. SekCyclesLeftS68k = after; \
  132. } \
  133. }
  134. #define SekCyclesDoneS68k() (SekCycleCntS68k - SekCyclesLeftS68k)
  135. // compare cycles, handling overflows
  136. // check if a > b
  137. #define CYCLES_GT(a, b) \
  138. ((int)((a) - (b)) > 0)
  139. // check if a >= b
  140. #define CYCLES_GE(a, b) \
  141. ((int)((a) - (b)) >= 0)
  142. // ----------------------- Z80 CPU -----------------------
  143. #if defined(_USE_DRZ80)
  144. #include "../cpu/DrZ80/drz80.h"
  145. extern struct DrZ80 drZ80;
  146. #define z80_run(cycles) ((cycles) - DrZ80Run(&drZ80, cycles))
  147. #define z80_run_nr(cycles) DrZ80Run(&drZ80, cycles)
  148. #define z80_int() drZ80.Z80_IRQ = 1
  149. #define z80_int_assert(a) drZ80.Z80_IRQ = (a)
  150. #define z80_nmi() drZ80.Z80IF |= 8
  151. #define z80_cyclesLeft drZ80.cycles
  152. #define z80_subCLeft(c) drZ80.cycles -= c
  153. #define z80_pc() (drZ80.Z80PC - drZ80.Z80PC_BASE)
  154. #elif defined(_USE_CZ80)
  155. #include "../cpu/cz80/cz80.h"
  156. #define z80_run(cycles) Cz80_Exec(&CZ80, cycles)
  157. #define z80_run_nr(cycles) Cz80_Exec(&CZ80, cycles)
  158. #define z80_int() Cz80_Set_IRQ(&CZ80, 0, HOLD_LINE)
  159. #define z80_int_assert(a) Cz80_Set_IRQ(&CZ80, 0, (a) ? ASSERT_LINE : CLEAR_LINE)
  160. #define z80_nmi() Cz80_Set_IRQ(&CZ80, IRQ_LINE_NMI, 0)
  161. #define z80_cyclesLeft CZ80.ICount
  162. #define z80_subCLeft(c) CZ80.ICount -= c
  163. #define z80_pc() Cz80_Get_Reg(&CZ80, CZ80_PC)
  164. #else
  165. #define z80_run(cycles) (cycles)
  166. #define z80_run_nr(cycles)
  167. #define z80_int()
  168. #define z80_int_assert(a)
  169. #define z80_nmi()
  170. #endif
  171. #define Z80_STATE_SIZE 0x60
  172. #define z80_resetCycles() \
  173. Pico.t.z80c_cnt = Pico.t.z80c_aim = Pico.t.z80_scanline = 0
  174. #define z80_cyclesDone() \
  175. (Pico.t.z80c_aim - z80_cyclesLeft)
  176. #define cycles_68k_to_z80(x) ((x) * 3822 >> 13)
  177. // ----------------------- SH2 CPU -----------------------
  178. #include "cpu/sh2/sh2.h"
  179. extern SH2 sh2s[2];
  180. #define msh2 sh2s[0]
  181. #define ssh2 sh2s[1]
  182. #ifndef DRC_SH2
  183. # define sh2_end_run(sh2, after_) do { \
  184. if ((sh2)->icount > (after_)) { \
  185. (sh2)->cycles_timeslice -= (sh2)->icount - (after_); \
  186. (sh2)->icount = after_; \
  187. } \
  188. } while (0)
  189. # define sh2_cycles_left(sh2) (sh2)->icount
  190. # define sh2_burn_cycles(sh2, n) (sh2)->icount -= n
  191. # define sh2_pc(sh2) (sh2)->ppc
  192. #else
  193. # define sh2_end_run(sh2, after_) do { \
  194. int left_ = ((signed int)(sh2)->sr >> 12) - (after_); \
  195. if (left_ > 0) { \
  196. (sh2)->cycles_timeslice -= left_; \
  197. (sh2)->sr -= (left_ << 12); \
  198. } \
  199. } while (0)
  200. # define sh2_cycles_left(sh2) ((signed int)(sh2)->sr >> 12)
  201. # define sh2_burn_cycles(sh2, n) (sh2)->sr -= ((n) << 12)
  202. # define sh2_pc(sh2) (sh2)->pc
  203. #endif
  204. #define sh2_cycles_done(sh2) (unsigned)((int)(sh2)->cycles_timeslice - sh2_cycles_left(sh2))
  205. #define sh2_cycles_done_t(sh2) \
  206. (unsigned)(C_M68K_TO_SH2(sh2, (sh2)->m68krcycles_done) + sh2_cycles_done(sh2))
  207. #define sh2_cycles_done_m68k(sh2) \
  208. (unsigned)((sh2)->m68krcycles_done + C_SH2_TO_M68K(sh2, sh2_cycles_done(sh2)))
  209. #define sh2_reg(c, x) (c) ? ssh2.r[x] : msh2.r[x]
  210. #define sh2_gbr(c) (c) ? ssh2.gbr : msh2.gbr
  211. #define sh2_vbr(c) (c) ? ssh2.vbr : msh2.vbr
  212. #define sh2_sr(c) (((c) ? ssh2.sr : msh2.sr) & 0xfff)
  213. #define sh2_set_gbr(c, v) \
  214. { if (c) ssh2.gbr = v; else msh2.gbr = v; }
  215. #define sh2_set_vbr(c, v) \
  216. { if (c) ssh2.vbr = v; else msh2.vbr = v; }
  217. #define elprintf_sh2(sh2, w, f, ...) \
  218. elprintf(w,"%csh2 "f,(sh2)->is_slave?'s':'m',##__VA_ARGS__)
  219. // ---------------------------------------------------------
  220. // main oscillator clock which controls timing
  221. #define OSC_NTSC 53693100
  222. #define OSC_PAL 53203424
  223. // PicoVideo.debug_p
  224. #define PVD_KILL_A (1 << 0)
  225. #define PVD_KILL_B (1 << 1)
  226. #define PVD_KILL_S_LO (1 << 2)
  227. #define PVD_KILL_S_HI (1 << 3)
  228. #define PVD_KILL_32X (1 << 4)
  229. #define PVD_FORCE_A (1 << 5)
  230. #define PVD_FORCE_B (1 << 6)
  231. #define PVD_FORCE_S (1 << 7)
  232. // PicoVideo.status, not part of real SR
  233. #define SR_PAL (1 << 0)
  234. #define SR_DMA (1 << 1)
  235. #define SR_HB (1 << 2)
  236. #define SR_VB (1 << 3)
  237. #define SR_ODD (1 << 4)
  238. #define SR_C (1 << 5)
  239. #define SR_SOVR (1 << 6)
  240. #define SR_F (1 << 7)
  241. #define SR_FULL (1 << 8)
  242. #define SR_EMPT (1 << 9)
  243. // not part of real SR
  244. #define PVS_ACTIVE (1 << 16)
  245. #define PVS_VB2 (1 << 17) // ignores forced blanking
  246. #define PVS_CPUWR (1 << 18) // CPU write blocked by FIFO full
  247. #define PVS_CPURD (1 << 19) // CPU read blocked by FIFO not empty
  248. #define PVS_DMAFILL (1 << 20) // DMA fill is waiting for fill data
  249. #define PVS_DMABG (1 << 21) // background DMA operation is running
  250. #define PVS_FIFORUN (1 << 22) // FIFO is processing
  251. struct PicoVideo
  252. {
  253. unsigned char reg[0x20];
  254. unsigned int command; // 32-bit Command
  255. unsigned char pending; // 1 if waiting for second half of 32-bit command
  256. unsigned char type; // Command type (v/c/vsram read/write)
  257. unsigned short addr; // Read/Write address
  258. unsigned int status; // Status bits (SR) and extra flags
  259. unsigned char pending_ints; // pending interrupts: ??VH????
  260. signed char pad1; // was VDP write count
  261. unsigned short v_counter; // V-counter
  262. unsigned short debug; // raw debug register
  263. unsigned char debug_p; // ... parsed: PVD_*
  264. unsigned char addr_u; // bit16 of .addr
  265. unsigned char hint_cnt;
  266. unsigned char pad2;
  267. unsigned short hv_latch; // latched hvcounter value
  268. signed int fifo_cnt; // pending xfers for current FIFO queue entry
  269. unsigned char pad[0x04];
  270. };
  271. struct PicoMisc
  272. {
  273. unsigned char rotate;
  274. unsigned char z80Run;
  275. unsigned char padTHPhase[2]; // 02 phase of gamepad TH switches
  276. unsigned short scanline; // 04 0 to 261||311
  277. char dirtyPal; // 06 Is the palette dirty (1 - change @ this frame, 2 - some time before)
  278. unsigned char hardware; // 07 Hardware value for country
  279. unsigned char pal; // 08 1=PAL 0=NTSC
  280. unsigned char sram_reg; // 09 SRAM reg. See SRR_* below
  281. unsigned short z80_bank68k; // 0a
  282. unsigned short pad0;
  283. unsigned char ncart_in; // 0e !cart_in
  284. unsigned char z80_reset; // 0f z80 reset held
  285. unsigned char padDelay[2]; // 10 gamepad phase time outs, so we count a delay
  286. unsigned short eeprom_addr; // EEPROM address register
  287. unsigned char eeprom_cycle; // EEPROM cycle number
  288. unsigned char eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs
  289. unsigned char eeprom_status;
  290. unsigned char pad1; // was ym2612 status
  291. unsigned short dma_xfers; // 18 unused (was VDP DMA transfer count)
  292. unsigned char eeprom_wb[2]; // EEPROM latch/write buffer
  293. unsigned int frame_count; // 1c for movies and idle det
  294. };
  295. struct PicoMS
  296. {
  297. unsigned char carthw[0x10];
  298. unsigned char io_ctl;
  299. unsigned char nmi_state;
  300. unsigned char pad[0x4e];
  301. };
  302. // emu state and data for the asm code
  303. struct PicoEState
  304. {
  305. int DrawScanline;
  306. int rendstatus;
  307. void *DrawLineDest; // draw destination
  308. unsigned char *HighCol;
  309. int *HighPreSpr;
  310. struct Pico *Pico;
  311. void *PicoMem_vram;
  312. void *PicoMem_cram;
  313. unsigned int *PicoOpt;
  314. unsigned char *Draw2FB;
  315. unsigned short HighPal[0x100];
  316. unsigned short SonicPal[0x100];
  317. int SonicPalCount;
  318. };
  319. struct PicoMem
  320. {
  321. unsigned char ram[0x10000]; // 0x00000 scratch ram
  322. union { // vram is byteswapped for easier reads when drawing
  323. unsigned short vram[0x8000]; // 0x10000
  324. unsigned char vramb[0x4000]; // VRAM in SMS mode
  325. };
  326. unsigned char zram[0x2000]; // 0x20000 Z80 ram
  327. unsigned char ioports[0x10]; // XXX: fix asm and mv
  328. unsigned short cram[0x40]; // 0x22010
  329. unsigned char pad[0x70]; // 0x22050 DrawStripVSRam reads 0 from here
  330. unsigned short vsram[0x40]; // 0x22100
  331. };
  332. // sram
  333. #define SRR_MAPPED (1 << 0)
  334. #define SRR_READONLY (1 << 1)
  335. #define SRF_ENABLED (1 << 0)
  336. #define SRF_EEPROM (1 << 1)
  337. struct PicoCartSave
  338. {
  339. unsigned char *data; // actual data
  340. unsigned int start; // start address in 68k address space
  341. unsigned int end;
  342. unsigned char flags; // 0c: SRF_*
  343. unsigned char unused2;
  344. unsigned char changed;
  345. unsigned char eeprom_type; // eeprom type: 0: 7bit (24C01), 2: 2 addr words (X24C02+), 3: 3 addr words
  346. unsigned char unused3;
  347. unsigned char eeprom_bit_cl; // bit number for cl
  348. unsigned char eeprom_bit_in; // bit number for in
  349. unsigned char eeprom_bit_out; // bit number for out
  350. unsigned int size;
  351. };
  352. struct PicoTiming
  353. {
  354. // while running, cnt represents target of current timeslice
  355. // while not in SekRun(), it's actual cycles done
  356. // (but always use SekCyclesDone() if you need current position)
  357. // _cnt may change if timeslice is ended prematurely or extended,
  358. // so we use _aim for the actual target
  359. unsigned int m68c_cnt;
  360. unsigned int m68c_aim;
  361. unsigned int m68c_frame_start; // m68k cycles
  362. unsigned int m68c_line_start;
  363. unsigned int z80c_cnt; // z80 cycles done (this frame)
  364. unsigned int z80c_aim;
  365. int z80_scanline;
  366. int timer_a_next_oflow, timer_a_step; // in z80 cycles
  367. int timer_b_next_oflow, timer_b_step;
  368. };
  369. struct PicoSound
  370. {
  371. short len; // number of mono samples
  372. short len_use; // adjusted
  373. int len_e_add; // for non-int samples/frame
  374. int len_e_cnt;
  375. unsigned int clkl_mult; // z80 clocks per line in Q20
  376. unsigned int smpl_mult; // samples per line in Q16
  377. short dac_val, dac_val2; // last DAC sample
  378. unsigned int dac_pos; // last DAC position in Q20
  379. unsigned int fm_pos; // last FM position in Q20
  380. unsigned int psg_pos; // last PSG position in Q16
  381. };
  382. // run tools/mkoffsets pico/pico_int_offs.h if you change these
  383. // careful with savestate compat
  384. struct Pico
  385. {
  386. struct PicoVideo video;
  387. struct PicoMisc m;
  388. struct PicoTiming t;
  389. struct PicoCartSave sv;
  390. struct PicoSound snd;
  391. struct PicoEState est;
  392. struct PicoMS ms;
  393. unsigned char *rom;
  394. unsigned int romsize;
  395. };
  396. // MCD
  397. #define PCM_MIXBUF_LEN ((12500000 / 384) / 50 + 1)
  398. struct mcd_pcm
  399. {
  400. unsigned char control; // reg7
  401. unsigned char enabled; // reg8
  402. unsigned char cur_ch;
  403. unsigned char bank;
  404. unsigned int update_cycles;
  405. struct pcm_chan // 08, size 0x10
  406. {
  407. unsigned char regs[8];
  408. unsigned int addr; // .08: played sample address
  409. int pad;
  410. } ch[8];
  411. };
  412. #define PCD_ST_S68K_RST 1
  413. struct mcd_misc
  414. {
  415. unsigned short hint_vector;
  416. unsigned char busreq; // not s68k_regs[1]
  417. unsigned char s68k_pend_ints;
  418. unsigned int state_flags; // 04
  419. unsigned int stopwatch_base_c;
  420. unsigned short m68k_poll_a;
  421. unsigned short m68k_poll_cnt;
  422. unsigned short s68k_poll_a;
  423. unsigned short s68k_poll_cnt;
  424. unsigned int s68k_poll_clk;
  425. unsigned char bcram_reg; // 18: battery-backed RAM cart register
  426. unsigned char dmna_ret_2m;
  427. unsigned char need_sync;
  428. unsigned char pad3;
  429. int pad4[9];
  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
  498. #define PREG8(regs,offs) ((unsigned char *)regs)[offs ^ 3]
  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 void *DrawLineDestBase;
  587. extern int DrawLineDestIncrement;
  588. extern unsigned int VdpSATCache[128];
  589. // draw2.c
  590. void PicoDraw2Init(void);
  591. PICO_INTERNAL void PicoFrameFull();
  592. // mode4.c
  593. void PicoFrameStartMode4(void);
  594. void PicoLineMode4(int line);
  595. void PicoDoHighPal555M4(void);
  596. void PicoDrawSetOutputMode4(pdso_t which);
  597. // memory.c
  598. PICO_INTERNAL void PicoMemSetup(void);
  599. unsigned int PicoRead8_io(unsigned int a);
  600. unsigned int PicoRead16_io(unsigned int a);
  601. void PicoWrite8_io(unsigned int a, unsigned int d);
  602. void PicoWrite16_io(unsigned int a, unsigned int d);
  603. // pico/memory.c
  604. PICO_INTERNAL void PicoMemSetupPico(void);
  605. // cd/cdc.c
  606. void cdc_init(void);
  607. void cdc_reset(void);
  608. int cdc_context_save(unsigned char *state);
  609. int cdc_context_load(unsigned char *state);
  610. int cdc_context_load_old(unsigned char *state);
  611. void cdc_dma_update(void);
  612. int cdc_decoder_update(unsigned char header[4]);
  613. void cdc_reg_w(unsigned char data);
  614. unsigned char cdc_reg_r(void);
  615. unsigned short cdc_host_r(void);
  616. // cd/cdd.c
  617. void cdd_reset(void);
  618. int cdd_context_save(unsigned char *state);
  619. int cdd_context_load(unsigned char *state);
  620. int cdd_context_load_old(unsigned char *state);
  621. void cdd_read_data(unsigned char *dst);
  622. void cdd_read_audio(unsigned int samples);
  623. void cdd_update(void);
  624. void cdd_process(void);
  625. // cd/cd_image.c
  626. int load_cd_image(const char *cd_img_name, int *type);
  627. // cd/gfx.c
  628. void gfx_init(void);
  629. void gfx_start(unsigned int base);
  630. void gfx_update(unsigned int cycles);
  631. int gfx_context_save(unsigned char *state);
  632. int gfx_context_load(const unsigned char *state);
  633. // cd/gfx_dma.c
  634. void DmaSlowCell(unsigned int source, unsigned int a, int len, unsigned char inc);
  635. // cd/memory.c
  636. PICO_INTERNAL void PicoMemSetupCD(void);
  637. unsigned int PicoRead8_mcd_io(unsigned int a);
  638. unsigned int PicoRead16_mcd_io(unsigned int a);
  639. void PicoWrite8_mcd_io(unsigned int a, unsigned int d);
  640. void PicoWrite16_mcd_io(unsigned int a, unsigned int d);
  641. void pcd_state_loaded_mem(void);
  642. // pico.c
  643. extern struct Pico Pico;
  644. extern struct PicoMem PicoMem;
  645. extern void (*PicoResetHook)(void);
  646. extern void (*PicoLineHook)(void);
  647. PICO_INTERNAL int CheckDMA(int cycles);
  648. PICO_INTERNAL void PicoDetectRegion(void);
  649. PICO_INTERNAL void PicoSyncZ80(unsigned int m68k_cycles_done);
  650. // cd/mcd.c
  651. #define PCDS_IEN1 (1<<1)
  652. #define PCDS_IEN2 (1<<2)
  653. #define PCDS_IEN3 (1<<3)
  654. #define PCDS_IEN4 (1<<4)
  655. #define PCDS_IEN5 (1<<5)
  656. #define PCDS_IEN6 (1<<6)
  657. PICO_INTERNAL void PicoInitMCD(void);
  658. PICO_INTERNAL void PicoExitMCD(void);
  659. PICO_INTERNAL void PicoPowerMCD(void);
  660. PICO_INTERNAL int PicoResetMCD(void);
  661. PICO_INTERNAL void PicoFrameMCD(void);
  662. enum pcd_event {
  663. PCD_EVENT_CDC,
  664. PCD_EVENT_TIMER3,
  665. PCD_EVENT_GFX,
  666. PCD_EVENT_DMA,
  667. PCD_EVENT_COUNT,
  668. };
  669. extern unsigned int pcd_event_times[PCD_EVENT_COUNT];
  670. void pcd_event_schedule(unsigned int now, enum pcd_event event, int after);
  671. void pcd_event_schedule_s68k(enum pcd_event event, int after);
  672. void pcd_prepare_frame(void);
  673. unsigned int pcd_cycles_m68k_to_s68k(unsigned int c);
  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(int *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 unsigned 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 (!((u16)(a^SATaddr) & SATmask))
  746. UpdateSAT(a, d);
  747. }
  748. PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d);
  749. PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a);
  750. unsigned char PicoVideoRead8DataH(void);
  751. unsigned char PicoVideoRead8DataL(void);
  752. unsigned char PicoVideoRead8CtlH(void);
  753. unsigned char PicoVideoRead8CtlL(void);
  754. unsigned char PicoVideoRead8HV_H(void);
  755. unsigned char PicoVideoRead8HV_L(void);
  756. extern int (*PicoDmaHook)(unsigned int source, int len, unsigned short **base, unsigned int *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 PicoVideoSave(void);
  762. void PicoVideoLoad(void);
  763. // misc.c
  764. PICO_INTERNAL_ASM void memcpy16bswap(unsigned short *dest, void *src, int count);
  765. PICO_INTERNAL_ASM void memset32(void *dest, int c, int count);
  766. // eeprom.c
  767. void EEPROM_write8(unsigned int a, unsigned int d);
  768. void EEPROM_write16(unsigned int d);
  769. unsigned int EEPROM_read(void);
  770. // z80 functionality wrappers
  771. PICO_INTERNAL void z80_init(void);
  772. PICO_INTERNAL void z80_pack(void *data);
  773. PICO_INTERNAL int z80_unpack(const void *data);
  774. PICO_INTERNAL void z80_reset(void);
  775. PICO_INTERNAL void z80_exit(void);
  776. // cd/misc.c
  777. PICO_INTERNAL_ASM void wram_2M_to_1M(unsigned char *m);
  778. PICO_INTERNAL_ASM void wram_1M_to_2M(unsigned char *m);
  779. // sound/sound.c
  780. PICO_INTERNAL void PsndReset(void);
  781. PICO_INTERNAL void PsndStartFrame(void);
  782. PICO_INTERNAL void PsndDoDAC(int cycle_to);
  783. PICO_INTERNAL void PsndDoPSG(int line_to);
  784. PICO_INTERNAL void PsndDoFM(int line_to);
  785. PICO_INTERNAL void PsndClear(void);
  786. PICO_INTERNAL void PsndGetSamples(int y);
  787. PICO_INTERNAL void PsndGetSamplesMS(int y);
  788. // sms.c
  789. #ifndef NO_SMS
  790. void PicoPowerMS(void);
  791. void PicoResetMS(void);
  792. void PicoMemSetupMS(void);
  793. void PicoStateLoadedMS(void);
  794. void PicoFrameMS(void);
  795. void PicoFrameDrawOnlyMS(void);
  796. #else
  797. #define PicoPowerMS()
  798. #define PicoResetMS()
  799. #define PicoMemSetupMS()
  800. #define PicoStateLoadedMS()
  801. #define PicoFrameMS()
  802. #define PicoFrameDrawOnlyMS()
  803. #endif
  804. // 32x/32x.c
  805. #ifndef NO_32X
  806. extern struct Pico32x Pico32x;
  807. enum p32x_event {
  808. P32X_EVENT_PWM,
  809. P32X_EVENT_FILLEND,
  810. P32X_EVENT_HINT,
  811. P32X_EVENT_COUNT,
  812. };
  813. extern unsigned int p32x_event_times[P32X_EVENT_COUNT];
  814. void Pico32xInit(void);
  815. void PicoPower32x(void);
  816. void PicoReset32x(void);
  817. void Pico32xStartup(void);
  818. void PicoUnload32x(void);
  819. void PicoFrame32x(void);
  820. void Pico32xStateLoaded(int is_early);
  821. void p32x_sync_sh2s(unsigned int m68k_target);
  822. void p32x_sync_other_sh2(SH2 *sh2, unsigned int m68k_target);
  823. void p32x_update_irls(SH2 *active_sh2, unsigned int m68k_cycles);
  824. void p32x_trigger_irq(SH2 *sh2, unsigned int m68k_cycles, unsigned int mask);
  825. void p32x_update_cmd_irq(SH2 *sh2, unsigned int m68k_cycles);
  826. void p32x_reset_sh2s(void);
  827. void p32x_event_schedule(unsigned int now, enum p32x_event event, int after);
  828. void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after);
  829. void p32x_schedule_hint(SH2 *sh2, unsigned int m68k_cycles);
  830. #define p32x_sh2_ready(sh2, cycles) \
  831. (CYCLES_GT(cycles,sh2->m68krcycles_done) && \
  832. !(sh2->state&(SH2_STATE_CPOLL|SH2_STATE_VPOLL|SH2_STATE_RPOLL)))
  833. // 32x/memory.c
  834. extern struct Pico32xMem *Pico32xMem;
  835. unsigned int PicoRead8_32x(unsigned int a);
  836. unsigned int PicoRead16_32x(unsigned int a);
  837. void PicoWrite8_32x(unsigned int a, unsigned int d);
  838. void PicoWrite16_32x(unsigned int a, unsigned int d);
  839. void PicoMemSetup32x(void);
  840. void Pico32xSwapDRAM(int b);
  841. void Pico32xMemStateLoaded(void);
  842. void p32x_update_banks(void);
  843. void p32x_m68k_poll_event(unsigned int flags);
  844. unsigned int REGPARM(3) p32x_sh2_poll_memory8(unsigned int a, unsigned int d, SH2 *sh2);
  845. unsigned int REGPARM(3) p32x_sh2_poll_memory16(unsigned int a, unsigned int d, SH2 *sh2);
  846. unsigned int REGPARM(3) p32x_sh2_poll_memory32(unsigned int a, unsigned int d, SH2 *sh2);
  847. void *p32x_sh2_get_mem_ptr(unsigned int a, unsigned int *mask, SH2 *sh2);
  848. void p32x_sh2_poll_detect(unsigned int a, SH2 *sh2, unsigned int flags, int maxcnt);
  849. void p32x_sh2_poll_event(SH2 *sh2, unsigned int flags, unsigned int m68k_cycles);
  850. int p32x_sh2_memcpy(unsigned int dst, unsigned int src, int count, int size, SH2 *sh2);
  851. // 32x/draw.c
  852. void PicoDrawSetOutFormat32x(pdso_t which, int use_32x_line_mode);
  853. void PicoDrawSetOutBuf32X(void *dest, int increment);
  854. void FinalizeLine32xRGB555(int sh, int line, struct PicoEState *est);
  855. void PicoDraw32xLayer(int offs, int lines, int mdbg);
  856. void PicoDraw32xLayerMdOnly(int offs, int lines);
  857. extern int (*PicoScan32xBegin)(unsigned int num);
  858. extern int (*PicoScan32xEnd)(unsigned int num);
  859. enum {
  860. PDM32X_OFF,
  861. PDM32X_32X_ONLY,
  862. PDM32X_BOTH,
  863. };
  864. extern int Pico32xDrawMode;
  865. // 32x/pwm.c
  866. unsigned int p32x_pwm_read16(unsigned int a, SH2 *sh2,
  867. unsigned int m68k_cycles);
  868. void p32x_pwm_write16(unsigned int a, unsigned int d,
  869. SH2 *sh2, unsigned int m68k_cycles);
  870. void p32x_pwm_update(int *buf32, int length, int stereo);
  871. void p32x_pwm_ctl_changed(void);
  872. void p32x_pwm_schedule(unsigned int m68k_now);
  873. void p32x_pwm_schedule_sh2(SH2 *sh2);
  874. void p32x_pwm_sync_to_sh2(SH2 *sh2);
  875. void p32x_pwm_irq_event(unsigned int m68k_now);
  876. void p32x_pwm_state_loaded(void);
  877. // 32x/sh2soc.c
  878. void p32x_dreq0_trigger(void);
  879. void p32x_dreq1_trigger(void);
  880. void p32x_timers_recalc(void);
  881. void p32x_timer_do(SH2 *sh2, unsigned int m68k_slice);
  882. void sh2_peripheral_reset(SH2 *sh2);
  883. unsigned int REGPARM(2) sh2_peripheral_read8(unsigned int a, SH2 *sh2);
  884. unsigned int REGPARM(2) sh2_peripheral_read16(unsigned int a, SH2 *sh2);
  885. unsigned int REGPARM(2) sh2_peripheral_read32(unsigned int a, SH2 *sh2);
  886. void REGPARM(3) sh2_peripheral_write8(unsigned int a, unsigned int d, SH2 *sh2);
  887. void REGPARM(3) sh2_peripheral_write16(unsigned int a, unsigned int d, SH2 *sh2);
  888. void REGPARM(3) sh2_peripheral_write32(unsigned int a, unsigned int d, SH2 *sh2);
  889. #else
  890. #define Pico32xInit()
  891. #define PicoPower32x()
  892. #define PicoReset32x()
  893. #define PicoFrame32x()
  894. #define PicoUnload32x()
  895. #define Pico32xStateLoaded()
  896. #define FinalizeLine32xRGB555 NULL
  897. #define p32x_pwm_update(...)
  898. #define p32x_timers_recalc()
  899. #endif
  900. /* avoid dependency on newer glibc */
  901. static __inline int isspace_(int c)
  902. {
  903. return (0x09 <= c && c <= 0x0d) || c == ' ';
  904. }
  905. #ifndef ARRAY_SIZE
  906. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  907. #endif
  908. // emulation event logging
  909. #ifndef EL_LOGMASK
  910. # ifdef __x86_64__ // HACK
  911. # define EL_LOGMASK (EL_STATUS|EL_ANOMALY)
  912. # else
  913. # define EL_LOGMASK (EL_STATUS)
  914. # endif
  915. #endif
  916. #define EL_HVCNT 0x00000001 /* hv counter reads */
  917. #define EL_SR 0x00000002 /* SR reads */
  918. #define EL_INTS 0x00000004 /* ints and acks */
  919. #define EL_YMTIMER 0x00000008 /* ym2612 timer stuff */
  920. #define EL_INTSW 0x00000010 /* log irq switching on/off */
  921. #define EL_ASVDP 0x00000020 /* VDP accesses during active scan */
  922. #define EL_VDPDMA 0x00000040 /* VDP DMA transfers and their timing */
  923. #define EL_BUSREQ 0x00000080 /* z80 busreq r/w or reset w */
  924. #define EL_Z80BNK 0x00000100 /* z80 i/o through bank area */
  925. #define EL_SRAMIO 0x00000200 /* sram i/o */
  926. #define EL_EEPROM 0x00000400 /* eeprom debug */
  927. #define EL_UIO 0x00000800 /* unmapped i/o */
  928. #define EL_IO 0x00001000 /* all i/o */
  929. #define EL_CDPOLL 0x00002000 /* MCD: log poll detection */
  930. #define EL_SVP 0x00004000 /* SVP stuff */
  931. #define EL_PICOHW 0x00008000 /* Pico stuff */
  932. #define EL_IDLE 0x00010000 /* idle loop det. */
  933. #define EL_CDREGS 0x00020000 /* MCD: register access */
  934. #define EL_CDREG3 0x00040000 /* MCD: register 3 only */
  935. #define EL_32X 0x00080000
  936. #define EL_PWM 0x00100000 /* 32X PWM stuff (LOTS of output) */
  937. #define EL_32XP 0x00200000 /* 32X peripherals */
  938. #define EL_CD 0x00400000 /* MCD */
  939. #define EL_STATUS 0x40000000 /* status messages */
  940. #define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */
  941. #if EL_LOGMASK
  942. #define elprintf(w,f,...) \
  943. do { \
  944. if ((w) & EL_LOGMASK) \
  945. lprintf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__); \
  946. } while (0)
  947. #elif defined(_MSC_VER)
  948. #define elprintf
  949. #else
  950. #define elprintf(w,f,...)
  951. #endif
  952. // profiling
  953. #ifdef PPROF
  954. #include <platform/linux/pprof.h>
  955. #else
  956. #define pprof_init()
  957. #define pprof_finish()
  958. #define pprof_start(x)
  959. #define pprof_end(...)
  960. #define pprof_end_sub(...)
  961. #endif
  962. #ifdef EVT_LOG
  963. enum evt {
  964. EVT_FRAME_START,
  965. EVT_NEXT_LINE,
  966. EVT_RUN_START,
  967. EVT_RUN_END,
  968. EVT_POLL_START,
  969. EVT_POLL_END,
  970. EVT_CNT
  971. };
  972. enum evt_cpu {
  973. EVT_M68K,
  974. EVT_S68K,
  975. EVT_MSH2,
  976. EVT_SSH2,
  977. EVT_CPU_CNT
  978. };
  979. void pevt_log(unsigned int cycles, enum evt_cpu c, enum evt e);
  980. void pevt_dump(void);
  981. #define pevt_log_m68k(e) \
  982. pevt_log(SekCyclesDone(), EVT_M68K, e)
  983. #define pevt_log_m68k_o(e) \
  984. pevt_log(SekCyclesDone(), EVT_M68K, e)
  985. #define pevt_log_sh2(sh2, e) \
  986. pevt_log(sh2_cycles_done_m68k(sh2), EVT_MSH2 + (sh2)->is_slave, e)
  987. #define pevt_log_sh2_o(sh2, e) \
  988. pevt_log((sh2)->m68krcycles_done, EVT_MSH2 + (sh2)->is_slave, e)
  989. #else
  990. #define pevt_log(c, e)
  991. #define pevt_log_m68k(e)
  992. #define pevt_log_m68k_o(e)
  993. #define pevt_log_sh2(sh2, e)
  994. #define pevt_log_sh2_o(sh2, e)
  995. #define pevt_dump()
  996. #endif
  997. #ifdef __cplusplus
  998. } // End of extern "C"
  999. #endif
  1000. #endif // PICO_INTERNAL_INCLUDED
  1001. // vim:shiftwidth=2:ts=2:expandtab