Skip to content

Instantly share code, notes, and snippets.

@cheapie
Created November 18, 2021 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheapie/cbd4b7decb8af068d70f105576acd0df to your computer and use it in GitHub Desktop.
Save cheapie/cbd4b7decb8af068d70f105576acd0df to your computer and use it in GitHub Desktop.
--MT Paint
--A product of Advanced Mesecons Devices, a Cheapie Systems company
--This is free and unencumbered software released into the public domain.
--See http://unlicense.org/ for more information
--Buffer allocation:
----0: User drawing (64x64)
----1: Temporary for UI on canvas area (64x64)
----2: Menu bar framebuffer (64x16)
----3: Toolbar framebuffer (16x64)
----4: Swatch framebuffer (16x16)
----5: Palette framebuffer (64x16)
----6: Temporary for whatever (variable)
----7: Temporary for whatever (variable)
local commands = {}
local function gpu(command)
table.insert(commands,command)
end
local function send(buf,channel,xpanels,ypanels)
for y=1,ypanels,1 do
for x=1,xpanels,1 do
gpu({command="sendregion",buffer=buf,channel=string.format("%s%d%d",channel,x,y),x1=(x-1)*16+1,y1=(y-1)*16+1,x2=x*16,y2=y*16})
end
end
end
local function updateswatch()
gpu({command="drawrect",buffer=4,x1=7,y1=7,x2=15,y2=15,fill=mem.bgcolor})
gpu({command="drawrect",buffer=4,x1=2,y1=3,x2=9,y2=10,fill=mem.fgcolor})
send(4,"swatch",1,1)
end
local function updatetoolbar()
local toolbar = "VVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVV464/VVVVAAAAVVVVVVVV464/464/464/VVVVVVVVAAAAVVVVVVVVVVVVVVVVA49/VVVVVVVVAAAAVVVVVVVV464/464/464/VVVVVVVVAAAAVVVVVVVVVVVVA49/VVVVVVVVVVVVAAAAVVVVVVVV464/464/464/VVVVVVVVAAAAVVVVVVVVA49/VVVVVVVVVVVVVVVVAAAAVVVVVVVV464/464/464/VVVVVVVVAAAAVVVVO6ojVVVVVVVVVVVVVVVVVV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VVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAVVVVVVVVVVVVVVVVVVVVVVVVVVVVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
gpu({command="loadpacked",buffer=3,x=1,y=1,xsize=16,ysize=64,data=toolbar,})
local positions = {
pencil = {x = 1,y = 1},
eraser = {x = 9,y = 1},
spraycan = {x = 1,y = 9},
brush = {x = 9,y = 9},
line = {x = 1,y = 17},
rectangle = {x = 9,y = 17},
colorpicker = {x = 1,y = 25},
}
if positions[mem.tool] then
local x = positions[mem.tool].x
local y = positions[mem.tool].y
gpu({command="createbuffer",buffer=7,xsize=7,ysize=7,fill="ffffff"})
gpu({command="copy",src=7,dst=3,srcx=1,srcy=1,xsize=7,ysize=7,dstx=x,dsty=y,mode="average"})
end
send(3,"toolbar",1,4)
end
if event.type == "program" then
mem.state = "init"
mem.tool = "pencil"
mem.fgcolor = "000000"
mem.bgcolor = "ffffff"
gpu({command="createbuffer",buffer=0,xsize=64,ysize=64,fill="ffffff"})
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="createbuffer",buffer=3,xsize=16,ysize=64,fill="555555"})
gpu({command="createbuffer",buffer=4,xsize=16,ysize=16,fill="555555"})
gpu({command="createbuffer",buffer=5,xsize=64,ysize=16,fill="555555"})
gpu({command="createbuffer",buffer=6,xsize=64,ysize=64,fill="555555"})
gpu({command="text",buffer=1,x=2,y=2,color="aaaaaa",text="Loading"})
send(1,"canvas",4,4)
send(2,"menu",4,1)
send(3,"toolbar",1,4)
interrupt(2,"init2")
elseif event.iid == "init2" then
send(4,"swatch",1,1)
send(5,"palette",4,1)
send(6,"unused",1,1)
interrupt(2,"init3")
elseif event.iid == "init3" then
updateswatch()
interrupt(2,"init4")
elseif event.iid == "init4" then
gpu({command="drawrect",buffer=5,x1=1,y1=1,x2=64,y2=1,fill="000000"})
gpu({command="drawrect",buffer=5,x1=1,y1=9,x2=64,y2=9,fill="000000"})
gpu({command="drawrect",buffer=5,x1=9,y1=2,x2=9,y2=16,fill="000000"})
gpu({command="drawrect",buffer=5,x1=18,y1=2,x2=18,y2=16,fill="000000"})
gpu({command="drawrect",buffer=5,x1=27,y1=2,x2=27,y2=16,fill="000000"})
gpu({command="drawrect",buffer=5,x1=36,y1=2,x2=36,y2=16,fill="000000"})
gpu({command="drawrect",buffer=5,x1=45,y1=2,x2=45,y2=16,fill="000000"})
gpu({command="drawrect",buffer=5,x1=54,y1=2,x2=54,y2=16,fill="000000"})
gpu({command="drawrect",buffer=5,x1=1,y1=2,x2=8,y2=8,fill="000000"})
gpu({command="drawrect",buffer=5,x1=10,y1=2,x2=17,y2=8,fill="555555"})
gpu({command="drawrect",buffer=5,x1=19,y1=2,x2=26,y2=8,fill="aaaaaa"})
gpu({command="drawrect",buffer=5,x1=28,y1=2,x2=35,y2=8,fill="ffffff"})
gpu({command="drawrect",buffer=5,x1=37,y1=2,x2=44,y2=8,fill="ff0000"})
gpu({command="drawrect",buffer=5,x1=46,y1=2,x2=53,y2=8,fill="00ff00"})
gpu({command="drawrect",buffer=5,x1=55,y1=2,x2=64,y2=8,fill="0000ff"})
gpu({command="drawrect",buffer=5,x1=1,y1=10,x2=8,y2=16,fill="ffff00"})
gpu({command="drawrect",buffer=5,x1=10,y1=10,x2=17,y2=16,fill="ff00ff"})
gpu({command="drawrect",buffer=5,x1=19,y1=10,x2=26,y2=16,fill="00ffff"})
gpu({command="drawrect",buffer=5,x1=28,y1=10,x2=35,y2=16,fill="aa5500"})
gpu({command="drawrect",buffer=5,x1=37,y1=10,x2=44,y2=16,fill="ff5555"})
gpu({command="drawrect",buffer=5,x1=46,y1=10,x2=53,y2=16,fill="55ff55"})
gpu({command="drawrect",buffer=5,x1=55,y1=10,x2=64,y2=16,fill="5555ff"})
send(5,"palette",4,1)
interrupt(2,"init5")
elseif event.iid == "init5" then
gpu({command="drawrect",buffer=3,x1=16,y1=1,x2=16,y2=64,fill="000000"})
send(3,"toolbar",1,4)
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
send(2,"menu",4,1)
gpu({command="createbuffer",buffer=7,xsize=16,ysize=16,fill="555555"})
gpu({command="drawrect",buffer=7,x1=1,y1=16,x2=16,y2=16,fill="000000"})
send(7,"unused",1,1)
interrupt(2,"init6")
elseif event.iid == "init6" then
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
send(2,"menu",4,1)
interrupt(2,"init7")
elseif event.iid == "init7" then
updatetoolbar()
interrupt(2,"init8")
elseif event.iid == "init8" then
send(0,"canvas",4,4)
mem.state = "ready"
elseif mem.state == "ready" and type(event.msg) == "table" and event.msg.x then
local section = string.sub(event.channel,1,-3)
local xpanel = string.sub(event.channel,-2,-2)
local ypanel = string.sub(event.channel,-1,-1)
local x = (xpanel-1)*16+event.msg.x
local y = (ypanel-1)*16+event.msg.y
if section == "swatch" then
local oldbg = mem.bgcolor
mem.bgcolor = mem.fgcolor
mem.fgcolor = oldbg
updateswatch()
elseif section == "palette" then
local colortouched = math.floor(x/9)+1
if y>9 then colortouched = colortouched+7 end
local colors = {
"000000",
"555555",
"aaaaaa",
"ffffff",
"ff0000",
"00ff00",
"0000ff",
"ffff00",
"ff00ff",
"00ffff",
"aa5500",
"ff5555",
"55ff55",
"5555ff",
}
mem.fgcolor = colors[colortouched]
updateswatch()
elseif section == "toolbar" then
if x<9 then
if y<9 then
mem.tool = "pencil"
elseif y<17 then
mem.tool = "spraycan"
elseif y<25 then
mem.tool = "line"
mem.toolstate = "point1"
elseif y<33 then
mem.tool = "colorpicker"
end
else
if y<9 then
mem.tool = "eraser"
elseif y<17 then
mem.tool = "brush"
elseif y<25 then
mem.tool = "rectangle"
mem.toolstate = "point1"
end
end
updatetoolbar()
send(0,"canvas",4,4)
elseif section == "canvas" then
if mem.tool == "pencil" then
gpu({command="drawpoint",buffer=0,x=x,y=y,color=mem.fgcolor})
send(0,"canvas",4,4)
elseif mem.tool == "eraser" then
gpu({command="drawpoint",buffer=0,x=x,y=y,color=mem.bgcolor})
send(0,"canvas",4,4)
elseif mem.tool == "brush" then
gpu({command="drawpoint",buffer=0,x=x,y=y,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x+1,y=y,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x-1,y=y,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x,y=y+1,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x+1,y=y+1,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x-1,y=y+1,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x,y=y-1,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x+1,y=y-1,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x-1,y=y-1,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x+2,y=y,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x-2,y=y,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x,y=y+2,color=mem.fgcolor})
gpu({command="drawpoint",buffer=0,x=x,y=y-2,color=mem.fgcolor})
send(0,"canvas",4,4)
elseif mem.tool == "spraycan" then
for i=1,10,1 do
gpu({command="drawpoint",buffer=0,x=x+math.random(-4,4),y=y+math.random(-4,4),color=mem.fgcolor})
end
for i=1,5,1 do
gpu({command="drawpoint",buffer=0,x=x+math.random(-2,2),y=y+math.random(-2,2),color=mem.fgcolor})
end
send(0,"canvas",4,4)
elseif mem.tool == "line" then
if mem.toolstate == "point1" then
gpu({command="createbuffer",buffer=7,xsize=64,ysize=64})
gpu({command="copy",src=0,dst=7,srcx=1,srcy=1,dstx=1,dsty=1,xsize=64,ysize=64,mode="normal",})
gpu({command="createbuffer",buffer=6,xsize=1,ysize=1,fill="ffffff"})
gpu({command="copy",src=6,dst=7,srcx=1,srcy=1,dstx=x,dsty=y,xsize=1,ysize=1,mode="xor",})
send(7,"canvas",4,4)
mem.point1x = x
mem.point1y = y
mem.toolstate = "point2"
elseif mem.toolstate == "point2" then
gpu({command="drawline",buffer=0,x1=mem.point1x,x2=x,y1=mem.point1y,y2=y,color=mem.fgcolor,antialias=true})
send(0,"canvas",4,4)
mem.toolstate = "point1"
end
elseif mem.tool == "rectangle" then
if mem.toolstate == "point1" then
gpu({command="createbuffer",buffer=7,xsize=64,ysize=64})
gpu({command="copy",src=0,dst=7,srcx=1,srcy=1,dstx=1,dsty=1,xsize=64,ysize=64,mode="normal",})
gpu({command="createbuffer",buffer=6,xsize=1,ysize=1,fill="ffffff"})
gpu({command="copy",src=6,dst=7,srcx=1,srcy=1,dstx=x,dsty=y,xsize=1,ysize=1,mode="xor",})
send(7,"canvas",4,4)
mem.point1x = x
mem.point1y = y
mem.toolstate = "point2"
elseif mem.toolstate == "point2" then
gpu({command="drawrect",buffer=0,x1=math.min(mem.point1x,x),x2=math.max(mem.point1x,x),y1=math.min(mem.point1y,y),y2=math.max(mem.point1y,y),fill=mem.fgcolor})
send(0,"canvas",4,4)
mem.toolstate = "point1"
end
elseif mem.tool == "colorpicker" then
gpu({command="sendregion",x1=x,x2=x,y1=y,y2=y,buffer=0,channel="gpuback"})
mem.gpubackwait = "colorpicker"
end
elseif section == "menu" then
if x<25 then
mem.state = "filemenu"
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="createbuffer",buffer=2,xsize=64,ysize=15,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,text="Back",color="aaaaaa"})
gpu({command="drawrect",buffer=2,x1=26,y1=1,x2=26,y2=16,fill="000000"})
gpu({command="text",buffer=1,x=2,y=2,text="New",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=18,text="Load",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=34,text="Save",color="aaaaaa"})
gpu({command="drawrect",buffer=1,x1=1,y1=16,x2=64,y2=16,fill="000000"})
gpu({command="drawrect",buffer=1,x1=1,y1=32,x2=64,y2=32,fill="000000"})
gpu({command="drawrect",buffer=1,x1=1,y1=48,x2=64,y2=48,fill="000000"})
send(2,"menu",4,1)
send(1,"canvas",4,4)
elseif x<57 then
mem.state = "about"
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="createbuffer",buffer=2,xsize=64,ysize=15,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,text="Back",color="aaaaaa"})
gpu({command="drawrect",buffer=2,x1=26,y1=1,x2=26,y2=16,fill="000000"})
send(2,"menu",4,1)
gpu({command="text",buffer=1,x=2,y=2,text="MT Paint",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=22,text="By",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=32,text="cheapie",color="aaaaaa"})
send(1,"canvas",4,4)
end
end
elseif mem.state == "filemenu" and type(event.msg) == "table" and event.msg.x then
local section = string.sub(event.channel,1,-3)
local xpanel = string.sub(event.channel,-2,-2)
local ypanel = string.sub(event.channel,-1,-1)
local x = (xpanel-1)*16+event.msg.x
local y = (ypanel-1)*16+event.msg.y
digiline_send("debug",string.format("%d,%d @ %d,%d\n%d,%d",xpanel,ypanel,event.msg.x,event.msg.y,x,y))
if section == "menu" and x<26 then
mem.state = "ready"
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
send(2,"menu",4,1)
send(0,"canvas",4,4)
elseif section == "canvas" then
if y < 16 then
mem.state = "ready"
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
send(2,"menu",4,1)
gpu({command="createbuffer",buffer=0,xsize=64,ysize=64,fill="ffffff"})
send(0,"canvas",4,4)
elseif y < 32 then
mem.state = "reading"
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="text",buffer=1,x=2,y=2,text="Please",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=12,text="Wait...",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=25,text="Reading",color="aaaaaa"})
send(1,"canvas",4,4)
mem.loadsector = 0
mem.loaddata = ""
interrupt(1,"load-read")
elseif y < 48 then
mem.state = "save-fetching"
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="text",buffer=1,x=2,y=2,text="Please",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=12,text="Wait...",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=25,text="Fetching",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=35,text="image",color="aaaaaa"})
mem.gpubackwait = "save"
gpu({command="sendpacked",buffer=0,channel="gpuback"})
send(1,"canvas",4,4)
end
end
elseif mem.state == "about" and type(event.msg) == "table" and event.msg.x then
local section = string.sub(event.channel,1,-3)
local xpanel = string.sub(event.channel,-2,-2)
local ypanel = string.sub(event.channel,-1,-1)
local x = (xpanel-1)*16+event.msg.x
local y = (ypanel-1)*16+event.msg.y
if section == "menu" and x<26 then
mem.state = "ready"
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
send(2,"menu",4,1)
send(0,"canvas",4,4)
end
elseif event.channel == "gpuback" then
if mem.gpubackwait == "colorpicker" then
mem.fgcolor = event.msg[1][1]
updateswatch()
elseif mem.gpubackwait == "save" and mem.state == "save-fetching" then
mem.savedata = event.msg
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="text",buffer=1,x=2,y=2,text="Please",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=12,text="Wait...",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=25,text="Writing",color="aaaaaa"})
send(1,"canvas",4,4)
mem.state = "save-writing"
mem.savesector = 0
interrupt(1,"save-write")
end
mem.gpubackwait = nil
elseif event.iid == "save-write" then
if mem.savesector <= 31 then
local savedata = string.sub(mem.savedata,mem.savesector*512,(mem.savesector*512)+511)
digiline_send("eeprom",{command="write",address=mem.savesector,data=savedata})
mem.savesector = mem.savesector + 1
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="text",buffer=1,x=2,y=2,text="Please",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=12,text="Wait...",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=25,text="Writing",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=35,text=string.format("%d/16 KiB",math.floor(mem.savesector/2)),color="aaaaaa"})
send(1,"canvas",4,4)
interrupt(1,"save-write")
else
mem.state = "ready"
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
send(2,"menu",4,1)
send(0,"canvas",4,4)
end
elseif event.iid == "load-read" then
if mem.loadsector <= 31 then
digiline_send("eeprom",{command="read",address=mem.loadsector})
interrupt(5,"loadtimeout")
else
mem.state = "ready"
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
gpu({command="createbuffer",buffer=0,xsize=64,ysize=64,fill="ffffff"})
gpu({command="loadpacked",buffer=0,x=1,y=1,xsize=64,ysize=64,data=mem.loaddata})
send(2,"menu",4,1)
send(0,"canvas",4,4)
end
elseif event.iid == "loadtimeout" and mem.state == "reading" then
mem.state = "ready"
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
gpu({command="createbuffer",buffer=0,xsize=64,ysize=64,fill="ffffff"})
gpu({command="loadpacked",buffer=0,x=1,y=1,xsize=64,ysize=64,data=mem.loaddata})
send(2,"menu",4,1)
send(0,"canvas",4,4)
elseif event.channel == "eeprom" and mem.state == "reading" then
mem.loaddata = mem.loaddata..event.msg
mem.loadsector = mem.loadsector + 1
gpu({command="createbuffer",buffer=1,xsize=64,ysize=64,fill="555555"})
gpu({command="text",buffer=1,x=2,y=2,text="Please",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=12,text="Wait...",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=25,text="Reading",color="aaaaaa"})
gpu({command="text",buffer=1,x=2,y=35,text=string.format("%d/16 KiB",math.floor(mem.loadsector/2)),color="aaaaaa"})
send(1,"canvas",4,4)
interrupt(1,"load-read")
elseif event.channel == "keyboard" and mem.state == "ready" then
gpu({command="createbuffer",buffer=2,xsize=64,ysize=16,fill="555555"})
gpu({command="text",buffer=2,x=2,y=2,color="aaaaaa",text="File"})
gpu({command="drawrect",buffer=2,x1=25,y1=1,x2=25,y2=16,fill="000000"})
gpu({command="text",buffer=2,x=27,y=2,color="aaaaaa",text="About"})
gpu({command="drawrect",buffer=2,x1=57,y1=1,x2=57,y2=16,fill="000000"})
gpu({command="drawrect",buffer=2,x1=1,y1=16,x2=64,y2=16,fill="000000"})
gpu({command="createbuffer",buffer=0,xsize=64,ysize=64,fill="ffffff"})
gpu({command="loadpacked",buffer=0,x=1,y=1,xsize=64,ysize=64,data=event.msg})
send(2,"menu",4,1)
send(0,"canvas",4,4)
end
if #commands > 0 then digiline_send("gpu",commands) end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment