Mercurial > repos > blastem
comparison ztestrun.c @ 675:5bf4e77b1a43
Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 03 Jan 2015 21:20:18 -0800 |
parents | 16e5dfdb67b5 |
children | ab017fb09e77 |
comparison
equal
deleted
inserted
replaced
674:16e5dfdb67b5 | 675:5bf4e77b1a43 |
---|---|
7 #include "z80_to_x86.h" | 7 #include "z80_to_x86.h" |
8 #include "mem.h" | 8 #include "mem.h" |
9 #include "vdp.h" | 9 #include "vdp.h" |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <stddef.h> | |
12 | 13 |
13 uint8_t z80_ram[0x2000]; | 14 uint8_t z80_ram[0x2000]; |
14 | 15 |
15 uint8_t z80_unmapped_read(uint32_t location, void * context) | 16 uint8_t z80_unmapped_read(uint32_t location, void * context) |
16 { | 17 { |
36 { | 37 { |
37 long filesize; | 38 long filesize; |
38 uint8_t *filebuf; | 39 uint8_t *filebuf; |
39 z80_options opts; | 40 z80_options opts; |
40 z80_context context; | 41 z80_context context; |
41 if (argc < 2) { | 42 char *fname = NULL; |
43 uint8_t retranslate = 0; | |
44 for (int i = 1; i < argc; i++) | |
45 { | |
46 if (argv[i][0] == '-') { | |
47 switch(argv[i][1]) | |
48 { | |
49 case 'r': | |
50 retranslate = 1; | |
51 break; | |
52 default: | |
53 fprintf(stderr, "Unrecognized switch -%c\n", argv[i][1]); | |
54 exit(1); | |
55 } | |
56 } else if (!fname) { | |
57 fname = argv[i]; | |
58 } | |
59 } | |
60 if (!fname) { | |
42 fputs("usage: ztestrun zrom [cartrom]\n", stderr); | 61 fputs("usage: ztestrun zrom [cartrom]\n", stderr); |
43 exit(1); | 62 exit(1); |
44 } | 63 } |
45 FILE * f = fopen(argv[1], "rb"); | 64 FILE * f = fopen(fname, "rb"); |
46 if (!f) { | 65 if (!f) { |
47 fprintf(stderr, "unable to open file %s\n", argv[2]); | 66 fprintf(stderr, "unable to open file %s\n", fname); |
48 exit(1); | 67 exit(1); |
49 } | 68 } |
50 fseek(f, 0, SEEK_END); | 69 fseek(f, 0, SEEK_END); |
51 filesize = ftell(f); | 70 filesize = ftell(f); |
52 fseek(f, 0, SEEK_SET); | 71 fseek(f, 0, SEEK_SET); |
53 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); | 72 filesize = filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram); |
73 if (fread(z80_ram, 1, filesize, f) != filesize) { | |
74 fprintf(stderr, "error reading %s\n",fname); | |
75 exit(1); | |
76 } | |
54 fclose(f); | 77 fclose(f); |
55 init_z80_opts(&opts, z80_map, 2, 1); | 78 init_z80_opts(&opts, z80_map, 2, 1); |
56 init_z80_context(&context, &opts); | 79 init_z80_context(&context, &opts); |
57 //Z80 RAM | 80 //Z80 RAM |
58 context.mem_pointers[0] = z80_ram; | 81 context.mem_pointers[0] = z80_ram; |
59 context.int_cycle = CYCLE_NEVER; | 82 if (retranslate) { |
83 //run core long enough to translate code | |
84 z80_run(&context, 1); | |
85 for (int i = 0; i < filesize; i++) | |
86 { | |
87 z80_handle_code_write(i, &context); | |
88 } | |
89 z80_assert_reset(&context, context.current_cycle); | |
90 z80_clear_reset(&context, context.current_cycle + 3); | |
91 z80_adjust_cycles(&context, context.current_cycle); | |
92 } | |
60 z80_run(&context, 1000); | 93 z80_run(&context, 1000); |
61 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", | 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", |
62 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], | 95 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], |
63 context.regs[Z80_D], context.regs[Z80_E], | 96 context.regs[Z80_D], context.regs[Z80_E], |
64 (context.regs[Z80_H] << 8) | context.regs[Z80_L], | 97 (context.regs[Z80_H] << 8) | context.regs[Z80_L], |