annotate z80_util.c @ 1748:48a43dff4dc0

Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
author Michael Pavone <pavone@retrodev.com>
date Thu, 07 Feb 2019 09:43:25 -0800
parents ca2336469397
children 01236179fc71
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1748
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
1 #include <string.h>
1706
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 void z80_read_8(z80_context *context)
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 {
1715
4fd84c3efc72 Implement 16-bit addition in new Z80 core along with necessary CPU DSL fixes to make them work right
Michael Pavone <pavone@retrodev.com>
parents: 1706
diff changeset
5 context->cycles += 3 * context->opts->gen.clock_divider;
1706
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 context->scratch1 = read_byte(context->scratch1, NULL, &context->opts->gen, context);
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 }
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 void z80_write_8(z80_context *context)
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 {
1715
4fd84c3efc72 Implement 16-bit addition in new Z80 core along with necessary CPU DSL fixes to make them work right
Michael Pavone <pavone@retrodev.com>
parents: 1706
diff changeset
11 context->cycles += 3 * context->opts->gen.clock_divider;
1706
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 write_byte(context->scratch2, context->scratch1, NULL, &context->opts->gen, context);
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 }
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 void z80_io_read8(z80_context *context)
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 {
1735
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
17 uint32_t tmp_mask = context->opts->gen.address_mask;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
18 memmap_chunk const *tmp_map = context->opts->gen.memmap;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
19 uint32_t tmp_chunks = context->opts->gen.memmap_chunks;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
20
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
21 context->opts->gen.address_mask = context->io_mask;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
22 context->opts->gen.memmap = context->io_map;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
23 context->opts->gen.memmap_chunks = context->io_chunks;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
24
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
25 context->scratch1 = read_byte(context->scratch1, NULL, &context->opts->gen, context);
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
26
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
27 context->opts->gen.address_mask = tmp_mask;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
28 context->opts->gen.memmap = tmp_map;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
29 context->opts->gen.memmap_chunks = tmp_chunks;
1706
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 }
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 void z80_io_write8(z80_context *context)
c2324849a5e5 Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 {
1735
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
34 uint32_t tmp_mask = context->opts->gen.address_mask;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
35 memmap_chunk const *tmp_map = context->opts->gen.memmap;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
36 uint32_t tmp_chunks = context->opts->gen.memmap_chunks;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
37
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
38 context->opts->gen.address_mask = context->io_mask;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
39 context->opts->gen.memmap = context->io_map;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
40 context->opts->gen.memmap_chunks = context->io_chunks;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
41
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
42 write_byte(context->scratch2, context->scratch1, NULL, &context->opts->gen, context);
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
43
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
44 context->opts->gen.address_mask = tmp_mask;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
45 context->opts->gen.memmap = tmp_map;
ca2336469397 Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents: 1715
diff changeset
46 context->opts->gen.memmap_chunks = tmp_chunks;
1748
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
47 }
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
48
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
49 //quick hack until I get a chance to change which init method these get passed to
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
50 static memmap_chunk const * tmp_io_chunks;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
51 static uint32_t tmp_num_io_chunks, tmp_io_mask;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
52 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)
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
53 {
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
54 memset(options, 0, sizeof(*options));
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
55 options->gen.memmap = chunks;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
56 options->gen.memmap_chunks = num_chunks;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
57 options->gen.address_mask = 0xFFFF;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
58 options->gen.max_address = 0xFFFF;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
59 options->gen.clock_divider = clock_divider;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
60 tmp_io_chunks = io_chunks;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
61 tmp_num_io_chunks = num_io_chunks;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
62 tmp_io_mask = io_address_mask;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
63 }
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
64
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
65 z80_context * init_z80_context(z80_options *options)
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
66 {
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
67 z80_context *context = calloc(1, sizeof(z80_context));
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
68 context->opts = options;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
69 context->io_map = (memmap_chunk *)tmp_io_chunks;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
70 context->io_chunks = tmp_num_io_chunks;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
71 context->io_mask = tmp_io_mask;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
72 return context;
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
73 }
48a43dff4dc0 Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
Michael Pavone <pavone@retrodev.com>
parents: 1735
diff changeset
74