mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-16 09:16:44 +00:00
parent
c5abe2efc5
commit
9979986c6a
@ -152,7 +152,7 @@ public class CPU implements JSONSerialisable{
|
||||
// LogManager.LOGGER.info(instruction.getMnemonic());
|
||||
}
|
||||
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) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.server.assembly;
|
||||
|
||||
import net.simon987.server.assembly.instruction.*;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -31,6 +32,7 @@ public class DefaultInstructionSet implements InstructionSet {
|
||||
add(new AndInstruction());
|
||||
add(new OrInstruction());
|
||||
add(new ShlInstruction());
|
||||
add(new SalInstruction()); //Alias is added
|
||||
add(new ShrInstruction());
|
||||
add(new XorInstruction());
|
||||
add(new TestInstruction());
|
||||
@ -85,6 +87,12 @@ public class DefaultInstructionSet implements InstructionSet {
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,11 @@ import net.simon987.server.assembly.Instruction;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
|
||||
/**
|
||||
* +-----------------+
|
||||
* | |
|
||||
* CF < 0<0<0<0<0<0<0<0 <-+
|
||||
*/
|
||||
public class RolInstruction extends Instruction {
|
||||
|
||||
private static final int OPCODE = 35;
|
||||
@ -15,7 +20,7 @@ public class RolInstruction extends Instruction {
|
||||
@Override
|
||||
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 signBit = (destination & 0x8000);
|
||||
@ -34,12 +39,12 @@ public class RolInstruction extends Instruction {
|
||||
@Override
|
||||
public Status execute(Target dst, int dstIndex, int src, Status status) {
|
||||
|
||||
|
||||
int count = src % 16;
|
||||
int destination = dst.get(dstIndex);
|
||||
int signBit = (destination & 0x8000);
|
||||
|
||||
destination = (destination << src) | (destination >>> (16 - src));
|
||||
if (src == 1) {
|
||||
destination = (destination << count) | (destination >>> (16 - count));
|
||||
if (count == 1) {
|
||||
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
|
||||
}
|
||||
status.setCarryFlag((destination & 1) == 1);
|
||||
|
@ -5,9 +5,10 @@ import net.simon987.server.assembly.Status;
|
||||
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 {
|
||||
|
||||
@ -20,7 +21,7 @@ public class RorInstruction extends Instruction {
|
||||
@Override
|
||||
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 signBit = (destination & 0x8000);
|
||||
@ -37,11 +38,12 @@ public class RorInstruction extends Instruction {
|
||||
@Override
|
||||
public Status execute(Target dst, int dstIndex, int src, Status status) {
|
||||
|
||||
int count = src % 16;
|
||||
int destination = dst.get(dstIndex);
|
||||
int signBit = (destination & 0x8000);
|
||||
|
||||
destination = (destination >>> src) | (destination << (16 - src));
|
||||
if (src == 1) {
|
||||
destination = (destination >>> count) | (destination << (16 - count));
|
||||
if (count == 1) {
|
||||
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
|
||||
}
|
||||
dst.set(dstIndex, destination);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -5,15 +5,13 @@ import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Target;
|
||||
import net.simon987.server.assembly.Util;
|
||||
|
||||
/**
|
||||
* Created by Gilbert Fortier on 3/12/2017.
|
||||
*/
|
||||
|
||||
public class XorInstruction extends Instruction {
|
||||
|
||||
/**
|
||||
* Opcode of the instruction
|
||||
*/
|
||||
public static final int OPCODE = 5;
|
||||
public static final int OPCODE = 38;
|
||||
|
||||
public XorInstruction() {
|
||||
super("xor", OPCODE);
|
||||
|
@ -3,7 +3,6 @@ package net.simon987.server.logging;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
@ -16,24 +15,13 @@ public class GenericFormatter extends Formatter {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (record.getLevel() == Level.FINE) {
|
||||
//Chat message, maximum 50 char per line
|
||||
if (record.getMessage().length() > 50) {
|
||||
sb.append(record.getMessage().substring(0, 50));
|
||||
sb.append('\n');
|
||||
sb.append(record.getMessage().substring(50));
|
||||
} 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
|
||||
//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');
|
||||
|
||||
sb.append(String.format("[%s] [%s] %s", sdf.format(date), record.getLevel(), record.getMessage()));
|
||||
sb.append('\n');
|
||||
}
|
||||
|
||||
|
||||
return sb.toString();
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user