Mercurial > repos > blastem
annotate z80_util.c @ 1892:1afd6e85ec26
Properly mask addresses to 24-bit in disassembler
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 05 Dec 2019 09:32:52 -0800 |
parents | 72540af9c90a |
children |
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; |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
6 uint8_t *fast = context->fastread[context->scratch1 >> 10]; |
1750
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
7 if (fast) { |
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
8 context->scratch1 = fast[context->scratch1 & 0x3FF]; |
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
9 } else { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
10 context->scratch1 = read_byte(context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); |
1750
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
11 } |
1706
c2324849a5e5
Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 } |
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 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
|
15 { |
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
|
16 context->cycles += 3 * context->opts->gen.clock_divider; |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
17 uint8_t *fast = context->fastwrite[context->scratch2 >> 10]; |
1750
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
18 if (fast) { |
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
19 fast[context->scratch2 & 0x3FF] = context->scratch1; |
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
20 } else { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
21 write_byte(context->scratch2, context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); |
1750
01236179fc71
Optimization to memory access in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1748
diff
changeset
|
22 } |
1706
c2324849a5e5
Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 } |
c2324849a5e5
Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 |
c2324849a5e5
Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 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
|
26 { |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 |
1755
28635b733d97
Add appropriate cycles for IO access
Michael Pavone <pavone@retrodev.com>
parents:
1753
diff
changeset
|
35 context->cycles += 4 * context->opts->gen.clock_divider; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
36 context->scratch1 = read_byte(context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); |
1735
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 = tmp_mask; |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
39 context->opts->gen.memmap = tmp_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 = tmp_chunks; |
1706
c2324849a5e5
Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } |
c2324849a5e5
Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 |
c2324849a5e5
Initial checkin of new WIP Z80 core using CPU DSL
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 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
|
44 { |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 |
1755
28635b733d97
Add appropriate cycles for IO access
Michael Pavone <pavone@retrodev.com>
parents:
1753
diff
changeset
|
53 context->cycles += 4 * context->opts->gen.clock_divider; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
54 write_byte(context->scratch2, context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); |
1735
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
55 |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
56 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
|
57 context->opts->gen.memmap = tmp_map; |
ca2336469397
Get new Z80 core running in CPM harness
Michael Pavone <pavone@retrodev.com>
parents:
1715
diff
changeset
|
58 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
|
59 } |
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 |
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 //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
|
62 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
|
63 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
|
64 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
|
65 { |
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 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 } |
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
|
76 |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
77 void z80_options_free(z80_options *opts) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
78 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
79 free(opts); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
80 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
81 |
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
|
82 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
|
83 { |
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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 context->io_mask = tmp_io_mask; |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
89 context->int_cycle = context->int_end_cycle = context->nmi_cycle = 0xFFFFFFFFU; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
90 z80_invalidate_code_range(context, 0, 0xFFFF); |
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
|
91 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
|
92 } |
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
|
93 |
1759
6e4faa10f9ee
Store sync_cycle in context rather than in a local in CPU DSL. Fix the timing of a number of instructions in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1755
diff
changeset
|
94 void z80_sync_cycle(z80_context *context, uint32_t target_cycle) |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
95 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
96 if (context->iff1 && context->int_cycle < target_cycle) { |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
97 if (context->cycles > context->int_end_cycle) { |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
98 context->int_cycle = 0xFFFFFFFFU; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
99 } else { |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
100 target_cycle = context->int_cycle; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
101 } |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
102 }; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
103 if (context->nmi_cycle < target_cycle) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
104 target_cycle = context->nmi_cycle; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
105 } |
1759
6e4faa10f9ee
Store sync_cycle in context rather than in a local in CPU DSL. Fix the timing of a number of instructions in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1755
diff
changeset
|
106 context->sync_cycle = target_cycle; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
107 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
108 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
109 void z80_run(z80_context *context, uint32_t target_cycle) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
110 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
111 if (context->reset || context->busack) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
112 context->cycles = target_cycle; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
113 } else if (target_cycle > context->cycles) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
114 if (context->busreq) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
115 //busreq is sampled at the end of an m-cycle |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
116 //we can approximate that by running for a single m-cycle after a bus request |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
117 target_cycle = context->cycles + 4 * context->opts->gen.clock_divider; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
118 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
119 z80_execute(context, target_cycle); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
120 if (context->busreq) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
121 context->busack = 1; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
122 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
123 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
124 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
125 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
126 void z80_assert_reset(z80_context * context, uint32_t cycle) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
127 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
128 z80_run(context, cycle); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
129 context->reset = 1; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
130 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
131 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
132 void z80_clear_reset(z80_context * context, uint32_t cycle) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
133 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
134 z80_run(context, cycle); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
135 if (context->reset) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
136 context->imode = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
137 context->iff1 = context->iff2 = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
138 context->pc = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
139 context->reset = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
140 if (context->busreq) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
141 //TODO: Figure out appropriate delay |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
142 context->busack = 1; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
143 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
144 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
145 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
146 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
147 #define MAX_MCYCLE_LENGTH 6 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
148 void z80_assert_busreq(z80_context * context, uint32_t cycle) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
149 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
150 z80_run(context, cycle); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
151 context->busreq = 1; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
152 //this is an imperfect aproximation since most M-cycles take less tstates than the max |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
153 //and a short 3-tstate m-cycle can take an unbounded number due to wait states |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
154 if (context->cycles - cycle > MAX_MCYCLE_LENGTH * context->opts->gen.clock_divider) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
155 context->busack = 1; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
156 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
157 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
158 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
159 void z80_clear_busreq(z80_context * context, uint32_t cycle) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
160 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
161 z80_run(context, cycle); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
162 context->busreq = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
163 context->busack = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
164 //there appears to be at least a 1 Z80 cycle delay between busreq |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
165 //being released and resumption of execution |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
166 context->cycles += context->opts->gen.clock_divider; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
167 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
168 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
169 void z80_assert_nmi(z80_context *context, uint32_t cycle) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
170 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
171 context->nmi_cycle = cycle; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
172 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
173 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
174 uint8_t z80_get_busack(z80_context * context, uint32_t cycle) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
175 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
176 z80_run(context, cycle); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
177 return context->busack; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
178 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
179 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
180 void z80_invalidate_code_range(z80_context *context, uint32_t startA, uint32_t endA) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
181 { |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
182 for(startA &= ~0x3FF; startA < endA; startA += 1024) |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
183 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
184 uint8_t *start = get_native_pointer(startA, (void**)context->mem_pointers, &context->opts->gen); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
185 if (start) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
186 uint8_t *end = get_native_pointer(startA + 1023, (void**)context->mem_pointers, &context->opts->gen); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
187 if (!end || end - start != 1023) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
188 start = NULL; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
189 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
190 } |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
191 context->fastread[startA >> 10] = start; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
192 start = get_native_write_pointer(startA, (void**)context->mem_pointers, &context->opts->gen); |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
193 if (start) { |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
194 uint8_t *end = get_native_write_pointer(startA + 1023, (void**)context->mem_pointers, &context->opts->gen); |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
195 if (!end || end - start != 1023) { |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
196 start = NULL; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
197 } |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
198 } |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
199 context->fastwrite[startA >> 10] = start; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
200 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
201 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
202 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
203 void z80_adjust_cycles(z80_context * context, uint32_t deduction) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
204 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
205 context->cycles -= deduction; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
206 if (context->int_cycle != 0xFFFFFFFFU) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
207 if (context->int_cycle > deduction) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
208 context->int_cycle -= deduction; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
209 } else { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
210 context->int_cycle = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
211 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
212 } |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
213 if (context->int_end_cycle != 0xFFFFFFFFU) { |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
214 if (context->int_end_cycle > deduction) { |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
215 context->int_end_cycle -= deduction; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
216 } else { |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
217 context->int_end_cycle = 0; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
218 } |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
219 } |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
220 if (context->nmi_cycle != 0xFFFFFFFFU) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
221 if (context->nmi_cycle > deduction) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
222 context->nmi_cycle -= deduction; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
223 } else { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
224 context->nmi_cycle = 0; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
225 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
226 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
227 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
228 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
229 void z80_serialize(z80_context *context, serialize_buffer *buf) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
230 { |
1784
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
231 save_int8(buf, context->main[1]);//C |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
232 save_int8(buf, context->main[0]);//B |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
233 save_int8(buf, context->main[3]);//E |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
234 save_int8(buf, context->main[2]);//D |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
235 save_int8(buf, context->main[5]);//L |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
236 save_int8(buf, context->main[4]);//H |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
237 save_int8(buf, context->ix);//IXL |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
238 save_int8(buf, context->ix >> 8);//IXH |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
239 save_int8(buf, context->iy);//IYL |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
240 save_int8(buf, context->iy >> 8);//IYH |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
241 save_int8(buf, context->i); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
242 save_int8(buf, (context->rhigh & 0x80) | (context->r & 0x7F)); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
243 save_int8(buf, context->main[7]);//A |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
244 uint8_t f = context->last_flag_result & 0xA8 |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
245 | (context->zflag ? 0x40 : 0) |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
246 | (context->chflags & 8 ? 0x10 : 0) |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
247 | (context->pvflag ? 4 : 0) |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
248 | (context->nflag ? 2 : 0) |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
249 | (context->chflags & 0x80 ? 1 : 0); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
250 save_int8(buf, f); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
251 save_int8(buf, context->alt[1]);//C |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
252 save_int8(buf, context->alt[0]);//B |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
253 save_int8(buf, context->alt[3]);//E |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
254 save_int8(buf, context->alt[2]);//D |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
255 save_int8(buf, context->alt[5]);//L |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
256 save_int8(buf, context->alt[4]);//H |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
257 save_int8(buf, 0);//non-existant alt ixl |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
258 save_int8(buf, 0);//non-existant alt ixh |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
259 save_int8(buf, 0);//non-existant alt iyl |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
260 save_int8(buf, 0);//non-existant alt iyh |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
261 save_int8(buf, 0);//non-existant alt i |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
262 save_int8(buf, 0);//non-existant alt r |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
263 save_int8(buf, context->alt[7]);//A |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
264 save_int8(buf, context->alt[6]);//F |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
265 |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
266 save_int16(buf, context->pc); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
267 save_int16(buf, context->sp); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
268 save_int8(buf, context->imode); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
269 save_int8(buf, context->iff1); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
270 save_int8(buf, context->iff2); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
271 uint8_t is_nmi = context->nmi_cycle != 0xFFFFFFFF && (context->nmi_cycle < context->int_cycle || !context->iff1); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
272 save_int8(buf, is_nmi);//int_is_nmi |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
273 save_int8(buf, context->busack); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
274 save_int32(buf, context->cycles); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
275 save_int32(buf, is_nmi ? context->nmi_cycle : context->int_cycle);//int_cycle |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
276 save_int32(buf, 0);//int_enable_cycle |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
277 save_int32(buf, context->int_cycle); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
278 save_int32(buf, context->int_end_cycle); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
279 save_int32(buf, context->nmi_cycle); |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
280 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
281 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
282 void z80_deserialize(deserialize_buffer *buf, void *vcontext) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
283 { |
1784
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
284 z80_context *context = vcontext; |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
285 context->main[1] = load_int8(buf);//C |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
286 context->main[0] = load_int8(buf);//B |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
287 context->main[3] = load_int8(buf);//E |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
288 context->main[2] = load_int8(buf);//D |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
289 context->main[5] = load_int8(buf);//L |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
290 context->main[4] = load_int8(buf);//H |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
291 context->ix = load_int8(buf);//IXL |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
292 context->ix |= load_int8(buf) << 8;//IXH |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
293 context->iy = load_int8(buf);//IYL |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
294 context->iy |= load_int8(buf) << 8;//IYH |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
295 context->i = load_int8(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
296 context->r = load_int8(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
297 context->rhigh = context->r & 0x80; |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
298 context->main[7] = load_int8(buf);//A |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
299 context->last_flag_result = load_int8(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
300 context->zflag = context->last_flag_result & 0x40; |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
301 context->chflags = context->last_flag_result & 0x10 ? 8 : 0; |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
302 context->pvflag = context->last_flag_result & 4; |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
303 context->nflag = context->last_flag_result & 2; |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
304 context->chflags |= context->last_flag_result & 1 ? 0x80 : 0; |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
305 context->alt[1] = load_int8(buf);//C |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
306 context->alt[0] = load_int8(buf);//B |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
307 context->alt[3] = load_int8(buf);//E |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
308 context->alt[2] = load_int8(buf);//D |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
309 context->alt[5] = load_int8(buf);//L |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
310 context->alt[4] = load_int8(buf);//H |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
311 load_int8(buf);//non-existant alt ixl |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
312 load_int8(buf);//non-existant alt ixh |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
313 load_int8(buf);//non-existant alt iyl |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
314 load_int8(buf);//non-existant alt iyh |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
315 load_int8(buf);//non-existant alt i |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
316 load_int8(buf);//non-existant alt r |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
317 context->alt[7] = load_int8(buf);//A |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
318 context->alt[6] = load_int8(buf);//F |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
319 |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
320 context->pc = load_int16(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
321 context->sp = load_int16(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
322 context->imode = load_int8(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
323 context->iff1 = load_int8(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
324 context->iff2 = load_int8(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
325 load_int8(buf);//int_is_nmi |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
326 context->busack = load_int8(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
327 context->cycles = load_int32(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
328 load_int32(buf);//int_cycle |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
329 load_int32(buf);//int_enable_cycle |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
330 context->int_cycle = load_int32(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
331 context->int_end_cycle = load_int32(buf); |
72540af9c90a
Implement serialization/deserialization in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
332 context->nmi_cycle = load_int32(buf); |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
333 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
334 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
335 void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
336 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
337 } |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
338 |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
339 void zremove_breakpoint(z80_context * context, uint16_t address) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
340 { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1750
diff
changeset
|
341 } |