changeset 1735:ca2336469397

Get new Z80 core running in CPM harness
author Michael Pavone <pavone@retrodev.com>
date Sun, 03 Feb 2019 11:05:40 -0800
parents 88fbc4e711fd
children 06c2438c7641
files blastcpm.c cpu_dsl.py z80.cpu z80_util.c
diffstat 4 files changed, 65 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/blastcpm.c	Sun Feb 03 10:40:41 2019 -0800
+++ b/blastcpm.c	Sun Feb 03 11:05:40 2019 -0800
@@ -4,7 +4,11 @@
 #include <string.h>
 #include <sys/select.h>
 
+#ifdef NEW_CORE
+#include "z80.h"
+#else
 #include "z80_to_x86.h"
+#endif
 #include "util.h"
 
 uint8_t ram[64 * 1024];
@@ -14,10 +18,12 @@
 #define OS_RESET 0xE403
 int headless = 1;
 
+#ifndef NEW_CORE
 void z80_next_int_pulse(z80_context * context)
 {
 	context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
 }
+#endif
 
 void render_errorbox(char *title, char *message)
 {
@@ -65,7 +71,7 @@
 	{ 0x0000, 0x10000,  0xFFFF, 0, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, NULL, NULL, NULL, NULL},
 };
 
-const memmap_chunk io_map[] = {
+memmap_chunk io_map[] = {
 	{ 0x0, 0x1, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_read, console_write},
 	{ 0x1, 0x2, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, console_status_read, console_flush_write},
 	{ 0x2, 0x3, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, NULL, exit_write},
@@ -101,12 +107,32 @@
 	
 	z80_options opts;
 	z80_context *context;
+#ifdef NEW_CORE
+	memset(&opts, 0, sizeof(opts));
+	opts.gen.memmap = z80_map;
+	opts.gen.memmap_chunks = 1;
+	opts.gen.address_mask = 0xFFFF;
+	opts.gen.max_address = 0xFFFF;
+	opts.gen.clock_divider = 1;
+	context = calloc(1, sizeof(z80_context));
+	context->opts = &opts;
+	context->io_map = io_map;
+	context->io_chunks = 3;
+	context->io_mask = 0xFF;
+#else
 	init_z80_opts(&opts, z80_map, 1, io_map, 3, 1, 0xFF);
 	context = init_z80_context(&opts);
+#endif
 	for(;;)
 	{
+#ifdef NEW_CORE
+		z80_execute(context, 1000000);
+		context->cycles = 0;
+#else
 		z80_run(context, 1000000);
 		context->current_cycle = 0;
+#endif
+		
 	}
 	return 0;
 }
\ No newline at end of file
--- a/cpu_dsl.py	Sun Feb 03 10:40:41 2019 -0800
+++ b/cpu_dsl.py	Sun Feb 03 11:05:40 2019 -0800
@@ -1026,7 +1026,7 @@
 			self.addRegArray(parts[0], int(parts[1]), parts[2:])
 		else:
 			if parts[1].startswith('ptr'):
-				self.addPointer(parts[0], int(parts[1][3:]))
+				self.addPointer(parts[0], parts[1][3:])
 			else:
 				self.addReg(parts[0], int(parts[1]))
 		return self
@@ -1034,7 +1034,14 @@
 	def writeHeader(self, otype, hFile):
 		fieldList = []
 		for pointer in self.pointers:
-			hFile.write('\n\tuint{sz}_t *{nm};'.format(nm=pointer, sz=self.pointers[pointer]))
+			stars = '*'
+			ptype = self.pointers[pointer]
+			while ptype.startswith('ptr'):
+				stars += '*'
+				ptype = ptype[3:]
+			if ptype.isdigit():
+				ptype = 'uint{sz}_t'.format(sz=ptype)
+			hFile.write('\n\t{ptype} {stars}{nm};'.format(nm=pointer, ptype=ptype, stars=stars))
 		for reg in self.regs:
 			if not self.isRegArrayMember(reg):
 				fieldList.append((self.regs[reg], 1, reg))
--- a/z80.cpu	Sun Feb 03 10:40:41 2019 -0800
+++ b/z80.cpu	Sun Feb 03 11:05:40 2019 -0800
@@ -27,6 +27,9 @@
 	zflag 8
 	scratch1 16
 	scratch2 16
+	io_map ptrmemmap_chunk
+	io_chunks 32
+	io_mask 32
 	
 flags
 	register f
--- a/z80_util.c	Sun Feb 03 10:40:41 2019 -0800
+++ b/z80_util.c	Sun Feb 03 11:05:40 2019 -0800
@@ -13,8 +13,34 @@
 
 void z80_io_read8(z80_context *context)
 {
+	uint32_t tmp_mask = context->opts->gen.address_mask;
+	memmap_chunk const *tmp_map = context->opts->gen.memmap;
+	uint32_t tmp_chunks = context->opts->gen.memmap_chunks;
+	
+	context->opts->gen.address_mask = context->io_mask;
+	context->opts->gen.memmap = context->io_map;
+	context->opts->gen.memmap_chunks = context->io_chunks;
+	
+	context->scratch1 = read_byte(context->scratch1, NULL, &context->opts->gen, context);
+	
+	context->opts->gen.address_mask = tmp_mask;
+	context->opts->gen.memmap = tmp_map;
+	context->opts->gen.memmap_chunks = tmp_chunks;
 }
 
 void z80_io_write8(z80_context *context)
 {
+	uint32_t tmp_mask = context->opts->gen.address_mask;
+	memmap_chunk const *tmp_map = context->opts->gen.memmap;
+	uint32_t tmp_chunks = context->opts->gen.memmap_chunks;
+	
+	context->opts->gen.address_mask = context->io_mask;
+	context->opts->gen.memmap = context->io_map;
+	context->opts->gen.memmap_chunks = context->io_chunks;
+	
+	write_byte(context->scratch2, context->scratch1, NULL, &context->opts->gen, context);
+	
+	context->opts->gen.address_mask = tmp_mask;
+	context->opts->gen.memmap = tmp_map;
+	context->opts->gen.memmap_chunks = tmp_chunks;
 }
\ No newline at end of file