main z80_to_x86.h
  1/*
  2 Copyright 2013 Michael Pavone
  3 This file is part of BlastEm.
  4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
  5*/
  6#ifndef Z80_TO_X86_H_
  7#define Z80_TO_X86_H_
  8#include "z80inst.h"
  9#include "backend.h"
 10#include "serialize.h"
 11
 12#define ZNUM_MEM_AREAS 4
 13#ifdef Z80_LOG_ADDRESS
 14#define ZMAX_NATIVE_SIZE 255
 15#else
 16#define ZMAX_NATIVE_SIZE 160
 17#endif
 18
 19enum {
 20	ZF_C = 0,
 21	ZF_N,
 22	ZF_PV,
 23	ZF_H,
 24	ZF_Z,
 25	ZF_S,
 26	ZF_XY,
 27	ZF_NUM
 28};
 29
 30typedef struct z80_context z80_context;
 31typedef void (*z80_ctx_fun)(z80_context * context);
 32
 33typedef struct {
 34	cpu_options     gen;
 35	code_ptr        save_context_scratch;
 36	code_ptr        load_context_scratch;
 37	code_ptr        native_addr;
 38	code_ptr        retrans_stub;
 39	code_ptr        do_sync;
 40	code_ptr        read_8;
 41	code_ptr        write_8;
 42	code_ptr        read_8_noinc;
 43	code_ptr        write_8_noinc;
 44	code_ptr        read_16;
 45	code_ptr        write_16_highfirst;
 46	code_ptr        write_16_lowfirst;
 47	code_ptr		read_io;
 48	code_ptr		write_io;
 49
 50	uint32_t        flags;
 51	int8_t          regs[Z80_UNUSED];
 52	z80_ctx_fun     run;
 53} z80_options;
 54
 55struct z80_context {
 56	void *            native_pc;
 57	uint16_t          sp;
 58	uint8_t           flags[ZF_NUM];
 59	uint16_t          bank_reg;
 60	uint8_t           regs[Z80_A+1];
 61	uint8_t           im;
 62	uint8_t           alt_regs[Z80_A+1];
 63	uint32_t          target_cycle;
 64	uint32_t          current_cycle;
 65	uint8_t           alt_flags[ZF_NUM];
 66	uint8_t *         mem_pointers[ZNUM_MEM_AREAS];
 67	uint8_t           iff1;
 68	uint8_t           iff2;
 69	uint16_t          scratch1;
 70	uint16_t          scratch2;
 71	void *            extra_pc;
 72	uint32_t          sync_cycle;
 73	uint32_t          int_cycle;
 74	z80_options *     options;
 75	void *            system;
 76	uint32_t          int_enable_cycle;
 77	uint16_t          pc;
 78	uint32_t          int_pulse_start;
 79	uint32_t          int_pulse_end;
 80	uint32_t          nmi_start;
 81	uint8_t           breakpoint_flags[(16 * 1024)/sizeof(uint8_t)];
 82	uint8_t *         bp_handler;
 83	uint8_t *         bp_stub;
 84	uint8_t *         interp_code[256];
 85	z80_ctx_fun       next_int_pulse;
 86	uint8_t           reset;
 87	uint8_t           busreq;
 88	uint8_t           busack;
 89	uint8_t           int_is_nmi;
 90	uint8_t           im2_vector;
 91	uint8_t           ram_code_flags[];
 92};
 93
 94void translate_z80_stream(z80_context * context, uint32_t address);
 95void 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);
 96void z80_options_free(z80_options *opts);
 97z80_context * init_z80_context(z80_options * options);
 98code_ptr z80_get_native_address(z80_context * context, uint32_t address);
 99code_ptr z80_get_native_address_trans(z80_context * context, uint32_t address);
100z80_context * z80_handle_code_write(uint32_t address, z80_context * context);
101void z80_invalidate_code_range(z80_context *context, uint32_t start, uint32_t end);
102void z80_reset(z80_context * context);
103void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler);
104void zremove_breakpoint(z80_context * context, uint16_t address);
105void z80_run(z80_context * context, uint32_t target_cycle);
106void z80_assert_reset(z80_context * context, uint32_t cycle);
107void z80_clear_reset(z80_context * context, uint32_t cycle);
108void z80_assert_busreq(z80_context * context, uint32_t cycle);
109void z80_clear_busreq(z80_context * context, uint32_t cycle);
110void z80_assert_nmi(z80_context *context, uint32_t cycle);
111uint8_t z80_get_busack(z80_context * context, uint32_t cycle);
112void z80_adjust_cycles(z80_context * context, uint32_t deduction);
113void z80_serialize(z80_context *context, serialize_buffer *buf);
114void z80_deserialize(deserialize_buffer *buf, void *vcontext);
115
116#endif //Z80_TO_X86_H_
117