From 12c73dc400c1b6b61531df4ff0fd1efe4ef7ae12 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Mon, 22 Dec 2014 20:55:10 -0800 Subject: Z80 core is sort of working again --- ztestrun.c | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) (limited to 'ztestrun.c') diff --git a/ztestrun.c b/ztestrun.c index 9f500f1..781afa9 100644 --- a/ztestrun.c +++ b/ztestrun.c @@ -1,6 +1,6 @@ /* Copyright 2013 Michael Pavone - This file is part of BlastEm. + This file is part of BlastEm. BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. */ #include "z80inst.h" @@ -11,7 +11,6 @@ #include uint8_t z80_ram[0x2000]; -uint16_t cart[0x200000]; #define MCLKS_PER_Z80 15 //TODO: Figure out the exact value for this @@ -19,26 +18,26 @@ uint16_t cart[0x200000]; #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) #define CYCLE_NEVER 0xFFFFFFFF -uint8_t z80_read_ym(uint16_t location, z80_context * context) +uint8_t z80_unmapped_read(uint32_t location, void * context) { return 0xFF; } -z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value) +void * z80_unmapped_write(uint32_t location, void * context, uint8_t value) { return context; } -z80_context * z80_vdp_port_write(uint16_t location, z80_context * context, uint8_t value) -{ - return context; -} +const memmap_chunk z80_map[] = { + { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, + { 0x4000, 0x10000, 0xFFFF, 0, MMAP_READ | MMAP_WRITE, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write} +}; int main(int argc, char ** argv) { long filesize; uint8_t *filebuf; - x86_z80_options opts; + z80_options opts; z80_context context; if (argc < 2) { fputs("usage: transz80 zrom [cartrom]\n", stderr); @@ -54,47 +53,29 @@ int main(int argc, char ** argv) fseek(f, 0, SEEK_SET); fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); fclose(f); - if (argc > 2) { - f = fopen(argv[2], "rb"); - if (!f) { - fprintf(stderr, "unable to open file %s\n", argv[2]); - exit(1); - } - fseek(f, 0, SEEK_END); - filesize = ftell(f); - fseek(f, 0, SEEK_SET); - fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f); - fclose(f); - for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) - { - *cur = (*cur >> 8) | (*cur << 8); - } - } - init_x86_z80_opts(&opts); + init_x86_z80_opts(&opts, z80_map, 2); init_z80_context(&context, &opts); //Z80 RAM context.mem_pointers[0] = z80_ram; context.sync_cycle = context.target_cycle = 1000; context.int_cycle = CYCLE_NEVER; - //cartridge/bank - context.mem_pointers[1] = context.mem_pointers[2] = (uint8_t *)cart; z80_reset(&context); while (context.current_cycle < 1000) { - z80_run(&context); + context.run(&context); } - 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", + 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", context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], - context.regs[Z80_D], context.regs[Z80_E], - (context.regs[Z80_H] << 8) | context.regs[Z80_L], - (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], - (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], + context.regs[Z80_D], context.regs[Z80_E], + (context.regs[Z80_H] << 8) | context.regs[Z80_L], + (context.regs[Z80_IXH] << 8) | context.regs[Z80_IXL], + (context.regs[Z80_IYH] << 8) | context.regs[Z80_IYL], context.sp, context.im, context.iff1, context.iff2); printf("Flags: SZVNC\n" " %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]); puts("--Alternate Regs--"); - printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n", + printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n", context.alt_regs[Z80_A], context.alt_regs[Z80_B], context.alt_regs[Z80_C], - context.alt_regs[Z80_D], context.alt_regs[Z80_E], + context.alt_regs[Z80_D], context.alt_regs[Z80_E], (context.alt_regs[Z80_H] << 8) | context.alt_regs[Z80_L]); return 0; } -- cgit v1.2.3 From 4bf9f13589dc4c9e59ead0a864dac28a518949f0 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Fri, 26 Dec 2014 21:26:25 -0800 Subject: Fix memory map flags in ztestrun --- ztestrun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ztestrun.c') diff --git a/ztestrun.c b/ztestrun.c index 781afa9..1c7c6d8 100644 --- a/ztestrun.c +++ b/ztestrun.c @@ -30,7 +30,7 @@ void * z80_unmapped_write(uint32_t location, void * context, uint8_t value) const memmap_chunk z80_map[] = { { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, - { 0x4000, 0x10000, 0xFFFF, 0, MMAP_READ | MMAP_WRITE, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write} + { 0x4000, 0x10000, 0xFFFF, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write} }; int main(int argc, char ** argv) -- cgit v1.2.3 From d41ae43228509a1a67446492b844013cf1e68c36 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Thu, 1 Jan 2015 20:26:22 -0800 Subject: Minor Z80 core cleanup --- ztestrun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ztestrun.c') diff --git a/ztestrun.c b/ztestrun.c index 1c7c6d8..ef042b5 100644 --- a/ztestrun.c +++ b/ztestrun.c @@ -53,7 +53,7 @@ int main(int argc, char ** argv) fseek(f, 0, SEEK_SET); fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); fclose(f); - init_x86_z80_opts(&opts, z80_map, 2); + init_z80_opts(&opts, z80_map, 2); init_z80_context(&context, &opts); //Z80 RAM context.mem_pointers[0] = z80_ram; -- cgit v1.2.3 From b50d8fcdaf4fd846d34f3bf07d7e6fd8675b7178 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 3 Jan 2015 20:46:45 -0800 Subject: Fix ztestrun --- ztestrun.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'ztestrun.c') diff --git a/ztestrun.c b/ztestrun.c index ef042b5..e9b8bf5 100644 --- a/ztestrun.c +++ b/ztestrun.c @@ -12,12 +12,6 @@ uint8_t z80_ram[0x2000]; -#define MCLKS_PER_Z80 15 -//TODO: Figure out the exact value for this -#define MCLKS_PER_FRAME (MCLKS_LINE*262) -#define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) -#define CYCLE_NEVER 0xFFFFFFFF - uint8_t z80_unmapped_read(uint32_t location, void * context) { return 0xFF; @@ -33,6 +27,11 @@ const memmap_chunk z80_map[] = { { 0x4000, 0x10000, 0xFFFF, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write} }; +void z80_next_int_pulse(z80_context * context) +{ + context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER; +} + int main(int argc, char ** argv) { long filesize; @@ -40,7 +39,7 @@ int main(int argc, char ** argv) z80_options opts; z80_context context; if (argc < 2) { - fputs("usage: transz80 zrom [cartrom]\n", stderr); + fputs("usage: ztestrun zrom [cartrom]\n", stderr); exit(1); } FILE * f = fopen(argv[1], "rb"); @@ -53,16 +52,12 @@ int main(int argc, char ** argv) fseek(f, 0, SEEK_SET); fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); fclose(f); - init_z80_opts(&opts, z80_map, 2); + init_z80_opts(&opts, z80_map, 2, 1); init_z80_context(&context, &opts); //Z80 RAM context.mem_pointers[0] = z80_ram; - context.sync_cycle = context.target_cycle = 1000; context.int_cycle = CYCLE_NEVER; - z80_reset(&context); - while (context.current_cycle < 1000) { - context.run(&context); - } + z80_run(&context, 1000); 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", context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], context.regs[Z80_D], context.regs[Z80_E], -- cgit v1.2.3 From bacdb22a02104be7b3bd32dad05c52ce706f069f Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 3 Jan 2015 21:20:18 -0800 Subject: Added a -r flag to ztestrun that force instruction retranslation to allow a quick sanity test of that feature --- ztestrun.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'ztestrun.c') diff --git a/ztestrun.c b/ztestrun.c index e9b8bf5..0e262d3 100644 --- a/ztestrun.c +++ b/ztestrun.c @@ -9,6 +9,7 @@ #include "vdp.h" #include #include +#include uint8_t z80_ram[0x2000]; @@ -38,25 +39,57 @@ int main(int argc, char ** argv) uint8_t *filebuf; z80_options opts; z80_context context; - if (argc < 2) { + char *fname = NULL; + uint8_t retranslate = 0; + for (int i = 1; i < argc; i++) + { + if (argv[i][0] == '-') { + switch(argv[i][1]) + { + case 'r': + retranslate = 1; + break; + default: + fprintf(stderr, "Unrecognized switch -%c\n", argv[i][1]); + exit(1); + } + } else if (!fname) { + fname = argv[i]; + } + } + if (!fname) { fputs("usage: ztestrun zrom [cartrom]\n", stderr); exit(1); } - FILE * f = fopen(argv[1], "rb"); + FILE * f = fopen(fname, "rb"); if (!f) { - fprintf(stderr, "unable to open file %s\n", argv[2]); + fprintf(stderr, "unable to open file %s\n", fname); exit(1); } fseek(f, 0, SEEK_END); filesize = ftell(f); fseek(f, 0, SEEK_SET); - fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); + filesize = filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram); + if (fread(z80_ram, 1, filesize, f) != filesize) { + fprintf(stderr, "error reading %s\n",fname); + exit(1); + } fclose(f); init_z80_opts(&opts, z80_map, 2, 1); init_z80_context(&context, &opts); //Z80 RAM context.mem_pointers[0] = z80_ram; - context.int_cycle = CYCLE_NEVER; + if (retranslate) { + //run core long enough to translate code + z80_run(&context, 1); + for (int i = 0; i < filesize; i++) + { + z80_handle_code_write(i, &context); + } + z80_assert_reset(&context, context.current_cycle); + z80_clear_reset(&context, context.current_cycle + 3); + z80_adjust_cycles(&context, context.current_cycle); + } z80_run(&context, 1000); 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", context.regs[Z80_A], context.regs[Z80_B], context.regs[Z80_C], -- cgit v1.2.3