home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol135 / extcom1.asm < prev    next >
Encoding:
Assembly Source File  |  1984-04-29  |  4.8 KB  |  150 lines

  1. ;MODEM PORT EQUATES
  2. MDATA   EQU     4               ;Modem data port
  3. MSTAT   EQU     5               ;Modem status port
  4. MCNTR   EQU     5               ;Modem control port
  5. MOMASK  EQU     1               ;Mask for input available
  6. MIMASK  EQU     2               ;Mask for output posible
  7. RESET   EQU     01000000B       ;Value for port reset
  8. MINIT1  EQU     01001111B       ;Modem initialise value
  9. MINIT2  EQU     00010101B       ; and second one
  10. PINIT1  EQU     01001110B       ;Printer initialise value
  11. PINIT2  EQU     00010101B       ; and second one
  12.  
  13. ;CP/M EQUATES
  14. BASE    EQU     0               ;Start of CP/M
  15. BDOS    EQU     BASE+5          ;OS calls
  16. CCP    EQU    0C000H        ;Console Command Processor address
  17. BIOS    EQU    0D600H        ;Basic I/O, first vector.
  18. TPA    EQU    0100H        ;Start or programs
  19. CONS    EQU     6               ;Direct console output
  20. PRINT    EQU    9        ;Print string
  21. ESC     EQU     27
  22.  
  23.  
  24.  
  25.     ORG    TPA
  26.     LXI    D,ACTIV
  27.     MVI    C,PRINT
  28.     CALL    BDOS        ;Print a message
  29.  
  30.     LHLD    BASE+6        ;Get BDOS vector and save it
  31.     SHLD    BDOSTP        ; for later if needed
  32.     LXI    H,STARTR    ;Protect memory - this will always
  33.     SHLD    BASE+6        ; happen after a warm boot
  34.  
  35.     LHLD    BIOS+09H+1    ;Check if already installed
  36.     MOV    A,H
  37.     CPI    CONSIN/256    ;Is jump already in?
  38.     RZ            ;Return to CP/M, hope that code
  39.                 ; is still sitting under CCP as
  40.                 ; no way of knowing where the
  41.                 ; vector is supposed to go
  42.     LXI    H,ENDP+1
  43.     LXI    D,STARTR
  44.     LXI    B,ENDR-STARTR
  45. MOVLOP: MOV    A,M        ;Move routine up there
  46.     STAX    D
  47.     INX    H
  48.     INX    D
  49.     DCX    B
  50.     MOV    A,B
  51.     ORA    C
  52.     JNZ    MOVLOP
  53.  
  54.     LHLD    BDOSTP        ;Get saved BDOS vector
  55.     SHLD    STARTR+1    ;Install it
  56.  
  57.     LHLD    BIOS+09H+1    ;Console input vector
  58.     SHLD    CONSIN+1    ;Save in my prog
  59.     LXI    H,CONSIN
  60.     SHLD    BIOS+09H+1    ;Trap calls to here
  61.  
  62.     RET            ;Return to CP/M
  63.         ;THIS MUST NOT BE A WARM BOOT. The reason is
  64.         ; because this program does not worry about
  65.         ; warm boots, hence should have this as an
  66.         ; auto-execute command. If we booted here
  67.         ; and have auto command , hey presto endless
  68.         ; loop !!
  69. ACTIV:    DT    '(EXTCOM active)$'
  70. BDOSTP:    DW    0        ;Temporary storage for BDOS vector
  71.  
  72. ENDP:    DB    0
  73.     ORG    CCP-100H    ;256 bytes of room
  74. STARTR: DB    0C3H
  75.     DW    0
  76. CONSIN: DB    0CDH        ;CALL = back here when
  77.     DW    0        ;    done
  78.     PUSH    PSW        ;Save status from routine
  79.     ORA    A        ; ^@ is go to extcom
  80.     JZ    EXTCOM
  81.     POP    PSW
  82.     RET            ;Back to wherever...
  83.  
  84.  
  85. EXTCOM:     LXI    H,STARTR-1
  86.         SPHL            ;Move to a new stack
  87.         LXI    D,SIGNON
  88.         MVI    C,PRINT
  89.         CALL    BDOS
  90.  
  91.         CALL    INITIALISE
  92. START:          CALL    GETCHAR
  93.                 CNZ     PUTMOD
  94.                 CALL    GETMOD
  95.                 CNZ     PUTCHAR
  96.                 JMP     START
  97.  
  98.  
  99. INITIALISE:     MVI     A,RESET         ;Set up the port for modem
  100.                 OUT     MCNTR           ;operation. Form : 8 data bits
  101.                 MVI     A,MINIT1        ;                  1 stop bit
  102.                 OUT     MCNTR           ;                  no parity
  103.                 MVI     A,MINIT2        ;                  300 baud
  104.                 OUT     MCNTR
  105.                 RET
  106.  
  107. GETCHAR:        MVI     C,CONS          ;Console I/O function
  108.                 MVI     E,0FFH          ;Requesting input
  109.                 CALL    BDOS
  110.                 ORA     A               ;If A=0, no character
  111.                 RZ
  112.         CPI    ESC        ;Check for ESCape
  113.                 RNZ
  114.                 MVI     A,RESET         ;Set up port for printer
  115.                 OUT     MCNTR           ;operation. Form : 8 data bits
  116.                 MVI     A,PINIT1        ;                  1 stop bit
  117.                 OUT     MCNTR           ;                  no parity
  118.                 MVI     A,PINIT2        ;                  1200 baud
  119.                 OUT     MCNTR           ;
  120.                 JMP     BASE            ;Back to CP/M
  121.  
  122. PUTMOD:         STA     TEMP            ;Save character..
  123.                 MVI     B,100           ;Initialise counter
  124. NEXTLOOP:       DCR     B               ;Drop counter. Finished ?
  125.                 RZ                      ;Go back if we are
  126.                 IN      MSTAT           ;Get modem status
  127.                 ANI     MOMASK          ;Is it ready ?
  128.                 JZ      NEXTLOOP        ;No, try again
  129.                 LDA     TEMP            ;Get chararacter back
  130.                 OUT     MDATA           ;Send it
  131.                 RET                     ;Lets go back
  132. TEMP:           DB      0               ;Temporary storage
  133.  
  134. GETMOD:         IN      MSTAT           ;Get status
  135.                 ANI     MIMASK          ;Is it ready ?
  136.                 RZ                      ;Go back if not
  137.                 IN      MDATA
  138.                 ORA     A               ;Reset Z flag
  139.                 RET
  140.  
  141. PUTCHAR:        ANI     07FH            ;Strip any high bits
  142.                 MOV     E,A             ;Move char to output
  143.                 MVI     C,CONS          ;Function: direct I/O
  144.                 CALL    BDOS            ;Display it.
  145.                 RET
  146. SIGNON:     DT    'EXTernal COMunications...(300 baud)...'
  147.         DW    0A0DH
  148.         DB    '$'
  149. ENDR:        DB    0
  150.