annotate ztestrun.c @ 354:15dd6418fe67

Initial PSG support. Mostly works, noise channel is borked though.
author Mike Pavone <pavone@retrodev.com>
date Thu, 23 May 2013 23:42:42 -0700
parents ba97772b1662
children 62177cc39049
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
292
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include "z80inst.h"
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "z80_to_x86.h"
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "mem.h"
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "vdp.h"
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include <stdio.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include <stdlib.h>
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 uint8_t z80_ram[0x2000];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 uint16_t cart[0x200000];
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 #define MCLKS_PER_Z80 15
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 //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
13 #define MCLKS_PER_FRAME (MCLKS_LINE*262)
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 #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
15 #define CYCLE_NEVER 0xFFFFFFFF
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 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
18 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 return 0xFF;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 }
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 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
23 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 return context;
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 int main(int argc, char ** argv)
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 long filesize;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 uint8_t *filebuf;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 x86_z80_options opts;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 z80_context context;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 if (argc < 2) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 fputs("usage: transz80 zrom [cartrom]\n", stderr);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 FILE * f = fopen(argv[1], "rb");
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 if (!f) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 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
40 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 fseek(f, 0, SEEK_END);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 filesize = ftell(f);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 fseek(f, 0, SEEK_SET);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 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
46 fclose(f);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 if (argc > 2) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 f = fopen(argv[2], "rb");
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 if (!f) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 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
51 exit(1);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 fseek(f, 0, SEEK_END);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 filesize = ftell(f);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 fseek(f, 0, SEEK_SET);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 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
57 fclose(f);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 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
59 {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 *cur = (*cur >> 8) | (*cur << 8);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 }
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 init_x86_z80_opts(&opts);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 init_z80_context(&context, &opts);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 //Z80 RAM
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 context.mem_pointers[0] = z80_ram;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 context.sync_cycle = context.target_cycle = 1000;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 context.int_cycle = CYCLE_NEVER;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 //cartridge/bank
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 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
71 z80_reset(&context);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 while (context.current_cycle < 1000) {
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 z80_run(&context);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 }
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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",
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 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
77 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
78 (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
79 (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
80 (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
81 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
82 printf("Flags: SZVNC\n"
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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]);
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 puts("--Alternate Regs--");
293
ba97772b1662 Cleanup reg printing in z80 test runner
Mike Pavone <pavone@retrodev.com>
parents: 292
diff changeset
85 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
86 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
87 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
88 (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
89 return 0;
b970ea214ecb Added z80 test generator and z80 test runner.
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 }