The STOI.I include file resides on the Kyan Pascal 2.x Utilities Disk 1.
- FUNCTION STRTOINT(VAR NUMBER:STRING6):INTEGER; VAR RESULT:INTEGER;
Source Code
FUNCTION STRTOINT(VAR NUMBER:STRING6):INTEGER;
VAR RESULT:INTEGER;
BEGIN
#A
STX _T
LDY #9 ;STRING ADDRESS
LDA (_SP),Y
STA _T+1
INY
LDA (_SP),Y
STA _T+2
;
LDA #0 ;ZERO RUNNING TOTAL
STA _T+3
STA _T+4
;
LDY #5 ;FIND FIRST NON-SPACE CHAR IN STRING
STI1 LDA (_T+1),Y
CMP #$20
BNE STI2
DEY
BPL STI1
BMI STI8 ;IF ALL SPACES, RESULT IS ZERO
;
STI2 LDX #0 ;INDEX INTO PWROFTEN TABLE
STI3 LDA (_T+1),Y
CMP #'0
BCC STI5 ;TREAT NON-DIGITS AS ZERO
CMP #'9+1
BCS STI5
AND #15 ;LEAVES 1..9 IN A
BEQ STI5
STY _T+5 ;SAFE
TAY
STI4 CLC ;MULTIPLY LOOP IS SLOWER THAN SHIFTING BITS
LDA ST10LO,X ;BUT IT'S ALSO MUCH SHORTER
ADC _T+3
STA _T+3
LDA ST10HI,X
ADC _T+4
STA _T+4
DEY
BNE STI4
LDY _T+5
STI5 INX
DEY
BPL STI3
INY ;Y=0
LDA (_T+1),Y
CMP #'- ;MINUS SIGN?
BNE STI8 ;NO
LDA _T+3
EOR #$FF
STA _T+3
LDA _T+4
EOR #$FF
STA _T+4
INC _T+3
BNE STI8
INC _T+4
STI8 LDY #5
LDA _T+3
STA (_SP),Y
INY
LDA _T+4
STA (_SP),Y
LDX _T
#
STRTOINT := RESULT
END;
#A
ST10LO DB >1
DB >10
DB >100
DB >1000
DB >10000
ST10HI DB <1
DB <10
DB <100
DB <1000
DB <10000
#
No comments:
Post a Comment