TITLE "SEVAL - Syslib 4.3" NAME ('EVAL') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SEVAL.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.3 ; Module : SEVAL ; Abstract: This module contains the routine EVAL which parses ; a character string returning any valid Binary, Octal, ; Decimal or Hexidecimal number representation. If a valid ; number is found, the value is returned, along with a ; pointer addressing the character after the last one in ; the number string. Flags indicate the validity of the ; returned number. The string can have any of the forms: ; bbbbbbbbbbbbbbbbB -- b=0 or b=1 (binary string) ; ttttt or tttttD -- 0 <= t <= 9 (decimal string) ; hhhhH or hhhhX -- 0 <= h <= F (hex string) ; oooooooO or oooooooQ -- 0 <= o <= 7 (octal string) ; Revision: ; 1.3 - 4 Jun 90 - Deleted CAPS calls and local variable, abort if ; if called routines return Error. HFB ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points: PUBLIC EVAL ; From SYSLIB Get.. EXT CAPS, EVAL16, EVAL10, EVAL8, EVAL2 .Z80 CSEG ;=============================================================== ; NAME - EVAL ; Entry: HL - Addresses a character string representation of number ; Exit : HL - Addresses char after end of string ; DE - Contains converted number ; A = E, Carry Set (C) if Error, Else Reset (NC) if Ok ; Uses AF,DE,HL ; Special Requirements: None ;=============================================================== EVAL: PUSH BC ; Save BC PUSH HL ; Save ptr to 1st char LD DE,0 ; Set Initial value to 0 LD B,D ; ..and Null Previous char storage ; Find end of string FEND: LD A,(HL) ; Get byte CALL CAPS ; ..and Capitalize CP '0' ; Less than Ascii 0? JR C,FEDONE ; ..jump Done if so CP '9'+1 ; 0 - 9? JR C,FECONT ; ..jump to Continue if so CP 'A' ; Greater than '9' but less than 'A'? JR C,FEDONE ; ..jump Done if so CP 'F'+1 ; A - F? JR NC,FEDONE ; ..jump Done if so ; Digit found -- set flag and point to next FECONT: LD E,1 ; Get a 1 to Digit found flag LD B,A ; Save this char as Last char INC HL ; Pt to next JR FEND ; ..and loop til end found ; Found end of string FEDONE: LD C,A ; Save this in current Terminator char POP HL ; Restore pointer to 1st char in string DEC E ; Did we find any digits? JR NZ,ERROR ; (1 --> 0) ..jump error if No digits ; Determine type of string (H,X=hex; O,Q=oct; B=bin; D,other=dec) LD A,C ; Get terminating char CP 'H' ; Hex JR Z,EHEX CP 'X' JR Z,EHEX CP 'O' ; Octal JR Z,EOCT CP 'Q' JR Z,EOCT LD A,B ; Get previous char for binary check CP 'B' ; Binary? JR Z,EBIN ; Evaluate string as decimal CALL EVAL10 ; Evaluate as decimal JR C,ERROR ; ..jump Error if we overflowed LD A,(HL) ; May pt to "D" CALL CAPS ; ..capitalize CP 'D' ; Incr HL if so JR NZ,DONE INC HL ; Pt to next JR DONE ; Evaluate string as hexadecimal EHEX: CALL EVAL16 ; Evaluate as Hexadecimal JR C,ERROR ; ..jump error if we overflowed LD A,(HL) ; Must pt to H or X CALL CAPS ; ..capitalize INC HL ; Pt to next CP 'H' JR Z,DONE CP 'X' JR Z,DONE ; String Error -- set flag ERROR: LD A,E ; Low-order in A SCF ; Set Carry flag for error POP BC ; Restore BC RET ; Evaluate string as octal EOCT: CALL EVAL8 ; Evaluate as Octal JR C,ERROR ; ..jump error if we overflowed LD A,(HL) ; Must pt to O or Q CALL CAPS ; ..capitalize INC HL ; Pt to next CP 'O' JR Z,DONE CP 'Q' JR EXITCK ; ..go to Exit condition check ; Evaluate string as binary EBIN: CALL EVAL2 ; Evaluate as binary JR C,ERROR ; ..jump error if we overflowed LD A,(HL) ; Must pt to B CALL CAPS ; ..capitalize INC HL ; Pt to next CP 'B' EXITCK: JR NZ,ERROR ; Done with evaluation -- no error DONE: LD A,E ; Low-order in A OR A ; Clear Carry flag POP BC ; Restore BC RET END