Skip to content

Commit d5555ba

Browse files
committed
2.8
Added 20x4 LCD Support.
1 parent a753e1d commit d5555ba

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed

src/EaterEmulator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import javax.swing.*;
99

1010
public class EaterEmulator extends JFrame implements ActionListener {
11-
public static String versionString = "2.6";
11+
public static String versionString = "2.8";
1212
public static boolean debug = false;
1313

1414
//Swing Things

src/LCD.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ public class LCD extends JFrame implements ActionListener {
1919
Scanner s;
2020

2121
boolean graphicalCursorBlinkFlag = false;
22+
boolean bigMode = false;
2223

2324
boolean debug = false;
25+
26+
int cols = 16;
27+
int rows = 2;
2428

2529
//Internal flags
2630
int cursorPos = 0;
@@ -30,7 +34,7 @@ public class LCD extends JFrame implements ActionListener {
3034
boolean cursorBlink = false;
3135
boolean fourBitMode = false;
3236

33-
char[] text = new char[0x50];
37+
char[] text = new char[80];
3438

3539
public LCD() {
3640
this.setSize(565,185);
@@ -41,7 +45,7 @@ public LCD() {
4145

4246
String s = "";
4347

44-
for (int i = 0; i < 0x50; i++) {
48+
for (int i = 0; i < 80; i++) {
4549
if (i<s.length()) {
4650
text[i] = s.charAt(i);
4751
} else {
@@ -79,7 +83,7 @@ public static void main(String[] args) {
7983
public void reset() {
8084
String s = "";
8185

82-
for (int i = 0; i < 0x50; i++) {
86+
for (int i = 0; i < 80; i++) {
8387
if (i<s.length()) {
8488
text[i] = s.charAt(i);
8589
} else {
@@ -174,8 +178,8 @@ public void write(boolean regSel, byte data) {
174178
} else if (data == 0b00000001) {
175179
//CLEAR
176180
cursorPos = 0;
177-
text = new char[0x50];
178-
for (int i = 0; i < 0x50; i++) {
181+
text = new char[80];
182+
for (int i = 0; i < 80; i++) {
179183
text[i] = ' ';
180184
}
181185
if (debug)
@@ -186,6 +190,11 @@ public void write(boolean regSel, byte data) {
186190
text[cursorPos] = (char)data;
187191
int prevCursorPos = cursorPos;
188192
cursorPos += increment ? 1 : -1;
193+
if (cursorPos == text.length) {
194+
cursorPos = 0;
195+
} else if (cursorPos < 0) {
196+
cursorPos = 0;
197+
}
189198
if (debug)
190199
System.out.println("Data: Wrote "+(char)data+" at "+prevCursorPos);
191200
}
@@ -212,18 +221,22 @@ public void paintComponent(Graphics g) {
212221
g.setColor(Color.getHSBColor(0.62f, 0.83f, 1f));
213222
g.fillRect(0, 0, p.getWidth(), p.getHeight());
214223
g.setColor(Color.getHSBColor(0.62f, 0.87f, 0.78f));
215-
for (int i = 0; i<16; i++) {
216-
for (int j = 0; j<2; j++) {
224+
for (int i = 0; i<rows; i++) {
225+
for (int j = 0; j<cols; j++) {
217226
g.fillRect(12+33*i, 25+50*j, 30, 47);
218227
}
219228
}
229+
230+
int[] rowRemap = {0,2,1,3};
231+
220232
if (displayPower) {
221233
g.setColor(Color.white);
222234
g.setFont(lcdFont);
223-
for (int i = 0; i<16; i++) {
224-
for (int j = 0; j<2; j++) {
225-
g.drawString(String.valueOf(text[i+j*40]), 12+33*i, 70+50*j);
226-
if (i+j*40 == cursorPos) {
235+
for (int i = 0; i<rows; i++) {
236+
for (int j = 0; j<cols; j++) {
237+
g.drawString(String.valueOf(text[rowRemap[j]*rows + i]), 12+33*i, 70+50*j);
238+
239+
if (rowRemap[j]*rows + i == cursorPos) {
227240
if (graphicalCursorBlinkFlag)
228241
g.fillRect(12+33*i, 66+50*j, 30, 5);
229242
}
@@ -250,4 +263,16 @@ public void actionPerformed(ActionEvent arg0) {
250263
}
251264
}
252265
}
266+
267+
public void updateMode() {
268+
if (!bigMode) {
269+
this.rows = 16;
270+
this.cols = 2;
271+
this.setSize(565,185);
272+
} else {
273+
this.rows = 20;
274+
this.cols = 4;
275+
this.setSize(685,275);
276+
}
277+
}
253278
}

src/OptionsData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class OptionsData implements Serializable {
1717
int GPUMode = GPU.gpuMode;
1818
int GPUBitmapPixelScale = GPU.GPUPixelScale;
1919
int keyboardLocation = 0x3fff;
20+
boolean lcdBigMode = false;
2021
Color bgColor = Color.blue;
2122
Color fgColor = Color.white;
2223

@@ -31,6 +32,7 @@ public String toString() {
3132
"GPU Mode: "+GPUMode+"\n"+
3233
"GPU Bitmap Pixel Scale: "+GPUBitmapPixelScale+"\n"+
3334
"Keyboard Memory Location: "+keyboardLocation+"\n"+
35+
"LCD Mode: "+(lcdBigMode ? "20x4" : "16x2")+"\n"+
3436
"Background Color: "+bgColor.toString()+"\n"+
3537
"Foreground Color: "+fgColor.toString()+"\n";
3638
}

src/OptionsPane.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public class OptionsPane extends JFrame implements ActionListener {
5757
JLabel GPUBitmapPixelScaleLabel = new JLabel("GPU Bitmap Pixel Scale: ");
5858
JTextField GPUBitmapPixelScaleTextField = new JTextField(""+data.GPUMode);
5959

60+
JLabel LCDModeLabel = new JLabel("LCD Mode: ");
61+
ButtonGroup lcdModeButtonGroup = new ButtonGroup();
62+
JRadioButton LCDModeRadioSmall = new JRadioButton("16x2");
63+
JRadioButton LCDModeRadioLarge = new JRadioButton("20x4");
64+
6065
JLabel KeyboardLocationLabel = new JLabel("Keyboard Memory Location: ");
6166
JTextField KeyboardLocationTextField = new JTextField(""+data.keyboardLocation);
6267
JLabel KeyboardLocationHexLabel = new JLabel(Integer.toHexString(data.GPUBufferBegin));
@@ -129,6 +134,9 @@ public OptionsPane() {
129134
SwingComponentsList.add(KeyboardLocationLabel);
130135
SwingComponentsList.add(KeyboardLocationTextField);
131136
SwingComponentsList.add(KeyboardLocationHexLabel);
137+
SwingComponentsList.add(LCDModeLabel);
138+
SwingComponentsList.add(LCDModeRadioLarge);
139+
SwingComponentsList.add(LCDModeRadioSmall);
132140

133141
this.setTitle("Options");
134142
this.setContentPane(p);
@@ -148,6 +156,9 @@ public OptionsPane() {
148156
p.add(component);
149157
}
150158

159+
lcdModeButtonGroup.add(LCDModeRadioSmall);
160+
lcdModeButtonGroup.add(LCDModeRadioLarge);
161+
151162
//Swing Positioning
152163
resetSwingPositions();
153164
}
@@ -313,6 +324,9 @@ public void updateSwingComponents() {
313324
GPUBitmapPixelScaleTextField.setText(""+data.GPUBitmapPixelScale);
314325
ForegroundColorChooser.setText("#"+Integer.toHexString(data.fgColor.getRGB()).substring(2));
315326
BackgroundColorChooser.setText("#"+Integer.toHexString(data.bgColor.getRGB()).substring(2));
327+
328+
LCDModeRadioSmall.setSelected(!data.lcdBigMode);
329+
LCDModeRadioLarge.setSelected(data.lcdBigMode);
316330
}
317331

318332
private void writeDataToFile(File f) {
@@ -364,6 +378,10 @@ public void applySwingValues() {
364378

365379
EaterEmulator.fc.setDirectory(data.defaultFileChooserDirectory);
366380
fc.setDirectory(data.defaultFileChooserDirectory);
381+
382+
data.lcdBigMode = LCDModeRadioLarge.isSelected();
383+
EaterEmulator.lcd.bigMode = data.lcdBigMode;
384+
EaterEmulator.lcd.updateMode();
367385
}
368386

369387
private void resetSwingPositions() {
@@ -394,7 +412,7 @@ private void resetSwingPositions() {
394412
GPUModeOptionLabel.setBounds(225,240,75,25);
395413
GPUModeOptionTextField.setBounds(300,240,25,25);
396414

397-
GPUBitmapPixelScaleLabel.setBounds(200,280,100,25);
415+
GPUBitmapPixelScaleLabel.setBounds(150,280,150,25);
398416
GPUBitmapPixelScaleTextField.setBounds(300,280,25,25);
399417

400418
VRAMRangeLabel.setBounds(175,320,300,25);
@@ -405,11 +423,15 @@ private void resetSwingPositions() {
405423
KeyboardLocationTextField.setBounds(300,440,100,25);
406424
KeyboardLocationHexLabel.setBounds(400,440,100,25);
407425

408-
ForegroundColorLabel.setBounds(175,480,125,25);
409-
ForegroundColorChooser.setBounds(300,480,100,25);
426+
LCDModeLabel.setBounds(225,480,75,25);
427+
LCDModeRadioSmall.setBounds(300,480,100,25);
428+
LCDModeRadioLarge.setBounds(400,480,100,25);
429+
430+
ForegroundColorLabel.setBounds(175,520,125,25);
431+
ForegroundColorChooser.setBounds(300,520,100,25);
410432

411-
BackgroundColorLabel.setBounds(175,520,125,25);
412-
BackgroundColorChooser.setBounds(300,520,100,25);
433+
BackgroundColorLabel.setBounds(175,560,125,25);
434+
BackgroundColorChooser.setBounds(300,560,100,25);
413435

414436
applyOptionsButton.setBounds(200,625,150,25);
415437
saveOptionsButton.setBounds(350,625,150,25);

0 commit comments

Comments
 (0)