
 1000  *SAVE S.65802.CONVERSIONS
 1010  *--------------------------------
 1020         .OP 65802
 1030  *--------------------------------
 1040  *   CONVERT UP TO 9999, MAX TIME < 80 MSEC
 1050  *      # CYCLES = 8*NUMBER + 44
 1060  *--------------------------------
 1070  CONV.1
 1080         CLC          ENTER 65802 NATIVE MODE
 1090         XCE
 1100         REP #$30     16-BIT MODES
 1110         LDA ##0      START WITH 0000
 1120         LDX 0        GET NUMBER TO BE CONVERTED
 1130         BEQ .2       ...IT IS 0000
 1140         SED          ENTER DECIMAL MODE
 1150         CLC
 1160  .1     ADC ##1      INCREMENT BCD VALUE
 1170         DEX          DECREMENT BINARY VALUE
 1180         BNE .1       ...NOT FINISHED YET
 1190         CLD          BACK TO BINARY MODE
 1200  .2     STA 2        STORE RESULT
 1210         SEC          BACK TO 6502 EMULATION MODE
 1220         XCE
 1230         RTS          RETURN TO CALLER
 1240  *--------------------------------
 1250  *   CONVERT UP TO 65535, MAX TIME < 705 MSEC
 1260  *      # CYCLES = 11*NUMBER +3*INT(NUMBER/10000) + 50
 1270  *--------------------------------
 1280  CONV.2
 1290         CLC          ENTER 65802 NATIVE MODE
 1300         XCE
 1310         REP #$30     16-BIT MODES
 1320         LDA ##0      START WITH 0000
 1330         TAY          CLEAR 10000'S DIGIT
 1340         LDX 0        GET NUMBER TO BE CONVERTED
 1350         BEQ .2       ...IT IS 0000
 1360         SED          ENTER DECIMAL MODE
 1370         CLC
 1380  .1     ADC ##1      INCREMENT BCD VALUE
 1390         BCC .3
 1400         INY          INCREMENT 10000'S DIGIT
 1410         CLC
 1420  .3     DEX          DECREMENT BINARY VALUE
 1430         BNE .1       ...NOT FINISHED YET
 1440         CLD          BACK TO BINARY MODE
 1450  .2     STA 2        STORE RESULT
 1460         SEC          BACK TO 6502 EMULATION MODE
 1470         XCE
 1480         STY 4        STORE 10000'S DIGIT
 1490         RTS          RETURN TO CALLER
 1500  *--------------------------------
 1510         .LIF

