Skip to content

Commit c39204f

Browse files
authored
Merge pull request #13 from ae6ch/master
Awesome work! Merging "Added ACIA support"
2 parents 0c88844 + 81e47d2 commit c39204f

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed

src/ACIA.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import java.util.Scanner;
2+
3+
public class ACIA {
4+
private byte dataRegister = 0;
5+
private byte commandRegister = 0;
6+
private byte statusRegister =0;
7+
private byte controlRegister = 0;
8+
9+
private Scanner s;
10+
11+
public ACIA() {
12+
s = new Scanner(System.in);
13+
14+
}
15+
16+
/**
17+
* @return theF dataRegister
18+
*/
19+
public byte getDataRegister() {
20+
return dataRegister;
21+
}
22+
23+
/**
24+
* @return the commandRegister
25+
*/
26+
public byte getCommandRegister() {
27+
return commandRegister;
28+
}
29+
30+
/**
31+
* @return the statusRegister
32+
*/
33+
public byte getStatusRegister() {
34+
return statusRegister;
35+
}
36+
37+
/**
38+
* @return the controlRegister
39+
*/
40+
public byte getControlRegister() {
41+
return controlRegister;
42+
}
43+
44+
public byte read(short address) {
45+
46+
switch (Short.toUnsignedInt(address) - Bus.ACIA_ADDRESS) {
47+
case 0x00:
48+
try {
49+
dataRegister = (byte) System.in.read();
50+
if (dataRegister == 0xa) dataRegister = 0xd; //convert \n to \r
51+
52+
} catch (Exception e) {
53+
System.err.println("Error reading from System.in");
54+
}
55+
return dataRegister; // Read Receiver Data Register
56+
case 0x01:
57+
try {
58+
if (System.in.available() >= 1) { // TODO: Remove this later when we go to a windowed interface
59+
statusRegister = 1 << 3;
60+
} else {
61+
statusRegister = 0 << 3;
62+
}
63+
} catch (Exception e) {
64+
System.err.println("Error reading from System.in");
65+
}
66+
return statusRegister; // Read Status Register
67+
case 0x02:
68+
return commandRegister; // Read Command Register
69+
70+
case 0x03:
71+
return controlRegister; // Read Control Register
72+
default:
73+
System.err.printf("Attempted to read from invalid ACIA register: %04x\n", address);
74+
return 0;
75+
76+
}
77+
}
78+
79+
public void write(short address, byte data) {
80+
switch (Short.toUnsignedInt(address) - Bus.ACIA_ADDRESS) {
81+
case 0x00:
82+
System.out.printf("%c", data); // Write Transmitter Data Register
83+
if (data == 0xd) System.out.printf("\n"); // convert \r to \n
84+
85+
case 0x01: // Programmed Reset
86+
// Clear bits 4 through 0 in the Command Register and bit 2 in the Status
87+
// Register
88+
case 0x02:
89+
commandRegister = data;
90+
break; // Write Command Register
91+
case 0x03:
92+
controlRegister = data;
93+
break; // Write Control Register
94+
default:
95+
System.err.printf("Attempted to write to invalid ACIA register: %04x\n", address);
96+
97+
}
98+
}
99+
100+
}

src/Bus.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
public class Bus {
22
public static int VIA_ADDRESS = 0x7ff0;
3+
public static int ACIA_ADDRESS = 0x5000;
34

45
public static byte read(short address) {
56
if (Short.toUnsignedInt(address) >= 0x8000) {
67
return EaterEmulator.rom.read((short)(address-0x8000));
78
} else if (Short.toUnsignedInt(address) <= VIA_ADDRESS+16 && Short.toUnsignedInt(address) >= VIA_ADDRESS) {
89
return EaterEmulator.via.read(address);
10+
} else if (Short.toUnsignedInt(address) <= ACIA_ADDRESS+3 && Short.toUnsignedInt(address) >= ACIA_ADDRESS) {
11+
return EaterEmulator.acia.read(address);
912
} else {
1013
return EaterEmulator.ram.read(address);
1114
}
@@ -16,6 +19,8 @@ public static void write(short address, byte data) {
1619
System.err.println("Can't write to ROM! ("+Integer.toHexString(Short.toUnsignedInt(address)).toUpperCase()+")");
1720
} else if (Short.toUnsignedInt(address) <= VIA_ADDRESS+16 && Short.toUnsignedInt(address) >= VIA_ADDRESS) {
1821
EaterEmulator.via.write(address, data);
22+
} else if (Short.toUnsignedInt(address) <= ACIA_ADDRESS+3 && Short.toUnsignedInt(address) >= ACIA_ADDRESS) {
23+
EaterEmulator.acia.write(address, data);
1924
} else {
2025
EaterEmulator.ram.write(address, data);
2126
}

src/CPU.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public CPU() {
111111
lookup[0xC4] = new Instruction("CPY","ZPP",3);
112112
lookup[0xCC] = new Instruction("CPY","ABS",4);
113113

114+
lookup[0x3A] = new Instruction("DEC","IMP", 2); // NEW for wozmon, need to verify cycles
114115
lookup[0xC6] = new Instruction("DEC","ZPP",5);
115116
lookup[0xD6] = new Instruction("DEC","ZPX",6);
116117
lookup[0xCE] = new Instruction("DEC","ABS",6);
@@ -1019,7 +1020,11 @@ public void CPY() {
10191020
public void DEC() {
10201021
fetch();
10211022
int temp = (Byte.toUnsignedInt(fetched)-1);
1022-
Bus.write(addressAbsolute, (byte)(temp&0x00FF));
1023+
if (lookup[Byte.toUnsignedInt(opcode)].addressMode.equals("IMP")) {
1024+
a = (byte) temp;
1025+
} else {
1026+
Bus.write(addressAbsolute, (byte)(temp&0x00FF));
1027+
}
10231028
setFlag('Z',(temp&0x00FF)==0x0000);
10241029
setFlag('N',(temp&0x0080)==0x0080);
10251030
}

src/DisplayPanel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ public void paintComponent(Graphics g) {
122122
g.drawString(" IFR: "+ROMLoader.padStringWithZeroes(Integer.toBinaryString(Byte.toUnsignedInt(EaterEmulator.via.IFR)), 8)+" ("+ROMLoader.byteToHexString(EaterEmulator.via.IFR)+")", 35, 670);
123123
g.drawString(" IER: "+ROMLoader.padStringWithZeroes(Integer.toBinaryString(Byte.toUnsignedInt(EaterEmulator.via.IER)), 8)+" ("+ROMLoader.byteToHexString(EaterEmulator.via.IER)+")", 35, 700);
124124

125+
//ACIA
126+
g.drawString("ACIA Registers:",350,490);
127+
g.drawString("Data Register: "+ROMLoader.padStringWithZeroes(Integer.toBinaryString(Byte.toUnsignedInt(EaterEmulator.acia.getDataRegister())), 8)+" ("+ROMLoader.byteToHexString(EaterEmulator.acia.getDataRegister())+")", 325, 520);
128+
g.drawString("Command Register: "+ROMLoader.padStringWithZeroes(Integer.toBinaryString(Byte.toUnsignedInt(EaterEmulator.acia.getCommandRegister())), 8)+" ("+ROMLoader.byteToHexString(EaterEmulator.acia.getCommandRegister())+")", 325, 550);
129+
g.drawString("Status Register: "+ROMLoader.padStringWithZeroes(Integer.toBinaryString(Byte.toUnsignedInt(EaterEmulator.acia.getStatusRegister())), 8)+" ("+ROMLoader.byteToHexString(EaterEmulator.acia.getStatusRegister())+")", 325, 580);
130+
g.drawString("Control Register: "+ROMLoader.padStringWithZeroes(Integer.toBinaryString(Byte.toUnsignedInt(EaterEmulator.acia.getControlRegister())), 8)+" ("+ROMLoader.byteToHexString(EaterEmulator.acia.getControlRegister())+")", 325, 610);
131+
132+
125133
//Controls
126134

127135
if (!EaterEmulator.keyboardMode) {

src/EaterEmulator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class EaterEmulator extends JFrame implements ActionListener {
3939
public static ROM rom = new ROM();
4040
public static LCD lcd = new LCD();
4141
public static VIA via = new VIA();
42+
public static ACIA acia = new ACIA();
4243
public static Bus bus = new Bus();
4344
public static CPU cpu = new CPU();
4445
public static GPU gpu = new GPU(ram,false);

0 commit comments

Comments
 (0)