c62d2810 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * Copyright notice for this file: |
4 | * Copyright (C) 2002 Ben Parnell |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ |
20 | |
21 | typedef struct { |
22 | int32 count; /* Cycle counter */ |
23 | int32 tcount; /* Temporary cycle counter */ |
24 | uint16 PC; /* I'll change this to uint32 later... */ |
25 | /* I'll need to AND PC after increments to 0xFFFF */ |
26 | /* when I do, though. Perhaps an IPC() macro? */ |
92e249b1 |
27 | uint8 A,X,Y,S,P,mooPI; |
c62d2810 |
28 | uint8 DB; /* Data bus "cache" for reads from certain areas */ |
29 | uint8 IRQlow; /* Simulated IRQ pin held low(or is it high?). */ |
30 | uint8 jammed; |
31 | } X6502; |
32 | |
33 | extern X6502 X; |
34 | |
35 | #define N_FLAG 0x80 |
36 | #define V_FLAG 0x40 |
37 | #define U_FLAG 0x20 |
38 | #define B_FLAG 0x10 |
39 | #define D_FLAG 0x08 |
40 | #define I_FLAG 0x04 |
41 | #define Z_FLAG 0x02 |
42 | #define C_FLAG 0x01 |
43 | |
44 | extern uint32 timestamp; |
45 | extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); |
46 | |
47 | #define NTSC_CPU 1789772.7272727272727272 |
48 | #define PAL_CPU 1662607.125 |
49 | |
50 | #define FCEU_IQEXT 0x01 |
51 | #define FCEU_IQNMI 0x08 |
52 | #define FCEU_IQDPCM 0x10 |
53 | #define FCEU_IQFCOUNT 0x20 |
54 | #define FCEU_IQTEMP 0x80 |
55 | |
af32b6c2 |
56 | #if defined(DEBUG_ASM_6502) |
57 | #define TriggerIRQ TriggerIRQ_d |
58 | #define TriggerNMI TriggerNMI_d |
59 | #define TriggerNMINSF TriggerNMINSF_d |
60 | #define X6502_Run X6502_Run_d |
61 | #define X6502_Reset X6502_Reset_d |
62 | #define X6502_Power X6502_Power_d |
63 | #define X6502_AddCycles X6502_AddCycles_d |
64 | #define X6502_IRQBegin X6502_IRQBegin_d |
65 | #define X6502_IRQEnd X6502_IRQEnd_d |
66 | #define X6502_C |
67 | #define X6502_A |
68 | #define X6502_D |
69 | |
70 | #elif defined(ASM_6502) |
71 | #define TriggerIRQ TriggerIRQ_a |
72 | #define TriggerNMI TriggerNMI_a |
73 | #define TriggerNMINSF TriggerNMINSF_a |
74 | #define X6502_Reset X6502_Reset_a |
75 | #define X6502_Power X6502_Power_a |
76 | #define X6502_AddCycles X6502_AddCycles_a |
77 | #define X6502_IRQBegin X6502_IRQBegin_a |
78 | #define X6502_IRQEnd X6502_IRQEnd_a |
79 | #define X6502_A |
80 | |
af32b6c2 |
81 | #define X6502_Run(c) \ |
82 | { \ |
83 | int32 cycles = (c) << 4; /* *16 */ \ |
84 | if (PAL) cycles -= (c); /* *15 */ \ |
85 | nes_registers[7]+=cycles; \ |
92e249b1 |
86 | if (nes_registers[7] > 0) { \ |
87 | cycles = (int32)nes_registers[7]; \ |
88 | X6502_Run_a(); \ |
89 | cycles -= (int32)nes_registers[7]; \ |
90 | asmcpu_update(cycles); \ |
91 | } \ |
af32b6c2 |
92 | } |
93 | |
94 | #else |
92e249b1 |
95 | #define TriggerIRQ TriggerIRQ_c |
96 | #define TriggerNMI TriggerNMI_c |
97 | #define TriggerNMINSF TriggerNMINSF_c |
98 | #define X6502_Reset X6502_Reset_c |
99 | #define X6502_Power X6502_Power_c |
100 | #define X6502_AddCycles X6502_AddCycles_c |
101 | #define X6502_IRQBegin X6502_IRQBegin_c |
102 | #define X6502_IRQEnd X6502_IRQEnd_c |
103 | #define X6502_C |
104 | |
937bf65b |
105 | #define X6502_Run(c) \ |
106 | { \ |
107 | int32 cycles = (c) << 4; /* *16 */ \ |
108 | if (PAL) cycles -= (c); /* *15 */ \ |
109 | X.count+=cycles; \ |
af32b6c2 |
110 | if (X.count > 0) X6502_Run_c(); \ |
937bf65b |
111 | } |
af32b6c2 |
112 | #define X6502_C |
113 | #endif |
937bf65b |
114 | |
af32b6c2 |
115 | // c |
116 | #ifdef X6502_C |
117 | void TriggerIRQ_c(void); |
118 | void TriggerNMI_c(void); |
119 | void TriggerNMINSF_c(void); |
120 | void X6502_Run_c(void); |
121 | void X6502_Reset_c(void); |
122 | void X6502_Power_c(void); |
123 | void FASTAPASS(1) X6502_AddCycles_c(int x); |
124 | void FASTAPASS(1) X6502_IRQBegin_c(int w); |
125 | void FASTAPASS(1) X6502_IRQEnd_c(int w); |
126 | #endif |
c62d2810 |
127 | |
af32b6c2 |
128 | // asm |
129 | #ifdef X6502_A |
92e249b1 |
130 | extern uint32 nes_registers[0x10]; |
131 | extern uint32 pc_base; |
af32b6c2 |
132 | void TriggerIRQ_a(void); |
133 | void TriggerNMI_a(void); |
134 | void TriggerNMINSF_a(void); |
135 | void X6502_Run_a(void); |
136 | void X6502_Reset_a(void); |
137 | void X6502_Power_a(void); |
138 | void X6502_AddCycles_a(int x); |
139 | void X6502_IRQBegin_a(int w); |
140 | void X6502_IRQEnd_a(int w); |
92e249b1 |
141 | void X6502_rebase_a(void); |
af32b6c2 |
142 | #endif |
c62d2810 |
143 | |
af32b6c2 |
144 | // debug |
145 | #ifdef X6502_D |
146 | void TriggerIRQ_d(void); |
147 | void TriggerNMI_d(void); |
148 | void TriggerNMINSF_d(void); |
149 | void X6502_Run_d(int32 c); |
150 | void X6502_Reset_d(void); |
151 | void X6502_Power_d(void); |
152 | void X6502_AddCycles_d(int x); |
153 | void X6502_IRQBegin_d(int w); |
154 | void X6502_IRQEnd_d(int w); |
155 | #endif |
937bf65b |
156 | |