FabGL
ESP32 Display Controller and Graphics Library
MOS6502.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3  Copyright (c) 2019-2021 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6 
7 * Please contact fdivitto2013@gmail.com if you need a commercial license.
8 
9 
10 * This library and related software is available under GPL v3.
11 
12  FabGL is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  FabGL is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #pragma once
28 
29 
38 #include <stdint.h>
39 
40 
41 
42 namespace fabgl {
43 
44 
45 
49 class MOS6502 {
50 
51 public:
52 
53  // callbacks
54  typedef int (*ReadByteCallback)(void * context, int addr);
55  typedef void (*WriteByteCallback)(void * context, int addr, int value);
56  typedef int (*Page0ReadByteCallback)(void * context, int addr);
57  typedef void (*Page0WriteByteCallback)(void * context, int addr, int value);
58  typedef int (*Page1ReadByteCallback)(void * context, int addr);
59  typedef void (*Page1WriteByteCallback)(void * context, int addr, int value);
60 
61 
62  void setCallbacks(void * context, ReadByteCallback readByte, WriteByteCallback writeByte, Page0ReadByteCallback page0ReadByte, Page0WriteByteCallback page0WriteByte, Page1ReadByteCallback page1ReadByte, Page1WriteByteCallback page1WriteByte) {
63  m_context = context;
64  m_readByte = readByte;
65  m_writeByte = writeByte;
66  m_page0ReadByte = page0ReadByte;
67  m_page0WriteByte = page0WriteByte;
68  m_page1ReadByte = page1ReadByte;
69  m_page1WriteByte = page1WriteByte;
70  }
71 
72  int reset();
73  int IRQ();
74  int NMI();
75 
76  void setPC(uint16_t addr) { m_PC = addr; }
77  uint16_t getPC() { return m_PC; }
78 
79  int step();
80 
81 private:
82 
83  typedef void (MOS6502::*ADCSBC)(uint8_t);
84 
85  void OP_BINADC(uint8_t m);
86  void OP_BINSBC(uint8_t m);
87 
88  void OP_BCDADC(uint8_t m);
89  void OP_BCDSBC(uint8_t m);
90 
91  void setADCSBC();
92 
93 
94  ADCSBC m_OP_ADC;
95  ADCSBC m_OP_SBC;
96 
97  uint16_t m_PC;
98  uint8_t m_A;
99  uint8_t m_X;
100  uint8_t m_Y;
101  uint8_t m_SP;
102 
103  bool m_carry;
104  bool m_zero;
105  bool m_intDisable;
106  bool m_decimal;
107  bool m_overflow;
108  bool m_negative;
109 
110  void * m_context;
111  ReadByteCallback m_readByte;
112  WriteByteCallback m_writeByte;
113  Page0ReadByteCallback m_page0ReadByte;
114  Page0WriteByteCallback m_page0WriteByte;
115  Page1ReadByteCallback m_page1ReadByte;
116  Page1WriteByteCallback m_page1WriteByte;
117 
118 };
119 
120 }; // namespace fabgl
Definition: canvas.cpp:36
MOS 6502 CPU emulator.
Definition: MOS6502.h:49