T400: Fixed sez and replaced dup with ppc, which puts the program counter on the stack, for jumps and returns and stuff.
Also added the T410, a memory console.
This commit is contained in:
parent
f361869107
commit
e95eb910c5
@ -1,10 +1,13 @@
|
|||||||
local MEMSIZE=16
|
local MEMSIZE=16
|
||||||
|
local SHUTUP = false
|
||||||
if not digiline then
|
if not digiline then
|
||||||
print("Digilines not found.")
|
print("Digilines not found.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local path = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local oldprint=print
|
local oldprint=print
|
||||||
local function print(...)
|
local function print(...)
|
||||||
|
if SHUTUP then return end
|
||||||
for k,v in ipairs({...}) do
|
for k,v in ipairs({...}) do
|
||||||
oldprint("[Test3D:T400] "..tostring(v))
|
oldprint("[Test3D:T400] "..tostring(v))
|
||||||
end
|
end
|
||||||
@ -19,7 +22,7 @@ local function push(pos,val)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local sstring = ""
|
local sstring = ""
|
||||||
local sstab = string.split(meta:get_string("stack"),"\n")
|
local sstab = string.split(meta:get_string("stack"),"\n")
|
||||||
sstab[#sstab+1] = tostring(tonumber(val))
|
sstab[#sstab+1] = tostring(tonumber(val) % 4096)
|
||||||
if #sstab > 16 then
|
if #sstab > 16 then
|
||||||
table.remove(sstab,1)
|
table.remove(sstab,1)
|
||||||
end
|
end
|
||||||
@ -38,7 +41,7 @@ local function pop(pos)
|
|||||||
end
|
end
|
||||||
meta:set_string("stack",sstring)
|
meta:set_string("stack",sstring)
|
||||||
if not sval then sval = 0 end
|
if not sval then sval = 0 end
|
||||||
return sval
|
return tonumber(sval) % 4096
|
||||||
end
|
end
|
||||||
|
|
||||||
local function t400_digiline_receive(pos, node, channel, msg)
|
local function t400_digiline_receive(pos, node, channel, msg)
|
||||||
@ -108,15 +111,13 @@ minetest.register_abm({
|
|||||||
chance=1,
|
chance=1,
|
||||||
action = function(pos)
|
action = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
local nins = 1
|
||||||
if meta:get_string("state") == "running" then
|
if meta:get_string("state") == "running" then
|
||||||
local skipnext = false
|
local skipnext = false
|
||||||
print("Attempting to run T400 node at "..pos2string(pos))
|
print("Attempting to run T400 node at "..pos2string(pos))
|
||||||
local ci = meta:get_int("ci")
|
local ci = meta:get_int("ci")
|
||||||
if ci == 4095 then
|
if ci == 4095 then
|
||||||
local dat = pop(pos)
|
push(pos,meta:get_int("pc"))
|
||||||
push(pos,dat)
|
|
||||||
push(pos,dat)
|
|
||||||
print("Duplicated "..tostring(dat).." at "..tostring(pos.x)..","..tostring(pos.y)..","..tostring(pos.z))
|
|
||||||
elseif ci == 4094 then
|
elseif ci == 4094 then
|
||||||
local a = pop(pos)
|
local a = pop(pos)
|
||||||
local b = pop(pos)
|
local b = pop(pos)
|
||||||
@ -143,15 +144,18 @@ minetest.register_abm({
|
|||||||
print("Jumping to "..tostring(npc))
|
print("Jumping to "..tostring(npc))
|
||||||
meta:set_int("pc",npc)
|
meta:set_int("pc",npc)
|
||||||
elseif ci == 4088 then
|
elseif ci == 4088 then
|
||||||
if pop(pos) == 0 then
|
local val = pop(pos)
|
||||||
meta:set_int("pc",meta:get_int("pc")+1)
|
print(val,type(val))
|
||||||
|
if val == 0 then
|
||||||
|
print("Skipping because "..tostring(val).." = 0")
|
||||||
|
nins=nins+1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("Pushing "..ci.." to "..pos2string(pos))
|
print("Pushing "..ci.." to "..pos2string(pos))
|
||||||
push(pos,ci)
|
push(pos,ci)
|
||||||
end
|
end
|
||||||
if not skipnext then
|
if not skipnext then
|
||||||
meta:set_int("pc",meta:get_int("pc")+1)
|
meta:set_int("pc",meta:get_int("pc")+nins)
|
||||||
meta:set_string("state","waitingins")
|
meta:set_string("state","waitingins")
|
||||||
meta:set_string("waitingfor",meta:get_string("channel")..string.format("%X",meta:get_int("pc")))
|
meta:set_string("waitingfor",meta:get_string("channel")..string.format("%X",meta:get_int("pc")))
|
||||||
digiline:receptor_send(pos, digiline.rules.default, meta:get_string("channel")..string.format("%X",meta:get_int("pc")), "get")
|
digiline:receptor_send(pos, digiline.rules.default, meta:get_string("channel")..string.format("%X",meta:get_int("pc")), "get")
|
||||||
|
2
test3d_t410/depends.txt
Normal file
2
test3d_t410/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
default
|
||||||
|
digilines
|
40
test3d_t410/init.lua
Normal file
40
test3d_t410/init.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
local MEMSIZE=16
|
||||||
|
if not digiline then
|
||||||
|
print("Digilines not found.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local oldprint=print
|
||||||
|
local function print(...)
|
||||||
|
for k,v in ipairs({...}) do
|
||||||
|
oldprint("[Test3D:T410] "..tostring(v))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print("Loading.")
|
||||||
|
|
||||||
|
local function t410_set_meta(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local ms = ""
|
||||||
|
for i = 1, MEMSIZE do
|
||||||
|
ms = ms .. "0\n"
|
||||||
|
end
|
||||||
|
meta:set_string("mem",ms)
|
||||||
|
meta:set_string("channel","Default")
|
||||||
|
meta:set_int("startaddr",0)
|
||||||
|
meta:set_string("formspec","size[2,4]\nfield[0,1;2.9,1;addr;Address;]\nfield[0,2;2.9,1;data;Data;]\nbutton[0,3;2,1;write;Write]")
|
||||||
|
--
|
||||||
|
end
|
||||||
|
minetest.register_node("test3d_t410:t410", {
|
||||||
|
description = "T410 Memory Access Console",
|
||||||
|
tiles = {"t416-top.png","t416-top.png","t416-side.png","t416-side.png","t416-side.png","t416-side.png"},
|
||||||
|
on_construct = t410_set_meta,
|
||||||
|
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
|
||||||
|
on_receive_fields = function(pos,_,fields,sender)
|
||||||
|
if fields.addr == nil then return end
|
||||||
|
digiline:receptor_send(pos, digiline.rules.default, fields.addr, tonumber(fields.data or 0))
|
||||||
|
print("Set "..fields.addr.." to "..fields.data)
|
||||||
|
end,
|
||||||
|
digiline = {
|
||||||
|
receptor = {},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
print("T410 node registered")
|
BIN
test3d_t410/textures/t416-side.png
Executable file
BIN
test3d_t410/textures/t416-side.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 217 B |
BIN
test3d_t410/textures/t416-top.png
Executable file
BIN
test3d_t410/textures/t416-top.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 301 B |
Loading…
Reference in New Issue
Block a user