Skip to content

Commit

Permalink
Merge pull request #343 from emustudio/feature-314
Browse files Browse the repository at this point in the history
[#314] Draft of cassette player + zx-spectrum-ula fixes
  • Loading branch information
vbmacher authored Apr 27, 2023
2 parents 69ca42b + ce7aed4 commit 68fb80d
Show file tree
Hide file tree
Showing 224 changed files with 5,212 additions and 3,028 deletions.
8 changes: 6 additions & 2 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ dependencies {
providedRuntime project(":plugins:device:vt100-terminal")
providedRuntime project(":plugins:device:simh-pseudo")
providedRuntime project(":plugins:device:ssem-display")
providedRuntime project(":plugins:device:zxspectrum-display")
providedRuntime project(":plugins:device:zxspectrum-bus")
providedRuntime project(":plugins:device:zxspectrum-ula")
providedRuntime project(":plugins:device:cassette-player")

testImplementation libs.junit
testImplementation libs.easyMock
Expand Down Expand Up @@ -217,7 +219,9 @@ distributions {
from(output(":plugins:device:vt100-terminal"))
from(output(":plugins:device:simh-pseudo"))
from(output(":plugins:device:ssem-display"))
from(output(":plugins:device:zxspectrum-display"))
from(output(":plugins:device:zxspectrum-bus"))
from(output(":plugins:device:zxspectrum-ula"))
from(output(":plugins:device:cassette-player"))
}

// Examples
Expand Down
55 changes: 36 additions & 19 deletions application/src/main/files/config/ZxSpectrum48K.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ZX Spectrum 48K"

[MEMORY]
schemaPoint = "220,60"
schemaPoint = "80,180"
path = "byte-mem.jar"
name = "byte-mem"
id = "1e13a25d-fb23-4061-853a-5fe996b03281"
Expand All @@ -10,15 +10,11 @@ name = "ZX Spectrum 48K"
[MEMORY.settings]
#memorySize = 49152
banksCount = 0
ROMfrom0 = 0
imageName0 = "/home/vbmacher/tmp/emuStudio/z80full.out"
imageName1 = "/home/vbmacher/tmp/emuStudio/examples/zxspectrum-48k/48.rom"
imageAddress1 = 0
imageName0 = "/home/vbmacher/tmp/emuStudio/examples/zxspectrum-48k/48.rom" # TODO: change!
imageBank1 = 0
imageBank0 = 0
commonBoundary = 0
imageAddress0 = 32768
ROMto0 = 16383
imageAddress0 = 0

# memorySize = 65536
# ROM areas are stored as pairs ROMfromN and ROMtoN, where N is 0-based counter. There can be multiple rom areas.
Expand All @@ -42,29 +38,44 @@ name = "ZX Spectrum 48K"
type = "COMPILER"

[CPU]
schemaPoint = "220,180"
schemaPoint = "260,300"
path = "z80-cpu.jar"
settings = {}
name = "z80-cpu"
id = "b86d4bc2-632c-46e3-bba1-c088c9177983"
type = "CPU"

[CPU.settings]
frequency_khz = 3500
frequency_khz = 3500

# Uncomment the following for specific settings (and remove settings = {} above)
# [CPU.settings]
# printCode = true
# printCodeUseCache = true
# printCodeFileName = "syserr" # Or custom path to a file
[[DEVICE]]
schemaPoint = "380,180"
path = "zxspectrum-display.jar"
schemaPoint = "420,60"
path = "zxspectrum-ula.jar"
settings = {}
name = "zxspectrum-display"
name = "zxspectrum-ula"
id = "1436ac2d-982f-4a52-b7c6-ecb6f2a0440d"
type = "DEVICE"

[[DEVICE]]
schemaPoint = "420,180"
path = "cassette-player.jar"
settings = {}
name = "cassette-player"
id = "581cc598-3beb-4a67-b1e3-b4ec1731a9a7"
type = "DEVICE"

[[DEVICE]]
schemaPoint = "260,180"
path = "zxspectrum-bus.jar"
settings = {}
name = "zxspectrum-bus"
id = "c16f6ea4-c26f-4dbf-972b-893c22a0d92c"
type = "DEVICE"

[[connections]]
bidirectional = true
from = "9233e0c2-b53c-41e7-9eca-bbb264fcd9da"
Expand All @@ -74,18 +85,24 @@ name = "ZX Spectrum 48K"
[[connections]]
bidirectional = true
from = "1e13a25d-fb23-4061-853a-5fe996b03281"
to = "b86d4bc2-632c-46e3-bba1-c088c9177983"
to = "c16f6ea4-c26f-4dbf-972b-893c22a0d92c"
points = []

[[connections]]
bidirectional = true
from = "b86d4bc2-632c-46e3-bba1-c088c9177983"
to = "1436ac2d-982f-4a52-b7c6-ecb6f2a0440d"
from = "1436ac2d-982f-4a52-b7c6-ecb6f2a0440d"
to = "c16f6ea4-c26f-4dbf-972b-893c22a0d92c"
points = ["260,60"]

[[connections]]
bidirectional = true
from = "581cc598-3beb-4a67-b1e3-b4ec1731a9a7"
to = "c16f6ea4-c26f-4dbf-972b-893c22a0d92c"
points = []

[[connections]]
bidirectional = true
from = "1e13a25d-fb23-4061-853a-5fe996b03281"
to = "1436ac2d-982f-4a52-b7c6-ecb6f2a0440d"
points = ["360,60"]
from = "c16f6ea4-c26f-4dbf-972b-893c22a0d92c"
to = "b86d4bc2-632c-46e3-bba1-c088c9177983"
points = []

Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
package net.emustudio.application.emulation;

import net.emustudio.application.gui.dialogs.AutoDialog;
import net.emustudio.application.internal.Unchecked;
import net.emustudio.application.settings.AppSettings;
import net.emustudio.application.virtualcomputer.VirtualComputer;
import net.emustudio.emulib.plugins.compiler.Compiler;
import net.emustudio.emulib.plugins.compiler.CompilerListener;
import net.emustudio.emulib.plugins.compiler.CompilerMessage;
import net.emustudio.emulib.plugins.cpu.CPU;
import net.emustudio.emulib.plugins.device.Device;
import net.emustudio.emulib.runtime.helpers.Unchecked;
import net.emustudio.emulib.runtime.interaction.Dialogs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -35,6 +35,7 @@
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

/**
* This class manages the emuStudio automation process. In the process
Expand Down Expand Up @@ -97,7 +98,6 @@ public void run() {
computer.getCPU().ifPresent(cpu -> LOGGER.info("CPU: " + cpu.getTitle() + ", version " + cpu.getVersion()));
computer.getMemory().ifPresent(memory -> {
LOGGER.info("Memory: " + memory.getTitle() + ", version " + memory.getVersion());
LOGGER.info("Memory size: {}", memory.getSize());
});
computer.getDevices().forEach(
device -> LOGGER.info("Device: " + device.getTitle() + ", version " + device.getVersion())
Expand Down Expand Up @@ -139,6 +139,7 @@ private void autoCompile(Compiler compiler) throws AutomationException {
return;
}
setProgress("Compiling input file: " + inputFile, false);
AtomicInteger errors = new AtomicInteger();
CompilerListener reporter = new CompilerListener() {
@Override
public void onStart() {
Expand All @@ -150,6 +151,7 @@ public void onMessage(CompilerMessage message) {

switch (message.getMessageType()) {
case TYPE_ERROR:
errors.incrementAndGet();
LOGGER.error(message.getFormattedMessage());
break;
case TYPE_WARNING:
Expand All @@ -169,10 +171,10 @@ public void onFinish() {

// Initialize compiler
compiler.addCompilerListener(reporter);
compiler.compile(inputFile.toPath(), Optional.empty());

String fileName = inputFile.getAbsolutePath();
if (!compiler.compile(fileName)) {
throw new AutomationException("Compile failed. Automation cannot continue.");
if (errors.get() > 0) {
throw new AutomationException("Compilation failed. Automation cannot continue.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,26 @@ public Optional<Path> chooseFile(String title, String approveButtonText, Path ba
title, approveButtonText, baseDirectory, appendMissingExtension, filters.toArray(FileExtensionsFilter[]::new)
);
}

@Override
public Optional<Path> chooseDirectory(String title, String approveButtonText) {
return chooseDirectory(title, approveButtonText, Path.of(System.getProperty("user.dir")));
}

@Override
public Optional<Path> chooseDirectory(String title, String approveButtonText, Path baseDirectory) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle(title);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setApproveButtonText(approveButtonText);
fileChooser.setCurrentDirectory(baseDirectory.toFile());
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

int result = fileChooser.showOpenDialog(parent);
fileChooser.setVisible(true);
if (result == JFileChooser.APPROVE_OPTION) {
return Optional.ofNullable(fileChooser.getSelectedFile()).map(File::toPath);
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,14 @@ public Optional<Path> chooseFile(String title, String approveButtonText, Path ba
boolean appendMissingExtension, List<FileExtensionsFilter> list) {
return Optional.empty();
}

@Override
public Optional<Path> chooseDirectory(String title, String approveButtonText) {
return Optional.empty();
}

@Override
public Optional<Path> chooseDirectory(String title, String approveButtonText, Path baseDirectory) {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;

public class CompileAction extends AbstractAction {
Expand Down Expand Up @@ -71,7 +72,7 @@ public void onStart() {
@Override
public void onMessage(CompilerMessage message) {
compilerOutput.append(message.getFormattedMessage() + "\n");
editor.setPosition(message.getLine(), message.getColumn());
message.getPosition().ifPresent(editor::setPosition);
}

@Override
Expand All @@ -94,7 +95,7 @@ public void actionPerformed(ActionEvent actionEvent) {

try {
computer.getMemory().ifPresent(Memory::reset);
compiler.compile(file.getAbsolutePath());
compiler.compile(file.toPath(), Optional.empty());
computer.getCPU().ifPresent(Plugin::reset);
} catch (Exception e) {
compilerOutput.append("Could not compile file: " + e + "\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package net.emustudio.application.gui.actions.emulator;

import net.emustudio.application.virtualcomputer.VirtualComputer;
import net.emustudio.emulib.plugins.memory.Memory;
import net.emustudio.emulib.runtime.interaction.Dialogs;

import javax.swing.*;
Expand Down Expand Up @@ -48,9 +47,7 @@ public void actionPerformed(ActionEvent actionEvent) {
.readInteger("Memory address:", "Jump to address", 0)
.ifPresent(address -> {
if (!cpu.setInstructionLocation(address)) {
int memorySize = computer.getMemory().map(Memory::getSize).orElse(0);
String maxSizeMessage = (memorySize == 0) ? "" : "(probably accepts range from 0 to " + memorySize + ")";
dialogs.showError("Invalid memory address" + maxSizeMessage);
dialogs.showError("Invalid memory address (please check memory size)");
} else {
refreshDebugTable.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import net.emustudio.application.gui.dialogs.SchemaEditorDialog;
import net.emustudio.application.gui.schema.Schema;
import net.emustudio.application.internal.Unchecked;
import net.emustudio.application.settings.AppSettings;
import net.emustudio.application.settings.ComputerConfig;
import net.emustudio.emulib.runtime.helpers.Unchecked;
import net.emustudio.emulib.runtime.interaction.Dialogs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
import java.util.*;
import java.util.function.Consumer;

/**
* Call flow.
* <p>
* Directed set of graphs, possibly with cycles.
*/
@ThreadSafe
class CallFlow {
private final static Logger LOGGER = LoggerFactory.getLogger(CallFlow.class);

private final Disassembler disassembler;
private final NavigableMap<Integer, Integer> flowGraph = new TreeMap<>();
private final NavigableMap<Integer, Integer> flowGraph = new TreeMap<>(); // location -> next location
private int longestInstructionSize = 1;

CallFlow(Disassembler disassembler) {
Expand Down
Loading

0 comments on commit 68fb80d

Please sign in to comment.