Now to draw some Fontrix fonts:

[Linked Image from][Linked Image from]
[Linked Image from][Linked Image from]

I was able to get some files from Printrix to draw also, which has Times 25,30,40,50,70 and Helvetica 25,30,40,50,70.

Since the printrix disk was Prodos, I created a dos3.3 image in the file manager (I called it created_image.dsk and you can see the SET.HELVET25) and used COPY II+ to copy the files over so I could access them. (I haven't written routines to access Prodos disks yet -- coming soon after I can decipher Beyond Apple Prodos).

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

function calcyaddr(line,page) return calc(line,page) end

function plot(x,y,page,bit,operation) page=page or 0 x = math.max(0,x) x = math.min(x,279) y = math.max(0,y) y = math.min(y,191) mem=applemem() 
local memloc=calcyaddr(y,page)+math.floor(x/7)
local readval=mem:read_u8(memloc) local bitpos=x%7
local mask=~(1<<bitpos)
local invertmask=(1<<bitpos)
local bitshifted = bit<<bitpos 
local notbitshifted=(iif(bit==0,1,0) << bitpos)
if operation == nil or operation == "or" then mem:write_u8(memloc,readval | (bit<<bitpos)) 
elseif operation == "erase"     then mem:write_u8(memloc,readval & (bit<<bitpos)) 
elseif operation == "color"     then mem:write_u8(memloc,readval & (bit<<bitpos))  -- erase = color black
elseif operation == "xor"     then mem:write_u8(memloc,readval ~ (bit<<bitpos)) 
elseif operation == "store"   then mem:write_u8(memloc,(readval & mask) | bitshifted)
elseif operation == "inverse" then mem:write_u8(memloc,(readval & mask) | notbitshifted)
else error("PLOT OPERATION "..operation.." not recognized") end

function applemem() return manager:machine().devices[":maincpu"].spaces["program"] end

function hgrwhite(page) for x=0,39 do for y=0,191 do applemem():write_u8(calcyaddr(y,page)+x,127) end end end

function getbits(a,lobit,hibit) if a==nil then print("getbits:NIL!") return 0 end local retval=0 for bit=lobit,hibit do retval=retval|((1<<bit)&a) end return retval end

function getbitsshift(a,lobit,hibit) if a==nil then print("getbitsshift:NIL!") return 0 end return getbits(a,lobit,hibit)>>lobit end

function getcharheightfontrix(a,c) return a:byte(0x14+1) end
function getcharwidthfontrix(a,c)  return a:byte((0xe2)+(c-1)+1) end

function getcharwidthfontrix(a,c)  if a:byte(0x12+1)==0 then return a:byte(0x13+1) else return a:byte((0xe2)+(c-1)+1) end end

function getcharoffsetfontrix(a,c) return a:byte((0x20)+(c-1)*2+1)+a:byte((0x21)+(c-1)*2+1)*256 end

function applemem() 
  if applememobject == nil then applememobject = manager:machine().devices[":maincpu"].spaces["program"] end
  return applememobject

-- subtle difference, between just catalog() and return catalog()
function cat(...) return catalog(...) end
function CAT(...) return catalog(...) end

--new version of drawfontrix font, with xpos coordinate is pixel, not byte
function drawfontrixfont2(a,c0,c1,offset,doprint,xpos,ypos,lineheight,drawmode)
-- draw font characters from c0 to c1
c0 = c0 or 0
c1 = c1 or 58
offset=offset or 0
xpos,ypos=xpos or 0,ypos or 0
for c=c0,c1 do 
local charwidth=getcharwidthfontrix(a,c)
local charheight=getcharheightfontrix(a,c)
local charoffset=getcharoffsetfontrix(a,c)
local charbytewidth=math.floor((charwidth-1)/8)+1
if doprint then print("char="..c.."  "..string.char(c+31),"width="..charwidth,"height="..charheight,"offset="..hex(charoffset).." vpos="..getcharvposfontrix(a,c))
if charoffset>#a then print("INVALID CHAR OFFSET") 
drawblockloop({"y",charheight,"x",charbytewidth},function(x,y,index) local bytetoplot=(a:sub(charoffset+1):byte(index+offset+1)) local numpixels=math.min(8,charwidth-8*x) x=xpos+x*8 for i=0,numpixels-1 do plot(x+i,y+ypos+getcharvposfontrix(a,c),0,getbitsshift(bytetoplot,i,i),drawmode) end end,32)
xpos=xpos+charwidth+2 -- pixels now
if xpos>250 then xpos=0 ypos=ypos+lineheight end  -- ypos=ypos+charheight+1 
print("returning xpos="..xpos.." ypos="..ypos)
return xpos,ypos

function writetextfontrix2(a,s,x,y,lineheight,drawmode) for i=1,#s do c=s:byte(i) c=c-32+1 x,y=drawfontrixfont2(a,c,c,0,nil,x,y,lineheight,drawmode) if x>250 then x=0 y=y+lineheight print(y) end end end

-- for the bigger fonts
function getcharheightfontrix(a,c) return a:byte(0x200+(c-2)+1) end

function getcharheightfontrix(a,c) if a:byte(1)==0x14 then return a:byte(0x200+(c-2)+1) else return a:byte(0x14+1) end end
function getcharvposfontrix(a,c) if a:byte(1)==0x14 then return a:byte(0x200+96*1-1+(c-2)+1) else return 0 end end


function getfilenamepart(s)
local curpos=1
local newpos=s:find("/",curpos,true)
if newpos then curpos = newpos+1 end  -- if you don't add the +1, keeps getting same match, infinite loop
until newpos == nil
return s:sub(curpos)

function trim2(s) return s:match "^%s*(.-)%s*$" end  -- from lua users wiki

loaddisk("../../fontrix.dsk") setascii=getfile("SET.ASCII BOLD")

co1=coroutine.create( function()
disknamelist={"../../fontrix.dsk","../../Font Paks 1 and 2.dsk","../../fontrixfontpak14.dsk","../../created_image.dsk"}
for d=1,#disknamelist do diskname=disknamelist[d] 
for i=1,#filelist do print(filelist[i]) 
if filelist[i]:find("SET.",1,true) then 
print("IT'S A FONT so let's render a sample!") 
 hgr() hgrfull() hgrclr() xpos=0 ypos=10
manager:machine():debugger():command("snap \"" .. sanefilename(getfilenamepart(diskname).."_"..trim2(filelist[i]))..".png\"")
end end


I think the screen's too small for 50 point type.

[Linked Image from][Linked Image from]