Skip to content

Commit 5a111b2

Browse files
committed
Add device selector switch to PIAs.
1 parent 594dc8a commit 5a111b2

File tree

4 files changed

+63
-24
lines changed

4 files changed

+63
-24
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ca.craigthomas.yacoco3e.components;
2+
3+
public class DeviceSelectorSwitch
4+
{
5+
protected int switchPosition;
6+
protected int CB2;
7+
protected int CA2;
8+
9+
public DeviceSelectorSwitch() {
10+
switchPosition = 0;
11+
CB2 = 0;
12+
CA2 = 0;
13+
}
14+
15+
public void setCB2(boolean isSet) {
16+
CB2 = (isSet) ? 1 : 0;
17+
switchPosition = (CB2 << 1) + CA2;
18+
System.out.println("New switch position = " + switchPosition);
19+
}
20+
21+
public void setCA2(boolean isSet) {
22+
CA2 = (isSet) ? 1 : 0;
23+
switchPosition = (CB2 << 1) + CA2;
24+
System.out.println("New switch position = " + switchPosition);
25+
}
26+
27+
public int getSwitchPosition() {
28+
return switchPosition;
29+
}
30+
}

src/main/java/ca/craigthomas/yacoco3e/components/IOController.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,8 @@ public class IOController
4646
protected PIA2a pia2a;
4747
protected PIA2b pia2b;
4848

49-
/* PIA2 */
50-
protected UnsignedByte pia2DRA; /* PIA 2 Data Register A */
51-
protected UnsignedByte pia2CRA; /* PIA 2 Control Register A*/
52-
protected UnsignedByte pia2DDRA; /* PIA 2 Data Direction Register A */
53-
54-
protected UnsignedByte pia2DRB;
55-
protected UnsignedByte pia2CRB;
56-
protected UnsignedByte pia2DDRB;
49+
/* Device Selector */
50+
protected DeviceSelectorSwitch deviceSelectorSwitch;
5751

5852
/* Video mode related functions */
5953
protected UnsignedByte samControlBits;
@@ -118,26 +112,19 @@ public IOController(Memory memory, RegisterSet registerSet, Keyboard keyboard, S
118112
/* Screen controls */
119113
samControlBits = new UnsignedByte();
120114

115+
/* Device Selector */
116+
deviceSelectorSwitch = new DeviceSelectorSwitch();
117+
121118
/* PIAs */
122-
pia1a = new PIA1a(keyboard);
123-
pia1b = new PIA1b(keyboard);
119+
pia1a = new PIA1a(keyboard, deviceSelectorSwitch);
120+
pia1b = new PIA1b(keyboard, deviceSelectorSwitch);
124121
pia2a = new PIA2a(cassette);
125122
pia2b = new PIA2b(this);
126123

127124
/* Display registers */
128125
verticalOffsetRegister = new UnsignedWord(0x0400);
129126
samDisplayOffsetRegister = new UnsignedByte(0x0);
130127

131-
/* PIAs */
132-
133-
pia2CRA = new UnsignedByte(0);
134-
pia2DRA = new UnsignedByte(0);
135-
pia2DDRA = new UnsignedByte(0);
136-
137-
pia2CRB = new UnsignedByte(0);
138-
pia2DRB = new UnsignedByte(0);
139-
pia2DDRB = new UnsignedByte(0);
140-
141128
/* Interrupts */
142129
irqStatus = new UnsignedByte();
143130
firqStatus = new UnsignedByte();

src/main/java/ca/craigthomas/yacoco3e/components/PIA1a.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
public class PIA1a extends PIA
1313
{
1414
protected Keyboard keyboard;
15+
protected DeviceSelectorSwitch deviceSelectorSwitch;
1516
protected int timerValue;
1617

17-
public PIA1a(Keyboard newKeyboard) {
18+
public PIA1a(Keyboard newKeyboard, DeviceSelectorSwitch newDeviceSelectorSwitch) {
1819
super();
1920
keyboard = newKeyboard;
2021
timerValue = 0;
22+
deviceSelectorSwitch = newDeviceSelectorSwitch;
2123
}
2224

2325
/**
@@ -50,9 +52,19 @@ public void setDataRegister(UnsignedByte newDataRegister) {
5052
*/
5153
@Override
5254
public void setControlRegister(UnsignedByte newControlRegister) {
53-
controlRegister = new UnsignedByte(newControlRegister.getShort() +
55+
controlRegister = new UnsignedByte(
56+
newControlRegister.getShort() +
5457
(controlRegister.isMasked(0x80) ? 0x80 : 0) +
55-
(controlRegister.isMasked(0x40) ? 0x40 : 0));
58+
(controlRegister.isMasked(0x40) ? 0x40 : 0)
59+
);
60+
61+
// Bit 5=1 - CA2 is an output
62+
if (controlRegister.isMasked(0x10)) {
63+
// Bit 4=1 - Output a signal directly on CA2 based on Bit 3 value
64+
if (controlRegister.isMasked(0x8)) {
65+
deviceSelectorSwitch.setCA2(controlRegister.isMasked(0x4));
66+
}
67+
}
5668
}
5769

5870
/**

src/main/java/ca/craigthomas/yacoco3e/components/PIA1b.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
public class PIA1b extends PIA
1313
{
1414
protected Keyboard keyboard;
15+
protected DeviceSelectorSwitch deviceSelectorSwitch;
1516
protected int timerValue;
1617

17-
public PIA1b(Keyboard newKeyboard) {
18+
public PIA1b(Keyboard newKeyboard, DeviceSelectorSwitch newDeviceSelectorSwitch) {
1819
super();
1920
keyboard = newKeyboard;
21+
deviceSelectorSwitch = newDeviceSelectorSwitch;
2022
timerValue = 0;
2123
}
2224

@@ -56,6 +58,14 @@ public void setControlRegister(UnsignedByte newControlRegister) {
5658
(controlRegister.isMasked(0x80) ? 0x80 : 0) +
5759
(controlRegister.isMasked(0x40) ? 0x40 : 0)
5860
);
61+
62+
// Bit 5=1 - CB2 is an output
63+
if (controlRegister.isMasked(0x10)) {
64+
// Bit 4=1 - Output a signal directly on CB2 based on Bit 3 value
65+
if (controlRegister.isMasked(0x8)) {
66+
deviceSelectorSwitch.setCB2(controlRegister.isMasked(0x4));
67+
}
68+
}
5969
}
6070

6171
/**

0 commit comments

Comments
 (0)