Mercurial > repos > blastem
comparison z80_util.c @ 1753:33ec5df77fac
Integration of new Z80 core is sort of working now
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 12 Feb 2019 09:58:04 -0800 |
parents | d6d4c006a7b3 |
children | 28635b733d97 |
comparison
equal
deleted
inserted
replaced
1752:d6d4c006a7b3 | 1753:33ec5df77fac |
---|---|
1 #include <string.h> | 1 #include <string.h> |
2 | 2 |
3 void z80_read_8(z80_context *context) | 3 void z80_read_8(z80_context *context) |
4 { | 4 { |
5 context->cycles += 3 * context->opts->gen.clock_divider; | 5 context->cycles += 3 * context->opts->gen.clock_divider; |
6 uint8_t *fast = context->fastmem[context->scratch1 >> 10]; | 6 uint8_t *fast = context->fastread[context->scratch1 >> 10]; |
7 if (fast) { | 7 if (fast) { |
8 context->scratch1 = fast[context->scratch1 & 0x3FF]; | 8 context->scratch1 = fast[context->scratch1 & 0x3FF]; |
9 } else { | 9 } else { |
10 context->scratch1 = read_byte(context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); | 10 context->scratch1 = read_byte(context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); |
11 } | 11 } |
12 } | 12 } |
13 | 13 |
14 void z80_write_8(z80_context *context) | 14 void z80_write_8(z80_context *context) |
15 { | 15 { |
16 context->cycles += 3 * context->opts->gen.clock_divider; | 16 context->cycles += 3 * context->opts->gen.clock_divider; |
17 uint8_t *fast = context->fastmem[context->scratch2 >> 10]; | 17 uint8_t *fast = context->fastwrite[context->scratch2 >> 10]; |
18 if (fast) { | 18 if (fast) { |
19 fast[context->scratch2 & 0x3FF] = context->scratch1; | 19 fast[context->scratch2 & 0x3FF] = context->scratch1; |
20 } else { | 20 } else { |
21 write_byte(context->scratch2, context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); | 21 write_byte(context->scratch2, context->scratch1, (void **)context->mem_pointers, &context->opts->gen, context); |
22 } | 22 } |
82 z80_context *context = calloc(1, sizeof(z80_context)); | 82 z80_context *context = calloc(1, sizeof(z80_context)); |
83 context->opts = options; | 83 context->opts = options; |
84 context->io_map = (memmap_chunk *)tmp_io_chunks; | 84 context->io_map = (memmap_chunk *)tmp_io_chunks; |
85 context->io_chunks = tmp_num_io_chunks; | 85 context->io_chunks = tmp_num_io_chunks; |
86 context->io_mask = tmp_io_mask; | 86 context->io_mask = tmp_io_mask; |
87 context->int_cycle = context->nmi_cycle = 0xFFFFFFFFU; | 87 context->int_cycle = context->int_end_cycle = context->nmi_cycle = 0xFFFFFFFFU; |
88 for(uint32_t address = 0; address < 0x10000; address+=1024) | 88 z80_invalidate_code_range(context, 0, 0xFFFF); |
89 { | |
90 uint8_t *start = get_native_pointer(address, (void**)context->mem_pointers, &options->gen); | |
91 if (start) { | |
92 uint8_t *end = get_native_pointer(address + 1023, (void**)context->mem_pointers, &options->gen); | |
93 if (end && end - start == 1023) { | |
94 context->fastmem[address >> 10] = start; | |
95 } | |
96 } | |
97 } | |
98 return context; | 89 return context; |
99 } | 90 } |
100 | 91 |
101 uint32_t z80_sync_cycle(z80_context *context, uint32_t target_cycle) | 92 uint32_t z80_sync_cycle(z80_context *context, uint32_t target_cycle) |
102 { | 93 { |
103 if (context->iff1 && context->int_cycle < target_cycle) { | 94 if (context->iff1 && context->int_cycle < target_cycle) { |
104 target_cycle = context->int_cycle; | 95 if (context->cycles > context->int_end_cycle) { |
96 context->int_cycle = 0xFFFFFFFFU; | |
97 } else { | |
98 target_cycle = context->int_cycle; | |
99 } | |
105 }; | 100 }; |
106 if (context->nmi_cycle < target_cycle) { | 101 if (context->nmi_cycle < target_cycle) { |
107 target_cycle = context->nmi_cycle; | 102 target_cycle = context->nmi_cycle; |
108 } | 103 } |
109 return target_cycle; | 104 return target_cycle; |
180 return context->busack; | 175 return context->busack; |
181 } | 176 } |
182 | 177 |
183 void z80_invalidate_code_range(z80_context *context, uint32_t startA, uint32_t endA) | 178 void z80_invalidate_code_range(z80_context *context, uint32_t startA, uint32_t endA) |
184 { | 179 { |
185 for(startA &= ~0x3FF; startA += 1024; startA < endA) | 180 for(startA &= ~0x3FF; startA < endA; startA += 1024) |
186 { | 181 { |
187 uint8_t *start = get_native_pointer(startA, (void**)context->mem_pointers, &context->opts->gen); | 182 uint8_t *start = get_native_pointer(startA, (void**)context->mem_pointers, &context->opts->gen); |
188 if (start) { | 183 if (start) { |
189 uint8_t *end = get_native_pointer(startA + 1023, (void**)context->mem_pointers, &context->opts->gen); | 184 uint8_t *end = get_native_pointer(startA + 1023, (void**)context->mem_pointers, &context->opts->gen); |
190 if (!end || end - start != 1023) { | 185 if (!end || end - start != 1023) { |
191 start = NULL; | 186 start = NULL; |
192 } | 187 } |
193 } | 188 } |
194 context->fastmem[startA >> 10] = start; | 189 context->fastread[startA >> 10] = start; |
190 start = get_native_write_pointer(startA, (void**)context->mem_pointers, &context->opts->gen); | |
191 if (start) { | |
192 uint8_t *end = get_native_write_pointer(startA + 1023, (void**)context->mem_pointers, &context->opts->gen); | |
193 if (!end || end - start != 1023) { | |
194 start = NULL; | |
195 } | |
196 } | |
197 context->fastwrite[startA >> 10] = start; | |
195 } | 198 } |
196 } | 199 } |
197 | 200 |
198 void z80_adjust_cycles(z80_context * context, uint32_t deduction) | 201 void z80_adjust_cycles(z80_context * context, uint32_t deduction) |
199 { | 202 { |
203 context->int_cycle -= deduction; | 206 context->int_cycle -= deduction; |
204 } else { | 207 } else { |
205 context->int_cycle = 0; | 208 context->int_cycle = 0; |
206 } | 209 } |
207 } | 210 } |
211 if (context->int_end_cycle != 0xFFFFFFFFU) { | |
212 if (context->int_end_cycle > deduction) { | |
213 context->int_end_cycle -= deduction; | |
214 } else { | |
215 context->int_end_cycle = 0; | |
216 } | |
217 } | |
208 if (context->nmi_cycle != 0xFFFFFFFFU) { | 218 if (context->nmi_cycle != 0xFFFFFFFFU) { |
209 if (context->nmi_cycle > deduction) { | 219 if (context->nmi_cycle > deduction) { |
210 context->nmi_cycle -= deduction; | 220 context->nmi_cycle -= deduction; |
211 } else { | 221 } else { |
212 context->nmi_cycle = 0; | 222 context->nmi_cycle = 0; |