| 1 | #ifndef _HuC6280H |
| 2 | |
| 3 | #define HUC6280_CRAZY_VERSION |
| 4 | //#define HUC6280_EXTRA_CRAZY |
| 5 | |
| 6 | #define HUC6280_LAZY_FLAGS |
| 7 | |
| 8 | typedef struct __HuC6280 |
| 9 | { |
| 10 | #ifdef HUC6280_CRAZY_VERSION |
| 11 | uint8 *PC, *PC_base; |
| 12 | #else |
| 13 | uint16 PC; |
| 14 | #endif |
| 15 | |
| 16 | uint8 A,X,Y,S,P,mooPI; |
| 17 | #ifdef HUC6280_LAZY_FLAGS |
| 18 | uint32 ZNFlags; |
| 19 | #endif |
| 20 | uint8 MPR[9]; // 8, + 1 for PC overflow from $ffff to $10000 |
| 21 | uint8 *FastPageR[9]; |
| 22 | uint8 *Page1; |
| 23 | //uint8 *PAGE1_W; |
| 24 | //const uint8 *PAGE1_R; |
| 25 | |
| 26 | uint32 IRQlow; /* Simulated IRQ pin held low(or is it high?). |
| 27 | And other junk hooked on for speed reasons.*/ |
| 28 | int32 timestamp; |
| 29 | |
| 30 | uint8 IRQMask, IRQMaskDelay; |
| 31 | uint8 timer_status; |
| 32 | int32 timer_value, timer_load; |
| 33 | int32 timer_next_timestamp; |
| 34 | |
| 35 | uint32 in_block_move; |
| 36 | uint16 bmt_src, bmt_dest, bmt_length; |
| 37 | uint32 bmt_alternate; |
| 38 | #define IBM_TIA 1 |
| 39 | #define IBM_TAI 2 |
| 40 | #define IBM_TDD 3 |
| 41 | #define IBM_TII 4 |
| 42 | #define IBM_TIN 5 |
| 43 | |
| 44 | int32 previous_next_user_event; |
| 45 | } HuC6280; |
| 46 | |
| 47 | void HuC6280_Run(int32 cycles); |
| 48 | void HuC6280_ResetTS(void); |
| 49 | |
| 50 | extern HuC6280 HuCPU; |
| 51 | extern uint8 *HuCPUFastMap[0x100]; |
| 52 | |
| 53 | #define N_FLAG 0x80 |
| 54 | #define V_FLAG 0x40 |
| 55 | #define T_FLAG 0x20 |
| 56 | #define B_FLAG 0x10 |
| 57 | #define D_FLAG 0x08 |
| 58 | #define I_FLAG 0x04 |
| 59 | #define Z_FLAG 0x02 |
| 60 | #define C_FLAG 0x01 |
| 61 | |
| 62 | #define NTSC_CPU 1789772.7272727272727272 |
| 63 | #define PAL_CPU 1662607.125 |
| 64 | |
| 65 | #define MDFN_IQIRQ1 0x002 |
| 66 | #define MDFN_IQIRQ2 0x001 |
| 67 | #define MDFN_IQTIMER 0x004 |
| 68 | #define MDFN_IQRESET 0x020 |
| 69 | |
| 70 | void HuC6280_Init(void) MDFN_COLD; |
| 71 | void HuC6280_Reset(void) MDFN_COLD; |
| 72 | void HuC6280_Power(void) MDFN_COLD; |
| 73 | |
| 74 | void HuC6280_IRQBegin(int w); |
| 75 | void HuC6280_IRQEnd(int w); |
| 76 | |
| 77 | int HuC6280_StateAction(StateMem *sm, int load, int data_only); |
| 78 | |
| 79 | static INLINE void HuC6280_StealCycle(void) |
| 80 | { |
| 81 | HuCPU.timestamp++; |
| 82 | } |
| 83 | |
| 84 | static INLINE uint8 HuC6280_TimerRead(unsigned int A) |
| 85 | { |
| 86 | #if 0 |
| 87 | return(HuCPU.timer_value | (PCEIODataBuffer & 0x80)); |
| 88 | #endif |
| 89 | |
| 90 | uint8 tvr = HuCPU.timer_value; |
| 91 | |
| 92 | if(HuCPU.timer_next_timestamp == HuCPU.timestamp) |
| 93 | tvr = (tvr - 1) & 0x7F; |
| 94 | |
| 95 | return(tvr | (PCEIODataBuffer & 0x80)); |
| 96 | } |
| 97 | |
| 98 | static INLINE void HuC6280_TimerWrite(unsigned int A, uint8 V) |
| 99 | { |
| 100 | switch(A & 1) |
| 101 | { |
| 102 | case 0: HuCPU.timer_load = (V & 0x7F); break; |
| 103 | case 1: if(V & 1) // Enable counter |
| 104 | { |
| 105 | if(HuCPU.timer_status == 0) |
| 106 | { |
| 107 | HuCPU.timer_next_timestamp = HuCPU.timestamp + 1024; |
| 108 | HuCPU.timer_value = HuCPU.timer_load; |
| 109 | } |
| 110 | } |
| 111 | HuCPU.timer_status = V & 1; |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | static INLINE uint8 HuC6280_IRQStatusRead(unsigned int A) |
| 117 | { |
| 118 | if(!(A & 2)) |
| 119 | return(PCEIODataBuffer); |
| 120 | |
| 121 | switch(A & 1) |
| 122 | { |
| 123 | case 0: |
| 124 | HuC6280_IRQEnd(MDFN_IQTIMER); |
| 125 | return(HuCPU.IRQMask ^ 0x7); |
| 126 | case 1: |
| 127 | { |
| 128 | int status = 0; |
| 129 | if(HuCPU.IRQlow & MDFN_IQIRQ1) status |= 2; |
| 130 | if(HuCPU.IRQlow & MDFN_IQIRQ2) status |= 1; |
| 131 | if(HuCPU.IRQlow & MDFN_IQTIMER) status |= 4; |
| 132 | return(status | (PCEIODataBuffer & ~(1 | 2 | 4))); |
| 133 | } |
| 134 | } |
| 135 | return(PCEIODataBuffer); |
| 136 | } |
| 137 | |
| 138 | static INLINE void HuC6280_IRQStatusWrite(unsigned int A, uint8 V) |
| 139 | { |
| 140 | if(!(A & 2)) return; |
| 141 | switch(A & 1) |
| 142 | { |
| 143 | case 0: HuCPU.IRQMask = (V & 0x7) ^ 0x7; break; |
| 144 | case 1: HuC6280_IRQEnd(MDFN_IQTIMER); break; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | #define _HuC6280H |
| 149 | #endif |