diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b99fbe3..f5fdc5a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -34,12 +34,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - # Install and setup JDK 17 - - name: Setup JDK 17 + # Install and setup JDK 25 + - name: Setup JDK 25 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: '17' + java-version: '25' # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL @@ -56,16 +56,17 @@ jobs: - name: Autobuild uses: github/codeql-action/autobuild@v4 - # ℹ️ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v4 - # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - #- run: | - # make bootstrap - # make release + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4 diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 9d524dd..6ca59b1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -16,11 +16,11 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 25 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: '17' + java-version: '25' - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle diff --git a/README.md b/README.md index 7d11fa9..60e3cee 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The build may take a few minutes as it includes a comprehensive test suite for t ## Java Version -Version 4.0.0 onwards of the emulator require Java 17 or above +Version 5.0.0 onwards of the emulator require Java 25 or above ### Include Using Maven @@ -39,7 +39,7 @@ Version 4.0.0 onwards of the emulator require Java 17 or above com.codingrodent.microprocessor Z80Processor - 4.2.0 + 5.0.0 ``` @@ -47,7 +47,7 @@ Version 4.0.0 onwards of the emulator require Java 17 or above ``` // https://mvnrepository.com/artifact/com.codingrodent.microprocessor/Z80Processor -compile group: 'com.codingrodent.microprocessor', name: 'Z80Processor', version: '4.2.0' +compile group: 'com.codingrodent.microprocessor', name: 'Z80Processor', version: '5.0.0' ``` ## Undocumented instruction diff --git a/build.gradle b/build.gradle index dd1aaeb..b59c882 100644 --- a/build.gradle +++ b/build.gradle @@ -1,53 +1,57 @@ +import com.github.spotbugs.snom.Effort + + buildscript { repositories { mavenCentral() mavenLocal() maven { - url "https://plugins.gradle.org/m2/" + url = "http://localhost:8081/artifactory/libs-release-local" + allowInsecureProtocol = true + credentials { + username = "${artifactory_user}" + password = "${artifactory_password}" + } } } + dependencies { //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory - classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '4.+') + classpath("org.jfrog.buildinfo:build-info-extractor-gradle:6.+") } } plugins { - id "com.github.spotbugs" version "5.0.12" + id "com.github.spotbugs" version "6.2.5" id 'java' id 'idea' id 'maven-publish' id 'jacoco' + id "com.jfrog.artifactory" version "6.+" id 'signing' } -apply plugin: 'com.jfrog.artifactory' - // set the java version java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 withJavadocJar() withSourcesJar() } group = 'com.codingrodent.microprocessor' -task setVersion { - if (System.env.BUILD_NUMBER) { - version = projectVersionMajor + '.' + projectVersionMinor + '.' + System.env.BUILD_NUMBER - } else { - version = projectVersionMajor + '.' + projectVersionMinor + '.' + projectVersionBuild - } -} - +def buildNum = System.getenv("BUILD_NUMBER") +version = buildNum + ? "${projectVersionMajor}.${projectVersionMinor}.${buildNum}" + : "${projectVersionMajor}.${projectVersionMinor}.${projectVersionBuild}" jar { - baseName = projectName + archiveBaseName = projectName manifest { attributes 'Implementation-Title': projectName, - 'Implementation-Version': version + 'Implementation-Version': archiveVersion } } @@ -55,18 +59,12 @@ javadoc { options.addBooleanOption('html5', true) } - -artifacts { - archives sourcesJar - archives javadocJar -} - repositories { mavenCentral() } jacoco { - toolVersion = "0.8.8" + toolVersion = "0.8.14" } test { @@ -77,53 +75,84 @@ test { includeTestsMatching "com.codingrodent.microprocessor.*" } jacoco { - destinationFile = file("$buildDir/jacoco/jacocoTest.exec") - classDumpDir = file("$buildDir/jacoco/classpathdumps") + destinationFile = layout.buildDirectory.file("jacoco/jacocoTest.exec").get().asFile + classDumpDir = layout.buildDirectory.dir("jacoco/classpathdumps").get().asFile } } jacocoTestReport { reports { - xml.enabled true - csv.enabled false - html.destination file("${buildDir}/jacocoHtml") + xml.required = true + csv.required = false + html.outputLocation = layout.buildDirectory.dir("jacocoHtml") } } - spotbugs { - toolVersion = '4.7.2' + toolVersion = "4.9.8" ignoreFailures = false - effort = 'max' + showProgress = true + effort = Effort.MAX + // reportLevel = Confidence.HIGH + excludeFilter = file("$rootProject.projectDir/excludeFilter.xml") } +spotbugsMain { + reports.create("html") { + required = true + } +} + +artifactory { + contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver + publish { + repository { + repoKey = 'libs-release-local' + username = "${artifactory_user}" + password = "${artifactory_password}" + } + defaults { + // Reference to Gradle publications defined in the build script. + // This is how we tell the Artifactory Plugin which artifacts should be + // published to Artifactory. + publications('mavenJava') + publishArtifacts = true + // Properties to be attached to the published artifacts. + properties = ['qa.level': 'basic', 'dev.team': 'core'] + // Publish generated POM files to Artifactory (true by default) + publishPom = true + } + } +} + + publishing { publications { mavenJava(MavenPublication) { from components.java pom { - artifactId= 'Z80Processor' - groupId= 'com.codingrodent.microprocessor' - name= 'com.codingrodent.microprocessor.Z80Processor' - description= 'A Z80 Microprocessor core in Java' - url= 'https://github.com/codesqueak/Z80Processor' + artifactId = 'Z80Processor' + groupId = 'com.codingrodent.microprocessor' + name = 'com.codingrodent.microprocessor.Z80Processor' + description = 'A Z80 Microprocessor core in Java' + url = 'https://github.com/codesqueak/Z80Processor' scm { - url= 'https://github.com/codesqueak/Z80Processor' - connection= 'scm:git:git://github.com/codesqueak/Z80Processor.git' - developerConnection= 'scm:git:ssh://github.com:codesqueak/Z80Processor.git' + url = 'https://github.com/codesqueak/Z80Processor' + connection = 'scm:git:git://github.com/codesqueak/Z80Processor.git' + developerConnection = 'scm:git:ssh://github.com:codesqueak/Z80Processor.git' } licenses { license { - name= 'The Apache Software License, Version 2.0' - url= 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution ='repo' + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution = 'repo' } } developers { developer { - id= 'codesqueak' - name= 'codesqueak' - organizationUrl ='http://www.codesqueak.com' + id = 'codesqueak' + name = 'codesqueak' + organizationUrl = 'http://www.codesqueak.com' // organization 'codesqueak' } } @@ -136,44 +165,19 @@ signing { sign(publishing.publications["mavenJava"]) } - -artifactory { - contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver - publish { - repository { - repoKey = 'gradle-dev-local' - username = "${artifactory_user}" - password = "${artifactory_password}" - maven = true - - } - defaults { - // Reference to Gradle publications defined in the build script. - // This is how we tell the Artifactory Plugin which artifacts should be - // published to Artifactory. - publications('mavenJava') - publishArtifacts = true - // Properties to be attached to the published artifacts. - properties = ['qa.level': 'basic', 'dev.team': 'core'] - // Publish generated POM files to Artifactory (true by default) - publishPom = true - } - } -} - // check.dependsOn jacocoTestReport dependencies { - implementation group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: '4.7.2' + implementation("com.github.spotbugs:spotbugs-annotations:4.9.8") // - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.1' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.9.1' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.8.0' - testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2' + testImplementation("org.junit.jupiter:junit-jupiter-api:6.0.1") + testImplementation("org.junit.jupiter:junit-jupiter-engine:6.0.1") + testImplementation("org.junit.platform:junit-platform-launcher:6.0.1") + testImplementation("org.mockito:mockito-core:5.20.0") + testImplementation("org.hamcrest:hamcrest:3.0") } - wrapper { - gradleVersion = '7.5.1' + gradleVersion = '9.2.1' distributionType = Wrapper.DistributionType.BIN } diff --git a/excludeFilter.xml b/excludeFilter.xml new file mode 100644 index 0000000..37ae27c --- /dev/null +++ b/excludeFilter.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/gradle.properties b/gradle.properties index 1d0d19d..e8f9e30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ # projectName=Z80Processor # -projectVersionMajor=4 -projectVersionMinor=2 +projectVersionMajor=5 +projectVersionMinor=0 projectVersionBuild=0 # artifactory_user=admin artifactory_password=secret -artifactory_contextUrl=http://localhost:9081/artifactory +artifactory_contextUrl=http://localhost:8081/artifactory diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..f8e1ee3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..23449a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..adff685 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -133,22 +132,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -165,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,32 +59,33 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/notes.md b/notes.md index 4a50778..b803d7d 100644 --- a/notes.md +++ b/notes.md @@ -16,11 +16,39 @@ The following field are required in the gradle.properties To see your key, `use gpg -k` +You will; need to generate a key ring + +`gpg --export-secret-keys >~/.gnupg/secring.gpg` + +You will also need the short form of the key id + +`gpg --list-keys --keyid-format short` + + +`signing.password=` +`signing.secretKeyRingFile=/home/wherever/.gnupg/secring.gpg` +`signing.keyId=>` +` + + ## Make a bundle example: -jar -cvf bundle.jar Z80Processor-4.1.0-javadoc.jar Z80Processor-4.1.0-javadoc.jar.asc Z80Processor-4.1.0-sources.jar Z80Processor-4.1.0-sources.jar.asc Z80Processor-4.1.0.jar Z80Processor-4.1.0.jar.asc Z80Processor-4.1.0.module Z80Processor-4.1.0.module.asc Z80Processor-4.1.0.pom Z80Processor-4.1.0.pom.asc +sign your files first + +`gpg -ab Z80Processor-5.0.0.jar` +`gpg -ab Z80Processor-5.0.0-javadoc.jar` +`gpg -ab Z80Processor-5.0.0.module` +`gpg -ab Z80Processor-5.0.0.pom` +`gpg -ab Z80Processor-5.0.0-sources.jar` + +Then generate Invalid sha1 and md5 files for each + +then zip + +The files should be in the sub-directory com/codingrodent/microprocessor/Z80Processor/5.0.0/ + # Manual Publish Bundle diff --git a/src/main/java/com/codingrodent/microprocessor/IBaseDevice.java b/src/main/java/com/codingrodent/microprocessor/IBaseDevice.java index 0c6e516..1cad05b 100644 --- a/src/main/java/com/codingrodent/microprocessor/IBaseDevice.java +++ b/src/main/java/com/codingrodent/microprocessor/IBaseDevice.java @@ -22,7 +22,7 @@ public interface IBaseDevice { /** * Read data from an I/O port * - * @param address The address contains the full 16 bit address + * @param address The address contains the full 16-bit address * The port to be read from is contained in the lower 8 bits * @return The 8 bit value at the request port address */ @@ -33,7 +33,7 @@ default int IORead(int address) { /** * Write data to an I/O port * - * @param address The address contains the full 16 bit address + * @param address The address contains the full 16-bit address * The port to be read from is contained in the lower 8 bits * @param data The 8 bit value to be written */ diff --git a/src/main/java/com/codingrodent/microprocessor/Z80/CPUConstants.java b/src/main/java/com/codingrodent/microprocessor/z80/CPUConstants.java similarity index 99% rename from src/main/java/com/codingrodent/microprocessor/Z80/CPUConstants.java rename to src/main/java/com/codingrodent/microprocessor/z80/CPUConstants.java index 14bd89d..503a91e 100644 --- a/src/main/java/com/codingrodent/microprocessor/Z80/CPUConstants.java +++ b/src/main/java/com/codingrodent/microprocessor/z80/CPUConstants.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; /** * Various constant data structures and types to support the CPU diff --git a/src/main/java/com/codingrodent/microprocessor/Z80/Utilities.java b/src/main/java/com/codingrodent/microprocessor/z80/Utilities.java similarity index 96% rename from src/main/java/com/codingrodent/microprocessor/Z80/Utilities.java rename to src/main/java/com/codingrodent/microprocessor/z80/Utilities.java index d7baef3..a2bf528 100644 --- a/src/main/java/com/codingrodent/microprocessor/Z80/Utilities.java +++ b/src/main/java/com/codingrodent/microprocessor/z80/Utilities.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; import java.util.HexFormat; @@ -76,7 +76,7 @@ public static int getHexValue(String hex) { /** * Generate a string representing the contents of the flag register * - * @param value Flag regsiter value, 0x00 .. 0XFF + * @param value Flag register value, 0x00 .. 0XFF * @return String representing the set flag values for each bit, or space(s) where not set */ public static String getFlags(final int value) { diff --git a/src/main/java/com/codingrodent/microprocessor/Z80/Z80Core.java b/src/main/java/com/codingrodent/microprocessor/z80/Z80Core.java similarity index 99% rename from src/main/java/com/codingrodent/microprocessor/Z80/Z80Core.java rename to src/main/java/com/codingrodent/microprocessor/z80/Z80Core.java index d0e605c..fac4f96 100644 --- a/src/main/java/com/codingrodent/microprocessor/Z80/Z80Core.java +++ b/src/main/java/com/codingrodent/microprocessor/z80/Z80Core.java @@ -13,12 +13,14 @@ * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.*; +import com.codingrodent.microprocessor.IBaseDevice; +import com.codingrodent.microprocessor.ICPUData; +import com.codingrodent.microprocessor.IMemory; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import static com.codingrodent.microprocessor.Z80.CPUConstants.*; +import static com.codingrodent.microprocessor.z80.CPUConstants.*; /** * The ZiLOG Z80 processor core @@ -45,6 +47,7 @@ public class Z80Core implements ICPUData { private boolean NMI_FF; private boolean blockMove; private int resetAddress; + private int interruptMode; /** * Standard constructor. Set the processor up with a memory and I/O interface. @@ -93,6 +96,7 @@ private void processorReset() { reg_PC = resetAddress; // tStates = 0; + interruptMode = 0; } /** @@ -118,6 +122,15 @@ public boolean getHalt() { return halt; } + /** + * Returns the interrupt mode state + * + * @return Mode state + */ + public int getInterruptMode() { + return interruptMode; + } + /** * Recover the present program counter (PC) value * @@ -218,7 +231,7 @@ public void executeOneInstruction() { // NMI check first if (NMI_FF) { // can't interrupt straight after an EI or DI - if (! EIDIFlag) { + if (!EIDIFlag) { NMI_FF = false; // interrupt accepted IFF2 = IFF1; // store IFF state dec2SP(); @@ -408,7 +421,8 @@ private void decodeOneByteInstruction(int opcode) { } // ld a,n case 0x3F -> CCF(); // ccf // LD B,* - case 0x40 -> {} /* reg_B = reg_B; */ // ld b,b + case 0x40 -> { + } /* reg_B = reg_B; */ // ld b,b case 0x41 -> reg_B = reg_C; // ld b,c case 0x42 -> reg_B = reg_D; // ld b,d case 0x43 -> reg_B = reg_E; // ld b,e @@ -418,7 +432,8 @@ private void decodeOneByteInstruction(int opcode) { case 0x47 -> reg_B = reg_A; // ld b,a // LD C,* case 0x48 -> reg_C = reg_B; // ld c,b - case 0x49 -> {} /* reg_C = reg_C; */ // ld c,c + case 0x49 -> { + } /* reg_C = reg_C; */ // ld c,c case 0x4A -> reg_C = reg_D; // ld c,d case 0x4B -> reg_C = reg_E; // ld c,e case 0x4C -> reg_C = reg_H; // ld c,h @@ -428,7 +443,8 @@ private void decodeOneByteInstruction(int opcode) { // LD D,* case 0x50 -> reg_D = reg_B; // ld d,b case 0x51 -> reg_D = reg_C; // ld d,c - case 0x52 -> {} /* reg_D = reg_D; */ // ld d,d + case 0x52 -> { + } /* reg_D = reg_D; */ // ld d,d case 0x53 -> reg_D = reg_E; // ld d,e case 0x54 -> reg_D = reg_H; // ld d,h case 0x55 -> reg_D = reg_L; // ld d,l @@ -438,7 +454,8 @@ private void decodeOneByteInstruction(int opcode) { case 0x58 -> reg_E = reg_B; // ld e,b case 0x59 -> reg_E = reg_C; // ld e,c case 0x5A -> reg_E = reg_D; // ld e,d - case 0x5B -> {} /* reg_E = reg_E; */ // ld e,e + case 0x5B -> { + } /* reg_E = reg_E; */ // ld e,e case 0x5C -> reg_E = reg_H; // ld e,h case 0x5D -> reg_E = reg_L; // ld e,l case 0x5E -> reg_E = ram.readByte(getHL()); // ld e,(hl) @@ -448,7 +465,8 @@ private void decodeOneByteInstruction(int opcode) { case 0x61 -> reg_H = reg_C; // ld h,c case 0x62 -> reg_H = reg_D; // ld h,d case 0x63 -> reg_H = reg_E; // ld h,e - case 0x64 -> {} /* reg_H = reg_H; */ // ld h,h + case 0x64 -> { + } /* reg_H = reg_H; */ // ld h,h case 0x65 -> reg_H = reg_L; // ld h,l case 0x66 -> reg_H = ram.readByte(getHL()); // ld h,(hl) case 0x67 -> reg_H = reg_A; // ld h,a @@ -458,7 +476,8 @@ private void decodeOneByteInstruction(int opcode) { case 0x6A -> reg_L = reg_D; // ld l,d case 0x6B -> reg_L = reg_E; // ld l,e case 0x6C -> reg_L = reg_H; // ld l,h - case 0x6D -> {} /* reg_L = reg_L; */ // ld l,l + case 0x6D -> { + } /* reg_L = reg_L; */ // ld l,l case 0x6E -> reg_L = ram.readByte(getHL()); // ld l,(hl) case 0x6F -> reg_L = reg_A; // ld l,a // LD (HL),* @@ -482,7 +501,8 @@ private void decodeOneByteInstruction(int opcode) { case 0x7C -> reg_A = reg_H; // ld a,h case 0x7D -> reg_A = reg_L; // ld a,l case 0x7E -> reg_A = ram.readByte(getHL()); // ld a,(hl) - case 0x7F -> {} /* reg_A = reg_A; */ // ld a,a + case 0x7F -> { + } /* reg_A = reg_A; */ // ld a,a // add case 0x80 -> ALU8BitAdd(reg_B); case 0x81 -> ALU8BitAdd(reg_C); @@ -3095,7 +3115,7 @@ private void LDnnnnRegInd16Bit(int regCode) { */ private void IM(int mode) { - // interruptMode = mode; + interruptMode = mode; } /* @@ -3301,7 +3321,7 @@ private void loadIndex8BitImmediate() { * @return major revision number */ public String getMajorVersion() { - return "4"; + return "5"; } /** diff --git a/src/main/java/com/codingrodent/microprocessor/Z80/package-info.java b/src/main/java/com/codingrodent/microprocessor/z80/package-info.java similarity index 91% rename from src/main/java/com/codingrodent/microprocessor/Z80/package-info.java rename to src/main/java/com/codingrodent/microprocessor/z80/package-info.java index 7f5aa4b..164573b 100644 --- a/src/main/java/com/codingrodent/microprocessor/Z80/package-info.java +++ b/src/main/java/com/codingrodent/microprocessor/z80/package-info.java @@ -16,5 +16,5 @@ *
  • NMI handling * */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; diff --git a/src/test/java/com/codingrodent/microprocessor/performance/TimedExecution.java b/src/test/java/com/codingrodent/microprocessor/performance/TimedExecution.java index 6aa61ea..c4540c8 100644 --- a/src/test/java/com/codingrodent/microprocessor/performance/TimedExecution.java +++ b/src/test/java/com/codingrodent/microprocessor/performance/TimedExecution.java @@ -14,8 +14,9 @@ */ package com.codingrodent.microprocessor.performance; -import com.codingrodent.microprocessor.Z80.Z80Core; -import com.codingrodent.microprocessor.support.*; +import com.codingrodent.microprocessor.support.Z80IOEcho; +import com.codingrodent.microprocessor.support.Z80Memory; +import com.codingrodent.microprocessor.z80.Z80Core; class TimedExecution { @@ -24,7 +25,7 @@ class TimedExecution { /** * Very basic timing loop to check on throughput */ - public static void main(String[] args) { + static void main(String[] args) { { { { @@ -33,12 +34,12 @@ public static void main(String[] args) { } } } - TimedExecution timedExecution = new TimedExecution(); + var timedExecution = new TimedExecution(); var average = 0; var cycles = 25; for (int i = 0; i < cycles; i++) { timedExecution.init(); - var mhz = (int) timedExecution.run(0x1000); + var mhz = (int) timedExecution.run(); average = average + mhz; System.out.println("MHz: " + mhz); } @@ -56,12 +57,11 @@ private void init() { /** * Run through op-code test program * - * @param address Loaded address * @return Rough speed in MHz */ - private float run(final int address) { + private float run() { long t = System.currentTimeMillis(); - z80.setProgramCounter(address); + z80.setProgramCounter(0x1000); while (!z80.getHalt()) { try { z80.executeOneInstruction(); diff --git a/src/test/java/com/codingrodent/microprocessor/support/Z80Memory.java b/src/test/java/com/codingrodent/microprocessor/support/Z80Memory.java index 85a1c2d..f0bc138 100644 --- a/src/test/java/com/codingrodent/microprocessor/support/Z80Memory.java +++ b/src/test/java/com/codingrodent/microprocessor/support/Z80Memory.java @@ -15,9 +15,12 @@ package com.codingrodent.microprocessor.support; import com.codingrodent.microprocessor.IMemory; -import com.codingrodent.microprocessor.Z80.Utilities; +import com.codingrodent.microprocessor.z80.Utilities; -import java.io.*; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -66,7 +69,7 @@ public Z80Memory(final String filename) { try { readHexDumpFile(filename); } catch (Exception e) { - e.printStackTrace(); + System.out.println("Memory error, oops! " + e.getMessage()); } } diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/I8080CoreTest.java b/src/test/java/com/codingrodent/microprocessor/z80/I8080CoreTest.java similarity index 72% rename from src/test/java/com/codingrodent/microprocessor/Z80/I8080CoreTest.java rename to src/test/java/com/codingrodent/microprocessor/z80/I8080CoreTest.java index e12f821..a266a88 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/I8080CoreTest.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/I8080CoreTest.java @@ -12,21 +12,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.support.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class I8080CoreTest { private Z80Core z80; - private Z80Memory z80Memory; @BeforeEach public void setUp() { - z80Memory = new Z80Memory("8080EX1.nas"); + var z80Memory = new Z80Memory("8080EX1.nas"); z80 = new Z80Core(z80Memory, new Z80IO()); z80.reset(); } @@ -34,11 +36,11 @@ public void setUp() { /** * Test core by running an initial i8080 test set */ - // @Test - public final void test8080Core() { + @Disabled + public void intel8080Core() { // Initial setup z80.setProgramCounter(0x0100); - assertEquals(z80.getProgramCounter(), 0x0100); + assertEquals(0x0100, z80.getProgramCounter()); // // T states ? assertEquals(0, z80.getTStates()); diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/UtilitiesTest.java b/src/test/java/com/codingrodent/microprocessor/z80/UtilitiesTest.java similarity index 96% rename from src/test/java/com/codingrodent/microprocessor/Z80/UtilitiesTest.java rename to src/test/java/com/codingrodent/microprocessor/z80/UtilitiesTest.java index 1f41489..428c46b 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/UtilitiesTest.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/UtilitiesTest.java @@ -1,4 +1,4 @@ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestCB.java b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreCBTest.java similarity index 83% rename from src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestCB.java rename to src/test/java/com/codingrodent/microprocessor/z80/Z80CoreCBTest.java index 0f1db19..6f4074e 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestCB.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreCBTest.java @@ -12,16 +12,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.Z80.CPUConstants.RegisterNames; -import com.codingrodent.microprocessor.support.*; -import org.junit.jupiter.api.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; +import com.codingrodent.microprocessor.z80.CPUConstants.RegisterNames; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -public class Z80CoreTestCB { +public class Z80CoreCBTest { + private final static int BASE = 0xC000; private Z80Core z80; private Z80Memory z80Memory; @@ -32,16 +35,12 @@ public void setUp() { z80.reset(); } - @AfterEach - public void tearDown() { - } - /** * Verify instructions not covered in the main test program [CB prefix set] */ @Test public final void testCB() { - int addr = 0xC000; + int addr = BASE; // RLC B z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // @@ -49,93 +48,92 @@ public final void testCB() { z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(RegisterNames.BC)); // // RRC B - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xCB); // RRC B z80Memory.writeByte(addr++, 0x08); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(RegisterNames.BC)); // // RL B - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xCB); // RL B z80Memory.writeByte(addr++, 0x10); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(RegisterNames.BC)); // // RR B - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xCB); // RR B z80Memory.writeByte(addr++, 0x18); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(RegisterNames.BC)); // // SLA B - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xCB); // SLA B z80Memory.writeByte(addr++, 0x20); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(RegisterNames.BC)); // // SRA B - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xCB); // SRA B z80Memory.writeByte(addr++, 0x28); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(RegisterNames.BC)); // // SLL B - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xCB); // SLL B z80Memory.writeByte(addr++, 0x30); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0100, z80.getRegisterValue(RegisterNames.BC)); // // SRL B - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xCB); // SRL B z80Memory.writeByte(addr++, 0x38); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(RegisterNames.BC)); } - private void run(int address) { // + private void run() { // // Ok, run the program - z80.setProgramCounter(address); + z80.setProgramCounter(BASE); while (!z80.getHalt()) { try { - // System.out.println(utilities.getWord(z80.getRegisterValue(RegisterNames.PC))); z80.executeOneInstruction(); } catch (Exception e) { System.out.println("Hardware crash, oops! " + e.getMessage()); diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestDDFD.java b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreDDFDTest.java similarity index 87% rename from src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestDDFD.java rename to src/test/java/com/codingrodent/microprocessor/z80/Z80CoreDDFDTest.java index 303af04..b5ecc9e 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestDDFD.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreDDFDTest.java @@ -12,15 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.support.*; -import org.junit.jupiter.api.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -public class Z80CoreTestDDFD { +public class Z80CoreDDFDTest { + private final static int BASE = 0xC000; private Z80Core z80; private Z80Memory z80Memory; @@ -31,16 +34,12 @@ public void setUp() { z80.reset(); } - @AfterEach - public void tearDown() { - } - /** * Verify instructions not covered in the main test program [DD prefix set] */ @Test public final void testDD() { - int addr = 0xC000; + int addr = BASE; // JP (IX) z80Memory.writeByte(addr++, 0xDD); // LD IX z80Memory.writeByte(addr++, 0x21); // @@ -55,11 +54,11 @@ public final void testDD() { z80Memory.writeByte(addr++, 0x34); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x34, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // LD SP,IX - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0xDD); // LD IX z80Memory.writeByte(addr++, 0x21); // z80Memory.writeByte(addr++, 0x34); // @@ -68,11 +67,11 @@ public final void testDD() { z80Memory.writeByte(addr++, 0xF9); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x1234, z80.getRegisterValue(CPUConstants.RegisterNames.SP)); // // EX (SP),IX - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x31); // LD SP z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0x10); // @@ -89,7 +88,7 @@ public final void testDD() { z80Memory.writeByte(addr, 0x76); // HALT // z80.reset(); - run(0xC000); + run(); assertEquals(0x5678, z80.getRegisterValue(CPUConstants.RegisterNames.IX)); } @@ -105,14 +104,14 @@ public final void testDD() { *

    * Test Program: #DD #CB nn #00 RLC (IX+nn) *

    - * Docs (e.g. http://www.z80.info/z80undoc.htm) : #DD #CB nn #00 RLC (IX+nn) & LD B,(IX+nn) + * Docs (e.g. ...) : #DD #CB nn #00 RLC (IX+nn) & LD B,(IX+nn) *

    * The issue is if the parallel load actually happens (e.g. LD B,(IX+nn)). The test program is derived from a real * chip so going with that for now. May change !!! */ @Test public final void testDDCB() { - int addr = 0xC000; + int addr = BASE; // for (int opcode = 0; opcode <= 0xFF; opcode++) { z80Memory.writeByte(addr++, 0xDD); // DD FD @@ -122,12 +121,12 @@ public final void testDDCB() { } z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); } - private void run(int address) { // + private void run() { // // Ok, run the program - z80.setProgramCounter(address); + z80.setProgramCounter(BASE); while (!z80.getHalt()) { try { // System.out.println(utilities.getWord(z80.getRegisterValue(RegisterNames.PC))); diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestED.java b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreEDTest.java similarity index 92% rename from src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestED.java rename to src/test/java/com/codingrodent/microprocessor/z80/Z80CoreEDTest.java index ec90f2f..881f092 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestED.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreEDTest.java @@ -12,16 +12,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.support.*; -import org.junit.jupiter.api.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static com.codingrodent.microprocessor.Z80.CPUConstants.RegisterNames.R; +import static com.codingrodent.microprocessor.z80.CPUConstants.RegisterNames.R; import static org.junit.jupiter.api.Assertions.assertEquals; -public class Z80CoreTestED { +public class Z80CoreEDTest { + private final static int BASE = 0xC000; private Z80Core z80; private Z80Memory z80Memory; @@ -32,16 +35,12 @@ public void setUp() { z80.reset(); } - @AfterEach - public void tearDown() { - } - /** * Verify instructions not covered in the main test program [ED prefix set] */ @Test public final void testED1() { - int addr = 0xC000; + int addr = BASE; // IN / OUT B z80Memory.writeByte(addr++, 0x06); // LD B z80Memory.writeByte(addr++, 0x45); // @@ -53,11 +52,11 @@ public final void testED1() { z80Memory.writeByte(addr++, 0x40); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x4534, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); // // RETN - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -71,29 +70,29 @@ public final void testED1() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // LD I,A - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xED); // LD I,A z80Memory.writeByte(addr++, 0x47); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x00, z80.getRegisterValue(CPUConstants.RegisterNames.I)); // // LD I,A - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x80); // z80Memory.writeByte(addr++, 0xED); // LD I,A z80Memory.writeByte(addr++, 0x47); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x80, z80.getRegisterValue(CPUConstants.RegisterNames.I)); } @@ -102,7 +101,7 @@ public final void testED1() { */ @Test public final void testED2() { - int addr = 0xC000; + int addr = BASE; // IN / OUT C z80Memory.writeByte(addr++, 0x0E); // LD C z80Memory.writeByte(addr++, 0x34); // @@ -112,11 +111,11 @@ public final void testED2() { z80Memory.writeByte(addr++, 0x48); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0034, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); // // RETI - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -130,21 +129,21 @@ public final void testED2() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // NEG - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x01); // z80Memory.writeByte(addr++, 0xED); // NEG z80Memory.writeByte(addr, 0x4C); // z80.reset(); - run(0xC000); + run(); assertEquals(0xFF, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // LD A,I - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xED); // LD I,A @@ -161,7 +160,7 @@ public final void testED2() { z80Memory.writeByte(addr++, 0x57); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x80, z80.getRegisterValue(CPUConstants.RegisterNames.A)); assertEquals(0x80, z80.getRegisterValue(CPUConstants.RegisterNames.I)); } @@ -171,7 +170,7 @@ public final void testED2() { */ @Test public final void testED3() { - int addr = 0xC000; + int addr = BASE; // IN / OUT D z80Memory.writeByte(addr++, 0x16); // LD D z80Memory.writeByte(addr++, 0x45); // @@ -183,11 +182,11 @@ public final void testED3() { z80Memory.writeByte(addr++, 0x50); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x4500, z80.getRegisterValue(CPUConstants.RegisterNames.DE)); // // RETN - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -201,39 +200,39 @@ public final void testED3() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // NEG - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x01); // z80Memory.writeByte(addr++, 0xED); // NEG z80Memory.writeByte(addr, 0x54); // z80.reset(); - run(0xC000); + run(); assertEquals(0xFF, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // LD R,A - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x00); // LD A z80Memory.writeByte(addr++, 0xF7); // z80Memory.writeByte(addr++, 0xED); // LD R,A z80Memory.writeByte(addr++, 0x4F); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x00, z80.getRegisterValue(R)); // // LD R,A - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x34); // z80Memory.writeByte(addr++, 0xED); // LD R,A z80Memory.writeByte(addr++, 0x4F); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x34, z80.getRegisterValue(R)); } @@ -242,7 +241,7 @@ public final void testED3() { */ @Test public final void testED4() { - int addr = 0xC000; + int addr = BASE; // IN / OUT E z80Memory.writeByte(addr++, 0x1E); // LD E z80Memory.writeByte(addr++, 0x45); // @@ -254,11 +253,11 @@ public final void testED4() { z80Memory.writeByte(addr++, 0x58); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0045, z80.getRegisterValue(CPUConstants.RegisterNames.DE)); // // RETN - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -272,21 +271,21 @@ public final void testED4() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // NEG - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x01); // z80Memory.writeByte(addr++, 0xED); // NEG z80Memory.writeByte(addr, 0x5C); // z80.reset(); - run(0xC000); + run(); assertEquals(0xFF, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // LD A,R - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xED); // LD R,A @@ -301,7 +300,7 @@ public final void testED4() { z80Memory.writeByte(addr++, 0x5F); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x40, z80.getRegisterValue(CPUConstants.RegisterNames.A)); assertEquals(0x40, z80.getRegisterValue(R)); } @@ -311,7 +310,7 @@ public final void testED4() { */ @Test public final void testED5() { - int addr = 0xC000; + int addr = BASE; // IN / OUT H z80Memory.writeByte(addr++, 0x26); // LD H z80Memory.writeByte(addr++, 0x45); // @@ -323,11 +322,11 @@ public final void testED5() { z80Memory.writeByte(addr++, 0x60); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x4500, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); // // RETN - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -341,21 +340,21 @@ public final void testED5() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // NEG - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x01); // z80Memory.writeByte(addr++, 0xED); // NEG z80Memory.writeByte(addr, 0x64); // z80.reset(); - run(0xC000); + run(); assertEquals(0xFF, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // LD A,R - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x45); // z80Memory.writeByte(addr++, 0xED); // LD R,A @@ -366,7 +365,7 @@ public final void testED5() { z80Memory.writeByte(addr++, 0x5F); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x45, z80.getRegisterValue(CPUConstants.RegisterNames.A)); } @@ -375,7 +374,7 @@ public final void testED5() { */ @Test public final void testED6() { - int addr = 0xC000; + int addr = BASE; // IN / OUT L z80Memory.writeByte(addr++, 0x2E); // LD L z80Memory.writeByte(addr++, 0x45); // @@ -387,11 +386,11 @@ public final void testED6() { z80Memory.writeByte(addr++, 0x68); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0045, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); // // RETN - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -405,17 +404,17 @@ public final void testED6() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // NEG - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x01); // z80Memory.writeByte(addr++, 0xED); // NEG z80Memory.writeByte(addr, 0x6C); // z80.reset(); - run(0xC000); + run(); assertEquals(0xFF, z80.getRegisterValue(CPUConstants.RegisterNames.A)); } @@ -424,7 +423,7 @@ public final void testED6() { */ @Test public final void testED7() { - int addr = 0xC000; + int addr = BASE; // IN / OUT F - Uber weird z80Memory.writeByte(addr++, 0x0E); // LD C z80Memory.writeByte(addr++, 0x34); // @@ -434,11 +433,11 @@ public final void testED7() { z80Memory.writeByte(addr++, 0x70); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x44, z80.getRegisterValue(CPUConstants.RegisterNames.F)); // // RETN - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -452,17 +451,17 @@ public final void testED7() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // NEG - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x01); // z80Memory.writeByte(addr++, 0xED); // NEG z80Memory.writeByte(addr, 0x74); // z80.reset(); - run(0xC000); + run(); assertEquals(0xFF, z80.getRegisterValue(CPUConstants.RegisterNames.A)); } @@ -471,7 +470,7 @@ public final void testED7() { */ @Test public final void testED8() { - int addr = 0xC000; + int addr = BASE; // IN / OUT z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x45); // @@ -483,11 +482,11 @@ public final void testED8() { z80Memory.writeByte(addr++, 0x78); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x45, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // RETN - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0xD0); // @@ -501,17 +500,17 @@ public final void testED8() { z80Memory.writeByte(addr++, 0x77); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // NEG - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x01); // z80Memory.writeByte(addr++, 0xED); // NEG z80Memory.writeByte(addr, 0x7C); // z80.reset(); - run(0xC000); + run(); assertEquals(0xFF, z80.getRegisterValue(CPUConstants.RegisterNames.A)); } @@ -520,7 +519,7 @@ public final void testED8() { */ @Test public final void testEDVarious() { - int addr = 0xC000; + int addr = BASE; // LD (nn),HL z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x34); // @@ -538,11 +537,11 @@ public final void testEDVarious() { z80Memory.writeByte(addr++, 0x10); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x1234, z80Memory.readWord(0x1000)); assertEquals(0x1234, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); // - addr = 0xC000; + addr = BASE; // LD (nn),HL z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0xFF); // @@ -554,10 +553,10 @@ public final void testEDVarious() { z80Memory.writeByte(addr++, 0x4A); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x0000, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); // - addr = 0xC000; + addr = BASE; // IN / OUT (Checking S flag) z80Memory.writeByte(addr++, 0x3E); // LD A z80Memory.writeByte(addr++, 0x80); // @@ -569,7 +568,7 @@ public final void testEDVarious() { z80Memory.writeByte(addr++, 0x40); // z80Memory.writeByte(addr, 0x76); // HALT z80.reset(); - run(0xC000); + run(); assertEquals(0x80, z80.getRegisterValue(CPUConstants.RegisterNames.A)); } @@ -580,7 +579,7 @@ public final void testEDVarious() { public final void testEDVariousIO() { // // INI - int addr = 0xC000; + int addr = BASE; z80Memory.writeByte(addr++, 0xD3); // OUT A z80Memory.writeByte(addr++, 0x34); // z80Memory.writeByte(addr++, 0x21); // LD HL @@ -595,13 +594,13 @@ public final void testEDVariousIO() { // z80Memory.writeByte(0x1000, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x1001, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0134, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x00, z80Memory.readByte(0x1000)); // // OUTI - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0x10); // @@ -616,13 +615,13 @@ public final void testEDVariousIO() { // z80Memory.writeByte(0x1000, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x1001, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0134, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // IND - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0xD3); // OUT A z80Memory.writeByte(addr++, 0x34); // z80Memory.writeByte(addr++, 0x21); // LD HL @@ -637,13 +636,13 @@ public final void testEDVariousIO() { // z80Memory.writeByte(0x1000, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x0FFF, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0134, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x00, z80Memory.readByte(0x1000)); // // OUTD - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0x10); // @@ -658,14 +657,14 @@ public final void testEDVariousIO() { // z80Memory.writeByte(0x1000, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x0FFF, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0134, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // INIR - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0xD3); // OUT A z80Memory.writeByte(addr++, 0x34); // z80Memory.writeByte(addr++, 0x21); // LD HL @@ -681,13 +680,13 @@ public final void testEDVariousIO() { z80Memory.writeByte(0x1000, 0x55); // data z80Memory.writeByte(0x1000, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x1002, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0034, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x00, z80Memory.readByte(0x1000)); // // OUTIR - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0x10); // @@ -703,13 +702,13 @@ public final void testEDVariousIO() { z80Memory.writeByte(0x1000, 0x55); // data z80Memory.writeByte(0x1001, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x1002, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0034, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); // // INDR - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0xD3); // OUT A z80Memory.writeByte(addr++, 0x34); // z80Memory.writeByte(addr++, 0x21); // LD HL @@ -725,13 +724,13 @@ public final void testEDVariousIO() { z80Memory.writeByte(0x1000, 0x55); // data z80Memory.writeByte(0x0FFF, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x0FFE, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0034, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x00, z80Memory.readByte(0x1000)); // // OUTDR - addr = 0xC000; + addr = BASE; z80Memory.writeByte(addr++, 0x21); // LD HL z80Memory.writeByte(addr++, 0x00); // z80Memory.writeByte(addr++, 0x10); // @@ -747,7 +746,7 @@ public final void testEDVariousIO() { z80Memory.writeByte(0x1000, 0x55); // data z80Memory.writeByte(0x0FFF, 0x77); // data z80.reset(); - run(0xC000); + run(); assertEquals(0x0FFE, z80.getRegisterValue(CPUConstants.RegisterNames.HL)); assertEquals(0x0034, z80.getRegisterValue(CPUConstants.RegisterNames.BC)); assertEquals(0x77, z80.getRegisterValue(CPUConstants.RegisterNames.A)); @@ -759,7 +758,7 @@ public final void testEDVariousIO() { */ @Test public final void testNotImplementedED() { - int addr = 0xC000; + int addr = BASE; // IM z80Memory.writeByte(addr++, 0xED); // IM (0) z80Memory.writeByte(addr++, 0x46); // @@ -788,12 +787,12 @@ public final void testNotImplementedED() { z80Memory.writeByte(addr, 0x76); // HALT // z80.reset(); - run(0xC000); + run(); } - private void run(int address) { // + private void run() { // // Ok, run the program - z80.setProgramCounter(address); + z80.setProgramCounter(BASE); while (!z80.getHalt()) { try { // System.out.println(utilities.getWord(z80.getRegisterValue(RegisterNames.PC))); diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestInterrupts.java b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreInterruptsTest.java similarity index 94% rename from src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestInterrupts.java rename to src/test/java/com/codingrodent/microprocessor/z80/Z80CoreInterruptsTest.java index bee84d3..e10723e 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestInterrupts.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreInterruptsTest.java @@ -12,15 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.Z80.CPUConstants.RegisterNames; -import com.codingrodent.microprocessor.support.*; -import org.junit.jupiter.api.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; +import com.codingrodent.microprocessor.z80.CPUConstants.RegisterNames; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -public class Z80CoreTestInterrupts { +public class Z80CoreInterruptsTest { private Z80Core z80; private Z80Memory z80Memory; @@ -31,10 +33,6 @@ public void setUp() { z80.reset(); } - @AfterEach - public void tearDown() { - } - /** * Does NMI work ? */ @@ -159,7 +157,7 @@ public final void testNMIdisabledAfterEIDI() { // Now Same Tests for EI addr = 0xC000; - z80Memory.writeByte(addr++, 0xFB); // EI + z80Memory.writeByte(addr, 0xFB); // EI // executing (with EI) with NMI after EI instruction testNMI(0xC000, 1); diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTest.java b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreTest.java similarity index 97% rename from src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTest.java rename to src/test/java/com/codingrodent/microprocessor/z80/Z80CoreTest.java index 3dd3496..62752b6 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTest.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreTest.java @@ -12,12 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.support.*; -import org.junit.jupiter.api.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class Z80CoreTest { private Z80Core z80; @@ -30,10 +33,6 @@ public void setUp() { z80.reset(); } - @AfterEach - public void tearDown() { - } - /** * Check LDIR / LDDIR function */ @@ -500,31 +499,26 @@ public final void testRST() { run(0xC000); assertEquals(0x0008, z80.getProgramCounter()); // - addr = 0xC000; z80.reset(); z80Memory.writeByte(addr, 0xD7); // RST 10 run(0xC000); assertEquals(0x0010, z80.getProgramCounter()); // - addr = 0xC000; z80.reset(); z80Memory.writeByte(addr, 0xDF); // RST 18 run(0xC000); assertEquals(0x0018, z80.getProgramCounter()); // - addr = 0xC000; z80.reset(); z80Memory.writeByte(addr, 0xE7); // RST 20 run(0xC000); assertEquals(0x0020, z80.getProgramCounter()); // - addr = 0xC000; z80.reset(); z80Memory.writeByte(addr, 0xEF); // RST 28 run(0xC000); assertEquals(0x0028, z80.getProgramCounter()); // - addr = 0xC000; z80.reset(); z80Memory.writeByte(addr++, 0xF7); // RST 30 z80Memory.writeByte(addr, 0x76); // HALT @@ -563,11 +557,11 @@ public final void testUtils() { assertEquals(0x00, z80.getRegisterValue(CPUConstants.RegisterNames.I)); assertEquals(0x00, z80.getRegisterValue(CPUConstants.RegisterNames.R)); // - assertEquals(z80.getMajorVersion(), "4"); - assertEquals(z80.getMinorVersion(), "0"); - assertEquals(z80.getPatchVersion(), "0"); - assertEquals(z80.getName(), "Z80A_NMOS"); - assertEquals(z80.toString(), "Z80A_NMOS Revision 4.0.0"); + assertEquals("5", z80.getMajorVersion()); + assertEquals("0", z80.getMinorVersion()); + assertEquals("0", z80.getPatchVersion()); + assertEquals("Z80A_NMOS", z80.getName()); + assertEquals("Z80A_NMOS Revision 5.0.0", z80.toString()); } private void run(int address) { // diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestUnimplemented.java b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreTestUnimplemented.java similarity index 79% rename from src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestUnimplemented.java rename to src/test/java/com/codingrodent/microprocessor/z80/Z80CoreTestUnimplemented.java index a77ae19..66b4f71 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/Z80CoreTestUnimplemented.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/Z80CoreTestUnimplemented.java @@ -12,26 +12,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.support.*; -import org.junit.jupiter.api.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; +import org.junit.jupiter.api.BeforeEach; public class Z80CoreTestUnimplemented { private Z80Core z80; - private Z80Memory z80Memory; @BeforeEach public void setUp() { - z80Memory = new Z80Memory("NAS_Test.nas"); + var z80Memory = new Z80Memory("NAS_Test.nas"); z80 = new Z80Core(z80Memory, new Z80IO()); z80.reset(); } - @AfterEach - public void tearDown() { - } - private void run(int address) { // // Ok, run the program z80.setProgramCounter(address); diff --git a/src/test/java/com/codingrodent/microprocessor/Z80/Z80NasTest.java b/src/test/java/com/codingrodent/microprocessor/z80/Z80NasTest.java similarity index 81% rename from src/test/java/com/codingrodent/microprocessor/Z80/Z80NasTest.java rename to src/test/java/com/codingrodent/microprocessor/z80/Z80NasTest.java index cefc2c1..6f08359 100644 --- a/src/test/java/com/codingrodent/microprocessor/Z80/Z80NasTest.java +++ b/src/test/java/com/codingrodent/microprocessor/z80/Z80NasTest.java @@ -12,30 +12,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.codingrodent.microprocessor.Z80; +package com.codingrodent.microprocessor.z80; -import com.codingrodent.microprocessor.support.*; -import org.junit.jupiter.api.*; +import com.codingrodent.microprocessor.support.Z80IO; +import com.codingrodent.microprocessor.support.Z80Memory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Z80NasTest { private Z80Core z80; - private Z80Memory z80Memory; private int a = 0; @BeforeEach public void setUp() { - z80Memory = new Z80Memory("NAS_Test.nas"); + Z80Memory z80Memory = new Z80Memory("NAS_Test.nas"); z80 = new Z80Core(z80Memory, new Z80IO()); z80.reset(); } - @AfterEach - public void tearDown() { - } - /** * Test core by running test application this covers most instructions. Other tests are to 'mop up' uncovered * regions @@ -43,18 +41,17 @@ public void tearDown() { @Test public final void testCore() { // Initial setup - assertEquals(z80.getProgramCounter(), 0x0000); + assertEquals(0x0000, z80.getProgramCounter()); z80.setResetAddress(0x1234); z80.reset(); - assertEquals(z80.getProgramCounter(), 0x1234); + assertEquals(0x1234, z80.getProgramCounter()); z80.setProgramCounter(0x1000); - assertEquals(z80.getProgramCounter(), 0x1000); + assertEquals(0x1000, z80.getProgramCounter()); // // T states ? assertEquals(0, z80.getTStates()); // // Ok, run the program -// int c = 0x2000; while (!z80.getHalt()) { try { // System.out.println(getRegs()); @@ -62,10 +59,7 @@ public final void testCore() { z80.executeOneInstruction(); } catch (Exception e) { System.out.println("Hardware crash, oops! " + e.getMessage()); - e.printStackTrace(); } -// c--; -// if (c<0) break; } assertTrue(z80.getTStates() > 0); z80.resetTStates();