TITLE "VIDR - Vlib 4.1" NAME ('VIDR') ;================================================================= ; Copyright (C) 1990 Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Joe Wright ; Date : 19 January 1990 ; Version : 1.0 ; Module : VIDR ; Abstract: This module allows reading the current cursor position ; from the terminal and to read the current line from Column 1 ; until and including the character at the current Cursor Column. ; Revision: ; 1.1 - 29 Aug 92 - Revised to add ANSI test and routine per ; changes by Terry Hazen. HFB ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC GETCUR, GETLIN, @LINE ; ..from VLIB get.. EXT VIDOUT, @CM, @RC, @RL EXT @B15, @PARSV ;1.1 ; ..from SYSLIB get.. EXT CAPS, CIN ; Constants LINLEN EQU 132+1 ; Maximum allowable line length .Z80 CSEG ;=============================================================== ; GETCUR - Return the current cursor position in HL in GOTOXY ; format. ; Entry: None ; Exit: HL is cursor position and A = 0FFH and NZ if no error. ; A = 00 and Z if function is not available. ;=============================================================== GETCUR: PUSH DE ; Save user's DE LD A,(@B15) ;1.1 Get configuration byte BIT 4,A ;1.1 Is it ANSI? JR NZ,ANSI ;1.1 ..jump if So LD DE,-1 ; Preset D and E to -1 LD HL,(@CM) ; Point to cursor movement string GCLOOP: LD A,(HL) INC HL OR A JR Z,RDCUR ; End of CM string CP '%' JR NZ,GCLOOP ; Not a command LD A,(HL) INC HL CALL CAPS CP 'I' JR Z,INCR ; Increment row and col CP '+' ; Is the cursor biased? JR NZ,GCLOOP ; No. LD A,D ; Get -1 or 0 from D LD D,E ; Previous E to D ADD A,(HL) ; Add the bias from CM string LD E,A ; Store it in E INC HL ; Next JR GCLOOP INCR: INC DE ; -1 goes to 0 JR GCLOOP RDCUR: CALL GETC ;1.1 Check for String presence ;1.1 LD HL,(@RC) ; Read Cursor string address ;1.1 CALL GETTRM ; Send the string and get response JR Z,ERR ; If not available LD A,(HL) ; Get the first character INC HL LD L,(HL) ; Get the second character LD H,A SBC HL,DE ; Remove bias OK: OR 0FFH ; Indicate success ERR: POP DE RET ;1.1 ANSI reports cursor position string as: ,'[r;cR', where r(ow) ;1.1 and c(ol) may be 1-3 ascii decimal digits. ANSI: CALL GETC ;1.1 Read cursor position JR Z,ERR ;1.1 ..jump if Not Avail PUSH HL ;1.1 Save buffer start ANSIL: CALL CIN ;1.1 Get returned character LD (HL),A ;1.1 .save in buffer INC HL ;1.1 ..advance to next CP 'R' ;1.1 End of String? JR NZ,ANSIL ;1.1 ..jump if Not GETVAL: POP HL ;1.1 Restore starting buffer pointer INC HL ;1.1 Skip '[' CALL EVAL ;1.1 Get row in D PUSH DE ;1.1 ..Save Row INC HL ;1.1 CALL EVAL ;1.1 Get Col in D LD L,D ;1.1 Move Col to L POP DE ;1.1 .restore Row LD H,D ;1.1 ..and move Row to H JR OK ;1.1 Exit EVAL: LD D,0 ;1.1 Initialize accumulator EVLP: LD A,(HL) ;1.1 Get char CP '0' ;1.1 Check range RET C ;1.1 ..return if out of range SUB '0' ;1.1 Make binary CP 10 ;1.1 Legal? RET NC ;1.1 ..return if Not PUSH AF ;1.1 Save for a while LD A,D ;1.1 Multiply D by 10 ADD A,A ;1.1 *2 ADD A,A ;1.1 *4 ADD A,D ;1.1 *5 ADD A,A ;1.1 *10 LD D,A ;1.1 ..put it back POP AF ;1.1 Restore current digit ADD A,D ;1.1 Add it in LD D,A ;1.1 .save INC HL ;1.1 ..advance to next char JR EVLP ;1.1 ...and loop ;=============================================================== ;1.1 GETC - Report the current cursor position. ;1.1 Entry: GETC will read the current cursor position. ;1.1 Exit: HL points to the null-terminated string read ;1.1 from the Terminal. ;=============================================================== GETC: LD HL,(@RC) ;1.1 Read Cursor string address JR GETTRM ;1.1 ..send the string and get response ;=============================================================== ; GETLIN - Get a line from the terminal screen. ; Entry: The cursor has been positioned to a particular ; Column on the current Row. GETLIN will read ; from Col 1 until and including the Cursor position. ; ; Exit: HL points to the null-terminated string read ; from the Terminal. ;=============================================================== GETLIN: LD HL,(@RL) ; Read Line string ; Fall through to GETTRM ;=============================================================== ; GETTRM - Read Terminal characters until any control character. ; Return HL pointing to the Terminal string. ;=============================================================== GETTRM: LD A,(HL) ; First character OR A ; Check for Null RET Z ; Forget it PUSH DE LD D,0 ; No delay CALL VIDOUT ; Ship the string at HL LD HL,@LINE ; Our string PUSH HL ; Save it.. GETT: CALL CIN ; Get any character LD (HL),A ; Save it INC HL ; Next.. CP ' ' ; Is it a Control? JR NC,GETT ; No, Keep it up DEC HL ; Back up to the Control LD (HL),0 ; Null it POP HL ; Restore @LINE pointer POP DE OR 0FFH ; Indicate success RET ; Put this in the Data Segment DSEG @LINE: DS LINLEN END ; End of VIDR.Z80