forked from jasonfrowe/2600MultiCart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart_setup.h
183 lines (166 loc) · 5.35 KB
/
cart_setup.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
// Variables about the ROM
uint romsize = 4096; // Will be set by setup_cart
uint8_t rom_contents[32768] = { 0 }; // Will be set by setup_cart
uint8_t cart = 0; // Will be set by GPIO pins
uint bankswitch = 0; // Will be set by setup_cart
uint16_t romoffset = 0; // offset for bankswitching
uint16_t addr; // address read from address lines
void setup_cart(); // Will fetch the rom contents
void (*fpBankSwitching)(uint16_t); // function pointer
void BankSwitching_none(uint16_t);
void BankSwitching_F8(uint16_t); // 8K
void BankSwitching_F6(uint16_t); // 16K
void BankSwitching_F4(uint16_t); // 32K
// Function to set up ROM from DIP-switches
void setup_cart() {
// Read in DIPs to get cart to use
gpio_init(21);
gpio_set_dir(21, GPIO_IN);
gpio_pull_up(21);
gpio_init(22);
gpio_set_dir(22, GPIO_IN);
gpio_pull_up(22);
gpio_init(26);
gpio_set_dir(26, GPIO_IN);
gpio_pull_up(26);
gpio_init(27);
gpio_set_dir(27, GPIO_IN);
gpio_pull_up(27);
cart = 8*gpio_get(27) + 4*gpio_get(26) + 2*gpio_get(22) + gpio_get(21);
// GPIO(27)*8 only works if called twice?? What is wrong?
cart = 8*gpio_get(27) + 4*gpio_get(26) + 2*gpio_get(22) + gpio_get(21);
// uint8_t gp27 = gpio_get(27);
// cart = gp27*8 + 4*gpio_get(26) + 2*gpio_get(22) + gpio_get(21);
// Specify contents of emulated ROM.
if (cart == 0){
#include "roms_00.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 1){
#include "roms_01.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 2){
#include "roms_02.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 3){
#include "roms_03.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 4){
#include "roms_04.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 5){
#include "roms_05.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 6){
#include "roms_06.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 7){
#include "roms_07.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 8){
#include "roms_08.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 9){
#include "roms_09.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 10){
#include "roms_10.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 11){
#include "roms_11.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 12){
#include "roms_12.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 13){
#include "roms_13.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 14){
#include "roms_14.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
} else if (cart == 15){
#include "roms_15.h"
romsize = romsize_in;
for (int i = 0; i < romsize_in; i++){
rom_contents[i] = rom_contents_in[i];
}
}
if (romsize == 4096){
bankswitch = 0; // No bankswitching
fpBankSwitching = &BankSwitching_none;
} else if (romsize == 8192){
bankswitch = 1; // F8 bankswitching
fpBankSwitching = &BankSwitching_F8;
} else if (romsize == 16384){
bankswitch = 2; // F6 bankswitching
fpBankSwitching = &BankSwitching_F6;
} else if (romsize == 32768){
bankswitch = 3; // F4 bankswitching
fpBankSwitching = &BankSwitching_F4;
}
}
// Bank Switching Functions
void BankSwitching_none(uint16_t addr_in) {
romoffset = 0;
}
void BankSwitching_F8(uint16_t addr_in) {
if (addr_in == 4088){
romoffset = 0;
} else if (addr_in == 4089){
romoffset = 4096;
}
}
void BankSwitching_F6(uint16_t addr_in) {
if ((addr_in >= 4086) && (addr_in <= 4089)){
romoffset = 4096 * (addr_in - 4086);
}
}
void BankSwitching_F4(uint16_t addr_in) {
if ((addr_in >= 4084) && (addr_in <= 4091)){
romoffset = 4096 * (addr_in - 4084);
}
}