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 : Keeping the cursor flashing
Author | Message | ||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
Today's inane question: In my program, when a user is building up an entry screen I want the > cursor to keep flashing at the entry point (although that part of the program is in a loop). The loop has the effect of silencing the cursor. I'd like to overcome that in the entry routine. Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
I should add that I can emulate the cursor at the insertion point with CHRS(62) alternating with CHR$(32) but if there's an easier way I'd like to avoid that Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5886 |
The cursor is the underline, not the ">" which is the prompt and never flashes. If you are happy with the underline flashing and are able to use INPUT to retrieve your responses, this will do the job: Note the comma after the prompt string to suppress the question mark. Jim VK7JH MMedit  MMBasic Help |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
Thanks Jim You must be on permanent duty! My program has a much more complicated operation. I set up an input box of a fixed length using String$(x,46) and finishing with CHR$(222). In do loop I use inkey$ to pick up individual characters and build the string and also allow for prevention of overflow as well as intercepting backspace and signalling end of input string using Chr$(13). I'm working on the optimum pause settings to prevent 'keybounce'. I now alternate the 'next' chr$(46) with Chr$(32) to give a flashing cursor at the next character entry point. I'm 'porting' the functions in a large business system I wrote years ago and used for years under DOS (remember that?) and QuickBasic. So my problem is sometimes subtle differences in the operation of CMM2 commands as well as not so subtle aging. Maybe I'll post my code when tidied up to just to give you experts some mirth in this serious world and tempt posters to tear it apart! Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3010 |
If you are doing text boxes and other DOS windows-type things, I'd certainly like to see that code tidy or not. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
You asked for it! Here's my old QuickBasic standard subroutine for string input, with allowance for ENTER (end of string) and Backspace. This is old code and not what I'm doing now as a port from it. Spaghetti I know, but a busy office ran faultlessly on it for years. 800 PLAY O2$: EN$ = "": Color 11, 0: Print "ENTER "; PR$; " ? ";: RO = CSRLIN: CO = POS(0): Print String$(LT, 46); Chr$(222);: LOCATE RO, CO 802 LOCATE , , 1: EK$ = INKEY$: If EK$ = "" Or EK$ = Chr$(9) Then GoTo 802 803 If EK$ <> Chr$(8) Then GoTo 804 Else If POS(0) < CO + 1 Then GoTo 802 Else EN$ = Left$(EN$, Len(EN$) - 1): LOCATE RO, CO: Print EN$ + "." + Chr$(29);: GoTo 802 804 If EK$ = Chr$(13) Then GoTo 805 Else Color 14, 0: Print EK$;: EN$ = EN$ + EK$: GoTo 802 805 Print: If Len(EN$) > LT Then GoSub 508: Print: GoTo 800 Else PR$ = "": EK$ = "": Return No suggestions please folks(!) New environment now. (all my current business programs have been written under Vb6) Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
flip Senior Member Joined: 18/07/2016 Location: AustraliaPosts: 114 |
I posted a simple MULTI-TASKing program (using MM for DOS) 3 years ago (how time flies) back in https://www.thebackshed.com/forum/forum_posts.asp?TID=9851&PN=49 It's just a demo and very rough and slow...you can tab between windows, type text in them and press Function keys along bottom of screen to start scroller...have since made improvements but no means ready for posting... Pressing 'Insert' key toggles between OVR and INS modes - which can be seen as different cursors (underline and block) regards Phil |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3010 |
Two-character variable names, heaven help us. (But no suggestions implied.) Thanks. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3010 |
Flip--thanks very much. DOS MMBasic is what I'm looking at for starters. If you have updates to that code, can you post them in the thread you linked, however rough? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
@Herry >> Considering that your code was written before BASIC acquired better conditional test commands and looping structures, I really like it. It's probably about as fast as it can be. The short variable names speed up BASIC's search of the table of variables and they compress the load space for the program. It's probably pretty bullet proof. It's just a little hard for humans to read. Polacks like me are not really part of the human race and it's been working for years, so I don't mind it. Paul in NY |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5886 |
This is one I prepared earlier: ' text input routines ' TassyJim November 2019 ' option console serial ' to stop messing up the display const FALSE = 0 const TRUE = not false dim n$(10) dim integer tHt = MM.INFO(FONTHEIGHT), tWth = MM.INFO(FONTWIDTH) dim float num dim integer k cls message 3, 1, "Enter your text. Blank line to end." multiline 3,3,10 for k = 1 to 10 'prints final result to console print n$(k) next k multiline 3,15,1,20 print n$(1) message 20,20, "Enter a number..." num = getNum(20,22,"42.0") print num option console both end ' creates a box for multiline text input ' Gets valid numeric input from user ' Parameters: ' x, y - top left corner measured in characters ' li - number of lines ' c - number of characters per line sub multiline(x as integer, y as integer, li as integer, c as integer) local integer k if c = 0 then c = 79 box x*tWth - 2, y*tHt - 2,(c+2)*tWth + 4, li*tHt+4,1,rgb(white) for k = 1 to li n$(k) = GetStr$(x,k+y-1,"",c) if n$(k) = "" then exit for next k box x*tWth - 2, y*tHt - 2,(c+2)*tWth + 4, li*tHt+4,1,rgb(gray) end sub ' Gets valid numeric input from user ' Parameters: ' Row, Col - location to echo input ' Initial$ - default value FUNCTION GetNum(Col as integer, Row as integer,initial$) Result$ = initial$ Done = FALSE do WHILE INKEY$ <> "": loop 'Clear keyboard buffer DO WHILE NOT Done text col*tWth,Row*tHt,Result$+CHR$(95)+ " ",lt,1,1 do Kbd$ = INKEY$ loop until Kbd$ <> "" SELECT CASE Kbd$ case chr$(27) result$ = initial$ done = true CASE "0","1","2","3","4","5","6","7","8", "9" Result$ = Result$ + Kbd$ CASE "." IF INSTR(Result$, ".") = 0 THEN Result$ = Result$ + Kbd$ else play tone 440,440,100 END IF CASE CHR$(13),chr$(9) Done = TRUE CASE CHR$(8) IF LEN(Result$) > 0 THEN Result$ = LEFT$(Result$, LEN(Result$) - 1) END IF CASE ELSE IF LEN(Kbd$) > 0 THEN play tone 440,440,100 END IF END SELECT LOOP text col*tWth,Row*tHt,Result$+ " ",lt,1,1 GetNum = VAL(Result$) END FUNCTION ' Gets valid text input from user ' allows basic editing ' Parameters: ' Row, Col - location to echo input ' Initial$ - default text ' mx - maximum number of characters FUNCTION GetStr$(Col as integer, Row as integer, Initial$, mx as integer) local rhs$ local integer done, tlen if mx = 0 then mx = 80 Result$ = initial$ Done = FALSE DO WHILE NOT Done text col*tWth,Row*tHt,Result$+CHR$(95)+rhs$+ " ",lt,1,1 tlen = len(Result$)+len(rhs$) if tlen > mx then exit do do Kbd$ = INKEY$ loop until Kbd$ <> "" 'print asc(Kbd$) SELECT CASE Kbd$ case chr$(27) ' ESC result$ = initial$ rhs$ = space$(len(rhs$)) done = true CASE CHR$(13),chr$(9) 'CR or TAB Done = TRUE case chr$(130) ' left arrow if len(Result$)>0 then rhs$= right$(Result$,1)+rhs$ Result$ = left$(Result$,len(Result$)-1) endif case chr$(131) ' right arrow Result$=Result$+left$(rhs$,1) rhs$= mid$(rhs$,2) CASE CHR$(8) ' backspace IF LEN(Result$) > 0 THEN Result$ = LEFT$(Result$, LEN(Result$) - 1) END IF case chr$(127) ' delete rhs$= mid$(rhs$,2) CASE ELSE if isChar(Kbd$) then Result$ = Result$ + Kbd$ END SELECT LOOP text col*tWth,Row*tHt,Result$+rhs$+ " ",lt,1,1 GetStr$ = Result$+rhs$ END FUNCTION function isChar(ch$) as integer if asc(ch$) >31 and asc(ch$) < 128 then isChar = 1 endif end function sub message(Col as integer, Row as integer, txt$) ' prints text at given location text col*tWth,Row*tHt,txt$,lt,1,1 end sub Written for an early beta firmware but stills seems to be OK Jim VK7JH MMedit  MMBasic Help |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
With regards to Lizby's post, the 2 char variable names were from the very start on the TRS80 1978 with 4K (yes that's K) memory! Tassy Jim, I am working on a much shorter routine, which is designed to respond to the monkey text. No need to signal end of input other than pressing enter (clever monkey...). Limit of files signaled by routine. User cannot go past it. I won't post that code until it works 100% because I don't want suggestions unless I'm stuck, and you experts will not be able to resist! With regard to the very kind assistance I have received on here generally (Most from TJ!) I do not bother you blokes until I have hit a brick wall (usually my own stupidity). My routine still has operational flaws. I would post it now if each and every poster solemnly promised on a stack of 16K DIL RAM chips that they would not make any suggestions until I connect an electrolytic across AC. (I've done it -- an anode of the rectifier rather than the KT66 --replaces the starting pistol).... Oh, one more point. Because BASIC was (before QuickBasic) an interpreter language not compiled, to speed things up the subroutines were put at the start of program, rather than the end. Edited 2020-09-21 11:47 by Herry Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
OK Here it is. This is my conversion of the old BASIC spaghetti code tha I posted earlier . I should explain that this was part of a standard module I used for business programs in the 80s and which lasted until the 90s in a DOS office. The operator was faced with the main area of the screen and could make various entries at the foot. The entries were given fixed limits. '* TRIES CLS '* user defined; converts character to pixel count FUNCTION WD(Y) WD = Y * MM.INFO(FONTWIDTH) END FUNCTION '* main program STRINGENTRY("THIS IS THE TEST PROMPT",6) '* string, max length eg 6 PRINT@(10,150)"BACK NOW WITH ENTERED STRING >> "+ANS$ '* end main program area '* subroutine area SUB STRINGENTRY(X$,LIMIT) '* X$ = prompt; ANS$ = Result. GOSUB 800 in old BASIC code COLOUR RGB(CYAN) '* for entry routine ANS$="" '* start wih empty string DO '* build string ANSCHR$ = INKEY$ '* pick up char IF ANSCHR$ = CHR$(13) THEN EXIT DO '* exit to main program if <ENTER> is pressed IF ANSCHR$ <> CHR$(8) AND LEN(ANS$) < LIMIT THEN ANS$ = ANS$ + ANSCHR$ '* build ANS$ until limit IF ANSCHR$ = CHR$(8) AND LEN(ANS$) > 0 THEN ANS$ = LEFT$(ANS$,LEN(ANS$)-1) '* backspace '* left margin 10, and flash entry point (static for rest) IF LEN(ANS$) <> LIMIT THEN PAUSE(150) PRINT @(10,570)X$+":"+ANS$+CHR$(46) +STRING$(LIMIT - LEN(ANS$)-1,46) +CHR$(222) PAUSE(150) PRINT @(10,570)X$+":"+ANS$+CHR$(32) +STRING$(LIMIT - LEN(ANS$)-1,46) +CHR$(222) ELSE '* unless field is full PRINT @(10,570)X$+":"+ANS$+CHR$(222) END IF LOOP COLOUR RGB(WHITE) '* restore normal colour END SUB Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
Herry Senior Member Joined: 31/05/2014 Location: AustraliaPosts: 261 |
No response... Either posters were stunned by my brilliance, or more likely shattered by my incompetence... Senior?! Whatever it says, I'm a complete and utter beginner... |
||||
Print this page |