Add classic 16x16 blocks

master
Joachim Stolberg 2022-03-21 19:16:58 +01:00
parent 02ab1cf328
commit 54b3ddabdd
11 changed files with 228 additions and 176 deletions

View File

@ -42,6 +42,64 @@ local function init(pos, mem)
end
end
local function after_place_node(pos, placer, itemstack, pointed_thing)
local mem = prog.get_mem(pos)
preserve_cpu_server_pos(pos, itemstack)
local meta = M(pos)
meta:set_string("infotext", "VM16 Programmer")
if cpu_server_pos(pos, mem) then
init(pos, mem)
end
meta:set_string("formspec", prog.fs_connect(mem))
end
local function on_rightclick(pos)
local mem = prog.get_mem(pos)
if cpu_server_pos(pos, mem) and mem.running then
M(pos):set_string("formspec", vm16.prog.formspec(pos, mem))
end
end
local function on_receive_fields(pos, formname, fields, player)
local mem = prog.get_mem(pos)
if cpu_server_pos(pos, mem) then
mem.cpu_def = mem.cpu_def or prog.get_cpu_def(mem.cpu_pos)
vm16.prog.on_receive_fields(pos, formname, fields, player)
end
end
local function after_dig_node(pos)
prog.del_mem(pos)
end
local function on_use(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
local name = user and user:get_player_name()
local pos = pointed_thing.under
if not user or minetest.is_protected(pos, user:get_player_name()) then
minetest.chat_send_player(name, "[vm16] Error: Protected position!")
return
end
local node = minetest.get_node(pos)
if prog.get_cpu_def(pos) then
local meta = itemstack:get_meta()
meta:set_string("cpu_pos", P2S(pos))
minetest.chat_send_player(name, "[vm16] Connected to CPU")
elseif node.name == "vm16:server" or node.name == "vm16:server2" then
local meta = itemstack:get_meta()
meta:set_string("server_pos", P2S(pos))
minetest.chat_send_player(name, "[vm16] Connected to Server")
end
end
return itemstack
end
local function preserve_metadata(pos, oldnode, oldmetadata, drops)
local meta = drops[1]:get_meta()
meta:set_string("cpu_pos", oldmetadata.cpu_pos)
meta:set_string("server_pos", oldmetadata.server_pos)
end
minetest.register_node("vm16:programmer", {
description = "VM16 Programmer",
drawtype = "nodebox",
@ -67,67 +125,45 @@ minetest.register_node("vm16:programmer", {
'vm16_programmer_bottom.png^vm16_logo.png',
"vm16_programmer_front.png",
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
local mem = prog.get_mem(pos)
preserve_cpu_server_pos(pos, itemstack)
local meta = M(pos)
meta:set_string("infotext", "VM16 Programmer")
if cpu_server_pos(pos, mem) then
init(pos, mem)
end
meta:set_string("formspec", prog.fs_connect(mem))
end,
on_rightclick = function(pos)
local mem = prog.get_mem(pos)
if cpu_server_pos(pos, mem) and mem.running then
M(pos):set_string("formspec", vm16.prog.formspec(pos, mem))
end
end,
on_receive_fields = function(pos, formname, fields, player)
local mem = prog.get_mem(pos)
if cpu_server_pos(pos, mem) then
mem.cpu_def = mem.cpu_def or prog.get_cpu_def(mem.cpu_pos)
vm16.prog.on_receive_fields(pos, formname, fields, player)
end
end,
after_dig_node = function(pos)
prog.del_mem(pos)
end,
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
local name = user and user:get_player_name()
local pos = pointed_thing.under
if not user or minetest.is_protected(pos, user:get_player_name()) then
minetest.chat_send_player(name, "[vm16] Error: Protected position!")
return
end
local node = minetest.get_node(pos)
if prog.get_cpu_def(pos) then
local meta = itemstack:get_meta()
meta:set_string("cpu_pos", P2S(pos))
minetest.chat_send_player(name, "[vm16] Connected to CPU")
elseif node.name == "vm16:server" then
local meta = itemstack:get_meta()
meta:set_string("server_pos", P2S(pos))
minetest.chat_send_player(name, "[vm16] Connected to Server")
end
end
return itemstack
end,
preserve_metadata = function(pos, oldnode, oldmetadata, drops)
local meta = drops[1]:get_meta()
meta:set_string("cpu_pos", oldmetadata.cpu_pos)
meta:set_string("server_pos", oldmetadata.server_pos)
end,
after_place_node = after_place_node,
on_rightclick = on_rightclick,
on_receive_fields = on_receive_fields,
after_dig_node = after_dig_node,
on_use = on_use,
preserve_metadata = preserve_metadata,
stack_max = 1,
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
})
minetest.register_node("vm16:programmer2", {
description = "VM16 Programmer",
paramtype2 = "facedir",
tiles = {
-- up, down, right, left, back, front
'vm16_programmer2_top.png',
'vm16_programmer2_top.png',
'vm16_programmer2_side.png',
'vm16_programmer2_side.png',
'vm16_programmer2_side.png',
"vm16_programmer2_front.png",
},
after_place_node = after_place_node,
on_rightclick = on_rightclick,
on_receive_fields = on_receive_fields,
after_dig_node = after_dig_node,
on_use = on_use,
preserve_metadata = preserve_metadata,
stack_max = 1,
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,
})
minetest.register_lbm({
label = "vm16 Programmer",
name = "vm16:programmer",
nodenames = {"vm16:programmer"},
nodenames = {"vm16:programmer", "vm16:programmer2"},
run_at_every_load = true,
action = function(pos, node)
local mem = prog.get_mem(pos)

View File

@ -111,6 +111,26 @@ function vm16.server.add_ro_file(pos, filename, text)
mem.ro_files[filename] = text
end
local function after_place_node(pos, placer, itemstack, pointed_thing)
local meta = M(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", "formspec_version[4]size[6,3]button[0.8,0.8;4.4,1.4;destroy;Destroy Server\n with all files?]")
meta:set_string("files", minetest.serialize({}))
meta:mark_as_private("files")
meta:set_string("infotext", placer:get_player_name() .. "'s VM16 File Server")
end
local function on_receive_fields(pos, formname, fields, player)
if player and player:get_player_name() == M(pos):get_string("owner") then
if fields.destroy then
local node = minetest.get_node(pos)
minetest.remove_node(pos)
minetest.add_item(pos, node)
prog.del_mem(pos)
end
end
end
minetest.register_node("vm16:server", {
description = "VM16 File Server",
drawtype = "nodebox",
@ -129,23 +149,8 @@ minetest.register_node("vm16:server", {
"vm16_server_back.png",
"vm16_server_front.png",
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = M(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", "formspec_version[4]size[6,3]button[0.8,0.8;4.4,1.4;destroy;Destroy Server\n with all files?]")
meta:set_string("files", minetest.serialize({}))
meta:mark_as_private("files")
meta:set_string("infotext", placer:get_player_name() .. "'s VM16 File Server")
end,
on_receive_fields = function(pos, formname, fields, player)
if player and player:get_player_name() == M(pos):get_string("owner") then
if fields.destroy then
minetest.remove_node(pos)
minetest.add_item(pos, {name = "vm16:server"})
prog.del_mem(pos)
end
end
end,
after_place_node = after_place_node,
on_receive_fields = on_receive_fields,
paramtype2 = "facedir",
paramtype = "light",
sunlight_propagates = true,
@ -161,3 +166,27 @@ minetest.register_node("vm16:server", {
stack_max = 1,
groups = {cracky=2, crumbly=2, choppy=2},
})
minetest.register_node("vm16:server2", {
description = "VM16 File Server",
tiles = {
-- up, down, right, left, back, front
"vm16_programmer2_top.png",
"vm16_programmer2_top.png",
"vm16_programmer2_side.png",
"vm16_programmer2_side.png",
"vm16_server2_back.png",
"vm16_server2_front.png",
},
after_place_node = after_place_node,
on_receive_fields = on_receive_fields,
paramtype2 = "facedir",
is_ground_content = false,
on_blast = function() end,
on_destruct = function () end,
can_dig = function() return false end,
diggable = false,
drop = "",
stack_max = 1,
groups = {cracky=2, crumbly=2, choppy=2},
})

View File

@ -31,7 +31,6 @@ local function format_asm_code(mem, text)
saddr = string.format("%04X: ", mem.tAddress[lineno])
is_curr_line = mem.tAddress[lineno] == addr
end
if is_curr_line and mem.breakpoint_lines[lineno] then
tag = "*>"
elseif is_curr_line then
@ -165,9 +164,9 @@ end
local function fs_window(pos, mem, x, y, xsize, ysize, fontsize, text)
local color = mem.running and "#AAA" or "#FFF"
local code
if mem.asm_code then
if mem.file_ext == "asm" then
code = format_asm_code(mem, text) .. ";" .. (mem.cursorline or 1) .. "]"
else
elseif mem.file_ext == "c" then
code = format_src_code(mem, text) .. ";" .. (mem.cursorline or 1) .. "]"
end
@ -179,23 +178,25 @@ local function fs_window(pos, mem, x, y, xsize, ysize, fontsize, text)
end
function vm16.debug.formspec(pos, mem, textsize)
if mem.running then
vm16.menubar.add_button("stop", "Stop")
else
vm16.menubar.add_button("edit", "Edit")
vm16.menubar.add_button("step", "Step")
vm16.menubar.add_button("runto", "Run to C")
vm16.menubar.add_button("run", "Run")
vm16.menubar.add_button("reset", "Reset")
end
mem.status = mem.running and "Running..." or minetest.formspec_escape("Debug | Out[0]: " .. (mem.output or ""))
if mem.asm_code then
return fs_window(pos, mem, 0.2, 0.6, 8.4, 9.6, textsize, mem.asm_code or "") ..
if mem.running then
vm16.menubar.add_button("stop", "Stop")
else
vm16.menubar.add_button("edit", "Edit")
vm16.menubar.add_button("step", "Step")
vm16.menubar.add_button("runto", "Run to C")
vm16.menubar.add_button("run", "Run")
vm16.menubar.add_button("reset", "Reset")
end
mem.status = mem.running and "Running..." or minetest.formspec_escape("Debug | Out[0]: " .. (mem.output or ""))
if mem.file_text then
if mem.file_ext == "asm" then
return fs_window(pos, mem, 0.2, 0.6, 8.4, 9.6, textsize, mem.file_text) ..
vm16.memory.fs_window(pos, mem, 8.8, 0.6, 6, 9.6, textsize)
else
return fs_window(pos, mem, 0.2, 0.6, 11.4, 9.6, textsize, mem.text or "") ..
elseif mem.file_ext == "c" then
return fs_window(pos, mem, 0.2, 0.6, 11.4, 9.6, textsize, mem.file_text) ..
vm16.watch.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
end
end
end
function vm16.debug.on_receive_fields(pos, fields, mem)
@ -214,12 +215,12 @@ function vm16.debug.on_receive_fields(pos, fields, mem)
end
elseif fields.step then
if vm16.is_loaded(mem.cpu_pos) then
if mem.asm_code then
if mem.file_ext == "asm" then
vm16.run(mem.cpu_pos, mem.cpu_def, mem.breakpoints, 1)
local addr = vm16.get_pc(mem.cpu_pos)
mem.cursorline = mem.tLineno[addr] or 1
mem.curr_lineno = mem.cursorline
else
elseif mem.file_ext == "c" then
local lineno = get_next_lineno(pos, mem)
set_temp_breakpoint(pos, mem, lineno)
start_cpu(mem)

View File

@ -37,6 +37,11 @@ local function file_ext(filename)
return ext
end
local function file_base(filename)
local name, _ = unpack(string.split(filename, ".", true, 1))
return name
end
local function fs_editor(pos, mem, fontsize, file, text)
return "box[" .. EDIT_SIZE .. ";#000]" ..
"style_type[textarea;font=mono;textcolor=#FFF;border=false;font_size=" .. fontsize .. "]" ..
@ -51,115 +56,96 @@ local function fs_listing(pos, mem, fontsize, file, text, err)
minetest.formspec_escape(add_lineno(pos, text, err)) .. "]"
end
local function fs_asm_code(pos, mem, fontsize, file, text)
return "box[" .. EDIT_SIZE .. ";#000]" ..
"style_type[textarea;font=mono;textcolor=#FFF;border=false;font_size=" .. fontsize .. "]" ..
"textarea[" .. EDIT_SIZE .. ";;ASM Code: " .. file .. ";" ..
minetest.formspec_escape(text) .. "]"
end
function vm16.edit.formspec(pos, mem, textsize)
if mem.error then
-- Output listing + error
vm16.menubar.add_button("edit", "Edit")
mem.status = "Error !!!"
mem.text = mem.text or ""
return fs_listing(pos, mem, textsize, "out.lst", mem.text, mem.error) ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
elseif mem.asm_code then
-- Edit asm code
vm16.menubar.add_button("edit", "Edit")
vm16.menubar.add_button("asmdbg", "Debug")
mem.status = "Edit"
mem.text = nil
return fs_asm_code(pos, mem, textsize, mem.filename, mem.asm_code) ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
else
-- Edit source code
mem.status = "Edit"
if not mem.filename or not mem.text then
mem.filename = "-"
mem.text = "<no file>"
end
vm16.menubar.add_button("cancel", "Cancel")
vm16.menubar.add_button("save", "Save")
local ext = file_ext(mem.filename)
if ext == "c" then
if mem.file_name and mem.file_text then
if mem.error then
-- Output listing + error
mem.status = "Error !!!"
vm16.menubar.add_button("edit", "Edit")
return fs_listing(pos, mem, textsize, "out.lst", mem.file_text , mem.error) ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
elseif mem.file_ext == "asm" then
mem.status = "Edit"
vm16.menubar.add_button("edit", "Edit")
vm16.menubar.add_button("asmdbg", "Debug")
elseif mem.file_ext == "c" then
mem.status = "Edit"
vm16.menubar.add_button("cancel", "Cancel")
vm16.menubar.add_button("save", "Save")
vm16.menubar.add_button("compile", "Compile")
vm16.menubar.add_button("debug", "Debug")
return fs_editor(pos, mem, textsize, mem.filename, mem.text) ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
elseif ext == "asm" then
elseif mem.file_ext == "asm" then
mem.status = "Edit"
vm16.menubar.add_button("cancel", "Cancel")
vm16.menubar.add_button("save", "Save")
vm16.menubar.add_button("asmdbg", "Debug")
mem.asm_code = mem.text
mem.text = nil
return fs_editor(pos, mem, textsize, mem.filename, mem.asm_code) ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
else
return fs_editor(pos, mem, textsize, mem.filename, mem.text) ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
end
return fs_editor(pos, mem, textsize, mem.file_name, mem.file_text) ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
else
return fs_editor(pos, mem, textsize, "-", "<no file>") ..
vm16.files.fs_window(pos, mem, 11.8, 0.6, 6, 9.6, textsize)
end
end
function vm16.edit.on_load_file(mem, name, text)
mem.filename = name
mem.text = text
mem.file_name = name
mem.file_text = text
mem.file_ext = file_ext(mem.file_name)
mem.error = nil
mem.asm_code = nil -- TODO hier gleich die ext checken
end
function vm16.edit.on_receive_fields(pos, fields, mem)
if fields.code and (fields.save or fields.compile or fields.assemble or fields.debug) then
if mem.filename and mem.server_pos then
mem.text = fields.code
server.write_file(mem.server_pos, mem.filename, mem.text)
if mem.file_name and mem.server_pos then
mem.file_text = fields.code
server.write_file(mem.server_pos, mem.file_name, mem.file_text)
end
end
if fields.cancel then
mem.filename = nil
mem.text = nil
mem.file_name = nil
mem.file_text = nil
mem.error = nil
mem.asm_code = nil
elseif fields.edit then
mem.error = nil
elseif fields.compile then
mem.error = nil
mem.asm_code, mem.error = vm16.gen_asm_code(mem.filename or "", mem.text or "")
vm16.files.init(pos, mem)
elseif fields.debug then
local def = prog.get_cpu_def(mem.cpu_pos)
if def then
local prog_pos = def.on_check_connection(mem.cpu_pos)
if vector.equals(pos, prog_pos) then
local result = vm16.gen_obj_code(mem.filename or "", mem.text or "")
if not result.errors then
vm16.debug.init(pos, mem, result)
vm16.watch.init(pos, mem, result)
else
mem.error = result.errors
elseif mem.file_name and mem.file_text then
if fields.compile then
mem.error = nil
mem.file_name = file_base(mem.file_name) .. ".asm"
mem.file_ext = "asm"
mem.file_text, mem.error = vm16.gen_asm_code(mem.file_name, mem.file_text)
vm16.files.init(pos, mem)
elseif fields.debug then
local def = prog.get_cpu_def(mem.cpu_pos)
if def then
local prog_pos = def.on_check_connection(mem.cpu_pos)
if vector.equals(pos, prog_pos) then
local result = vm16.gen_obj_code(mem.file_name, mem.file_text)
if not result.errors then
vm16.debug.init(pos, mem, result)
vm16.watch.init(pos, mem, result)
mem.error = nil
else
mem.error = result.errors
end
end
end
elseif fields.asmdbg then
local def = prog.get_cpu_def(mem.cpu_pos)
if def then
local prog_pos = def.on_check_connection(mem.cpu_pos)
if vector.equals(pos, prog_pos) then
local result = vm16.assemble(mem.file_name, mem.file_text)
if not result.errors then
vm16.debug.init(pos, mem, result)
vm16.memory.init(pos, mem, result)
mem.error = nil
else
mem.error = result.errors
end
end
mem.error = nil
mem.asm_code = nil
end
end
elseif fields.asmdbg and mem.asm_code then
local def = prog.get_cpu_def(mem.cpu_pos)
if def then
local prog_pos = def.on_check_connection(mem.cpu_pos)
if vector.equals(pos, prog_pos) then
local result = vm16.assemble(mem.filename or "out.asm", mem.asm_code)
if not result.errors then
vm16.debug.init(pos, mem, result)
vm16.memory.init(pos, mem, result)
else
mem.error = result.errors
end
mem.error = nil
mem.text = nil
end
end
else
vm16.files.on_receive_fields(pos, fields, mem)
end
vm16.files.on_receive_fields(pos, fields, mem)
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 70 KiB

BIN
textures/vm16_16.xcf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B