1 // (c) Copyright 2007 notaz, All rights reserved.
4 #include "../pico_int.h"
5 #include "../sound/ym2612.h"
7 extern unsigned char formatted_bram[4*0x10];
8 extern unsigned int s68k_poll_adclk;
10 void (*PicoMCDopenTray)(void) = NULL;
11 void (*PicoMCDcloseTray)(void) = NULL;
14 PICO_INTERNAL void PicoInitMCD(void)
20 PICO_INTERNAL void PicoExitMCD(void)
25 PICO_INTERNAL void PicoPowerMCD(void)
27 int fmt_size = sizeof(formatted_bram);
28 memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
29 memset(Pico_mcd->word_ram2M, 0, sizeof(Pico_mcd->word_ram2M));
30 memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram));
31 memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram));
32 memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - fmt_size, formatted_bram, fmt_size);
35 PICO_INTERNAL int PicoResetMCD(void)
37 memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs));
38 memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm));
39 memset(&Pico_mcd->m, 0, sizeof(Pico_mcd->m));
41 *(unsigned int *)(Pico_mcd->bios + 0x70) = 0xffffffff; // reset hint vector (simplest way to implement reg6)
42 Pico_mcd->m.state_flags |= 1; // s68k reset pending
43 Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode with m68k access after reset
48 #ifdef _ASM_CD_MEMORY_C
49 //PicoMemResetCDdecode(1); // don't have to call this in 2M mode
52 // use SRam.data for RAM cart
53 if (PicoOpt & POPT_EN_MCD_RAMCART) {
54 if (SRam.data == NULL)
55 SRam.data = calloc(1, 0x12000);
57 else if (SRam.data != NULL) {
61 SRam.start = SRam.end = 0; // unused
66 static __inline void SekRunM68k(int cyc)
70 if ((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;
71 #if defined(EMU_CORE_DEBUG)
72 SekCycleCnt+=CM_compareRun(cyc_do, 0);
73 #elif defined(EMU_C68K)
74 PicoCpuCM68k.cycles=cyc_do;
75 CycloneRun(&PicoCpuCM68k);
76 SekCycleCnt+=cyc_do-PicoCpuCM68k.cycles;
77 #elif defined(EMU_M68K)
78 m68k_set_context(&PicoCpuMM68k);
79 SekCycleCnt+=m68k_execute(cyc_do);
80 #elif defined(EMU_F68K)
81 g_m68kcontext=&PicoCpuFM68k;
82 SekCycleCnt+=fm68k_emulate(cyc_do, 0, 0);
86 static __inline void SekRunS68k(int cyc)
90 if ((cyc_do=SekCycleAimS68k-SekCycleCntS68k) <= 0) return;
91 #if defined(EMU_CORE_DEBUG)
92 SekCycleCntS68k+=CM_compareRun(cyc_do, 1);
93 #elif defined(EMU_C68K)
94 PicoCpuCS68k.cycles=cyc_do;
95 CycloneRun(&PicoCpuCS68k);
96 SekCycleCntS68k+=cyc_do-PicoCpuCS68k.cycles;
97 #elif defined(EMU_M68K)
98 m68k_set_context(&PicoCpuMS68k);
99 SekCycleCntS68k+=m68k_execute(cyc_do);
100 #elif defined(EMU_F68K)
101 g_m68kcontext=&PicoCpuFS68k;
102 SekCycleCntS68k+=fm68k_emulate(cyc_do, 0, 0);
106 #define PS_STEP_M68K ((488<<16)/20) // ~24
107 //#define PS_STEP_S68K 13
109 #if defined(_ASM_CD_PICO_C)
110 extern void SekRunPS(int cyc_m68k, int cyc_s68k);
111 #elif defined(EMU_F68K)
112 static __inline void SekRunPS(int cyc_m68k, int cyc_s68k)
114 SekCycleAim+=cyc_m68k;
115 SekCycleAimS68k+=cyc_s68k;
116 fm68k_emulate(0, 1, 0);
119 static __inline void SekRunPS(int cyc_m68k, int cyc_s68k)
121 int cycn, cycn_s68k, cyc_do;
122 SekCycleAim+=cyc_m68k;
123 SekCycleAimS68k+=cyc_s68k;
125 // fprintf(stderr, "=== start %3i/%3i [%3i/%3i] {%05i.%i} ===\n", cyc_m68k, cyc_s68k,
126 // SekCycleAim-SekCycleCnt, SekCycleAimS68k-SekCycleCntS68k, Pico.m.frame_count, Pico.m.scanline);
128 /* loop 488 downto 0 in steps of PS_STEP */
129 for (cycn = (488<<16)-PS_STEP_M68K; cycn >= 0; cycn -= PS_STEP_M68K)
131 cycn_s68k = (cycn + cycn/2 + cycn/8) >> 16;
132 if ((cyc_do = SekCycleAim-SekCycleCnt-(cycn>>16)) > 0) {
133 #if defined(EMU_C68K)
134 PicoCpuCM68k.cycles = cyc_do;
135 CycloneRun(&PicoCpuCM68k);
136 SekCycleCnt += cyc_do - PicoCpuCM68k.cycles;
137 #elif defined(EMU_M68K)
138 m68k_set_context(&PicoCpuMM68k);
139 SekCycleCnt += m68k_execute(cyc_do);
140 #elif defined(EMU_F68K)
141 g_m68kcontext = &PicoCpuFM68k;
142 SekCycleCnt += fm68k_emulate(cyc_do, 0, 0);
145 if ((cyc_do = SekCycleAimS68k-SekCycleCntS68k-cycn_s68k) > 0) {
146 #if defined(EMU_C68K)
147 PicoCpuCS68k.cycles = cyc_do;
148 CycloneRun(&PicoCpuCS68k);
149 SekCycleCntS68k += cyc_do - PicoCpuCS68k.cycles;
150 #elif defined(EMU_M68K)
151 m68k_set_context(&PicoCpuMS68k);
152 SekCycleCntS68k += m68k_execute(cyc_do);
153 #elif defined(EMU_F68K)
154 g_m68kcontext = &PicoCpuFS68k;
155 SekCycleCntS68k += fm68k_emulate(cyc_do, 0, 0);
163 static __inline void check_cd_dma(void)
167 if (!(Pico_mcd->scd.Status_CDC & 0x08)) return;
169 ddx = Pico_mcd->s68k_regs[4] & 7;
170 if (ddx < 2) return; // invalid
172 Pico_mcd->s68k_regs[4] |= 0x40; // Data set ready in host port
175 if (ddx == 6) return; // invalid
177 Update_CDC_TRansfer(ddx); // now go and do the actual transfer
180 static __inline void update_chips(void)
182 int counter_timer, int3_set;
183 int counter75hz_lim = Pico.m.pal ? 2080 : 2096;
186 if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) {
187 Pico_mcd->m.counter75hz -= counter75hz_lim;
192 counter_timer = Pico.m.pal ? 0x21630 : 0x2121c; // 136752 : 135708;
193 Pico_mcd->m.timer_stopwatch += counter_timer;
194 if ((int3_set = Pico_mcd->s68k_regs[0x31])) {
195 Pico_mcd->m.timer_int3 -= counter_timer;
196 if (Pico_mcd->m.timer_int3 < 0) {
197 if (Pico_mcd->s68k_regs[0x33] & (1<<3)) {
198 elprintf(EL_INTS, "s68k: timer irq 3");
200 Pico_mcd->m.timer_int3 += int3_set << 16;
202 // is this really what happens if irq3 is masked out?
203 Pico_mcd->m.timer_int3 &= 0xffffff;
208 if (Pico_mcd->rot_comp.Reg_58 & 0x8000)
214 #define CPUS_RUN(m68k_cycles,s68k_cycles) \
216 if ((PicoOpt&POPT_EN_MCD_PSYNC) && (Pico_mcd->m.busreq&3) == 1) { \
217 SekRunPS(m68k_cycles, s68k_cycles); /* "better/perfect sync" */ \
219 SekRunM68k(m68k_cycles); \
220 if ((Pico_mcd->m.busreq&3) == 1) /* no busreq/no reset */ \
221 SekRunS68k(s68k_cycles); \
224 #include "../pico_cmn.c"
227 PICO_INTERNAL void PicoFrameMCD(void)
229 if (!(PicoOpt&POPT_ALT_RENDERER))