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

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ;
  4. ;    Overlay for ZMP (Z-Modem Program)
  5. ;
  6. ;    Name    ZMO-PC05.Z80
  7. ;
  8. ;    Dated   01 MAY 1989
  9. ;
  10. ;    Written by -
  11. ;      Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia.
  12. ;
  13. ;
  14. ;      Rename subsequent versions as ZMO-PCxx.Z80 etc
  15. ;
  16. ;
  17. ;    This overlay is set up for an Amstrad PCW8256/512 under CPM Plus, with a
  18. ;        Zenith Z19/Z29 (VT52) terminal emulation and a Z80SIO and 8253 counter.
  19. ;              Overlay by Malcolm Smith, Murray Bridge, S.A.  01/05/89
  20. ;                     
  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-CPxx/H
  32. ;    MLOAD ZMP.COM=ZMPX.COM,ZMO-CPxx.HEX
  33. ; or
  34. ;    M80 =ZMO-CPxx/Z
  35. ;    RELHEX ZMO-CPxx
  36. ;    MLOAD ZMP.COM=ZMPX.COM,ZMO-CPxx.HEX
  37. ;
  38. ;
  39. ;       (Do not change the code in the boxes)
  40. ;         
  41. ;
  42. ;-----------------------------------------------------------------------------
  43. ;
  44. ;
  45. ; Notes on modifying this file:
  46. ;
  47. ;    C requires that functions do not change either index register
  48. ; (IX or IY), nor the BC register pair. If your overlay requires any of
  49. ; these to be changed, ensure they are restored to the original values
  50. ; on return.
  51. ;    Since collecting parameters from C functions can be tricky, only change
  52. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  53. ; table at the start. Do NOT modify the entry/exit sections of each
  54. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  55. ;    Apart from defining modem functions, this file also defines terminal
  56. ; characteristics. Most have been set up for ADM-3A (with a few of my own
  57. ; additions). Modify to suit your own terminal. An inline print routine
  58. ; is provided for printing strings in the usual way: usage is
  59. ;
  60. ;    call    print
  61. ;    db    'required string',0
  62. ;
  63. ;-----------------------------------------------------------------------------
  64. ;
  65. ;
  66. ;    Don't forget to set your clock speed at the clkspd variable.
  67. ;
  68. ;
  69. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  70. ; you will have to contact me for another version. If too many people need 
  71. ; to do it, we haven't allowed enough room.
  72. ;
  73. ; Ron Murray 15/8/88
  74. ;
  75. ;-----------------------------------------------------------------------------
  76.  
  77. false    equ    0
  78. true    equ    not false
  79.  
  80.  
  81. ; User-set variables: ***********
  82.  
  83. clkspd    equ    4        ; Processor clock speed in MHz
  84.  
  85. debug    equ    false
  86.  
  87. userdef    equ    00145h        ; origin of this overlay
  88.                 ; This address should remain constant
  89.                 ; with subsequent revisions.
  90. ;-----------------------------------------------------------------------------
  91. ;Set the following two equates to the drive and user area which will contain
  92. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  93. ;   (null) to locate them on the drive from which ZMP was invoked.
  94.  
  95. overdrive    equ    'B'    ; Drive to find overlay files on ('A'-'P')
  96. overuser    equ    1    ; User area to find files
  97. ;------------------------------------------------------------------------------
  98. ; NOT user-set variables
  99. mspeed    equ    003ch        ; baud rate id
  100.  
  101. ovsize    equ    0400h        ; max size of this overlay
  102.  
  103.     .z80            ; use z80 code
  104.     aseg            ; absolute
  105.  
  106.      if    debug
  107.     org    100h        ; so you can debug it with cebug, zsid, etc
  108.      else
  109.     org    userdef
  110.      endif
  111.  
  112. esc    equ    1bh
  113. ctrlq    equ    11h
  114. bell    equ    7
  115. cr    equ    0dh
  116. lf    equ    0ah
  117. bdos    equ    5
  118.  
  119. ; Amstrad PCW 8256/512 specific equates  ******************************************
  120.  
  121. mdata    equ    0E0H           ; data port
  122. mstat    equ    0E1H          ; status port
  123. rda    equ    0        ; Received data available
  124. tbe    equ    2        ; Tx ready
  125. onhook    equ    7Fh
  126. online    equ    80h
  127. error    equ    70h
  128. break    equ    0F8h
  129.  
  130. ; 8253 Counter equates
  131.  
  132. ctcont    equ    0E7H          ; Control register of the 8253
  133. ctc0    equ    0E4H          ; Counter # 0 of the 8253
  134. ctc1    equ    0E5H          ; Counter # 1 of the 8253
  135.  
  136.  
  137. ;-------------------------------------------------------------------------
  138. ; Main code starts here
  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        ; spares for later use
  175.     jp    spare        ; spares for later use
  176.     jp    spare        ; spares for later use
  177.     jp    spare        ; spares for later use
  178.     jp    spare        ; spares for later use
  179.  
  180. spare:    ret
  181.  
  182. ;-------------------------------------------------------------------------
  183.  
  184.  
  185. ;Screen print function
  186. scrnpr:
  187.  
  188.                 ; <== Insert your own code here
  189.  
  190.     call    print
  191.     db    bell
  192.     db    'This function not supported.',cr,lf
  193.     db    0
  194.  
  195.  
  196.                 ; <== End of your own code
  197.     ret
  198.  
  199.  
  200. ;Get a character from the modem: return in HL
  201. mchin:
  202.     push    bc
  203.                 ; <== Insert your own code here
  204.     ld    bc,mstat
  205. mchin2:
  206.     in    a,(c)        ; check for char waiting
  207.     bit    rda,a
  208.     jr    z,mchin2
  209.  
  210.     ld    bc,mdata
  211.     in    a,(c)        ; read the char
  212.  
  213.                 ; <== End of your own code
  214.  
  215.     ld    l,a        ; put in HL
  216.     ld    h,0
  217.     or    a        ; set/clear Z
  218.     pop    bc
  219.     ret
  220.  
  221.  
  222. ;Send a character to the modem
  223. mchout:
  224.     ld    hl,2        ; get the character
  225.     add    hl,sp        ;
  226.     ld    a,(hl)        ;
  227.                 ; <== Insert your own code here
  228.     push    bc
  229.     push    af        ; save the char
  230.  
  231.     ld    bc,mstat
  232.  
  233. mchout2:
  234.     in    a,(c)        ; check for uart ready
  235.     bit    tbe,a
  236.     jr    z,mchout2
  237.  
  238.     pop    af        ; char in a
  239.     ld    bc,mdata
  240.     out    (c),a        ; send it
  241.     pop    bc
  242.  
  243.                 ; <== End of your own code
  244.     ret            ; done
  245.  
  246.  
  247. ;Test for output ready: return TRUE (1) in HL if ok
  248. mordy:
  249.                 ; <== Insert your own code here
  250.     push    bc
  251.     ld    bc,mstat
  252.     ld    hl,0
  253.     in    a,(c)
  254.     bit    tbe,a        ; transmit buffer empty
  255.     jr    z,mordy1
  256.     inc    hl
  257. mordy1:
  258.     pop    bc
  259.                 ; <== End of your own code
  260.  
  261.     ld    a,l        ; set/clear Z
  262.     or    a
  263.     ret
  264. ;--------------------------------------------------------------------------
  265.  
  266. ;Test for character at modem: return TRUE (1) in HL if so
  267. mirdy:
  268.                 ; <== Insert your own code here
  269.     push    bc
  270.     ld    bc,mstat
  271.     ld    hl,0
  272.     in    a,(c)
  273.     bit    rda,a        ; received data available
  274.     jr    z,mirdy1
  275.     inc    hl
  276. mirdy1:
  277.     pop    bc
  278.                 ; <== End of your own code
  279.     ld    a,l        ; set/clear Z
  280.     or    a
  281.     ret
  282.  
  283. ;Send a break to the modem: leave empty if your system can't do it
  284. sndbrk:
  285.                 ; <== Insert your own code here
  286.     push    bc
  287.     ld    bc,mstat
  288.     ld    a,5
  289.     out    (c),a
  290.     ld    a,break        ; F8h
  291.     out    (c),a
  292.  
  293.     ld    hl,300        ; a 300 mS break
  294.     call    waithlms
  295.  
  296.     ld    a,5
  297.     out    (c),a
  298.     ld    a,online    ; 68h
  299.     out    (c),a
  300.  
  301.     ld    a,3
  302.     out    (c),a
  303.     ld    a,0E1h      ; E1h
  304.     out    (c),a
  305.     pop    bc
  306.                 ; <== End of your own code
  307.     ret
  308.  
  309. ;Test UART flags for error: return TRUE (1) in HL if error.
  310. mdmerr:
  311.                 ; <== Insert your own code here
  312.     push    bc
  313.     ld    bc,mstat
  314.     ld    hl,0
  315.     in    a,(c)
  316.        and    a,error
  317.     jr    z,mdmer2
  318.     inc    hl
  319. mdmer2:
  320.     pop    bc
  321.                 ; <== End of your own code
  322.     ld    a,l        ; set/clear Z
  323.     or    a
  324.     ret
  325.  
  326.  
  327.  
  328. ;Turn DTR ON
  329. dtron:
  330.             ; <== Insert your own code here
  331.     push    bc
  332.     ld    bc,mstat
  333.     ld    a,5
  334.     out    (c),a
  335.  
  336.     ld    a,(combyt)    ; get the one we used last time
  337.     or    a,online    ; 80h - set bit 7 high
  338.     ld    (combyt),a    ; save it for next time
  339.     out    (c),a        ; go
  340.     pop    bc        ;
  341.  
  342.                 ; <== End of your own code
  343.     ret
  344.  
  345.  
  346.  
  347. ;Turn DTR OFF
  348. dtroff:
  349.                 ; <== Insert your own code here
  350.     push    bc
  351.     ld    bc,mstat
  352.     ld    a,5
  353.     out    (c),a
  354.  
  355.     ld    a,(combyt)    ; get the one we used last time
  356.     and    onhook        ; 7Fh - clear bit 7
  357.     ld    (combyt),a    ; save it for next time
  358.     out    (c),a        ; go
  359.     pop    bc
  360.                 ; <== End of your own code
  361.     ret
  362.  
  363. ;Initialise the SIO +++
  364. ; The SIO is set up in four steps:
  365. ;     1)  Reset
  366. ;       2)  Reg 4 - clock, stop bits, parity
  367. ;    3)  Reg 5 - dtr, Tx bits, Brk, TxEn, rts
  368. ;    4)  Reg 3 - Rx bits, RxEn
  369.  
  370. init:
  371.  
  372.     ld    hl,2        ; get parameters
  373.     add    hl,sp
  374.     ex    de,hl
  375.     call    getparm        ; in HL
  376.     ld    (brate),hl    ; baud rat
  377.     call    getparm
  378.     ld    (parity),hl    ; parity
  379.     call    getparm
  380.     ld    (data),hl    ; data bits
  381.     call    getparm
  382.     ld    (stop),hl    ; stop bits
  383.  
  384.                 ; <== Insert your own code here
  385.                 ; using values below
  386.  
  387.     push    bc
  388.     ld    bc,mstat
  389.     ld    a,0
  390.     out    (c),a        ; point to reg 0
  391.     ld    a,18h        ; reset
  392.     out    (c),a        ;                *** step 1
  393.  
  394.     ld    a,4        ; point to wrt reg 4
  395.     out    (c),a
  396.     ld    e,44h        ; assume  x16, 1 stop, No parity
  397.     ld    a,(stop)    ; set stop bits
  398.     cp    2        ; set 2 if required
  399.     jr    nz,setpar
  400.     ld    a,08h        ; 0000 1000
  401.     or    e
  402.     ld    e,a
  403.  
  404. setpar:
  405.     ld    a,(parity)    ; set parity bits
  406.     cp    'O'
  407.     jr    nz,setpa2
  408.     ld    d,01h        ; 0000 0001    ODD
  409.     jr    setpa3
  410.  
  411. setpa2:    cp    'E'
  412.     jr    nz,setpa4
  413.     ld    d,03h        ; 0000 0011    EVEN
  414. setpa3:    ld    a,e
  415.     or    a,d
  416.     ld    e,a
  417.  
  418. setpa4:    ld    a,e
  419.     out    (c),a        ;                *** step 2
  420.  
  421.  
  422.  
  423.     ld    a,5        ; point to wrt reg 5 - dtr, Tx bits, etc
  424.     out    (c),a
  425.     ld    e,0EAh        ; assume dtr, TX 8 bits, TxEn, rts
  426.     ld    a,(data)
  427.     cp    7
  428.     jr    nz,setbi2
  429.     ld    d,0BFh        ; 1011 1111    7 bits
  430.     ld    a,e
  431.     and    a,d
  432.     ld    e,a
  433.  
  434. setbi2:    ld    a,e
  435.     out    (c),a        ;                *** step3
  436.  
  437.     ld    a,3        ; point to wrt reg 3
  438.     out    (c),a
  439.     ld    e,0C1h        ; assume 8 bits
  440.     ld    a,(data)
  441.     cp    7
  442.     jr    nz,setbi3
  443.     ld    d,07Fh        ; 0111 1111    7 bits
  444.     ld    a,e
  445.     and    a,d
  446.     ld    e,a
  447.  
  448. setbi3:    ld    a,e
  449.     out    (c),a        ;                *** step 4
  450.  
  451. setbrate:
  452.  
  453.     push    ix        ; save ix
  454.     ld    de,(brate)    ; get baud rate value (0-10)
  455.     ld    ix,brval
  456.     add    ix,de
  457.     add    ix,de        ; ix now points to the 2-byte value
  458.     ld    a,(ix)        ; if zero,
  459.     or    (ix+1)
  460.     jr    z,setbrx    ; it's not valid
  461.  
  462.     ld    bc,ctcont
  463.     ld    a,36h
  464.     out    (c),a
  465.  
  466.     ld    bc,ctc0
  467.     ld    a,(ix)
  468.     out    (c),a        ; lo byte
  469.     ld    a,(ix+1) 
  470.     out    (c),a        ; hi byte
  471.  
  472.     ld    bc,ctcont
  473.     ld    a,76h
  474.     out    (c),a
  475.  
  476.     ld    bc,ctc1
  477.     ld    a,(ix)
  478.     out    (c),a        ; lo byte
  479.     ld    a,(ix+1)
  480.     out    (c),a        ; hi byte
  481.     ld    a,(brate)    ; tell zmp it's valid
  482.     ld    (mspeed),a
  483.  
  484. setbrx:
  485.     pop    ix
  486.     pop    bc
  487.                 ; <== End of your own code
  488.     ret
  489.  
  490. brate:    dw    5        ; baud rate
  491. parity:    dw    'N'        ; parity
  492. data:    dw    8        ; data bits
  493. stop:    dw    1        ; stop bits
  494. combyt: ds    1           ; used for dtr on /off
  495.  
  496. ;Values for 8253 control reg for each baud rate: 0 if invalid
  497. brval:
  498.     dw    470H    ;   110        0
  499.     dw    1A1H    ;   300        1
  500.     dw    116H    ;   450        2
  501.     dw    0D0H    ;   600        3
  502.     dw    0B0H    ;   710        4
  503.     dw    068H    ;  1200        5
  504.     dw    034H    ;  2400        6
  505.     dw    01AH    ;  4800        7
  506.     dw    00DH    ;  9600        8
  507.     dw    007H    ; 19200        9 
  508.     dw    0    ; 38400        10
  509.     dw    0    ; 57600        11
  510.     dw    0    ; 76800        12
  511. ;---------------------------------------------------------------------------
  512. ;
  513. ; Set the port. ZMP supplies either 0 or 1 as a parameter. You're on your
  514. ; own here -- your system is bound to be different from any other! You may
  515. ; implement a software switch on all the modem-dependent routines, or perhaps
  516. ; you can have one or two centralised routines for accessing the UARTs and
  517. ; modify the code from this routine to select one or the other. (Who said
  518. ; there was anything wrong with self-modifying code?). If you have only one
  519. ; UART port, or if you don't want to go through all the hassles, just have
  520. ; this routine returning with no changes made. Note that ZMP calls this
  521. ; routine twice -- once for each port value -- on initialisation.
  522. ;
  523. setport:
  524.     ld    hl,2        ; get port number
  525.         add    hl,sp
  526.         ex    de,hl
  527.     call    getparm        ; in HL (values are 0 and 1)
  528.                 ; <== Insert your own code here
  529.  
  530.                 ; <== End of your own code
  531.     ret
  532.  
  533. port:    ds    1
  534.  
  535. ;****************************************************************************
  536. ;Video terminal sequences: these are for Zenith Z19/Z29: Modify as you wish
  537. ;Cursor addressing: 
  538. cursadd:
  539.     ld    hl,2        ; get parameters
  540.     add    hl,sp
  541.     ex    de,hl
  542.     call    getparm        ; in HL
  543.     ld    (row),hl    ; row
  544.     call    getparm
  545.     ld    (col),hl    ; column
  546.                 ; <== Insert your own code here
  547.                 ; using values in row and col
  548.     call    print
  549.     db    esc,'Y',0    ; leadin
  550.     ld    a,(row)        ; row first
  551.     add    a,' '        ; add offset
  552.     call    cout
  553.     ld    a,(col)        ; sane for column
  554.     add    a,' '
  555.     call    cout
  556.                 ; <== end of your own code
  557.     ret
  558.  
  559. row:    ds    2        ; row
  560. col:    ds    2        ; column
  561.  
  562.  
  563. ;Clear screen:
  564. cls:
  565.     call    print
  566.     db    esc,'E',esc,'H',0
  567.     ret
  568.  
  569. ;Inverse video on:
  570. invon:
  571.     call    print
  572.     db    esc,'p',0
  573.     ret
  574.  
  575. ;Inverse video off:
  576. invoff:
  577.     call    print
  578.     db    esc,'q',0
  579.     ret
  580.  
  581. ;Turn off cursor:
  582. hide:
  583.     call    print
  584.     db    esc,'f',0
  585.     ret
  586.  
  587. ;Turn on cursor:
  588. show:
  589.     call    print
  590.     db    esc,'e',0
  591.     ret
  592.  
  593. ;Save cursor position:
  594. savecu:
  595.     call    print
  596.     db    esc,'j',0
  597.     ret
  598.  
  599. ;Restore cursor position:
  600. rescu:
  601.     call    print
  602.     db    esc,'k',0
  603.     ret
  604.  
  605. ;****************************************************************************
  606.  
  607. ;Service modem interrupt:
  608. mint:
  609.     ret
  610.  
  611. ;Initialise interrupt vectors:
  612. invec:
  613.     ret
  614.  
  615. ;De-initialise interrupt vectors:
  616. dinvec:
  617.     ret
  618.  
  619. ;User-defined entry routine: leave empty if not used
  620. userin:
  621.     ret
  622.  
  623. ;User-defined exit routine: leave empty if not used
  624. userout:
  625.     ret
  626.  
  627.  
  628. ;****************** End of user-defined code ********************************
  629. ;         Do not change anything below here.
  630.  
  631.  
  632. ;Modem character test for 100 ms
  633. mrd:
  634.     push    bc        ; save bc
  635.     ld    bc,100        ; set limit
  636. mrd1:
  637.     call    mirdy        ; char at modem?
  638.     jr    nz,mrd2        ; yes, exit
  639.     ld    hl,1        ; else wait 1ms
  640.     call    waithlms
  641.     dec    bc        ; loop till done
  642.     ld    a,b
  643.     or    c
  644.     jr    nz,mrd1
  645.     ld    hl,0        ; none there, result=0
  646.     xor    a
  647. mrd2:
  648.     pop    bc
  649.     ret
  650.  
  651. ; Inline print routine: destroys A and HL
  652.  
  653. print:
  654.     ex    (sp),hl        ; get address of string
  655. ploop:
  656.     ld    a,(hl)        ; get next
  657.     inc    hl        ; bump pointer
  658.     or    a        ; done if zero
  659.     jr    z,pdone
  660.     call    cout        ; else print
  661.     jr    ploop        ; and loop
  662. pdone:
  663.     ex    (sp),hl        ; restore return address
  664.     ret            ; and quit
  665.  
  666. ;
  667. ;Output a character in A to the console
  668. ;
  669. cout:
  670.     push    bc        ; save regs
  671.     push    de
  672.     push    hl
  673.     ld    e,a        ; character to E
  674.     ld    c,2
  675.     call    bdos        ; print it
  676.     pop    hl
  677.     pop    de
  678.     pop    bc
  679.     ret
  680.  
  681. ;Wait(seconds)
  682. wait:
  683.     ld    hl,2
  684.     add    hl,sp
  685.     ex    de,hl        ; get delay size
  686.     call    getparm
  687.                 ; fall thru to..
  688. ;Wait seconds in HL
  689. waithls:
  690.     push    bc        ; save bc
  691.     push    de        ; de
  692.     push    ix        ; and ix
  693.     ld    ix,0        ; then point ix to 0
  694.                 ; so we don't upset memory-mapped i/o
  695.  
  696. ;Calculate values for loop constants. Need to have two loops to avoid
  697. ;   16-bit overflow with clock speeds above 9 MHz.
  698.  
  699. outerval    equ    (clkspd / 10) + 1
  700. innerval    equ    (6667 / outerval) * clkspd
  701.  
  702. wait10:
  703.     ld    b,outerval
  704.  
  705. wait11:
  706.     ld    de,innerval
  707.  
  708. wait12:
  709.     bit    0,(ix)        ; time-wasters
  710.     bit    0,(ix)
  711.     bit    0,(ix)        ; 20 T-states each
  712.     bit    0,(ix)
  713.     bit    0,(ix)
  714.     bit    0,(ix)
  715.     dec    de
  716.     ld    a,e
  717.     ld    a,d
  718.     or    e
  719.     jr    nz,wait12    ; 150 T-states per inner loop
  720.     djnz    wait11        ; decrement outer loop
  721.     dec    hl        ; ok, decrement count in hl
  722.     ld    a,h
  723.     or    l
  724.     jr    nz,wait10
  725.     pop    ix        ; done -- restore ix
  726.     pop    de        ; de
  727.     pop    bc        ; and bc
  728.     ret
  729.  
  730. ;Wait milliseconds
  731. mswait:
  732.     ld    hl,2
  733.     add    hl,sp
  734.     ex    de,hl        ; get delay size
  735.     call    getparm
  736.                 ; fall thru to..
  737. ;Wait milliseconds in HL
  738. waithlms:
  739.     push    de
  740. w1ms0:
  741.     ld    de,39 * clkspd
  742. w1ms1:
  743.     dec    de
  744.     ld    a,d
  745.     or    e
  746.     jr    nz,w1ms1
  747.     dec    hl
  748.     ld    a,h
  749.     or    l
  750.     jr    nz,w1ms0
  751.     pop    de
  752.     ret
  753.  
  754. ;Get next parameter from (de) into hl
  755. getparm:
  756.     ex    de,hl        ; get address into hl
  757.     ld    e,(hl)        ; get lo
  758.     inc    hl
  759.     ld    d,(hl)        ; then hi
  760.     inc    hl        ; bump for next
  761.     ex    de,hl        ; result in hl, address still in de
  762.     ret
  763.  
  764. ;Get address of user-defined variables
  765. getvars:
  766.     ld    hl,uservars
  767.     ret
  768.  
  769.     ds    ($ or 0Fh) - $ + 1,0
  770.     db    'OVERLAYS',0
  771. uservars:
  772.     dw    overdrive    ; all integer
  773.     dw    overuser
  774.  
  775.     ds    ovsize + codebgn - $,0        ; zero out the garbage
  776.  
  777.      if    ($ - codebgn) gt ovsize
  778. toobig:    jp    errval        ; Overlay too large!
  779.      endif
  780.  
  781.     end
  782.