TITLE "VID7 - Vlib 4.0" NAME ('VID7') ;===================================================================== ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;--------------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from VID7.Z80 Ver 1.1 by Richard Conn ; Date : 25 Feb 89 ; Version : 1.2 ; Module : VID7 ; Abstract: This module contains the routine GOTOXY which places the ; cursor of the current terminal at the specified location on ; the screen. The top left corner is Column 1, Row 1 (Home). ; Revision: ; 1.4 29 Aug 92 - Moved SETATT/SETATR to other module. HFB ; 1.3 22 Dec 89 Joe Wright ; Fixed bugs in '%.' and '%>xy' commands. ; Fixed DIGOUT routine for 101 etc. so that '0' is output. ; @PARSV now Public to be used by other routines. ; Modified SETATT to use new SA attribute string in TCAP. ; Added AT attribute string following SA string. ; Added SETATR routine. ; (May be moved to its own module as time permits.) ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC GOTOXY, @PARSV ; ..from VLIB Get.. EXT VIDPTR, VIDELAY, @CM, @CMD, @SA, @AT, @B15 ; ..from SYSLIB Get.. EXT COUT, CAPS .Z80 CSEG ;=============================================================== ; GOTOXY - Move Cursor to Col X, Row Y on Screen ; Entry: HL - H = Row, L = Column (Home = 1,1) ; Exit : A = 0 and Zero Flag Set (Z) if Not done, else ; A = FFH and Zero Flag Reset (NZ) if Cursor moved Ok ; Uses : AF ; Special Requirements: None ;=============================================================== GOTOXY: PUSH HL PUSH DE PUSH BC ; Save regs LD DE,(@CM) ; Get Cursor Movement string addr LD A,(DE) ; Is it valid? OR A JR Z,EXIT ; ..jump to exit w/Null Error Code if not CALL GXY ; Output XY string with delay DELAY: LD A,(@CMD) ; Get CM Delay factor CALL VIDELAY ; ..and pause OK: OR 0FFH ; Return Ok condition of NZ EXIT: POP BC POP DE POP HL ; Restore regs RET ;=============================================================== ; @PARSV - Public entry for routines which would use the ; Video Parser. ; Entry: HL, DE and BC will have been pushed onto the stack ; as in SETATT above, and DE will point to the relative ; string. A Complex string will be parsed according to ; CM rules with H as the first argument and L the second. ; A Simple string will be passed unchanged. ; Exit: A = 0 and Z if the string is empty. ; A = 255 and NZ if the string was sent. ;=============================================================== @PARSV: LD A,(DE) ; First character of the string OR A ; Check for null string JR Z,EXIT ; Not supported, return Z CALL GOXY ; Don't adjust HL JR DELAY ; Exit through cursor motion delay ;================== Cursor Movement ================= ; GXY - General Entry for Cursor Movement. ; On input: H=Row, L=Column to Position To (1,1 is Home) ; DE=address of CM string GXY: DEC H ; Adjust to 0,0 for home DEC L ; Fall through to GOXY.. ;================ Generalized Parser ================ ; Entry: DE points to the TCAP string. ; H is the first macro value, L is the second. ; Normal CM programming rules apply. ; ; Exit: A is always Null and DE points to the next ; string. HL and BC are undefined. ;==================================================== GOXY: LD A,(DE) ; Get next char INC DE ; Point to next OR A ; Done? RET Z ; ..return if so CP '%' ; Is it a command? JR Z,GXYCMD ; ..jump if so CP '\' ; Is it an escape sequence? JR NZ,GXYNOR ; ..jump if normal char LD A,(DE) ; Else get next literal char GXYNOX: INC DE ; ..and advance GXYNOR: CALL COUT ; Send char JR GOXY ; ..and loop ; Interpret next character as a command character GXYCMD: LD A,(DE) ; Get command char INC DE ; Point to next CALL CAPS ; Make uppercase CP 'D' ; %D JR Z,GXYOUT1 ; Print H as 1-3 decimal digits CP '2' ; %2 JR Z,GXYOUT2 ; Print H as 2 decimal digits CP '3' ; %3 JR Z,GXYOUT3 ; Print H as 3 decimal digits CP '.' ; %. JR Z,GXYOUT4 ; Print H as binary CP '+' ; %+v JR Z,GXYOUT5 ; Print next character + H as binary CP '>' ; %>xy JR Z,GXYGT ; If H > x then H = H + y CP 'R' ; %R JR Z,GXYREV ; Reverse H and L CP 'I' ; %I JR Z,GXYINC ; Increment H and L CP 'N' ; %N Null command? JR NZ,GXYNOR ; Ship it literally if not, else.. XOR A ; ..get a null and.. JR GXYNOR ; ..ship it ; I - Set row/col home to 1,1 rather than 0,0 GXYINC: INC H ; Set Row to Row + 1 INC L ; Set Col to Col + 1 JR GOXY ; R - Reverse order of output to column then row (default is row then column) GXYREV: LD A,L ; Reverse Row and Column LD L,H LD H,A JR GOXY ; >xy - If value of row/col is greater than x, add y to it GXYGT: LD A,(DE) ; Get x INC DE ; Point to y CP H ; Compare x - H JR NC,GXYGT1 ; H is LE x LD A,(DE) ; Get y ADD A,H ; Add H to it LD H,A ; Put value back in H GXYGT1: INC DE ; Point to next JR GOXY ; ..and resume ; . - Output Next value in Binary GXYOUT4: LD A,H JR OUTMRK ; +n - Add n to next value and output GXYOUT5: LD A,(DE) ; Get value to add INC DE ; Point to next ADD A,H ; Add in H ; OUTMRK: CALL COUT ; Output value LD H,L ; Move any next byte in position JR GOXY ; ..and back for more ; 3 - Output next value as 3 decimal digits GXYOUT3: LD C,1 ; Set for leading zeroes JR GXYO1A ; ..and continue below ; 2 - Output next value as 2 decimal digits GXYOUT2: LD A,H ; Get value LD C,1 ; Set for leading zeroes JR GXYOT3 ; ..and print 2 above ; D - Output next value as n decimal digits with no leading zeroes GXYOUT1: LD C,0 ; Set for No leading zeroes GXYO1A: LD A,H ; Get value LD B,100 ; Output 100's CALL DIGOUT GXYOT3: LD B,10 ; Output 10's CALL DIGOUT ADD A,'0' ; Output 1's JR OUTMRK ; jump to output last digit and continue ;============================================================ ; DIGOUT - Output A/B as decimal digit to COUT ; Entry: A = Dividend ; B = Divisor ; C = Leading Zero Flag ; Exit: A = Remainder ;============================================================ DIGOUT: PUSH DE ; Save DE LD D,'0'-1 ; Start with -1 DECOT1: SUB B ; Subtract INC D ; Count successful subtractions JR NC,DECOT1 ; Loop until Cy ADD A,B ; Add back in LD B,A ; Save remainder in B LD A,D ; Get digit CP '0' JR NZ,DECOT2 ; Go for it BIT 0,C ; Leading Zero flag JR Z,DECOT3 ; No leading zeroes DECOT2: CALL COUT ; Send it.. LD C,1 ; ..and any zero next time DECOT3: LD A,B ; Get A back POP DE ; Restore DE RET END ; ; End of VID7.Z80