--- generator/main/cpuz80-mz80.c 2020/03/04 04:46:43 1.1 +++ generator/main/cpuz80-mz80.c 2020/03/04 04:47:06 1.1.1.3 @@ -18,32 +18,33 @@ void cpuz80_iowrite_actual(UINT16 addr, uint8 *cpuz80_ram = NULL; uint32 cpuz80_bank = 0; -unsigned int cpuz80_active = 0; +uint8 cpuz80_resetting = 0; +uint8 cpuz80_active = 0; +unsigned int cpuz80_on = 1; /* z80 turned on? */ CONTEXTMZ80 cpuz80_z80; /*** global variables ***/ static unsigned int cpuz80_lastsync = 0; -static unsigned int cpuz80_resetting = 0; static struct MemoryReadByte cpuz80_read[] = { - { 0x0000, 0xFFFF, cpuz80_read_actual, NULL }, - { -1, -1, NULL, NULL } + {0x0000, 0xFFFF, cpuz80_read_actual, NULL}, + {-1, -1, NULL, NULL} }; static struct MemoryWriteByte cpuz80_write[] = { - { 0x0000, 0xFFFF, cpuz80_write_actual, NULL }, - { -1, -1, NULL, NULL } + {0x0000, 0xFFFF, cpuz80_write_actual, NULL}, + {-1, -1, NULL, NULL} }; static struct z80PortRead cpuz80_ioread[] = { - { 0x0000, 0x00FF, cpuz80_ioread_actual, NULL }, - { -1, -1, NULL, NULL } + {0x0000, 0x00FF, cpuz80_ioread_actual, NULL}, + {-1, -1, NULL, NULL} }; static struct z80PortWrite cpuz80_iowrite[] = { - { 0x0000, 0x00FF, cpuz80_iowrite_actual, NULL }, - { -1, -1, NULL, NULL } + {0x0000, 0x00FF, cpuz80_iowrite_actual, NULL}, + {-1, -1, NULL, NULL} }; UINT8 cpuz80_read_actual(UINT32 addr, struct MemoryReadByte *me) @@ -116,21 +117,21 @@ void cpuz80_updatecontext(void) void cpuz80_resetcpu(void) { mz80reset(); - cpuz80_resetting = 1; /* suspends execution */ + cpuz80_resetting = 1; /* suspends execution */ } /*** cpuz80_unresetcpu - unreset z80 cpu ***/ void cpuz80_unresetcpu(void) { - cpuz80_resetting = 0; /* un-suspends execution */ + cpuz80_resetting = 0; /* un-suspends execution */ } /*** cpuz80_bankwrite - data is being written to latch ***/ void cpuz80_bankwrite(uint8 data) { - cpuz80_bank = (((cpuz80_bank >> 1) | ((data & 1) <<23)) & 0xff8000); + cpuz80_bank = (((cpuz80_bank >> 1) | ((data & 1) << 23)) & 0xff8000); } /*** cpuz80_stop - stop the processor ***/ @@ -161,15 +162,15 @@ void cpuz80_endfield(void) void cpuz80_sync(void) { int cpu68k_wanted = cpu68k_clocks - cpuz80_lastsync; - int wanted = (cpu68k_wanted<0?0:cpu68k_wanted)*7/15; + int wanted = (cpu68k_wanted < 0 ? 0 : cpu68k_wanted) * 7 / 15; int acheived; - if (cpuz80_active && !cpuz80_resetting) { + if (cpuz80_on && cpuz80_active && !cpuz80_resetting) { /* ui_log(LOG_USER, "executing %d z80 clocks @ %X", wanted, cpuz80_z80.z80pc); */ mz80exec(wanted); acheived = mz80GetElapsedTicks(1); - cpuz80_lastsync = cpuz80_lastsync + acheived*15/7; + cpuz80_lastsync = cpuz80_lastsync + acheived * 15 / 7; } else { cpuz80_lastsync = cpu68k_clocks; }