        NAM    PROM MONITOR
**
** CUSTOMIZED VERSION TO VECTOR SWI THROUGH $0010. IF THE USER 
** WANTS TO USE BREAKPOINTS (SWI), $0010 SHOULD BE SET TO 7E FF EE
** (JMP $FFEE) TO POINT SWI TO THE ORIGINAL ENTRY POINT (INTRPT).
**
**ALTAIR 680B PROM MONITOR
**ACIA VERSION 1.0
**
SWIVEC  EQU    $10
MIVEC   EQU    $100
NMIVEC  EQU    $104
STRAPS  EQU    $F002
NOTERM  EQU    0
ACIACS  EQU    $F000
ACIADA  EQU    $F001
**
**MONITOR STACK AND FLAGS
**
        ORG    $F1
STACK   RMB    1         BOTTOM OF MONITOR'S STACK
BRKADR  RMB    1         BREAKPOINT ADDRESS FLAG
ECHO    RMB    1         TTY ECHO FLAG
EXTFLG  RMB    1         EXTENDED CHARACTER FLAG
BUFULL  RMB    1         BUFFER FULL FLAG
SAVSTK  RMB    2         TEMP FOR STACK POINTER
TEMP    RMB    1         TEMPORARY STORAGE
BYTECT  RMB    1         BYTE COUNT
XHI     RMB    1         XREG HIGH
XLOW    RMB    1         XREG LOW
SHIFT   RMB    1         BAUDOT SHIFT FLAG
SAVEX   RMB    2         TEMP FOR INDEX RG
BUFFER  RMB    1         BAUDOT CHARACTER FLAG
**
* START OF PROM
**
        ORG    $FF00
**
* INPUT ONE CHAR INTO B-REGISTER
* ECHO CHARACTER IF BIT 7 OF ECHO FLAG IS CLEAR
**
INCH    BSR    POLCAT    ACIA STATUS TO A REG
        BCC    INCH      RECEIVE NOT READY
        LDAB   #$7F      MASK FOR PARITY REMOVAL
        CMPB   ECHO      CHECK ECHO FLAG
        ANDB   ACIADA    GET CARACTER
        BCC    OUTCH     ECHO
        RTS              NO ECHO
**
* THE FOLLOWING NOP LINES LINES UP THE ENTRY
* POINTS TO POLCAT IN THE TWO VERSIONS
* OF THE MONITOR
**
        NOP
**
* INPUT ONE HEX DIGIT INTO B REG
* RETURN TO CALLING PROGRAM IF
* CHARACTER RECEIVED IS A HEX
* DIGIT. IF NOT HEX, GO TO CRLF
**
INHEX   BSR    INCH      GET A CHARACTER
        SUBB   #'0
        BMI    C1        NOT HEX
        CMPB   #$9
        BLE    IN1HG     NOT HEX
        CMPB   #$11
        BMI    C1        NOT HEX 
        CMPB   #$16
        BGT    C1        NOT HEX
        SUBB   #7        IT'S A LETTER-GET BCD
IN1HG   RTS              RETURN
**
* POLL FOR CHARACTER
* SETS CARRY IF CHARACTER IS IN BUFFER
* CLOBBERS B REG
**
POLCAT  LDAB   ACIACS    ACIA STATUS TO B
        ASRB             ROTATE RDRF BIT INTO CARRY
        RTS              RETURN
**
* LOAD PAPER TAPE
* LOAD ONLY S1 TYPE RECORDS 
* TERMINATE ON S9 OR CHECKSUM ERROR
**
LOAD    BSR    INCH      READ CHARACTER
        SUBB   #'S
        BNE    LOAD      FIRST CHAR NOT (S)
        BSR    INCH      READ CHARACTER
        CMPB   #'9
        BEQ    C1        S9 END OF FILE
        CMPB   #'1
        BNE    LOAD      SECOND CHAR NOT (1)
        CLRA             ZERO THE CHECKSUM
        BSR    BYTE      READ BYTE
        SUBB   #2
        STAB   BYTECT    BYTE COUNT
        BSR    BADDR     GET ADDRESS OF BLOCK
LOAD11  BSR    BYTE      GET DATA BYTE
        DEC    BYTECT    DECREMENT BYTE COUNT
        BEQ    LOAD15    DONE WITH THIS BLOCK
        STAB   0,X       STORE DATA
        INX              BUMP POINTER
        BRA    LOAD11    GO BACK FOR MORE
LOAD15  INCA             INCREMENT CHECKSUM
LLOAD   BEQ    LOAD      ALL OK - IT'S ZERO
C1      BRA    CRLF      CHECKSUM ERROR - QUIT
**
* READ BYTE (2 HEX DIGITS)
* INTO B REG
* A IS USED FOR PAPER TAPE CHECKSUM
**
BYTE    BSR    INHEX     GET FIRST HEX DIG
        ASLB             SHIFT TO HIGH ORDER 4 BITS
        ASLB
        ASLB
        ASLB
        ABA              ADD TO CHEKSUM
        STAB   TEMP      STORE DIGIT
        BSR    INHEX     GET 2ND HEX DIG
        ABA              ADD TO CHECKSUM
        ADDB   TEMP      COMBINE DIGITS TO GET BYTE
        RTS              RETURN
**
* READ 16 BIT ADDRESS INTO X
* STORE SAME ADDRESS IN XHI & XLO
* CLOBBERS B REG
**
BADDR   BSR    BYTE      GET HIGH ORDER ADDRESS
        STAB   XHI       STORE IT
        BSR    BYTE      GET LOW ORDER ADDRESS
        STAB   XLOW      STORE IT
        LDX    XHI       LOAD X WITH ADDRESS BUILT
        RTS              RETURN
**
* PRINT BYTE IN A REG
* CLOBBERS B REG
**
OUT2H   TAB              COPY BYTE TO B
        LSRB             SHIFT TO RIGHT
        LSRB
        LSRB
        LSRB
        BSR    OUTHR     OUTPUT FIRST DIGIT
        TAB              BYTE INTO B AGAIN
OUTHR   ANDB   #$F       GET RID OF LEFT DIG
        ADDB   #$30      GET ASCII
        CMPB   #$39
        BLS    OUTCH
        ADDB   #7        IF IT'S A LETTER ADD 7
        NOP              LINE UP OUTCH ENTRY POINTS
        NOP
OUTCH   FCB     $8C      USE CPX SKIP TRICK
OUTS    LDAB   #$20      OUTS PRINTS A SPACE
**
* OUTCH OUTPUTS CHARACTER IN B
**
        PSHB             SAVE CHAR
OUTC1   BSR    POLCAT    ACIA STATUS TO B REG
        ASRB
        BCC    OUTC1     XMIT NOT READY
        PULB             CHAR BACK TO B REG
        STAB   ACIADA    OUTPUT CHARACTER
        RTS
**
* EXAMINE AND DEPOSIT NEXT
* USES CONTENTS OF XHI & XLO AS POINTER
**
NCHANG  LDX    XHI       INCREMENT POINTER
        INX
        STX    XHI
        LDAA   XHI
        BSR    OUT2H     PRINT OUT ADDRESS
        LDAA   XLOW
        BSR    OUT2H
        FCB    $8C       USE CPX SKIP TRICK
**
* EXAMINE & DEPOSIT
**
CHANGE  BSR    BADDR     BUILD ADDRESS
        BSR    OUTS      PRINT SPACE
        LDAA   0,X       BYTE INTO A
        BSR    OUT2H     PRINT BYTE
        BSR    OUTS      PRINT SPACE
        BSR    BYTE      GET NEW BYTE
        STAB   0,X       STORE NEW BYTE
**
* COMMAND DECODING SECTION
**
CRLF    LDS    SAVSTK
        LDAB   #$D       CARRIAGE RETURN
        BSR    OUTCH
        LDAB   #$A       LINE FEED
        BSR    OUTCH
        LDAB   #'.       PROMPT CHARACTER
        BSR    OUTCH
        JSR    INCH      READ CHARACTER
        TBA              MAKE A COPY
        BSR    OUTS      PRINT SPACE
        CMPA   #'L
        BEQ    LLOAD     LOAD PAPER TAPE
        CMPA   #'J
        BNE    NOTJ
        BSR    BADDR     GET ADDRESS TO JUMP TO
        JMP    0,X       JUMP TO IT
NOTJ    CMPA   #'M
        BEQ    CHANGE    EXAMINE & DEPOSIT
        CMPA   #'N
        BEQ    NCHANG    E & D NEXT
        CMPA   #'P
        BNE    CRLF
        RTI              PROCEED FROM BREAKPOINT
**
* RESET ENTRY POINT
**
RESET   LDS    #ECHO     INITIALIZE STACK POINTER
        LDAB   #3        INIT ECHO AND BRKADR FLAGS
        PSHB
        PSHB
        STAB   ACIACS    MASTER RESET ACIA
        LDAB   STRAPS    LOOK AT STRAPS
        BMI    NOTERM    NO TERM - JUMP TO 0
        ANDB   #4        GET # OF STOP BITS
        ORAB   #$D1
        STAB   ACIACS    INIT ACIA PORT
**
* SOFTWARE INTERRUPT ENTRY POINT
**
INTRPT  STS    SAVSTK    SAVE STACK POINTER
        STS    XHI       SAVE SP FOR N COMMAND
        LDAB   BRKADR    IF BIT 7 OF BRKADR IS SET
        BMI    NOTERM    JUMP TO 0
        BRA    CRLF      GOTO COMMAND DECODER
**
* NOW COME THE INTERRUPT VECTORS
**
        ORG    $FFF8
        FDB    MIVEC     MI VECTOR
*        FDB    INTRPT    SWI VECTOR
        FDB    SWIVEC    SWI VECTOR (VECTOR THROUGH $0010)
        FDB    NMIVEC    NMI VECTOR
        FDB    RESET     RESET VECTOR
        END    

