Skip to content

Commit

Permalink
Moved several byte/int reading methods to emuLib
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmacher committed Aug 12, 2021
1 parent 40b3047 commit 6696e08
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 199 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Expand Up @@ -5,20 +5,21 @@ plugins {
}

ext {
emulib = '11.5'
emulib = '11.6'
}

group 'net.emustudio'
version '1.2.0-SNAPSHOT'

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation "net.emustudio:emulib:${emulib}.+"
implementation 'net.jcip:jcip-annotations:1.0'
implementation 'junit:junit:4.12'
implementation 'junit:junit:4.13.2'
}

java {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 3 additions & 1 deletion gradlew
Expand Up @@ -72,7 +72,7 @@ case "`uname`" in
Darwin* )
darwin=true
;;
MINGW* )
MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
Expand All @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
192 changes: 89 additions & 103 deletions gradlew.bat
@@ -1,103 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

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.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

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.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

: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 %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="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

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "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.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
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.

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 %*

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="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

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
16 changes: 5 additions & 11 deletions src/main/java/net/emustudio/cpu/testsuite/CpuVerifier.java
Expand Up @@ -30,7 +30,6 @@
*
* Used for checking the result (registers, flags, memory) after test execution.
*/
@SuppressWarnings("unchecked")
public abstract class CpuVerifier {
protected final MemoryStub<? extends Number> memoryStub;

Expand All @@ -46,18 +45,13 @@ public void checkMemoryByte(int address, int value) {
);
}

public void checkMemoryWord(int address, int value) {
Number[] read = memoryStub.readWord(address);
Byte[] word = new Byte[] {0,0,0,0};
for (int i = 0; i < read.length; i++) {
word[i] = read[i].byteValue();
}

int memoryWord = NumberUtils.readInt(word, memoryStub.getWordReadingStrategy());
public void checkMemoryInteger(int address, int value) {
Byte[] word = NumberUtils.numbersToBytes(memoryStub.read(address, 4));
int memoryInt = NumberUtils.readInt(word, memoryStub.getWordReadingStrategy());

assertEquals(
String.format("Expected word mem[%04x]=%04x, but was %04x", address, value, memoryWord),
value, memoryWord
String.format("Expected word mem[%04x]=%04x, but was %04x", address, value, memoryInt),
value, memoryInt
);
}

Expand Down
Expand Up @@ -19,21 +19,28 @@
package net.emustudio.cpu.testsuite.memory;

import net.emustudio.emulib.plugins.memory.Memory;
import net.emustudio.emulib.runtime.helpers.NumberUtils;

import java.util.Arrays;

import static net.emustudio.emulib.runtime.helpers.NumberUtils.nativeShortsToBytes;

@SuppressWarnings("unused")
public class ByteMemoryStub implements MemoryStub<Byte> {
private final int wordReadingStrategy;

protected byte[] memory = new byte[1000];
private int wordCellsCount = 2;
protected Byte[] memory = new Byte[1000];

public ByteMemoryStub(int wordReadingStrategy) {
Arrays.fill(memory, (byte) 0);
this.wordReadingStrategy = wordReadingStrategy;
}

public void setMemory(byte[] memory) {
this.memory = NumberUtils.nativeBytesToBytes(memory);
}

public void setMemory(Byte[] memory) {
this.memory = memory;
}

Expand All @@ -43,13 +50,10 @@ public Byte read(int memoryPosition) {
}

@Override
public Byte[] readWord(int memoryPosition) {
Byte[] word = new Byte[wordCellsCount];
for (int i = 0; i < wordCellsCount; i++) {
word[i] = memory[memoryPosition + i];
}

return word;
public Byte[] read(int memoryPosition, int count) {
Byte[] result = new Byte[count];
System.arraycopy(memory, memoryPosition, result, 0, count);
return result;
}

@Override
Expand All @@ -58,10 +62,8 @@ public void write(int memoryPosition, Byte value) {
}

@Override
public void writeWord(int memoryPosition, Byte[] cells) {
for (int i = 0; i < wordCellsCount; i++) {
memory[memoryPosition + i] = cells[i];
}
public void write(int memoryPosition, Byte[] cells, int count) {
System.arraycopy(cells, 0, memory, memoryPosition, count);
}

@Override
Expand Down Expand Up @@ -99,14 +101,9 @@ public void setMemoryNotificationsEnabled(boolean enabled) {

}

@Override
public void setWordCellsCount(int count) {
this.wordCellsCount = count;
}

@Override
public void setMemory(short[] memory) {
this.memory = nativeShortsToNativeBytes(memory);
this.memory = nativeShortsToBytes(memory);
}

@Override
Expand Down

0 comments on commit 6696e08

Please sign in to comment.