-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBus.java
More file actions
315 lines (281 loc) · 13.2 KB
/
Copy pathBus.java
File metadata and controls
315 lines (281 loc) · 13.2 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import java.util.Arrays;
public class Bus {
/*
0000-002C TIA Write
0000-000D TIA Read (sometimes mirrored at 0030-003D)
0080-00FF PIA RAM (128 bytes)
0280-0297 PIA Ports and Timer
F000-FFFF Cartridge Memory (4 Kbytes area)
*/
public static void clearMem() {
Arrays.fill(Pia.ram, 0);
}
public static int read(int address) {
if (address < 0x80) { // TIA Read (sometimes mirrored at 0030-003D)
switch (address) {
// 30 CXM0P 11...... read collision M0-P1, M0-P0 (Bit 7,6)
case 0x00: return Tia.CXM0P;
// 31 CXM1P 11...... read collision M1-P0, M1-P1
case 0x01: return Tia.CXM1P;
// 32 CXP0FB 11...... read collision P0-PF, P0-BL
case 0x02: return Tia.CXP0FB;
// 33 CXP1FB 11...... read collision P1-PF, P1-BL
case 0x03: return Tia.CXP1FB;
// 34 CXM0FB 11...... read collision M0-PF, M0-BL
case 0x04: return Tia.CXM0FB;
// 35 CXM1FB 11...... read collision M1-PF, M1-BL
case 0x05: return Tia.CXM1FB;
// 36 CXBLPF 1....... read collision BL-PF, unused
case 0x06: return Tia.CXBLPF;
// 37 CXPPMM 11...... read collision P0-P1, M0-M1
case 0x07: return Tia.CXPPMM;
// 3C INPT4 1....... read input
case 0x0C: return Tia.INPT4;
// 3D INPT5 1....... read input
case 0x0D: return Tia.INPT5;
}
}
else if (address >= 0x0080 && address <= 0x00FF) { // ram
return Pia.ram[address];
}
else if (address >= 0x0180 && address <= 0x01FF) { // ram mirror (stack)
return Pia.ram[address - 0x100];
}
else if (address >= 0x003C && address <= 0x003D) { // TIA Read (sometimes mirrored at 0030-003D)
switch (address) {
// 30 CXM0P 11...... read collision M0-P1, M0-P0 (Bit 7,6)
case 0x30: return Tia.CXM0P;
// 31 CXM1P 11...... read collision M1-P0, M1-P1
case 0x31: return Tia.CXM1P;
// 32 CXP0FB 11...... read collision P0-PF, P0-BL
case 0x32: return Tia.CXP0FB;
// 33 CXP1FB 11...... read collision P1-PF, P1-BL
case 0x33: return Tia.CXP1FB;
// 34 CXM0FB 11...... read collision M0-PF, M0-BL
case 0x34: return Tia.CXM0FB;
// 35 CXM1FB 11...... read collision M1-PF, M1-BL
case 0x35: return Tia.CXM1FB;
// 36 CXBLPF 1....... read collision BL-PF, unused
case 0x36: return Tia.CXBLPF;
// 37 CXPPMM 11...... read collision P0-P1, M0-M1
case 0x37: return Tia.CXPPMM;
// 3C INPT4 1....... read input
case 0x3C: return Tia.INPT4;
// 3D INPT5 1....... read input
case 0x3D: return Tia.INPT5;
}
}
/*
if (address >= 0x0000 && address <= 0x002C) { // TIA Write
}
else if (address >= 0x0080 && address <= 0x00FF) { // PIA RAM (128 bytes)
return mem[address];
}
*/
else if (address >= 0x0280 && address <= 0x0297) { // PIA Ports and Timer
switch (address) {
// 0280 SWCHA 11111111 Port A; input or output (read or write)
case 0x280: return Pia.SWCHA;
// 0282 SWCHB 11111111 Port B; console switches (read only)
case 0x282: return Pia.SWCHB;
// 0284 INTIM 11111111 Timer output (read only)
case 0x284: return Pia.INTIM();
// 0285 INSTAT 11...... Timer Status (read only, undocumented)
case 0x285: return Pia.INSTAT;
}
}
else if (address >= 0xF000 && address <= 0xFFFF) { // Cartridge Memory (4 Kbytes area)
return Cartridge.rom[address];
}
else {
System.out.println("NOT HANDLED READ address: " + address);
}
return 0; //mem[address & 0xffff] & 0xff;
}
public static boolean postWrite = false;
private static int writeAddress;
private static int writeValue;
private static int writeAddress2;
private static int writeValue2;
private static int writeCount;
private static boolean write2 = false;
public static void write(int address, int value) {
if (postWrite) {
writeAddress2 = address;
writeValue2 = value;
write2 = true;
return;
}
writeAddress = address;
writeValue = value;
postWrite = true;
writeCount++;
if (writeCount > 2) {
System.out.println();
}
}
public static void commitPostWrite() {
if (postWrite) {
writePost(writeAddress, writeValue);
if (write2) {
writePost(writeAddress2, writeValue2);
write2 = false;
}
postWrite = false;
writeCount = 0;
}
}
// test
private static int saveWriteAddress;
private static int saveWriteValue;
private static int saveWriteAddress2;
private static int saveWriteValue2;
private static int saveWriteCount;
public static boolean saveWrite = false;
public static void savePostWrite() {
if (postWrite) {
saveWriteAddress = writeAddress;
saveWriteValue = writeValue;
saveWriteAddress2 = writeAddress2;
saveWriteValue2 = writeValue2;
saveWriteCount = writeCount;
saveWrite = true;
}
}
public static void commitSaveWrite() {
saveWrite = false;
writePost(saveWriteAddress, saveWriteValue);
if (saveWriteCount > 1) {
writePost(saveWriteAddress2, saveWriteValue2);
}
}
public static void writePost(int address, int value) {
if (address >= 0x0080 && address <= 0x00FF) { // ram
Pia.ram[address] = value;
}
else if (address >= 0x0180 && address <= 0x01FF) { // ram mirror
Pia.ram[address - 0x100] = value;
}
else if (address >= 0x0000 && address <= 0x002C) { // TIA Write
switch (address) {
// 00 VSYNC ......1. vertical sync set-clear
case 0x00 -> Tia.VSYNC(value);
// 01 VBLANK 11....1. vertical blank set-clear
case 0x01 -> Tia.VBLANK(value);
// 02 WSYNC <strobe> wait for leading edge of horizontal blank
case 0x02 -> Tia.WSYNC(value);
// 04 NUSIZ0 ..111111 number-size player-missile 0
case 0x04 -> Tia.NUSIZ0 = value;
// 05 NUSIZ1 ..111111 number-size player-missile 1
case 0x05 -> Tia.NUSIZ1 = value;
// 06 COLUP0 1111111. color-lum player 0 and missile 0
case 0x06 -> Tia.COLUP0 = value;
// 07 COLUP1 1111111. color-lum player 1 and missile 1
case 0x07 -> Tia.COLUP1 = value;
// 08 COLUPF 1111111. color-lum playfield and ball
case 0x08 -> Tia.COLUPF = value;
// 09 COLUBK 1111111. color-lum background
case 0x09 -> Tia.COLUBK = value;
// 0A CTRLPF ..11.111 control playfield ball size & collisions
case 0x0A -> Tia.CTRLPF = value;
// 0B REFP0 ....1... reflect player 0
case 0x0B -> Tia.REFP0 = value;
// 0C REFP1 ....1... reflect player 1
case 0x0C -> Tia.REFP1 = value;
// 0D PF0 1111.... playfield register byte 0
case 0x0D -> Tia.PF0 = value;
// 0E PF1 11111111 playfield register byte 1
case 0x0E -> Tia.PF1 = value;
// 0F PF2 11111111 playfield register byte 2
case 0x0F -> Tia.PF2 = value;
// 10 RESP0 <strobe> reset player 0
case 0x10 -> Tia.RESP0(value);
// 11 RESP1 <strobe> reset player 1
case 0x11 -> Tia.RESP1(value);
// 12 RESM0 <strobe> reset missile 0
case 0x12 -> Tia.RESM0(value);
// 13 RESM1 <strobe> reset missile 1
case 0x13 -> Tia.RESM1(value);
// 14 RESBL <strobe> reset ball
case 0x14 -> Tia.RESBL(value);
// 15 AUDC0 ....1111 audio control 0
case 0x15 -> TiaAudio.AUD0.AUDC = value;
// 16 AUDC1 ....1111 audio control 1
case 0x16 -> TiaAudio.AUD1.AUDC = value;
// 17 AUDF0 ...11111 audio frequency 0
case 0x17 -> TiaAudio.AUD0.AUDF = value;
// 18 AUDF1 ...11111 audio frequency 1
case 0x18 -> TiaAudio.AUD1.AUDF = value;
// 19 AUDV0 ....1111 audio volume 0
case 0x19 -> TiaAudio.AUD0.AUDV = value;
// 1A AUDV1 ....1111 audio volume 1
case 0x1A -> TiaAudio.AUD1.AUDV = value;
// 1B GRP0 11111111 graphics player 0
case 0x1B -> Tia.GRP0(value);
// 1C GRP1 11111111 graphics player 1
case 0x1C -> Tia.GRP1(value);
// 22 HMM0 1111.... horizontal motion missile 0
case 0x22 -> Tia.HMM0 = value;
// 23 HMM1 1111.... horizontal motion missile 1
case 0x23 -> Tia.HMM1 = value;
// 25 VDELP0 .......1 vertical delay player 0
case 0x25 -> Tia.VDELP0 = value;
// 26 VDELP1 .......1 vertical delay player 1
case 0x26 -> Tia.VDELP1 = value;
// 27 VDELBL .......1 vertical delay ball
case 0x27 -> Tia.VDELBL = value;
// 28 RESMP0 ......1. reset missile 0 to player 0
case 0x28 -> Tia.RESMP0(value);
// 29 RESMP1 ......1. reset missile 1 to player 1
case 0x29 -> Tia.RESMP1(value);
// 1D ENAM0 ......1. graphics (enable) missile 0
case 0x1D -> Tia.ENAM0(value);
// 1E ENAM1 ......1. graphics (enable) missile 1
case 0x1E -> Tia.ENAM1(value);
// 1F ENABL ......1. graphics (enable) ball
case 0x1F -> Tia.ENABL(value);
// 20 HMP0 1111.... horizontal motion player 0
case 0x20 -> Tia.HMP0 = value;
// 21 HMP1 1111.... horizontal motion player 1
case 0x21 -> Tia.HMP1 = value;
// 24 HMBL 1111.... horizontal motion ball
case 0x24 -> Tia.HMBL = value;
// 2A HMOVE <strobe> apply horizontal motion
case 0x2A -> Tia.HMOVE(value);
// 2B HMCLR <strobe> clear horizontal motion registers
case 0x2B -> Tia.HMCLR(value);
// 2C CXCLR <strobe> clear collision latches
case 0x2C -> Tia.CXCLR(value);
default -> {}
}
}
else if (address >= 0x0280 && address <= 0x0297) { // PIA Ports and Timer
switch (address) {
// 0280 SWCHA 11111111 Port A; input or output (read or write)
case 0x280 -> Pia.SWCHA = value;
// 0294 TIM1T 11111111 set 1 clock interval (838 nsec/interval)
case 0x294 -> Pia.TIM1T(value);
// 0295 TIM8T 11111111 set 8 clock interval (6.7 usec/interval)
case 0x295 -> Pia.TIM8T(value);
// 0296 TIM64T 11111111 set 64 clock interval (53.6 usec/interval)
case 0x296 -> Pia.TIM64T(value);
// 0297 T1024T 11111111 set 1024 clock interval (858.2 usec/interval)
case 0x297 -> Pia.T1024T(value);
}
}
else {
System.out.println("NOT HANDLED WRITE address: " + address + " value: " + value);
}
/*
else if (address >= 0x0000 && address <= 0x000D) { // TIA Read (sometimes mirrored at 0030-003D)
}
else if (address >= 0x0080 && address <= 0x00FF) { // PIA RAM (128 bytes)
mem[address] = address;
}
else if (address >= 0xF000 && address <= 0xFFFF) { // Cartridge Memory (4 Kbytes area)
// Cartridge.rom[address] = value; // <- read only
}
*/
//mem[address & 0xffff] = value & 0xff;
}
}