annotate ztestrun.c @ 1086:f0a1e0a2263c

Made some optimizations to gen_mem_fun to keep the size of chunk handler sections within range of a single byte displacement
author Michael Pavone <pavone@retrodev.com>
date Thu, 06 Oct 2016 22:25:12 -0700
parents 56713dac6a69
children fe8c79f82c22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1060
56713dac6a69 Implement INI
Michael Pavone <pavone@retrodev.com>
parents: 1049
diff changeset
41 const memmap_chunk port_map[] = {
56713dac6a69 Implement INI
Michael Pavone <pavone@retrodev.com>
parents: 1049
diff changeset
42 { 0x0000, 0x100, 0xFF, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write}
56713dac6a69 Implement INI
Michael Pavone <pavone@retrodev.com>
parents: 1049
diff changeset
43 };
56713dac6a69 Implement INI
Michael Pavone <pavone@retrodev.com>
parents: 1049
diff changeset
44
674
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
45 void z80_next_int_pulse(z80_context * context)
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
46 {
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
47 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
48 }
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
49
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 int main(int argc, char ** argv)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 long filesize;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 uint8_t *filebuf;
593
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
54 z80_options opts;
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 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
56 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
57 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
58 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
59 {
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 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
61 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
62 {
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 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
64 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
65 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
66 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
67 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
68 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
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 } 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
71 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
72 }
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
73 }
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 if (!fname) {
674
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
75 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
76 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 }
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
78 FILE * f = fopen(fname, "rb");
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
79 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
80 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
81 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 fseek(f, 0, SEEK_END);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 filesize = ftell(f);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 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
86 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
87 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
88 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
89 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
90 }
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 fclose(f);
1060
56713dac6a69 Implement INI
Michael Pavone <pavone@retrodev.com>
parents: 1049
diff changeset
92 init_z80_opts(&opts, z80_map, 2, port_map, 1, 1);
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 init_z80_context(&context, &opts);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
94 //Z80 RAM
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 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
96 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
97 //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
98 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
99 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
100 {
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_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
102 }
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
103 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
104 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
105 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
106 }
674
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
107 z80_run(&context, 1000);
593
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
108 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
109 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
110 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
111 (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
112 (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
113 (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
114 context.sp, context.im, context.iff1, context.iff2);
1049
ef7ee9919a73 Partial support for undocumented flag bits
Michael Pavone <pavone@retrodev.com>
parents: 1046
diff changeset
115 printf("Flags: SZYHXVNC\n"
ef7ee9919a73 Partial support for undocumented flag bits
Michael Pavone <pavone@retrodev.com>
parents: 1046
diff changeset
116 " %d%d%d%d%d%d%d%d\n",
ef7ee9919a73 Partial support for undocumented flag bits
Michael Pavone <pavone@retrodev.com>
parents: 1046
diff changeset
117 context.flags[ZF_S], context.flags[ZF_Z], context.flags[ZF_XY] >> 5 & 1, context.flags[ZF_H],
ef7ee9919a73 Partial support for undocumented flag bits
Michael Pavone <pavone@retrodev.com>
parents: 1046
diff changeset
118 context.flags[ZF_XY] >> 3 & 1, context.flags[ZF_PV], context.flags[ZF_N], context.flags[ZF_C]
ef7ee9919a73 Partial support for undocumented flag bits
Michael Pavone <pavone@retrodev.com>
parents: 1046
diff changeset
119 );
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 puts("--Alternate Regs--");
593
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
121 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
122 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
123 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
124 (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
125 return 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 }