mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Added Clock
This commit is contained in:
parent
e2ed744479
commit
3d9bfb2a42
42
Plugin Misc HW/src/net/simon987/mischwplugin/Clock.java
Normal file
42
Plugin Misc HW/src/net/simon987/mischwplugin/Clock.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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
BIN
plugins/Plugin Misc HW.jar
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user