Added Clock

This commit is contained in:
simon 2017-11-11 15:07:28 -05:00
parent e2ed744479
commit 3d9bfb2a42
4 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,42 @@
package net.simon987.mischwplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Util;
import org.json.simple.JSONObject;
public class Clock extends CpuHardware {
public static final char HWID = 0x0008;
public static final char DEFAULT_ADDRESS = 0x0008;
@Override
public void handleInterrupt(Status status) {
int time = (int) GameServer.INSTANCE.getGameUniverse().getTime();
//Will need to be changed to quadword in about 136 years
getCpu().getRegisterSet().getRegister("B").setValue(Util.getHigherWord(time));
getCpu().getRegisterSet().getRegister("C").setValue(Util.getLowerWord(time));
}
@Override
public char getId() {
return HWID;
}
public static Clock deserialize(JSONObject hwJSON) {
return new Clock();
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
return json;
}
}

View File

@ -24,6 +24,8 @@ public class MiscHWPlugin extends ServerPlugin implements CpuHardwareDeserialize
switch (hwid) {
case RandomNumberGenerator.HWID:
return RandomNumberGenerator.deserialize(hwJson);
case Clock.HWID:
return Clock.deserialize(hwJson);
}
return null;

View File

@ -1,5 +1,6 @@
package net.simon987.mischwplugin.event;
import net.simon987.mischwplugin.Clock;
import net.simon987.mischwplugin.RandomNumberGenerator;
import net.simon987.server.assembly.CPU;
import net.simon987.server.event.CpuInitialisationEvent;
@ -19,5 +20,6 @@ public class CpuInitialisationListener implements GameEventListener {
CPU cpu = (CPU) event.getSource();
cpu.attachHardware(new RandomNumberGenerator(), RandomNumberGenerator.DEFAULT_ADDRESS);
cpu.attachHardware(new Clock(), Clock.DEFAULT_ADDRESS);
}
}

BIN
plugins/Plugin Misc HW.jar Normal file

Binary file not shown.