Skip to content

Commit 4f6b9ea

Browse files
committed
Fix cryptic r3.term error message when overlapping the screen and keyboard
Also fix negative-size area check and a crash when passing no configuration to r3.plot.
1 parent 19aac78 commit 4f6b9ea

2 files changed

Lines changed: 46 additions & 40 deletions

File tree

r3/comp/terminal/init.lua

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,10 @@ local function build_internal(params, derived_params)
17911791
-- skip
17921792
else
17931793
for yy = 0, 3 do
1794-
part({ type = pt.FILT, x = x, y = y_interface + 21 + yy })
1794+
local p = part({ type = pt.FILT, x = x, y = y_interface + 21 + yy })
1795+
if x <= x1 or x >= x2 then
1796+
p.dcolour = 0xFF00FFFF
1797+
end
17951798
end
17961799
end
17971800
end
@@ -1854,46 +1857,30 @@ local function build(params, params_name)
18541857
have_screen = have_screen,
18551858
have_keyboard = have_keyboard,
18561859
}
1857-
if have_screen then
1858-
if interface_y - (chars_h + yoff + screen_padding) + 1 < 0 then
1859-
misc.user_error("%s specifies too little distance from the bus", params_name .. "." .. params.screen_y.which)
1860-
end
1861-
end
1862-
if have_keyboard then
1863-
if keyboard_y - interface_y - 5 < 0 then
1864-
misc.user_error("%s specifies too little distance from the bus", params_name .. "." .. params.keyboard_y.which)
1865-
end
1866-
end
18671860
if not have_screen and not have_keyboard then
18681861
misc.user_error("at least one of %s and %s must be specified", params_name .. ".screen_top/.screen_bottom", params_name .. ".keyboard_top/.keyboard_bottom")
18691862
end
18701863
if params.unibody then
18711864
if not (have_screen and have_keyboard) then
1872-
misc.user_error("%s requests a unibody configuration, which required both a screen and a keyboard", params_name .. ".unibody")
1865+
misc.user_error("%s requests a unibody configuration, which requires both a screen and a keyboard", params_name .. ".unibody")
18731866
end
18741867
end
18751868
local parts_internal = build_internal(params, derived_params)
18761869
local parts = {}
18771870
plot.merge_parts(xoff, yoff, parts, parts_internal)
1878-
if params.unibody then
1879-
table.insert(areas, {
1871+
local screen_body, keyboard_body
1872+
if have_screen then
1873+
screen_body = {
18801874
type = "solid",
1881-
name = "body",
1875+
name = "screen",
18821876
x = xoff - screen_padding,
18831877
y = yoff - screen_padding,
18841878
w = chars_w + 2 * screen_padding,
1885-
h = keyboard_y + 51 - (yoff - screen_padding),
1886-
})
1887-
else
1888-
if have_screen then
1889-
table.insert(areas, {
1890-
type = "solid",
1891-
name = "screen",
1892-
x = xoff - screen_padding,
1893-
y = yoff - screen_padding,
1894-
w = chars_w + 2 * screen_padding,
1895-
h = chars_h + 2 * screen_padding,
1896-
})
1879+
h = chars_h + 2 * screen_padding,
1880+
}
1881+
if params.unibody then
1882+
screen_body.h = screen_body.h - 1
1883+
else
18971884
local interface = {
18981885
type = "solid",
18991886
name = "screen_interface",
@@ -1913,15 +1900,21 @@ local function build(params, params_name)
19131900
h = interface_y - (yoff + chars_h + screen_padding) - 3,
19141901
})
19151902
end
1916-
if have_keyboard then
1917-
table.insert(areas, {
1918-
type = "solid",
1919-
name = "keyboard",
1920-
x = xoff - screen_padding,
1921-
y = keyboard_y,
1922-
w = chars_w + 2 * screen_padding,
1923-
h = 51,
1924-
})
1903+
table.insert(areas, screen_body)
1904+
end
1905+
if have_keyboard then
1906+
keyboard_body = {
1907+
type = "solid",
1908+
name = "keyboard",
1909+
x = xoff - screen_padding,
1910+
y = keyboard_y,
1911+
w = chars_w + 2 * screen_padding,
1912+
h = 51,
1913+
}
1914+
if params.unibody then
1915+
keyboard_body.y = keyboard_body.y - 1
1916+
keyboard_body.h = keyboard_body.h + 1
1917+
else
19251918
local interface = {
19261919
type = "solid",
19271920
name = "keyboard_interface",
@@ -1941,6 +1934,19 @@ local function build(params, params_name)
19411934
h = keyboard_y - interface_y - 9,
19421935
})
19431936
end
1937+
table.insert(areas, keyboard_body)
1938+
end
1939+
if params.unibody then
1940+
local interface = {
1941+
type = "solid",
1942+
name = "unibody_interface",
1943+
x = xoff - screen_padding,
1944+
y = screen_body.y + screen_body.h,
1945+
w = chars_w + 2 * screen_padding,
1946+
h = keyboard_body.y - (screen_body.y + screen_body.h),
1947+
}
1948+
table.insert(areas, interface)
1949+
table.insert(params.bus.through_areas, interface)
19441950
end
19451951
return {
19461952
parts = parts,

r3/plot.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ local function run(params)
2828
if rawget(_G, "r3plot") then
2929
r3plot.unregister()
3030
end
31-
if params.clear_sim then
32-
sim.clearSim()
33-
end
3431
check.table("params", params)
3532
check.table("params.components", params.components)
3633
if params.debug_stacks ~= nil then
@@ -231,7 +228,7 @@ local function run(params)
231228
local err
232229
local coverage = {}
233230
for ix_area, area in ipairs(areas) do
234-
if area.x < 0 or area.y < 0 then
231+
if area.w < 0 or area.h < 0 then
235232
err = ("area %s has negative dimensions"):format(area.name)
236233
break
237234
end
@@ -282,6 +279,9 @@ local function run(params)
282279
return prev_aftersimdraw()
283280
end
284281
end
282+
if params.clear_sim then
283+
sim.clearSim()
284+
end
285285
plot.create_parts(0, 0, parts)
286286
if params.clear_sim then
287287
sim.paused(true)

0 commit comments

Comments
 (0)