summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--backend.c67
-rw-r--r--backend.h2
-rwxr-xr-xcpu_dsl.py8
-rw-r--r--ztestrun.c36
5 files changed, 116 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 8a5b397..1bc741d 100644
--- a/Makefile
+++ b/Makefile
@@ -159,7 +159,12 @@ TRANSOBJS+= gen_x86.o backend_x86.o
endif
endif
+ifdef NEW_CORE
+Z80OBJS=z80.o
+CFLAGS+= -DNEW_CORE
+else
Z80OBJS=z80inst.o z80_to_x86.o
+endif
AUDIOOBJS=ym2612.o psg.o wave.o
CONFIGOBJS=config.o tern.o util.o paths.o
NUKLEAROBJS=$(FONT) nuklear_ui/blastem_nuklear.o nuklear_ui/sfnt.o controller_info.o
@@ -295,6 +300,9 @@ offsets : offsets.c z80_to_x86.h m68k_core.h
vos_prog_info : vos_prog_info.o vos_program_module.o
$(CC) -o vos_prog_info vos_prog_info.o vos_program_module.o
+
+%.c : %.cpu
+ ./cpu_dsl.py $< > $@
%.o : %.S
$(CC) -c -o $@ $<
diff --git a/backend.c b/backend.c
index 400b6d8..e8bea75 100644
--- a/backend.c
+++ b/backend.c
@@ -129,6 +129,73 @@ uint16_t read_word(uint32_t address, void **mem_pointers, cpu_options *opts, voi
return 0xFFFF;
}
+uint8_t read_byte(uint32_t address, void **mem_pointers, cpu_options *opts, void *context)
+{
+ memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL);
+ if (!chunk) {
+ return 0xFF;
+ }
+ uint32_t offset = address & chunk->mask;
+ if (chunk->flags & MMAP_READ) {
+ uint8_t *base;
+ if (chunk->flags & MMAP_PTR_IDX) {
+ base = mem_pointers[chunk->ptr_index];
+ } else {
+ base = chunk->buffer;
+ }
+ if (base) {
+ if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
+ if (address & 1) {
+ if (chunk->flags & MMAP_ONLY_EVEN) {
+ return 0xFF;
+ }
+ } else if (chunk->flags & MMAP_ONLY_ODD) {
+ return 0xFF;
+ }
+ offset /= 2;
+ }
+ return base[offset];
+ }
+ }
+ if ((!(chunk->flags & MMAP_READ) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->read_8) {
+ return chunk->read_8(offset, context);
+ }
+ return 0xFF;
+}
+
+void write_byte(uint32_t address, uint8_t value, void **mem_pointers, cpu_options *opts, void *context)
+{
+ memmap_chunk const *chunk = find_map_chunk(address, opts, 0, NULL);
+ if (!chunk) {
+ return;
+ }
+ uint32_t offset = address & chunk->mask;
+ if (chunk->flags & MMAP_WRITE) {
+ uint8_t *base;
+ if (chunk->flags & MMAP_PTR_IDX) {
+ base = mem_pointers[chunk->ptr_index];
+ } else {
+ base = chunk->buffer;
+ }
+ if (base) {
+ if ((chunk->flags & MMAP_ONLY_ODD) || (chunk->flags & MMAP_ONLY_EVEN)) {
+ if (address & 1) {
+ if (chunk->flags & MMAP_ONLY_EVEN) {
+ return;
+ }
+ } else if (chunk->flags & MMAP_ONLY_ODD) {
+ return;
+ }
+ offset /= 2;
+ }
+ base[offset] = value;
+ }
+ }
+ if ((!(chunk->flags & MMAP_WRITE) || (chunk->flags & MMAP_FUNC_NULL)) && chunk->write_8) {
+ chunk->write_8(offset, context, value);
+ }
+}
+
uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk)
{
if (chunk->mask == opts->address_mask) {
diff --git a/backend.h b/backend.h
index b227aca..5949c91 100644
--- a/backend.h
+++ b/backend.h
@@ -96,6 +96,8 @@ void patch_for_retranslate(cpu_options *opts, code_ptr native_address, code_ptr
code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t num_chunks, ftype fun_type, code_ptr *after_inc);
void * get_native_pointer(uint32_t address, void ** mem_pointers, cpu_options * opts);
uint16_t read_word(uint32_t address, void **mem_pointers, cpu_options *opts, void *context);
+uint8_t read_byte(uint32_t address, void **mem_pointers, cpu_options *opts, void *context);
+void write_byte(uint32_t address, uint8_t value, void **mem_pointers, cpu_options *opts, void *context);
memmap_chunk const *find_map_chunk(uint32_t address, cpu_options *opts, uint16_t flags, uint32_t *size_sum);
uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk);
uint32_t ram_size(cpu_options *opts);
diff --git a/cpu_dsl.py b/cpu_dsl.py
index 9c056d5..1f43203 100755
--- a/cpu_dsl.py
+++ b/cpu_dsl.py
@@ -324,14 +324,11 @@ def _updateFlagsCImpl(prog, params, rawParams):
output.append('\n\t{reg} = {res} ? ({reg} & {mask}U) : ({reg} | {bit}U);'.format(
reg = reg, mask = ~(1 << storageBit), res = lastDst, bit = 1 << storageBit
))
- elif prog.paramSize(prog.lastDst) > prog.paramSize(storage):
+ else:
reg = prog.resolveParam(storage, None, {})
- output.append('\n\t{reg} = {res} != 0;'.format(
+ output.append('\n\t{reg} = {res} == 0;'.format(
reg = reg, res = lastDst
))
- else:
- reg = prog.resolveParam(storage, None, {})
- output.append('\n\t{reg} = {res};'.format(reg = reg, res = lastDst))
elif calc == 'half-carry':
pass
elif calc == 'carry':
@@ -978,6 +975,7 @@ class Program:
self.regs.writeHeader(otype, hFile)
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))
hFile.write('\n#endif //{0}_'.format(macro))
hFile.write('\n')
hFile.close()
diff --git a/ztestrun.c b/ztestrun.c
index e64226a..4a59534 100644
--- a/ztestrun.c
+++ b/ztestrun.c
@@ -4,7 +4,12 @@
BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
*/
#include "z80inst.h"
+#ifdef NEW_CORE
+#include "z80.h"
+#include <string.h>
+#else
#include "z80_to_x86.h"
+#endif
#include "mem.h"
#include "vdp.h"
#include <stdio.h>
@@ -42,10 +47,12 @@ const memmap_chunk port_map[] = {
{ 0x0000, 0x100, 0xFF, 0, 0, 0, NULL, NULL, NULL, z80_unmapped_read, z80_unmapped_write}
};
+#ifndef NEW_CORE
void z80_next_int_pulse(z80_context * context)
{
context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
}
+#endif
int main(int argc, char ** argv)
{
@@ -89,6 +96,34 @@ int main(int argc, char ** argv)
exit(1);
}
fclose(f);
+#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],
+ context->main[2], context->main[3],
+ (context->main[4] << 8) | context->main[5],
+ context->ix,
+ context->iy,
+ context->sp, context->imode, context->iff1, context->iff2);
+ printf("Flags: SZYHXVNC\n"
+ " %d%d%d%d%d%d%d%d\n",
+ context->last_flag_result >> 7, context->zflag != 0, context->last_flag_result >> 5 & 1, context->chflags >> 3 & 1,
+ context->last_flag_result >> 3 & 1, context->pvflag != 0, context->nflag, context->chflags >> 7 & 1
+ );
+ puts("--Alternate Regs--");
+ printf("A: %X\nB: %X\nC: %X\nD: %X\nE: %X\nHL: %X\n",
+ context->alt[7], context->alt[0], context->alt[1],
+ 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
@@ -122,5 +157,6 @@ int main(int argc, char ** argv)
context->alt_regs[Z80_A], context->alt_regs[Z80_B], context->alt_regs[Z80_C],
context->alt_regs[Z80_D], context->alt_regs[Z80_E],
(context->alt_regs[Z80_H] << 8) | context->alt_regs[Z80_L]);
+#endif
return 0;
}