lonestar

0x10c-inspired space game based on the DCPU-16
git clone git://squid-tech.com/lonestar.git
Log | Files | Refs | README

commit 6bf2de24a87667c5bb263294945bde40f9d94982
parent 9a168bbc395e4a26f15025cad4bb96ed59885d4e
Author: Josh Moore <jxm5210@rit.edu>
Date:   Tue, 19 Nov 2019 19:17:17 -0500

Fix JSR, add refactored device script files

Diffstat:
Asrc/LoneStar/Assets/Devices/LightDevice/LightScript.cs | 38++++++++++++++++++++++++++++++++++++++
Asrc/LoneStar/Assets/Devices/LightDevice/LightScript.cs.meta | 11+++++++++++
Msrc/LoneStar/Assets/Scripts/DCPU16Controller.cs | 6+++++-
Asrc/LoneStar/Assets/Scripts/DeviceScript.cs | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asrc/LoneStar/Assets/Scripts/DeviceScript.cs.meta | 11+++++++++++
5 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/src/LoneStar/Assets/Devices/LightDevice/LightScript.cs b/src/LoneStar/Assets/Devices/LightDevice/LightScript.cs @@ -0,0 +1,38 @@ +´╗┐using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// LIGHT SPECS +// A = 0 light off +// A = 1 light on + +public class LightScript : DeviceScript +{ + void Start() + { + // the ID of the company that manufactures this device + MANUFACTURER_ID = 0xDEADBEEF; + // the device ID of this device + DEVICE_ID = 0xAAAABBBB; + // hardware version + DEVICE_VERSION = 0x0001; + + this.gameObject.transform.Find("Sphere").GetComponent<Renderer>().material.color = Color.white; + } + + // handle a hardware interrupt + // GP_REG corresponds to the general-purpose DCPU registers + public override void HWI(GameObject dcpu, ushort[] GP_REG) + { + if (GP_REG[0] == 1) + { + this.gameObject.transform.Find("PointLight").GetComponent<Light>().enabled = true; + this.gameObject.transform.Find("Sphere").gameObject.GetComponent<Renderer>().material.color = this.gameObject.transform.Find("PointLight").GetComponent<Light>().color; + } + else + { + this.gameObject.transform.Find("PointLight").GetComponent<Light>().enabled = false; + this.gameObject.transform.Find("Sphere").gameObject.GetComponent<Renderer>().material.color = Color.white; + } + } +} diff --git a/src/LoneStar/Assets/Devices/LightDevice/LightScript.cs.meta b/src/LoneStar/Assets/Devices/LightDevice/LightScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cfffeb104851e534a86226facc3354a7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/LoneStar/Assets/Scripts/DCPU16Controller.cs b/src/LoneStar/Assets/Scripts/DCPU16Controller.cs @@ -798,7 +798,11 @@ public class DCPU16Controller : NetworkBehaviour { case 0x01: // JSR a - MEM[--REG_SP] = REG_PC; + MEM[--REG_SP] = (ushort)(REG_PC + getInstructionSize( + (byte)((MEM[REG_PC] >> 10) & 0x3F), + (byte)((MEM[REG_PC] >> 5) & 0x1F), + (byte)(MEM[REG_PC] & 0x1F) + )); REG_PC = READ(a); INC_PC = false; break; diff --git a/src/LoneStar/Assets/Scripts/DeviceScript.cs b/src/LoneStar/Assets/Scripts/DeviceScript.cs @@ -0,0 +1,47 @@ +´╗┐using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Mirror; + +public class DeviceScript : NetworkBehaviour +{ + // Set these fields to information about your device in your inherited class + // the ID of the company that manufactures this device + public uint MANUFACTURER_ID; + // the device ID of this device + public uint DEVICE_ID; + // hardware version + public ushort DEVICE_VERSION; + + // handle a hardware interrupt + // GP_REG corresponds to the general-purpose DCPU registers + public virtual void HWI(GameObject dcpu, ushort[] GP_REG) + { + // override this function and add your HWI response here + } + + // respond to request for hardware information + // do not override this function + public void HWQ(GameObject dcpu, ushort[] GP_REG) + { + ushort[] info = new ushort[8]; + + // hardware ID (registers A+(B<<16)) + info[0] = (ushort)(DEVICE_ID & 0xFFFF); + info[1] = (ushort)((DEVICE_ID >> 16) & 0xFFFF); + + // device version (register C) + info[2] = DEVICE_VERSION; + + // manufacturer ID (registers X+(Y<<16)) + info[3] = (ushort)(MANUFACTURER_ID & 0xFFFF); + info[4] = (ushort)((MANUFACTURER_ID >> 16) & 0xFFFF); + + info[5] = GP_REG[5]; + info[6] = GP_REG[6]; + info[7] = GP_REG[7]; + + // return the information to the requesting DCPU + dcpu.GetComponent<DCPU16Controller>().returnHW(info); + } +} diff --git a/src/LoneStar/Assets/Scripts/DeviceScript.cs.meta b/src/LoneStar/Assets/Scripts/DeviceScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 05244e7917287274b86e15ab7d2a5ce7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: