|
| 1 | + |
| 2 | +// Cyclone 68000 Emulator - Header File |
| 3 | + |
| 4 | +// Copyright (c) 2004,2011 FinalDave (emudave (at) gmail.com) |
| 5 | +// Copyright (c) 2005-2011 Gražvydas "notaz" Ignotas (notasas (at) gmail.com) |
| 6 | + |
| 7 | +// This code is licensed under the GNU General Public License version 2.0 and the MAME License. |
| 8 | +// You can choose the license that has the most advantages for you. |
| 9 | + |
| 10 | +// SVN repository can be found at http://code.google.com/p/cyclone68000/ |
| 11 | + |
| 12 | + |
| 13 | +#ifndef __CYCLONE_H__ |
| 14 | +#define __CYCLONE_H__ |
| 15 | + |
| 16 | +#ifdef __cplusplus |
| 17 | +extern "C" { |
| 18 | +#endif |
| 19 | + |
| 20 | +extern int CycloneVer; // Version number of library |
| 21 | + |
| 22 | +extern long CycloneJumpTab[65536]; // default jump table |
| 23 | + |
| 24 | +struct Cyclone |
| 25 | +{ |
| 26 | + unsigned int d[8]; // [r7,#0x00] |
| 27 | + unsigned int a[8]; // [r7,#0x20] |
| 28 | + unsigned int pc; // [r7,#0x40] Memory Base (.membase) + 68k PC |
| 29 | + unsigned char srh; // [r7,#0x44] Status Register high (T_S__III) |
| 30 | + unsigned char not_pol;// [r7,#0x45] not polling |
| 31 | + unsigned char flags; // [r7,#0x46] Flags (ARM order: ____NZCV) [68k order is XNZVC] |
| 32 | + unsigned char irq; // [r7,#0x47] IRQ level |
| 33 | + unsigned int osp; // [r7,#0x48] Other Stack Pointer (USP/SSP) |
| 34 | + unsigned int xc; // [r7,#0x4c] Extend flag (bit29: ??X? _) |
| 35 | + unsigned int prev_pc; // [r7,#0x50] Set to start address of currently executed opcode + 2 (if enabled in config.h) |
| 36 | + unsigned int jumptab; // [r7,#0x54] Jump table pointer |
| 37 | + int state_flags; // [r7,#0x58] bit: 0: stopped state, 1: trace state, 2: activity bit, 3: addr error, 4: fatal halt |
| 38 | + int cycles; // [r7,#0x5c] Number of cycles to execute - 1. Updates to cycles left after CycloneRun() |
| 39 | + int membase; // [r7,#0x60] Memory Base (ARM address minus 68000 address) |
| 40 | + unsigned int (*checkpc)(unsigned int pc); // [r7,#0x64] called to recalc Memory Base+pc |
| 41 | + unsigned int (*read8 )(unsigned int a); // [r7,#0x68] |
| 42 | + unsigned int (*read16 )(unsigned int a); // [r7,#0x6c] |
| 43 | + unsigned int (*read32 )(unsigned int a); // [r7,#0x70] |
| 44 | + void (*write8 )(unsigned int a,unsigned char d); // [r7,#0x74] |
| 45 | + void (*write16)(unsigned int a,unsigned short d); // [r7,#0x78] |
| 46 | + void (*write32)(unsigned int a,unsigned int d); // [r7,#0x7c] |
| 47 | + unsigned int (*fetch8 )(unsigned int a); // [r7,#0x80] |
| 48 | + unsigned int (*fetch16)(unsigned int a); // [r7,#0x84] |
| 49 | + unsigned int (*fetch32)(unsigned int a); // [r7,#0x88] |
| 50 | + int (*IrqCallback)(int int_level); // [r7,#0x8c] optional irq callback function, see config.h |
| 51 | + void (*ResetCallback)(void); // [r7,#0x90] if enabled in config.h, calls this whenever RESET opcode is encountered. |
| 52 | + int (*UnrecognizedCallback)(void); // [r7,#0x94] if enabled in config.h, calls this whenever unrecognized opcode is encountered. |
| 53 | + void *internal_CycloneEnd; // [r7,#0x98] internal, do not modify |
| 54 | + int internal_s_cycles; // [r7,#0x9c] internal, do not modify |
| 55 | + void *internal_s_CycloneEnd; // [r7,#0xa0] internal, do not modify |
| 56 | + unsigned int internal[3]; // [r7,#0xa4] reserved for internal use, do not change. |
| 57 | +}; |
| 58 | + |
| 59 | +// Initialize. Used only if Cyclone was compiled with compressed jumptable, see config.h |
| 60 | +#define CycloneInit() \ |
| 61 | + CycloneInitJT(CycloneJumpTab) |
| 62 | +void CycloneInitJT(void *jt); |
| 63 | + |
| 64 | +// Reset |
| 65 | +#define CycloneReset(pcy) \ |
| 66 | + CycloneResetJT(pcy, CycloneJumpTab) |
| 67 | +void CycloneResetJT(struct Cyclone *pcy, void *jt); |
| 68 | + |
| 69 | +// Run cyclone. Cycles should be specified in context (pcy->cycles) |
| 70 | +void CycloneRun(struct Cyclone *pcy); |
| 71 | + |
| 72 | +// Utility functions to get and set SR |
| 73 | +void CycloneSetSr(struct Cyclone *pcy, unsigned int sr); |
| 74 | +unsigned int CycloneGetSr(const struct Cyclone *pcy); |
| 75 | + |
| 76 | +// Generates irq exception if needed (if pcy->irq > mask). |
| 77 | +// Returns cycles used for exception if it was generated, 0 otherwise. |
| 78 | +int CycloneFlushIrq(struct Cyclone *pcy); |
| 79 | + |
| 80 | +// Functions for saving and restoring state. |
| 81 | +// CycloneUnpack() uses checkpc(), so it must be initialized. |
| 82 | +// save_buffer must point to buffer of 128 (0x80) bytes of size. |
| 83 | +void CyclonePack(const struct Cyclone *pcy, void *save_buffer); |
| 84 | +void CycloneUnpack(struct Cyclone *pcy, const void *save_buffer); |
| 85 | + |
| 86 | +// genesis: if 1, switch to normal TAS handlers |
| 87 | +#define CycloneSetRealTAS(use_real) \ |
| 88 | + CycloneSetRealTAS_JT(use_real, CycloneJumpTab) |
| 89 | +void CycloneSetRealTAS_JT(int use_real, void *jt); |
| 90 | + |
| 91 | + |
| 92 | +// These values are special return values for IrqCallback. |
| 93 | + |
| 94 | +// Causes an interrupt autovector (0x18 + interrupt level) to be taken. |
| 95 | +// This happens in a real 68K if VPA or AVEC is asserted during an interrupt |
| 96 | +// acknowledge cycle instead of DTACK (the most common situation). |
| 97 | +#define CYCLONE_INT_ACK_AUTOVECTOR -1 |
| 98 | + |
| 99 | +// Causes the spurious interrupt vector (0x18) to be taken |
| 100 | +// This happens in a real 68K if BERR is asserted during the interrupt |
| 101 | +// acknowledge cycle (i.e. no devices responded to the acknowledge). |
| 102 | +#define CYCLONE_INT_ACK_SPURIOUS -2 |
| 103 | + |
| 104 | + |
| 105 | +#ifdef __cplusplus |
| 106 | +} // End of extern "C" |
| 107 | +#endif |
| 108 | + |
| 109 | +#endif // __CYCLONE_H__ |
| 110 | + |
0 commit comments