From bc9215493693fee51258c1b21e7617ed04010c2a Mon Sep 17 00:00:00 2001 From: Izaya Date: Mon, 13 Mar 2017 13:37:30 +1100 Subject: [PATCH] cleaned up some stuff, just the T408 right now --- test3d_t400/depends.txt | 2 - test3d_t400/init.lua | 136 ----------------------------- test3d_t400/t400.lua | 85 ------------------ test3d_t400/textures/t400.png | Bin 778 -> 0 bytes test3d_t416/depends.txt | 2 - test3d_t416/init.lua | 68 --------------- test3d_t416/textures/t416-side.png | Bin 217 -> 0 bytes test3d_t416/textures/t416-top.png | Bin 301 -> 0 bytes 8 files changed, 293 deletions(-) delete mode 100644 test3d_t400/depends.txt delete mode 100644 test3d_t400/init.lua delete mode 100644 test3d_t400/t400.lua delete mode 100644 test3d_t400/textures/t400.png delete mode 100644 test3d_t416/depends.txt delete mode 100644 test3d_t416/init.lua delete mode 100755 test3d_t416/textures/t416-side.png delete mode 100755 test3d_t416/textures/t416-top.png diff --git a/test3d_t400/depends.txt b/test3d_t400/depends.txt deleted file mode 100644 index 2cec86e..0000000 --- a/test3d_t400/depends.txt +++ /dev/null @@ -1,2 +0,0 @@ -default -digilines diff --git a/test3d_t400/init.lua b/test3d_t400/init.lua deleted file mode 100644 index 46d11c4..0000000 --- a/test3d_t400/init.lua +++ /dev/null @@ -1,136 +0,0 @@ -local MEMSIZE=16 -- does this still apply? -local SHUTUP = false -if not digiline then - print("Digilines not found.") - return -end -local path = minetest.get_modpath(minetest.get_current_modname()) -local t400 = dofile(path.."/t400.lua") -local oldprint=print -local function print(...) - if SHUTUP then return end - for k,v in ipairs({...}) do - oldprint("[Test3D:T400] "..tostring(v)) - end -end -print("Loading.") - -local function pos2string(pos) - return tostring(pos.x)..","..tostring(pos.y)..","..tostring(pos.z) -end - -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) % 4096) - if #sstab > MEMSIZE then - table.remove(sstab,1) - end - for k,v in ipairs(sstab) do - sstring = sstring .. v .. "\n" - end - meta:set_string("stack",sstring) -end - -function rqaddr(pos,addr,tp) - local meta = minetest.get_meta(pos) - meta:set_string("state","waiting"..tostring(tp)) - meta:set_string("addr",addr) - print("rqaddr: "..addr.." "..tp) - digiline:receptor_send(pos,digiline.rules.default,meta:get_string("channel")..string.format("%X",tonumber(addr)),"get") -end - -local function t400_set_meta(pos) - local meta = minetest.get_meta(pos) - local stab = {} - stab.stack,stab.rstack = {},{} - for i = 1, MEMSIZE do - stab.stack[#stab.stack+1] = 0 - stab.rstack[#stab.stack+1] = 0 - end - stab.cins = 0 - stab.pc = 0 - meta:set_string("stab",minetest.serialize(stab)) - meta:set_string("channel","") - meta:set_string("rw","") - meta:set_string("state","running") - meta:set_int("pc",0) - meta:set_string("formspec","size[5,5]\nlabel[0.4,0.5;T400 Execution Node]\nfield[0.5,2;4,1;channel;Channel prefix;${channel}]\nfield[0.5,3;4,1;pc;Program Counter;${pc}]field[0.5,4;4,1;state;State;${state}]") - print("Set metadata for a T400 node at "..pos2string(pos)) -end - -minetest.register_node("test3d_t400:t400", { - description = "T400 Execution Node", - tiles = { - { - image="t400.png", - animation={ - type = "vertical_frames", - aspect_w=16, - aspect_h=16, - length=18, - length=1.8, - }, - }, - }, - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, - on_construct = t400_set_meta, - on_receive_fields = function(pos,_,fields,sender) - print("Received fields for a T400 node at "..pos2string(pos)) - for k,v in pairs(fields) do print(tostring(k).." = "..tostring(v)) end - local meta = minetest.get_meta(pos) - if fields.channel ~= nil then - meta:set_string("channel",fields.channel) - end - if fields.pc ~= nil then - local stab = minetest.deserialize(meta:get_string("stab")) - stab.pc = tonumber(fields.pc) - meta:set_int("pc",fields.pc) -- for display only - meta:set_string("stab",minetest.serialize(stab)) - end - if fields.state ~= nil then - meta:set_string("state",fields.state) - end - end, - digiline = { - receptor = {}, - effector = { - action = function(pos,node,channel,msg) - local meta = minetest.get_meta(pos) - local stab = minetest.deserialize(meta:get_string("stab")) - print(meta:get_string("state").." "..meta:get_string("addr"),channel.." "..msg.." = "..meta:get_string("channel")..string.format("%X",meta:get_string("addr"))) - if meta:get_string("state") == "waitingread" and meta:get_string("channel")..string.format("%X",meta:get_string("addr")) == channel then - push(pos,tonumber(msg)%4096) - rqaddr(pos,stab.pc,"ins") - elseif meta:get_string("state") == "waitingins" and meta:get_string("channel")..string.format("%X",meta:get_string("addr")) == channel then - stab.ins = (tonumber(msg)%4096) - meta:set_string("state","running") - end - end - } - } -}) -print("T400 node registered") -minetest.register_abm({ - nodenames={"test3d_t400:t400"}, - interval=1, - chance=1, - action = function(pos) - local meta = minetest.get_meta(pos) - if meta:get_string("state") ~= "running" then return false end - local stab = minetest.deserialize(meta:get_string("stab")) - local stab, rw, addr, dat = t400.run(stab) - meta:set_int("pc",stab.pc) - meta:set_string("stab",minetest.serialize(stab)) - print(minetest.serialize(stab)) - if rw == "read" then - rqaddr(pos,addr,rw) - else - if rw == "write" then - digiline:receptor_send(pos,digiline.rules.default,meta:get_string("channel")..string.format("%X",addr),dat) - end - rqaddr(pos,stab.pc,"ins") - end - end -}) diff --git a/test3d_t400/t400.lua b/test3d_t400/t400.lua deleted file mode 100644 index 136f030..0000000 --- a/test3d_t400/t400.lua +++ /dev/null @@ -1,85 +0,0 @@ -local t = {} --- internal state ---- program counter (pc) ---- current instruction (ci) -- only passed from the environment to the emulator ---- stack (stack) -local function pop(s) - return table.remove(s,#s) or 0 -end -local function push(s,v) - v=v or 0 - s[#s+1] = v%4096 - if #s > 16 then - table.remove(s,1) - end -end - -function t.run(stab) - -- variables - local pc = stab.pc or 1 - local ci = stab.cins or 0 - local stack = stab.stack or {} - local rstack = stab.rstack or {} - local pci = 1 - local rw = nil - local addr = 0 - local dat = 0 - -- instruction processing - if ci == 4095 then -- ppc - push(stack,pc) - elseif ci == 4094 then -- swp - a=pop(stack) - b=pop(stack) - push(stack,a) - pusk(stack,b) - elseif ci == 4093 then -- read - rw = "read" -- terrible IPC - addr = pop(stack) - elseif ci == 4092 then -- write - rw = "write" - addr = pop(stack) - dat = pop(stack) - elseif ci == 4091 then -- add - push(stack,pop(stack)+pop(stack)) - elseif ci == 4090 then -- sub - push(stack,pop(stack)+pop(stack)) - elseif ci == 4089 then -- jmp - pc = pop(stack) - pci = 0 - elseif ci == 4088 then -- sez - if pop(stack) == 0 then - pci = pci + 1 - end - elseif ci == 4087 then -- jez - local a = pop(stack) - if pop(stack) == 0 then - pc = a - pci = 0 - end - elseif ci == 4086 then -- jsr - push(rstack,pc) - pc = pop(stack) - pci = 0 - elseif ci == 4085 then -- ret - pc = pop(rstack) - elseif ci == 4084 then -- dup - local v = pop(stack) - push(stack,v) - push(stack,v) - elseif ci == 4083 then -- drop - pop(stack) - elseif ci == 4082 then -- hlt - rw = "halt" - else - push(stack,ci) - end - -- return stuff - stab = {} - stab.pc = pc + pci -- increment pc - stab.cins = 0 - stab.stack = stack - stab.rstack = rstack - return stab, rw, addr, dat -end - -return t diff --git a/test3d_t400/textures/t400.png b/test3d_t400/textures/t400.png deleted file mode 100644 index e5bfed3840363a715966e6332eb1bec92a3d06c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 778 zcmV+l1NHogP)+v8?yE3yLO72OU8Q|lz<#VJq zAoSR2e^5#x#HcL!cn|pKE3M^Ua`mUYmeVeN+4jvp*TUfUmHy`;9i)0NdZ-!r^@u}{ zP(8xXBUX=e0f7fMkH#TWJ-CBZ4@HkS^hnhs3_U{iNJEc^9$Gy*2T%3T4pKer#eVM* zh90SUq@hO`d6*ScJsO8j^@ts0PJ7Ob9*iEQ5SZ$5l|A4gm>-ND`gJ{~=)ssDf*z(& zoa@m*Fh4SS2-Y8r9$GyVJs9f`L6402(K+UNgbsopg7rs652+sdvVv@ltJOo$BV+v` z=+QZ5=V=4M`h(F!uz$(bgI{LY9*C<)#{NangR%bT9CJNl2SE?T{-xyy5CVsr}2fETO+` z9)k5p#{ETx`60N!WUM~~J-GLC{YIYJ-(Il=&p%rKlF>u3{@~&M!dQO@dSvWh+Vc++ z^i!XIT-(|?Bcq34|H9~@!}>$fgRy@R^vL~rP%i}j 0 then - local memaddr = tonumber(channel:sub(#chan+1),16)+1-memoffset - if tostring(msg):lower() == "get" then - digiline:receptor_send(pos, digiline.rules.default, channel, tonumber(mem[memaddr] or 0)) - print("Reading address "..tostring(memaddr)..": "..tostring(mem[memaddr])) - else - mem[memaddr] = tonumber(msg) or 0 - for k,v in ipairs(mem) do - ms = ms .. tostring(v) .. "\n" - end - meta:set_string("mem",ms) - print("Set address "..tostring(memaddr).." to "..tostring(tonumber(msg))) - end - end -end -print("Created T416 digiline function") - -local function t416_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[5,12]\nlabel[0.4,0.5;T416 Memory Node (16 words)]\nfield[0.5,2;4,1;channel;Channel prefix;${channel}]\nfield[0.5,3;4,1;startaddr;Starting address;${startaddr}]\ntextarea[0.5,4;4,8;mem;Memory contents;${mem}]") -end -minetest.register_node("test3d_t416:t416", { - description = "T416 Memory Node", - tiles = {"t416-top.png","t416-top.png","t416-side.png","t416-side.png","t416-side.png","t416-side.png"}, - on_construct = t416_set_meta, - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, - digiline = { - receptor = {}, - effector = { - action = function (a,b,c,d) pcall(t416_digiline_receive,a,b,c,d) end - } - }, - on_receive_fields = function(pos,_,fields,sender) - if fields.channel == nil then return end - local meta = minetest.get_meta(pos) - fields.channel = fields.channel or "" - meta:set_string("channel",fields.channel) - meta:set_int("startaddr",tonumber(fields.startaddr)) - end -}) -print("T416 node registered") diff --git a/test3d_t416/textures/t416-side.png b/test3d_t416/textures/t416-side.png deleted file mode 100755 index 43b57037bbed1e92f96f7cfad5a4edc4c7c222a2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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*` diff --git a/test3d_t416/textures/t416-top.png b/test3d_t416/textures/t416-top.png deleted file mode 100755 index 05c2d9cee1905bb88dbad48a9fab6cafc1cf8e31..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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