From 8e6447b1e2366d6ce9ccbf465ef34b312328fe8b Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Mon, 29 Apr 2013 00:59:50 -0700 Subject: Implemented basic interrupt support in Z80 core. --- transz80.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'transz80.c') diff --git a/transz80.c b/transz80.c index 897adee..afe99fd 100644 --- a/transz80.c +++ b/transz80.c @@ -1,12 +1,19 @@ #include "z80inst.h" #include "z80_to_x86.h" #include "mem.h" +#include "vdp.h" #include #include uint8_t z80_ram[0x2000]; uint16_t cart[0x200000]; +#define MCLKS_PER_Z80 15 +//TODO: Figure out the exact value for this +#define MCLKS_PER_FRAME (MCLKS_LINE*262) +#define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) +#define CYCLE_NEVER 0xFFFFFFFF + int main(int argc, char ** argv) { long filesize; @@ -38,18 +45,30 @@ int main(int argc, char ** argv) fseek(f, 0, SEEK_SET); fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f); fclose(f); + for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) + { + *cur = (*cur >> 8) | (*cur << 8); + } } init_x86_z80_opts(&opts); init_z80_context(&context, &opts); //Z80 RAM context.mem_pointers[0] = z80_ram; - context.sync_cycle = context.target_cycle = 0x7FFFFFFF; + context.sync_cycle = context.target_cycle = MCLKS_PER_FRAME/MCLKS_PER_Z80; + context.int_cycle = CYCLE_NEVER; //cartridge/bank - context.mem_pointers[1] = context.mem_pointers[2] = cart; + context.mem_pointers[1] = context.mem_pointers[2] = (uint8_t *)cart; z80_reset(&context); for(;;) { z80_run(&context); + if (context.current_cycle >= MCLKS_PER_FRAME/MCLKS_PER_Z80) { + context.current_cycle -= MCLKS_PER_FRAME/MCLKS_PER_Z80; + } + if (context.current_cycle < VINT_CYCLE && context.iff1) { + context.int_cycle = VINT_CYCLE; + } + context.target_cycle = context.sync_cycle < context.int_cycle ? context.sync_cycle : context.int_cycle; } return 0; } -- cgit v1.2.3