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) - www.fabgl.com
3  Copyright (c) 2019-2021 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of FabGL Library.
7 
8  FabGL 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 3 of the License, or
11  (at your option) any later version.
12 
13  FabGL 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 FabGL. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #pragma once
24 
25 
34 #include <stdint.h>
35 
36 
37 
38 namespace fabgl {
39 
40 
41 
45 class MOS6502 {
46 
47 public:
48 
49  // callbacks
50  typedef int (*ReadByteCallback)(void * context, int addr);
51  typedef void (*WriteByteCallback)(void * context, int addr, int value);
52  typedef int (*Page0ReadByteCallback)(void * context, int addr);
53  typedef void (*Page0WriteByteCallback)(void * context, int addr, int value);
54  typedef int (*Page1ReadByteCallback)(void * context, int addr);
55  typedef void (*Page1WriteByteCallback)(void * context, int addr, int value);
56 
57 
58  void setCallbacks(void * context, ReadByteCallback readByte, WriteByteCallback writeByte, Page0ReadByteCallback page0ReadByte, Page0WriteByteCallback page0WriteByte, Page1ReadByteCallback page1ReadByte, Page1WriteByteCallback page1WriteByte) {
59  m_context = context;
60  m_readByte = readByte;
61  m_writeByte = writeByte;
62  m_page0ReadByte = page0ReadByte;
63  m_page0WriteByte = page0WriteByte;
64  m_page1ReadByte = page1ReadByte;
65  m_page1WriteByte = page1WriteByte;
66  }
67 
68  int reset();
69  int IRQ();
70  int NMI();
71 
72  void setPC(uint16_t addr) { m_PC = addr; }
73  uint16_t getPC() { return m_PC; }
74 
75  int step();
76 
77 private:
78 
79  typedef void (MOS6502::*ADCSBC)(uint8_t);
80 
81  void OP_BINADC(uint8_t m);
82  void OP_BINSBC(uint8_t m);
83 
84  void OP_BCDADC(uint8_t m);
85  void OP_BCDSBC(uint8_t m);
86 
87  void setADCSBC();
88 
89 
90  ADCSBC m_OP_ADC;
91  ADCSBC m_OP_SBC;
92 
93  uint16_t m_PC;
94  uint8_t m_A;
95  uint8_t m_X;
96  uint8_t m_Y;
97  uint8_t m_SP;
98 
99  bool m_carry;
100  bool m_zero;
101  bool m_intDisable;
102  bool m_decimal;
103  bool m_overflow;
104  bool m_negative;
105 
106  void * m_context;
107  ReadByteCallback m_readByte;
108  WriteByteCallback m_writeByte;
109  Page0ReadByteCallback m_page0ReadByte;
110  Page0WriteByteCallback m_page0WriteByte;
111  Page1ReadByteCallback m_page1ReadByte;
112  Page1WriteByteCallback m_page1WriteByte;
113 
114 };
115 
116 }; // namespace fabgl
Definition: canvas.cpp:32
MOS 6502 CPU emulator.
Definition: MOS6502.h:45