diff options
author | Mike Pavone <pavone@retrodev.com> | 2013-04-29 00:59:50 -0700 |
---|---|---|
committer | Mike Pavone <pavone@retrodev.com> | 2013-04-29 00:59:50 -0700 |
commit | 8e6447b1e2366d6ce9ccbf465ef34b312328fe8b (patch) | |
tree | 73dc8e39ba1d863e0b6c304622f5dad459358e6f /transz80.c | |
parent | db9268702bd408ed8cdb418094181b7a3bb62838 (diff) |
Implemented basic interrupt support in Z80 core.
Diffstat (limited to 'transz80.c')
-rw-r--r-- | transz80.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1,12 +1,19 @@ #include "z80inst.h" #include "z80_to_x86.h" #include "mem.h" +#include "vdp.h" #include <stdio.h> #include <stdlib.h> 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; } |