Added SAL Instruction #6. Added ROL/ROR Instructions #7.

This commit is contained in:
simon 2017-11-13 17:51:16 -05:00
parent c5abe2efc5
commit 9979986c6a
8 changed files with 48 additions and 34 deletions

View File

@ -152,7 +152,7 @@ public class CPU implements JSONSerialisable{
// LogManager.LOGGER.info(instruction.getMnemonic()); // LogManager.LOGGER.info(instruction.getMnemonic());
} }
double elapsed = (System.currentTimeMillis() - startTime); double elapsed = (System.currentTimeMillis() - startTime);
LogManager.LOGGER.fine("----------\n" + counter + " instruction in " + elapsed + "ms : " + (double) counter / (elapsed / 1000) / 1000000 + "MHz"); LogManager.LOGGER.fine(counter + " instruction in " + elapsed + "ms : " + (double) counter / (elapsed / 1000) / 1000000 + "MHz");
} }
public void executeInstruction(Instruction instruction, int source, int destination) { public void executeInstruction(Instruction instruction, int source, int destination) {

View File

@ -1,6 +1,7 @@
package net.simon987.server.assembly; package net.simon987.server.assembly;
import net.simon987.server.assembly.instruction.*; import net.simon987.server.assembly.instruction.*;
import net.simon987.server.logging.LogManager;
import java.util.HashMap; import java.util.HashMap;
@ -31,6 +32,7 @@ public class DefaultInstructionSet implements InstructionSet {
add(new AndInstruction()); add(new AndInstruction());
add(new OrInstruction()); add(new OrInstruction());
add(new ShlInstruction()); add(new ShlInstruction());
add(new SalInstruction()); //Alias is added
add(new ShrInstruction()); add(new ShrInstruction());
add(new XorInstruction()); add(new XorInstruction());
add(new TestInstruction()); add(new TestInstruction());
@ -85,6 +87,12 @@ public class DefaultInstructionSet implements InstructionSet {
@Override @Override
public void add(Instruction instruction) { public void add(Instruction instruction) {
instructionMap.put(instruction.getOpCode(), instruction); if (instructionMap.containsKey(instruction.getOpCode())) {
LogManager.LOGGER.fine(instruction.getMnemonic() + " instruction is an alias for " +
instructionMap.get(instruction.getOpCode()).getMnemonic());
} else {
instructionMap.put(instruction.getOpCode(), instruction);
}
} }
} }

View File

@ -4,6 +4,11 @@ import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target; import net.simon987.server.assembly.Target;
/**
* +-----------------+
* | |
* CF < 0<0<0<0<0<0<0<0 <-+
*/
public class RolInstruction extends Instruction { public class RolInstruction extends Instruction {
private static final int OPCODE = 35; private static final int OPCODE = 35;
@ -15,7 +20,7 @@ public class RolInstruction extends Instruction {
@Override @Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int count = src.get(srcIndex); int count = src.get(srcIndex) % 16;
int destination = dst.get(dstIndex); int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000); int signBit = (destination & 0x8000);
@ -34,12 +39,12 @@ public class RolInstruction extends Instruction {
@Override @Override
public Status execute(Target dst, int dstIndex, int src, Status status) { public Status execute(Target dst, int dstIndex, int src, Status status) {
int count = src % 16;
int destination = dst.get(dstIndex); int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000); int signBit = (destination & 0x8000);
destination = (destination << src) | (destination >>> (16 - src)); destination = (destination << count) | (destination >>> (16 - count));
if (src == 1) { if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
} }
status.setCarryFlag((destination & 1) == 1); status.setCarryFlag((destination & 1) == 1);

View File

@ -5,9 +5,10 @@ import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target; import net.simon987.server.assembly.Target;
/** /**
* Rotate right * +-----------------+
* <br> * | |
* ->  destination -(CF)>  * +-> 0>0>0>0>0>0>0>0 > CF
*
*/ */
public class RorInstruction extends Instruction { public class RorInstruction extends Instruction {
@ -20,7 +21,7 @@ public class RorInstruction extends Instruction {
@Override @Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) { public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int count = src.get(srcIndex); int count = src.get(srcIndex) % 16;
int destination = dst.get(dstIndex); int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000); int signBit = (destination & 0x8000);
@ -37,11 +38,12 @@ public class RorInstruction extends Instruction {
@Override @Override
public Status execute(Target dst, int dstIndex, int src, Status status) { public Status execute(Target dst, int dstIndex, int src, Status status) {
int count = src % 16;
int destination = dst.get(dstIndex); int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000); int signBit = (destination & 0x8000);
destination = (destination >>> src) | (destination << (16 - src)); destination = (destination >>> count) | (destination << (16 - count));
if (src == 1) { if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
} }
dst.set(dstIndex, destination); dst.set(dstIndex, destination);

View File

@ -0,0 +1,13 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
/**
* Alias of SHL instruction
*/
public class SalInstruction extends Instruction {
public SalInstruction() {
super("sal", ShlInstruction.OPCODE);
}
}

View File

@ -5,15 +5,13 @@ import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target; import net.simon987.server.assembly.Target;
import net.simon987.server.assembly.Util; import net.simon987.server.assembly.Util;
/**
* Created by Gilbert Fortier on 3/12/2017.
*/
public class XorInstruction extends Instruction { public class XorInstruction extends Instruction {
/** /**
* Opcode of the instruction * Opcode of the instruction
*/ */
public static final int OPCODE = 5; public static final int OPCODE = 38;
public XorInstruction() { public XorInstruction() {
super("xor", OPCODE); super("xor", OPCODE);

View File

@ -3,7 +3,6 @@ package net.simon987.server.logging;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
/** /**
@ -16,24 +15,13 @@ public class GenericFormatter extends Formatter {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (record.getLevel() == Level.FINE) { //Regular record
//Chat message, maximum 50 char per line Date date = new Date();
if (record.getMessage().length() > 50) { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss:SSS"); //ex. 11/25 22:03:59:010
sb.append(record.getMessage().substring(0, 50));
sb.append('\n'); sb.append(String.format("[%s] [%s] %s", sdf.format(date), record.getLevel(), record.getMessage()));
sb.append(record.getMessage().substring(50)); sb.append('\n');
} else {
sb.append(record.getMessage());
}
sb.append('\n');
} else {
//Regular record
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss:SSS"); //ex. 11/25 22:03:59:010
sb.append(String.format("[%s] [%s] %s", sdf.format(date), record.getLevel(), record.getMessage()));
sb.append('\n');
}
return sb.toString(); return sb.toString();

Binary file not shown.