Mercurial > repos > blastem
comparison 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 |
comparison
equal
deleted
inserted
replaced
249:d94e6cd5a8a5 | 250:5f1b68cecfc7 |
---|---|
1 #include "z80inst.h" | 1 #include "z80inst.h" |
2 #include "z80_to_x86.h" | 2 #include "z80_to_x86.h" |
3 #include "mem.h" | 3 #include "mem.h" |
4 #include "vdp.h" | |
4 #include <stdio.h> | 5 #include <stdio.h> |
5 #include <stdlib.h> | 6 #include <stdlib.h> |
6 | 7 |
7 uint8_t z80_ram[0x2000]; | 8 uint8_t z80_ram[0x2000]; |
8 uint16_t cart[0x200000]; | 9 uint16_t cart[0x200000]; |
10 | |
11 #define MCLKS_PER_Z80 15 | |
12 //TODO: Figure out the exact value for this | |
13 #define MCLKS_PER_FRAME (MCLKS_LINE*262) | |
14 #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) | |
15 #define CYCLE_NEVER 0xFFFFFFFF | |
9 | 16 |
10 int main(int argc, char ** argv) | 17 int main(int argc, char ** argv) |
11 { | 18 { |
12 long filesize; | 19 long filesize; |
13 uint8_t *filebuf; | 20 uint8_t *filebuf; |
36 fseek(f, 0, SEEK_END); | 43 fseek(f, 0, SEEK_END); |
37 filesize = ftell(f); | 44 filesize = ftell(f); |
38 fseek(f, 0, SEEK_SET); | 45 fseek(f, 0, SEEK_SET); |
39 fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f); | 46 fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f); |
40 fclose(f); | 47 fclose(f); |
48 for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) | |
49 { | |
50 *cur = (*cur >> 8) | (*cur << 8); | |
51 } | |
41 } | 52 } |
42 init_x86_z80_opts(&opts); | 53 init_x86_z80_opts(&opts); |
43 init_z80_context(&context, &opts); | 54 init_z80_context(&context, &opts); |
44 //Z80 RAM | 55 //Z80 RAM |
45 context.mem_pointers[0] = z80_ram; | 56 context.mem_pointers[0] = z80_ram; |
46 context.sync_cycle = context.target_cycle = 0x7FFFFFFF; | 57 context.sync_cycle = context.target_cycle = MCLKS_PER_FRAME/MCLKS_PER_Z80; |
58 context.int_cycle = CYCLE_NEVER; | |
47 //cartridge/bank | 59 //cartridge/bank |
48 context.mem_pointers[1] = context.mem_pointers[2] = cart; | 60 context.mem_pointers[1] = context.mem_pointers[2] = (uint8_t *)cart; |
49 z80_reset(&context); | 61 z80_reset(&context); |
50 for(;;) | 62 for(;;) |
51 { | 63 { |
52 z80_run(&context); | 64 z80_run(&context); |
65 if (context.current_cycle >= MCLKS_PER_FRAME/MCLKS_PER_Z80) { | |
66 context.current_cycle -= MCLKS_PER_FRAME/MCLKS_PER_Z80; | |
67 } | |
68 if (context.current_cycle < VINT_CYCLE && context.iff1) { | |
69 context.int_cycle = VINT_CYCLE; | |
70 } | |
71 context.target_cycle = context.sync_cycle < context.int_cycle ? context.sync_cycle : context.int_cycle; | |
53 } | 72 } |
54 return 0; | 73 return 0; |
55 } | 74 } |