  ttl buffered terminal output
  bin

  dc.w $feeb

beg ds.l 1
get ds.l 1
put ds.l 1
lim ds.l 1
kbh ds.l 1

freebot equ $3ff0
vep     equ $3720
ion equ $B1
iof equ $91
ttys equ $4000c1
ttyd equ $4000c3

interrupt move.l kbh,-(sp)
   btst.b #1,ttys
   beq.s intdone
   movem.l a0-a1,-(sp)
   lea get,a1
   move.l get,a0
   cmp.l put,a0
   beq.s disint
   move.b (a0)+,ttyd
   cmp.l lim,a0
   bne.s int1
   move.l beg,a0
int1 move.l a0,(a1)
   bra.s int9
disint move.b #iof,ttys
int9 movem.l (sp)+,a0-a1
intdone rts

putsym lea put,a1
   move.l put,a0
   move.b d0,(a0)+    insert character
   cmp.l lim,a0
   bne.s ps1
   move.l beg,a0      wrap round
ps1 cmp.l get,a0
   beq ps1            wait if full
   move.l a0,(a1)     update put pointer
   move.b #ion,ttys
   rts

printsymbol  bsr putsym
   cmp.b #10,d0
   bne.s ps9
   move.b #13,d0
   bsr putsym
ps9 movem.l (sp)+,d0-d2/a0-a2
   rts

begin lea beg-2,a0
   cmp.l freebot,a0
   beq.s ok1
   move.l a0,1       *fail*
ok1 lea eof,a1
   lea beg,a0
   move.l a1,(a0)    set beg
   lea 256(a1),a1
   lea lim,a0
   move.l a1,(a0)    set lim
   lea 4(a1),a1
   move.l a1,freebot lock down
   lea put,a0
   move.l beg,(a0)   set put
   lea get,a0
   move.l beg,(a0)   set get
   lea kbh,a0
   move.l $1074,(a0) set kbh
   lea interrupt,a0
   move.l a0,$1074   replace kbh
   lea printsymbol,a0
   move.l a0,vep     replace printsymbol
   lea terminal,a0
   moveq #0,d0
   jsr $10f4         openoutput to terminal
   rts

terminal dc.b 1,':'
   ds.l 0
   bra.w begin
eof equ *
   end
