fame.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*****************************************************************************/
  2. /* FAME Fast and Accurate Motorola 68000 Emulation Core */
  3. /* (c) 2005 Oscar Orallo Pelaez */
  4. /* Version: 1.24 */
  5. /* Date: 08-20-2005 */
  6. /* See FAME.HTML for documentation and license information */
  7. /*****************************************************************************/
  8. #ifndef __FAME_H__
  9. #define __FAME_H__
  10. // uintptr_t
  11. #include <stdlib.h>
  12. #ifndef _MSC_VER
  13. #include <stdint.h>
  14. #endif
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. // PicoDrive hacks
  19. #define FAMEC_FETCHBITS 8
  20. #define M68K_FETCHBANK1 (1 << FAMEC_FETCHBITS)
  21. //#define M68K_RUNNING 0x01
  22. #define FM68K_HALTED 0x80
  23. //#define M68K_WAITING 0x04
  24. //#define M68K_DISABLE 0x20
  25. //#define M68K_FAULTED 0x40
  26. #define FM68K_EMULATE_GROUP_0 0x02
  27. #define FM68K_EMULATE_TRACE 0x08
  28. #define FM68K_DO_TRACE 0x10
  29. /************************************/
  30. /* General library defines */
  31. /************************************/
  32. #ifndef M68K_OK
  33. #define M68K_OK 0
  34. #endif
  35. #ifndef M68K_RUNNING
  36. #define M68K_RUNNING 1
  37. #endif
  38. #ifndef M68K_NO_SUP_ADDR_SPACE
  39. #define M68K_NO_SUP_ADDR_SPACE 2
  40. #endif
  41. #ifndef M68K_DOUBLE_BUS_FAULT
  42. #define M68K_DOUBLE_BUS_FAULT -1
  43. #endif
  44. #ifndef M68K_INV_REG
  45. #define M68K_INV_REG -1
  46. #endif
  47. /* Hardware interrupt state */
  48. #ifndef M68K_IRQ_LEVEL_ERROR
  49. #define M68K_IRQ_LEVEL_ERROR -1
  50. #endif
  51. #ifndef M68K_IRQ_INV_PARAMS
  52. #define M68K_IRQ_INV_PARAMS -2
  53. #endif
  54. /* Defines to specify hardware interrupt type */
  55. #ifndef M68K_AUTOVECTORED_IRQ
  56. #define M68K_AUTOVECTORED_IRQ -1
  57. #endif
  58. #ifndef M68K_SPURIOUS_IRQ
  59. #define M68K_SPURIOUS_IRQ -2
  60. #endif
  61. #ifndef M68K_AUTO_LOWER_IRQ
  62. #define M68K_AUTO_LOWER_IRQ 1
  63. #endif
  64. #ifndef M68K_MANUAL_LOWER_IRQ
  65. #define M68K_MANUAL_LOWER_IRQ 0
  66. #endif
  67. /* Defines to specify address space */
  68. #ifndef M68K_SUP_ADDR_SPACE
  69. #define M68K_SUP_ADDR_SPACE 0
  70. #endif
  71. #ifndef M68K_USER_ADDR_SPACE
  72. #define M68K_USER_ADDR_SPACE 2
  73. #endif
  74. #ifndef M68K_PROG_ADDR_SPACE
  75. #define M68K_PROG_ADDR_SPACE 0
  76. #endif
  77. #ifndef M68K_DATA_ADDR_SPACE
  78. #define M68K_DATA_ADDR_SPACE 1
  79. #endif
  80. /*******************/
  81. /* Data definition */
  82. /*******************/
  83. #include <pico/pico_types.h>
  84. /*
  85. #ifdef u8
  86. #undef u8
  87. #endif
  88. #ifdef s8
  89. #undef s8
  90. #endif
  91. #ifdef u16
  92. #undef u16
  93. #endif
  94. #ifdef s16
  95. #undef s16
  96. #endif
  97. #ifdef u32
  98. #undef u32
  99. #endif
  100. #ifdef s32
  101. #undef s32
  102. #endif
  103. #ifdef uptr
  104. #undef uptr
  105. #endif
  106. #define u8 unsigned char
  107. #define s8 signed char
  108. #define u16 unsigned short
  109. #define s16 signed short
  110. #define u32 unsigned int
  111. #define s32 signed int
  112. #define uptr uintptr_t
  113. */
  114. /*
  115. typedef unsigned char u8;
  116. typedef signed char s8;
  117. typedef unsigned short u16;
  118. typedef signed short s16;
  119. typedef unsigned int u32;
  120. typedef signed int s32;
  121. */
  122. typedef union
  123. {
  124. u8 B;
  125. s8 SB;
  126. u16 W;
  127. s16 SW;
  128. u32 D;
  129. s32 SD;
  130. } famec_union32;
  131. /* M68K CPU CONTEXT */
  132. typedef struct
  133. {
  134. unsigned int (*read_byte )(unsigned int a);
  135. unsigned int (*read_word )(unsigned int a);
  136. unsigned int (*read_long )(unsigned int a);
  137. void (*write_byte)(unsigned int a,unsigned char d);
  138. void (*write_word)(unsigned int a,unsigned short d);
  139. void (*write_long)(unsigned int a,unsigned int d);
  140. void (*reset_handler)(void);
  141. void (*iack_handler)(unsigned level);
  142. famec_union32 dreg[8];
  143. famec_union32 areg[8];
  144. unsigned asp;
  145. unsigned pc;
  146. unsigned char interrupts[8];
  147. unsigned short sr;
  148. unsigned short execinfo;
  149. // PD extension
  150. int io_cycle_counter; // cycles left
  151. unsigned int Opcode;
  152. signed int cycles_needed;
  153. unsigned short *PC;
  154. uintptr_t BasePC;
  155. unsigned int flag_C;
  156. unsigned int flag_V;
  157. unsigned int flag_NotZ;
  158. unsigned int flag_N;
  159. unsigned int flag_X;
  160. unsigned int flag_T;
  161. unsigned int flag_S;
  162. unsigned int flag_I;
  163. unsigned char not_polling;
  164. unsigned char pad[3];
  165. uintptr_t Fetch[M68K_FETCHBANK1];
  166. } M68K_CONTEXT;
  167. typedef enum
  168. {
  169. fm68k_reason_emulate = 0,
  170. fm68k_reason_init,
  171. fm68k_reason_idle_install,
  172. fm68k_reason_idle_remove,
  173. } fm68k_call_reason;
  174. /************************/
  175. /* Function definition */
  176. /************************/
  177. /* General purpose functions */
  178. void fm68k_init(void);
  179. int fm68k_reset(M68K_CONTEXT *ctx);
  180. int fm68k_emulate(M68K_CONTEXT *ctx, int n, fm68k_call_reason reason);
  181. int fm68k_would_interrupt(M68K_CONTEXT *ctx); // to be called from fm68k_emulate()
  182. u32 fm68k_get_pc(const M68K_CONTEXT *ctx);
  183. // PICODRIVE_HACK
  184. int fm68k_idle_install(void);
  185. int fm68k_idle_remove(void);
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif