chapter8/CH8PRG11.SRC:

20         *= $4000  ; ARBITRARY STARTING POINT
30   FMOVE  = $DDB6
40   FSUB   = $DA60
50   FTEMP  = $0482
60   FSTOR  = $DDA7
70   FASC   = $D8E6
80   INBUFF = $00F3
85   AFP    = $D800
90   CIX    = $00F2
0100 LBUFF  = $0580
0120 CR     = $9B
0130 PUTREC = $09
0140 GETREC = $05
0150 CIOV   = $E456
0160 ICCOM  = $0342
0170 ICBAL  = $0344
0180 ICBLL  = $0348
0190 ;
0200 ; FLOATING POINT DEMONSTRATION
0210 ; READS TWO NUMBERS FROM SCREEN EDITOR,
0215 ; CONVERTS THEM TO FLOATING POINT,
0220 ; SUBTRACTS THE FIRST FROM THE SECOND,
0225 ; STORES THE RESULT IN FTEMP,
0230 ; WHICH IS A USER DEFINED FP REGISTER,
0240 ; AND DISPLAYS THE RESULT.
0260 START  JSR GETNUM ; GET 1ST NUMBER FROM E:
0270        JSR FMOVE  ; MOVE NUMBER FROM FRO TO FR1
0280        JSR GETNUM ; GET 2ND NUMBER FROM E:
0290        JSR FSUB ; FRO <-- FR0-FR1
0300        BCC NOERR  ; SKIP IF NO ERROR
0340        LDA #ERRMSG&255 ; IF ERR., DISPLAY MESSAGE
0350        STA ICBAL
0360        LDA #ERRMSG/256
0370        JMP CONTIN
0390 NOERR  LDX #FTEMP&255 ; STORE RESULT IN FTEMP
0400        LDY #FTEMP/256
0410        JSR FSTOR
0420 ;
0430 ; CONVERT NUMBER TO ATACSII STRING.
0440 ; FIND END OF STRING,
0445 ; CHANGE NEGATIVE NUM. TO POSITIVE,
0450 ; AND ADD CARRIAGE RETURN.
0470        JSR FASC ; FP TO ATASCII, RESULT IN LBUFF
0480        LDY #$FF
0490 MLOOP  INY
0500        LDA (INBUFF),Y ; LOAD NEXT BYTE
0510        BPL MLOOP  ; IF POSITIVE, CONTINUE
0520        AND #$7F ; IF NOT, MASK OFF MSBIT
0530        STA (INBUFF),Y
0540        INY
0550        LDA #CR  ; STORE CARRIAGE RETURN
0560        STA (INBUFF),Y
0570 ;
0580 ; DISPLAY RESULT
0600        LDA INBUFF ; GET BUFFER ADDRESS
0610        STA ICBAL
0620        LDA INBUFF+1
0630 CONTIN STA ICBAL+1
0640        LDA #PUTREC  ; COMMAND FOR PUT RECORD
0650        STA ICCOM
0660        LDA #40  ; SET BUFFER LENGTH = 40
0670        STA ICBLL
0690        LDA #0
0700        STA ICBLL+1
0710        LDX #0 ; IOCB 0 FOR SCREEN EDITOR
0720        JSR CIOV ; CALL CIO
0730        JMP START  ; DO IT AGAIN
0750 ; GET ATASCII STRING FROM E:
0755 ; CONVERT TO FP, RESULT IN FR0
0780 GETNUM LDA #GETREC  ; GET RECORD (ENDS WITH CR)
0790        STA ICCOM
0800        LDA #LBUFF&255 ; SET BUFFER ADDRESS = LBUFF
0810        STA ICBAL
0820        LDA #LBUFF/256
0830        STA ICBAL+1
0840        LDA #40  ; SET BUFFER LENGTH =40
0850        STA ICBLL
0860        LDA #0
0870        STA ICBLL+1
0880        LDX #0 ; IOCB 0 FOR SCREEN EDITOR
0890        JSR CIOV ; CALL CIO
0900        LDA #LBUFF&255 ; STORE BUFFER ADD. IN INBUFF
0910        STA INBUFF
0920        LDA #LBUFF/256
0930        STA INBUFF+1
0940        LDA #0 ; SET BUFFER INDEX = 0
0950        STA CIX
0960        JSR AFP  ; CALL ATASCII TO FP
0970        RTS
0980 ERRMSG .BYTE "ERROR",CR
1000 ; ROUTINE START INFO
1020        * = $2E0
1030        .WORD START
1040        .END

Back to previous page