Add NanoBasic to TA3 Terminal
This commit is contained in:
parent
849112013f
commit
d7576fa6f6
@ -124,10 +124,9 @@ local function get_action(nvm, fields)
|
|||||||
if nvm.status == "" then
|
if nvm.status == "" then
|
||||||
nvm.status = "init"
|
nvm.status = "init"
|
||||||
end
|
end
|
||||||
print("get_action", nvm.status, dump(fields))
|
--print("get_action", nvm.status, dump(fields))
|
||||||
for _,key in ipairs(keys) do
|
for _,key in ipairs(keys) do
|
||||||
if fields[key] and Actions[nvm.status] and Actions[nvm.status][key] then
|
if fields[key] and Actions[nvm.status] and Actions[nvm.status][key] then
|
||||||
print("get_action", nvm.status, key)
|
|
||||||
return Actions[nvm.status][key]
|
return Actions[nvm.status][key]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -393,21 +392,34 @@ minetest.register_node("techage:basic_terminal", {
|
|||||||
-- Register VM external/callback functions
|
-- Register VM external/callback functions
|
||||||
--
|
--
|
||||||
local function get_num_param(pos, num_param)
|
local function get_num_param(pos, num_param)
|
||||||
|
local payload3 = 0
|
||||||
local payload2 = 0
|
local payload2 = 0
|
||||||
local payload1 = 0
|
local payload1 = 0
|
||||||
local cmnd, num, owner, own_num
|
local cmnd, num, owner, own_num
|
||||||
|
|
||||||
if num_param == 4 then
|
if num_param == 5 then
|
||||||
|
payload3 = nanobasic.pop_num(pos) or 0
|
||||||
|
if payload3 >= 0x8000000 then
|
||||||
|
payload3 = payload3 - 0x100000000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if num_param >= 4 then
|
||||||
payload2 = nanobasic.pop_num(pos) or 0
|
payload2 = nanobasic.pop_num(pos) or 0
|
||||||
|
if payload2 >= 0x8000000 then
|
||||||
|
payload2 = payload2 - 0x100000000
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if num_param >= 3 then
|
if num_param >= 3 then
|
||||||
payload1 = nanobasic.pop_num(pos) or 0
|
payload1 = nanobasic.pop_num(pos) or 0
|
||||||
|
if payload1 >= 0x8000000 then
|
||||||
|
payload1 = payload1 - 0x100000000
|
||||||
|
end
|
||||||
end
|
end
|
||||||
cmnd = nanobasic.pop_num(pos)
|
cmnd = nanobasic.pop_num(pos)
|
||||||
num = nanobasic.pop_num(pos) or 0
|
num = nanobasic.pop_num(pos) or 0
|
||||||
owner = M(pos):get_string("owner")
|
owner = M(pos):get_string("owner")
|
||||||
own_num = M(pos):get_string("node_number")
|
own_num = M(pos):get_string("node_number")
|
||||||
return owner, num, own_num, {payload1, payload2}
|
return owner, num, own_num, {payload1, payload2, payload3}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_str_param(pos, num_param)
|
local function get_str_param(pos, num_param)
|
||||||
@ -424,10 +436,11 @@ local function get_str_param(pos, num_param)
|
|||||||
return owner, num, own_num, payload1
|
return owner, num, own_num, payload1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function error_handling(pos, sts)
|
local function error_handling(pos, num, sts)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if sts > 0 and nvm.error_label_addr and nvm.error_label_addr > 0 then
|
if sts > 0 and nvm.error_label_addr and nvm.error_label_addr > 0 then
|
||||||
local err = ErrorStr[sts] or "unknown error"
|
local err = ErrorStr[sts] or "unknown error"
|
||||||
|
nanobasic.push_num(pos, num)
|
||||||
nanobasic.push_str(pos, err)
|
nanobasic.push_str(pos, err)
|
||||||
nanobasic.set_pc(pos, nvm.error_label_addr)
|
nanobasic.set_pc(pos, nvm.error_label_addr)
|
||||||
end
|
end
|
||||||
@ -470,10 +483,10 @@ register_ext_function("time", {}, nanobasic.NB_NUM, function(pos, nvm)
|
|||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- num: cmd(num: node_num, num: cmnd, any: pyld1, any: pyld2)
|
-- num: cmd(num: node_num, num: cmnd, any: pyld1, num: pyld2, num: pyld3)
|
||||||
register_ext_function("cmd", {nanobasic.NB_NUM, nanobasic.NB_NUM, nanobasic.NB_ANY, nanobasic.NB_ANY}, nanobasic.NB_NUM, function(pos, nvm)
|
register_ext_function("cmd", {nanobasic.NB_NUM, nanobasic.NB_NUM, nanobasic.NB_ANY, nanobasic.NB_ANY, nanobasic.NB_ANY}, nanobasic.NB_NUM, function(pos, nvm)
|
||||||
local num_param = nanobasic.stack_depth(pos)
|
local num_param = nanobasic.stack_depth(pos)
|
||||||
if num_param >= 2 and num_param <= 4 then
|
if num_param >= 2 and num_param <= 5 then
|
||||||
local cmnd = nanobasic.peek_num(pos, num_param - 1) or 0
|
local cmnd = nanobasic.peek_num(pos, num_param - 1) or 0
|
||||||
if cmnd < 64 then -- command with payload as number(s)
|
if cmnd < 64 then -- command with payload as number(s)
|
||||||
local owner, num, own_num, payload = get_num_param(pos, num_param)
|
local owner, num, own_num, payload = get_num_param(pos, num_param)
|
||||||
@ -481,10 +494,10 @@ register_ext_function("cmd", {nanobasic.NB_NUM, nanobasic.NB_NUM, nanobasic.NB_A
|
|||||||
techage.counting_add(owner, 1)
|
techage.counting_add(owner, 1)
|
||||||
local sts, resp = techage.beduino_send_cmnd(own_num, num, cmnd, payload)
|
local sts, resp = techage.beduino_send_cmnd(own_num, num, cmnd, payload)
|
||||||
nanobasic.push_num(pos, sts)
|
nanobasic.push_num(pos, sts)
|
||||||
error_handling(pos, sts)
|
error_handling(pos, num, sts)
|
||||||
else
|
else
|
||||||
nanobasic.push_num(pos, 4)
|
nanobasic.push_num(pos, 4)
|
||||||
error_handling(pos, 4)
|
error_handling(pos, num, 4)
|
||||||
end
|
end
|
||||||
elseif cmnd < 128 then -- command with payload as string
|
elseif cmnd < 128 then -- command with payload as string
|
||||||
local owner, num, own_num, payload = get_str_param(pos, num_param)
|
local owner, num, own_num, payload = get_str_param(pos, num_param)
|
||||||
@ -492,40 +505,39 @@ register_ext_function("cmd", {nanobasic.NB_NUM, nanobasic.NB_NUM, nanobasic.NB_A
|
|||||||
techage.counting_add(owner, 1)
|
techage.counting_add(owner, 1)
|
||||||
local sts, resp = techage.beduino_send_cmnd(own_num, num, cmnd, payload)
|
local sts, resp = techage.beduino_send_cmnd(own_num, num, cmnd, payload)
|
||||||
nanobasic.push_num(pos, sts)
|
nanobasic.push_num(pos, sts)
|
||||||
error_handling(pos, sts)
|
error_handling(pos, num, sts)
|
||||||
else
|
else
|
||||||
nanobasic.push_num(pos, 4)
|
nanobasic.push_num(pos, 4)
|
||||||
error_handling(pos, 4)
|
error_handling(pos, num, 4)
|
||||||
end
|
end
|
||||||
else -- request with payload as number(s) and result as number
|
else -- request with payload as number(s) and result as number
|
||||||
local owner, num, own_num, payload = get_num_param(pos, num_param)
|
local owner, num, own_num, payload = get_num_param(pos, num_param)
|
||||||
if techage.not_protected(tostring(num), owner) then
|
if techage.not_protected(tostring(num), owner) then
|
||||||
techage.counting_add(owner, 1)
|
techage.counting_add(owner, 1)
|
||||||
local sts, resp = techage.beduino_request_data(own_num, num, cmnd, payload)
|
local sts, resp = techage.beduino_request_data(own_num, num, cmnd, payload)
|
||||||
print("cmd resp", sts, dump(resp))
|
|
||||||
if type(resp) == "table" then
|
if type(resp) == "table" then
|
||||||
nanobasic.push_num(pos, resp[1] or 0)
|
nanobasic.push_num(pos, resp[1] or 0)
|
||||||
else
|
else
|
||||||
nanobasic.push_num(pos, 5)
|
nanobasic.push_num(pos, 5)
|
||||||
sts = 5
|
sts = 5
|
||||||
end
|
end
|
||||||
error_handling(pos, sts)
|
error_handling(pos, num, sts)
|
||||||
else
|
else
|
||||||
nanobasic.push_num(pos, 4)
|
nanobasic.push_num(pos, 4)
|
||||||
error_handling(pos, 4)
|
error_handling(pos, num, 4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nanobasic.push_num(pos, 6)
|
nanobasic.push_num(pos, 6)
|
||||||
error_handling(pos, 6)
|
error_handling(pos, num, 6)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- str: cmd(num: node_num, num: cmnd, any: pyld1, any: pyld2)
|
-- str: cmd(num: node_num, num: cmnd, any: pyld1, any: pyld2, num: pyld3)
|
||||||
register_ext_function("cmd$", {nanobasic.NB_NUM, nanobasic.NB_NUM, nanobasic.NB_ANY, nanobasic.NB_ANY}, nanobasic.NB_STR, function(pos, nvm)
|
register_ext_function("cmd$", {nanobasic.NB_NUM, nanobasic.NB_NUM, nanobasic.NB_ANY, nanobasic.NB_ANY, nanobasic.NB_ANY}, nanobasic.NB_STR, function(pos, nvm)
|
||||||
local num_param = nanobasic.stack_depth(pos)
|
local num_param = nanobasic.stack_depth(pos)
|
||||||
if num_param >= 2 and num_param <= 4 then
|
if num_param >= 2 and num_param <= 5 then
|
||||||
local cmnd = nanobasic.peek_num(pos, num_param - 1) or 0
|
local cmnd = nanobasic.peek_num(pos, num_param - 1) or 0
|
||||||
if cmnd >= 128 then -- request with payload as number(s) and result as string
|
if cmnd >= 128 then -- request with payload as number(s) and result as string
|
||||||
local owner, num, own_num, payload = get_num_param(pos, num_param)
|
local owner, num, own_num, payload = get_num_param(pos, num_param)
|
||||||
@ -538,15 +550,15 @@ register_ext_function("cmd$", {nanobasic.NB_NUM, nanobasic.NB_NUM, nanobasic.NB_
|
|||||||
nanobasic.push_str(pos, "")
|
nanobasic.push_str(pos, "")
|
||||||
sts = 5
|
sts = 5
|
||||||
end
|
end
|
||||||
error_handling(pos, sts)
|
error_handling(pos, num, sts)
|
||||||
else
|
else
|
||||||
nanobasic.push_str(pos, "")
|
nanobasic.push_str(pos, "")
|
||||||
error_handling(pos, 4)
|
error_handling(pos, num, 4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nanobasic.push_str(pos, "")
|
nanobasic.push_str(pos, "")
|
||||||
error_handling(pos, 6)
|
error_handling(pos, num, 6)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
@ -619,7 +631,6 @@ end)
|
|||||||
-- str: iname(str: item_name)
|
-- str: iname(str: item_name)
|
||||||
register_ext_function("iname$", {nanobasic.NB_STR}, nanobasic.NB_STR, function(pos, nvm)
|
register_ext_function("iname$", {nanobasic.NB_STR}, nanobasic.NB_STR, function(pos, nvm)
|
||||||
local item_name = nanobasic.pop_str(pos) or ""
|
local item_name = nanobasic.pop_str(pos) or ""
|
||||||
print("iname", item_name)
|
|
||||||
local item = minetest.registered_items[item_name]
|
local item = minetest.registered_items[item_name]
|
||||||
if item and item.description then
|
if item and item.description then
|
||||||
local s = minetest.get_translated_string("en", item.description)
|
local s = minetest.get_translated_string("en", item.description)
|
||||||
@ -641,6 +652,7 @@ register_action({"init", "stopped", "error", "break"}, "Edit", function(pos, nvm
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
register_action({"edit"}, "Save", function(pos, nvm, fields)
|
register_action({"edit"}, "Save", function(pos, nvm, fields)
|
||||||
|
nanobasic.clear_screen(pos)
|
||||||
local code = sort_lines(pos, nvm, fields.code)
|
local code = sort_lines(pos, nvm, fields.code)
|
||||||
if code == nil then
|
if code == nil then
|
||||||
nvm.status = "error"
|
nvm.status = "error"
|
||||||
@ -654,6 +666,7 @@ register_action({"edit"}, "Save", function(pos, nvm, fields)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
register_action({"edit"}, "Renum", function(pos, nvm, fields)
|
register_action({"edit"}, "Renum", function(pos, nvm, fields)
|
||||||
|
nanobasic.clear_screen(pos)
|
||||||
local code = sort_lines(pos, nvm, fields.code)
|
local code = sort_lines(pos, nvm, fields.code)
|
||||||
if code == nil then
|
if code == nil then
|
||||||
nvm.status = "error"
|
nvm.status = "error"
|
||||||
@ -663,7 +676,6 @@ register_action({"edit"}, "Renum", function(pos, nvm, fields)
|
|||||||
return nanobasic.get_screen_buffer(pos) or ""
|
return nanobasic.get_screen_buffer(pos) or ""
|
||||||
end
|
end
|
||||||
code = renumber_lines(pos, nvm, code)
|
code = renumber_lines(pos, nvm, code)
|
||||||
print("Renum", code)
|
|
||||||
M(pos):set_string("code", code)
|
M(pos):set_string("code", code)
|
||||||
return code
|
return code
|
||||||
end)
|
end)
|
||||||
@ -686,7 +698,6 @@ register_action({"init", "edit", "stopped"}, "Run", function(pos, nvm, fields)
|
|||||||
nvm.input = ""
|
nvm.input = ""
|
||||||
nvm.variables = nanobasic.get_variable_list(pos)
|
nvm.variables = nanobasic.get_variable_list(pos)
|
||||||
nvm.error_label_addr = nanobasic.get_label_address(pos, "65000") or 0
|
nvm.error_label_addr = nanobasic.get_label_address(pos, "65000") or 0
|
||||||
--print("nvm.variables", dump(nvm.variables))
|
|
||||||
minetest.get_node_timer(pos):start(0.2)
|
minetest.get_node_timer(pos):start(0.2)
|
||||||
return nanobasic.get_screen_buffer(pos) or ""
|
return nanobasic.get_screen_buffer(pos) or ""
|
||||||
else
|
else
|
||||||
@ -721,11 +732,9 @@ register_action({"break"}, "Enter", function(pos, nvm, fields)
|
|||||||
if var_name == nil then
|
if var_name == nil then
|
||||||
var_name, arr_idx = s, "0"
|
var_name, arr_idx = s, "0"
|
||||||
end
|
end
|
||||||
print("fields.input:lower()", s, var_name, arr_idx)
|
|
||||||
if nvm.variables[var_name] then
|
if nvm.variables[var_name] then
|
||||||
arr_idx = tonumber(arr_idx)
|
arr_idx = tonumber(arr_idx)
|
||||||
local var_type, var_idx = nvm.variables[var_name][1], nvm.variables[var_name][2]
|
local var_type, var_idx = nvm.variables[var_name][1], nvm.variables[var_name][2]
|
||||||
print("break / Enter", var_type, var_idx, arr_idx, dump(nvm.variables[var_name]))
|
|
||||||
local val = nanobasic.read_variable(pos, var_type, var_idx, arr_idx)
|
local val = nanobasic.read_variable(pos, var_type, var_idx, arr_idx)
|
||||||
if var_type == nanobasic.NB_NUM then
|
if var_type == nanobasic.NB_NUM then
|
||||||
nanobasic.print(pos, string.format("%s = %u\n", var_name, val));
|
nanobasic.print(pos, string.format("%s = %u\n", var_name, val));
|
||||||
@ -767,13 +776,11 @@ end)
|
|||||||
|
|
||||||
register_action(States, "larger", function(pos, nvm, fields)
|
register_action(States, "larger", function(pos, nvm, fields)
|
||||||
nvm.trm_text_size = math.min((nvm.trm_text_size or 0) + 1, 8)
|
nvm.trm_text_size = math.min((nvm.trm_text_size or 0) + 1, 8)
|
||||||
print("larger", nvm.trm_text_size)
|
|
||||||
return fields.code or nanobasic.get_screen_buffer(pos) or ""
|
return fields.code or nanobasic.get_screen_buffer(pos) or ""
|
||||||
end)
|
end)
|
||||||
|
|
||||||
register_action(States, "smaller", function(pos, nvm, fields)
|
register_action(States, "smaller", function(pos, nvm, fields)
|
||||||
nvm.trm_text_size = math.max((nvm.trm_text_size or 0) - 1, -8)
|
nvm.trm_text_size = math.max((nvm.trm_text_size or 0) - 1, -8)
|
||||||
print("smaller", nvm.trm_text_size)
|
|
||||||
return fields.code or nanobasic.get_screen_buffer(pos) or ""
|
return fields.code or nanobasic.get_screen_buffer(pos) or ""
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -805,7 +812,6 @@ end)
|
|||||||
|
|
||||||
techage.register_node({"techage:basic_terminal"}, {
|
techage.register_node({"techage:basic_terminal"}, {
|
||||||
on_node_load = function(pos)
|
on_node_load = function(pos)
|
||||||
print("register_lbm")
|
|
||||||
nanobasic.vm_restore(pos)
|
nanobasic.vm_restore(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if nvm.status == "running" then
|
if nvm.status == "running" then
|
||||||
|
Loading…
Reference in New Issue
Block a user