home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / ftp.demon.co.uk-pub-cpm / amstrad / uucppcw.com / QTERMRSX.ASM < prev    next >
Assembly Source File  |  1979-11-30  |  7KB  |  383 lines

  1. ; QTERMRSX.ASM - RSX to handle interrupt driven serial I/P for Qterm.com
  2. ; Coding in Philip Wade's VDU program has provided inspiration for this RSX.
  3. ; Coding to send Remote Off if buffer nearly full added 25/04/95
  4. ; Some elements of Z80.LIB imported 24/05/95
  5. ;
  6. ; Stephen Younger - 14th June 1995
  7.  
  8. ; Assemble with RMAC
  9.  
  10. YES    EQU    -1
  11. NO    EQU    0
  12.  
  13. FAXLINK    EQU    NO          ; will be set to YES by QTERMNEW.BAS
  14.                 ;  if required            ~~~~~~~~~~~~
  15. ZMP    EQU    NO        ; set TRUE if RSX is for ZMP, not QTERM
  16. IF FAXLINK            ; Values for Serial ports with Fax link fitted
  17.                 ;                    ~~~~~~~~~~~~~~~
  18. STATP    EQU    0C9H        ; Status channel
  19. DATAP    EQU    0C8H        ; Data channel
  20.  
  21. ELSE                ; Port addresses for CPS8256
  22.  
  23. STATP    EQU    0E1H        ; Status channel
  24. DATAP    EQU    0E0H        ; Data channel
  25.  
  26. ENDIF
  27.  
  28. XOFF    EQU    'S'-40H        ; Remote Off & On
  29. XON    EQU    'Q'-40H
  30.  
  31. SYSINF    EQU    00E6H        ; System information getter
  32. SIPGES    EQU    32        ; No of 256 byte pages in buffer
  33.                 ;  use 8, 16 or 32 * ONLY * (largest
  34.                 ;  buffer gives best results but
  35.                 ;  bulkiest file)
  36.  
  37. ;;    NECESSARY FRAGMENTS OF Z80.LIB FOLLOW
  38.  
  39. ;;    @CHKJ MACRO USED FOR CHECKING RELATIVE JUMPS
  40. ;;
  41. @CHKJ    MACRO    ?DD    ;; USED FOR CHECKING RANGE OF 8-BIT DISP.S
  42.     IF (?DD GT 7FH) AND (?DD LT 0FF80H)
  43.  'RELATIVE JUMP ERROR'
  44.     ENDIF
  45.     ENDM
  46.  
  47. JR    MACRO    ?N
  48.     @CHKJ    ?N-$-1
  49.     DB    18H,?N-$-1
  50.     ENDM
  51. JRC    MACRO    ?N
  52.     @CHKJ    ?N-$-1
  53.     DB    38H,?N-$-1
  54.     ENDM
  55. JRNC    MACRO    ?N
  56.     @CHKJ    ?N-$-1
  57.     DB    30H,?N-$-1
  58.     ENDM
  59. JRZ    MACRO    ?N
  60.     @CHKJ    ?N-$-1
  61.     DB    28H,?N-$-1
  62.     ENDM
  63. JRNZ    MACRO    ?N
  64.     @CHKJ    ?N-$-1
  65.     DB    20H,?N-$-1
  66.     ENDM
  67. DJNZ    MACRO    ?N
  68.     @CHKJ    ?N-$-1
  69.     DB    10H,?N-$-1
  70.     ENDM
  71.  
  72. BC    EQU    0
  73. DE    EQU    2
  74. HL    EQU    4
  75.  
  76. DSBC    MACRO    ?R        ; Covers for - SBC  RR
  77.     DB    0EDH,?R*8+42H    ;  where RR may be BC, DE or HL
  78.     ENDM
  79. OUTI    MACRO        
  80.     DB    0EDH,0A3H
  81.     ENDM
  82. OUTIR    MACRO        
  83.     DB    0EDH,0B3H
  84.     ENDM
  85. OUTP    MACRO    ?R        ; OUT    (C),R
  86.     DB    0EDH,?R*8+41H
  87.     ENDM
  88. RETI    MACRO        
  89.     DB    0EDH,4DH
  90.     ENDM
  91.  
  92. CR    EQU    13
  93. LF    EQU    10
  94.  
  95.     CSEG
  96.     
  97.     ; -----------
  98.     ; RSX Header
  99.     ; -----------
  100.  
  101.     DS    6
  102.     JMP    CPM
  103. CPM:    JMP    $-$
  104. PREV:    DW    $-$
  105. REMOV:    DB    -1        ; Set remove flag on
  106. NBANK:    DB    0        ; shows banked system
  107. IF    ZMP
  108. NAM:    DB    'ZMPRSX  '
  109. ELSE
  110. NAM:    DB    'QTERMRSX'
  111. ENDIF
  112. LOADER:    DB    0
  113. SPARE:    DW    0
  114.  
  115. INIT:    JMP    INI        ; initialize
  116. QUIT:    JMP    QUII        ; and quit
  117.  
  118. JPHL:    PCHL
  119.  
  120. INI:    LHLD    6
  121.     LXI    D,0C100H    ; allow for stack
  122.     ORA    A
  123.     DSBC    DE
  124.     JRNC    INI1
  125.     LXI    D,NOMEM
  126. FAIL:    MVI    C,9
  127.     CALL    CPM
  128.     JMP    0
  129.  
  130. NOMEM:    DB    'Not enough memory',CR,LF,LF,'$'
  131. NOSIO:    DB    ' ERROR: Serial Interface NOT fitted',7,CR,LF,LF,'$'
  132.  
  133. SELMEM:    JMP    $-$
  134.  
  135. INI1:    LHLD    1
  136.     LXI    D,3*(27-1)    ; Selmem offset
  137.     DAD    D
  138.     SHLD    SELMEM+1
  139.     LXI    D,9
  140.     DAD    D
  141.     CALL    JPHL
  142.     DW    SYSINF
  143.     INR    C
  144.     JRZ    INI2
  145.     LXI    D,NOSIO        ; lifted from main program
  146.     JR    FAIL
  147.  
  148. INI2:
  149.     LXI    H,CHRTST    ; covers for ModIst - Modem in state
  150. IF    ZMP
  151.     SHLD    20BH        ; set up call address
  152.     LXI    H,GTCHR
  153.     SHLD    1F0H        ; covers for ModIn
  154. ELSE
  155.     SHLD    111H        ; set up call address
  156.     LXI    H,GTCHR
  157.     SHLD    121H        ; covers for ModIn
  158. ENDIF
  159.     DI
  160.     CALL    SETINT        ; Divert interrupt in bank 1
  161.     XRA    A
  162.     CALL    SELMEM
  163.     DI            ; selmem clears the interrupt
  164.     CALL    SETINT        ; Divert interrupt in bank 0
  165.     MVI    A,1
  166.     CALL    SELMEM
  167. IF FAXLINK
  168.     DI
  169.     LXI    B,0BCBH        ; Reset Channel B
  170.     LXI    H,CHBTAB    ;    ~~~~~~~~~
  171.     OUTIR
  172.     JR    TAKWT
  173.  
  174. CHBTAB:    DB    18h        ; Reset the Channel
  175.     DB    4,0C4h        ; x 64 Clock Mode, 1 Stop bit
  176.     DB    3,0C0h        ; Rx 8 bits/Char
  177.     DB    2,0        ; Set Interrupt Vector to nul
  178.     DB    5,0E0h        ; DTR & 8 bits
  179.     DB    1,4        ; Status Affects Vector
  180.     
  181. TAKWT:    EI
  182.     CALL    InWait
  183. ENDIF        
  184.     RET
  185.  
  186. SETINT:    MVI    A,0DFH        ; is RST 18h
  187.     STA    38H
  188.     LXI    H,18H        ; RST 18h Address
  189.     LXI    D,GTSIX
  190.     MVI    M,0C3H        ; jump op
  191.     INX    H
  192.     MOV    M,E
  193.     INX    H
  194.     MOV    M,D
  195.     RET
  196.  
  197. QUII:    DI
  198.     LXI    H,38H
  199.     MVI    M,0C3H        ; restore normal interrupt
  200.     XRA    A
  201.     CALL    SELMEM
  202.     DI
  203.     MVI    M,0C3H        ; in both banks
  204.     MVI    A,1
  205.     CALL    SELMEM        ; back to TPA
  206. IF    FAXLINK
  207.     DI
  208.     MVI    A,1        ; Select Reg 1
  209.     OUT    0C9h
  210.     XRA    A        ; Clear WR1
  211.     OUT    0C9h
  212.     INR    A
  213.     OUT    0CBh
  214.     XRA    A
  215.     OUT    0CBh        ; Clear Stat Reg 1
  216.     EI
  217. ENDIF
  218.     RET
  219.  
  220. GTSIX:                ; Read a Char to store in Buffer
  221.     PUSH    PSW
  222.     IN    STATP
  223.     RAR            ; Has a '1'?
  224.     JRC    GTSI00        ; if the jump fails, use of relative jump
  225.     LDA    WAIBYT        ;  is quicker
  226.     ORA    A
  227.     JRZ    GTSIX1
  228.     DCR    A
  229.     STA    WAIBYT
  230. GTSIX1:    POP    PSW
  231.     XTHL
  232.     LHLD    039H        ; go directly to normal interrupt address
  233.     XTHL
  234.     RET
  235.  
  236. GTSI00:
  237. IF FAXLINK
  238.  
  239.     MVI    A,2        ; Look at Modified Interrupt Vector
  240.     OUT    0CBh
  241.     IN    0CBh
  242.     ANI    6        ; Will return '4' if byte to deliver
  243.     JRZ    GTSI02
  244.     RRC
  245.     DCR    A
  246.     JRZ    GTSI01
  247.     DCR    A
  248.     JRZ    GTSIA
  249.     MVI    A,30h        ; Error Reset
  250.     OUT    0C9h
  251.     OUT    0C9h
  252.     IN    0C8h
  253.     JR    GTSI04
  254.  
  255. GTSI01:    MVI    A,10h        ; Reset Ext/Status Interrupts
  256.     OUT    0C9h
  257.     OUT    0C9h
  258.     JR    GTSI04
  259.  
  260. GTSI02:    MVI    A,10h        ; Reset Ext/Status Interrupts
  261.     OUT    0C9h
  262.     OUT    0C9h
  263.     MVI    A,28h        ; Reset Tx Int Pending
  264.     OUT    0C9h
  265.     OUT    0C9h
  266.  
  267. ELSE
  268.     JR    GTSIA
  269. ENDIF
  270.  
  271. GTSI04:    MVI    A,38h        ; Return from Interrupt
  272.     OUT    STATP
  273.     POP    PSW
  274.     XTHL
  275.     POP    H
  276.     EI
  277.     RETI
  278.  
  279. GTSIA:    PUSH    D
  280.     PUSH    H
  281. GTSIA1:    IN    DATAP
  282.     LHLD    BUFWT        ; get addr to put byte
  283.     MOV    M,A
  284.     LXI    D,BUFBAS-1    ; bump address
  285.     ORA    A
  286.     DSBC    DE
  287.     MOV    A,H
  288.     ANI    SIPGES-1    ; set buffer limit
  289.     MOV    H,A
  290.     INX    D        ; Set DE to BUFBAS
  291.     DAD    D
  292.     SHLD    BUFWT        ; and store address for next write
  293.     LHLD    BUFCNT
  294.     INX    H        ; bump buffer count
  295.     SHLD    BUFCNT
  296.     LDA    XOFFFG        ; Test for impending overflow
  297.     ORA    A
  298.     JRNZ    GTSIB
  299.     LDA    BUFCNT+1
  300.     CPI    SIPGES-8
  301.     JRC    GTSIB        ; if few spare pages left
  302.     MVI    A,XOFF        ; send XOFF
  303.     CALL    CHRSND
  304.     MVI    A,-1
  305.     STA    XOFFFG        ; and set flag
  306. GTSIB:    IN    STATP
  307.     RAR            ; Char ready?
  308.     JRC    GTSIA1        ; Loop back for any more
  309.     POP    H
  310.     POP    D
  311.     JR    GTSI04
  312.  
  313. CHRTST:                ; Test for Char Ready
  314.     LHLD    BUFCNT        ; Anything to lift?
  315.     MOV    A,H
  316.     ORA    L
  317.     RET
  318. GTCHR:                ; Get Char from buffer
  319.     LDA    XOFFFG
  320.     ORA    A
  321.     JZ    GTCHR1
  322.     LDA    BUFCNT+1
  323.     CPI    SIPGES/8
  324.     JNC    GTCHR1
  325.     MVI    A,XON        ; re-start flow
  326.     CALL    CHRSND
  327.     XRA    A
  328.     STA    XOFFFG        ; flag off
  329. GTCHR1:    DI
  330.     LHLD    BUFCNT        ; Anything to lift?
  331.     MOV    A,H
  332.     ORA    L
  333.     JZ    GTCHR3        ; quit if not
  334.     DCX    H        ; bump down contents
  335.     SHLD    BUFCNT
  336.     EI
  337.     LHLD    BUFRD        ; get read address
  338.     MOV    A,M
  339.     PUSH    PSW
  340.     LXI    D,BUFBAS-1    ; bump address
  341.     ORA    A
  342.     DSBC    DE
  343.     MOV    A,H
  344.     ANI    SIPGES-1    ; set buffer limit
  345.     MOV    H,A
  346.     INX    D
  347.     DAD    D
  348.     SHLD    BUFRD        ; store address for next read
  349.     POP    PSW
  350. GTCHR3:    EI
  351.     RET
  352.  
  353. CHRSND:                ; SEND A CHAR
  354.     PUSH    PSW
  355. CHRSN1:    IN    STATP
  356.     ANI    4
  357.     JZ    CHRSN1
  358.     POP    PSW
  359.     OUT    DATAP
  360.     RET
  361.  
  362. InWait:    PUSH    PSW        ; Count off 30 Interrupts
  363.     PUSH    H
  364.     LXI    H,WAIBYT
  365.     MVI    M,30
  366. InWt01:    MOV    A,M
  367.     ORA    A
  368.     JNZ    InWt01
  369.     POP    H
  370.     POP    PSW
  371.     RET
  372.  
  373. XOFFFG:    DB    0        ; Set true if Remote Off called
  374. WAIBYT:    DB    0        ; Used to allow DART to settle?
  375. BUFCNT:    DW    0        ; No. of bytes in buffer
  376. BUFWT:    DW    BUFBAS        ; Address of SI byte written to buffer
  377. BUFRD:    DW    BUFBAS        ;     "    "    read from buffer
  378.  
  379. BUFBAS    EQU    $        ; buffer origin
  380. BUFFER:    DS    (SIPGES*256)
  381.  
  382. END
  383.  in Philip Wade's VDU program has provided ins