Some more silly fun:

I always thought that Altirra's enhanced text mode was pretty cool, so why not see if I could do a text overlay with lua?

Code

-- 80 column text overlay for Apple IIe

function calc(line,page) page=page or 0 return line % 8 * 1024 + math.floor(line / 64) * 40 + math.floor((line%64) / 8) * 128 + 8192* (page + 1) end

function iskeypressed(keycode) 
inp = manager:machine():input() return inp:code_pressed(inp:code_from_token(keycode))
end

function striphi(a) if type(a)=="number" then a=string.char(a) end local b="" for i=1,#a do b=b..string.char(string.byte(a,i)&0x7f) end return b end

mem=manager:machine().devices[":maincpu"].spaces["program"]
aux=emu.item(manager:machine().devices[":aux:ext80"].items["0/m_ram"])
scr=manager:machine().screens[":screen"]

function widthpct(c) if c==nil or c==string.char(0) then return 0 end return ((manager:ui():get_string_width(c,1.0)/manager:ui():get_string_width("A",1.0))) end
function widthoffset(c) if c==nil or c==string.char(0) then return 0 end return 3.5*(1-widthpct(c)) end


drawoverlay=true
keydelay=0

function print_80col()
for y=0,23 do for x=0,39 do offset=calc(y*8)-8192+x 
c1=striphi(aux:read(1024+offset)) c0=striphi(mem:read_u8(1024+offset))
io.write(c1..c0) end print() end
end

function draw_80col()
if keydelay > 0 then keydelay = keydelay - 1 end
if drawoverlay then 
scr:draw_box(0,0,559,279,0xff000000,0xffffffff)for y=0,23 do for x=0,39 do offset=calc(y*8)-8192+x 
c1=striphi(aux:read(1024+offset)) c0=striphi(mem:read_u8(1024+offset))
scr:draw_text((x*2+0)*7+widthoffset(c1),y*8,c1,0xffffffff,0xff000000) scr:draw_text((x*2+1)*7+widthoffset(c0),y*8,c0,0xffffffff,0xff000000) end end
end
if iskeypressed("KEYCODE_LSHIFT") and keydelay==0 then drawoverlay=not drawoverlay keydelay=20 end
end

draw80dispatchlist={draw_80col}

function draw80dispatch() for i,j in pairs(draw80dispatchlist) do j() end end

function drawon() draw80dispatchlist={draw_80col} end
function drawoff() draw80dispatchlist={} end

if not alreadyregistereddraw80 then
  emu.register_frame_done(draw80dispatch)
  alreadyregistereddraw80=true
end



With overlay:
[Linked Image from i.imgur.com]

Without overlay:
[Linked Image from i.imgur.com]


Just hit the shift key to toggle it on/off


It took me a while to figure out why it looks strange when it's scrolling in 80 columns. Reading with manager:machine().devices[":maincpu"].spaces["program"]:read_u8() gets the data from the auxiliary memory when the softswitches are set during the scroll.

Last edited by Golden Child; 03/03/19 01:42 AM.