initial import
[picodrive.git] / cpu / musashi / m68k.h
diff --git a/cpu/musashi/m68k.h b/cpu/musashi/m68k.h
new file mode 100644 (file)
index 0000000..6de1fab
--- /dev/null
@@ -0,0 +1,371 @@
+#ifndef M68K__HEADER\r
+#define M68K__HEADER\r
+\r
+/* ======================================================================== */\r
+/* ========================= LICENSING & COPYRIGHT ======================== */\r
+/* ======================================================================== */\r
+/*\r
+ *                                  MUSASHI\r
+ *                                Version 3.3\r
+ *\r
+ * A portable Motorola M680x0 processor emulation engine.\r
+ * Copyright 1998-2001 Karl Stenerud.  All rights reserved.\r
+ *\r
+ * This code may be freely used for non-commercial purposes as long as this\r
+ * copyright notice remains unaltered in the source code and any binary files\r
+ * containing this code in compiled form.\r
+ *\r
+ * All other lisencing terms must be negotiated with the author\r
+ * (Karl Stenerud).\r
+ *\r
+ * The latest version of this code can be obtained at:\r
+ * http://kstenerud.cjb.net\r
+ */\r
+\r
+/* ======================================================================== */\r
+/* ============================= CONFIGURATION ============================ */\r
+/* ======================================================================== */\r
+\r
+/* Import the configuration for this build */\r
+#include "m68kconf.h"\r
+\r
+\r
+/* ======================================================================== */\r
+/* ============================ GENERAL DEFINES =========================== */\r
+\r
+/* ======================================================================== */\r
+\r
+/* There are 7 levels of interrupt to the 68K.\r
+ * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).\r
+ */\r
+#define M68K_IRQ_NONE 0\r
+#define M68K_IRQ_1    1\r
+#define M68K_IRQ_2    2\r
+#define M68K_IRQ_3    3\r
+#define M68K_IRQ_4    4\r
+#define M68K_IRQ_5    5\r
+#define M68K_IRQ_6    6\r
+#define M68K_IRQ_7    7\r
+\r
+\r
+/* Special interrupt acknowledge values.\r
+ * Use these as special returns from the interrupt acknowledge callback\r
+ * (specified later in this header).\r
+ */\r
+\r
+/* Causes an interrupt autovector (0x18 + interrupt level) to be taken.\r
+ * This happens in a real 68K if VPA or AVEC is asserted during an interrupt\r
+ * acknowledge cycle instead of DTACK.\r
+ */\r
+#define M68K_INT_ACK_AUTOVECTOR    0xffffffff\r
+\r
+/* Causes the spurious interrupt vector (0x18) to be taken\r
+ * This happens in a real 68K if BERR is asserted during the interrupt\r
+ * acknowledge cycle (i.e. no devices responded to the acknowledge).\r
+ */\r
+#define M68K_INT_ACK_SPURIOUS      0xfffffffe\r
+\r
+\r
+/* CPU types for use in m68k_set_cpu_type() */\r
+enum\r
+{\r
+       M68K_CPU_TYPE_INVALID,\r
+       M68K_CPU_TYPE_68000,\r
+       M68K_CPU_TYPE_68008,\r
+       M68K_CPU_TYPE_68010,\r
+       M68K_CPU_TYPE_68EC020,\r
+       M68K_CPU_TYPE_68020,\r
+       M68K_CPU_TYPE_68030,    /* Supported by disassembler ONLY */\r
+       M68K_CPU_TYPE_68040             /* Supported by disassembler ONLY */\r
+};\r
+\r
+/* Registers used by m68k_get_reg() and m68k_set_reg() */\r
+typedef enum\r
+{\r
+       /* Real registers */\r
+       M68K_REG_D0,            /* Data registers */\r
+       M68K_REG_D1,\r
+       M68K_REG_D2,\r
+       M68K_REG_D3,\r
+       M68K_REG_D4,\r
+       M68K_REG_D5,\r
+       M68K_REG_D6,\r
+       M68K_REG_D7,\r
+       M68K_REG_A0,            /* Address registers */\r
+       M68K_REG_A1,\r
+       M68K_REG_A2,\r
+       M68K_REG_A3,\r
+       M68K_REG_A4,\r
+       M68K_REG_A5,\r
+       M68K_REG_A6,\r
+       M68K_REG_A7,\r
+       M68K_REG_PC,            /* Program Counter */\r
+       M68K_REG_SR,            /* Status Register */\r
+       M68K_REG_SP,            /* The current Stack Pointer (located in A7) */\r
+       M68K_REG_USP,           /* User Stack Pointer */\r
+       M68K_REG_ISP,           /* Interrupt Stack Pointer */\r
+       M68K_REG_MSP,           /* Master Stack Pointer */\r
+       M68K_REG_SFC,           /* Source Function Code */\r
+       M68K_REG_DFC,           /* Destination Function Code */\r
+       M68K_REG_VBR,           /* Vector Base Register */\r
+       M68K_REG_CACR,          /* Cache Control Register */\r
+       M68K_REG_CAAR,          /* Cache Address Register */\r
+\r
+       /* Assumed registers */\r
+       /* These are cheat registers which emulate the 1-longword prefetch\r
+     * present in the 68000 and 68010.\r
+     */\r
+       M68K_REG_PREF_ADDR,     /* Last prefetch address */\r
+       M68K_REG_PREF_DATA,     /* Last prefetch data */\r
+\r
+       /* Convenience registers */\r
+       M68K_REG_PPC,           /* Previous value in the program counter */\r
+       M68K_REG_IR,            /* Instruction register */\r
+       M68K_REG_CPU_TYPE       /* Type of CPU being run */\r
+} m68k_register_t;\r
+\r
+/* ======================================================================== */\r
+/* ====================== FUNCTIONS CALLED BY THE CPU ===================== */\r
+/* ======================================================================== */\r
+\r
+/* You will have to implement these functions */\r
+\r
+/* read/write functions called by the CPU to access memory.\r
+ * while values used are 32 bits, only the appropriate number\r
+ * of bits are relevant (i.e. in write_memory_8, only the lower 8 bits\r
+ * of value should be written to memory).\r
+ *\r
+ * NOTE: I have separated the immediate and PC-relative memory fetches\r
+ *       from the other memory fetches because some systems require\r
+ *       differentiation between PROGRAM and DATA fetches (usually\r
+ *       for security setups such as encryption).\r
+ *       This separation can either be achieved by setting\r
+ *       M68K_SEPARATE_READS in m68kconf.h and defining\r
+ *       the read functions, or by setting M68K_EMULATE_FC and\r
+ *       making a function code callback function.\r
+ *       Using the callback offers better emulation coverage\r
+ *       because you can also monitor whether the CPU is in SYSTEM or\r
+ *       USER mode, but it is also slower.\r
+ */\r
+\r
+/* Read from anywhere */\r
+unsigned int  m68k_read_memory_8(unsigned int address);\r
+unsigned int  m68k_read_memory_16(unsigned int address);\r
+unsigned int  m68k_read_memory_32(unsigned int address);\r
+\r
+/* Read data immediately following the PC */\r
+unsigned int  m68k_read_immediate_16(unsigned int address);\r
+unsigned int  m68k_read_immediate_32(unsigned int address);\r
+\r
+/* Read data relative to the PC */\r
+unsigned int  m68k_read_pcrelative_8(unsigned int address);\r
+unsigned int  m68k_read_pcrelative_16(unsigned int address);\r
+unsigned int  m68k_read_pcrelative_32(unsigned int address);\r
+\r
+/* Memory access for the disassembler */\r
+unsigned int m68k_read_disassembler_8  (unsigned int address);\r
+unsigned int m68k_read_disassembler_16 (unsigned int address);\r
+unsigned int m68k_read_disassembler_32 (unsigned int address);\r
+\r
+/* Write to anywhere */\r
+void m68k_write_memory_8(unsigned int address, unsigned int value);\r
+void m68k_write_memory_16(unsigned int address, unsigned int value);\r
+void m68k_write_memory_32(unsigned int address, unsigned int value);\r
+\r
+/* Special call to simulate undocumented 68k behavior when move.l with a\r
+ * predecrement destination mode is executed.\r
+ * To simulate real 68k behavior, first write the high word to\r
+ * [address+2], and then write the low word to [address].\r
+ *\r
+ * Enable this functionality with M68K_SIMULATE_PD_WRITES in m68kconf.h.\r
+ */\r
+void m68k_write_memory_32_pd(unsigned int address, unsigned int value);\r
+\r
+\r
+\r
+/* ======================================================================== */\r
+/* ============================== CALLBACKS =============================== */\r
+/* ======================================================================== */\r
+\r
+/* These functions allow you to set callbacks to the host when specific events\r
+ * occur.  Note that you must enable the corresponding value in m68kconf.h\r
+ * in order for these to do anything useful.\r
+ * Note: I have defined default callbacks which are used if you have enabled\r
+ * the corresponding #define in m68kconf.h but either haven't assigned a\r
+ * callback or have assigned a callback of NULL.\r
+ */\r
+\r
+/* Set the callback for an interrupt acknowledge.\r
+ * You must enable M68K_EMULATE_INT_ACK in m68kconf.h.\r
+ * The CPU will call the callback with the interrupt level being acknowledged.\r
+ * The host program must return either a vector from 0x02-0xff, or one of the\r
+ * special interrupt acknowledge values specified earlier in this header.\r
+ * If this is not implemented, the CPU will always assume an autovectored\r
+ * interrupt, and will automatically clear the interrupt request when it\r
+ * services the interrupt.\r
+ * Default behavior: return M68K_INT_ACK_AUTOVECTOR.\r
+ */\r
+void m68k_set_int_ack_callback(int  (*callback)(int int_level));\r
+\r
+\r
+/* Set the callback for a breakpoint acknowledge (68010+).\r
+ * You must enable M68K_EMULATE_BKPT_ACK in m68kconf.h.\r
+ * The CPU will call the callback with whatever was in the data field of the\r
+ * BKPT instruction for 68020+, or 0 for 68010.\r
+ * Default behavior: do nothing.\r
+ */\r
+void m68k_set_bkpt_ack_callback(void (*callback)(unsigned int data));\r
+\r
+\r
+/* Set the callback for the RESET instruction.\r
+ * You must enable M68K_EMULATE_RESET in m68kconf.h.\r
+ * The CPU calls this callback every time it encounters a RESET instruction.\r
+ * Default behavior: do nothing.\r
+ */\r
+void m68k_set_reset_instr_callback(void  (*callback)(void));\r
+\r
+\r
+/* Set the callback for the CMPI.L #v, Dn instruction.\r
+ * You must enable M68K_CMPILD_HAS_CALLBACK in m68kconf.h.\r
+ * The CPU calls this callback every time it encounters a CMPI.L #v, Dn instruction.\r
+ * Default behavior: do nothing.\r
+ */\r
+void m68k_set_cmpild_instr_callback(void  (*callback)(unsigned int val, int reg));\r
+\r
+\r
+/* Set the callback for the RTE instruction.\r
+ * You must enable M68K_RTE_HAS_CALLBACK in m68kconf.h.\r
+ * The CPU calls this callback every time it encounters a RTE instruction.\r
+ * Default behavior: do nothing.\r
+ */\r
+void m68k_set_rte_instr_callback(void  (*callback)(void));\r
+\r
+\r
+/* Set the callback for informing of a large PC change.\r
+ * You must enable M68K_MONITOR_PC in m68kconf.h.\r
+ * The CPU calls this callback with the new PC value every time the PC changes\r
+ * by a large value (currently set for changes by longwords).\r
+ * Default behavior: do nothing.\r
+ */\r
+void m68k_set_pc_changed_callback(void  (*callback)(unsigned int new_pc));\r
+\r
+\r
+/* Set the callback for CPU function code changes.\r
+ * You must enable M68K_EMULATE_FC in m68kconf.h.\r
+ * The CPU calls this callback with the function code before every memory\r
+ * access to set the CPU's function code according to what kind of memory\r
+ * access it is (supervisor/user, program/data and such).\r
+ * Default behavior: do nothing.\r
+ */\r
+void m68k_set_fc_callback(void  (*callback)(unsigned int new_fc));\r
+\r
+\r
+/* Set a callback for the instruction cycle of the CPU.\r
+ * You must enable M68K_INSTRUCTION_HOOK in m68kconf.h.\r
+ * The CPU calls this callback just before fetching the opcode in the\r
+ * instruction cycle.\r
+ * Default behavior: do nothing.\r
+ */\r
+void m68k_set_instr_hook_callback(void  (*callback)(void));\r
+\r
+\r
+\r
+/* ======================================================================== */\r
+/* ====================== FUNCTIONS TO ACCESS THE CPU ===================== */\r
+/* ======================================================================== */\r
+\r
+/* Use this function to set the CPU type you want to emulate.\r
+ * Currently supported types are: M68K_CPU_TYPE_68000, M68K_CPU_TYPE_68008,\r
+ * M68K_CPU_TYPE_68010, M68K_CPU_TYPE_EC020, and M68K_CPU_TYPE_68020.\r
+ */\r
+void m68k_set_cpu_type(unsigned int cpu_type);\r
+\r
+/* Do whatever initialisations the core requires.  Should be called\r
+ * at least once at init time.\r
+ */\r
+void m68k_init(void);\r
+\r
+/* Pulse the RESET pin on the CPU.\r
+ * You *MUST* reset the CPU at least once to initialize the emulation\r
+ * Note: If you didn't call m68k_set_cpu_type() before resetting\r
+ *       the CPU for the first time, the CPU will be set to\r
+ *       M68K_CPU_TYPE_68000.\r
+ */\r
+void m68k_pulse_reset(void);\r
+\r
+/* execute num_cycles worth of instructions.  returns number of cycles used */\r
+int m68k_execute(int num_cycles);\r
+\r
+/* These functions let you read/write/modify the number of cycles left to run\r
+ * while m68k_execute() is running.\r
+ * These are useful if the 68k accesses a memory-mapped port on another device\r
+ * that requires immediate processing by another CPU.\r
+ */\r
+int m68k_cycles_run(void);              /* Number of cycles run so far */\r
+int m68k_cycles_remaining(void);        /* Number of cycles left */\r
+void m68k_modify_timeslice(int cycles); /* Modify cycles left */\r
+void m68k_end_timeslice(void);          /* End timeslice now */\r
+\r
+/* Set the IPL0-IPL2 pins on the CPU (IRQ).\r
+ * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).\r
+ * Setting IRQ to 0 will clear an interrupt request.\r
+ */\r
+void m68k_set_irq(unsigned int int_level);\r
+\r
+\r
+/* Halt the CPU as if you pulsed the HALT pin. */\r
+void m68k_pulse_halt(void);\r
+\r
+\r
+/* Context switching to allow multiple CPUs */\r
+\r
+/* Get the size of the cpu context in bytes */\r
+unsigned int m68k_context_size(void);\r
+\r
+/* Get a cpu context */\r
+unsigned int m68k_get_context(void* dst);\r
+\r
+/* set the current cpu context */\r
+void m68k_set_context(void* dst);\r
+\r
+/* Register the CPU state information */\r
+void m68k_state_register(const char *type, int index);\r
+\r
+\r
+/* Peek at the internals of a CPU context.  This can either be a context\r
+ * retrieved using m68k_get_context() or the currently running context.\r
+ * If context is NULL, the currently running CPU context will be used.\r
+ */\r
+unsigned int m68k_get_reg(void* context, m68k_register_t reg);\r
+\r
+/* Poke values into the internals of the currently running CPU context */\r
+void m68k_set_reg(m68k_register_t reg, unsigned int value);\r
+\r
+/* Check if an instruction is valid for the specified CPU type */\r
+unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type);\r
+\r
+/* Disassemble 1 instruction using the epecified CPU type at pc.  Stores\r
+ * disassembly in str_buff and returns the size of the instruction in bytes.\r
+ */\r
+unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type);\r
+\r
+/* Same as above but accepts raw opcode data directly rather than fetching\r
+ * via the read/write interfaces.\r
+ */\r
+unsigned int m68k_disassemble_raw(char* str_buff, unsigned int pc, unsigned char* opdata, unsigned char* argdata, int length, unsigned int cpu_type);\r
+\r
+\r
+/* ======================================================================== */\r
+/* ============================== MAME STUFF ============================== */\r
+/* ======================================================================== */\r
+\r
+#if M68K_COMPILE_FOR_MAME == OPT_ON\r
+#include "m68kmame.h"\r
+#endif /* M68K_COMPILE_FOR_MAME */\r
+\r
+\r
+/* ======================================================================== */\r
+/* ============================== END OF FILE ============================= */\r
+/* ======================================================================== */\r
+\r
+#endif /* M68K__HEADER */\r