mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Added Random number generator
This commit is contained in:
parent
f98e0701eb
commit
e2ed744479
@ -64,7 +64,7 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
|
||||
//Write to memory
|
||||
byte[] mem = getCpu().getMemory().getBytes();
|
||||
|
||||
int counter = 0; //todo get memory address from config/constant
|
||||
int counter = MEMORY_PATH_START;
|
||||
|
||||
if (nodes != null) {
|
||||
|
||||
|
3
Plugin Misc HW/plugin.properties
Normal file
3
Plugin Misc HW/plugin.properties
Normal file
@ -0,0 +1,3 @@
|
||||
classpath=net.simon987.mischwplugin.MiscHWPlugin
|
||||
name=Misc HW Plugin
|
||||
version=1.0
|
@ -0,0 +1,31 @@
|
||||
package net.simon987.mischwplugin;
|
||||
|
||||
import net.simon987.mischwplugin.event.CpuInitialisationListener;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.io.CpuHardwareDeserializer;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class MiscHWPlugin extends ServerPlugin implements CpuHardwareDeserializer {
|
||||
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
listeners.add(new CpuInitialisationListener());
|
||||
|
||||
LogManager.LOGGER.info("Initialised Misc Hardware Plugin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CpuHardware deserializeHardware(JSONObject hwJson) {
|
||||
int hwid = (int) (long) hwJson.get("hwid");
|
||||
|
||||
switch (hwid) {
|
||||
case RandomNumberGenerator.HWID:
|
||||
return RandomNumberGenerator.deserialize(hwJson);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package net.simon987.mischwplugin;
|
||||
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomNumberGenerator extends CpuHardware {
|
||||
|
||||
public static final char HWID = 0x0007;
|
||||
|
||||
public static final char DEFAULT_ADDRESS = 0x0007;
|
||||
|
||||
private Random random;
|
||||
|
||||
public RandomNumberGenerator() {
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInterrupt(Status status) {
|
||||
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(random.nextInt(0xFFFF));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getId() {
|
||||
return HWID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("hwid", (int) HWID);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static RandomNumberGenerator deserialize(JSONObject hwJSON) {
|
||||
return new RandomNumberGenerator();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.simon987.mischwplugin.event;
|
||||
|
||||
import net.simon987.mischwplugin.RandomNumberGenerator;
|
||||
import net.simon987.server.assembly.CPU;
|
||||
import net.simon987.server.event.CpuInitialisationEvent;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
|
||||
public class CpuInitialisationListener implements GameEventListener {
|
||||
|
||||
@Override
|
||||
public Class getListenedEventType() {
|
||||
return CpuInitialisationEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
|
||||
CPU cpu = (CPU) event.getSource();
|
||||
|
||||
cpu.attachHardware(new RandomNumberGenerator(), RandomNumberGenerator.DEFAULT_ADDRESS);
|
||||
}
|
||||
}
|
@ -20,10 +20,15 @@ public class Main {
|
||||
* - Instruction set
|
||||
* -
|
||||
*/
|
||||
//TODO: Random number generator
|
||||
//TODO: Clock hardware
|
||||
//TODO: Floppy drive hardware (and item?)
|
||||
//TODO: LEA instruction
|
||||
//TODO: NOT instruction
|
||||
//TODO: Battery Hardware
|
||||
|
||||
//---------------------------------
|
||||
|
||||
//TODO: Random number generator
|
||||
//TODO: favicon
|
||||
//TODO: Email verification
|
||||
//TODO: Real account page
|
||||
@ -35,9 +40,6 @@ public class Main {
|
||||
* - INT/INTO instruction
|
||||
* - IRET instruction
|
||||
*/
|
||||
//TODO: Clock hardware
|
||||
//TODO: Floppy drive hardware (and item?)
|
||||
//TODO: LEA instruction
|
||||
//TODO: XCHG instruction
|
||||
//TODO: SAL/SAR instruction
|
||||
//TODO: ROL/ROR/RCL/RCR instruction
|
||||
@ -56,7 +58,6 @@ public class Main {
|
||||
//TODO: Multiple Biomass style (and yield, rarity)
|
||||
//TODO: Clean sprites
|
||||
//TODO: Auto-resize
|
||||
//TODO: Battery Hardware
|
||||
|
||||
|
||||
LogManager.initialize();
|
||||
|
@ -7,9 +7,9 @@ mysql_url=jdbc:mysql://localhost:3306/mar?useSSL=false
|
||||
save_interval=10
|
||||
# Web server port
|
||||
webSocket_port=8887
|
||||
webSocket_host=localhost
|
||||
webSocket_host=0.0.0.0
|
||||
|
||||
use_secure_webSocket=1
|
||||
use_secure_webSocket=0
|
||||
cert_path=certificates
|
||||
# ----------------------------------------------
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user