cpuintrf.h
1 #ifndef CPUINTRF_H 2 #define CPUINTRF_H 3 4 5 /* The old system is obsolete and no longer supported by the core */ 6 #define NEW_INTERRUPT_SYSTEM 1 7 8 #define MAX_IRQ_LINES 8 /* maximum number of IRQ lines per CPU */ 9 10 #define CLEAR_LINE 0 /* clear (a fired, held or pulsed) line */ 11 #define ASSERT_LINE 1 /* assert an interrupt immediately */ 12 #define HOLD_LINE 2 /* hold interrupt line until enable is true */ 13 #define PULSE_LINE 3 /* pulse interrupt line for one instruction */ 14 15 #define MAX_REGS 64 /* maximum number of register of any CPU */ 16 17 /* Values passed to the cpu_info function of a core to retrieve information */ 18 enum { 19 CPU_INFO_REG, 20 CPU_INFO_FLAGS=MAX_REGS, 21 CPU_INFO_NAME, 22 CPU_INFO_FAMILY, 23 CPU_INFO_VERSION, 24 CPU_INFO_FILE, 25 CPU_INFO_CREDITS, 26 CPU_INFO_REG_LAYOUT, 27 CPU_INFO_WIN_LAYOUT 28 }; 29 30 #define CPU_IS_LE 0 /* emulated CPU is little endian */ 31 #define CPU_IS_BE 1 /* emulated CPU is big endian */ 32 33 /* 34 * This value is passed to cpu_get_reg to retrieve the previous 35 * program counter value, ie. before a CPU emulation started 36 * to fetch opcodes and arguments for the current instrution. 37 */ 38 #define REG_PREVIOUSPC -1 39 40 /* 41 * This value is passed to cpu_get_reg/cpu_set_reg, instead of one of 42 * the names from the enum a CPU core defines for it's registers, 43 * to get or set the contents of the memory pointed to by a stack pointer. 44 * You can specify the n'th element on the stack by (REG_SP_CONTENTS-n), 45 * ie. lower negative values. The actual element size (UINT16 or UINT32) 46 * depends on the CPU core. 47 * This is also used to replace the cpu_geturnpc() function. 48 */ 49 #define REG_SP_CONTENTS -2 50 51 52 /* ASG 971222 -- added this generic structure */ 53 struct cpu_interface 54 { 55 unsigned cpu_num; 56 void (*reset)(void *param); 57 void (*exit)(void); 58 int (*execute)(int cycles); 59 void (*burn)(int cycles); 60 unsigned (*get_context)(void *reg); 61 void (*set_context)(void *reg); 62 unsigned (*get_pc)(void); 63 void (*set_pc)(unsigned val); 64 unsigned (*get_sp)(void); 65 void (*set_sp)(unsigned val); 66 unsigned (*get_reg)(int regnum); 67 void (*set_reg)(int regnum, unsigned val); 68 void (*set_nmi_line)(int linestate); 69 void (*set_irq_line)(int irqline, int linestate); 70 void (*set_irq_callback)(int(*callback)(int irqline)); 71 void (*internal_interrupt)(int type); 72 void (*cpu_state_save)(void *file); 73 void (*cpu_state_load)(void *file); 74 const char* (*cpu_info)(void *context,int regnum); 75 unsigned (*cpu_dasm)(char *buffer,unsigned pc); 76 unsigned num_irqs; 77 int default_vector; 78 int *icount; 79 double overclock; 80 int no_int, irq_int, nmi_int; 81 int (*memory_read)(int offset); 82 void (*memory_write)(int offset, int data); 83 void (*set_op_base)(int pc); 84 int address_shift; 85 unsigned address_bits, endianess, align_unit, max_inst_len; 86 unsigned abits1, abits2, abitsmin; 87 }; 88 89 extern struct cpu_interface cpuintf[]; 90 91 void cpu_init(void); 92 void cpu_run(void); 93 94 /* optional watchdog */ 95 void watchdog_reset_w(int offset,int data); 96 int watchdog_reset_r(int offset); 97 /* Use this function to reset the machine */ 98 void machine_reset(void); 99 /* Use this function to reset a single CPU */ 100 void cpu_set_reset_line(int cpu,int state); 101 /* Use this function to halt a single CPU */ 102 void cpu_set_halt_line(int cpu,int state); 103 104 /* This function returns CPUNUM current status (running or halted) */ 105 int cpu_getstatus(int cpunum); 106 int cpu_gettotalcpu(void); 107 int cpu_getactivecpu(void); 108 void cpu_setactivecpu(int cpunum); 109 110 /* Returns the current program counter */ 111 unsigned cpu_get_pc(void); 112 /* Set the current program counter */ 113 void cpu_set_pc(unsigned val); 114 115 /* Returns the current stack pointer */ 116 unsigned cpu_get_sp(void); 117 /* Set the current stack pointer */ 118 void cpu_set_sp(unsigned val); 119 120 /* Get the active CPUs context and return it's size */ 121 unsigned cpu_get_context(void *context); 122 /* Set the active CPUs context */ 123 void cpu_set_context(void *context); 124 125 /* Returns a specific register value (mamedbg) */ 126 unsigned cpu_get_reg(int regnum); 127 /* Sets a specific register value (mamedbg) */ 128 void cpu_set_reg(int regnum, unsigned val); 129 130 /* Returns previous pc (start of opcode causing read/write) */ 131 /* int cpu_getpreviouspc(void); */ 132 #define cpu_getpreviouspc() cpu_get_reg(REG_PREVIOUSPC) 133 134 /* Returns the return address from the top of the stack (Z80 only) */ 135 /* int cpu_getreturnpc(void); */ 136 /* This can now be handled with a generic function */ 137 #define cpu_geturnpc() cpu_get_reg(REG_SP_CONTENTS) 138 139 int cycles_currently_ran(void); 140 int cycles_left_to_run(void); 141 142 /* Returns the number of CPU cycles which take place in one video frame */ 143 int cpu_gettotalcycles(void); 144 /* Returns the number of CPU cycles before the next interrupt handler call */ 145 int cpu_geticount(void); 146 /* Returns the number of CPU cycles before the end of the current video frame */ 147 int cpu_getfcount(void); 148 /* Returns the number of CPU cycles in one video frame */ 149 int cpu_getfperiod(void); 150 /* Scales a given value by the ratio of fcount / fperiod */ 151 int cpu_scalebyfcount(int value); 152 /* Returns the current scanline number */ 153 int cpu_getscanline(void); 154 /* Returns the amount of time until a given scanline */ 155 double cpu_getscanlinetime(int scanline); 156 /* Returns the duration of a single scanline */ 157 double cpu_getscanlineperiod(void); 158 /* Returns the duration of a single scanline in cycles */ 159 int cpu_getscanlinecycles(void); 160 /* Returns the number of cycles since the beginning of this frame */ 161 int cpu_getcurrentcycles(void); 162 /* Returns the current horizontal beam position in pixels */ 163 int cpu_gethorzbeampos(void); 164 /* 165 Returns the number of times the interrupt handler will be called before 166 the end of the current video frame. This is can be useful to interrupt 167 handlers to synchronize their operation. If you call this from outside 168 an interrupt handler, add 1 to the result, i.e. if it returns 0, it means 169 that the interrupt handler will be called once. 170 */ 171 int cpu_getiloops(void); 172 173 /* Returns the current VBLANK state */ 174 int cpu_getvblank(void); 175 176 /* Returns the number of the video frame we are currently playing */ 177 int cpu_getcurrentframe(void); 178 179 180 /* generate a trigger after a specific period of time */ 181 void cpu_triggertime (double duration, int trigger); 182 /* generate a trigger now */ 183 void cpu_trigger (int trigger); 184 185 /* burn CPU cycles until a timer trigger */ 186 void cpu_spinuntil_trigger (int trigger); 187 /* burn CPU cycles until the next interrupt */ 188 void cpu_spinuntil_int (void); 189 /* burn CPU cycles until our timeslice is up */ 190 void cpu_spin (void); 191 /* burn CPU cycles for a specific period of time */ 192 void cpu_spinuntil_time (double duration); 193 194 /* yield our timeslice for a specific period of time */ 195 void cpu_yielduntil_trigger (int trigger); 196 /* yield our timeslice until the next interrupt */ 197 void cpu_yielduntil_int (void); 198 /* yield our current timeslice */ 199 void cpu_yield (void); 200 /* yield our timeslice for a specific period of time */ 201 void cpu_yielduntil_time (double duration); 202 203 /* set the NMI line state for a CPU, normally use PULSE_LINE */ 204 void cpu_set_nmi_line(int cpunum, int state); 205 /* set the IRQ line state for a specific irq line of a CPU */ 206 /* normally use state HOLD_LINE, irqline 0 for first IRQ type of a cpu */ 207 void cpu_set_irq_line(int cpunum, int irqline, int state); 208 /* this is to be called by CPU cores only! */ 209 void cpu_generate_internal_interrupt(int cpunum, int type); 210 /* set the vector to be returned during a CPU's interrupt acknowledge cycle */ 211 void cpu_irq_line_vector_w(int cpunum, int irqline, int vector); 212 213 /* use these in your write memory/port handles to set an IRQ vector */ 214 /* offset corresponds to the irq line number here */ 215 void cpu_0_irq_line_vector_w(int offset, int data); 216 void cpu_1_irq_line_vector_w(int offset, int data); 217 void cpu_2_irq_line_vector_w(int offset, int data); 218 void cpu_3_irq_line_vector_w(int offset, int data); 219 void cpu_4_irq_line_vector_w(int offset, int data); 220 void cpu_5_irq_line_vector_w(int offset, int data); 221 void cpu_6_irq_line_vector_w(int offset, int data); 222 void cpu_7_irq_line_vector_w(int offset, int data); 223 224 /* Obsolete functions: avoid to use them in new drivers if possible. */ 225 226 /* cause an interrupt on a CPU */ 227 void cpu_cause_interrupt(int cpu,int type); 228 void cpu_clear_pending_interrupts(int cpu); 229 void interrupt_enable_w(int offset,int data); 230 void interrupt_vector_w(int offset,int data); 231 int interrupt(void); 232 int nmi_interrupt(void); 233 int m68_level1_irq(void); 234 int m68_level2_irq(void); 235 int m68_level3_irq(void); 236 int m68_level4_irq(void); 237 int m68_level5_irq(void); 238 int m68_level6_irq(void); 239 int m68_level7_irq(void); 240 int ignore_interrupt(void); 241 242 /* CPU context access */ 243 void* cpu_getcontext (int _activecpu); 244 int cpu_is_saving_context(int _activecpu); 245 246 /*************************************************************************** 247 * Get information for the currently active CPU 248 * cputype is a value from the CPU enum in driver.h 249 ***************************************************************************/ 250 /* Return number of address bits */ 251 unsigned cpu_address_bits(void); 252 /* Return address mask */ 253 unsigned cpu_address_mask(void); 254 /* Return address shift factor (TMS34010 bit addressing mode) */ 255 int cpu_address_shift(void); 256 /* Return endianess of the emulated CPU (CPU_IS_LE or CPU_IS_BE) */ 257 unsigned cpu_endianess(void); 258 /* Return opcode align unit (1 byte, 2 word, 4 dword) */ 259 unsigned cpu_align_unit(void); 260 /* Return maximum instruction length */ 261 unsigned cpu_max_inst_len(void); 262 263 /* Return name of the active CPU */ 264 const char *cpu_name(void); 265 /* Return family name of the active CPU */ 266 const char *cpu_core_family(void); 267 /* Return core version of the active CPU */ 268 const char *cpu_core_version(void); 269 /* Return core filename of the active CPU */ 270 const char *cpu_core_file(void); 271 /* Return credits info for of the active CPU */ 272 const char *cpu_core_credits(void); 273 /* Return register layout definition for the active CPU */ 274 const char *cpu_reg_layout(void); 275 /* Return (debugger) window layout definition for the active CPU */ 276 const char *cpu_win_layout(void); 277 278 /* Disassemble an instruction at PC into the given buffer */ 279 unsigned cpu_dasm(char *buffer, unsigned pc); 280 /* Return a string describing the currently set flag (status) bits of the active CPU */ 281 const char *cpu_flags(void); 282 /* Return a string with a register name and hex value for the active CPU */ 283 /* regnum is a value defined in the CPU cores header files */ 284 const char *cpu_dump_reg(int regnum); 285 /* Return a string describing the active CPUs current state */ 286 const char *cpu_dump_state(void); 287 288 /*************************************************************************** 289 * Get information for a specific CPU type 290 * cputype is a value from the CPU enum in driver.h 291 ***************************************************************************/ 292 /* Return address shift factor */ 293 /* TMS320C10 -1: word addressing mode, TMS34010 3: bit addressing mode */ 294 int cputype_address_shift(int cputype); 295 /* Return number of address bits */ 296 unsigned cputype_address_bits(int cputype); 297 /* Return address mask */ 298 unsigned cputype_address_mask(int cputype); 299 /* Return endianess of the emulated CPU (CPU_IS_LE or CPU_IS_BE) */ 300 unsigned cputype_endianess(int cputype); 301 /* Return opcode align unit (1 byte, 2 word, 4 dword) */ 302 unsigned cputype_align_unit(int cputype); 303 /* Return maximum instruction length */ 304 unsigned cputype_max_inst_len(int cputype); 305 306 /* Return name of the CPU */ 307 const char *cputype_name(int cputype); 308 /* Return family name of the CPU */ 309 const char *cputype_core_family(int cputype); 310 /* Return core version number of the CPU */ 311 const char *cputype_core_version(int cputype); 312 /* Return core filename of the CPU */ 313 const char *cputype_core_file(int cputype); 314 /* Return credits for the CPU core */ 315 const char *cputype_core_credits(int cputype); 316 /* Return register layout definition for the CPU core */ 317 const char *cputype_reg_layout(int cputype); 318 /* Return (debugger) window layout definition for the CPU core */ 319 const char *cputype_win_layout(int cputype); 320 321 /*************************************************************************** 322 * Get (or set) information for a numbered CPU of the running machine 323 * cpunum is a value between 0 and cpu_gettotalcpu() - 1 324 ***************************************************************************/ 325 /* Return number of address bits */ 326 unsigned cpunum_address_bits(int cputype); 327 /* Return address mask */ 328 unsigned cpunum_address_mask(int cputype); 329 /* Return endianess of the emulated CPU (CPU_LSB_FIRST or CPU_MSB_FIRST) */ 330 unsigned cpunum_endianess(int cputype); 331 /* Return opcode align unit (1 byte, 2 word, 4 dword) */ 332 unsigned cpunum_align_unit(int cputype); 333 /* Return maximum instruction length */ 334 unsigned cpunum_max_inst_len(int cputype); 335 336 /* Get a register value for the specified CPU number of the running machine */ 337 unsigned cpunum_get_reg(int cpunum, int regnum); 338 /* Set a register value for the specified CPU number of the running machine */ 339 void cpunum_set_reg(int cpunum, int regnum, unsigned val); 340 341 /* Return (debugger) register layout definition for the CPU core */ 342 const char *cpunum_reg_layout(int cpunum); 343 /* Return (debugger) window layout definition for the CPU core */ 344 const char *cpunum_win_layout(int cpunum); 345 346 unsigned cpunum_dasm(int cpunum,char *buffer,unsigned pc); 347 /* Return a string describing the currently set flag (status) bits of the CPU */ 348 const char *cpunum_flags(int cpunum); 349 /* Return a string with a register name and value */ 350 /* regnum is a value defined in the CPU cores header files */ 351 const char *cpunum_dump_reg(int cpunum, int regnum); 352 /* Return a string describing the CPUs current state */ 353 const char *cpunum_dump_state(int cpunum); 354 /* Return a name for the specified cpu number */ 355 const char *cpunum_name(int cpunum); 356 /* Return a family name for the specified cpu number */ 357 const char *cpunum_core_family(int cpunum); 358 /* Return a version for the specified cpu number */ 359 const char *cpunum_core_version(int cpunum); 360 /* Return a the source filename for the specified cpu number */ 361 const char *cpunum_core_file(int cpunum); 362 /* Return a the credits for the specified cpu number */ 363 const char *cpunum_core_credits(int cpunum); 364 365 /* Dump all of the running machines CPUs state to stderr */ 366 void cpu_dump_states(void); 367 368 /* daisy-chain link */ 369 typedef struct { 370 void (*reset)(int); /* reset callback */ 371 int (*interrupt_entry)(int); /* entry callback */ 372 void (*interrupt_reti)(int); /* reti callback */ 373 int irq_param; /* callback paramater */ 374 } Z80_DaisyChain; 375 376 #define Z80_MAXDAISY 4 /* maximum of daisy chan device */ 377 378 #define Z80_INT_REQ 0x01 /* interrupt request mask */ 379 #define Z80_INT_IEO 0x02 /* interrupt disable mask(IEO) */ 380 381 #define Z80_VECTOR(device,state) (((device)<<8)|(state)) 382 383 #endif /* CPUINTRF_H */