return vcounts[SekCyclesDone()>>8];\r
}\r
\r
+/* probably not should be in this file, but it's near related code here */\r
+void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new)\r
+{\r
+ int xcycles = z80_cycles << 8;\r
+\r
+ /* check for overflows */\r
+ if ((mode_old & 4) && xcycles > timer_a_next_oflow)\r
+ ym2612.OPN.ST.status |= 1;\r
+\r
+ if ((mode_old & 8) && xcycles > timer_b_next_oflow)\r
+ ym2612.OPN.ST.status |= 2;\r
+\r
+ /* update timer a */\r
+ if (mode_old & 1)\r
+ while (xcycles >= timer_a_next_oflow)\r
+ timer_a_next_oflow += timer_a_step;\r
+\r
+ if ((mode_old ^ mode_new) & 1) // turning on/off\r
+ {\r
+ if (mode_old & 1) {\r
+ timer_a_offset = timer_a_next_oflow - xcycles;\r
+ timer_a_next_oflow = 0x70000000;\r
+ }\r
+ else\r
+ timer_a_next_oflow = xcycles + timer_a_offset;\r
+ }\r
+ if (mode_new & 1)\r
+ elprintf(EL_YMTIMER, "timer a upd to %i @ %i", timer_a_next_oflow>>8, z80_cycles);\r
+\r
+ /* update timer b */\r
+ if (mode_old & 2)\r
+ while (xcycles >= timer_b_next_oflow)\r
+ timer_b_next_oflow += timer_b_step;\r
+\r
+ if ((mode_old ^ mode_new) & 2)\r
+ {\r
+ if (mode_old & 2) {\r
+ timer_b_offset = timer_b_next_oflow - xcycles;\r
+ timer_b_next_oflow = 0x70000000;\r
+ }\r
+ else\r
+ timer_b_next_oflow = xcycles + timer_b_offset;\r
+ }\r
+ if (mode_new & 2)\r
+ elprintf(EL_YMTIMER, "timer b upd to %i @ %i", timer_b_next_oflow>>8, z80_cycles);\r
+}\r
+\r
// ym2612 DAC and timer I/O handlers for z80\r
int ym2612_write_local(u32 a, u32 d, int is_from_z80)\r
{\r
//ym2612.OPN.ST.TAC = (1024-TAnew)*18;\r
//ym2612.OPN.ST.TAT = 0;\r
//\r
- timer_a_step = 16495 * (1024 - TAnew);\r
- if ((ym2612.OPN.ST.mode & 5) == 5) {\r
+ timer_a_step = timer_a_offset = 16495 * (1024 - TAnew);\r
+ if (ym2612.OPN.ST.mode & 1) {\r
int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
timer_a_next_oflow = (cycles << 8) + timer_a_step;\r
- //elprintf(EL_STATUS, "set to %i @ %i", timer_a_next_oflow>>8, cycles);\r
}\r
+ elprintf(EL_YMTIMER, "timer a set to %i, %i", 1024 - TAnew, timer_a_next_oflow>>8);\r
}\r
return 0;\r
}\r
//ym2612.OPN.ST.TBC = (256-d)<<4;\r
//ym2612.OPN.ST.TBC *= 18;\r
//ym2612.OPN.ST.TBT = 0;\r
+ timer_b_step = timer_b_offset = 263912 * (256 - d);\r
+ if (ym2612.OPN.ST.mode & 2) {\r
+ int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
+ timer_b_next_oflow = (cycles << 8) + timer_b_step;\r
+ }\r
+ elprintf(EL_YMTIMER, "timer b set to %i, %i", 256 - d, timer_b_next_oflow>>8);\r
}\r
return 0;\r
case 0x27: { /* mode, timer control */\r
int old_mode = ym2612.OPN.ST.mode;\r
- int xcycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
- xcycles <<= 8;\r
+ int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
+ ym2612.OPN.ST.mode = d;\r
\r
- //elprintf(EL_STATUS, "st mode %02x", d);\r
+ elprintf(EL_YMTIMER, "st mode %02x", d);\r
+ ym2612_sync_timers(cycles, old_mode, d);\r
\r
- if ((ym2612.OPN.ST.mode & 5) != 5 && (d & 5) == 5) {\r
- timer_a_next_oflow = xcycles + timer_a_step;\r
- //elprintf(EL_STATUS, "set to %i @ %i st", timer_a_next_oflow>>8, xcycles >> 8);\r
- }\r
+ /* reset Timer a flag */\r
+ if (d & 0x10)\r
+ ym2612.OPN.ST.status &= ~1;\r
\r
/* reset Timer b flag */\r
if (d & 0x20)\r
ym2612.OPN.ST.status &= ~2;\r
\r
- /* reset Timer a flag */\r
- if (d & 0x10) {\r
- if (ym2612.OPN.ST.status & 1)\r
- while (xcycles > timer_a_next_oflow)\r
- timer_a_next_oflow += timer_a_step;\r
- ym2612.OPN.ST.status &= ~1;\r
- }\r
- if (!(d & 5)) timer_a_next_oflow = 0x80000000;\r
- ym2612.OPN.ST.mode = d;\r
+ if ((d ^ old_mode) & 0xc0) {\r
#ifdef __GP2X__\r
- if (PicoOpt & POPT_EXT_FM) YM2612Write_940(a, d, get_scanline(is_from_z80));\r
+ if (PicoOpt & POPT_EXT_FM) YM2612Write_940(a, d, get_scanline(is_from_z80));\r
#endif\r
+ return 1;\r
+ }\r
return 0;\r
}\r
case 0x2b: { /* DAC Sel (YM2612) */\r
return YM2612Write_(a, d);\r
}\r
\r
-// TODO: timer b, 68k side + asm, savestates\r
+// TODO: savestates\r
+#define ym2612_read_local() \\r
+ if (xcycles >= timer_a_next_oflow) \\r
+ ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 1; \\r
+ if (xcycles >= timer_b_next_oflow) \\r
+ ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 2\r
+\r
+\r
u32 ym2612_read_local_z80(void)\r
{\r
int xcycles = z80_cyclesDone() << 8;\r
- if (timer_a_next_oflow != 0x80000000 && xcycles >= timer_a_next_oflow) {\r
- ym2612.OPN.ST.status |= 1;\r
- }\r
\r
- //elprintf(EL_STATUS, "timer %i, sched %i, @ %i|%i", ym2612.OPN.ST.status, timer_a_next_oflow>>8,\r
- // xcycles >> 8, (xcycles >> 8) / 228);\r
+ ym2612_read_local();\r
+\r
+ elprintf(EL_YMTIMER, "timer z80 read %i, sched %i, %i @ %i|%i", ym2612.OPN.ST.status,\r
+ timer_a_next_oflow>>8, timer_b_next_oflow>>8, xcycles >> 8, (xcycles >> 8) / 228);\r
+ return ym2612.OPN.ST.status;\r
+}\r
+\r
+u32 ym2612_read_local_68k(void)\r
+{\r
+ int xcycles = cycles_68k_to_z80(SekCyclesDone()) << 8;\r
+\r
+ ym2612_read_local();\r
+\r
+ elprintf(EL_YMTIMER, "timer 68k read %i, sched %i, %i @ %i|%i", ym2612.OPN.ST.status,\r
+ timer_a_next_oflow>>8, timer_b_next_oflow>>8, xcycles >> 8, (xcycles >> 8) / 228);\r
return ym2612.OPN.ST.status;\r
}\r
\r
addr68k=Pico.m.z80_bank68k<<15;\r
addr68k+=a&0x7fff;\r
\r
+ if (addr68k < Pico.romsize) { ret = Pico.rom[addr68k^1]; goto bnkend; }\r
+ elprintf(EL_ANOMALY, "z80->68k upper read [%06x] %02x", addr68k, ret);\r
if (PicoAHW & PAHW_MCD)\r
ret = PicoReadM68k8(addr68k);\r
else ret = PicoRead8(addr68k);\r
- if (addr68k >= 0x400000) // not many games do this\r
- { elprintf(EL_ANOMALY, "z80->68k upper read [%06x] %02x", addr68k, ret); }\r
- else\r
- { elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret); }\r
+bnkend:\r
+ elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret);\r
return ret;\r
}\r
\r
\r
// Pico/Memory.c\r
PICO_INTERNAL void PicoMemSetupPico(void);\r
+PICO_INTERNAL unsigned int ym2612_read_local_68k(void);\r
\r
// Pico.c\r
extern struct Pico Pico;\r
extern short cdda_out_buffer[2*1152];\r
extern int PsndLen_exc_cnt;\r
extern int PsndLen_exc_add;\r
-extern int timer_a_next_oflow, timer_a_step; // in z80 cycles\r
+extern int timer_a_next_oflow, timer_a_step, timer_a_offset; // in z80 cycles\r
+extern int timer_b_next_oflow, timer_b_step, timer_b_offset;\r
+\r
+void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new);\r
\r
#define timers_cycle() \\r
- if (timer_a_next_oflow > 0) timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256\r
+ if (timer_a_next_oflow > 0 && timer_a_next_oflow < 0x70000000) \\r
+ timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \\r
+ if (timer_b_next_oflow > 0 && timer_b_next_oflow < 0x70000000) \\r
+ timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \\r
+ ym2612_sync_timers(0, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode);\r
\r
#define timers_reset() \\r
- timer_a_next_oflow = 0x80000000\r
+ timer_a_next_oflow = timer_b_next_oflow = 0x70000000; \\r
+ timer_a_step = timer_a_offset = 16495 * 1024; \\r
+ timer_b_step = timer_b_offset = 263912 * 256;\r
+\r
\r
// VideoPort.c\r
PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d);\r
#define EL_HVCNT 0x00000001 /* hv counter reads */\r
#define EL_SR 0x00000002 /* SR reads */\r
#define EL_INTS 0x00000004 /* ints and acks */\r
-#define EL_YM2612R 0x00000008 /* 68k ym2612 reads */\r
+#define EL_YMTIMER 0x00000008 /* ym2612 timer stuff */\r
#define EL_INTSW 0x00000010 /* log irq switching on/off */\r
#define EL_ASVDP 0x00000020 /* VDP accesses during active scan */\r
#define EL_VDPDMA 0x00000040 /* VDP DMA transfers and their timing */\r