Mercurial > repos > blastem
annotate ztestrun.c @ 951:fec4a59ae5d7
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 11 Apr 2016 20:56:54 -0700 |
parents | 74cc31040521 |
children | a27fdf43f1a7 |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
2 Copyright 2013 Michael Pavone |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
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. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
5 */ |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "z80inst.h" |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "z80_to_x86.h" |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "mem.h" |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "vdp.h" |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <stdio.h> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include <stdlib.h> |
675
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
12 #include <stddef.h> |
896
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
13 #include <stdarg.h> |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
14 |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
15 void fatal_error(char *format, ...) |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
16 { |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
17 va_list args; |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
18 va_start(args, format); |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
19 vfprintf(stderr, format, args); |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
20 va_end(args); |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
21 exit(1); |
74cc31040521
Get ztestrun compiling again
Michael Pavone <pavone@retrodev.com>
parents:
819
diff
changeset
|
22 } |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 uint8_t z80_ram[0x2000]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
26 uint8_t z80_unmapped_read(uint32_t location, void * context) |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 return 0xFF; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
31 void * z80_unmapped_write(uint32_t location, void * context, uint8_t value) |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 return context; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
36 const memmap_chunk z80_map[] = { |
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
37 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, |
607
f838bc0aeb7c
Fix memory map flags in ztestrun
Michael Pavone <pavone@retrodev.com>
parents:
593
diff
changeset
|
38 { 0x4000, 0x10000, 0xFFFF, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write} |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
39 }; |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
293
diff
changeset
|
40 |
674 | 41 void z80_next_int_pulse(z80_context * context) |
42 { | |
43 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER; | |
44 } | |
45 | |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 int main(int argc, char ** argv) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 long filesize; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 uint8_t *filebuf; |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
50 z80_options opts; |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 z80_context context; |
675
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
52 char *fname = NULL; |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
53 uint8_t retranslate = 0; |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
54 for (int i = 1; i < argc; i++) |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
55 { |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
56 if (argv[i][0] == '-') { |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
57 switch(argv[i][1]) |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
58 { |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
59 case 'r': |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
60 retranslate = 1; |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
61 break; |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
62 default: |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
63 fprintf(stderr, "Unrecognized switch -%c\n", argv[i][1]); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
64 exit(1); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
65 } |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
66 } else if (!fname) { |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
67 fname = argv[i]; |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
68 } |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
69 } |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
70 if (!fname) { |
674 | 71 fputs("usage: ztestrun zrom [cartrom]\n", stderr); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 exit(1); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } |
675
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
74 FILE * f = fopen(fname, "rb"); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 if (!f) { |
675
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
76 fprintf(stderr, "unable to open file %s\n", fname); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 exit(1); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 fseek(f, 0, SEEK_END); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 filesize = ftell(f); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 fseek(f, 0, SEEK_SET); |
675
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
82 filesize = filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
83 if (fread(z80_ram, 1, filesize, f) != filesize) { |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
84 fprintf(stderr, "error reading %s\n",fname); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
85 exit(1); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
86 } |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 fclose(f); |
819
ab017fb09e77
Added support for an IO memory map in Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
675
diff
changeset
|
88 init_z80_opts(&opts, z80_map, 2, NULL, 0, 1); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 init_z80_context(&context, &opts); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 //Z80 RAM |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 context.mem_pointers[0] = z80_ram; |
675
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
92 if (retranslate) { |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
93 //run core long enough to translate code |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
94 z80_run(&context, 1); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
95 for (int i = 0; i < filesize; i++) |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
96 { |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
97 z80_handle_code_write(i, &context); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
98 } |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
99 z80_assert_reset(&context, context.current_cycle); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
100 z80_clear_reset(&context, context.current_cycle + 3); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
101 z80_adjust_cycles(&context, context.current_cycle); |
5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
Michael Pavone <pavone@retrodev.com>
parents:
674
diff
changeset
|
102 } |
674 | 103 z80_run(&context, 1000); |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
104 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", |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
106 context.regs[Z80_D], context.regs[Z80_E], |
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
107 (context.regs[Z80_H] << 8) | context.regs[Z80_L], |
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
108 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], |
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
109 (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 context.sp, context.im, context.iff1, context.iff2); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 printf("Flags: SZVNC\n" |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 " %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]); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 puts("--Alternate Regs--"); |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
114 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n", |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C], |
593
5ef3fe516da9
Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
116 context.alt_regs[Z80_D], context.alt_regs[Z80_E], |
293
ba97772b1662
Cleanup reg printing in z80 test runner
Mike Pavone <pavone@retrodev.com>
parents:
292
diff
changeset
|
117 (context.alt_regs[Z80_H] << 8) | context.alt_regs[Z80_L]); |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 return 0; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |