Skip to content

Commit 68e4031

Browse files
committed
v2.8
LCD can now read/write DDRAM address (cursor position).
1 parent d5555ba commit 68e4031

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

src/LCD.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public LCD() {
5858
this.setAlwaysOnTop(true);
5959
this.setVisible(false);
6060
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
61+
62+
updateMode();
6163
}
6264

6365
public static void main(String[] args) {
@@ -66,17 +68,30 @@ public static void main(String[] args) {
6668

6769
@SuppressWarnings("resource")
6870
Scanner scan = new Scanner(System.in);
69-
System.out.println("[RS] [data]");
71+
System.out.println("[R/W] [RS] [data]");
7072

7173
while (true) {
7274
String input = scan.nextLine();
7375

74-
boolean rs = input.charAt(0) == '1' ? true : false;
75-
byte data = Byte.parseByte(input.substring(2,10), 2);
76-
77-
System.out.println(rs ? "Data" : "Instruction" + ": 0x" + ROMLoader.byteToHexString(data));
76+
char rw = input.charAt(0);
77+
boolean rs = input.charAt(2) == '1' ? true : false;
7878

79-
lcd.write(rs, data);
79+
if (Character.toUpperCase(rw) == 'W') {
80+
//Write
81+
82+
try {
83+
byte data = (byte)Integer.parseInt(input.substring(4,12), 2);
84+
System.out.println((rs ? "Data" : "Instruction") + ": 0x" + ROMLoader.byteToHexString(data));
85+
lcd.write(rs, data);
86+
} catch (Exception e) {
87+
System.out.println("Error!");
88+
}
89+
90+
} else {
91+
//Read
92+
byte readData = lcd.read(rs);
93+
System.out.println("Read byte 0x" + ROMLoader.byteToHexString(readData));
94+
}
8095
}
8196
}
8297

@@ -105,7 +120,21 @@ public void reset() {
105120
public void write(boolean regSel, byte data) {
106121
if (regSel == false) {
107122
//INSTRUCTION
108-
if ((data & 0b00100000) == 0b00100000) {
123+
if ((data & 0b10000000) == 0b10000000) {
124+
//Set DDRAM Address
125+
int newPos = (data & 0b01111111);
126+
127+
if (newPos >= 0 && newPos < text.length) {
128+
cursorPos = (data & 0b01111111);
129+
} else {
130+
cursorPos = 0;
131+
}
132+
133+
} else if ((data & 0b01000000) == 0b01000000) {
134+
//Set CGRAM Address
135+
System.out.println("LCD: Tried to set CGRAM Address, that is unimplemented!");
136+
137+
} else if ((data & 0b00100000) == 0b00100000) {
109138
//FUNCTION SET
110139
if ((data & 0b00010000) == 0b00010000) {
111140
fourBitMode = false;
@@ -184,13 +213,15 @@ public void write(boolean regSel, byte data) {
184213
}
185214
if (debug)
186215
System.out.println("Cleared!");
216+
} else {
217+
System.out.println("Tried to do invalid instruction "+ROMLoader.byteToHexString(data));
187218
}
188219
} else {
189220
//DATA
190221
text[cursorPos] = (char)data;
191222
int prevCursorPos = cursorPos;
192223
cursorPos += increment ? 1 : -1;
193-
if (cursorPos == text.length) {
224+
if (cursorPos >= text.length) {
194225
cursorPos = 0;
195226
} else if (cursorPos < 0) {
196227
cursorPos = 0;
@@ -202,7 +233,20 @@ public void write(boolean regSel, byte data) {
202233

203234
//Read from LCD
204235
public byte read(boolean regSel) {
205-
return 0x0;
236+
if (debug)
237+
System.out.println("Reading from LCD with regSel"+(regSel ? '1':'0'));
238+
239+
byte retVal = 0;
240+
241+
if (regSel) {
242+
//Read from RAM
243+
retVal = (byte)(text[cursorPos]);
244+
} else {
245+
//Read busy flag and address
246+
retVal = (byte)(127 & cursorPos);
247+
}
248+
249+
return retVal;
206250
}
207251

208252
public class LCDPanel extends JPanel {

src/VIA.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public byte read(short address) {
1111
switch (Short.toUnsignedInt(address)-Bus.VIA_ADDRESS) {
1212
case 0x000:
1313
IFR &= (byte)(0b01100111);
14-
return 0;
14+
PORTB = EaterEmulator.lcd.read((PORTA & 0x20) != 0);
15+
return PORTB;
1516
case 0x001:
1617
IFR &= (byte)(0b01111100);
1718
return 0;
@@ -33,10 +34,13 @@ public void write(short address, byte data) {
3334
switch (Short.toUnsignedInt(address)-Bus.VIA_ADDRESS) {
3435
case 0x000:
3536
PORTB = data;
37+
if ((PORTA&0x80)==0x80 && (PORTA&0x40)==0x00) {
38+
EaterEmulator.lcd.write((PORTA&0x20)==0x20, (byte)(PORTB&DDRB));
39+
}
3640
break;
3741
case 0x001:
3842
PORTA = data;
39-
if ((data&0x80)==0x80) {
43+
if ((PORTA&0x80)==0x80 && (PORTA&0x40)==0x00) {
4044
EaterEmulator.lcd.write((PORTA&0x20)==0x20, (byte)(PORTB&DDRB));
4145
}
4246
break;

0 commit comments

Comments
 (0)