From 7501d003a55e39e9b505948a31d048a713e87893 Mon Sep 17 00:00:00 2001 From: Peter Jakubco Date: Wed, 1 Feb 2023 10:10:55 +0100 Subject: [PATCH] [#314] zx-spectrum48k: border + background color --- .../device/zxspectrum/display/ULA.java | 17 +++---- .../zxspectrum/display/gui/DisplayCanvas.java | 44 +++++++++++-------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/ULA.java b/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/ULA.java index af762c6c1..5fd7b1fd9 100644 --- a/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/ULA.java +++ b/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/ULA.java @@ -34,7 +34,7 @@ * *

* OUT: - * Bit 7 6 5 4 3 2 1 0 + * 7 6 5 4 3 2 1 0 * +-------------------------------+ * | | | | E | M | Border | * +-------------------------------+ @@ -49,7 +49,7 @@ * top to bottom. * Each attribute byte colours an 8x8 character on the screen and is encoded as follows: *

- * Bit 7 6 5 4 3 2 1 0 + * 7 6 5 4 3 2 1 0 * +-------------------------------+ * | F | B | P2| P1| P0| I2| I1| I0| * +-------------------------------+ @@ -75,8 +75,7 @@ public class ULA implements Context8080.CpuPortDevice, Keyboard.OnKeyListener { private final Context8080 cpu; private int borderColor; - private boolean microphone; - private boolean ear; + private boolean microphoneAndEar; private static int[] computeLineStartOffsets() { final int[] result = new int[SCREEN_HEIGHT]; @@ -114,8 +113,7 @@ public void readScreen() { public void reset() { borderColor = 7; - microphone = false; - ear = true; + microphoneAndEar = false; Arrays.fill(keymap, (byte) 0xBF); } @@ -128,7 +126,7 @@ public byte read(int portAddress) { // A zero in one of the five lowest bits means that the corresponding key is pressed. // If more than one address line is made low, the result is the logical AND of all single inputs - byte result = (byte)0xBF; + byte result = (byte) 0xBF; if ((portAddress & 0xFEFE) == 0xFEFE) { // SHIFT, Z, X, C, V result &= keymap[0]; @@ -154,7 +152,7 @@ public byte read(int portAddress) { // SPACE, SYM SHFT, M, N, B result &= keymap[7]; } - if (!ear) { + if (!microphoneAndEar) { result |= 0x40; } return result; @@ -165,8 +163,7 @@ public void write(int portAddress, byte data) { this.borderColor = data & 7; if (((data & 0x10) == 0x10) || ((data & 0x8) == 0)) { // the EAR and MIC sockets are connected only by resistors, so activating one activates the other - microphone = true; - ear = true; + microphoneAndEar = true; } } diff --git a/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/DisplayCanvas.java b/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/DisplayCanvas.java index c3e24f06b..683c9dfb6 100644 --- a/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/DisplayCanvas.java +++ b/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/DisplayCanvas.java @@ -36,16 +36,17 @@ public class DisplayCanvas extends Canvas implements AutoCloseable { // a 3.5MHz/69888=50.08 Hz interrupt private static final int REPAINT_CPU_TSTATES = 69888; - private static final int BORDER_WIDHT = 48; // pixels + private static final int BORDER_WIDTH = 48; // pixels + private static final int BORDER_HEIGHT = 56; // pixels private static final int X_GAP = 48; // pixels private static final int Y_GAP = 48; // pixels private static final Color FOREGROUND = new Color(255, 255, 255); private static final Color BACKGROUND = new Color(0xAA, 0xAA, 0xAA); - private static final Color[] COLOR_MAP = new Color[] { - new Color(0,0 ,0), // black - new Color(0,0, 0xEE), // blue + private static final Color[] COLOR_MAP = new Color[]{ + new Color(0, 0, 0), // black + new Color(0, 0, 0xEE), // blue new Color(0xEE, 0, 0), // red new Color(0xEE, 0, 0xEE), // magenta new Color(0, 0xEE, 0), // green @@ -54,9 +55,9 @@ public class DisplayCanvas extends Canvas implements AutoCloseable { new Color(0xEE, 0xEE, 0xEE) // white }; - private static final Color[] BRIGHT_COLOR_MAP = new Color[] { - new Color(0,0 ,0), // black - new Color(0,0, 0xFF), // blue + private static final Color[] BRIGHT_COLOR_MAP = new Color[]{ + new Color(0, 0, 0), // black + new Color(0, 0, 0xFF), // blue new Color(0xFF, 0, 0), // red new Color(0xFF, 0, 0xFF), // magenta new Color(0, 0xFF, 0), // green @@ -154,28 +155,33 @@ protected void paint() { byte[][] videoMemory = ula.videoMemory; byte[][] attrMemory = ula.attributeMemory; - // border - - + graphics.setBackground(COLOR_MAP[ula.getBorderColor()]); + graphics.setColor(COLOR_MAP[ula.getBorderColor()]); + graphics.fillRect( + X_GAP, Y_GAP, + 2*(BORDER_WIDTH + SCREEN_WIDTH*8 + BORDER_WIDTH), + 2*(SCREEN_HEIGHT + 2*BORDER_HEIGHT) + ); int screenX = 0; for (int y = 0; y < SCREEN_HEIGHT; y++) { for (int x = 0; x < SCREEN_WIDTH; x++) { byte row = videoMemory[x][y]; - int attr = attrMemory[x][y/8]; + int attr = attrMemory[x][y / 8]; Color[] colorMap = ((attr & 0x40) == 0x40) ? BRIGHT_COLOR_MAP : COLOR_MAP; - graphics.setBackground(colorMap[(attr >>> 3) & 7]); - graphics.setColor(colorMap[attr & 7]); for (int i = 0; i < 8; i++) { boolean bit = ((row << i) & 0x80) == 0x80; if (bit) { - graphics.drawLine( - 2*(X_GAP + BORDER_WIDHT) + 2*screenX + 2*i, 2*Y_GAP + 2*y, - 2*(X_GAP + BORDER_WIDHT) + 2*screenX + 2*i + 1, 2*Y_GAP + 2*y); - graphics.drawLine( - 2*(X_GAP + BORDER_WIDHT) + 2*screenX + 2*i, 2*Y_GAP + 2*y + 1, - 2*(X_GAP + BORDER_WIDHT) + 2*screenX + 2*i + 1, 2*Y_GAP + 2*y + 1); + graphics.setColor(colorMap[attr & 7]); + } else { + graphics.setColor(colorMap[(attr >>> 3) & 7]); } + graphics.drawLine( + X_GAP + 2 * (BORDER_WIDTH + screenX + i), Y_GAP + 2 * (BORDER_HEIGHT + y), + X_GAP + 2 * (BORDER_WIDTH + screenX + i) + 1, Y_GAP + 2 * (BORDER_HEIGHT + y)); + graphics.drawLine( + X_GAP + 2 * (BORDER_WIDTH + screenX + i), Y_GAP + 2 * (BORDER_HEIGHT + y) + 1, + X_GAP + 2 * (BORDER_WIDTH + screenX + i) + 1, Y_GAP + 2 * (BORDER_HEIGHT + y) + 1); } screenX += 8; }