mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-24 13:05:51 +00:00
Fixes #115
This commit is contained in:
parent
0bd25df977
commit
a8beb8c3e2
@ -21,30 +21,32 @@ public class CodeUploadHandler implements MessageHandler {
|
|||||||
//TODO Should we wait at the end of the tick to modify the CPU ?
|
//TODO Should we wait at the end of the tick to modify the CPU ?
|
||||||
user.getUser().setUserCode((String) json.get("code"));
|
user.getUser().setUserCode((String) json.get("code"));
|
||||||
|
|
||||||
AssemblyResult ar = new Assembler(user.getUser().getCpu().getInstructionSet(),
|
if (user.getUser().getUserCode() != null) {
|
||||||
user.getUser().getCpu().getRegisterSet(),
|
AssemblyResult ar = new Assembler(user.getUser().getCpu().getInstructionSet(),
|
||||||
GameServer.INSTANCE.getConfig()).parse(user.getUser().getUserCode());
|
user.getUser().getCpu().getRegisterSet(),
|
||||||
|
GameServer.INSTANCE.getConfig()).parse(user.getUser().getUserCode());
|
||||||
|
|
||||||
user.getUser().getCpu().getMemory().clear();
|
user.getUser().getCpu().getMemory().clear();
|
||||||
|
|
||||||
//Write assembled code to mem
|
//Write assembled code to mem
|
||||||
char[] assembledCode = ar.getWords();
|
char[] assembledCode = ar.getWords();
|
||||||
|
|
||||||
user.getUser().getCpu().getMemory().write((char) ar.origin, assembledCode, 0, assembledCode.length);
|
user.getUser().getCpu().getMemory().write((char) ar.origin, assembledCode, 0, assembledCode.length);
|
||||||
user.getUser().getCpu().setCodeSectionOffset(ar.getCodeSectionOffset());
|
user.getUser().getCpu().setCodeSectionOffset(ar.getCodeSectionOffset());
|
||||||
|
|
||||||
//Clear keyboard buffer
|
//Clear keyboard buffer
|
||||||
if (user.getUser().getControlledUnit() != null &&
|
if (user.getUser().getControlledUnit() != null &&
|
||||||
user.getUser().getControlledUnit().getKeyboardBuffer() != null) {
|
user.getUser().getControlledUnit().getKeyboardBuffer() != null) {
|
||||||
user.getUser().getControlledUnit().getKeyboardBuffer().clear();
|
user.getUser().getControlledUnit().getKeyboardBuffer().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JSONObject response = new JSONObject();
|
||||||
|
response.put("t", "codeResponse");
|
||||||
|
response.put("bytes", ar.bytes.length);
|
||||||
|
|
||||||
|
user.getWebSocket().send(response.toJSONString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSONObject response = new JSONObject();
|
|
||||||
response.put("t", "codeResponse");
|
|
||||||
response.put("bytes", ar.bytes.length);
|
|
||||||
|
|
||||||
user.getWebSocket().send(response.toJSONString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user