NEW
  AUTO 3,1
*--------------------------------------
*      PR#slot         copy address from OUTVEC,slot to CSW
*      PR#Aaddr        copy Aaddress into CSW
*      PR#slot,Aaddr   copy Aaddress into OUTVEC,slot
*
*      IN#slot         copy address from INVEC,slot to KSW
*      IN#Aaddr        copy Aaddress into KSW
*      IN#slot,Aaddr   copy Aaddress into INVEC,slot
*--------------------------------
PR     LDA #0
       .HS 2C       SKIP NEXT LINE
IN     LDA #2
       PHA          SAVE 0 OR 2
       ASL
       ASL          00 OR 08
       ORA VAL.LB   +SLOT
       ASL          *2
       TAX
       BIT FBITS    WAS SLOT PARAMETER GIVEN?
       BVC .1       ...NO
       LDA FBITS+1  ...YES, WAS A$ PARM ALSO?
       BMI .2       ...YES, SO UPDATE TABLE
       TXA          Check for "PR#0"
       BEQ .4       ...yes, so call MON.SETVID directly
       LDA OUTVEC,X ...NO, ONLY SLOT
       STA VAL.A    SO GET VALUE FROM TABLE
       LDA OUTVEC+1,X
       STA VAL.A+1
.1     JSR CHECK.IO.DRIVER
       BCS .3       ...NOT VALID DRIVER
       PLA          POP SAVED 0 OR 2
       TAX
       LDA VAL.A    INSTALL HOOK FOR DRIVER
       STA CSWL,X
       LDA VAL.A+1
       STA CSWH,X
       RTS
*---ENTER NEW VALUE IN TABLE-----
.2     JSR CHECK.IO.DRIVER
       BCS .3       ...ERROR
       PLA          POP OFF SAVED 0 OR 2
       LDA VAL.A+1  UPDATE TABLE
       STA OUTVEC+1,X
       LDA VAL.A
       STA OUTVEC,X
       RTS
.3     PLA          POP OFF SAVED 0 OR 2
       LDA #$03          "NO DEVICE CONNECTED"
       RTS
*--------------------------------
.4     PLA          POP OFF SAVED 0 OR 2
       JSR MON.SETVID
       CLC
       RTS
*--------------------------------
CHECK.IO.DRIVER
       LDA VAL.A    GET DRIVER ADDRESS INTO PNTR
       STA DRIVER.PTR  
       LDA VAL.A+1
       STA DRIVER.PTR+1
       LDY #0
       CMP #$C0     IS IT IN ROM AREA?
       BCC .3       ...NO
       LDA IO.OFF   ...YES, TURN OFF $C800 SPACE
       STY RETRY.COUNT  
       LDA (DRIVER.PTR),Y CHECK FOR ROM PRESENT
       CMP #$FF
       BEQ .4       ...NOT VALID ROM VALUE
.1     CMP (DRIVER.PTR),Y      BETTER NOT CHANGE...
       BNE .4            ...WOOPS, NOT ROM
       DEC RETRY.COUNT  TRY IT 256 TIMES
       BNE .1       ...AGAIN
.2     CLC          ...REALLY A DRIVER
       RTS
*---VERIFY RAM-BASED DRIVER------
.3     LDA (DRIVER.PTR),Y      GET FIRST BYTE
       CMP #$D8          "CLD" OPCODE?
       BEQ .2            ...YES, VALID DRIVER
.4     SEC
       RTS
*--------------------------------------
MAN
SAVE usr/src/scmasm.30/sci.s.prin
LOAD usr/src/scmasm.30/scmasm.s
ASM
