Mercurial > repos > blastem
comparison ztestrun.c @ 292:b970ea214ecb
Added z80 test generator and z80 test runner.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 08 May 2013 14:40:48 -0700 |
parents | |
children | ba97772b1662 |
comparison
equal
deleted
inserted
replaced
291:eea3b118940d | 292:b970ea214ecb |
---|---|
1 #include "z80inst.h" | |
2 #include "z80_to_x86.h" | |
3 #include "mem.h" | |
4 #include "vdp.h" | |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 | |
8 uint8_t z80_ram[0x2000]; | |
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 | |
16 | |
17 uint8_t z80_read_ym(uint16_t location, z80_context * context) | |
18 { | |
19 return 0xFF; | |
20 } | |
21 | |
22 z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value) | |
23 { | |
24 return context; | |
25 } | |
26 | |
27 int main(int argc, char ** argv) | |
28 { | |
29 long filesize; | |
30 uint8_t *filebuf; | |
31 x86_z80_options opts; | |
32 z80_context context; | |
33 if (argc < 2) { | |
34 fputs("usage: transz80 zrom [cartrom]\n", stderr); | |
35 exit(1); | |
36 } | |
37 FILE * f = fopen(argv[1], "rb"); | |
38 if (!f) { | |
39 fprintf(stderr, "unable to open file %s\n", argv[2]); | |
40 exit(1); | |
41 } | |
42 fseek(f, 0, SEEK_END); | |
43 filesize = ftell(f); | |
44 fseek(f, 0, SEEK_SET); | |
45 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); | |
46 fclose(f); | |
47 if (argc > 2) { | |
48 f = fopen(argv[2], "rb"); | |
49 if (!f) { | |
50 fprintf(stderr, "unable to open file %s\n", argv[2]); | |
51 exit(1); | |
52 } | |
53 fseek(f, 0, SEEK_END); | |
54 filesize = ftell(f); | |
55 fseek(f, 0, SEEK_SET); | |
56 fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f); | |
57 fclose(f); | |
58 for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) | |
59 { | |
60 *cur = (*cur >> 8) | (*cur << 8); | |
61 } | |
62 } | |
63 init_x86_z80_opts(&opts); | |
64 init_z80_context(&context, &opts); | |
65 //Z80 RAM | |
66 context.mem_pointers[0] = z80_ram; | |
67 context.sync_cycle = context.target_cycle = 1000; | |
68 context.int_cycle = CYCLE_NEVER; | |
69 //cartridge/bank | |
70 context.mem_pointers[1] = context.mem_pointers[2] = (uint8_t *)cart; | |
71 z80_reset(&context); | |
72 while (context.current_cycle < 1000) { | |
73 z80_run(&context); | |
74 } | |
75 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", | |
76 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], | |
77 context.regs[Z80_D], context.regs[Z80_E], | |
78 (context.regs[Z80_H] << 8) | context.regs[Z80_L], | |
79 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], | |
80 (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], | |
81 context.sp, context.im, context.iff1, context.iff2); | |
82 printf("Flags: SZVNC\n" | |
83 " %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]); | |
84 puts("--Alternate Regs--"); | |
85 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\nIX: %X\nIY: %X\n", | |
86 context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C], | |
87 context.alt_regs[Z80_D], context.alt_regs[Z80_E], | |
88 (context.alt_regs[Z80_H] << 8) | context.alt_regs[Z80_L], | |
89 (context.alt_regs[Z80_IXH] << 8) | context.alt_regs[Z80_IXL], | |
90 (context.alt_regs[Z80_IYH] << 8) | context.alt_regs[Z80_IYL]); | |
91 return 0; | |
92 } |