You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
4.1 KiB
201 lines
4.1 KiB
--listing pane
|
|
|
|
//room for 14 lines in the listing
|
|
|
|
selected_address = {"main", 1}
|
|
|
|
function l_pane_update()
|
|
if current_pane == 1 then
|
|
if last_edit_pane == 3 then
|
|
handle = holding
|
|
if (handle==nil) handle=under
|
|
addr = get_address_from_handle(handle)
|
|
if (addr ~= nil) selected_address=addr
|
|
end
|
|
last_edit_pane = 1
|
|
|
|
if btn(4) then
|
|
dx = 0
|
|
dy = 0
|
|
|
|
if (btn(0) and tx > 0) dx -= 1
|
|
if (btn(1) and tx < 127) dx += 1
|
|
if (btn(2) and ty > 0) dy -= 1
|
|
if (btn(3) and ty < 127) dy += 1
|
|
|
|
local h = nil
|
|
for handle in all(record_list) do
|
|
if deep_eq(handle.address, selected_address) then
|
|
h = handle
|
|
end
|
|
end
|
|
if h ~= nil then
|
|
perform_edit(m, h, dx, dy, false)
|
|
end
|
|
else
|
|
if btnp(2) then
|
|
selected_address[2] -= 1
|
|
if selected_address[2] < 1 then
|
|
selected_address[1] = get_previous_bank(selected_address[1])
|
|
selected_address[2] = #m[selected_address[1]]
|
|
end
|
|
end
|
|
if btnp(3) then
|
|
selected_address[2] += 1
|
|
if selected_address[2] > #m[selected_address[1]] then
|
|
selected_address[1] = get_next_bank(selected_address[1])
|
|
selected_address[2] = 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
// this should get run when we
|
|
// switch from the render pane
|
|
// to the listing pane, to get
|
|
// a selection in the listing
|
|
// pane
|
|
function get_address_from_handle(handle)
|
|
if handle ~= nil then
|
|
return deep_copy(handle.address)
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
function get_previous_bank(bank)
|
|
local i = #banks
|
|
for b in all(banks) do
|
|
if b == bank then
|
|
break
|
|
end
|
|
i += 1
|
|
if i > #banks then
|
|
i = 1
|
|
end
|
|
end
|
|
return banks[i]
|
|
end
|
|
|
|
function get_next_bank(bank)
|
|
local i = 1
|
|
for b in all(banks) do
|
|
i += 1
|
|
if i > #banks then
|
|
i = 1
|
|
end
|
|
if b == bank then
|
|
break
|
|
end
|
|
end
|
|
return banks[i]
|
|
end
|
|
|
|
disp_start = 1
|
|
window_size = 14
|
|
margin = 2
|
|
function l_pane_draw()
|
|
the_listing = make_listing()
|
|
|
|
s_index = nil
|
|
|
|
for idx, listing in pairs(the_listing) do
|
|
if deep_eq(listing[3], selected_address) then
|
|
s_index = idx
|
|
end
|
|
end
|
|
|
|
// if the selected line is
|
|
// outside the bounds, then
|
|
// move the bounds.
|
|
|
|
// if the selected line is
|
|
// less than start+margin
|
|
// then we need to move start
|
|
// up (decrease it)
|
|
while s_index < disp_start + margin do
|
|
disp_start = disp_start - 1
|
|
end
|
|
|
|
// if it's greater than
|
|
// start+window_size - margin
|
|
// then we need to move start
|
|
// down (increase it)
|
|
while s_index >= disp_start + window_size - margin do
|
|
disp_start = disp_start + 1
|
|
end
|
|
|
|
// if start + window_size is
|
|
// greater than the number of
|
|
// lines in the listing, then
|
|
// move back up (decrease)
|
|
if disp_start + window_size > #the_listing then
|
|
disp_start = #the_listing - window_size + 1
|
|
end
|
|
|
|
// if start is less than 1
|
|
// then start should be 1
|
|
if (disp_start < 1) disp_start = 1
|
|
|
|
for i, v in pairs(the_listing) do
|
|
if i>=disp_start and i < disp_start + window_size then
|
|
print(v[1], 0, 17+7*(i - disp_start), v[2])
|
|
end
|
|
end
|
|
end
|
|
|
|
function make_listing()
|
|
local output = {}
|
|
for bank in all(banks) do
|
|
contents = m[bank]
|
|
|
|
str = ":"..bank..":"
|
|
col = 13
|
|
addr = nil
|
|
|
|
add(output, {str, col, addr})
|
|
|
|
for j,op in pairs(contents) do
|
|
str = op_pretty_print(op)
|
|
col = get_line_color(bank, j)
|
|
addr = {bank, j}
|
|
|
|
add(output, {str, col, addr})
|
|
end
|
|
end
|
|
|
|
return output
|
|
end
|
|
function get_line_color(bank, idx)
|
|
if bank==selected_address[1]
|
|
and idx==selected_address[2] then
|
|
return 6
|
|
end
|
|
return 13
|
|
end
|
|
|
|
function op_pretty_print(op)
|
|
opc = "n"
|
|
|
|
if (op[1]=="return") opc="return"
|
|
if (op[1]=="jump") opc="j"
|
|
if (op[1]=="scale") opc="s"
|
|
if (op[1]=="rotate") opc="rot "
|
|
if (op[1]=="move") opc="m"
|
|
if (op[1]=="place") opc="p"
|
|
if (op[1]=="draw") opc="d"
|
|
if (op[1]=="draw_abs") opc="a"
|
|
if (op[1]=="color") opc="c"
|
|
|
|
if #op == 2 then
|
|
opc = opc..op[2]
|
|
elseif #op == 3 then
|
|
arg1 = sub(tostr(op[2]), 1, 3)
|
|
arg2 = sub(tostr(op[3]), 1, 3)
|
|
opc = opc..arg1..","..arg2
|
|
end
|
|
|
|
return opc
|
|
end
|
|
|
|
|