libsidplayfp  1.5.3
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 "sidplayfp/EventScheduler.h"
30 
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34 
35 class EventContext;
36 
46 class MOS6510
47 {
48  friend class MOS6510Debug;
49 
50 private:
51  static const char *credit;
52 
53 private:
59  static const int MAX = 65536;
60 
62  static const uint8_t SP_PAGE = 0x01;
63 
64 public:
66  static const int SR_INTERRUPT = 2;
67 
68 private:
69  struct ProcessorCycle
70  {
71  void (MOS6510::*func)();
72  bool nosteal;
73  ProcessorCycle () :
74  func(0),
75  nosteal(false) {}
76  };
77 
78 private:
80  EventContext &eventContext;
81 
83  int cycleCount;
84 
86  int interruptCycle;
87 
89  bool irqAssertedOnPin;
90 
92  bool nmiFlag;
93 
95  bool rstFlag;
96 
98  bool rdy;
99 
100  // Flags
101  bool flagN;
102  bool flagC;
103  bool flagD;
104  bool flagZ;
105  bool flagV;
106  bool flagI;
107  bool flagB;
108 
109  // Data regarding current instruction
110  uint_least16_t Register_ProgramCounter;
111  uint_least16_t Cycle_EffectiveAddress;
112  uint_least16_t Cycle_HighByteWrongEffectiveAddress;
113  uint_least16_t Cycle_Pointer;
114 
115  uint8_t Cycle_Data;
116  uint8_t Register_StackPointer;
117  uint8_t Register_Accumulator;
118  uint8_t Register_X;
119  uint8_t Register_Y;
120 
121 #ifdef DEBUG
122  // Debug info
123  uint_least16_t instrStartPC;
124  uint_least16_t instrOperand;
125 
126  FILE *m_fdbg;
127 
128  bool dodump;
129 #endif
130 
132  struct ProcessorCycle instrTable[0x101 << 3];
133 
134 private:
136  EventCallback<MOS6510> m_nosteal;
137 
139  EventCallback<MOS6510> m_steal;
140 
141  void eventWithoutSteals();
142  void eventWithSteals();
143 
144  void Initialise();
145 
146  // Flag utility functions
147  inline void setFlagsNZ(uint8_t value);
148  inline uint8_t getStatusRegister();
149  inline void setStatusRegister(uint8_t sr);
150 
151  // Declare Interrupt Routines
152  inline void IRQLoRequest();
153  inline void IRQHiRequest();
154  inline void interruptsAndNextOpcode();
155  inline void calculateInterruptTriggerCycle();
156 
157  // Declare Instruction Routines
158  inline void fetchNextOpcode();
159  inline void throwAwayFetch();
160  inline void throwAwayRead();
161  inline void FetchDataByte();
162  inline void FetchLowAddr();
163  inline void FetchLowAddrX();
164  inline void FetchLowAddrY();
165  inline void FetchHighAddr();
166  inline void FetchHighAddrX();
167  inline void FetchHighAddrX2();
168  inline void FetchHighAddrY();
169  inline void FetchHighAddrY2();
170  inline void FetchLowEffAddr();
171  inline void FetchHighEffAddr();
172  inline void FetchHighEffAddrY();
173  inline void FetchHighEffAddrY2();
174  inline void FetchLowPointer();
175  inline void FetchLowPointerX();
176  inline void FetchHighPointer();
177  inline void FetchEffAddrDataByte ();
178  inline void PutEffAddrDataByte();
179  inline void PushLowPC();
180  inline void PushHighPC();
181  inline void PushSR();
182  inline void PopLowPC();
183  inline void PopHighPC();
184  inline void PopSR();
185  inline void brkPushLowPC();
186  inline void WasteCycle();
187 
188  // Delcare Instruction Operation Routines
189  inline void adc_instr();
190  inline void alr_instr();
191  inline void anc_instr();
192  inline void and_instr();
193  inline void ane_instr();
194  inline void arr_instr();
195  inline void asl_instr();
196  inline void asla_instr();
197  inline void aso_instr();
198  inline void axa_instr();
199  inline void axs_instr();
200  inline void bcc_instr();
201  inline void bcs_instr();
202  inline void beq_instr();
203  inline void bit_instr();
204  inline void bmi_instr();
205  inline void bne_instr();
206  inline void branch_instr(bool condition);
207  inline void bpl_instr();
208  inline void brk_instr();
209  inline void bvc_instr();
210  inline void bvs_instr();
211  inline void clc_instr();
212  inline void cld_instr();
213  inline void cli_instr();
214  inline void clv_instr();
215  inline void cmp_instr();
216  inline void cpx_instr();
217  inline void cpy_instr();
218  inline void dcm_instr();
219  inline void dec_instr();
220  inline void dex_instr();
221  inline void dey_instr();
222  inline void eor_instr();
223  inline void inc_instr();
224  inline void ins_instr();
225  inline void inx_instr();
226  inline void iny_instr();
227  inline void jmp_instr();
228  inline void las_instr();
229  inline void lax_instr();
230  inline void lda_instr();
231  inline void ldx_instr();
232  inline void ldy_instr();
233  inline void lse_instr();
234  inline void lsr_instr();
235  inline void lsra_instr();
236  inline void oal_instr();
237  inline void ora_instr();
238  inline void pha_instr();
239  inline void pla_instr();
240  inline void plp_instr();
241  inline void rla_instr();
242  inline void rol_instr();
243  inline void rola_instr();
244  inline void ror_instr();
245  inline void rora_instr();
246  inline void rra_instr();
247  inline void rti_instr();
248  inline void rts_instr();
249  inline void sbx_instr();
250  inline void say_instr();
251  inline void sbc_instr();
252  inline void sec_instr();
253  inline void sed_instr();
254  inline void sei_instr();
255  inline void shs_instr();
256  inline void sta_instr();
257  inline void stx_instr();
258  inline void sty_instr();
259  inline void tax_instr();
260  inline void tay_instr();
261  inline void tsx_instr();
262  inline void txa_instr();
263  inline void txs_instr();
264  inline void tya_instr();
265  inline void xas_instr();
266 
267  void illegal_instr();
268 
269  // Declare Arithmetic Operations
270  inline void doADC();
271  inline void doSBC();
272 
273  inline void doJSR();
274 
275 protected:
276  MOS6510(EventContext *context);
277  ~MOS6510() {}
278 
279 public:
286  virtual uint8_t cpuRead(uint_least16_t addr) =0;
287 
294  virtual void cpuWrite(uint_least16_t addr, uint8_t data) =0;
295 
296 #ifdef PC64_TESTSUITE
297  virtual void loadFile (const char *file) =0;
298 #endif
299 
300  virtual void reset();
301 
302  const char *credits() const { return credit; }
303 
304  void debug(bool enable, FILE *out);
305  void setRDY(bool newRDY);
306 
307  // Non-standard functions
308  void triggerRST();
309  void triggerNMI();
310  void triggerIRQ();
311  void clearIRQ();
312 };
313 
314 #endif // MOS6510_H
MOS6510(EventContext *context)
Definition: mos6510.cpp:1522
void setRDY(bool newRDY)
Definition: mos6510.cpp:156
virtual void reset()
Definition: mos6510.cpp:2215
static const int SR_INTERRUPT
Status register interrupt bit.
Definition: mos6510.h:66
virtual void cpuWrite(uint_least16_t addr, uint8_t data)=0
Definition: event.h:107
Definition: mos6510.h:46
virtual uint8_t cpuRead(uint_least16_t addr)=0
void triggerNMI()
Definition: mos6510.cpp:225
void triggerIRQ()
Definition: mos6510.cpp:239
void clearIRQ()
Definition: mos6510.cpp:253
void triggerRST()
Definition: mos6510.cpp:211