Mercurial > repos > blastem
comparison ztestrun.c @ 593:5ef3fe516da9
Z80 core is sort of working again
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 22 Dec 2014 20:55:10 -0800 |
parents | 140af5509ce7 |
children | f838bc0aeb7c |
comparison
equal
deleted
inserted
replaced
592:4ff7bbb3943b | 593:5ef3fe516da9 |
---|---|
1 /* | 1 /* |
2 Copyright 2013 Michael Pavone | 2 Copyright 2013 Michael Pavone |
3 This file is part of BlastEm. | 3 This file is part of BlastEm. |
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. | 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
5 */ | 5 */ |
6 #include "z80inst.h" | 6 #include "z80inst.h" |
7 #include "z80_to_x86.h" | 7 #include "z80_to_x86.h" |
8 #include "mem.h" | 8 #include "mem.h" |
9 #include "vdp.h" | 9 #include "vdp.h" |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 | 12 |
13 uint8_t z80_ram[0x2000]; | 13 uint8_t z80_ram[0x2000]; |
14 uint16_t cart[0x200000]; | |
15 | 14 |
16 #define MCLKS_PER_Z80 15 | 15 #define MCLKS_PER_Z80 15 |
17 //TODO: Figure out the exact value for this | 16 //TODO: Figure out the exact value for this |
18 #define MCLKS_PER_FRAME (MCLKS_LINE*262) | 17 #define MCLKS_PER_FRAME (MCLKS_LINE*262) |
19 #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) | 18 #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) |
20 #define CYCLE_NEVER 0xFFFFFFFF | 19 #define CYCLE_NEVER 0xFFFFFFFF |
21 | 20 |
22 uint8_t z80_read_ym(uint16_t location, z80_context * context) | 21 uint8_t z80_unmapped_read(uint32_t location, void * context) |
23 { | 22 { |
24 return 0xFF; | 23 return 0xFF; |
25 } | 24 } |
26 | 25 |
27 z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value) | 26 void * z80_unmapped_write(uint32_t location, void * context, uint8_t value) |
28 { | 27 { |
29 return context; | 28 return context; |
30 } | 29 } |
31 | 30 |
32 z80_context * z80_vdp_port_write(uint16_t location, z80_context * context, uint8_t value) | 31 const memmap_chunk z80_map[] = { |
33 { | 32 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, |
34 return context; | 33 { 0x4000, 0x10000, 0xFFFF, 0, MMAP_READ | MMAP_WRITE, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write} |
35 } | 34 }; |
36 | 35 |
37 int main(int argc, char ** argv) | 36 int main(int argc, char ** argv) |
38 { | 37 { |
39 long filesize; | 38 long filesize; |
40 uint8_t *filebuf; | 39 uint8_t *filebuf; |
41 x86_z80_options opts; | 40 z80_options opts; |
42 z80_context context; | 41 z80_context context; |
43 if (argc < 2) { | 42 if (argc < 2) { |
44 fputs("usage: transz80 zrom [cartrom]\n", stderr); | 43 fputs("usage: transz80 zrom [cartrom]\n", stderr); |
45 exit(1); | 44 exit(1); |
46 } | 45 } |
52 fseek(f, 0, SEEK_END); | 51 fseek(f, 0, SEEK_END); |
53 filesize = ftell(f); | 52 filesize = ftell(f); |
54 fseek(f, 0, SEEK_SET); | 53 fseek(f, 0, SEEK_SET); |
55 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); | 54 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); |
56 fclose(f); | 55 fclose(f); |
57 if (argc > 2) { | 56 init_x86_z80_opts(&opts, z80_map, 2); |
58 f = fopen(argv[2], "rb"); | |
59 if (!f) { | |
60 fprintf(stderr, "unable to open file %s\n", argv[2]); | |
61 exit(1); | |
62 } | |
63 fseek(f, 0, SEEK_END); | |
64 filesize = ftell(f); | |
65 fseek(f, 0, SEEK_SET); | |
66 fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f); | |
67 fclose(f); | |
68 for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) | |
69 { | |
70 *cur = (*cur >> 8) | (*cur << 8); | |
71 } | |
72 } | |
73 init_x86_z80_opts(&opts); | |
74 init_z80_context(&context, &opts); | 57 init_z80_context(&context, &opts); |
75 //Z80 RAM | 58 //Z80 RAM |
76 context.mem_pointers[0] = z80_ram; | 59 context.mem_pointers[0] = z80_ram; |
77 context.sync_cycle = context.target_cycle = 1000; | 60 context.sync_cycle = context.target_cycle = 1000; |
78 context.int_cycle = CYCLE_NEVER; | 61 context.int_cycle = CYCLE_NEVER; |
79 //cartridge/bank | |
80 context.mem_pointers[1] = context.mem_pointers[2] = (uint8_t *)cart; | |
81 z80_reset(&context); | 62 z80_reset(&context); |
82 while (context.current_cycle < 1000) { | 63 while (context.current_cycle < 1000) { |
83 z80_run(&context); | 64 context.run(&context); |
84 } | 65 } |
85 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\nIX: %X\nIY: %X\nSP: %X\n\nIM: %d, IFF1: %d, IFF2: %d\n", | 66 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\nIX: %X\nIY: %X\nSP: %X\n\nIM: %d, IFF1: %d, IFF2: %d\n", |
86 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], | 67 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], |
87 context.regs[Z80_D], context.regs[Z80_E], | 68 context.regs[Z80_D], context.regs[Z80_E], |
88 (context.regs[Z80_H] << 8) | context.regs[Z80_L], | 69 (context.regs[Z80_H] << 8) | context.regs[Z80_L], |
89 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], | 70 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], |
90 (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], | 71 (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], |
91 context.sp, context.im, context.iff1, context.iff2); | 72 context.sp, context.im, context.iff1, context.iff2); |
92 printf("Flags: SZVNC\n" | 73 printf("Flags: SZVNC\n" |
93 " %d%d%d%d%d\n", context.flags[ZF_S], context.flags[ZF_Z], context.flags[ZF_PV], context.flags[ZF_N], context.flags[ZF_C]); | 74 " %d%d%d%d%d\n", context.flags[ZF_S], context.flags[ZF_Z], context.flags[ZF_PV], context.flags[ZF_N], context.flags[ZF_C]); |
94 puts("--Alternate Regs--"); | 75 puts("--Alternate Regs--"); |
95 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n", | 76 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n", |
96 context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C], | 77 context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C], |
97 context.alt_regs[Z80_D], context.alt_regs[Z80_E], | 78 context.alt_regs[Z80_D], context.alt_regs[Z80_E], |
98 (context.alt_regs[Z80_H] << 8) | context.alt_regs[Z80_L]); | 79 (context.alt_regs[Z80_H] << 8) | context.alt_regs[Z80_L]); |
99 return 0; | 80 return 0; |
100 } | 81 } |