Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : VT100 library for the Micromite console
Author | Message | ||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5705 |
If anyone is interested, I put this together a while back and it's rather nice to have a bit of colour and Print@ to console displays. It's at it's most useful when loaded as a "fit & forget" library when it can, of course, run on a "headless" Micromite chip. 'These are MMBasic library routines for TeraTerm VT100 terminal video. 'Comments are NOT recoverable from the Micromite as they are stripped out on 'inclusion into the library. It is worth keeping a copy of this file. :) ' Vhelp show help info ' Vcls clear screen ' Vch cursor home to top left ' Vcdn n move cursor down n lines ' Vcr n move cursor rignt n characters ' Vcl n move cursor left n characters ' Vcup n move cursor up n lines ' Vat row col move cursor to row,column ' Vsc save current cursor position ' Vrc restore cursor position saved by Vsc ' Vbox y,x,w,h,t draw a box ' Vl y,x,l,t draw a vertical or horixontal line to divide a box ' Vatt n$ set text attributes to n$ (none,bold,inverse,underlined) ' Vfc n$ set text/foreground colour by name or str$(number) 0-15 ' Vbc n$ set background colour by name or str$(number) 0-16 (16 is light grey) ' ch print Chr$(27)+"[" (the Escape sequence) - used internally Sub Vcls 'clear the screen ch Print "2J"; End Sub Sub Vch 'cursor home to top left corner ch Print "H"; End Sub Sub Vcdn(n) 'move cursor down n lines Local vz$ vz$=Str$(n)+";B" ch Print vz$; End Sub Sub Vcup(n) 'move cursor up n lines Local vz$ vz$=Str$(n)+";A" ch Print vz$; End Sub Sub Vcr(n) 'move cursor right n characters Local vz$ vz$=Str$(n)+";C" ch Print vz$; End Sub Sub Vcl(n) 'move cursor left n characters Local vz$ vz$=Str$(n)+";D" ch Print vz$; End Sub Sub Vat(row,col) 'locate cursor to row,col Local vz$ vz$=Str$(row)+";"+Str$(col)+"H" ch Print vz$; End Sub Sub Vsc 'save current cursor position ch Print "7"; End Sub Sub Vrc 'restore cursor position saved with Vsc ch Print "8"; End Sub Sub Vbox(row,col,w,h,t) 'daw a box in "Terminal" font box chars Vat row,col If t=0 Then Print Chr$(218);String$(w-2,196);Chr$(191); Vat row+h,col Print Chr$(192);String$(w-2,196);Chr$(217); For i=1 To h-1 Vat row+i,col:Print Chr$(179); Vat row+i,col+w-1:Print Chr$(179); Next Else Print Chr$(201);String$(w-2,205);Chr$(187); Vat row+h,col Print Chr$(200);String$(w-2,205);Chr$(188); For i=1 To h-1 Vat row+i,col:Print Chr$(186); Vat row+i,col+w-1:Print Chr$(186); Next End If End Sub Sub Vl(row,col,l,t) 'draw a vertical or horizontal line to divide a box Local i,m m=t:t=Abs(t) If m>0 Then 'vertical line vat row,col: If t=0 Then Print Chr$(194); Else Print Chr$(203); vat row+l,col: If t=0 Then Print Chr$(193); Else Print Chr$(202); vat row+1,col For i=1 To l-1 vat row+i,col If t=0 Then Print Chr$(179); Else Print Chr$(186); Next Else 'horizontal line vat row,col If t=0 Then Print Chr$(195)String$(w-2,196)Chr$(180) Else Print Chr$(204)String$(w-2,205)Chr$(185) End If End If End Sub Sub Vatt(tatt$) 'set text attributes ch Select Case LCase$(tatt$) Case "none" Print "0m"; Case "b" Print "1m"; Case "/b" Print "22m"; Case "in" Print "7m"; Case "/in" Print "27m"; Case "u" Print "4m"; Case "/u" Print "24m"; End Select End Sub Sub Vfc(color$) 'set text foreground colour Local vz$ 'if we have a colour number 0-15 then use it If Len(color$)<3 And Val(color$)<16 Then vz$="38;5;"+color$+"m" ch Print vz$ Else ch Select Case LCase$(color$) 'otherwise use the colour name Case "black" Print "30m"; Case "red" Print "31m"; Case "green" Print "32m"; Case "yellow" Print "33m"; Case "blue" Print "34m"; Case "magenta" Print "35m"; Case "cyan" Print "36m"; Case "white" Print "37m"; Case "grey","gray" Print "90m"; End Select End If End Sub Sub Vbc(color$) 'set text background colour Local vz$ 'if we have a colour number 0-15 then use it If Len(color$)<3 And Val(color$)<16 Then vz$="48;5;"+color$+"m" ch Print vz$ Else If Val(color$)=16 Then vz$="48:2:115:115:115m" ch Print vz$ Else ch Select Case LCase$(color$) 'otherwise use the colour name Case "black" Print "40m"; Case "red" Print "41m"; Case "green" Print "42m"; Case "yellow" Print "43m"; Case "blue" Print "44m"; Case "magenta" Print "45m"; Case "cyan" Print "46m"; Case "white" Print "47m"; Case "grey","gray" Print "100m"; Case Else Print "39m"; 'default background End Select End If End Sub Sub Vhelp Print " The V VT100 library" Print "Vcls clear screen" Print "Vch cursor home to top left" Print "Vcdn n move cursor down n lines" Print "Vcup n move cursor up n lines" Print "Vcr n move cursor rignt n characters" Print "Vcl n move cursor left n characters" Print "Vat row col move cursor to row,column" Print "Vsc save current cursor position" Print "Vrc restore cursor position saved by Vsc" Print "Vbox x,y,w,h,t draw a box width w height h at x,y using 'Terminal' font box characters." Print " t=0 for single line, 1 for double" Print "Vl y,x,l,t draw a horizotal or vertical line to divide a box." Print " l is length, t=0 for single line, 1 for double, negative for horizontal" Print "Vatt n$ set text attributes to n$ - none b /b in /in low u /u" Print " (none,bold,inverse,low_intensity,underlined)" Print "Vfc n$ set text/foreground colour by name or str$(number) 0-15" Print "Vbc n$ set background colour by name or str$(number) 0-16 (16 is light grey)" Print " Colours names are black, red, green, yellow, blue, magenta, cyan, white, grey" Print "ch print the Escape sequence 'Chr$27 [' - used internally" End Sub Sub ch Print Chr$(27);"["; End Sub Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Cyber Senior Member Joined: 13/01/2019 Location: UkrainePosts: 161 |
Nice! Thank you! I thought of making similar thiggy, but did not get my hands to it. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5705 |
You're welcome. It was fun to write and I just hope it's useful to someone. :) There's a couple of "yeah-but"s in it. It doesn't automatically insert crossing characters when lines cross in a box. That's left as mental exercise for the programmer. :) There seems to be something a bit odd about text attributes IIRC (I've not used them much). It might be the way that Tera Term uses them as I think I have all the codes correct. Error checking is erm... lax, but that saves space in the library. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
electricat Regular Member Joined: 30/11/2020 Location: LithuaniaPosts: 74 |
This is exactly I was thinking on yesterday and wrote few lines I needed, but you implemented so much more already, boxes colors... nice :D So yes, it is useful :) Thank you. |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3008 |
Did you happen to write a test program for this? I'm looking to write a simplified VT100 terminal emulator for the F4 (for use as a debugging terminal for the CMM2) and would be happy to try testing it with someone else's code outputting VT100 sequences. That program and your library might do will paired on either end of a set of micromites. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5705 |
Sorry, no. I wrote it in bits as I needed them and did a bit of testing at each stage. I've not done anything specific. Sloppy, I know, but it was only for me at the time. :) All the testing I did was Micromite to Tera Term. Edited 2021-05-10 16:38 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
electricat Regular Member Joined: 30/11/2020 Location: LithuaniaPosts: 74 |
Hi, Mixtel90 and all I wrote simple, universal i2C scanner. (PICOMITE MMBasic Ver 5.07.00) All works ok, text formatting, terminal clear, returning cursor to home pos etc. The problem I have - I am hiding cursor by sending [?25l It works as expected. But if for example one would brake program via ctrl+C, after returning to terminal, cursor is still hidden :D and if I would EDIT program, there is no cursor of course. I see in status line indications it is moving, but there is no cursor. I can return it by pressing in terminal window setup>OK but it is still somehow going roundabouts. Do you have any ideas, how to deal on this, as if I would send [?25h e.i show cursor it still might happen not executed before ctrl+c and on returning to editor cursor would be hidden :D How we could return cursor after program was interrupted? It seems to me as it would be firmware business already. But Im not too experenced in working with terminals so I might overlooked something:) |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3831 |
Courtesy of @matherp, but any bugs are probably my fault: ' Change the break key. Option Break 4 ' On CTRL-C call my_exit(). On Key 3, my_exit() Sub my_exit() ' Show cursor and clear console attributes. Print Chr$(27) "[?25h" Chr$(27) "[0m" ' Restore CTRL-C as the break key. Option Break 3 ' End the program. End End Sub Best wishes, Tom Edited 2021-11-22 21:21 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5705 |
The best way isn't to use Ctrl-C to break the program! Change it to something else and include some sort of command to leave the program, doing all the necessary tidying up (setting sensible colours, switching the cursor on etc) before an END statement. EDIT: Beaten to it by Tom... :( Edited 2021-11-22 21:26 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
electricat Regular Member Joined: 30/11/2020 Location: LithuaniaPosts: 74 |
thwill YES!! Elegant solve! Don`t be upset Mixtel90 :) I will include nice message for user "Press Ctrl+C to exit" ;) |
||||
Print this page |