From df86ebdf3820e8ff88c4a54515602dba3a5bfb04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Tue, 9 Dec 2014 13:49:33 +0100 Subject: [PATCH] Added flash.lua program to make programming EEPROMs a little more comfortable. --- .../opencomputers/loot/OpenOS/bin/flash.lua | 55 +++++++++++++++++++ .../li/cil/oc/server/component/EEPROM.scala | 3 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua new file mode 100644 index 000000000..bc6c304c6 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/flash.lua @@ -0,0 +1,55 @@ +local component = require("component") +local shell = require("shell") + +local args, options = shell.parse(...) + +if #args < 1 and not options.l then + io.write("Usage: flash [-ql] [] [label]\n") + io.write(" q: quiet mode, don't ask questions.\n") + io.write(" l: print current contents of installed EEPROM.") + return +end + +if options.l then + io.write(component.eeprom.get()) + return +end + +local file = assert(io.open(args[1], "rb")) + +if not options.q then + io.write("Insert the EEPROM you would like to flash.\n") + io.write("When ready to write, type `y` to confirm.\n") + repeat + local response = io.read() + until response and response:lower():sub(1, 1) == "y" + io.write("Beginning to flash EEPROM.") +end + +local eeprom = component.eeprom + +if not options.q then + io.write("Beginning to flash EEPROM " .. eeprom.address .. ".\n") + io.write("Please do NOT power down or restart your computer during this operation!\n") +end + +local bios = file:read("*a") +file:close() + +eeprom.set(bios) + +local label = args[2] +if not options.q and not label then + io.write("Enter new label for this EEPROM. Leave input blank to leave the label unchanged.\n") + label = io.read() +end +if label then + eeprom.setLabel(label) + if not options.q then + io.write("Set label to '" .. eeprom.getLabel() .. "'.\n") + end +end + +if not options.q then + io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n") +end \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/server/component/EEPROM.scala b/src/main/scala/li/cil/oc/server/component/EEPROM.scala index adb30e230..7d668d125 100644 --- a/src/main/scala/li/cil/oc/server/component/EEPROM.scala +++ b/src/main/scala/li/cil/oc/server/component/EEPROM.scala @@ -41,7 +41,8 @@ class EEPROM extends prefab.ManagedEnvironment { @Callback(doc = """function(data:string) -- Set the label of the EEPROM.""") def setLabel(context: Context, args: Arguments): Array[AnyRef] = { - label = args.checkString(0).take(16) + label = args.optString(0, "EEPROM").trim.take(16) + if (label.length == 0) label = "EEPROM" null }