
 1000         .OR $300
 1010         .TF XB.A/S HEX CONSTANTS
 1020  *---------------------------------
 1030  *
 1040  *      APPLESOFT HEX CONSTANTS
 1050  *
 1060  *      WRITTEN BY DAVID H. BARTLEY
 1070  *      AUSTIN, TEXAS -- AUGUST 1981
 1080  *
 1090  *      TO INITIALIZE:
 1100  *          BRUN THIS PROGRAM (XB.A/S HEX CONSTANTS)
 1110  *
 1120  *      TO USE:
 1130  *          PRECEDE HEX CONSTANTS
 1140  *          WITH A "$" CHARACTER
 1150  *
 1160  *---------------------------------
 1170  BASIC  .EQ $E003    SOFT RE-ENTRY
 1180  CHRGET .EQ $00B1    A/S CHRGET RTN
 1190  CHRGOT .EQ $00B7    A/S CHRGOT RTN
 1200  CHRCHK .EQ CHRGOT+3
 1210  TXTPTR .EQ $B8      A/S TEXT PTR
 1220  OVERR  .EQ $E8D5    OVERFLOW ERROR
 1230  TEMP   .EQ $FC      16-BIT TEMPORARY
 1240  VAL    .EQ $FE      16-BIT VALUE
 1250  *---------------------------------
 1260  INIT
 1270         LDA #$4C     MODIFY CHRGET
 1280         STA CHRGET   TO CALL HERE
 1290         LDA #NEW.CHRGET
 1300         STA CHRGET+1
 1310         LDA /NEW.CHRGET
 1320         STA CHRGET+2
 1330         JMP BASIC    RETURN TO A/S
 1340  NEXTCH
 1350         INC TXTPTR   DUPLICATE THE
 1360         BNE .10      OLD CHRGET
 1370         INC TXTPTR+1
 1380  .10    JMP CHRGOT
 1390  *---------------------------------
 1400  NEW.CHRGET
 1410         BIT IDX      NORMAL MODE?
 1420         BPL .60      -NO
 1430  *
 1440  * CHECK FOR "$" AS NEXT CHARACTER
 1450  *
 1460         JSR NEXTCH   GET CHAR
 1470         CMP #$24    "$"?
 1480         BNE .50      -NO, RETURN IT
 1490  .10
 1500  * PARSE A HEX NUMBER AND CONVERT
 1510  * IT TO A BINARY VALUE
 1520  *
 1530         LDA #0
 1540         STA VAL      VAL = 0
 1550         STA VAL+1
 1560         LDA #4       INDEX TO POWER
 1570         STA IDX
 1580  .20
 1590         JSR NEXTCH   GET HEX DIGIT
 1600         BEQ .40      -EOL OR ":"
 1610         SEC
 1620         SBC #$30     CHECK FOR DIGIT
 1630         BMI .35      -NOT A DIGIT
 1640         CMP #10
 1650         BCC .30      -OK (0-9)
 1660         SBC #17
 1670         BMI .40      -NOT A DIGIT
 1680         CMP #6
 1690         BCS .40      -NOT A DIGIT
 1700         ADC #10
 1710  .30    JSR ASL4     MULT VAL BY 16
 1720         ORA VAL      ADD NEW DIGIT
 1730         STA VAL
 1740         JMP .20
 1750  .35
 1760         CMP #$88     "DEF" TOKEN?
 1770         BNE .40      -NO
 1780         JSR ASL4     -YES
 1790         LDA VAL
 1800         ORA #$0D     ASL BY 12 AND
 1810         STA VAL+1    ADD $0DEF
 1820         LDA #$EF
 1830         STA VAL
 1840         BNE .20      (ALWAYS)
 1850  .40
 1860         LDA TXTPTR   BACK UP THE
 1870         BNE .41
 1880         DEC TXTPTR+1
 1890  .41    DEC TXTPTR
 1900         LDA TXTPTR   SAVE TXTPTR
 1910         STA TEMP     IN CASE IS IS
 1920         LDA TXTPTR+1 DECREMENTED
 1930         STA TEMP+1   BY THE CALLER
 1940  *
 1950         LDA #$30     ASCII "0"
 1960  .50    JMP CHRCHK   -EXIT
 1970  .60
 1980  * CONVERT BINARY VALUE TO DECIMAL
 1990  * AND RETURN THE NEXT ASCII DIGIT
 2000  *
 2010         LDA TEMP     FIX ANY ATTEMPT
 2020         STA TXTPTR   TO DECREMENT
 2030         LDA TEMP+1   TXTPTR
 2040         STA TXTPTR+1
 2050         STX SAVE.X
 2060         LDX IDX      POWER OF TEN
 2070         DEC IDX
 2080         LDA #$30     ASCII "0"
 2090  .70
 2100         PHA          ASCII DIGIT
 2110         LDA VAL
 2120         CMP LO.TENS,X  SET CARRY
 2130         LDA VAL+1
 2140         SBC HI.TENS,X
 2150         BCC .80      -EXIT LOOP
 2160         STA VAL+1
 2170         LDA VAL
 2180         SBC LO.TENS,X
 2190         STA VAL
 2200         PLA          ASCII DIGIT
 2210         CLC
 2220         ADC #1       INCREMENT IT
 2230         BNE .70      -LOOP
 2240  .80
 2250         PLA          ASCII DIGIT
 2260         LDX SAVE.X
 2270  .90
 2280         JMP CHRCHK   PROCESS IT
 2290  *---------------------------------
 2300  ASL4   JSR ASL2     ASL VAL BY 4
 2310  ASL2   JSR ASL1     ASL VAL BY 2
 2320  ASL1   ASL VAL      ASL VAL BY 1
 2330         ROL VAL+1
 2340         BCS OVFLOW   -OVERFLOW ERROR
 2350         RTS          -EXIT
 2360  OVFLOW
 2370         JMP OVERR    REPORT OVERFLOW
 2380  *---------------------------------
 2390  LO.TENS .DA #1
 2400         .DA #10
 2410         .DA #100
 2420         .DA #1000
 2430         .DA #10000
 2440  HI.TENS .DA /1
 2450         .DA /10
 2460         .DA /100
 2470         .DA /1000
 2480         .DA /10000
 2490  IDX    .DA #$FF     TABLE INDEX
 2500  SAVE.X .DA #0       SAVE X-REG
 2510  *---------------------------------
 2520  ZZZZZZ .EN

