summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/cheat/init.lua
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2016-04-07 10:37:44 -0500
committer cracyc <cracyc@users.noreply.github.com>2016-04-07 10:38:51 -0500
commit4edb50a92aeb8129bab5611b2ee27129288377ed (patch)
tree84058830658e266f4088413979c64df1b0474e29 /plugins/cheat/init.lua
parent1fcb7dd0e07de5d9fb968e1212f7155c40557d83 (diff)
plugin/cheat: better conversion (nw)
Diffstat (limited to 'plugins/cheat/init.lua')
-rw-r--r--plugins/cheat/init.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index 459657ea122..705ecca77cb 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -120,10 +120,34 @@ function cheat.startplugin()
output[#output + 1] = { type = "box", scr = screen, x1 = x1, x2 = x2, y1 = y1, y2 = y2, bgcolor = bgcolor, linecolor = linecolor }
end
+ local function tobcd(val)
+ local result = 0
+ local shift = 0
+ while val ~= 0 do
+ result = result + ((val % 10) << shift)
+ val = val / 10
+ shift = shift + 4
+ end
+ return result
+ end
+
+ local function frombcd(val)
+ local result = 0
+ local mul = 1
+ while val ~= 0 do
+ result = result + ((val % 16) * mul)
+ val = val >> 4
+ mul = mul * 10
+ end
+ return result
+ end
+
local function parse_cheat(cheat)
cheat.cheat_env = { draw_text = draw_text,
draw_line = draw_line,
draw_box = draw_box,
+ tobcd = tobcd,
+ frombcd = frombcd,
pairs = pairs }
cheat.enabled = false
-- verify scripts are valid first