# HG changeset patch # User Michael Pavone # Date 1549561405 28800 # Node ID 48a43dff4dc05747e88f5e0b6629d34e98e6568d # Parent 89ddf41a50bb7f175f6972dde9058a9111ea880a Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one diff -r 89ddf41a50bb -r 48a43dff4dc0 blastcpm.c --- a/blastcpm.c Wed Feb 06 09:13:24 2019 -0800 +++ b/blastcpm.c Thu Feb 07 09:43:25 2019 -0800 @@ -107,22 +107,8 @@ 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 -r 89ddf41a50bb -r 48a43dff4dc0 cpu_dsl.py --- a/cpu_dsl.py Wed Feb 06 09:13:24 2019 -0800 +++ b/cpu_dsl.py Thu Feb 07 09:43:25 2019 -0800 @@ -1281,6 +1281,7 @@ self.lastB = None self.lastBFlow = None self.conditional = False + self.declares = [] def __str__(self): pieces = [] @@ -1308,6 +1309,8 @@ 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 @@ subroutines = {} registers = None flags = None + declares = [] errors = [] info = {} line_num = 0 @@ -1505,6 +1509,8 @@ 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 @@ 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 @@ print(errors) else: p = Program(registers, instructions, subroutines, info, flags) + p.declares = declares p.booleans['dynarec'] = False p.booleans['interp'] = True diff -r 89ddf41a50bb -r 48a43dff4dc0 z80.cpu --- a/z80.cpu Wed Feb 06 09:13:24 2019 -0800 +++ b/z80.cpu Thu Feb 07 09:43:25 2019 -0800 @@ -6,6 +6,10 @@ 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 -r 89ddf41a50bb -r 48a43dff4dc0 z80_util.c --- a/z80_util.c Wed Feb 06 09:13:24 2019 -0800 +++ b/z80_util.c Thu Feb 07 09:43:25 2019 -0800 @@ -1,3 +1,4 @@ +#include void z80_read_8(z80_context *context) { @@ -43,4 +44,31 @@ 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 -r 89ddf41a50bb -r 48a43dff4dc0 ztestrun.c --- a/ztestrun.c Wed Feb 06 09:13:24 2019 -0800 +++ b/ztestrun.c Thu Feb 07 09:43:25 2019 -0800 @@ -96,15 +96,9 @@ 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 @@ 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) {