Skip to content

Instantly share code, notes, and snippets.

@XeonSquared
Last active November 7, 2015 10:53
A simple networked dumb terminal for OpenComputers

Simple Dumb Terminal

This is a simple dumb terminal for placing onto an EEPROM. It requires about 2k of RAM, a display, and a network card, preferably pre-configured.

Protocol

The protocol is simple (and will be expanded later to support multiple clients on the same address (switching sessions, anyone?).

When the terminal boots, it reads an address from the EEPROM's data section, which is the sever it wants to connect to. It sends to that server "dtpconnect" on port 23, and will assume all other communications occur on port 23. This will probably be configurable in the future.

Following that, any strings it receives from that address will be printed to the screen and any keys pressed will be sent to the address as raw keycodes. The only mangling done is changing the carriage returns from pressing enter to newlines because carriage returns are more-or-less useless.

That's basically the whole protocol.

Control codes supported:

  • \n (newline, goes to x=1,y=y+1)
  • \r (carriage return, returns to start of line)
  • \a (bell)
  • backspace (0x08)
  • \f (form feed, clears the screen)
function p(t)
return component.proxy(component.list(t)())
end
n,v,s,e,x,y,po=p("modem"),p("gpu"),p("screen"),p("eeprom"),1,1,23
v.bind(s.address)
w,h=v.getResolution()
function v.sfb(f,b)
v.setForeground(f)
v.setBackground(b)
end
function cs()
if x>w then x,y=1,y+1 end
if x<1 then x=1 end
if y>=h then v.copy(1,2,w,h-1,0,-1) v.fill(1,h,w,1," ") y=h end
end
v.setResolution(w,h)
v.fill(1,1,w,h," ")
a=e.getData()
n.open(23)
n.send(a,23,"dtpconnect")
function beep()
computer.beep()
end
while true do
t,_,r,p,_,m = computer.pullSignal()
if t=="modem_message" and r==a then
for i=1,#m do
c=m:sub(i,i)
if c == "\n" then
x,y=1,y+1
cs()
elseif c=="\r" then
x=1
elseif c=="\f" then
x,y=1,1
v.fill(1,1,w,h," ")
elseif c=="\a" then beep()
elseif c==string.char(8) then
x=x-1
v.set(x,y," ")
cs()
else
v.set(x,y,c)
x=x+1
cs()
end
end
elseif t=="key_down" then
if r~=13 then
n.send(a,23,r)
else
n.send(a,23,10)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment