CP/M 2.2 CONSOLE DRIVERS / IMSAI 8080

VTI.COM and VTI-TB.COM

Puts the CP/M console on a PolyMorphic VTI video card, with either floppy controller.

Console output goes to the VTI as well as the serial terminal, and either keyboard can type. The drivers handle scrolling, CR, LF, BS, TAB, clear screen and ADM-3A ESC = cursor addressing, plus ESC E, H, J and K.

VTI.COM is for the Disk Jockey 2D (the VTI at F800) and VTI-TB.COM for the Tarbell (the VTI at F000). Both are relocatable and check, before installing, that their page is free RAM clear of CP/M, the disk controller and the VTI.

Using it

A>VTI                      the Disk Jockey configuration
A>VTI C000H                install at C000H
A>VTI-TB                   the Tarbell configuration

VTI.ASM

639 LINES
; VTI.ASM - PolyMorphic VTI console driver for CP/M 2.2;            on an IMSAI 8080 with a Morrow Disk Jockey 2D at E000;                       # Created by S.E. Craswell; Run VTI once after booting CP/M.  It copies a small resident driver (398; bytes) into free RAM and points the BIOS console entries at it:;;   CONOUT  writes to the VTI screen as well as the serial terminal;   CONST   reports a key waiting on either the VTI keyboard or the serial port;   CONIN   reads from whichever has a key;;   VTI           installs the driver at 6100H, or at E800H above the Disk;                 Jockey if CP/M reaches 6100H (a 56K CP/M on a 64K IMSAI), or;                 with no RAM there (56K fitted) just below the CCP, where it;                 lowers the BDOS address at 0006 so programs leave it alone;                 (and lowers it again after each warm boot);   VTI 80        installs it at 8000H (any page: VTI C0, VTI C000H, ...);VTIRAM  EQU     0F800H          ; VTI display memory, 1K = 64 x 16VTIEND  EQU     VTIRAM+400HVTIKEY  EQU     0F8H            ; keyboard data port (reading clears the latch)VTISTA  EQU     0F9H            ; keyboard status: bit 0 low = key waitingRESBASE EQU     0DE00H          ; where the resident code is assembled (MAKE.PY varies it)RESLEN  EQU     RESEND-RESBASEDEFPAGE EQU     61H             ; default page: 6100HHIPAGE  EQU     0E8H            ; default for a big CP/M: E800H, above the Disk JockeyCOLS    EQU     64ROWS    EQU     16BLANK   EQU     0A0H            ; a space (bit 7 set selects characters)CURSOR  EQU     00H             ; graphics code with all six blocks litBDOS    EQU     5CONOUT  EQU     2               ; BDOS console outputPRINT   EQU     9               ; BDOS print string        ORG     100HSTART:  LHLD    1               ; HL = BIOS warm boot entry (BIOS+3)        INX     H        INX     H        INX     H               ; HL -> JMP CONST (BIOS+6)        SHLD    TABLE        INX     H        MOV     E,M        INX     H        MOV     D,M        XCHG                    ; HL = where CONST goes now        MOV     A,M             ; this driver's CONST starts IN VTISTA / RAR        CPI     0DBH        JNZ     NOTYET        INX     H        MOV     A,M        CPI     VTISTA        JNZ     NOTYET        INX     H        MOV     A,M        CPI     1FH        JZ      ALREADYNOTYET: LDA     2               ; BIOS page        SUI     16H             ; the CCP starts 1600H below the BIOS        MOV     B,A        LDA     7               ; the top of the TPA (the BDOS, or something below it)        CMP     B        JC      TOPOK        MOV     A,BTOPOK:  STA     TOPPG           ; the driver can go anywhere below this page        CALL    GETPG           ; A = the page asked for        LXI     D,USAGE        JC      SAY        STA     PAGE        LXI     H,ASMPAGE        SUB     M        STA     DELTA        LXI     D,CHECK1        ; say what is happening before touching anything        CALL    PSTR        LDA     PAGE        CALL    PHEX        LXI     D,CHECK2        CALL    PSTR        LDA     PAGE            ; all below the CCP: in the TPA, guarded through 0006        INR     A               ; its last page        MOV     B,A        LDA     TOPPG        CMP     B        JZ      ABOVE        JC      ABOVE        MVI     A,1        STA     GUARDED        JMP     PLACEDABOVE:  LDA     2               ; BIOS page (from the warm boot jump at 0000)        ADI     0DH             ; the BIOS and its buffers end below BIOS+0D00H        MOV     B,A        LDA     PAGE        CMP     B        LXI     D,INCPM        JC      SAY        LXI     D,CLASH        CPI     0FFH        JZ      SAY        INR     A               ; the driver's lst page        CPI     0E0H        JC      PLACED          ; all below the DJ thng        CPI     0F8H        JNC     SAY             ; reaches the VTI        DCR     A        CPI     0E8H        JC      SAY             ; overlaps summutPLACED:        LDA     PAGE        MOV     H,A        MVI     L,0        SHLD    BASE        LXI     B,RESLEN        ; chk ram        CALL    RAMTST        LXI     D,NORAM        JNZ     SAY        LXI     H,VTIRAM        ; chk vti mem?        LXI     B,VTIEND-VTIRAM        CALL    RAMTST        LXI     D,NOVTI        JNZ     SAY        LHLD    RELTAB          ; run wherever unless tbl        MOV     A,H        ANA     L        INR     A        JNZ     COPYIT        LDA     DELTA        ORA     A        LXI     D,NOREL        JNZ     SAYCOPYIT: LHLD    BASE            ; blit code        XCHG        LXI     H,RESIMG        LXI     B,RESLENCOPY:   MOV     A,M        STAX    D        INX     H        INX     D        DCX     B        MOV     A,B        ORA     C        JNZ     COPY        LXI     D,RELTAB        ; add offset to byteRELOOP: XCHG                    ; HL in2 table        MOV     E,M        INX     H        MOV     D,M        INX     H        MOV     A,D        ANA     E        INR     A               ; FFFF ends the table        JZ      HOOKUP        PUSH    H        LHLD    BASE        DAD     D        LDA     DELTA        ADD     M        MOV     M,A        POP     D               ; DE -> table        JMP     RELOOPHOOKUP: LDA     GUARDED         ; in the TPA: 0006 -> the driver's JMP BDOS        ORA     A        JZ      HOOKCB        LHLD    6        XCHG                    ; DE = the BDOS entry        LHLD    BASE        LXI     B,BDOSJ+1-RESBASE        DAD     B        MOV     M,E        INX     H        MOV     M,D        LHLD    BASE        LXI     B,REALBD-RESBASE        DAD     B        MOV     M,E        INX     H        MOV     M,D        LHLD    BASE            ; BDOSJ is the first thing in the driver        SHLD    6HOOKCB: LHLD    TABLE           ; hook cpm calls in2 CONST, CONIN and CONOUT into here        LXI     D,NEWST-RESBASE        LXI     B,OLDST+1-RESBASE        CALL    HOOKR        LXI     D,NEWIN-RESBASE        LXI     B,OLDIN+1-RESBASE        CALL    HOOKR        LXI     D,NEWOUT-RESBASE        LXI     B,OLDOUT+1-RESBASE        CALL    HOOKR        LXI     D,VCLEAR-RESBASE ; CLS        LHLD    BASE        DAD     D        LXI     D,CLEARED        PUSH    D        PCHLCLEARED:        LXI     H,VTIRAM        MVI     M,CURSOR        LXI     D,HELLO1        ; pass 2 driver        CALL    PSTR        LDA     PAGE        CALL    PHEX        LXI     D,HELLO2        CALL    PSTR        LDA     GUARDED        ORA     A        RZ                      ; back to the CCP        LXI     D,TPAMSG        JMP     SAYALREADY:        LXI     D,AGAINSAY:    MVI     C,PRINT        JMP     BDOS            ; BDOS returns to the CCPPSTR:   MVI     C,PRINT        JMP     BDOS; PHEX: prints A as two hex digits.PHEX:   PUSH    PSW        RRC        RRC        RRC        RRC        CALL    PNIB        POP     PSWPNIB:   ANI     0FH        ADI     90H        DAA        ACI     40H        DAA        MOV     E,A        MVI     C,CONOUT        JMP     BDOS; GETPG: the page from the command tail ("61", "6100", "6100H"), or DEFPAGE; (HIPAGE when the CP/M BIOS and its buffers reach DEFPAGE, or just below the; CCP if there is no RAM at HIPAGE); if there is none.  Carry set if it isn't a hex page.GETPG:  LXI     H,80H        MOV     B,M             ; length of the tail        INX     HGP1:    MOV     A,B        ORA     A        JZ      GPDEF        MOV     A,M        CPI     ' '        JNZ     GP2        INX     H        DCR     B        JMP     GP1GPDEF:  LDA     2               ; BIOS page        ADI     0DH             ; where its buffers end, as at NOTYET        CPI     DEFPAGE+1        MVI     A,DEFPAGE        JC      GPRET           ; all below 6100H        LXI     H,HIPAGE*256    ; RAM above the Disk Jockey (64K fitted)?        LXI     B,200H        CALL    RAMTST        MVI     A,HIPAGE        JZ      GPRET        LDA     TOPPG           ; no: the two pages just below the CCP        SUI     2GPRET:  ORA     A        RETGP2:    LXI     D,0             ; DE = the numberGP3:    MOV     A,B        ORA     A        JZ      GPEND        MOV     A,M        CPI     'H'        JZ      GPEND        CPI     ' '        JZ      GPEND        SUI     '0'        RC        CPI     10        JC      GP4        SUI     'A'-'0'-10      ; A-F        CPI     10        RC        CPI     16        CMC        RCGP4:    PUSH    H        XCHG        DAD     H        DAD     H        DAD     H        DAD     H        MOV     E,A        MVI     D,0        DAD     D        XCHG        POP     H        INX     H        DCR     B        JMP     GP3GPEND:  MOV     A,D        ORA     A        MOV     A,E        RZ                      ; up to FF: a page        ORA     A               ; an address tht starts a page        STC        RNZ        MOV     A,D        ORA     A        RET; HOOKR: HOOK with DE and BC given as offsets into the resident code.HOOKR:  PUSH    H        LHLD    BASE        DAD     D        XCHG                    ; DE = the new routine        LHLD    BASE        DAD     B        MOV     B,H        MOV     C,L             ; BC = its OLDxx jump operand        POP     H; HOOK: HL -> a BIOS "JMP target".  Stores the old target at (BC),; jmp to DE instead, and leaves HL ont the next jump.HOOK:   INX     H        MOV     A,M        STAX    B        MOV     M,E        INX     H        INX     B        MOV     A,M        STAX    B        MOV     M,D        INX     H        RET; RAMTST: chcks BC bytes from HL are RAM by writing each complement.RAMTST: MOV     A,M        CMA        MOV     M,A        CMP     M        CMA                     ; (CMA and MOV leave the flags alone)        MOV     M,A        RNZ                     ; not in her dip sht        INX     H        DCX     B        MOV     A,B        ORA     C        JNZ     RAMTST        RETTABLE:  DW      0BASE:   DW      0PAGE:   DB      0DELTA:  DB      0TOPPG:  DB      0GUARDED:DB      0ASMPAGE:DB      HIGH RESBASE    ; the page put resident code was assembled forCHECK1: DB      'VTI: checking for RAM at $'CHECK2: DB      '00H and the VTI at F800H...',13,10,'$'INCPM:  DB      'That is inside the CP/M BIOS and its buffers: pick a higher page.',13,10,'$'CLASH:  DB      'That overlaps the Disk Jockey (E000-E7FF) or the VTI (F800-FBFF).',13,10,'$'NORAM:  DB      'No RAM there for the driver: VTI not installed.',13,10,'$'NOVTI:  DB      'No VTI display memory at F800H: VTI not installed.',13,10,'$'NOREL:  DB      'This VTI.COM has no relocation table: build it with MAKE.PY.',13,10,'$'USAGE:  DB      'Usage: VTI [page], e.g. VTI 80 or VTI 8000H (default 6100H, E800H or below CP/M).',13,10,'$'HELLO1: DB      'PolyMorphic VTI console driver installed at $'HELLO2: DB      '00H.',13,10,'$'TPAMSG: DB      'That is below CP/M, so the TPA now ends there.',13,10,'$'AGAIN:  DB      'The VTI driver is already installed.',13,10,'$'; ---------------------------------------------------------------- resident bitRESIMG:        .PHASE  RESBASE; In the TPA, 0006 points here so programs see a TPA ending below the driver.BDOSJ:  JMP     0               ; the BDOS (filled in when installed); Console status: A = 0FFH if a key is waiting on either keyboard.NEWST:  IN      VTISTA        RAR        JNC     KEYWAITOLDST:  JMP     0               ; serial CONST (filled in when installed)KEYWAIT:        MVI     A,0FFH        RET; Console input: wait for a key from either keyboard.NEWIN:  CALL    GUARDNEWIN1: IN      VTISTA        RAR        JNC     VTIGET        CALL    OLDST        ORA     A        JZ      NEWIN1OLDIN:  JMP     0               ; serial CONIN (filled in when installed)VTIGET: IN      VTIKEY        ANI     7FH        CPI     7FH             ; the Poly keyboard sends DEL for backspace        RNZ        MVI     A,08H        RET; Console output: character -> C, to the VTI -> serial port.NEWOUT: PUSH    B        PUSH    D        PUSH    H        CALL    GUARD        CALL    VOUT        POP     H        POP     D        POP     BOLDOUT: JMP     0               ; serial CONOUT; GUARD: a warm boot points 0006 back at the BDOS; point it at BDOSJ again.; (A program that has moved 0006 itself, like DDT, is left alone.)GUARD:  PUSH    D        PUSH    H        LHLD    6        XCHG        LHLD    REALBD          ; 0 unless the driver is in the TPA        MOV     A,L        CMP     E        JNZ     GDONE        MOV     A,H        CMP     D        JNZ     GDONE        LXI     H,BDOSJ        SHLD    6GDONE:  POP     H        POP     D        RET; VOUT: push the chr in C on the VTI screen.VOUT:   LHLD    CURPOS        LDA     UNDER        MOV     M,A             ; stp cursor        LDA     ESCST        ORA     A        JNZ     ESCSEQ        MOV     A,C        ANI     7FH        CPI     ' '        JC      CONTROL        ORI     80H             ; characters have bit 7 set        MOV     M,A        INX     H        MOV     A,L        ANI     COLS-1        JNZ     VDONE           ; still on the same line        CALL    CHKEND          ; wrapped: ran off the bottom        JMP     VDONECONTROL:        CPI     0DH        JZ      CRET        CPI     0AH        JZ      LFEED        CPI     08H        JZ      BACK        CPI     09H        JZ      TAB        CPI     0CH        JZ      CLEARS        CPI     1AH        JZ      CLEARS        CPI     1BH        JNZ     VDONE           ; forgt evrythng else        MVI     A,1        STA     ESCST        JMP     VDONECRET:   MOV     A,L        ANI     0FFH-(COLS-1)   ; back to col 0        MOV     L,A        JMP     VDONELFEED:  LXI     D,COLS        DAD     D        CALL    CHKEND        JMP     VDONEBACK:   MOV     A,L        ANI     COLS-1        JZ      VDONE           ; already at col 0        DCX     H        JMP     VDONETAB:    MOV     A,L        ANI     COLS-1        CPI     COLS-8        JNC     VDONE           ; no tab stops after col 56        MOV     A,L        ORI     07H        INR     A        MOV     L,A        JMP     VDONECLEARS: CALL    VCLEARHOME:   LXI     H,VTIRAM        JMP     VDONE; Escape sequences: ESCST 1 = after ESC, 2 = waiting for row, 3 = for column.ESCSEQ: CPI     1        JNZ     ESC2        XRA     A        STA     ESCST        MOV     A,C        CPI     '='        JZ      ESCADDR        CPI     'Y'        JZ      ESCADDR        CPI     'E'        JZ      CLEARS        CPI     'H'        JZ      HOME        CPI     'J'        JZ      CLREOS        CPI     'K'        JZ      CLREOL        JMP     VDONEESCADDR:        MVI     A,2        STA     ESCST        JMP     VDONEESC2:   CPI     2        JNZ     ESC3        MOV     A,C        SUI     ' '        STA     ESCROW        MVI     A,3        STA     ESCST        JMP     VDONEESC3:   XRA     A        STA     ESCST        LDA     ESCROW        CPI     ROWS        JNC     VDONE           ; not on the screen        MOV     E,A        MOV     A,C        SUI     ' '        CPI     COLS        JNC     VDONE        MOV     L,E             ; HL = row * 64        MVI     H,0        DAD     H        DAD     H        DAD     H        DAD     H        DAD     H        DAD     H        MOV     E,A             ; + column        MVI     D,0        DAD     D        LXI     D,VTIRAM        DAD     D        JMP     VDONECLREOL: PUSH    HCLR1:   MVI     M,BLANK        INX     H        MOV     A,L        ANI     COLS-1        JNZ     CLR1        POP     H        JMP     VDONECLREOS: PUSH    HCLR2:   MVI     M,BLANK        INX     H        MOV     A,H        CPI     HIGH VTIEND        JNZ     CLR2        POP     H; flag for positionVDONE:  SHLD    CURPOS        MOV     A,M        STA     UNDER        MVI     M,CURSOR        RET; CHKEND: if HL has gone past the last line scrl and move upCHKEND: MOV     A,H        CPI     HIGH VTIEND        RC                      ; still on the screen        PUSH    H        LXI     H,VTIRAM+COLS        LXI     D,VTIRAM        LXI     B,(ROWS-1)*COLSSCROLL: MOV     A,M        STAX    D        INX     H        INX     D        DCX     B        MOV     A,B        ORA     C        JNZ     SCROLL        XCHG                    ; HL is last line        MVI     B,COLSSCRCLR: MVI     M,BLANK        INX     H        DCR     B        JNZ     SCRCLR        POP     H        LXI     D,-COLS        DAD     D        RET; VCLEAR: CLSVCLEAR: LXI     H,VTIRAMVCL1:   MVI     M,BLANK        INX     H        MOV     A,H        CPI     HIGH VTIEND        JNZ     VCL1        LXI     H,VTIRAM        SHLD    CURPOS        MVI     A,BLANK        STA     UNDER        RETCURPOS: DW      VTIRAMUNDER:  DB      BLANKESCST:  DB      0ESCROW: DB      0REALBD: DW      0               ; the BDOS entry 0006 held, when in the TPARESEND:        .DEPHASE; Offsets (from RESBASE) of the address high bytes in the resident code,; ended by 0FFFFH.  MAKE.PY fills this in.RELTAB: DW      0FFFFH        END