libsidplayfp  1.8.7
mos6510.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2000 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef MOS6510_H
24 #define MOS6510_H
25 
26 #include <stdint.h>
27 #include <cstdio>
28 
29 #include "flags.h"
30 #include "EventScheduler.h"
31 
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35 
36 class EventContext;
37 
47 class MOS6510
48 {
49  friend class MOS6510Debug;
50 
51 private:
52  static const char *credit;
53 
54 private:
60  static const int MAX = 65536;
61 
63  static const uint8_t SP_PAGE = 0x01;
64 
65 public:
67  static const int SR_INTERRUPT = 2;
68 
69 private:
70  struct ProcessorCycle
71  {
72  void (MOS6510::*func)();
73  bool nosteal;
74  ProcessorCycle () :
75  func(0),
76  nosteal(false) {}
77  };
78 
79 private:
81  EventContext &eventContext;
82 
84  int cycleCount;
85 
87  int interruptCycle;
88 
90  bool irqAssertedOnPin;
91 
93  bool nmiFlag;
94 
96  bool rstFlag;
97 
99  bool rdy;
100 
102  Flags flags;
103 
104  // Data regarding current instruction
105  uint_least16_t Register_ProgramCounter;
106  uint_least16_t Cycle_EffectiveAddress;
107  uint_least16_t Cycle_HighByteWrongEffectiveAddress;
108  uint_least16_t Cycle_Pointer;
109 
110  uint8_t Cycle_Data;
111  uint8_t Register_StackPointer;
112  uint8_t Register_Accumulator;
113  uint8_t Register_X;
114  uint8_t Register_Y;
115 
116 #ifdef DEBUG
117  // Debug info
118  uint_least16_t instrStartPC;
119  uint_least16_t instrOperand;
120 
121  FILE *m_fdbg;
122 
123  bool dodump;
124 #endif
125 
127  struct ProcessorCycle instrTable[0x101 << 3];
128 
129 private:
131  EventCallback<MOS6510> m_nosteal;
132 
134  EventCallback<MOS6510> m_steal;
135 
136  void eventWithoutSteals();
137  void eventWithSteals();
138 
139  void Initialise();
140 
141  // Declare Interrupt Routines
142  inline void IRQLoRequest();
143  inline void IRQHiRequest();
144  inline void interruptsAndNextOpcode();
145  inline void calculateInterruptTriggerCycle();
146 
147  // Declare Instruction Routines
148  inline void fetchNextOpcode();
149  inline void throwAwayFetch();
150  inline void throwAwayRead();
151  inline void FetchDataByte();
152  inline void FetchLowAddr();
153  inline void FetchLowAddrX();
154  inline void FetchLowAddrY();
155  inline void FetchHighAddr();
156  inline void FetchHighAddrX();
157  inline void FetchHighAddrX2();
158  inline void FetchHighAddrY();
159  inline void FetchHighAddrY2();
160  inline void FetchLowEffAddr();
161  inline void FetchHighEffAddr();
162  inline void FetchHighEffAddrY();
163  inline void FetchHighEffAddrY2();
164  inline void FetchLowPointer();
165  inline void FetchLowPointerX();
166  inline void FetchHighPointer();
167  inline void FetchEffAddrDataByte ();
168  inline void PutEffAddrDataByte();
169  inline void PushLowPC();
170  inline void PushHighPC();
171  inline void PushSR();
172  inline void PopLowPC();
173  inline void PopHighPC();
174  inline void PopSR();
175  inline void brkPushLowPC();
176  inline void WasteCycle();
177 
178  // Delcare Instruction Operation Routines
179  inline void adc_instr();
180  inline void alr_instr();
181  inline void anc_instr();
182  inline void and_instr();
183  inline void ane_instr();
184  inline void arr_instr();
185  inline void asl_instr();
186  inline void asla_instr();
187  inline void aso_instr();
188  inline void axa_instr();
189  inline void axs_instr();
190  inline void bcc_instr();
191  inline void bcs_instr();
192  inline void beq_instr();
193  inline void bit_instr();
194  inline void bmi_instr();
195  inline void bne_instr();
196  inline void branch_instr(bool condition);
197  inline void bpl_instr();
198  inline void brk_instr();
199  inline void bvc_instr();
200  inline void bvs_instr();
201  inline void clc_instr();
202  inline void cld_instr();
203  inline void cli_instr();
204  inline void clv_instr();
205  inline void cmp_instr();
206  inline void cpx_instr();
207  inline void cpy_instr();
208  inline void dcm_instr();
209  inline void dec_instr();
210  inline void dex_instr();
211  inline void dey_instr();
212  inline void eor_instr();
213  inline void inc_instr();
214  inline void ins_instr();
215  inline void inx_instr();
216  inline void iny_instr();
217  inline void jmp_instr();
218  inline void las_instr();
219  inline void lax_instr();
220  inline void lda_instr();
221  inline void ldx_instr();
222  inline void ldy_instr();
223  inline void lse_instr();
224  inline void lsr_instr();
225  inline void lsra_instr();
226  inline void oal_instr();
227  inline void ora_instr();
228  inline void pha_instr();
229  inline void pla_instr();
230  inline void plp_instr();
231  inline void rla_instr();
232  inline void rol_instr();
233  inline void rola_instr();
234  inline void ror_instr();
235  inline void rora_instr();
236  inline void rra_instr();
237  inline void rti_instr();
238  inline void rts_instr();
239  inline void sbx_instr();
240  inline void say_instr();
241  inline void sbc_instr();
242  inline void sec_instr();
243  inline void sed_instr();
244  inline void sei_instr();
245  inline void shs_instr();
246  inline void sta_instr();
247  inline void stx_instr();
248  inline void sty_instr();
249  inline void tax_instr();
250  inline void tay_instr();
251  inline void tsx_instr();
252  inline void txa_instr();
253  inline void txs_instr();
254  inline void tya_instr();
255  inline void xas_instr();
256 
257  void illegal_instr();
258 
259  // Declare Arithmetic Operations
260  inline void doADC();
261  inline void doSBC();
262 
263  inline void doJSR();
264 
265 protected:
266  MOS6510(EventContext *context);
267  ~MOS6510() {}
268 
269 public:
276  virtual uint8_t cpuRead(uint_least16_t addr) =0;
277 
284  virtual void cpuWrite(uint_least16_t addr, uint8_t data) =0;
285 
286 #ifdef PC64_TESTSUITE
287  virtual void loadFile (const char *file) =0;
288 #endif
289 
290  void reset();
291 
292  static const char *credits() { return credit; }
293 
294  void debug(bool enable, FILE *out);
295  void setRDY(bool newRDY);
296 
297  // Non-standard functions
298  void triggerRST();
299  void triggerNMI();
300  void triggerIRQ();
301  void clearIRQ();
302 };
303 
304 #endif // MOS6510_H
MOS6510(EventContext *context)
Definition: mos6510.cpp:1475
void setRDY(bool newRDY)
Definition: mos6510.cpp:116
void reset()
Definition: mos6510.cpp:2167
static const int SR_INTERRUPT
Status register interrupt bit.
Definition: mos6510.h:67
virtual void cpuWrite(uint_least16_t addr, uint8_t data)=0
Definition: event.h:107
Definition: mos6510.h:47
Definition: flags.h:31
virtual uint8_t cpuRead(uint_least16_t addr)=0
void triggerNMI()
Definition: mos6510.cpp:185
void triggerIRQ()
Definition: mos6510.cpp:199
void clearIRQ()
Definition: mos6510.cpp:213
void triggerRST()
Definition: mos6510.cpp:171