From 201639b58bf8b6c3ebbed8c33778c9c9c0a691ce Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Thu, 7 Feb 2019 09:43:25 -0800 Subject: Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one --- blastcpm.c | 14 -------------- cpu_dsl.py | 9 +++++++++ z80.cpu | 4 ++++ z80_util.c | 30 +++++++++++++++++++++++++++++- ztestrun.c | 12 ++---------- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/blastcpm.c b/blastcpm.c index 36fb3ae..5afcbae 100644 --- a/blastcpm.c +++ b/blastcpm.c @@ -107,22 +107,8 @@ int main(int argc, char **argv) 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 diff --git a/cpu_dsl.py b/cpu_dsl.py index 1bf7caf..ecb9f89 100755 --- a/cpu_dsl.py +++ b/cpu_dsl.py @@ -1281,6 +1281,7 @@ class Program: self.lastB = None self.lastBFlow = None self.conditional = False + self.declares = [] def __str__(self): pieces = [] @@ -1308,6 +1309,8 @@ class Program: hFile.write('\n}} {0}context;'.format(self.prefix)) hFile.write('\n') hFile.write('\nvoid {pre}execute({type} *context, uint32_t target_cycle);'.format(pre = self.prefix, type = self.context_type)) + for decl in self.declares: + hFile.write('\n' + decl) hFile.write('\n#endif //{0}_'.format(macro)) hFile.write('\n') hFile.close() @@ -1491,6 +1494,7 @@ def parse(f): subroutines = {} registers = None flags = None + declares = [] errors = [] info = {} line_num = 0 @@ -1505,6 +1509,8 @@ def parse(f): parts = [el.strip() for el in line.split(' ')] if type(cur_object) is dict: cur_object[parts[0]] = parts[1:] + elif type(cur_object) is list: + cur_object.append(line.strip()) else: cur_object = cur_object.processLine(parts) @@ -1562,6 +1568,8 @@ def parse(f): if flags is None: flags = Flags() cur_object = flags + elif line.strip() == 'declare': + cur_object = declares else: cur_object = SubRoutine(line.strip()) subroutines[cur_object.name] = cur_object @@ -1569,6 +1577,7 @@ def parse(f): print(errors) else: p = Program(registers, instructions, subroutines, info, flags) + p.declares = declares p.booleans['dynarec'] = False p.booleans['interp'] = True diff --git a/z80.cpu b/z80.cpu index db19837..3261187 100644 --- a/z80.cpu +++ b/z80.cpu @@ -6,6 +6,10 @@ info include z80_util.c header z80.h +declare + void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, memmap_chunk const * io_chunks, uint32_t num_io_chunks, uint32_t clock_divider, uint32_t io_address_mask); + z80_context * init_z80_context(z80_options *options); + regs main 8 b c d e h l f a alt 8 b' c' d' e' h' l' f' a' diff --git a/z80_util.c b/z80_util.c index 39526aa..e1f0855 100644 --- a/z80_util.c +++ b/z80_util.c @@ -1,3 +1,4 @@ +#include void z80_read_8(z80_context *context) { @@ -43,4 +44,31 @@ void z80_io_write8(z80_context *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 +} + +//quick hack until I get a chance to change which init method these get passed to +static memmap_chunk const * tmp_io_chunks; +static uint32_t tmp_num_io_chunks, tmp_io_mask; +void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, memmap_chunk const * io_chunks, uint32_t num_io_chunks, uint32_t clock_divider, uint32_t io_address_mask) +{ + memset(options, 0, sizeof(*options)); + options->gen.memmap = chunks; + options->gen.memmap_chunks = num_chunks; + options->gen.address_mask = 0xFFFF; + options->gen.max_address = 0xFFFF; + options->gen.clock_divider = clock_divider; + tmp_io_chunks = io_chunks; + tmp_num_io_chunks = num_io_chunks; + tmp_io_mask = io_address_mask; +} + +z80_context * init_z80_context(z80_options *options) +{ + z80_context *context = calloc(1, sizeof(z80_context)); + context->opts = options; + context->io_map = (memmap_chunk *)tmp_io_chunks; + context->io_chunks = tmp_num_io_chunks; + context->io_mask = tmp_io_mask; + return context; +} + diff --git a/ztestrun.c b/ztestrun.c index 42c934f..96a3738 100644 --- a/ztestrun.c +++ b/ztestrun.c @@ -96,15 +96,9 @@ int main(int argc, char ** argv) exit(1); } fclose(f); + init_z80_opts(&opts, z80_map, 2, port_map, 1, 1, 0xFF); + context = init_z80_context(&opts); #ifdef NEW_CORE - memset(&opts, 0, sizeof(opts)); - opts.gen.memmap = z80_map; - opts.gen.memmap_chunks = 2; - opts.gen.address_mask = 0xFFFF; - opts.gen.max_address = 0xFFFF; - opts.gen.clock_divider = 1; - context = calloc(1, sizeof(z80_context)); - context->opts = &opts; z80_execute(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->main[7], context->main[0], context->main[1], @@ -124,8 +118,6 @@ int main(int argc, char ** argv) context->alt[2], context->alt[3], (context->alt[4] << 8) | context->alt[5]); #else - init_z80_opts(&opts, z80_map, 2, port_map, 1, 1, 0xFF); - context = init_z80_context(&opts); //Z80 RAM context->mem_pointers[0] = z80_ram; if (retranslate) { -- cgit v1.2.3