Mercurial > repos > blastem
diff transz80.c @ 250:5f1b68cecfc7
Implemented basic interrupt support in Z80 core.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 29 Apr 2013 00:59:50 -0700 |
parents | ea3899e3e7ec |
children | fd7c24b97ebf |
line wrap: on
line diff
--- a/transz80.c Mon Apr 29 00:59:32 2013 -0700 +++ b/transz80.c Mon Apr 29 00:59:50 2013 -0700 @@ -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 @@ 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; }