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-MD06.Z80 < prev    next >
Text File  |  1991-02-02  |  16KB  |  728 lines

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