home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ZSYS
/
SIMTEL20
/
SYSLIB
/
SLIB2.LBR
/
SEVAL2.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
78 lines
;
; SYSLIB Module Name: SEVAL2
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public eval16
;
; EVAL16 --
; Convert the string of ASCII hexadecimal digits pointed to by HL
; into a binary value; string is converted until invalid digit is
; encountered.
; On return, HL points to error character, DE=value, A=E (low
; order 8 bits of value). BC not affected.
;
EXT CAPS ; CAPITALIZATION ROUTINE
EVAL16:
PUSH BC ; SAVE BC
LD DE,0 ; SET DE=0 INITIALLY
; Get next digit and check for '0' - '9'
E16L:
LD A,(HL) ; GET BYTE
CALL CAPS ; CAPITALIZE
CP '0' ; CHECK FOR RANGE
JP C,DONE
CP 'F'+1 ; CHECK FOR RANGE
JP NC,DONE
CP '9'+1 ; CHECK FOR 0-9
JP C,PRODEC
CP 'A' ; CHECK FOR OUT OF RANGE
JP C,DONE
PRODEC:
SUB '0' ; CONVERT TO BINARY
CP 10
JP C,PROC
SUB 7 ; ADJUST FOR 'A'-'F'
; Proceed with processing
PROC:
PUSH AF ; SAVE VALUE
; Multiply DE by 16
MUL16:
PUSH HL ; SAVE HL
LD HL,0 ; ACC=0
LD B,16 ; 16 LOOPS
MUL16L:
ADD HL,DE ; HL=HL+DE
DEC B ; COUNT DOWN
JP NZ,MUL16L
LD D,H ; NEW DE
LD E,L
POP HL ; RESTORE HL
; Add in A
POP AF ; GET LATEST DIGIT
ADD A,E ; A=A+E
LD E,A
LD A,D ; ADD TO D IF NECESSARY
ADC 0
; Continue
INC HL ; PT TO NEXT CHARACTER
JP E16L
; Done -- Result already in DE; Set A=E
DONE:
LD A,E ; A=E
POP BC ; RESTORE BC
RET
END