// -----------------------------------------------------------------\r
// z80 memhandlers\r
\r
+static void access_68k_bus(int delay) // bus delay as Q8\r
+{\r
+ // 68k bus access delay for z80. The fractional part needs to be accumulated\r
+ // until an additional cycle is full. That is then added to the integer part.\r
+ Pico.t.z80_busdelay = (delay&0xff) + (Pico.t.z80_busdelay&0xff); // accumulate\r
+ z80_subCLeft((delay>>8) + (Pico.t.z80_busdelay>>8));\r
+ // don't use SekCyclesBurn(7) here since the Z80 doesn't run in cycle lock to\r
+ // the 68K. Count the stolen cycles to be accounted later in the 68k CPU runs\r
+ Pico.t.z80_buscycles += 7;\r
+}\r
+\r
static unsigned char z80_md_vdp_read(unsigned short a)\r
{\r
if ((a & 0xff00) == 0x7f00) {\r
- static int f; f = (f&0xff) + 0x8c; // 0.6\r
- z80_subCLeft(2+(f>>8)); // 3.3 per kabuto, but notaz' test implies 2.6 ?!?\r
- Pico.t.z80_buscycles += 7;\r
+ // 68k bus access delay=3.3 per kabuto, for notaz picotest 2.4<=delay<2.55?\r
+ access_68k_bus(0x280); // Q8, picotest: 0x266(>=2.4) - 0x28b(<2.55)\r
\r
switch (a & 0x0d)\r
{\r
unsigned int addr68k;\r
unsigned char ret;\r
\r
- // account for 68K bus access on both CPUs.\r
- static int f; f = (f&0xff) + 0x4c; // 0.3\r
- z80_subCLeft(3+(f>>8)); // 3.3 per kabuto\r
- // don't use SekCyclesBurn(7) here since the Z80 doesn't run in cycle lock to\r
- // the 68K. Count the stolen cycles to be accounted later in the 68k CPU runs\r
- Pico.t.z80_buscycles += 7;\r
+ // 68k bus access delay=3.3 per kabuto, but for notaz picotest 3.0<delay<3.3\r
+ access_68k_bus(0x340); // // Q8, picotest: 0x301(>3.0)-0x34c(<3.3)\r
\r
addr68k = Pico.m.z80_bank68k << 15;\r
addr68k |= a & 0x7fff;\r
{\r
unsigned int addr68k;\r
\r
- // account for 68K bus access on both CPUs.\r
- static int f; f = (f&0xff) + 0x4c; // 0.3\r
- z80_subCLeft(3+(f>>8)); // 3.3 per kabuto\r
- // don't use SekCyclesBurn(7) here since the Z80 doesn't run in cycle lock to\r
- // the 68K. Count the stolen cycles to be accounted later in the 68K CPU runs\r
- Pico.t.z80_buscycles += 7;\r
+ // 68k bus access delay=3.3 per kabuto, but for notaz picotest 3.0<delay<3.3\r
+ access_68k_bus(0x340); // // Q8, picotest: 0x301(>3.0)-0x34c(<3.3)\r
\r
addr68k = Pico.m.z80_bank68k << 15;\r
addr68k += a & 0x7fff;\r
#define z80_cyclesDone() \\r
(Pico.t.z80c_aim - z80_cyclesLeft)\r
\r
-// one line has 488 68K cycles and 228 Z80 cycles, 228/488*8192=3827\r
-#define cycles_68k_to_z80(x) ((x) * 3847 >> 13)\r
+// 68k clock = OSC/7, z80 clock = OSC/15, 68k:z80 ratio = 7/15*8192=3822.9\r
+#define cycles_68k_to_z80(x) ((x) * 3823 >> 13)\r
\r
// ----------------------- SH2 CPU -----------------------\r
\r
unsigned int z80c_line_start;\r
int z80_scanline;\r
int z80_buscycles;\r
+ int z80_busdelay;\r
\r
int timer_a_next_oflow, timer_a_step; // in z80 cycles\r
int timer_b_next_oflow, timer_b_step;\r