function asc(c) return string.byte(c) end
function getnnnn()
local i local retval=0 for i=3,0,-1 do ch=coroutine.yield() if ch >= asc('0') and ch <= asc('9') then retval = retval + (ch-asc('0'))*10^(i) end end return retval end
function getn(n)
local i local retval=0 for i=n-1,0,-1 do ch=coroutine.yield() if ch >= asc('0') and ch <= asc('9') then retval = retval + (ch-asc('0'))*10^(i) end end return retval end
function renderhead(v) for i=0,7 do if (v & (2^i))~=0 then lp0:drawpixel(xpos,ypos+i,0) end end end
function dogfx() ch=coroutine.yield() renderhead(ch) xpos=xpos+1 lp0:setheadpos(xpos,ypos) end
function renderprt(ch)
local xdpi,ydpi,feed,lfdir
xdpi = 144
ydpi = 72
feed=144/8
xpos=0
ypos=0
while 1 do
ch = coroutine.yield()
--print ("renderprt: "..ch.." "..string.char(ch))
if ch == 27 then
ch = coroutine.yield()
if ch == asc('n') then dpi=72
elseif ch == asc('N') then xdpi=80
elseif ch == asc('E') then xdpi=96
elseif ch == asc('p') then xdpi=144
elseif ch == asc('P') then xdpi=160
elseif ch == asc('e') then xdpi=107
elseif ch == asc('q') then xdpi=120
elseif ch == asc('Q') then xdpi=136
elseif ch == asc('f') then lfdir=1
elseif ch == asc('r') then lfdir=-1
elseif ch == asc('L') then lm=getn(3)
elseif ch == asc('>') then bidir=0
elseif ch == asc('<') then bidir=1
elseif ch == asc('A') then feed=144/6 -- 24
elseif ch == asc('B') then feed=144/8 -- 18
elseif ch == asc('T') then feed=getn(2)
elseif ch == asc('G') then nchars=getn(4) for i=1,nchars do dogfx() end
elseif ch == asc('S') then nchars=getn(4) for i=1,nchars do dogfx() end
elseif ch == asc('g') then nchars=getn(3)*8 for i=1,nchars do dogfx() end
elseif ch == asc('V') then nchars=getn(4)
ch=coroutine.yield() for i=1,nchars do renderhead(ch) end
elseif ch == asc('F') then xpos = getn(4)
elseif ch == asc('V') then -- set tof
elseif ch == asc('O') then -- paper detect off
elseif ch == asc('o') then -- paper detect on
elseif ch == asc('!') then -- start bold
elseif ch == asc('"') then -- end bold
elseif ch == asc('X') then -- start underline
elseif ch == asc('Y') then -- end underline
else -- gobble char
end
elseif ch == 13 then xpos = 0 -- cr
elseif ch == 10 then ypos = ypos + feed/144*ydpi xpos = 0 -- lf
elseif ch == 12 then -- formfeed
end
end
end
corenderprt = coroutine.create(renderprt)
coroutine.resume(corenderprt)
lp0 = manager:machine().luaprinters[0]
function feedchars(ch)
repeat
nextchar = lp0:getnextchar()
if nextchar >= 0 then coroutine.resume(corenderprt,nextchar) end
until nextchar < 0
end
function framedispatch() for i,j in pairs(dispatchlist) do j() end end
emu.register_frame(framedispatch)
dispatchlist={feedchars}