NEW
  AUTO 3,1
*--------------------------------------
*   Error Handler
*--------------------------------
ERROR.HANDLER
       AND #$1F     TRIM TO SIZE
       STA ERROR.CODE
       LDA #$0F     LEVEL
       STA LEVEL
       JSR UNHOOK.WRITE  ...IF WRITING
       LDA #0
       STA CLOSE.FLUSH.PARMS+1
       JSR MLI.CC   CLOSE ALL FILES
       BCS .1
       LDA #0
       STA LEVEL
       STA CLOSE.FLUSH.PARMS+1
       JSR MLI.CD   FLUSH
.1     LDA ERROR.CODE
       JSR PRINT.ERROR
       JSR CLOSE.EXEC.FILE
       JSR CROUT
       JMP SC.SOFT
*--------------------------------
ERR.FILE.BUSY
       LDA #$14
       SEC
       RTS
*--------------------------------
ERROR.PRINTER
       JSR FIND.AND.PUT.MSG.IN.WBUF
       JSR BELL
*---PRINT MESSAGE FROM WBUF------
PRINT.CR.MESSAGE
       JSR CROUT
PRINT.MESSAGE
       LDX #0
.1     LDA WBUF+1,X
       JSR COUT
       INX
       CMP #$8D     END OF MESSAGE?
       BNE .1       ...NO
       RTS          ...YES
*--------------------------------
FIND.AND.PUT.MSG.IN.WBUF
       LDX #0
       CLC
*---SEARCH FOR MESSAGE #---------
       STA WBUF
       TAY
       BEQ .5       ...FIRST MESSAGE
.2     JSR SCI.GET.NEXT.NYBBLE
       BNE .4
.3     JSR SCI.GET.NEXT.NYBBLE
       BEQ .3
       BNE .2
.4     EOR #$0F
       BNE .2
       DEC WBUF
       BNE .2
*---Put message in WBUF----------
.5     LDY #0
       STY WBUF+80  SQUEEZED BLANK COUNT
.6     STY WBUF     STORAGE INDEX
       LDA WBUF+80  BLANK COUNT
       BNE .8       ...ANOTHER BLANK
.7     JSR SCI.GET.NEXT.NYBBLE
       LDA SCI.FIRST.TABLE,Y
       BNE .9       ...FREQUENT CHAR
       JSR SCI.GET.NEXT.NYBBLE
       LDA SCI.SECOND.TABLE,Y
       BNE .9       ...TWO NYBBLE CHAR
       JSR SCI.GET.NEXT.NYBBLE
       LDA SCI.THIRD.TABLE,Y
       BMI .9       ...REAL CHAR
       STA WBUF+80  ...BLANK COUNT
.8     LDA #" "
       DEC WBUF+80
       BEQ .7       ...NO MORE BLANKS
.9     LDY WBUF     STORAGE INDEX
       STA WBUF+1,Y
       INY          NEXT COLUMN
       EOR #$8D     END OF MESSAGE?
       BNE .6       ...NO
       RTS          ...YES
*--------------------------------
SCI.GET.NEXT.NYBBLE
       LDA SCI.MESSAGES,X
       BCS .1       2ND NYBBLE
       LSR          1ST NYBBLE
       LSR
       LSR
       LSR
       TAY
       SEC
       RTS
.1     INX
       AND #$0F
       TAY
       CLC
       RTS
*--------------------------------------
MAN
SAVE usr/src/scmasm.30/sci.s.errors
LOAD usr/src/scmasm.30/scmasm.s
ASM
