home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / COMMS / ZMP-OV16.ARC / ZMO-TV03.Z80 < prev    next >
Text File  |  1991-02-02  |  14KB  |  734 lines

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ;
  4. ;    Overlay for ZMP (Z-Modem Program)
  5. ;
  6. ;    Name    ZMO-TV03.Z80
  7. ;
  8. ;    Dated   10 Nov 1988
  9. ;
  10. ;    Written by -
  11. ;      Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia.
  12. ;         Modified for Televideo TS80x(H) by Michael Evenson, sysop, 680x0
  13. ;        flags must be set for Televideo TS806, TS816, or TS802(H)
  14. ;        currently does not support TS803 (STI) or TS804 (MPM system)
  15. ;
  16. ;    Rename subsequent versions as ZMO-TVxx.Z80 etc
  17. ;
  18. ;
  19. ;    This overlay is set up for Televideo using modem port.
  20. ;     Uses a Z80SIO AND A Z80CTC.
  21. ;
  22. ;-----------------------------------------------------------------------------
  23. ;
  24. ;
  25. ;    System-dependent code overlay for ZMODEM
  26. ;
  27. ;
  28. ;    Insert your own code as necessary in this file. Code contained herein
  29. ; has been written in Z80 code for use with M80 or SLR. Assemble as follows:
  30. ;
  31. ;    SLR ZMO-TVxx/h
  32. ;    MLOAD ZMP.COM=ZMPX.COM,ZMO-TVxx.HEX
  33. ; or
  34. ;    M80 =ZMO-TVxx.Z80
  35. ;    RELHEX ZMO-TVxx
  36. ;    MLOAD ZMP.COM=ZMPX.COM,ZMO-TVxx.HEX
  37. ;
  38. ;
  39. ;       (Don't use L80 without changing the source for assembly as a
  40. ;         cseg file.)
  41. ;
  42. ;-----------------------------------------------------------------------------
  43. ;
  44. ; Notes on modifying this file:
  45. ;
  46. ;    C requires that functions do not change either index register
  47. ; (IX or IY), nor the BC register pair. If your overlay requires any of
  48. ; these to be changed, ensure they are restored to the original values
  49. ; on return.
  50. ;    Since collecting parameters from C functions can be tricky, only change
  51. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  52. ; table at the start. Do NOT modify the entry/exit sections of each
  53. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  54. ;    Apart from defining modem functions, this file also defines terminal
  55. ; characteristics. Most have been set up for ADM-3A (with a few of my own
  56. ; additions). Modify to suit your own terminal. An inline print routine
  57. ; is provided for printing strings in the usual way: usage is
  58. ;
  59. ;    call    print
  60. ;    db    'required string',0
  61. ;
  62. ;-----------------------------------------------------------------------------
  63. ;
  64. ;
  65. ;    Don't forget to set your clock speed at the clkspd variable.
  66. ;
  67. ;
  68. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  69. ; you will have to contact me for another version. If too many people need 
  70. ; to do it, we haven't allowed enough room.
  71. ;
  72. ; Ron Murray 15/8/88
  73. ;
  74. ;
  75. ;
  76. ;
  77. ;
  78. ;
  79. ;
  80. ;
  81. ;
  82. ;-----------------------------------------------------------------------------
  83.  
  84. false    equ    0
  85. true    equ    not false
  86.  
  87.  
  88. ; User-set variables: ***********
  89.  
  90. clkspd    equ    4        ; Processor clock speed in MHz
  91.  
  92. debug    equ    false
  93.  
  94. userdef    equ    00145h        ; origin of this overlay
  95.                 ; This address should remain constant
  96.                 ; with subsequent revisions.
  97.  
  98. ; NOT user-set variables
  99. mspeed    equ    003ch        ; current baud rate id
  100. ovsize    equ    0400h        ; max size of this overlay
  101.  
  102.     .z80            ; use z80 code
  103.     aseg            ; absolute
  104.  
  105.      if    debug
  106.     org    100h        ; so you can debug it with cebug, zsid, etc
  107.      else
  108.     org    userdef
  109.      endif
  110.  
  111. ;    be sure to set the correct system and port identifier here
  112. ;        (only one of each please)
  113.  
  114. TS802    equ    true
  115. TS806    equ    false
  116. TS816    equ    false
  117.  
  118. MODEMP    equ    true
  119. PRINTP    equ    false
  120.  
  121. ;
  122.  
  123. esc    equ    1bh
  124. ctrlq    equ    11h
  125. cr    equ    0dh
  126. lf    equ    0ah
  127. bdos    equ    5
  128.  
  129.  
  130. ; Televideo specific equates  ******************************************
  131.  
  132.      if    TS802
  133.       if    MODEMP
  134. mdata    equ    020h
  135. mstat    equ    022h
  136. ctc    equ    08h
  137.       else
  138. mdata    equ    021h
  139. mstat    equ    023h
  140. ctc    equ    09h
  141.      endif
  142.  
  143.      else
  144.  
  145.       if    TS806
  146.        if    MODEMP
  147. mdata    equ    050h
  148. mstat    equ    052h
  149. ctc    equ    80h
  150.        else
  151. mdata    equ    051h
  152. mstat    equ    053h
  153. ctc    equ    81h
  154.        endif
  155.       else
  156.        if    TS816
  157.         if    MODEMP
  158. mdata    equ    059h        ; channel B
  159. mstat    equ    05Bh
  160. ctc    equ    C1h        ; CTC 1
  161.         else
  162. mdata    equ    058h        ; channel A
  163. mstat    equ    05Ah
  164. ctc    equ    C0h        ; CTC 0
  165.         endif
  166.        endif
  167.       endif
  168.      endif
  169.  
  170. rda    equ    0
  171. tbe    equ    2
  172. mode    equ    47h
  173. onhook    equ    7Fh
  174. online    equ    80h
  175. error    equ    70h
  176. break    equ    0F8h
  177. reset    equ    30h
  178. ;            ******************************************
  179.  
  180. ; Main code starts here
  181.  
  182. codebgn    equ    $
  183.  
  184. ;Jump table for the overlay: do NOT change this
  185. jump_tab:
  186.     jp    scrnpr        ; screen print
  187.     jp    mrd        ; modem read with timeout
  188.     jp    mchin        ; get a character from modem
  189.     jp    mchout        ; send a character to the modem
  190.     jp    mordy        ; test for tx buffer empty
  191.     jp    mirdy        ; test for character received
  192.     jp    sndbrk        ; send break
  193.     jp    cursadd        ; cursor addressing
  194.     jp    cls        ; clear screen
  195.     jp    invon        ; inverse video on
  196.     jp    invoff        ; inverse video off
  197.     jp    hide        ; hide cursor
  198.     jp    show        ; show cursor
  199.     jp    savecu        ; save cursor position
  200.     jp    rescu        ; restore cursor position
  201.     jp    mint        ; service modem interrupt
  202.     jp    invec        ; initialise interrupt vectors
  203.     jp    dinvec        ; de-initialise interrupt vectors
  204.     jp    mdmerr        ; test uart flags for error
  205.     jp    dtron        ; turn DTR on
  206.     jp    dtroff        ; turn DTR OFF
  207.     jp    init        ; initialise uart
  208.     jp    wait        ; wait seconds
  209.     jp    mswait        ; wait milliseconds
  210.     jp    userin        ; user-defined entry routine
  211.     jp    userout        ; user-defined exit routine
  212.  
  213. ;Spare jumps for compatibility with future versions
  214.     jp    spare        ; spares for later use
  215.     jp    spare        ; spares for later use
  216.     jp    spare        ; spares for later use
  217.     jp    spare        ; spares for later use
  218.     jp    spare        ; spares for later use
  219.  
  220. spare:    ret
  221.  
  222. ;-------------------------------------------------------------------------
  223.  
  224.  
  225. ;Screen print function
  226. scrnpr:
  227.                 ; <== Insert your own code here
  228.     call    print
  229.     db    'This function not supported.',cr,lf,0
  230.                 ; <== End of your own code
  231.     ret
  232.  
  233.  
  234. ;Get a character from the modem: return in HL
  235. mchin:
  236.     push    bc
  237.                 ; <== Insert your own code here
  238.  
  239. mchin2:
  240.     in    a,(mstat)    ; check for char waiting
  241.     bit    rda,a
  242.     jr    z,mchin2
  243.  
  244.     in    a,(mdata)    ; read the char
  245.  
  246.  
  247.                 ; <== End of your own code
  248.  
  249.  
  250.     ld    l,a        ; put in HL
  251.     ld    h,0
  252.     or    a        ; set/clear Z
  253.     pop    bc
  254.     ret
  255.  
  256. ;Send a character to the modem
  257. mchout:
  258.     ld    hl,2        ; get the character
  259.     add    hl,sp
  260.     ld    a,(hl)
  261.                 ; <== Insert your own code here
  262.  
  263.     push    bc
  264.     ld    b,a        ; save the char
  265.  
  266. mchout2:
  267.     in    a,(mstat)    ; check for uart ready
  268.     bit    tbe,a
  269.     jr    z,mchout2
  270.  
  271.     ld    a,b        ; char in a
  272.     out    (mdata),a    ; send it
  273.     pop    bc
  274.  
  275.                 ; <== End of your own code
  276.     ret            ; done
  277.  
  278. ;Test for output ready: return TRUE (1) in HL if ok
  279. mordy:
  280.                 ; <== Insert your own code here
  281.  
  282.     ld    hl,0
  283.     in    a,(mstat)
  284.     bit    tbe,a        ; transmit buffer empty
  285.     jr    z,mordy1
  286.     inc    hl
  287. mordy1:
  288.  
  289.                 ; <== End of your own code
  290.  
  291.     ld    a,l        ; set/clear Z
  292.     or    a
  293.     ret
  294.  
  295. ;Test for character at modem: return TRUE (1) in HL if so
  296. mirdy:
  297.                 ; <== Insert your own code here
  298.  
  299.     ld    hl,0
  300.     in    a,(mstat)
  301.     bit    rda,a        ; received data available
  302.     jr    z,mirdy1
  303.     inc    hl
  304. mirdy1:
  305.  
  306.                 ; <== End of your own code
  307.     ld    a,l        ; set/clear Z
  308.     or    a
  309.     ret
  310.  
  311. ;Send a break to the modem: leave empty if your system can't do it
  312. sndbrk:
  313.                 ; <== Insert your own code here
  314.     ld    a,5
  315.     out    (mstat),a
  316.     ld    a,break        ; F8
  317.     out    (mstat),a
  318.  
  319.     ld    hl,300        ; wait 300 mS
  320.     call    waithlms
  321.  
  322.     ld    a,5
  323.     out    (mstat),a
  324.     ld    a,online    ; 68
  325.     out    (mstat),a
  326.  
  327.     ld    a,3
  328.     out    (mstat),a
  329.     ld    a,0E1h
  330.     out    (mstat),a    ; E1
  331.  
  332.                 ; <== End of your own code
  333.     ret
  334. ;
  335. ;Test UART flags for error: return TRUE (1) in HL if error.
  336. mdmerr:
  337.                 ; <== Insert your own code here
  338.     ld    hl,0
  339.     in    a,(mstat)
  340.     and    error
  341.     jr    z,mdmer2
  342.     inc    hl
  343. mdmer2:
  344.                 ; <== End of your own code
  345.     ld    a,l        ; set/clear Z
  346.     or    a
  347.     ret
  348.  
  349.  
  350.  
  351. ;Turn DTR ON
  352. dtron:
  353.                 ; <== Insert your own code here
  354.     ld    a,5
  355.     out    (mstat),a
  356.  
  357.     ld    a,(combyt)    ; get the one we used last time
  358.     or    online        ; 80h - set bit 7 high
  359.     ld    (combyt),a    ; save it for next time
  360.     out    (mstat),a    ; go
  361.  
  362.                 ; <== End of your own code
  363.     ret
  364.  
  365.  
  366.  
  367. ;Turn DTR OFF
  368. dtroff:
  369.                 ; <== Insert your own code here
  370.  
  371.     ld    a,5
  372.     out    (mstat),a
  373.  
  374.     ld    a,(combyt)    ; get the one we used last time
  375.     and    onhook        ; 7Fh - clear bit 7
  376.     ld    (combyt),a    ; save it for next time
  377.     out    (mstat),a    ; go
  378.  
  379.                 ; <== End of your own code
  380.     ret
  381.  
  382.  
  383.  
  384. ;Initialise the SIO +++
  385. ; The SIO is set up in four steps:
  386. ;     1)  Reset
  387. ;       2)  Reg 4 - clock, stop bits, parity
  388. ;    3)  Reg 5 - dtr, Tx bits, Brk, TxEn, rts
  389. ;    4)  Reg 3 - Rx bits, RxEn
  390.  
  391. init:
  392.  
  393.     ld    hl,2        ; get parameters
  394.     add    hl,sp
  395.     ex    de,hl
  396.     call    getparm        ; in HL
  397.     ld    (brate),hl    ; baud rate
  398.     call    getparm
  399.     ld    (parity),hl    ; parity
  400.     call    getparm
  401.     ld    (data),hl    ; data bits
  402.     call    getparm
  403.     ld    (stop),hl    ; stop bits
  404.  
  405.  
  406.                 ; <== Insert your own code here
  407.                 ; using values below
  408.  
  409.     push    bc
  410.  
  411.     ld    a,0
  412.     out    (mstat),a    ; point to reg 0
  413.     ld    a,18h        ; reset
  414.     out    (mstat),a    ;                *** step 1
  415.  
  416.     ld    a,4        ; point to wrt reg 4
  417.     out    (mstat),a
  418.     ld    e,44h        ; assume  x16, 1 stop, No parity
  419.     ld    a,(stop)    ; set stop bits
  420.     cp    2        ; set 2 if required
  421.     jr    nz,setpar
  422.     set    3,e
  423.  
  424. setpar:
  425.     ld    a,(parity)    ; set parity bits
  426.     cp    'O'
  427.     jr    nz,setpa2
  428.     set    0,e        ; ODD
  429.     jr    setpa3
  430.  
  431. setpa2:    cp    'E'
  432.     jr    nz,setpa3
  433.     set    0,e
  434.     set    1,e        ; EVEN
  435.  
  436. setpa3:    ld    a,e
  437.     out    (mstat),a    ;                *** step 2
  438.  
  439.  
  440.  
  441.     ld    a,5        ; point to wrt reg 5 - dtr, Tx bits, etc
  442.     out    (mstat),a
  443.     ld    e,0EAh        ; assume dtr, TX 8 bits, TxEn, rts
  444.     ld    a,(data)
  445.     cp    7
  446.     jr    nz,setbi2
  447.     res    6,e        ; 7 bits
  448.  
  449. setbi2:    ld    a,e
  450.     out    (mstat),a    ;                *** step 3
  451.     
  452.     ld    a,3        ; point to wrt reg 3
  453.     out    (mstat),a
  454.     ld    e,0C1h        ; assume 8 bits
  455.     ld    a,(data)
  456.     cp    7
  457.     jr    nz,setbi3
  458.     res    7,e        ; 7 bits
  459.  
  460. setbi3:    ld    a,e
  461.     out    (mstat),a    ;                *** step 4
  462.  
  463.  
  464. setbrate:
  465.     ld    de,(brate)    ; get baud rate value (0-10)
  466.     ld    hl,brval
  467.     add    hl,de
  468.     ld    a,(hl)        ; get value from table
  469.     or    a        ; 0 = not valid
  470.     jr    z,setbrx    ; so quit
  471.     ld    a,mode        ; 47h
  472.     out    (ctc),a        ; select the correct timer and mode of the CTC
  473.     ld    a,(hl)        ; then get value back
  474.     out    (ctc),a        ; do it
  475.     ld    a,(brate)
  476.     ld    (mspeed),a    ; tell zmp it's ok
  477. setbrx:
  478.     pop    bc
  479.     ret
  480.  
  481.  
  482.  
  483. brate:    dw    7        ; baud rate:
  484. parity:    dw    'N'        ; parity
  485. data:    dw    8        ; data bits
  486. stop:    dw    1        ; stop bits
  487. combyt:    db    0EAh        ; save it here
  488.  
  489. ;Values for Z80CTC control reg for each baud rate: 0 if invalid
  490. brval:
  491.     db     0    ;   110        0
  492.     db    80h    ;   300        1
  493.     db     0    ;   450        2
  494.     db    40h    ;   600        3
  495.     db     0    ;   710        4
  496.     db    20h    ;  1200        5
  497.     db    10h    ;  2400        6
  498.     db    08h    ;  4800        7
  499.     db    04h    ;  9600        8
  500.     db    02h    ; 19200        9
  501.     db    0    ; 38400           10
  502.     db    0    ; 57600           11
  503.     db    0    ; 76800           12
  504.  
  505. ;****************************************************************************
  506. ;Video terminal sequences: these are for Televideo TS950: Modify as you wish
  507. ;Cursor addressing: 
  508. cursadd:
  509.     ld    hl,2        ; get parameters
  510.     add    hl,sp
  511.     ex    de,hl
  512.     call    getparm        ; in HL
  513.     ld    (row),hl    ; row
  514.     call    getparm
  515.     ld    (col),hl    ; column
  516.                 ; <== Insert your own code here
  517.                 ; using values in row and col
  518.     call    print
  519.     db    esc,'=',0    ; ADM-3A leadin
  520.     ld    a,(row)        ; row first
  521.     add    a,' '        ; add offset
  522.     call    cout
  523.     ld    a,(col)        ; sane for column
  524.     add    a,' '
  525.     call    cout
  526.                 ; <== end of your own code
  527.     ret
  528.  
  529. row:    ds    2        ; row
  530. col:    ds    2        ; column
  531.  
  532.  
  533. ;Clear screen:
  534. cls:
  535.     call    print
  536.     db    esc,'*',0
  537.     ret
  538.  
  539. ;Inverse video on:
  540. invon:
  541.     call    print
  542.     db    esc,'G4',0
  543.     ret
  544.  
  545. ;Inverse video off:
  546. invoff:
  547.     call    print
  548.     db    esc,'G0',0
  549.     ret
  550.  
  551. ;Turn off cursor:
  552. hide:
  553.     call    print
  554.     db    esc,'.1',0
  555.     ret
  556.  
  557. ;Turn on cursor:
  558. show:
  559.     call    print
  560.     db    esc,'.2',0
  561.     ret
  562.  
  563. ;Save cursor position:
  564. savecu:
  565.     ret
  566.  
  567. ;Restore cursor position:
  568. rescu:
  569.     ret
  570.  
  571. ;User-defined entry routine: leave empty if not used
  572. userin:
  573.     ret
  574.  
  575. ;User-defined exit routine: leave empty if not used
  576. userout:
  577.     ret
  578.  
  579.  
  580. ;****************************************************************************
  581.  
  582. ;Service modem interrupt:
  583. mint:
  584.     ret            ; my system doesn't need this
  585.  
  586. ;Initialise interrupt vectors:
  587. invec:
  588.     ret            ; ditto
  589.  
  590. ;De-initialise interrupt vectors:
  591. dinvec:
  592.     ret            ; ditto
  593.  
  594. ;****************** End of user-defined code ********************************
  595. ;        Do not change anything below here.
  596.  
  597. ;Modem character test for 100 ms
  598. mrd:
  599.     push    bc        ; save bc
  600.     ld    bc,100        ; set limit
  601. mrd1:
  602.     call    mirdy        ; char at modem?
  603.     jr    nz,mrd2        ; yes, exit
  604.     ld    hl,1        ; else wait 1ms
  605.     call    waithlms
  606.     dec    bc        ; loop till done
  607.     ld    a,b
  608.     or    c
  609.     jr    nz,mrd1
  610.     ld    hl,0        ; none there, result=0
  611.     xor    a
  612. mrd2:
  613.     pop    bc
  614.     ret
  615.  
  616. ; Inline print routine: destroys A and HL
  617.  
  618. print:
  619.     ex    (sp),hl        ; get address of string
  620. ploop:
  621.     ld    a,(hl)        ; get next
  622.     inc    hl        ; bump pointer
  623.     or    a        ; done if zero
  624.     jr    z,pdone
  625.     call    cout        ; else print
  626.     jr    ploop        ; and loop
  627. pdone:
  628.     ex    (sp),hl        ; restore return address
  629.     ret            ; and quit
  630.  
  631. ;
  632. ;Output a character in A to the console
  633. ;
  634. cout:
  635.     push    bc        ; save regs
  636.     push    de
  637.     push    hl
  638.     ld    e,a        ; character to E
  639.     ld    c,2
  640.     call    bdos        ; print it
  641.     pop    hl
  642.     pop    de
  643.     pop    bc
  644.     ret
  645.  
  646. ;Wait(seconds)
  647. wait:
  648.     ld    hl,2
  649.     add    hl,sp
  650.     ex    de,hl        ; get delay size
  651.     call    getparm
  652.                 ; fall thru to..
  653. ;Wait seconds in HL
  654. waithls:
  655.     push    bc        ; save bc
  656.     push    de        ; de
  657.     push    ix        ; and ix
  658.     ld    ix,0        ; then point ix to 0
  659.                 ; so we don't upset memory-mapped i/o
  660.  
  661. ;Calculate values for loop constants. Need to have two loops to avoid
  662. ;   16-bit overflow with clock speeds above 9 MHz.
  663.  
  664. outerval    equ    (clkspd / 10) + 1
  665. innerval    equ    (6667 / outerval) * clkspd
  666.  
  667. wait10:
  668.     ld    b,outerval
  669.  
  670. wait11:
  671.     ld    de,innerval
  672.  
  673. wait12:
  674.     bit    0,(ix)        ; time-wasters
  675.     bit    0,(ix)
  676.     bit    0,(ix)        ; 20 T-states each
  677.     bit    0,(ix)
  678.     bit    0,(ix)
  679.     bit    0,(ix)
  680.     dec    de
  681.     ld    a,e
  682.     ld    a,d
  683.     or    e
  684.     jr    nz,wait12    ; 150 T-states per inner loop
  685.     djnz    wait11        ; decrement outer loop
  686.     dec    hl        ; ok, decrement count in hl
  687.     ld    a,h
  688.     or    l
  689.     jr    nz,wait10
  690.     pop    ix        ; done -- restore ix
  691.     pop    de        ; de
  692.     pop    bc        ; and bc
  693.     ret
  694.  
  695. ;Wait milliseconds
  696. mswait:
  697.     ld    hl,2
  698.     add    hl,sp
  699.     ex    de,hl        ; get delay size
  700.     call    getparm
  701.                 ; fall thru to..
  702. ;Wait milliseconds in HL
  703. waithlms:
  704.     push    de
  705. w1ms0:
  706.     ld    de,39 * clkspd
  707. w1ms1:
  708.     dec    de
  709.     ld    a,d
  710.     or    e
  711.     jr    nz,w1ms1
  712.     dec    hl
  713.     ld    a,h
  714.     or    l
  715.     jr    nz,w1ms0
  716.     pop    de
  717.     ret
  718.  
  719. ;Get next parameter from (de) into hl
  720. getparm:
  721.     ex    de,hl        ; get address into hl
  722.     ld    e,(hl)        ; get lo
  723.     inc    hl
  724.     ld    d,(hl)        ; then hi
  725.     inc    hl        ; bump for next
  726.     ex    de,hl        ; result in hl, address still in de
  727.     ret
  728.  
  729.      if    ($ - codebgn) gt ovsize
  730. toobig:    jp    errval        ; Overlay too large!
  731.      endif
  732.  
  733.     end
  734.