comparison ztestrun.c @ 674:16e5dfdb67b5

Fix ztestrun
author Michael Pavone <pavone@retrodev.com>
date Sat, 03 Jan 2015 20:46:45 -0800
parents 759c38bf97f8
children 5bf4e77b1a43
comparison
equal deleted inserted replaced
673:7f1b5570b2a1 674:16e5dfdb67b5
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 12
13 uint8_t z80_ram[0x2000]; 13 uint8_t z80_ram[0x2000];
14
15 #define MCLKS_PER_Z80 15
16 //TODO: Figure out the exact value for this
17 #define MCLKS_PER_FRAME (MCLKS_LINE*262)
18 #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80)
19 #define CYCLE_NEVER 0xFFFFFFFF
20 14
21 uint8_t z80_unmapped_read(uint32_t location, void * context) 15 uint8_t z80_unmapped_read(uint32_t location, void * context)
22 { 16 {
23 return 0xFF; 17 return 0xFF;
24 } 18 }
31 const memmap_chunk z80_map[] = { 25 const memmap_chunk z80_map[] = {
32 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, 26 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL },
33 { 0x4000, 0x10000, 0xFFFF, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write} 27 { 0x4000, 0x10000, 0xFFFF, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write}
34 }; 28 };
35 29
30 void z80_next_int_pulse(z80_context * context)
31 {
32 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
33 }
34
36 int main(int argc, char ** argv) 35 int main(int argc, char ** argv)
37 { 36 {
38 long filesize; 37 long filesize;
39 uint8_t *filebuf; 38 uint8_t *filebuf;
40 z80_options opts; 39 z80_options opts;
41 z80_context context; 40 z80_context context;
42 if (argc < 2) { 41 if (argc < 2) {
43 fputs("usage: transz80 zrom [cartrom]\n", stderr); 42 fputs("usage: ztestrun zrom [cartrom]\n", stderr);
44 exit(1); 43 exit(1);
45 } 44 }
46 FILE * f = fopen(argv[1], "rb"); 45 FILE * f = fopen(argv[1], "rb");
47 if (!f) { 46 if (!f) {
48 fprintf(stderr, "unable to open file %s\n", argv[2]); 47 fprintf(stderr, "unable to open file %s\n", argv[2]);
51 fseek(f, 0, SEEK_END); 50 fseek(f, 0, SEEK_END);
52 filesize = ftell(f); 51 filesize = ftell(f);
53 fseek(f, 0, SEEK_SET); 52 fseek(f, 0, SEEK_SET);
54 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); 53 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f);
55 fclose(f); 54 fclose(f);
56 init_z80_opts(&opts, z80_map, 2); 55 init_z80_opts(&opts, z80_map, 2, 1);
57 init_z80_context(&context, &opts); 56 init_z80_context(&context, &opts);
58 //Z80 RAM 57 //Z80 RAM
59 context.mem_pointers[0] = z80_ram; 58 context.mem_pointers[0] = z80_ram;
60 context.sync_cycle = context.target_cycle = 1000;
61 context.int_cycle = CYCLE_NEVER; 59 context.int_cycle = CYCLE_NEVER;
62 z80_reset(&context); 60 z80_run(&context, 1000);
63 while (context.current_cycle < 1000) {
64 context.run(&context);
65 }
66 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", 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",
67 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], 62 context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C],
68 context.regs[Z80_D], context.regs[Z80_E], 63 context.regs[Z80_D], context.regs[Z80_E],
69 (context.regs[Z80_H] << 8) | context.regs[Z80_L], 64 (context.regs[Z80_H] << 8) | context.regs[Z80_L],
70 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], 65 (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL],