Skip to content

Commit

Permalink
[#314] zx-spectrum48K: fix display size
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmacher committed Feb 1, 2023
1 parent 7501d00 commit d75b886
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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,
Expand All @@ -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++) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down

0 comments on commit d75b886

Please sign in to comment.