From a39a82cc9773c8336eaa48379f2d2fe3615f178c Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Tue, 17 Jun 2014 01:50:29 -0400 Subject: blastem builds and almost works on OS X now --- z80_to_x86.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index ab2c846..48cc942 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -62,9 +62,9 @@ void translate_z80_stream(z80_context * context, uint32_t address); void init_x86_z80_opts(x86_z80_options * options); void init_z80_context(z80_context * context, x86_z80_options * options); uint8_t * z80_get_native_address(z80_context * context, uint32_t address); -uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address); -z80_context * z80_handle_code_write(uint32_t address, z80_context * context); -void z80_run(z80_context * context); +extern uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address) asm("z80_get_native_address_trans"); +z80_context * z80_handle_code_write(uint32_t address, z80_context * context) asm("z80_handle_code_write"); +extern void z80_run(z80_context * context) asm("z80_run"); void z80_reset(z80_context * context); void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler); void zremove_breakpoint(z80_context * context, uint16_t address); -- cgit v1.2.3 From a14794522213f99ddef00aa049785ff806d4b1dd Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Thu, 19 Jun 2014 19:50:16 -0700 Subject: Properly handle Z80 breakpoints on self-modifying code and setting Z80 breakpoints before the Z80 program has been loaded --- z80_to_x86.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index dd5864b..28f860f 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -1,6 +1,6 @@ /* Copyright 2013 Michael Pavone - This file is part of BlastEm. + This file is part of BlastEm. BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. */ #ifndef Z80_TO_X86_H_ @@ -55,6 +55,9 @@ typedef struct { void * system; uint8_t ram_code_flags[(8 * 1024)/128/8]; uint32_t int_enable_cycle; + uint8_t breakpoint_flags[(16 * 1024)/sizeof(uint8_t)]; + uint8_t * bp_handler; + uint8_t * bp_stub; uint16_t pc; } z80_context; -- cgit v1.2.3 From 4c06b02583a69756a7cdf6561c0760087eb642ec Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Fri, 20 Jun 2014 07:57:32 -0700 Subject: Added some preliminary support for interpreting Z80 code from non-RAM addresses --- z80_to_x86.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index 28f860f..fc30179 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -55,10 +55,12 @@ typedef struct { void * system; uint8_t ram_code_flags[(8 * 1024)/128/8]; uint32_t int_enable_cycle; + uint16_t pc; uint8_t breakpoint_flags[(16 * 1024)/sizeof(uint8_t)]; uint8_t * bp_handler; uint8_t * bp_stub; - uint16_t pc; + uint8_t * interp_code[256]; + } z80_context; void translate_z80_stream(z80_context * context, uint32_t address); -- cgit v1.2.3 From 24d56647b3b2baa4e7016ac5d66c0167d51688be Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 21 Jun 2014 09:36:15 -0700 Subject: Fix Z80 interrupts --- z80_to_x86.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index fc30179..fdf7866 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -56,6 +56,8 @@ typedef struct { uint8_t ram_code_flags[(8 * 1024)/128/8]; uint32_t int_enable_cycle; uint16_t pc; + uint32_t int_pulse_start; + uint32_t int_pulse_end; uint8_t breakpoint_flags[(16 * 1024)/sizeof(uint8_t)]; uint8_t * bp_handler; uint8_t * bp_stub; -- cgit v1.2.3 From d07b907bc7889308890b590d2aaf88dfc44ae616 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 14 Dec 2014 16:45:23 -0800 Subject: WIP effort to update z80 core for code gen changes --- z80_to_x86.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index ab2c846..b33311e 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -22,13 +22,14 @@ enum { }; typedef struct { - uint8_t * cur_code; - uint8_t * code_end; - uint8_t *ram_inst_sizes; - deferred_addr * deferred; + cpu_options gen; + code_ptr save_context_scratch; + code_ptr load_context_scratch; + code_ptr write_8_noinc; + uint32_t flags; int8_t regs[Z80_UNUSED]; -} x86_z80_options; +} z80_options; typedef struct { void * native_pc; @@ -51,7 +52,7 @@ typedef struct { uint32_t int_cycle; native_map_slot * static_code_map; native_map_slot * banked_code_map; - void * options; + z80_options * options; void * system; uint8_t ram_code_flags[(8 * 1024)/128/8]; uint32_t int_enable_cycle; @@ -59,8 +60,8 @@ typedef struct { } z80_context; void translate_z80_stream(z80_context * context, uint32_t address); -void init_x86_z80_opts(x86_z80_options * options); -void init_z80_context(z80_context * context, x86_z80_options * options); +void init_x86_z80_opts(z80_options * options, memmap_chunk * chunks, uint32_t num_chunks); +void init_z80_context(z80_context * context, z80_options * options); uint8_t * z80_get_native_address(z80_context * context, uint32_t address); uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address); z80_context * z80_handle_code_write(uint32_t address, z80_context * context); -- cgit v1.2.3 From 9dc3feb135af0a8853798bd79cff754cd86dbd0f Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Wed, 17 Dec 2014 09:53:51 -0800 Subject: Get Z80 core back into compileable state --- z80_to_x86.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index b33311e..fa9db33 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -25,10 +25,17 @@ typedef struct { cpu_options gen; code_ptr save_context_scratch; code_ptr load_context_scratch; + code_ptr read_8; + code_ptr write_8; code_ptr write_8_noinc; + code_ptr read_16; + code_ptr write_16_highfirst; + code_ptr write_16_lowfirst; uint32_t flags; int8_t regs[Z80_UNUSED]; + int8_t bank_reg; + int8_t bank_pointer; } z80_options; typedef struct { @@ -62,8 +69,8 @@ typedef struct { void translate_z80_stream(z80_context * context, uint32_t address); void init_x86_z80_opts(z80_options * options, memmap_chunk * chunks, uint32_t num_chunks); void init_z80_context(z80_context * context, z80_options * options); -uint8_t * z80_get_native_address(z80_context * context, uint32_t address); -uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address); +code_ptr z80_get_native_address(z80_context * context, uint32_t address); +code_ptr z80_get_native_address_trans(z80_context * context, uint32_t address); z80_context * z80_handle_code_write(uint32_t address, z80_context * context); void z80_run(z80_context * context); void z80_reset(z80_context * context); -- cgit v1.2.3 From 4cad512b6d7ac0f7042b90e1029626fb14788bf0 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Wed, 17 Dec 2014 23:03:19 -0800 Subject: Get rest of emulator compiling again with Z80 core enabled --- z80_to_x86.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index fa9db33..d5d232c 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -67,7 +67,7 @@ typedef struct { } z80_context; void translate_z80_stream(z80_context * context, uint32_t address); -void init_x86_z80_opts(z80_options * options, memmap_chunk * chunks, uint32_t num_chunks); +void init_x86_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks); void init_z80_context(z80_context * context, z80_options * options); code_ptr z80_get_native_address(z80_context * context, uint32_t address); code_ptr z80_get_native_address_trans(z80_context * context, uint32_t address); @@ -76,6 +76,7 @@ void z80_run(z80_context * context); void z80_reset(z80_context * context); void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler); void zremove_breakpoint(z80_context * context, uint16_t address); +void * z80_gen_bank_write(uint32_t start_address, void * voptions); #endif //Z80_TO_X86_H_ -- cgit v1.2.3 From 12c73dc400c1b6b61531df4ff0fd1efe4ef7ae12 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Mon, 22 Dec 2014 20:55:10 -0800 Subject: Z80 core is sort of working again --- z80_to_x86.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index d5d232c..6870343 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -21,21 +21,29 @@ enum { ZF_NUM }; +typedef void (*z80_run_fun)(void * context); + typedef struct { cpu_options gen; code_ptr save_context_scratch; code_ptr load_context_scratch; - code_ptr read_8; - code_ptr write_8; + code_ptr native_addr; + code_ptr retrans_stub; + code_ptr do_sync; + code_ptr read_8; + code_ptr write_8; code_ptr write_8_noinc; - code_ptr read_16; - code_ptr write_16_highfirst; - code_ptr write_16_lowfirst; + code_ptr read_16; + code_ptr write_16_highfirst; + code_ptr write_16_lowfirst; + code_ptr read_io; + code_ptr write_io; uint32_t flags; int8_t regs[Z80_UNUSED]; - int8_t bank_reg; - int8_t bank_pointer; + int8_t bank_reg; + int8_t bank_pointer; + z80_run_fun run; } z80_options; typedef struct { @@ -63,6 +71,7 @@ typedef struct { void * system; uint8_t ram_code_flags[(8 * 1024)/128/8]; uint32_t int_enable_cycle; + z80_run_fun run; uint16_t pc; } z80_context; -- cgit v1.2.3 From 55471707f6478f63fc07b2d260f6755ca259b6a2 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Fri, 26 Dec 2014 12:34:41 -0800 Subject: Add in missing generated Z80 helper functions. Fix a small bug in Z80_HALT. Fix generation of save and load context for Z80 --- z80_to_x86.h | 1 + 1 file changed, 1 insertion(+) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index 6870343..507965d 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -32,6 +32,7 @@ typedef struct { code_ptr do_sync; code_ptr read_8; code_ptr write_8; + code_ptr read_8_noinc; code_ptr write_8_noinc; code_ptr read_16; code_ptr write_16_highfirst; -- cgit v1.2.3 From d41ae43228509a1a67446492b844013cf1e68c36 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Thu, 1 Jan 2015 20:26:22 -0800 Subject: Minor Z80 core cleanup --- z80_to_x86.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index 71d6f10..0c035c6 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -84,7 +84,7 @@ typedef struct { } z80_context; void translate_z80_stream(z80_context * context, uint32_t address); -void init_x86_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks); +void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks); void init_z80_context(z80_context * context, z80_options * options); code_ptr z80_get_native_address(z80_context * context, uint32_t address); code_ptr z80_get_native_address_trans(z80_context * context, uint32_t address); -- cgit v1.2.3 From 758586c1b7feec3c4fa3761ed17d1a6ea3cbab00 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Thu, 1 Jan 2015 22:18:32 -0800 Subject: Add the 3 cycle delay back in to Z80 bank area access --- z80_to_x86.h | 1 - 1 file changed, 1 deletion(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index 0c035c6..9b29852 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -93,7 +93,6 @@ void z80_run(z80_context * context); void z80_reset(z80_context * context); void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler); void zremove_breakpoint(z80_context * context, uint16_t address); -void * z80_gen_bank_write(uint32_t start_address, void * voptions); #endif //Z80_TO_X86_H_ -- cgit v1.2.3 From 32c7399651b886128f9cbd7d185684f84d392a1a Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Thu, 1 Jan 2015 23:37:24 -0800 Subject: Remove dedicated registers for Z80 bank reg and Z80 bank pointer as they are no longer used --- z80_to_x86.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index 9b29852..d3e7b89 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -42,8 +42,6 @@ typedef struct { uint32_t flags; int8_t regs[Z80_UNUSED]; - int8_t bank_reg; - int8_t bank_pointer; z80_run_fun run; } z80_options; -- cgit v1.2.3 From 8ac1e753e1af481b2090a4c1b7395853f30b5e8f Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 3 Jan 2015 16:08:23 -0800 Subject: All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working --- z80_to_x86.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index d3e7b89..792d7b5 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -1,6 +1,6 @@ /* Copyright 2013 Michael Pavone - This file is part of BlastEm. + This file is part of BlastEm. BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. */ #ifndef Z80_TO_X86_H_ @@ -82,7 +82,7 @@ typedef struct { } z80_context; void translate_z80_stream(z80_context * context, uint32_t address); -void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks); +void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, uint32_t clock_divider); void init_z80_context(z80_context * context, z80_options * options); code_ptr z80_get_native_address(z80_context * context, uint32_t address); code_ptr z80_get_native_address_trans(z80_context * context, uint32_t address); -- cgit v1.2.3 From e6216d5d0a9f8cdb700124558d38cd47e63fbdda Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 3 Jan 2015 18:23:04 -0800 Subject: Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c --- z80_to_x86.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index 792d7b5..7a77636 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -70,15 +70,16 @@ typedef struct { void * system; uint8_t ram_code_flags[(8 * 1024)/128/8]; uint32_t int_enable_cycle; - z80_run_fun run; - uint16_t pc; + uint16_t pc; uint32_t int_pulse_start; uint32_t int_pulse_end; uint8_t breakpoint_flags[(16 * 1024)/sizeof(uint8_t)]; uint8_t * bp_handler; uint8_t * bp_stub; uint8_t * interp_code[256]; - + uint8_t reset; + uint8_t busreq; + uint8_t busack; } z80_context; void translate_z80_stream(z80_context * context, uint32_t address); @@ -87,10 +88,18 @@ void init_z80_context(z80_context * context, z80_options * options); code_ptr z80_get_native_address(z80_context * context, uint32_t address); code_ptr z80_get_native_address_trans(z80_context * context, uint32_t address); z80_context * z80_handle_code_write(uint32_t address, z80_context * context); -void z80_run(z80_context * context); void z80_reset(z80_context * context); void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler); void zremove_breakpoint(z80_context * context, uint16_t address); +void z80_run(z80_context * context, uint32_t target_cycle); +void z80_assert_reset(z80_context * context, uint32_t cycle); +void z80_clear_reset(z80_context * context, uint32_t cycle); +void z80_assert_busreq(z80_context * context, uint32_t cycle); +void z80_clear_busreq(z80_context * context, uint32_t cycle); +uint8_t z80_get_busack(z80_context * context, uint32_t cycle); +void z80_adjust_cycles(z80_context * context, uint32_t deduction); +//to be provided by system code +void z80_next_int_pulse(z80_context * z_context); #endif //Z80_TO_X86_H_ -- cgit v1.2.3 From a75fc6b803164c251b62a941a4544f71a2e86892 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Mon, 25 May 2015 18:56:22 -0700 Subject: Add a define in both the source and Makefile for enabling logging of z80 instruction address/cycle counts. Fix Z80 in/out instructions to eliminate assumptions about which registers are stored in native regs. Fix read_16 to not corrupt the low byte when the read has to call into a C function. --- z80_to_x86.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'z80_to_x86.h') diff --git a/z80_to_x86.h b/z80_to_x86.h index fefa836..a940bb7 100644 --- a/z80_to_x86.h +++ b/z80_to_x86.h @@ -9,7 +9,11 @@ #include "backend.h" #define ZNUM_MEM_AREAS 4 +#ifdef Z80_LOG_ADDRESS +#define ZMAX_NATIVE_SIZE 255 +#else #define ZMAX_NATIVE_SIZE 128 +#endif enum { ZF_C = 0, -- cgit v1.2.3