mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
Added ROL/ROR Instructions #7 as well as JC/JNC and JO/JNO instructions
This commit is contained in:
parent
fdfa568e07
commit
c5abe2efc5
@ -104,7 +104,8 @@ public class GameServer implements Runnable {
|
|||||||
gameUniverse.incrementTime();
|
gameUniverse.incrementTime();
|
||||||
|
|
||||||
//Process user code
|
//Process user code
|
||||||
for(User user : gameUniverse.getUsers()){
|
ArrayList<User> users_ = gameUniverse.getUsers();
|
||||||
|
for (User user : users_) {
|
||||||
|
|
||||||
if(user.getCpu() != null){
|
if(user.getCpu() != null){
|
||||||
user.getCpu().reset();
|
user.getCpu().reset();
|
||||||
|
@ -271,7 +271,7 @@ public class Assembler {
|
|||||||
* usage: constant_name EQU <immediate_value>
|
* usage: constant_name EQU <immediate_value>
|
||||||
* A constant treated the same way as a label.
|
* A constant treated the same way as a label.
|
||||||
*/
|
*/
|
||||||
|
line = line.trim();
|
||||||
String[] tokens = line.split("\\s+");
|
String[] tokens = line.split("\\s+");
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,6 +94,10 @@ public class CPU implements JSONSerialisable{
|
|||||||
instructionSet.add(new HwiInstruction(this));
|
instructionSet.add(new HwiInstruction(this));
|
||||||
instructionSet.add(new HwqInstruction(this));
|
instructionSet.add(new HwqInstruction(this));
|
||||||
instructionSet.add(new XchgInstruction(this));
|
instructionSet.add(new XchgInstruction(this));
|
||||||
|
instructionSet.add(new JcInstruction(this));
|
||||||
|
instructionSet.add(new JncInstruction(this));
|
||||||
|
instructionSet.add(new JnoInstruction(this));
|
||||||
|
instructionSet.add(new JoInstruction(this));
|
||||||
|
|
||||||
status = new Status();
|
status = new Status();
|
||||||
memory = new Memory(config.getInt("memory_size"));
|
memory = new Memory(config.getInt("memory_size"));
|
||||||
|
@ -37,6 +37,8 @@ public class DefaultInstructionSet implements InstructionSet {
|
|||||||
add(new CmpInstruction());
|
add(new CmpInstruction());
|
||||||
add(new NegInstruction());
|
add(new NegInstruction());
|
||||||
add(new NotInstruction());
|
add(new NotInstruction());
|
||||||
|
add(new RorInstruction());
|
||||||
|
add(new RolInstruction());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
|
import net.simon987.server.assembly.CPU;
|
||||||
|
import net.simon987.server.assembly.Instruction;
|
||||||
|
import net.simon987.server.assembly.Status;
|
||||||
|
import net.simon987.server.assembly.Target;
|
||||||
|
|
||||||
|
public class JcInstruction extends Instruction {
|
||||||
|
|
||||||
|
private static final int OPCODE = 33;
|
||||||
|
|
||||||
|
private CPU cpu;
|
||||||
|
|
||||||
|
public JcInstruction(CPU cpu) {
|
||||||
|
super("jc", OPCODE);
|
||||||
|
this.cpu = cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target src, int srcIndex, Status status) {
|
||||||
|
if (status.isCarryFlag()) {
|
||||||
|
cpu.setIp((char) src.get(srcIndex));
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(int src, Status status) {
|
||||||
|
if (status.isCarryFlag()) {
|
||||||
|
cpu.setIp((char) src);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
|
import net.simon987.server.assembly.CPU;
|
||||||
|
import net.simon987.server.assembly.Instruction;
|
||||||
|
import net.simon987.server.assembly.Status;
|
||||||
|
import net.simon987.server.assembly.Target;
|
||||||
|
|
||||||
|
public class JncInstruction extends Instruction {
|
||||||
|
|
||||||
|
private static final int OPCODE = 34;
|
||||||
|
|
||||||
|
private CPU cpu;
|
||||||
|
|
||||||
|
public JncInstruction(CPU cpu) {
|
||||||
|
super("jnc", OPCODE);
|
||||||
|
this.cpu = cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target src, int srcIndex, Status status) {
|
||||||
|
if (!status.isCarryFlag()) {
|
||||||
|
cpu.setIp((char) src.get(srcIndex));
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(int src, Status status) {
|
||||||
|
if (!status.isCarryFlag()) {
|
||||||
|
cpu.setIp((char) src);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
|
import net.simon987.server.assembly.CPU;
|
||||||
|
import net.simon987.server.assembly.Instruction;
|
||||||
|
import net.simon987.server.assembly.Status;
|
||||||
|
import net.simon987.server.assembly.Target;
|
||||||
|
|
||||||
|
|
||||||
|
public class JnoInstruction extends Instruction {
|
||||||
|
|
||||||
|
private static final int OPCODE = 37;
|
||||||
|
|
||||||
|
private CPU cpu;
|
||||||
|
|
||||||
|
public JnoInstruction(CPU cpu) {
|
||||||
|
super("jno", OPCODE);
|
||||||
|
this.cpu = cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target src, int srcIndex, Status status) {
|
||||||
|
if (!status.isOverflowFlag()) {
|
||||||
|
cpu.setIp((char) src.get(srcIndex));
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(int src, Status status) {
|
||||||
|
if (!status.isOverflowFlag()) {
|
||||||
|
cpu.setIp((char) src);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
|
import net.simon987.server.assembly.CPU;
|
||||||
|
import net.simon987.server.assembly.Instruction;
|
||||||
|
import net.simon987.server.assembly.Status;
|
||||||
|
import net.simon987.server.assembly.Target;
|
||||||
|
|
||||||
|
public class JoInstruction extends Instruction {
|
||||||
|
|
||||||
|
private static final int OPCODE = 36;
|
||||||
|
|
||||||
|
private CPU cpu;
|
||||||
|
|
||||||
|
public JoInstruction(CPU cpu) {
|
||||||
|
super("jo", OPCODE);
|
||||||
|
this.cpu = cpu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target src, int srcIndex, Status status) {
|
||||||
|
if (status.isOverflowFlag()) {
|
||||||
|
cpu.setIp((char) src.get(srcIndex));
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(int src, Status status) {
|
||||||
|
if (status.isOverflowFlag()) {
|
||||||
|
cpu.setIp((char) src);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
|
import net.simon987.server.assembly.Instruction;
|
||||||
|
import net.simon987.server.assembly.Status;
|
||||||
|
import net.simon987.server.assembly.Target;
|
||||||
|
|
||||||
|
public class RolInstruction extends Instruction {
|
||||||
|
|
||||||
|
private static final int OPCODE = 35;
|
||||||
|
|
||||||
|
public RolInstruction() {
|
||||||
|
super("rol", OPCODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
|
||||||
|
|
||||||
|
int count = src.get(srcIndex);
|
||||||
|
|
||||||
|
int destination = dst.get(dstIndex);
|
||||||
|
int signBit = (destination & 0x8000);
|
||||||
|
|
||||||
|
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);
|
||||||
|
dst.set(dstIndex, destination);
|
||||||
|
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target dst, int dstIndex, int src, Status status) {
|
||||||
|
|
||||||
|
|
||||||
|
int destination = dst.get(dstIndex);
|
||||||
|
int signBit = (destination & 0x8000);
|
||||||
|
|
||||||
|
destination = (destination << src) | (destination >>> (16 - src));
|
||||||
|
if (src == 1) {
|
||||||
|
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
|
||||||
|
}
|
||||||
|
status.setCarryFlag((destination & 1) == 1);
|
||||||
|
dst.set(dstIndex, destination);
|
||||||
|
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package net.simon987.server.assembly.instruction;
|
||||||
|
|
||||||
|
import net.simon987.server.assembly.Instruction;
|
||||||
|
import net.simon987.server.assembly.Status;
|
||||||
|
import net.simon987.server.assembly.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotate right
|
||||||
|
* <br>
|
||||||
|
* -> destination -(CF)>
|
||||||
|
*/
|
||||||
|
public class RorInstruction extends Instruction {
|
||||||
|
|
||||||
|
private static final int OPCODE = 32;
|
||||||
|
|
||||||
|
public RorInstruction() {
|
||||||
|
super("ror", OPCODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
|
||||||
|
|
||||||
|
int count = src.get(srcIndex);
|
||||||
|
|
||||||
|
int destination = dst.get(dstIndex);
|
||||||
|
int signBit = (destination & 0x8000);
|
||||||
|
|
||||||
|
destination = (destination >>> count) | (destination << (16 - count));
|
||||||
|
if (count == 1) {
|
||||||
|
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
|
||||||
|
}
|
||||||
|
dst.set(dstIndex, destination);
|
||||||
|
status.setCarryFlag((destination & 0x8000) == 0x8000);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status execute(Target dst, int dstIndex, int src, Status status) {
|
||||||
|
|
||||||
|
int destination = dst.get(dstIndex);
|
||||||
|
int signBit = (destination & 0x8000);
|
||||||
|
|
||||||
|
destination = (destination >>> src) | (destination << (16 - src));
|
||||||
|
if (src == 1) {
|
||||||
|
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
|
||||||
|
}
|
||||||
|
dst.set(dstIndex, destination);
|
||||||
|
status.setCarryFlag((destination & 0x8000) == 0x8000);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
@ -129,8 +129,17 @@ public class GameUniverse implements JSONSerialisable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an object by id
|
||||||
|
* <br>
|
||||||
|
* ConcurrentModificationException risk when inside game loop
|
||||||
|
*
|
||||||
|
* @param id id of the game object
|
||||||
|
* @return GameObject, null if not found
|
||||||
|
*/
|
||||||
public GameObject getObject(int id) {
|
public GameObject getObject(int id) {
|
||||||
|
|
||||||
|
//
|
||||||
for (World world : worlds) {
|
for (World world : worlds) {
|
||||||
for(GameObject object : world.getGameObjects()){
|
for(GameObject object : world.getGameObjects()){
|
||||||
if(object.getObjectId() == id){
|
if(object.getObjectId() == id){
|
||||||
@ -161,12 +170,14 @@ public class GameUniverse implements JSONSerialisable{
|
|||||||
|
|
||||||
JSONArray worlds = new JSONArray();
|
JSONArray worlds = new JSONArray();
|
||||||
|
|
||||||
for(World world : this.worlds){
|
ArrayList<World> worlds_ = new ArrayList<>(this.worlds);
|
||||||
|
for (World world : worlds_){
|
||||||
worlds.add(world.serialise());
|
worlds.add(world.serialise());
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray users = new JSONArray();
|
JSONArray users = new JSONArray();
|
||||||
for(User user : this.users){
|
ArrayList<User> users_ = new ArrayList<User>(this.users);
|
||||||
|
for (User user : users_){
|
||||||
if (!user.isGuest()) {
|
if (!user.isGuest()) {
|
||||||
users.add(user.serialise());
|
users.add(user.serialise());
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,8 @@ public class World implements JSONSerialisable{
|
|||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
JSONArray objects = new JSONArray();
|
JSONArray objects = new JSONArray();
|
||||||
for(GameObject obj : gameObjects){
|
ArrayList<GameObject> gameObjects_ = new ArrayList<>(gameObjects);
|
||||||
|
for (GameObject obj : gameObjects_) {
|
||||||
objects.add(obj.serialise());
|
objects.add(obj.serialise());
|
||||||
}
|
}
|
||||||
json.put("objects", objects);
|
json.put("objects", objects);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user