Commit 486876bc by Jessica Hawkwell

initial commit

1 parent 80397fbd
Pipeline #202 passed
in 58 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.felinewith</groupId>
<artifactId>kcpu</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<tag>master</tag>
<rev>~${env.USER}</rev>
<fulltag>${tag}/${rev}</fulltag>
<fullver>${project.name} ${project.version} (${fulltag})</fullver>
<gl.group>LadySerenaKitty</gl.group>
<gl.group-url>ladyserenakitty</gl.group-url>
<gl.name>kcpu</gl.name>
<gl.url>https://felinewith.me/${gl.group-url}/${gl.name}</gl.url>
<gl.pages>https://${gl.group-url}.felinewith.me/${gl.name}</gl.pages>
</properties>
<url>${gl.pages}</url>
<licenses>
<license>
<distribution>repo</distribution>
<name>BSD</name>
<url>https://felinewith.me/LadySerenaKitty/kcpu/raw/master/LICENSE</url>
</license>
</licenses>
<distributionManagement>
<repository>
<id>releases</id>
<name>SPM Releases</name>
<url>https://mvn.felinewith.me/repository/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>SPM Snapshots</name>
<url>https://mvn.felinewith.me/repository/snapshots</url>
</snapshotRepository>
<site>
<id>Main</id>
<name>${project.name}</name>
<url>${gl.pages}</url>
</site>
<downloadUrl>https://mvn.felinewith.me/#artifact-details-download-content/${project.groupId}/${project.artifactId}</downloadUrl>
</distributionManagement>
<issueManagement>
<system>GitLab</system>
<url>${gl.url}/issues</url>
</issueManagement>
<ciManagement>
<system>GitLab CI</system>
<url>${gl.url}/pipelines</url>
</ciManagement>
<scm>
<connection>scm:git:${gl.url}.git</connection>
<developerConnection>scm:git:[email protected]:${gl.group-url}/${gl.name}.git</developerConnection>
<tag>${tag}</tag>
<url>${gl.url}/blob/${tag}/</url>
</scm>
<organization>
<name>StarPhoenix Media</name>
<url>https://starphoenixmedia.com/</url>
</organization>
<developers>
<developer>
<id>jlhawkwell</id>
<name>Jessica Hawkwell</name>
<email>[email protected]</email>
<organization>StarPhoenix Media</organization>
<organizationUrl>http://starphoenixmedia.com/</organizationUrl>
<timezone>-5</timezone>
</developer>
</developers>
<repositories>
<repository>
<id>external</id>
<name>SPM Externals</name>
<url>https://mvn.felinewith.me/repository/external</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>test package install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
<!-- MAVEN BUILD DEPENDENCIES ************************************************************* MAVEN BUILD DEPENDENCIES -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<classpathLayoutType>repository</classpathLayoutType>
<packageName></packageName>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
</plugin>
<!-- MAVEN SITE BUILDER ************************************************************************* MAVEN SITE BUILDER -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.6</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.3</version>
<configuration>
<range>30</range>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<!-- configLocation>https://dev.vocasystem.net/checkstyle.xml</configLocation -->
</configuration>
<reportSets>
<reportSet>
<id>parent</id>
<inherited>false</inherited>
<configuration>
<skip>true</skip>
</configuration>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<noqualifier>all</noqualifier>
<show>public</show>
<sourcetab>4</sourcetab>
<splitindex>true</splitindex>
<detectLinks>true</detectLinks>
<nodeprecated>true</nodeprecated>
<quiet>true</quiet>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<targetJdk>1.8</targetJdk>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.9</version>
<configuration>
<version>1.0-SNAPSHOT</version>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.20</version>
</plugin>
</plugins>
</reporting>
<profiles>
<profile>
<id>ci</id>
<activation>
<property>
<name>env.CI_COMMIT_REF_NAME</name>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<tag>${env.CI_COMMIT_REF_NAME}</tag>
</properties>
</profile>
<profile>
<id>rev-env</id>
<activation>
<property>
<name>env.GIT_REV</name>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<rev>${env.GIT_REV}</rev>
</properties>
</profile>
<profile>
<id>rev-cli</id>
<activation>
<property>
<name>git-rev</name>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<rev>${git-rev}</rev>
</properties>
</profile>
<profile>
<id>debug</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-g</compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>release</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-g:none</compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
package me.felinewith.kcpu;
/**
*
* @author jlhawkwell
*/
public class Converter {
// convert bytes to stuff
public static short byte2short(byte[] input) {
return (short)(0xffff & arrayAdder(byteShifterUp(input)));
}
public static int byte2int(byte[] input) {
return arrayAdder(byteShifterUp(input));
}
// convert stuff to bytes
public static byte[] short2byte(short input) {
return byteShifterDown(input, 2);
}
public static byte[] int2byte(int input) {
return byteShifterDown(input, 4);
}
private static int[] byteShifterUp(byte[] input) {
int a = input.length;
int[] temp = new int[a];
for (a = 0; a < input.length; a++) {
temp[a] = (0xff & input[a]) << (a * 8);
}
return temp;
}
private static byte[] byteShifterDown(int input, int length) {
int a = 0;
byte[] temp = new byte[length];
int shift = 0;
int mask = 0xff;
for (a = 0; a < length; a++) {
shift = a * 8;
mask = mask << shift;
temp[a] = (byte)((mask & input) >> shift);
}
return temp;
}
private static int arrayAdder(int[] input) {
int a;
int output = 0;
for (a = 0; a < input.length; a++) {
output += input[a];
}
return output;
}
}
package me.felinewith.kcpu;
/**
*
* @author jlhawkwell
*/
public interface IDevice extends IMemory {
public void init(IMemory board);
public short getInterrupt();
public void setInterrupt(short irq);
public short getSetting(short setting);
public void setSetting(short setting, short value);
public byte[] getName();
public void exec();
}
package me.felinewith.kcpu;
/**
*
* @author jlhawkwell
*/
public interface IMemory {
public abstract short length();
public abstract byte[] read(short offset, short length);
public abstract void write(short offset, byte[] data);
public void copy(short offsetSrc, short offsetDest, short length, IMemory dest);
}
package me.felinewith.kcpu;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import me.felinewith.kcpu.hardware.BootRom;
import me.felinewith.kcpu.hardware.Kfpu;
import me.felinewith.kcpu.memory.KMemoryRange;
import me.felinewith.kcpu.util.BaseMemory;
import me.felinewith.kcpu.util.HardwareTask;
import me.felinewith.kcpu.util.IDeviceRunner;
/**
*
* @author jlhawkwell
*/
public class KBoard extends BaseMemory implements IMemory {
ThreadPoolExecutor tpe;
TimerTask tt;
Timer t;
byte[] memory;
IDevice[] devices;
KMemoryRange[] deviceMaps;
public KBoard() {
tpe = new ThreadPoolExecutor(16, 32, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(16));
memory = new byte[0xffff];
devices = new IDevice[16];
deviceMaps = new KMemoryRange[16];
}
public void init() {
attachDevice(0, 0x8000, new Kcpu(this));
attachDevice(1, 0x8800, new Kfpu());
attachDevice(2, 0x1000, new BootRom());
tt = new HardwareTask(devices[0]);
t = new Timer("CPU Cycler");
t.schedule(tt, 0, 1);
}
@Override public short length() { return (short)memory.length; };
@Override public byte[] read(short offset, short length) {
short dev = checkDevice(offset, length);
if ( dev == 0x7f ) { return Arrays.copyOfRange(memory, offset, offset + length); }
else {
short devOff = (short)(offset - deviceMaps[dev].getOffset());
return devices[dev].read(devOff, length);
}
}
@Override public void write(short offset, byte[] data) {
IDeviceRunner idr;
short dev = checkDevice(offset, (short)data.length);
if ( dev == 0x7f ) {
short len = (short)data.length;
short a;
short addr;
for (a = 0; a < len; a++) {
addr = (short)(offset + a);
memory[addr] = data[a];
}
idr = new IDeviceRunner(devices[0]);
}
else {
short devOff = (short)(offset - deviceMaps[dev].getOffset());
devices[dev].write(devOff, data);
idr = new IDeviceRunner(devices[dev]);
}
tpe.execute(idr);
}
private void attachDevice(int port, int offset, IDevice device) {
attachDevice(port, (short)offset, device); }
private void attachDevice(int port, short offset, IDevice device) {
if ( devices[port] != null ) { return; }
else if ( deviceMaps[port] != null ) { return; }
devices[port] = device;
deviceMaps[port] = new KMemoryRange(offset, device.length());
}
private short checkDevice(short offset, short length) {
short a;
short top = (short)(offset + length);
KMemoryRange io;
short devOff;
short devTop;
for (a = 0; a < 16; a++) {
if ( deviceMaps[a] != null ) {
io = deviceMaps[a];
devOff = io.getOffset();
devTop = (short)(devOff + io.getLength());
if ( devOff <= offset && offset <= devTop ) { return a; }
else if ( devOff <= top && top <= devTop ) { return a; }
}
}
return 0x7f;
}
}
package me.felinewith.kcpu;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.TimerTask;
/**
*
* @author jlhawkwell
*/
public class Kcpu extends TimerTask implements IDevice {
byte[] memory;
String name;
short[] settings;
KBoard board;
public Kcpu(KBoard system) {
memory = new byte[0x0800];
name = "Kcpu";
settings = new short[4];
board = system;
}
@Override public void init(IMemory system) { }
@Override public short getInterrupt() { return 0; }
@Override public void setInterrupt(short irq) { }
@Override public short getSetting(short setting) {
int addr = 0x07f0 + setting;
if (addr > 0x07ff) { return 0x7fff; }
return memory[addr];
}
@Override public void setSetting(short setting, short value) {
int addr = 0x07f0 + setting;
if (addr > 0x07ff) { return; }
memory[addr] = (byte)(0xff & value);
}
@Override public byte[] getName() { return "Kcpu".getBytes(Charset.forName("UTF-8"));}
// use this one during interrupts
@Override public void exec() {
}
@Override public short length() { return 0x07ff; }
@Override public byte[] read(short offset, short length) {
return Arrays.copyOfRange(memory, offset, offset + length);
}
@Override public void write(short offset, byte[] data) { }
@Override public void copy(short offsetSrc, short offsetDest, short length, IMemory dest) { }
// this one for normal execution
@Override public void run() {
}
}
package me.felinewith.kcpu.hardware;
import java.util.Arrays;
import me.felinewith.kcpu.util.BaseDevice;
/**
*
* @author jlhawkwell
*/
public class BootRom extends BaseDevice {
public BootRom() {
memory = new byte[0x0fff];
Arrays.fill(memory, (byte)0x75);
settings = new short[0];
name = "BootRom";
}
@Override public void write(short offset, byte[] data) { }
@Override public void exec() { }
}
package me.felinewith.kcpu.hardware;
import me.felinewith.kcpu.Converter;
import me.felinewith.kcpu.util.BaseDevice;
/**
*
* @author jlhawkwell
*/
public class Kfpu extends BaseDevice {
public Kfpu() {
memory = new byte[0x010];
name = "Kfpu";
settings = new short[2];
}
@Override public void exec() {
workInit((short)0);
workInit((short)1);
}
private void workInit(short setting) {
short[] reg = new short[4];
short[] temp;
short a = 0;
for ( a = 0; a <= 3; a++ ) {
reg[a] = readReg(setting, a);
}
a = (short)(0xff & settings[setting]);
temp = doTheWork(a, reg[0], reg[1]);
reg[0] = temp[0];
reg[1] = temp[1];
a = (short)((0xff00 & setting) >> 8);
temp = doTheWork(a, reg[2], reg[3]);
reg[2] = temp[0];
reg[3] = temp[1];
for ( a = 0; a <= 3; a++ ) {
writeReg(setting, a, reg[a]);
}
}
private short[] doTheWork(short setting, short reg0, short reg1) {
short[] out = new short[2];
out[0] = reg0;
out[1] = reg1;
switch (setting) {
case 0x10: // add
out[0] = (short)(reg0 + reg1);
break;
case 0x11: // subt
out[0] = (short)(reg0 - reg1);
break;
case 0x12: // mult
out[0] = (short)(reg0 * reg1);
break;
case 0x13: // div
out[0] = (short)(reg0 / reg1);
out[1] = (short)(reg0 % reg1);
break;
}
return new short[]{reg0, reg1};
}
private short readReg(short setting, short reg) {
short addr = 0;
if (setting == 1) { addr += 0x8; }
addr += (reg * 2);
return Converter.byte2short(read(addr, (short)2));
}
private void writeReg(short setting, short reg, short data) {
short addr = 0;
if (setting == 1) { addr += 0x8; }
addr += (reg * 2);
write(addr, Converter.short2byte(data));
}
}
package me.felinewith.kcpu.memory;
/**
*
* @author jlhawkwell
*/
public class KMemoryRange {
short offset;
short length;
public KMemoryRange(short offset, short length) {
this.offset = offset;
this.length = length;
}
public short getOffset() { return offset; }
public short getLength() { return length; }
}
package me.felinewith.kcpu.memory;
/**
*
* @author jlhawkwell
*/
public class KMemorySecurity extends KMemoryRange {
byte id;
byte level;
public KMemorySecurity(byte id, byte level, short offset, short length) {
super(offset, length);
this.id = id;
this.level = level;
}
public byte getId() { return id; }
public byte getLevel() { return level; }
}
package me.felinewith.kcpu.util;
import java.nio.charset.Charset;
import me.felinewith.kcpu.IDevice;
import me.felinewith.kcpu.IMemory;
/**
*
* @author jlhawkwell
*/
public abstract class BaseDevice extends BaseMemory implements IDevice {
protected String name;
protected short[] settings;
protected IMemory board;
@Override public void init(IMemory system) {
board = system;
}
@Override public short getInterrupt() { return settings[0]; }
@Override public void setInterrupt(short irq) { settings[0] = irq;}
@Override public short getSetting(short setting) {
if ( setting > settings.length ) { return 0x7fff; }
return settings[setting];
}
@Override public void setSetting(short setting, short value) {
if ( setting > settings.length ) { return; }
else if ( setting == 0 ) { return; }
settings[setting] = value;
}
@Override public byte[] getName() { return name.getBytes(Charset.forName("UTF-8")); }
@Override public short length() {
return (short)memory.length;
}
}
package me.felinewith.kcpu.util;
import java.util.Arrays;
import me.felinewith.kcpu.IMemory;
/**
*
* @author jlhawkwell
*/
public abstract class BaseMemory implements IMemory {
protected byte[] memory;
@Override public byte[] read(short offset, short length) {
return Arrays.copyOfRange(memory, offset, offset + length);
}
@Override public void write(short offset, byte[] data) {
short len = (short)data.length;
short a;
short addr;
for (a = 0; a < len; a++) {
addr = (short)(offset + a);
memory[addr] = data[a];
}
}
@Override public void copy(short offsetSrc, short offsetDest, short length, IMemory dest) {
byte[] data = read(offsetSrc, length);
dest.write(offsetDest, data);
}
}
package me.felinewith.kcpu.util;
import java.util.TimerTask;
import me.felinewith.kcpu.IDevice;
/**
*
* @author jlhawkwell
*/
public class HardwareTask extends TimerTask {
IDevice id;
public HardwareTask(IDevice device) {
id = device;
}
@Override public void run() {
id.exec();
}
}
package me.felinewith.kcpu.util;
import me.felinewith.kcpu.IDevice;
/**
*
* @author jlhawkwell
*/
public class IDeviceRunner implements Runnable {
IDevice id;
public IDeviceRunner(IDevice device) {
id = device;
}
@Override public void run() { id.exec(); }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/DECORATION/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.6</version>
</skin>
<custom>
<fluidoSkin>
<sideBarEnabled>true</sideBarEnabled>
<topBarEnabled>true</topBarEnabled>
<navBarStyle>navbar-inverse</navBarStyle>
<copyrightClass>pull-right</copyrightClass>
<breadcrumbDivider>&raquo;</breadcrumbDivider>
<sourceLineNumbersEnabled>true</sourceLineNumbersEnabled>
</fluidoSkin>
</custom>
<version position="right" />
<publishDate position="right" format="yyyy-MM-dd'T'HH:mm:ssZ" />
<!-- poweredBy>
<logo name="VOCASystem.Net" href="https://dev.vocasystem.net/" alt="VOCASystem.Net"
img="http://static.vocasystem.net/vocasystem.net/images/vocasystem.net-black.png" />
</poweredBy -->
<body>
<breadcrumbs>
<item name="${this.name}" href="${this.url}" />
</breadcrumbs>
<menu ref="parent" inherit="top" />
<menu ref="modules" inherit="bottom" />
<menu name="Project Information" ref="reports" inherit="bottom" />
</body>
</project>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!