; ; Module Name: MEVALD24 ; Author: Steven Cohen ; based on Richard Conn's EVAL10 ; March 10, 1987 ; public EVALD24 EXT DOUBLE24,ZEROBUF MACLIB MATH24 ; ; EVALD24 ; Convert a string of ASCII decimal digits ; into a binary value; string is converted until invalid digit is ; encountered. ; ; INPUT: DE POINTS TO a 3-byte buffer in which the converted ; value is to be stored. ; HL POINTS TO the first byte of the string to be converted ; OUTPUT: HL points to error character if any ; A contains the lowest order 8 bits of the value ; carry flag set indicates error ; EVALD24: PUSH BC ; SAVE BC CALL ZEROBUF ; Get next digit and check for '0' - '9' E10L: LD A,(HL) ; GET BYTE CP '0' ; CHECK FOR RANGE JR C,DONE CP '9'+1 ; CHECK FOR 0-9 JR NC,DONE SUB '0' ; CONVERT TO BINARY PUSH HL ; Multiply buffer by 10 MUL10: PUSH DE PUSH AF ; SAVE VALUE EX DE,HL CALL DOUBLE24 ;buffer=buffer*2 PUSH HL LD DE,NBUF ;save a copy for later addition LDI LDI LDI POP HL CALL DOUBLE24 ;buffer=buffer*4 CALL DOUBLE24 ;buffer=buffer*8 ; EX DE,HL ; ; add our copy of 2*buffer to 8*buffer to yield 10*buffer ; OR A LD B,3 PUSH HL ; EX DE,HL LD DE,NBUF A10LP: LD A,(DE) ADC (HL) LD (HL),A INC DE INC HL DJNZ A10LP POP HL ; ; Add in the new digit ; LD B,3 ; 3 bytes POP AF ; get latest digit A10BLP: ADC (HL) ; add to memory byte with carry LD (HL),A ; put it back in memory INC HL ; next byte LD A,0 ; zero the accumulator w/o disturbing carry DJNZ A10BLP POP DE ; ; Continue ; POP HL INC HL ; PT TO NEXT CHARACTER JR E10L ; ; Done -- Result already in buffer pted to by DE; Set A=its lowest byte ; DONE: LD A,(DE) ; A=first byte of numeric buffer POP BC ; RESTORE BC RET NBUF: ;24 bit buffer for temporary storage M24BQ END