Mercurial > repos > blastem
annotate ztestrun.c @ 566:624dd5106060
Add backtrace (bt) command to 68K debugger
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 02 Mar 2014 14:41:43 -0800 |
parents | 140af5509ce7 |
children | 5ef3fe516da9 |
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 |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
3 This file is part of BlastEm. |
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> |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 uint8_t z80_ram[0x2000]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 uint16_t cart[0x200000]; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #define MCLKS_PER_Z80 15 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 //TODO: Figure out the exact value for this |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 #define MCLKS_PER_FRAME (MCLKS_LINE*262) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #define CYCLE_NEVER 0xFFFFFFFF |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 uint8_t z80_read_ym(uint16_t location, z80_context * context) |
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 return 0xFF; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 return context; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
293
diff
changeset
|
32 z80_context * z80_vdp_port_write(uint16_t location, z80_context * context, uint8_t value) |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
293
diff
changeset
|
33 { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
293
diff
changeset
|
34 return context; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
293
diff
changeset
|
35 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
293
diff
changeset
|
36 |
292
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 int main(int argc, char ** argv) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 long filesize; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 uint8_t *filebuf; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 x86_z80_options opts; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 z80_context context; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 if (argc < 2) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 fputs("usage: transz80 zrom [cartrom]\n", stderr); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 exit(1); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 FILE * f = fopen(argv[1], "rb"); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 if (!f) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 fprintf(stderr, "unable to open file %s\n", argv[2]); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 exit(1); |
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 fseek(f, 0, SEEK_END); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 filesize = ftell(f); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 fseek(f, 0, SEEK_SET); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 fclose(f); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 if (argc > 2) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 f = fopen(argv[2], "rb"); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 if (!f) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 fprintf(stderr, "unable to open file %s\n", argv[2]); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 exit(1); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 fseek(f, 0, SEEK_END); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 filesize = ftell(f); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 fseek(f, 0, SEEK_SET); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 fclose(f); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 *cur = (*cur >> 8) | (*cur << 8); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 init_x86_z80_opts(&opts); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 init_z80_context(&context, &opts); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 //Z80 RAM |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 context.mem_pointers[0] = z80_ram; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 context.sync_cycle = context.target_cycle = 1000; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 context.int_cycle = CYCLE_NEVER; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 //cartridge/bank |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 context.mem_pointers[1] = context.mem_pointers[2] = (uint8_t *)cart; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 z80_reset(&context); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 while (context.current_cycle < 1000) { |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 z80_run(&context); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 } |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
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", |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 context.regs[Z80_D], context.regs[Z80_E], |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 (context.regs[Z80_H] << 8) | context.regs[Z80_L], |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 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
|
92 printf("Flags: SZVNC\n" |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
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]); |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 puts("--Alternate Regs--"); |
293
ba97772b1662
Cleanup reg printing in z80 test runner
Mike Pavone <pavone@retrodev.com>
parents:
292
diff
changeset
|
95 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
|
96 context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C], |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 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
|
98 (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
|
99 return 0; |
b970ea214ecb
Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 } |