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 SHUTUP = false
|
||||
if not digiline then
|
||||
print("Digilines not found.")
|
||||
return
|
||||
end
|
||||
local path = minetest.get_modpath(minetest.get_current_modname())
|
||||
local oldprint=print
|
||||
local function print(...)
|
||||
if SHUTUP then return end
|
||||
for k,v in ipairs({...}) do
|
||||
oldprint("[Test3D:T400] "..tostring(v))
|
||||
end
|
||||
@ -19,7 +22,7 @@ local function push(pos,val)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local sstring = ""
|
||||
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
|
||||
table.remove(sstab,1)
|
||||
end
|
||||
@ -38,7 +41,7 @@ local function pop(pos)
|
||||
end
|
||||
meta:set_string("stack",sstring)
|
||||
if not sval then sval = 0 end
|
||||
return sval
|
||||
return tonumber(sval) % 4096
|
||||
end
|
||||
|
||||
local function t400_digiline_receive(pos, node, channel, msg)
|
||||
@ -108,15 +111,13 @@ minetest.register_abm({
|
||||
chance=1,
|
||||
action = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local nins = 1
|
||||
if meta:get_string("state") == "running" then
|
||||
local skipnext = false
|
||||
print("Attempting to run T400 node at "..pos2string(pos))
|
||||
local ci = meta:get_int("ci")
|
||||
if ci == 4095 then
|
||||
local dat = pop(pos)
|
||||
push(pos,dat)
|
||||
push(pos,dat)
|
||||
print("Duplicated "..tostring(dat).." at "..tostring(pos.x)..","..tostring(pos.y)..","..tostring(pos.z))
|
||||
push(pos,meta:get_int("pc"))
|
||||
elseif ci == 4094 then
|
||||
local a = pop(pos)
|
||||
local b = pop(pos)
|
||||
@ -143,15 +144,18 @@ minetest.register_abm({
|
||||
print("Jumping to "..tostring(npc))
|
||||
meta:set_int("pc",npc)
|
||||
elseif ci == 4088 then
|
||||
if pop(pos) == 0 then
|
||||
meta:set_int("pc",meta:get_int("pc")+1)
|
||||
local val = pop(pos)
|
||||
print(val,type(val))
|
||||
if val == 0 then
|
||||
print("Skipping because "..tostring(val).." = 0")
|
||||
nins=nins+1
|
||||
end
|
||||
else
|
||||
print("Pushing "..ci.." to "..pos2string(pos))
|
||||
push(pos,ci)
|
||||
end
|
||||
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("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")
|
||||
|
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