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-EX15.Z80 < prev    next >
Text File  |  1991-02-02  |  15KB  |  704 lines

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