annotate ztestrun.c @ 716:b707a8ddc202

Make sure z80_save_reg does nothing when there is no register in the reg field of the instruction. This fixes a bug that corrupted SP in the MDEM 2011 demo
author Michael Pavone <pavone@retrodev.com>
date Sun, 17 May 2015 20:03:27 -0700
parents 5bf4e77b1a43
children ab017fb09e77
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>
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 uint8_t z80_ram[0x2000];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15
593
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
16 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
17 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 return 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20
593
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
21 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
22 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 return context;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 }
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 const memmap_chunk z80_map[] = {
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
27 { 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
28 { 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
29 };
364
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 293
diff changeset
30
674
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
31 void z80_next_int_pulse(z80_context * context)
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
32 {
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
33 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
34 }
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
35
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 int main(int argc, char ** argv)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 long filesize;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 uint8_t *filebuf;
593
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
40 z80_options opts;
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 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
42 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
43 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
44 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
45 {
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
46 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
47 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
48 {
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
49 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
50 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
51 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
52 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
53 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
54 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
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 } 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
57 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
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 }
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 (!fname) {
674
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
61 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
62 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 }
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
64 FILE * f = fopen(fname, "rb");
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 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
66 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
67 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 fseek(f, 0, SEEK_END);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 filesize = ftell(f);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 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
72 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
73 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
74 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
75 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
76 }
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 fclose(f);
674
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
78 init_z80_opts(&opts, z80_map, 2, 1);
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
79 init_z80_context(&context, &opts);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 //Z80 RAM
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
81 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
82 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
83 //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
84 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
85 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
86 {
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 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
88 }
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 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
90 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
91 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
92 }
674
16e5dfdb67b5 Fix ztestrun
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
93 z80_run(&context, 1000);
593
5ef3fe516da9 Z80 core is sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
94 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
95 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
96 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
97 (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
98 (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
99 (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
100 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
101 printf("Flags: SZVNC\n"
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 " %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
103 puts("--Alternate Regs--");
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\n",
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 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
106 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
107 (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
108 return 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 }