-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCPUBUS.h
213 lines (163 loc) · 5.64 KB
/
CPUBUS.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
@file
@brief interface to the 8bit 68xx memory bus
@version 1.0
@author Arco van Geest <arco@appeltaart.mine.nu>
@copyright 2013 Arco van Geest <arco@appeltaart.mine.nu> All right reserved.
This file is part of PinDA.
PinDA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PinDA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PinDA. If not, see <http://www.gnu.org/licenses/>.
@date 20130520 Initial version
several methods to access the 680x memory bus.
This is no emulator, just a way to access the periperials on the memory bus.
*/
#ifndef CPUBUS_h
#define CPUBUS_h
// --------------------------------------------------------
// Includes
// --------------------------------------------------------
#include <inttypes.h>
#include <string.h>
#include "pinda.h"
#include <SPI.h>
#include "mcp23s17.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
//#if defined(ARDUINO)
#include "WProgram.h"
//#endif
#endif
// --------------------------------------------------------
// Definitions
// --------------------------------------------------------
//! SPI slave select for CPUBUS_spi
#define CPUBUS_SPI_SS 53
/**
* placeholder class for accessing the 8bit 68xx memory bus
*/
class CPUBUSClass : public PindaObj {
public:
CPUBUSClass();
//! initialize bus
//virtual void init(void);
//! placeholder for interrupts
void interrupt(void);
//! placeholder for untimed serviceLoop
void serviceLoop(void);
//! read byte from bus
virtual uint8_t read(const unsigned int address);
//! write byte to bus
virtual void write(const unsigned int address, const uint8_t data);
//! toggle reset port on 68xx bus low
virtual void reset(void);
// status
// getname
// interrupt
//String objName;
String status(void);
protected:
unsigned long reads; //!< amount of cpubus reads (diag)
unsigned long writes; //!< amount of cpubus writes
// String name;
String system; //!< name of system (diag)
};
/**
* CPUBUS using direct IO on arduino mega
*/
class Cpubus_Direct : public CPUBUSClass {
//"private" defines
// I do not know how to static const define the PORTS.
//! arduino port for data pins
#define CPUBUS_DATA_PORT PORTL
//! arduino pins for data pins
#define CPUBUS_DATA_PINS PINL
//! arduino datadirection for data pins
#define CPUBUS_DATA_DDR DDRL
//! arduino port for lower address pins
#define CPUBUS_ADDRL_PORT PORTA
//! arduino pins for lower address pins
#define CPUBUS_ADDRL_PINS PINA
//! arduino datadirection for lower address pins
#define CPUBUS_ADDRL_DDR DDRA
//! arduino port for higher address pins
#define CPUBUS_ADDRH_PORT PORTC
//! arduino pins for higher address pins
#define CPUBUS_ADDRH_PINS PINC
//! arduino datadirection for higher address pins
#define CPUBUS_ADDRH_DDR DDRC
//! arduino port for cpu control pins
#define CPUBUS_CTL_PORT PORTF
//! arduino pins for cpu control pins
#define CPUBUS_CTL_PINS PINF
//! arduino datadirection for cpu control pins
#define CPUBUS_CTL_DDR DDRF
private:
// hardware pins on arduino CPUBUS
static const uint8_t CPUBUS_RW=0; //! RW bit on arduino port
static const uint8_t CPUBUS_E=1; //! E bit on arduino port
static const uint8_t CPUBUS_VMA=2;
static const uint8_t CPUBUS_RESET=3;
static const uint8_t CPUBUS_HALT=4;
static const uint8_t CPUBUS_MR=5;
static const uint8_t CPUBUS_IRQ=6;
static const uint8_t CPUBUS_NMI=7;
static const uint8_t CPUBUS_RW_PIN=A0; //! RW PIN on arduino port
static const uint8_t CPUBUS_E_PIN=A1; //! E PIN on arduino port
static const uint8_t CPUBUS_VMA_PIN=A2;
static const uint8_t CPUBUS_RESET_PIN=A3;
static const uint8_t CPUBUS_HALT_PIN=A4;
static const uint8_t CPUBUS_MR_PIN=A5;
static const uint8_t CPUBUS_IRQ_PIN=A6;
static const uint8_t CPUBUS_NMI_PIN=A7;
public:
Cpubus_Direct(String _name="CPUBUSDIRECT");
//void init(void);
void reset(void);
uint8_t read(const unsigned int address);
void write(const unsigned int address, const uint8_t data);
void writeref(const unsigned int & address, const uint8_t & dataref);
//void setName( String name );
//String getName( void);
};
//extern Cpubus_Direct Cpubus;
/**
* CPUBUS using spi MCP23S17 io extenders
*/
class Cpubus_SPI : public CPUBUSClass {
public:
Cpubus_SPI(MCP23S17 * _mcpa , MCP23S17 * _mcpd , String _name="CPUBUS SPI");
//void init(void);
uint8_t read(unsigned int address);
void write(unsigned int address, uint8_t data);
private:
// SPI * spi;
static const uint8_t CPUBUS_RW=0; //! RW bit on arduino port
static const uint8_t CPUBUS_E=1; //! E bit on arduino port
static const uint8_t CPUBUS_VMA=2;
static const uint8_t CPUBUS_RESET=3;
static const uint8_t CPUBUS_HALT=4;
static const uint8_t CPUBUS_MR=5;
static const uint8_t CPUBUS_IRQ=6;
static const uint8_t CPUBUS_NMI=7;
MCP23S17 * mcpaddr;
MCP23S17 * mcpdata;
uint8_t sv_cpureg;
void writeData(uint8_t addr,uint8_t data);
};
/**
* CPUBUS using I2C MCP23017 io extenders
*/
class Cpubus_I2C : CPUBUSClass {
};
//extern Cpubus_SPI Cpubus;
//extern Cpubus_I2C Cpubus;
#endif /* CPUBUS_h */