From e95eb910c50347e20de2d5037099bc4dad84bc38 Mon Sep 17 00:00:00 2001 From: Izaya Orihara Date: Sun, 15 Jan 2017 06:52:08 +1100 Subject: [PATCH] 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. --- test3d_t400/init.lua | 22 +++++++++------- test3d_t410/depends.txt | 2 ++ test3d_t410/init.lua | 40 +++++++++++++++++++++++++++++ test3d_t410/textures/t416-side.png | Bin 0 -> 217 bytes test3d_t410/textures/t416-top.png | Bin 0 -> 301 bytes 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 test3d_t410/depends.txt create mode 100644 test3d_t410/init.lua create mode 100755 test3d_t410/textures/t416-side.png create mode 100755 test3d_t410/textures/t416-top.png diff --git a/test3d_t400/init.lua b/test3d_t400/init.lua index eff0cf1..2291c71 100644 --- a/test3d_t400/init.lua +++ b/test3d_t400/init.lua @@ -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") diff --git a/test3d_t410/depends.txt b/test3d_t410/depends.txt new file mode 100644 index 0000000..2cec86e --- /dev/null +++ b/test3d_t410/depends.txt @@ -0,0 +1,2 @@ +default +digilines diff --git a/test3d_t410/init.lua b/test3d_t410/init.lua new file mode 100644 index 0000000..e15d77d --- /dev/null +++ b/test3d_t410/init.lua @@ -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") diff --git a/test3d_t410/textures/t416-side.png b/test3d_t410/textures/t416-side.png new file mode 100755 index 0000000000000000000000000000000000000000..43b57037bbed1e92f96f7cfad5a4edc4c7c222a2 GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#AtN8F7R#c2-|hj0WHUn|N}Tg^b5rw5fLsO!=c3falGGH1^30M91$R&1fE2w{ zcA&Vwr;B5V#`$EMk{1HZnhmT@OP4Pf4zVhJ=EKIucFeh*@9peB*CikQBy)9mczCqW z?^g|DKH~YX?a-2+iC5YbGnkcCwhB$2Gsozb!~>}gc7~tws&+PkYz-hgJzf1=);T3K F0RRU9J!k*` literal 0 HcmV?d00001 diff --git a/test3d_t410/textures/t416-top.png b/test3d_t410/textures/t416-top.png new file mode 100755 index 0000000000000000000000000000000000000000..05c2d9cee1905bb88dbad48a9fab6cafc1cf8e31 GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#AtN6vhoT=x%1)q=Y-UJAiF1B#Zfaf$kjuc}T$GwvlA5AWo>`Ki;O^-gkfN8$ z4isPP>EaloaX#6muvsvIUSM| zn{JWNoD;}90o22g nc;Kwt55`HWI(%w+mZ;@3gnwUQ(jzi|0>~epu6{1-oD!M<-NI?U literal 0 HcmV?d00001