From d75b886fc28a18abed8af6fe221e96e989193074 Mon Sep 17 00:00:00 2001 From: Peter Jakubco Date: Wed, 1 Feb 2023 10:25:16 +0100 Subject: [PATCH] [#314] zx-spectrum48K: fix display size --- .../plugins/cpu/zilogZ80/EmulatorEngine.java | 1 + .../zxspectrum/display/gui/DisplayCanvas.java | 38 +++++++------------ .../display/gui/TerminalWindow.java | 4 +- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/plugins/cpu/z80-cpu/src/main/java/net/emustudio/plugins/cpu/zilogZ80/EmulatorEngine.java b/plugins/cpu/z80-cpu/src/main/java/net/emustudio/plugins/cpu/zilogZ80/EmulatorEngine.java index b9230b612..2f25ece7e 100644 --- a/plugins/cpu/z80-cpu/src/main/java/net/emustudio/plugins/cpu/zilogZ80/EmulatorEngine.java +++ b/plugins/cpu/z80-cpu/src/main/java/net/emustudio/plugins/cpu/zilogZ80/EmulatorEngine.java @@ -2118,6 +2118,7 @@ int I_ADD_A_REF_IY_N() { } int I_ADD_A_REF_II_N(int special) { + // TODO: BUG byte disp = memory.read(PC); PC = (PC + 1) & 0xFFFF; int address = (special + disp) & 0xFFFF; 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 683c9dfb6..757e47353 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 @@ -32,17 +32,15 @@ // https://worldofspectrum.org/faq/reference/48kreference.htm public class DisplayCanvas extends Canvas implements AutoCloseable { - // a frame is (64+192+56)*224=69888 T states long, which means that the '50 Hz' interrupt is actually - // a 3.5MHz/69888=50.08 Hz interrupt - private static final int REPAINT_CPU_TSTATES = 69888; - 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); + public final static int HOST_SCREEN_WIDTH = 2 * (2 * BORDER_WIDTH + SCREEN_WIDTH * 8); + public final static int HOST_SCREEN_HEIGHT = 2 * (2 * BORDER_HEIGHT + SCREEN_HEIGHT); + + // a frame is (64+192+56)*224=69888 T states long, which means that the '50 Hz' interrupt is actually + // a 3.5MHz/69888=50.08 Hz interrupt + private static final int REPAINT_CPU_TSTATES = 69888; private static final Color[] COLOR_MAP = new Color[]{ new Color(0, 0, 0), // black @@ -75,12 +73,6 @@ public class DisplayCanvas extends Canvas implements AutoCloseable { public DisplayCanvas(ULA ula) { this.ula = Objects.requireNonNull(ula); - - setForeground(FOREGROUND); - setBackground(BACKGROUND); - Font textFont = new Font("Monospaced", Font.PLAIN, 14); - setFont(textFont); - this.ted = ula.getCpu() .getTimedEventsProcessor() .orElseThrow(() -> new NoSuchElementException("The CPU does not provide TimedEventProcessor")); @@ -139,7 +131,6 @@ public void run() { } protected void paint() { - Dimension dimension = size; // The buffers in a buffer strategy are usually type VolatileImage, they may become lost. // VolatileImage differs from other Image variants in that if possible, VolatileImage is stored in // Video RAM. This means that instead of keeping the image in the system memory with everything else, @@ -148,19 +139,16 @@ protected void paint() { do { do { Graphics2D graphics = (Graphics2D) strategy.getDrawGraphics(); - graphics.setColor(BACKGROUND); - graphics.fillRect(0, 0, dimension.width, dimension.height); - graphics.setColor(FOREGROUND); byte[][] videoMemory = ula.videoMemory; byte[][] attrMemory = ula.attributeMemory; 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) + 0, 0, + 2 * (2 * BORDER_WIDTH + SCREEN_WIDTH * 8), + 2 * (2 * BORDER_HEIGHT + SCREEN_HEIGHT) ); int screenX = 0; for (int y = 0; y < SCREEN_HEIGHT; y++) { @@ -177,11 +165,11 @@ protected void paint() { 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)); + 2 * (BORDER_WIDTH + screenX + i), 2 * (BORDER_HEIGHT + y), + 2 * (BORDER_WIDTH + screenX + i) + 1, 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); + 2 * (BORDER_WIDTH + screenX + i), 2 * (BORDER_HEIGHT + y) + 1, + 2 * (BORDER_WIDTH + screenX + i) + 1, 2 * (BORDER_HEIGHT + y) + 1); } screenX += 8; } diff --git a/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/TerminalWindow.java b/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/TerminalWindow.java index a63475ed5..0cfeb7715 100644 --- a/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/TerminalWindow.java +++ b/plugins/device/zxspectrum-display/src/main/java/net/emustudio/plugins/device/zxspectrum/display/gui/TerminalWindow.java @@ -44,7 +44,7 @@ private void initComponents() { setTitle("ZX Spectrum48K"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - canvas.setBounds(0, 0, 900, 700); + canvas.setBounds(0, 0, DisplayCanvas.HOST_SCREEN_WIDTH, DisplayCanvas.HOST_SCREEN_HEIGHT); btnRedraw.setFocusable(false); @@ -55,7 +55,7 @@ private void initComponents() { .addGroup(panelStatusLayout.createSequentialGroup() .addContainerGap() .addComponent(btnRedraw, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap(900, Short.MAX_VALUE)) + .addContainerGap()) ); panelStatusLayout.setVerticalGroup( panelStatusLayout.createParallelGroup(GroupLayout.Alignment.LEADING)