-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
177 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...m-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/PassedCyclesMediator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* This file is part of emuStudio. | ||
* | ||
* Copyright (C) 2006-2024 Peter Jakubčo | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package net.emustudio.plugins.device.zxspectrum.ula; | ||
|
||
import net.emustudio.emulib.plugins.cpu.CPUContext; | ||
import net.emustudio.plugins.device.zxspectrum.ula.gui.DisplayCanvas; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static net.emustudio.plugins.device.zxspectrum.ula.ZxParameters.*; | ||
|
||
/** | ||
* Triggers actions based on passed CPU cycles. | ||
* <p> | ||
* For <a href="https://worldofspectrum.org/faq/reference/48kreference.htm">ZX Spectrum 48K</a> the actions are: | ||
* <p> | ||
* - 0: CPU interrupt | ||
* - 0 - 14336: first 64 lines. From those, at least 48 are border-lines, others are either border or vertical retraces | ||
* After an interrupt occurs, 64 line times (14336 T states; see below for exact timings) pass before | ||
* - 14337 - 57344: 192 screen lines are displayed | ||
* - 57345 - 69888: 56 border-lines are displayed | ||
* <p> | ||
* This means a frame is (64+192+56)*224=69888 T states long, which means that the CPU interrupt occurs | ||
* at 3.5MHz/69888=50.08 Hz. | ||
*/ | ||
public class PassedCyclesMediator implements CPUContext.PassedCyclesListener { | ||
private static final long LINE_CYCLES = 224; | ||
private static final long FRAME_CYCLES = (PRE_SCREEN_LINES + SCREEN_HEIGHT + POST_SCREEN_LINES) * LINE_CYCLES; // 69888; | ||
|
||
private long frameCycles = 0; | ||
private long lineCycles = 0; | ||
private int lastLinePainted = 0; | ||
|
||
private final AtomicReference<DisplayCanvas> canvas = new AtomicReference<>(); | ||
private final ULA ula; | ||
|
||
public PassedCyclesMediator(ULA ula) { | ||
this.ula = Objects.requireNonNull(ula); | ||
} | ||
|
||
public void setCanvas(DisplayCanvas canvas) { | ||
this.canvas.set(canvas); | ||
} | ||
|
||
@Override | ||
public void passedCycles(long cycles) { | ||
frameCycles += cycles; | ||
lineCycles += cycles; | ||
|
||
DisplayCanvas canvas = this.canvas.get(); | ||
if (canvas != null) { | ||
if (lineCycles >= LINE_CYCLES) { | ||
canvas.drawNextLine(lastLinePainted++); | ||
} | ||
} | ||
lineCycles = lineCycles % LINE_CYCLES; | ||
if (frameCycles >= FRAME_CYCLES) { | ||
lastLinePainted = 0; | ||
ula.onNextFrame(); | ||
frameCycles = frameCycles % FRAME_CYCLES; | ||
if (canvas != null) { | ||
canvas.runPaintCycle(); // expensive operation | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...xspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/ZxParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This file is part of emuStudio. | ||
* | ||
* Copyright (C) 2006-2024 Peter Jakubčo | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package net.emustudio.plugins.device.zxspectrum.ula; | ||
|
||
public class ZxParameters { | ||
public static final int SCREEN_WIDTH = 32; // in bytes; each byte represents 8 pixels in a row, reversed | ||
public static final int SCREEN_HEIGHT = 192; | ||
public static final int ATTRIBUTE_HEIGHT = SCREEN_HEIGHT / 8; | ||
|
||
public static final int PRE_SCREEN_LINES = 64; | ||
public static final int POST_SCREEN_LINES = 56; | ||
public static final int BORDER_WIDTH = 48; // pixels | ||
|
||
public static final int SCREEN_IMAGE_WIDTH = 2 * BORDER_WIDTH + SCREEN_WIDTH * 8; | ||
public static final int SCREEN_IMAGE_HEIGHT = PRE_SCREEN_LINES + SCREEN_HEIGHT + POST_SCREEN_LINES; | ||
|
||
// The Spectrum's 'FLASH' effect is also produced by the ULA: Every 16 frames, the ink and paper of all flashing | ||
// bytes is swapped; ie a normal to inverted to normal cycle takes 32 frames, which is (good as) 0.64 seconds. | ||
public static final int VIDEO_FLASH_FRAME = 15; | ||
} |
Oops, something went wrong.