m68k.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #ifndef M68K__HEADER
  2. #define M68K__HEADER
  3. /* ======================================================================== */
  4. /* ========================= LICENSING & COPYRIGHT ======================== */
  5. /* ======================================================================== */
  6. /*
  7. * MUSASHI
  8. * Version 3.31
  9. *
  10. * A portable Motorola M680x0 processor emulation engine.
  11. * Copyright 1998-2007 Karl Stenerud. All rights reserved.
  12. *
  13. * This code may be freely used for non-commercial purposes as long as this
  14. * copyright notice remains unaltered in the source code and any binary files
  15. * containing this code in compiled form.
  16. *
  17. * All other lisencing terms must be negotiated with the author
  18. * (Karl Stenerud).
  19. *
  20. * The latest version of this code can be obtained at:
  21. * http://kstenerud.cjb.net
  22. */
  23. /* ======================================================================== */
  24. /* ============================= CONFIGURATION ============================ */
  25. /* ======================================================================== */
  26. /* Import the configuration for this build */
  27. #include "m68kconf.h"
  28. /* ======================================================================== */
  29. /* ============================ GENERAL DEFINES =========================== */
  30. /* ======================================================================== */
  31. /* There are 7 levels of interrupt to the 68K.
  32. * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
  33. */
  34. #define M68K_IRQ_NONE 0
  35. #define M68K_IRQ_1 1
  36. #define M68K_IRQ_2 2
  37. #define M68K_IRQ_3 3
  38. #define M68K_IRQ_4 4
  39. #define M68K_IRQ_5 5
  40. #define M68K_IRQ_6 6
  41. #define M68K_IRQ_7 7
  42. /* Special interrupt acknowledge values.
  43. * Use these as special returns from the interrupt acknowledge callback
  44. * (specified later in this header).
  45. */
  46. /* Causes an interrupt autovector (0x18 + interrupt level) to be taken.
  47. * This happens in a real 68K if VPA or AVEC is asserted during an interrupt
  48. * acknowledge cycle instead of DTACK.
  49. */
  50. #define M68K_INT_ACK_AUTOVECTOR 0xffffffff
  51. /* Causes the spurious interrupt vector (0x18) to be taken
  52. * This happens in a real 68K if BERR is asserted during the interrupt
  53. * acknowledge cycle (i.e. no devices responded to the acknowledge).
  54. */
  55. #define M68K_INT_ACK_SPURIOUS 0xfffffffe
  56. /* CPU types for use in m68k_set_cpu_type() */
  57. enum
  58. {
  59. M68K_CPU_TYPE_INVALID,
  60. M68K_CPU_TYPE_68000,
  61. M68K_CPU_TYPE_68008,
  62. M68K_CPU_TYPE_68010,
  63. M68K_CPU_TYPE_68EC020,
  64. M68K_CPU_TYPE_68020,
  65. M68K_CPU_TYPE_68030, /* Supported by disassembler ONLY */
  66. M68K_CPU_TYPE_68040 /* Supported by disassembler ONLY */
  67. };
  68. /* Registers used by m68k_get_reg() and m68k_set_reg() */
  69. typedef enum
  70. {
  71. /* Real registers */
  72. M68K_REG_D0, /* Data registers */
  73. M68K_REG_D1,
  74. M68K_REG_D2,
  75. M68K_REG_D3,
  76. M68K_REG_D4,
  77. M68K_REG_D5,
  78. M68K_REG_D6,
  79. M68K_REG_D7,
  80. M68K_REG_A0, /* Address registers */
  81. M68K_REG_A1,
  82. M68K_REG_A2,
  83. M68K_REG_A3,
  84. M68K_REG_A4,
  85. M68K_REG_A5,
  86. M68K_REG_A6,
  87. M68K_REG_A7,
  88. M68K_REG_PC, /* Program Counter */
  89. M68K_REG_SR, /* Status Register */
  90. M68K_REG_SP, /* The current Stack Pointer (located in A7) */
  91. M68K_REG_USP, /* User Stack Pointer */
  92. M68K_REG_ISP, /* Interrupt Stack Pointer */
  93. M68K_REG_MSP, /* Master Stack Pointer */
  94. M68K_REG_SFC, /* Source Function Code */
  95. M68K_REG_DFC, /* Destination Function Code */
  96. M68K_REG_VBR, /* Vector Base Register */
  97. M68K_REG_CACR, /* Cache Control Register */
  98. M68K_REG_CAAR, /* Cache Address Register */
  99. /* Assumed registers */
  100. /* These are cheat registers which emulate the 1-longword prefetch
  101. * present in the 68000 and 68010.
  102. */
  103. M68K_REG_PREF_ADDR, /* Last prefetch address */
  104. M68K_REG_PREF_DATA, /* Last prefetch data */
  105. /* Convenience registers */
  106. M68K_REG_PPC, /* Previous value in the program counter */
  107. M68K_REG_IR, /* Instruction register */
  108. M68K_REG_CPU_TYPE /* Type of CPU being run */
  109. } m68k_register_t;
  110. /* ======================================================================== */
  111. /* ====================== FUNCTIONS CALLED BY THE CPU ===================== */
  112. /* ======================================================================== */
  113. /* You will have to implement these functions */
  114. /* read/write functions called by the CPU to access memory.
  115. * while values used are 32 bits, only the appropriate number
  116. * of bits are relevant (i.e. in write_memory_8, only the lower 8 bits
  117. * of value should be written to memory).
  118. *
  119. * NOTE: I have separated the immediate and PC-relative memory fetches
  120. * from the other memory fetches because some systems require
  121. * differentiation between PROGRAM and DATA fetches (usually
  122. * for security setups such as encryption).
  123. * This separation can either be achieved by setting
  124. * M68K_SEPARATE_READS in m68kconf.h and defining
  125. * the read functions, or by setting M68K_EMULATE_FC and
  126. * making a function code callback function.
  127. * Using the callback offers better emulation coverage
  128. * because you can also monitor whether the CPU is in SYSTEM or
  129. * USER mode, but it is also slower.
  130. */
  131. /* Read from anywhere */
  132. unsigned int m68k_read_memory_8(unsigned int address);
  133. unsigned int m68k_read_memory_16(unsigned int address);
  134. unsigned int m68k_read_memory_32(unsigned int address);
  135. /* Read data immediately following the PC */
  136. unsigned int m68k_read_immediate_16(unsigned int address);
  137. unsigned int m68k_read_immediate_32(unsigned int address);
  138. /* Read data relative to the PC */
  139. unsigned int m68k_read_pcrelative_8(unsigned int address);
  140. unsigned int m68k_read_pcrelative_16(unsigned int address);
  141. unsigned int m68k_read_pcrelative_32(unsigned int address);
  142. /* Memory access for the disassembler */
  143. unsigned int m68k_read_disassembler_8 (unsigned int address);
  144. unsigned int m68k_read_disassembler_16 (unsigned int address);
  145. unsigned int m68k_read_disassembler_32 (unsigned int address);
  146. /* Write to anywhere */
  147. void m68k_write_memory_8(unsigned int address, unsigned int value);
  148. void m68k_write_memory_16(unsigned int address, unsigned int value);
  149. void m68k_write_memory_32(unsigned int address, unsigned int value);
  150. /* Special call to simulate undocumented 68k behavior when move.l with a
  151. * predecrement destination mode is executed.
  152. * To simulate real 68k behavior, first write the high word to
  153. * [address+2], and then write the low word to [address].
  154. *
  155. * Enable this functionality with M68K_SIMULATE_PD_WRITES in m68kconf.h.
  156. */
  157. void m68k_write_memory_32_pd(unsigned int address, unsigned int value);
  158. /* ======================================================================== */
  159. /* ============================== CALLBACKS =============================== */
  160. /* ======================================================================== */
  161. /* These functions allow you to set callbacks to the host when specific events
  162. * occur. Note that you must enable the corresponding value in m68kconf.h
  163. * in order for these to do anything useful.
  164. * Note: I have defined default callbacks which are used if you have enabled
  165. * the corresponding #define in m68kconf.h but either haven't assigned a
  166. * callback or have assigned a callback of NULL.
  167. */
  168. /* Set the callback for an interrupt acknowledge.
  169. * You must enable M68K_EMULATE_INT_ACK in m68kconf.h.
  170. * The CPU will call the callback with the interrupt level being acknowledged.
  171. * The host program must return either a vector from 0x02-0xff, or one of the
  172. * special interrupt acknowledge values specified earlier in this header.
  173. * If this is not implemented, the CPU will always assume an autovectored
  174. * interrupt, and will automatically clear the interrupt request when it
  175. * services the interrupt.
  176. * Default behavior: return M68K_INT_ACK_AUTOVECTOR.
  177. */
  178. void m68k_set_int_ack_callback(int (*callback)(int int_level));
  179. /* Set the callback for a breakpoint acknowledge (68010+).
  180. * You must enable M68K_EMULATE_BKPT_ACK in m68kconf.h.
  181. * The CPU will call the callback with whatever was in the data field of the
  182. * BKPT instruction for 68020+, or 0 for 68010.
  183. * Default behavior: do nothing.
  184. */
  185. void m68k_set_bkpt_ack_callback(void (*callback)(unsigned int data));
  186. /* Set the callback for the RESET instruction.
  187. * You must enable M68K_EMULATE_RESET in m68kconf.h.
  188. * The CPU calls this callback every time it encounters a RESET instruction.
  189. * Default behavior: do nothing.
  190. */
  191. void m68k_set_reset_instr_callback(void (*callback)(void));
  192. /* Set the callback for the CMPI.L #v, Dn instruction.
  193. * You must enable M68K_CMPILD_HAS_CALLBACK in m68kconf.h.
  194. * The CPU calls this callback every time it encounters a CMPI.L #v, Dn instruction.
  195. * Default behavior: do nothing.
  196. */
  197. void m68k_set_cmpild_instr_callback(void (*callback)(unsigned int val, int reg));
  198. /* Set the callback for the RTE instruction.
  199. * You must enable M68K_RTE_HAS_CALLBACK in m68kconf.h.
  200. * The CPU calls this callback every time it encounters a RTE instruction.
  201. * Default behavior: do nothing.
  202. */
  203. void m68k_set_rte_instr_callback(void (*callback)(void));
  204. /* Set the callback for the TAS instruction.
  205. * You must enable M68K_TAS_HAS_CALLBACK in m68kconf.h.
  206. * The CPU calls this callback every time it encounters a TAS instruction.
  207. * Default behavior: return 1, allow writeback.
  208. */
  209. void m68k_set_tas_instr_callback(int (*callback)(void));
  210. /* Set the callback for informing of a large PC change.
  211. * You must enable M68K_MONITOR_PC in m68kconf.h.
  212. * The CPU calls this callback with the new PC value every time the PC changes
  213. * by a large value (currently set for changes by longwords).
  214. * Default behavior: do nothing.
  215. */
  216. void m68k_set_pc_changed_callback(void (*callback)(unsigned int new_pc));
  217. /* Set the callback for CPU function code changes.
  218. * You must enable M68K_EMULATE_FC in m68kconf.h.
  219. * The CPU calls this callback with the function code before every memory
  220. * access to set the CPU's function code according to what kind of memory
  221. * access it is (supervisor/user, program/data and such).
  222. * Default behavior: do nothing.
  223. */
  224. void m68k_set_fc_callback(void (*callback)(unsigned int new_fc));
  225. /* Set a callback for the instruction cycle of the CPU.
  226. * You must enable M68K_INSTRUCTION_HOOK in m68kconf.h.
  227. * The CPU calls this callback just before fetching the opcode in the
  228. * instruction cycle.
  229. * Default behavior: do nothing.
  230. */
  231. void m68k_set_instr_hook_callback(void (*callback)(void));
  232. /* ======================================================================== */
  233. /* ====================== FUNCTIONS TO ACCESS THE CPU ===================== */
  234. /* ======================================================================== */
  235. /* Use this function to set the CPU type you want to emulate.
  236. * Currently supported types are: M68K_CPU_TYPE_68000, M68K_CPU_TYPE_68008,
  237. * M68K_CPU_TYPE_68010, M68K_CPU_TYPE_EC020, and M68K_CPU_TYPE_68020.
  238. */
  239. void m68k_set_cpu_type(unsigned int cpu_type);
  240. /* Do whatever initialisations the core requires. Should be called
  241. * at least once at init time.
  242. */
  243. void m68k_init(void);
  244. /* Pulse the RESET pin on the CPU.
  245. * You *MUST* reset the CPU at least once to initialize the emulation
  246. * Note: If you didn't call m68k_set_cpu_type() before resetting
  247. * the CPU for the first time, the CPU will be set to
  248. * M68K_CPU_TYPE_68000.
  249. */
  250. void m68k_pulse_reset(void);
  251. /* execute num_cycles worth of instructions. returns number of cycles used */
  252. int m68k_execute(int num_cycles);
  253. /* These functions let you read/write/modify the number of cycles left to run
  254. * while m68k_execute() is running.
  255. * These are useful if the 68k accesses a memory-mapped port on another device
  256. * that requires immediate processing by another CPU.
  257. */
  258. int m68k_cycles_run(void); /* Number of cycles run so far */
  259. int m68k_cycles_remaining(void); /* Number of cycles left */
  260. void m68k_modify_timeslice(int cycles); /* Modify cycles left */
  261. void m68k_end_timeslice(void); /* End timeslice now */
  262. /* Set the IPL0-IPL2 pins on the CPU (IRQ).
  263. * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
  264. * Setting IRQ to 0 will clear an interrupt request.
  265. */
  266. void m68k_set_irq(unsigned int int_level);
  267. /* Halt the CPU as if you pulsed the HALT pin. */
  268. void m68k_pulse_halt(void);
  269. /* Context switching to allow multiple CPUs */
  270. /* Get the size of the cpu context in bytes */
  271. unsigned int m68k_context_size(void);
  272. /* Get a cpu context */
  273. unsigned int m68k_get_context(void* dst);
  274. /* set the current cpu context */
  275. void m68k_set_context(void* dst);
  276. /* Register the CPU state information */
  277. void m68k_state_register(const char *type, int index);
  278. /* Peek at the internals of a CPU context. This can either be a context
  279. * retrieved using m68k_get_context() or the currently running context.
  280. * If context is NULL, the currently running CPU context will be used.
  281. */
  282. unsigned int m68k_get_reg(void* context, m68k_register_t reg);
  283. /* Poke values into the internals of the currently running CPU context */
  284. void m68k_set_reg(m68k_register_t reg, unsigned int value);
  285. /* Check if an instruction is valid for the specified CPU type */
  286. unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type);
  287. /* Disassemble 1 instruction using the epecified CPU type at pc. Stores
  288. * disassembly in str_buff and returns the size of the instruction in bytes.
  289. */
  290. unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type);
  291. /* Same as above but accepts raw opcode data directly rather than fetching
  292. * via the read/write interfaces.
  293. */
  294. unsigned int m68k_disassemble_raw(char* str_buff, unsigned int pc, const unsigned char* opdata, const unsigned char* argdata, unsigned int cpu_type);
  295. /* ======================================================================== */
  296. /* ============================== MAME STUFF ============================== */
  297. /* ======================================================================== */
  298. #if M68K_COMPILE_FOR_MAME == OPT_ON
  299. #include "m68kmame.h"
  300. #endif /* M68K_COMPILE_FOR_MAME */
  301. /* ======================================================================== */
  302. /* ============================== END OF FILE ============================= */
  303. /* ======================================================================== */
  304. #endif /* M68K__HEADER */