AppleIIAsm-Collection/source/disk5_strings/T.STR2NUM.SUB.MIN

119 lines
3.2 KiB
Plaintext
Raw Normal View History

2018-11-15 00:02:04 +00:00
STR2NUM
PLA
STA RETADR
PLA
STA RETADR+1
PLA
STA ADDR1 ; ADRESS OF STRING
PLA ; TO CNVERT
STA ADDR1+1
LDY #0
LDA (ADDR1),Y
TAX ; GET LENGITH; TO REGX
LDA #1
STA :NINDEX ; INDEX = 1
LDA #0
STA :NACCUM ; ACCUM = 0
STA :NACCUM+1
STA :SNGFLAG ; SIGN IS POSITIVE
TXA
BNE :INIT1 ; EXIT WITH ACCUM = 0
; IF BUFFER IS EMPTY
JMP :EREXIT ; ERROR EXIT IF NOTHING
; IN BUFFER
:INIT1
LDY :NINDEX
LDA (ADDR1),Y
CMP #173
2018-11-15 00:02:04 +00:00
BNE :PLUS ; BR IF NOT -
LDA #$0FF
STA :SNGFLAG ; ELSE SIGN IS NEGATIVE
INC :NINDEX
DEX ; DECREMENT COUNT
BEQ :EREXIT ; ERROR EXIT IF ONLY
; - IN BUFFER
JMP :CNVERT
:PLUS
CMP #'+'
BNE :CHKDIG ; START CONVERSION IF 1ST
INC :NINDEX
DEX ; DEC COUNT; IGNORE + SIGN
BEQ :EREXIT ; ERROR EXIT IF ONLY
; + IN THE BUFFER
:CNVERT
LDY :NINDEX
LDA (ADDR1),Y
; GET NEXT CHAR
:CHKDIG
CMP #$B0 ; "0"
BMI :EREXIT ; ERROR IF NOT A NUMERAL
CMP #$BA ; '9'+1; TECHNICALLY :
BPL :EREXIT ; ERR IF > 9 (NOT NUMERAL)
PHA ; PUSH DIGIT TO STACK
ASL :NACCUM
ROL :NACCUM+1 ; TIMES 2
LDA :NACCUM
LDY :NACCUM+1 ; SAVE ACCUM * 2
ASL :NACCUM
ROL :NACCUM+1
ASL :NACCUM
ROL :NACCUM+1 ; TIMES 8
CLC
ADC :NACCUM ; SUM WITH * 2
STA :NACCUM
TYA
ADC :NACCUM+1
STA :NACCUM+1 ; ACCUM=ACCUM * 10
PLA ; GET THE DIGIT NACK
SEC
SBC #$B0
CLC ; CONVERT STR TO BIN
ADC :NACCUM
STA :NACCUM
BCC :D2B1 ; BRANCH IF NO CARRY TO HBYTE
INC :NACCUM+1 ; ELSE INC HIGH BYTE
:D2B1
INC :NINDEX ;INC TO NEXT CHARACTER
DEX
BNE :CNVERT ; CONTINUE CONVERSION
LDA :SNGFLAG
BPL :OKEXIT ; BR IF VAL IS POSITIVE
LDA #0 ; ELSE REPLACE WITH -RESULT
SEC
SBC :NACCUM
STA :NACCUM
LDA #0
SBC :NACCUM+1
STA :NACCUM+1
:OKEXIT
CLC
BCC :EXIT
:EREXIT
SEC
LDA ERRCTRL
CMP #1
BEQ :CHKERR
JMP :ERREND
:CHKERR
_ERR :E_SID;:E_MSG;:E_DUMP;:NACCUM;#4
:ERREND
2018-11-15 00:02:04 +00:00
:EXIT
LDA RETADR+1
PHA
LDA RETADR
PHA
LDX :NACCUM+1
LDY :NACCUM
STY RETURN
STX RETURN+1
LDA #2
STA RETLEN
2018-11-15 00:02:04 +00:00
LDA :NINDEX
RTS
:NACCUM DS 2
:SNGFLAG DS 1
:NINDEX DS 1
:E_SID ASC "STR2NUM (S2N MACRO)",00
:E_MSG ASC "ERR! NO DATA, OR NOT A NUMERAL VALUE",00
:E_DUMP ASC "DUMPING :NACCUM(2) :SNGFLAG(1) :NINDEX(1)",00