comparison ztestrun.c @ 744:fc68992cf18d

Merge windows branch with latest changes
author Michael Pavone <pavone@retrodev.com>
date Thu, 28 May 2015 21:19:55 -0700
parents 5bf4e77b1a43
children ab017fb09e77
comparison
equal deleted inserted replaced
743:cf78cb045fa4 744:fc68992cf18d
1 /* 1 /*
2 Copyright 2013 Michael Pavone 2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm. 3 This file is part of BlastEm.
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. 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.
5 */ 5 */
6 #include "z80inst.h" 6 #include "z80inst.h"
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 uint16_t cart[0x200000];
15 15
16 #define MCLKS_PER_Z80 15 16 uint8_t z80_unmapped_read(uint32_t location, void * context)
17 //TODO: Figure out the exact value for this
18 #define MCLKS_PER_FRAME (MCLKS_LINE*262)
19 #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80)
20 #define CYCLE_NEVER 0xFFFFFFFF
21
22 uint8_t z80_read_ym(uint16_t location, z80_context * context)
23 { 17 {
24 return 0xFF; 18 return 0xFF;
25 } 19 }
26 20
27 z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value) 21 void * z80_unmapped_write(uint32_t location, void * context, uint8_t value)
28 { 22 {
29 return context; 23 return context;
30 } 24 }
31 25
32 z80_context * z80_vdp_port_write(uint16_t location, z80_context * context, uint8_t value) 26 const memmap_chunk z80_map[] = {
27 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL },
28 { 0x4000, 0x10000, 0xFFFF, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write}
29 };
30
31 void z80_next_int_pulse(z80_context * context)
33 { 32 {
34 return context; 33 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
35 } 34 }
36 35
37 int main(int argc, char ** argv) 36 int main(int argc, char ** argv)
38 { 37 {
39 long filesize; 38 long filesize;
40 uint8_t *filebuf; 39 uint8_t *filebuf;
41 x86_z80_options opts; 40 z80_options opts;
42 z80_context context; 41 z80_context context;
43 if (argc < 2) { 42 char *fname = NULL;
44 fputs("usage: transz80 zrom [cartrom]\n", stderr); 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) {
61 fputs("usage: ztestrun zrom [cartrom]\n", stderr);
45 exit(1); 62 exit(1);
46 } 63 }
47 FILE * f = fopen(argv[1], "rb"); 64 FILE * f = fopen(fname, "rb");
48 if (!f) { 65 if (!f) {
49 fprintf(stderr, "unable to open file %s\n", argv[2]); 66 fprintf(stderr, "unable to open file %s\n", fname);
50 exit(1); 67 exit(1);
51 } 68 }
52 fseek(f, 0, SEEK_END); 69 fseek(f, 0, SEEK_END);
53 filesize = ftell(f); 70 filesize = ftell(f);
54 fseek(f, 0, SEEK_SET); 71 fseek(f, 0, SEEK_SET);
55 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 }
56 fclose(f); 77 fclose(f);
57 if (argc > 2) { 78 init_z80_opts(&opts, z80_map, 2, 1);
58 f = fopen(argv[2], "rb");
59 if (!f) {
60 fprintf(stderr, "unable to open file %s\n", argv[2]);
61 exit(1);
62 }
63 fseek(f, 0, SEEK_END);
64 filesize = ftell(f);
65 fseek(f, 0, SEEK_SET);
66 fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f);
67 fclose(f);
68 for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur)
69 {
70 *cur = (*cur >> 8) | (*cur << 8);
71 }
72 }
73 init_x86_z80_opts(&opts);
74 init_z80_context(&context, &opts); 79 init_z80_context(&context, &opts);
75 //Z80 RAM 80 //Z80 RAM
76 context.mem_pointers[0] = z80_ram; 81 context.mem_pointers[0] = z80_ram;
77 context.sync_cycle = context.target_cycle = 1000; 82 if (retranslate) {
78 context.int_cycle = CYCLE_NEVER; 83 //run core long enough to translate code
79 //cartridge/bank 84 z80_run(&context, 1);
80 context.mem_pointers[1] = context.mem_pointers[2] = (uint8_t *)cart; 85 for (int i = 0; i < filesize; i++)
81 z80_reset(&context); 86 {
82 while (context.current_cycle < 1000) { 87 z80_handle_code_write(i, &context);
83 z80_run(&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);
84 } 92 }
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", 93 z80_run(&context, 1000);
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",
86 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],
87 context.regs[Z80_D], context.regs[Z80_E], 96 context.regs[Z80_D], context.regs[Z80_E],
88 (context.regs[Z80_H] << 8) | context.regs[Z80_L], 97 (context.regs[Z80_H] << 8) | context.regs[Z80_L],
89 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], 98 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL],
90 (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], 99 (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL],
91 context.sp, context.im, context.iff1, context.iff2); 100 context.sp, context.im, context.iff1, context.iff2);
92 printf("Flags: SZVNC\n" 101 printf("Flags: SZVNC\n"
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]); 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]);
94 puts("--Alternate Regs--"); 103 puts("--Alternate Regs--");
95 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n", 104 printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n",
96 context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C], 105 context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C],
97 context.alt_regs[Z80_D], context.alt_regs[Z80_E], 106 context.alt_regs[Z80_D], context.alt_regs[Z80_E],
98 (context.alt_regs[Z80_H] << 8) | context.alt_regs[Z80_L]); 107 (context.alt_regs[Z80_H] << 8) | context.alt_regs[Z80_L]);
99 return 0; 108 return 0;
100 } 109 }