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 : LIB - ASCII Graphics - A Start
Author | Message | ||||
Chris Roper Senior Member Joined: 19/05/2015 Location: South AfricaPosts: 280 |
Much attention has been given to having the Micromite drive various display types and the stunning Graphics that Matherp is developing show just how powerful it can get. But the simple Console is being neglected, so I decided to have a go at remedying that omission. Geoff's inbuilt Full Screen Editor is an example of what can be achieved on a VT100 Terminal. Many applications may only need a simple terminal based user interface and, whilst we can't do any high resolution Graphics on it,with a combination of ASCII Graphics Characters and the VT100 escape codes, a respectable Console Screen for Display and Input can be created. So far I have only just scratched the Surface but in the process I have created a few new commands and put together a small demo to test them: First the Use Notes: ' LIB - ASCII Graphics ' ' LOCATE [row, col, FG, BG] ' Positions Cursor at Row & Column and optionally sets the Foreground and Background Colours ' row defaults to 1 ' col defaults to 1 ' row must be specified for any other options to be specified ' See the CONSTANTS in the program for a list of Colours ' CLS ' Clears the Screen and positions Cursor at row 1, col 1 ' BLANK [line] 'Clears the 'line' - Default is the top line ' RESET ' Resets The VT100 Terminal ' PSTRING( nbr, ascii ) ' Prints a string 'nbr' bytes long consisting of the character representing the ASCII value 'ascii' ' Similar to STRING$ but accepts all ASCII values 0 through 255 ' GSTRING$( nbr, ascii ) ' Returns a string 'nbr' bytes long consisting of the character representing the ASCII value 'ascii' ' Similar to STRING$ but accepts all ASCII values 0 through 255 ' HLINE row, col, len[, fill, fst, lst] ' Draws a line starting at Row, Col, Right 'len' Columns ' fill is the character to use, default is CHR$(196) HS - Horizontal Single Line ' fst is an optional start character default is fill ' lst is an optional end character default is fill ' VLINE row, col, len[, fill, fst, lst] ' Draws a line starting at Row, Col, Down 'len' Rows ' fill is the character to use, default is CHR$(179) VS - Vertical Single Line ' fst is an optional start character default is fill ' lst is an optional end character default is fill ' BOX row, col, width, hight[, fill, style] ' Draws a Box starting at row, col of width and hight ' filled with the 'fill' character - Default fill is " " - SPACE ' style ' 0 - No Border (Default) ' 1 - Single Line ' 2 - Double Line ' FOREGROUND colour ' Self explanatory ' ' See the CONSTANTS in the program for a list of Colours ' BACKGROUND colour ' as above and the very early stages of a ASCII Graphics Library with a DEMO Program to give an idea of its capability's even in this early form. ' LIB - ASCII Graphics Const ESC = Chr$(27) Const BLACK=1,RED=2,GREEN=3,YELLOW=4,BLUE=5,MAGENTA=6,CYAN=7,WHITE=8 Const HS=196,VS=179,TLSS=218,TRSS=191,BLSS=192,BRSS=217,LSS=195,RSS=180 Const HD=205,VD=186,TLDD=201,TRDD=187,BLDD=200,BRDD=188,LDD=204,RDD=185 Const LSD=198,RSD=182,LDS=199,RDS=181 Const TSS=194,BSS=193,TDD=203,BDD=202 Const TSD=210,BSD=208,TDS=209,BDS=207 Const FG_RED=ESC+"[32m" Sub LOCATE(row,col,FG,BG) If FG > 0 Then FOREGROUND FG If FG > 0 Then BACKGROUND BG Print ESC+"[";Str$(row);";";Str$(col);"H"; End Sub Sub CLS ' Clear Screen Print ESC+"[2J"; LOCATE End Sub Sub BLANK (row) ' Clear a Line LOCATE row Print ESC+"[2K"; End Sub Sub RESET Print ESC+"c"; End Sub Sub PSTRING(nbr, ascii) Do nbr = nbr - 1 Print Chr$(ascii); Loop Until nbr <= 0 End Sub Function GSTRING$(nbr, ascii) Do nbr = nbr - 1 GSTRING$ = GSTRING$ + Chr$(ascii) Loop Until nbr <= 0 End Function Sub HLINE(row,col,len,fill,fst,lst) LOCATE row,col If fill= 0 Then fill= HS If fst = 0 Then fst = fill If lst = 0 Then lst = fill Print Chr$(fst); If len > 2 Then PSTRING len-2, fill If len > 1 Then Print Chr$(0);Chr$(lst); End Sub Sub VLINE(row,col,len,type,fst,lst) If type= 0 Then type = VS If fst = 0 Then fst = type If lst = 0 Then lst = type LOCATE row,col Print Chr$(fst); If len > 2 Then For x = row + 1 To len - 1 LOCATE x, col Print Chr$(type); Next LOCATE len,col If len > 1 Then Print Chr$(0);Chr$(lst); End Sub Sub BOX(row,col,width,hight,fill,style) If fill = 0 Then fill = 32 Select Case style Case 1 hl = HS tl = TLSS tr = TRSS vl = VS bl = BLSS br = BRSS Case 2 hl = HD tl = TLDD tr = TRDD vl = VD bl = BLDD br = BRDD Case Else hl = fill tl = fill tr = fill vl = fill bl = fill br = fill row = row + 1 col = col + 1 width = width - 2 hight = hight - 1 End Select HLINE row, col, width, hl, tl, tr For x = row + 1 To hight - 1 HLINE x, col, width, fill, vl, vl Next HLINE hight, col, width, hl, bl, br End Sub Sub GSET row, col, ascii LOCATE row, col Print Chr$(ascii); End Sub Sub FOREGROUND (colour) Print Chr$(27)+"[3"+Str$(colour - 1)+"m" End Sub Sub BACKGROUND (colour) Print Chr$(27)+"[4"+Str$(colour - 1)+"m" End Sub ' LIBRARY ENDS '------------------------------- ' PROGRAM STARTS CLS Input "After each step press enter to continue",a$ BLANK Input "Draw a box from 4,2, 25 col wide 15 rows high with a 1 line border",a$ BOX 4,2,25,15,,1 BLANK Input "Next we use LOCATE to add a heading",a$ LOCATE 5,10 : Print "Test Box 1"; BLANK Input "Segment the box with a Double Line Below the Heading",a$ HLINE 6,2,25,HD,LSD,RDS BLANK Input "Now Divide the new box Verticaly with a Single Line",a$ VLINE 6,6,15,VS,TDS,BSS BLANK Input "Maybe the Heading would be better in Red?",a$ LOCATE 5,10,RED : Print "Test Box 1"; FOREGROUND WHITE BLANK Input "Or Green",a$ LOCATE 5,10,GREEN : Print "Test Box 1"; FOREGROUND WHITE BLANK Input "and now just for fun lets fill this new box", a$ BOX 6,6,21,15,176 BLANK Input "lets change the fill", a$ BOX 6,6,21,15,178 BLANK Input "It was beter empty", a$ BOX 6,6,21,15 BLANK Input "But the Sidebar could be Yellow", a$ BACKGROUND YELLOW BOX 6,2,5,15 BACKGROUND BLACK BLANK Input "That's all Folks - Read the Program for details ..............",a$ 'Move to the second last row Locate 23 End I have only tested it on TerraTerm so far and would appreciate any feedback from testing on other hardware. Next step is to add some standard widgets and try to refine the code a bit more. Cheers for now, Chris http://caroper.blogspot.com/ |
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1097 |
Hi Chris, Very impressive. Works fine on a 28 pin 170 running 4.6b to Putty on a Linux box. Fails on a 44 pin 170 running 4.7b8 with the error "Error: Display not configured" CLS Sub LOCATE(row,col,FG,BG) If FG > 0 Then FOREGROUND FG If FG > 0 Then BACKGROUND BG Print ESC+"[";Str$(row);";";Str$(col);"H"; End Sub Sub CLS ' Clear Screen Print ESC+"[2J"; LOCATE End Sub If I simulate the two print statements at the command prompt substituting real values, they work OK. Geoff, this might be one for you? Cheers, Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
Probably because of the CLS statement as in 4.7b8 this is part of an lcd display command.... I'm guessing??? |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5913 |
That is correct. To help reduce the chance of conflicts, I would prefix all the functions with 'VT_' or similar. RESET is a good function name to avoid! A useful set of functions. Jim VK7JH MMedit MMBasic Help |
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1097 |
@TassieJim and viscomjim, My apologies lads, should have seen that myself @Chris I put VT. in front of all commands and subs etc and it all works fine under 4.7b8 I agree with TassieJim, the VT. in front takes away any chance of competing with existing commands now or the future. Cheers, Doug PS. @Geoff, hope you didn't waste any time on this , sorry. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Chris Roper Senior Member Joined: 19/05/2015 Location: South AfricaPosts: 280 |
Thanks Guys, Very useful feedback. I was rather surprised that it allowed me to create the CLS and Reset commands. I assumed MMBasic would throw an ERROR if they were reserved words. Initially I was trying to use the GW-BASIC Graphics command set hence the choose of Key Words, but I have deviated so far from that now I may as well rename the commands too. I also need to look at the fact that it is console specific, it would be better if it could run over any available com: port, and preferably more than one at a time, so I will include some form of Set-up command for Screen Resolution, port etc. Cheers Chris http://caroper.blogspot.com/ |
||||
Print this page |