mirror of
https://github.com/zenith391/OCEmu.git
synced 2025-09-28 23:47:41 -04:00
Moar fixes
wrap unicode.lower/upper since utf8's handling of numbers differs than oc's handling of numbers move getCharWidth out of unicode.lua and into main.lua Fix characters being rendered when they should be hidden by a wide character Fix wide characters not setting the overlapping cell as a space Fix the overlapping character not being rendered when the wide character is removed Fix fill treating wide characters as not wide characters Fix set being crashed on invalid characters Change checkArg and compCheckArg to non merge versions, and edit the error message in compCheckArg to be similar to actual error messages
This commit is contained in:
parent
744e640bea
commit
d29c2bc7d7
@ -3,21 +3,24 @@ local env = ...
|
|||||||
local utf8 = require("utf8")
|
local utf8 = require("utf8")
|
||||||
|
|
||||||
env.unicode = {
|
env.unicode = {
|
||||||
lower = utf8.lower,
|
|
||||||
upper = utf8.upper,
|
|
||||||
char = utf8.char,
|
char = utf8.char,
|
||||||
len = utf8.len,
|
len = utf8.len,
|
||||||
reverse = utf8.reverse,
|
reverse = utf8.reverse,
|
||||||
sub = utf8.sub,
|
sub = utf8.sub,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function getCharWidth(char)
|
function env.unicode.lower(str)
|
||||||
if unifont[char] ~= nil then
|
cprint("unicode.lower", str)
|
||||||
return #unifont[char] / 32
|
if type(str) == "number" then str = tostring(str) end
|
||||||
end
|
checkArg(1,str,"string")
|
||||||
return 1
|
return utf8.lower(str)
|
||||||
|
end
|
||||||
|
function env.unicode.upper(str)
|
||||||
|
cprint("unicode.upper", str)
|
||||||
|
if type(str) == "number" then str = tostring(str) end
|
||||||
|
checkArg(1,str,"string")
|
||||||
|
return utf8.upper(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
function env.unicode.isWide(str)
|
function env.unicode.isWide(str)
|
||||||
cprint("unicode.isWide", str)
|
cprint("unicode.isWide", str)
|
||||||
checkArg(1,str,"string")
|
checkArg(1,str,"string")
|
||||||
|
@ -111,8 +111,8 @@ function elsa.draw()
|
|||||||
SDL.renderPresent(renderer)
|
SDL.renderPresent(renderer)
|
||||||
end
|
end
|
||||||
|
|
||||||
local char8 = ffi.new("uint32_t[?]", 8*16);
|
local char8 = ffi.new("uint32_t[?]", 8*16)
|
||||||
local char16 = ffi.new("uint32_t[?]", 16*16);
|
local char16 = ffi.new("uint32_t[?]", 16*16)
|
||||||
local function renderChar(char,x,y,fg,bg)
|
local function renderChar(char,x,y,fg,bg)
|
||||||
if unifont[char] == nil then
|
if unifont[char] == nil then
|
||||||
char = 63
|
char = 63
|
||||||
@ -139,15 +139,31 @@ local function renderChar(char,x,y,fg,bg)
|
|||||||
SDL.updateTexture(texture, ffi.new("SDL_Rect",{x=x,y=y,w=size*4,h=16}), pchar, (size*4) * ffi.sizeof("uint32_t"))
|
SDL.updateTexture(texture, ffi.new("SDL_Rect",{x=x,y=y,w=size*4,h=16}), pchar, (size*4) * ffi.sizeof("uint32_t"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setPos(x,y,c,fg,bg)
|
local function screenSet(x,y,c)
|
||||||
local renderchange = screen.txt[y][x] ~= utf8.char(c) or screen.bg[y][x] ~= scrbgc or (screen.txt[y][x] ~= " " and screen.fg[y][x] ~= scrfgc)
|
|
||||||
screen.txt[y][x] = utf8.char(c)
|
screen.txt[y][x] = utf8.char(c)
|
||||||
screen.fg[y][x] = scrfgc
|
screen.fg[y][x] = scrfgc
|
||||||
screen.bg[y][x] = scrbgc
|
screen.bg[y][x] = scrbgc
|
||||||
screen.fgp[y][x] = scrfgp
|
screen.fgp[y][x] = scrfgp
|
||||||
screen.bgp[y][x] = scrbgp
|
screen.bgp[y][x] = scrbgp
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setPos(x,y,c,fg,bg)
|
||||||
|
local renderchange = screen.txt[y][x] ~= utf8.char(c) or screen.bg[y][x] ~= scrbgc or (screen.txt[y][x] ~= " " and screen.fg[y][x] ~= scrfgc)
|
||||||
|
local charWidth = getCharWidth(c)
|
||||||
|
local renderafter = getCharWidth(utf8.byte(screen.txt[y][x])) > 1 and charWidth == 1 and x < width
|
||||||
|
if x > 1 and getCharWidth(utf8.byte(screen.txt[y][x-1])) > 1 then
|
||||||
|
renderchange = false
|
||||||
|
else
|
||||||
|
screenSet(x,y,c)
|
||||||
|
end
|
||||||
if renderchange then
|
if renderchange then
|
||||||
renderChar(c,(x-1)*8,(y-1)*16,fg,bg)
|
renderChar(c,(x-1)*8,(y-1)*16,fg,bg)
|
||||||
|
if charWidth > 1 and x < width then
|
||||||
|
screenSet(x+1,y,32)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if renderafter then
|
||||||
|
renderChar(32,x*8,(y-1)*16,screen.fg[y][x+1],screen.bg[y][x+1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -248,14 +264,14 @@ function cec.fill(x1, y1, w, h, char) -- Fills a portion of the screen at the sp
|
|||||||
if w <= 0 or h <= 0 then
|
if w <= 0 or h <= 0 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local x2 = x1+w-1
|
local code = utf8.byte(char)
|
||||||
|
local x2 = x1+(w*getCharWidth(code))-1
|
||||||
local y2 = y1+h-1
|
local y2 = y1+h-1
|
||||||
if x2 < 1 or y2 < 1 or x1 > width or y1 > height then
|
if x2 < 1 or y2 < 1 or x1 > width or y1 > height then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local code = utf8.byte(char)
|
|
||||||
for y = y1,y2 do
|
for y = y1,y2 do
|
||||||
for x = x1,x2 do
|
for x = x1,x2,getCharWidth(code) do
|
||||||
setPos(x,y,code,scrfgc,scrbgc)
|
setPos(x,y,code,scrfgc,scrbgc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -305,7 +321,7 @@ function cec.set(x, y, value, vertical) -- Plots a string value to the screen at
|
|||||||
if x >= 1 then
|
if x >= 1 then
|
||||||
setPos(x,y,c,scrfgc,scrbgc)
|
setPos(x,y,c,scrfgc,scrbgc)
|
||||||
end
|
end
|
||||||
x = x + #unifont[c]/32
|
x = x + getCharWidth(c)
|
||||||
if x > width then break end
|
if x > width then break end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
39
src/main.lua
39
src/main.lua
@ -45,27 +45,28 @@ machine = {
|
|||||||
signals = {},
|
signals = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
local function _checkArg(pos, n, have, ...)
|
local function check(have, want, ...)
|
||||||
|
if not want then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return have == want or check(have, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function checkArg(n, have, ...)
|
||||||
have = type(have)
|
have = type(have)
|
||||||
local function check(want, ...)
|
if not check(have, ...) then
|
||||||
if not want then
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
return have == want or check(...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not check(...) then
|
|
||||||
local msg = string.format("bad argument #%d (%s expected, got %s)", n, table.concat({...}, " or "), have)
|
local msg = string.format("bad argument #%d (%s expected, got %s)", n, table.concat({...}, " or "), have)
|
||||||
error(msg, pos)
|
error(msg, 3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function checkArg(...)
|
function compCheckArg(n, have, ...)
|
||||||
_checkArg(4, ...)
|
have = type(have)
|
||||||
end
|
if not check(have, ...) then
|
||||||
|
local msg = string.format("bad arguments #%d (%s expected, got %s)", n, table.concat({...}, " or "), have)
|
||||||
function compCheckArg(...)
|
error(msg, 4)
|
||||||
_checkArg(5, ...)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if true then
|
if true then
|
||||||
@ -236,6 +237,12 @@ for line in elsa.filesystem.lines("unifont.hex") do
|
|||||||
local a,b = line:match("(.+):(.*)")
|
local a,b = line:match("(.+):(.*)")
|
||||||
unifont[tonumber(a,16)] = b
|
unifont[tonumber(a,16)] = b
|
||||||
end
|
end
|
||||||
|
function getCharWidth(char)
|
||||||
|
if unifont[char] ~= nil then
|
||||||
|
return #unifont[char] / 32
|
||||||
|
end
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
-- load api's into environment
|
-- load api's into environment
|
||||||
elsa.filesystem.load("apis/computer.lua")(env)
|
elsa.filesystem.load("apis/computer.lua")(env)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user