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 / CPM / MODEMS / ZMODEM / ZMO-KP11.Z80 < prev    next >
Text File  |  2000-06-30  |  18KB  |  695 lines

  1. ;
  2. ;    Overlay to ZMP (Z-Modem Program), for the Kaypro CP/M computers.
  3. ;        (Z80 SIO and 8116 baudrate generator.)
  4. ;
  5. ;    Name:  ZMO-KP05.MAC
  6. ;
  7. ;    Dated: November 25, 1988
  8. ;
  9. ;    Written by -
  10. ;      Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia.
  11. ;
  12. ; 89/04/12 - Modified to ZMP v1.5        - George Conover
  13. ;    KP05 - Nov. 24, 88. Updated for ZMP version 1.4 (overlay drive/user
  14. ;            equates).  Added conditional to check RTS/CTS signals.
  15. ;            Bill Duerr, GEnie ID: B.DUERR
  16. ;                    DKUG RBBS [313] 772-0522
  17. ;
  18. ;    KP04 - Oct. 22, 88. Updated to allow program to be reentered properly,
  19. ;            for 8-N-1 only -- still problems with even/odd parity.
  20. ;            Bill Duerr, GEnie ID: B.DUERR
  21. ;                    DKUG RBBS [313] 772-0522
  22. ;
  23. ;    KP03 - Oct. 12, 88 Modified to ZMP v1.3 standard rjm
  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. Once assembled,
  28. ; convert to hex with RELHEX and use MLOAD to overlay it over the main
  29. ; ZMPX.COM file to produce your very own ZMP.COM.
  30. ;
  31. ; Notes on modifying this file:
  32. ;    Hi-Tech C requires that functions do not change either index register
  33. ; (IX or IY). If your overlay requires either of these to be changed, ensure
  34. ; they are restored to their original values on return.
  35. ;    Since collecting parameters from C functions can be tricky, only change
  36. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  37. ; table at the start. Do NOT modify the entry/exit sections of each
  38. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  39. ;    Apart from defining modem functions, this file also defines terminal
  40. ; characteristics. Most have been set up for ADM-3A (with a few of my own
  41. ; additions). Modify to suit your own terminal. An inline print routine
  42. ; is provided for printing strings in the usual way: usage is
  43. ;
  44. ;    call    print
  45. ;    db    'required string',0
  46. ;
  47. ;    Don't forget to set your clock speed at the clkspd variable.
  48. ;
  49. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  50. ; you will have to re-compile the whole thing. Good luck. You might try
  51. ; informing us if you need to do this: if too many people need to do it, we
  52. ; haven't allowed enough room.
  53. ;
  54. ; Ron Murray 15/8/88
  55. ;
  56. ;
  57. false    equ    0
  58. true    equ    not false
  59. ;
  60. ; If the following equate is set to true, code will be added to set
  61. ; the RTS modem signal, telling the modem not to send any characters
  62. ; till RTS is reset, and also to check CTS if characters may be sent.
  63. ; This allows the Kaypro screen to keep up with the characters sent
  64. ; over the modem lines at higher speeds.  (The modem must be able to
  65. ; recognize RTS and set CTS for this to work.)
  66. ;
  67. rtscts    equ    true
  68. ;
  69. ;Set the following two equates to the drive and user area which will contain
  70. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file.  Set both to zero
  71. ;   (null) to locate them on the drive from which ZMP was invoked.
  72.  
  73. overdrive    equ    'A'    ; Drive to find overlay files on ('A'-'P')
  74. overuser    equ    15    ; User area to find files
  75.  
  76. ;------------------------------------------------------------------------------
  77.  
  78. ;User-set variables:
  79. clkspd    equ    4        ; Processor clock speed in MHz
  80. mspeed    equ    003ch        ; Current baud rate: as used by BYE etc
  81.                 ; This MUST be the same as Mspeed in
  82.                 ; ZMP.H
  83.  
  84.  
  85. dport    equ    04h        ; Kaypro SIO data port
  86. sport    equ    dport+2        ; Modem control port
  87. mdrcv    equ    01h        ; Modem receive ready
  88. mdsnd    equ    04h        ; Modem send ready bit
  89. mdtxe    equ    01h        ; Modem send buffer empty, holding buffer empty
  90. rsterr    equ    30h        ; Reset parity and overrun flags - register 0
  91. reg1ins    equ    0        ; No interrupts - register 1
  92. reg3ins    equ    0c1h        ; 8 Rx bits, Rx enable
  93. reg4ins    equ    44h        ; 16X baud rate, 1 stop bit, no parity
  94. reg5ins    equ    0eah        ; 8 Tx bits, Tx enable, RTS, DTR
  95.  
  96. bauda    equ    00h        ; 8116 port for baudrate
  97. rstsio    equ    18h        ; Reset the SIO
  98. dcd    equ    08h        ; Data Carrier Detect
  99. dtr    equ    80h        ; Data Terminal Ready
  100. rts    equ    02h        ; Request to send
  101. cts    equ    20h        ; Clear to send
  102. brk    equ    10h        ; SIO Break
  103. sioerr    equ    70h        ; SIO error
  104.  
  105. userdef    equ    00145h        ; origin of this overlay: get this value
  106.                 ; from the .SYM file produced when ZMP.COM
  107.                 ; is linked
  108. ovsize    equ    0400h        ; max size of this overlay
  109.  
  110.     org    userdef
  111.  
  112. esc    equ    1bh
  113. ctrlq    equ    11h
  114. cr    equ    0dh
  115. lf    equ    0ah
  116. bdos    equ    5
  117.  
  118. ;Jump table for the overlay: do NOT change this
  119.  
  120. jump_tab:
  121.     jp    scrnpr        ; screen print
  122.     jp    mrd        ; modem read with timeout
  123.     jp    mchin        ; get a character from modem
  124.     jp    mchout        ; send a character to the modem
  125.     jp    mordy        ; test for tx buffer empty
  126.     jp    mirdy        ; test for character received
  127.     jp    sndbrk        ; send break
  128.     jp    cursadd        ; cursor addressing
  129.     jp    cls        ; clear screen
  130.     jp    invon        ; inverse video on
  131.     jp    invoff        ; inverse video off
  132.     jp    hide        ; hide cursor
  133.     jp    show        ; show cursor
  134.     jp    savecu        ; save cursor position
  135.     jp    rescu        ; restore cursor position
  136.     jp    mint        ; service modem interrupt
  137.     jp    invec        ; initialise interrupt vectors
  138.     jp    dinvec        ; de-initialise interrupt vectors
  139.     jp    mdmerr        ; test uart flags for error
  140.     jp    dtron        ; turn DTR on
  141.     jp    dtroff        ; turn DTR OFF
  142.     jp    init        ; initialise uart
  143.     jp    wait        ; wait seconds
  144.     jp    mswait        ; wait milliseconds
  145.     jp    userin        ; user-defined entry routine
  146.     jp    userout        ; user-defined exit routine
  147.     jp    getvars        ; get system variables
  148.       JP    SETPORT        ; Set port (0 or 1)
  149.  
  150. ; Spare jumps for compatibility with future versions
  151.     jp    spare        ; spare for later use
  152.     jp    spare        ; spare for later use
  153.     jp    spare        ; spare for later use
  154.     jp    spare        ; spare for later use
  155.     jp    spare        ; spare for later use
  156.     jp    spare        ; spare for later use
  157.  
  158. ;
  159. ; Main code starts here
  160. ;
  161. codebgn    equ    $
  162. ;
  163. ;Screen print function
  164. scrnpr:
  165.                 ; <== Insert your own code here
  166.     call    print
  167.     db    'This function not supported.',cr,lf,0
  168.                 ; <== End of your own code
  169. spare:
  170.     ret
  171.  
  172. ; User-defined entry routine
  173. userin:
  174.     ret
  175. ; User-defined exit routine
  176. userout:            ; Leave RTS off
  177.     if    rtscts
  178.     ld    a,05h        ; Select register 5
  179.     out    (sport),a    ; Send to the status port
  180.     ld    a,(reg5)    ; Get register 5 settings
  181.     and    255-rts        ; Turn off RTS
  182.     out    (sport),a    ; Send to the status port
  183.     endif            ; rtscts
  184.     ret
  185.  
  186. ;Get a character from the modem: return in HL
  187. ; It is not necessary to test for status
  188. mchin:
  189. ;-- Code added specific to Kaypro
  190.     in    a,(dport)    ; get the character in A
  191. ;
  192. ; This routine checks parity, and if parity is not "none", strips high bit.
  193. ; This is needed, even if the filter is turned on, because CONNECT message
  194. ; is not filtered.
  195. ;
  196.     ld    l,a        ; Save in L
  197.     ld    a,(parity)    ; Check parity
  198.     cp    'N'        ; No parity?
  199.     ld    a,l        ; Get the character back
  200.     jr    z,mchin1    ; Bypass following kludge
  201.     and    7fh
  202.     ld    l,a        ; put in HL
  203. mchin1:
  204.     if    rtscts
  205.     ld    a,05h        ; Select register 5
  206.     out    (sport),a    ; Send to the status port
  207.     ld    a,(reg5)    ; Get register 5 settings
  208.     and    255-rts        ; Turn off RTS
  209.     out    (sport),a    ; Send to the status port
  210.     endif            ; rtscts
  211. ;-- End of this block of machine specific code
  212.     ld    a,l        ; get character from HL
  213.     ld    h,0
  214.     or    a        ; set/clear Z
  215.     ret
  216.  
  217. ;Send a character to the modem
  218. mchout:
  219.     ld    hl,2        ; Get the character
  220.     add    hl,sp
  221.     ld    a,(hl)        ; in A
  222. ;-- Code added specific to Kaypro
  223.     out    (dport),a    ; Put the character to the serial port
  224. ;-- End of this block of machine specific code
  225.     ret            ; done
  226.  
  227. ;Test for output ready: return TRUE (1) in HL if ok
  228. mordy:
  229. ;-- Code added specific to Kaypro
  230.     ld    hl,0        ; Assume not ready
  231. ;
  232.     if    rtscts
  233.     ld    a,10h        ; Reset register 0
  234.     out    (sport),a    ; Send to the status port
  235.     in    a,(sport)    ; read status port
  236.     and    cts        ; Is clear to send up
  237.     jr    z,mordy1    ; Branch if not clear to send
  238.     endif            ; rtscts
  239. ;
  240.     ld    a,10h        ; Reset register 0
  241.     out    (sport),a    ; Send to the status port
  242.     in    a,(sport)    ; Read status port
  243.     and    mdsnd        ; Isolate transmit empty bit
  244.     jr    z,mordy1    ; Branch if not ready
  245.     inc    hl        ; otherwise set HL to indicate ready
  246. mordy1:
  247. ;-- End of this block of machine specific code
  248.     ld    a,l
  249.     or    a        ; set/clear Z
  250.     ret
  251.  
  252. ;Test for character at modem: return TRUE (1) in HL if so
  253. mirdy:
  254. ;-- Code added specific to Kaypro
  255.     ld    a,05h        ; Select register 5
  256.     out    (sport),a    ; Send to the status port
  257.     ld    a,(reg5)    ; Get register 5 settings
  258.     or    rts        ; Turn on RTS
  259.     out    (sport),a    ; Send to the status port
  260.     ld    hl,0        ; Assume not ready
  261.     ld    a,10h        ; Reset register 0
  262.     out    (sport),a    ; Send to the status port
  263.     in    a,(sport)    ; Get the status
  264.     and    mdrcv        ; Isolate receive ready bit
  265.     jr    z,mirdy1    ; Branch if not ready
  266.     inc    hl        ; otherwise set HL to indicate ready
  267. mirdy1:
  268. ;-- End of this block of machine specific code
  269.     ld    a,l
  270.     or    a        ; set/clear Z
  271.     ret
  272.  
  273. ;Send a break to the modem: leave empty if your system can't do it
  274. sndbrk:
  275. ;-- Code added specific to Kaypro
  276.     ld    a,5        ; Select register 5
  277.     out    (sport),a    ; Send to the status port
  278.     ld    a,(reg5)    ; Get parameters for register 5
  279.     or    brk        ; Set the break tone
  280.     out    (sport),a    ; Send to the status port
  281. ;-- End of this block of machine specific code
  282.     ld    hl,300
  283.     call    waitms        ; wait 300 mS
  284. ;-- Code added specific to Kaypro
  285.     ld    a,5        ; Select register 5
  286.     out    (sport),a    ; Send to the status port
  287.     ld    a,(reg5)    ; Restore register 5 settings
  288.     out    (sport),a    ; Send to the status port
  289. ;-- End of this block of machine specific code
  290.     ret
  291.  
  292. ;Test UART flags for error: return TRUE (1) in HL if error
  293. mdmerr:
  294. ;-- Code added specific to Kaypro
  295.     ld    hl,0        ; Assume no error
  296.     ld    a,011h        ; Select read register 1
  297.     out    (sport),a    ; Send to the status port
  298.     in    a,(sport)    ; Get error status
  299.     and    sioerr        ; Mask all but error bits
  300.     ret    z        ; Return zeor in HL if no error
  301.     inc    hl        ; Otherwise set HL to indicate error
  302.     ret            ; Return
  303.  
  304.  
  305. ;Turn DTR (and optionally RTS) ON.
  306. dtron:
  307. ;-- Code added specific to Kaypro
  308.     ld    a,05h        ; Select register 5
  309.     out    (sport),a    ; Send to the status port
  310.     ld    a,(reg5)    ; Get register 5 settings
  311.     out    (sport),a    ; Send to the status port
  312. ;-- End of this block of machine specific code
  313.     ret
  314.  
  315. ;Turn DTR ( and RTS?) OFF
  316. dtroff:
  317. ;-- Code added specific to Kaypro
  318.     ld    a,05h        ; Select register 5
  319.     out    (sport),a    ; Send to the status port
  320.     ld    a,(reg5)    ; Get register 5 settings
  321.     and    255-dtr        ; Turn off DTR
  322.     out    (sport),a    ; Send to the status port
  323. ;-- End of this block of machine specific code
  324.     ret
  325.  
  326. ;Initialise the UART
  327. init:
  328.     ld    hl,2        ; get parameters
  329.     add    hl,sp
  330.     ld    a,(hl)        ; get lo
  331.     ld    (mspeed),a    ; save in baud rate low memory
  332.     inc    hl
  333.     inc    hl        ; bump for next
  334.     ld    a,(hl)        ; get lo
  335.     and    5Fh        ; Convert to upper case
  336.     ld    (parity),a    ; parity
  337.     inc    hl
  338.     inc    hl        ; bump for next
  339.     ld    a,(hl)        ; get lo
  340.     and    0fh        ; Make sure binary
  341.     ld    (data),a    ; Save data bits
  342.     cp    7        ; but 7 if required
  343.     ld    a,reg5ins    ; 8 Tx bits, Tx enable, RTS, DTR
  344.     jr    nz,setbs
  345.     ld    a,reg5ins-040h    ; Turn bit off
  346. setbs:
  347.     ld    (reg5),a
  348.     inc    hl
  349.     inc    hl        ; bump for next
  350.     ld    a,(hl)        ; get lo
  351.     and    0fh        ; Make sure binary
  352.     ld    (stop),a    ; stop bits
  353.                 ; <== Insert your own code here
  354. ;-- Code added specific to Kaypro
  355.     ld    a,10h        ; Reset register 0
  356.     out    (sport),a    ; Send to the status port
  357.     in    a,(sport)    ; read status port
  358.     and    DCD        ; Is carrier up
  359.     jr    nz,initr    ; Branch if carrier already there
  360.     ld    A,0        ; Select register 0
  361.     out    (sport),a    ; Send to status port
  362.     ld    a,rstsio    ; Reset SIO - 18h
  363.     out    (sport),a    ; Send to status port
  364. ;
  365.     ld    A,4        ; Select register 4
  366.     out    (sport),a    ; Send to status port
  367.     ld    a,(parity)    ; do parity
  368.     ld    e,003h        ; assume even parity
  369.     cp    'E'        ; even?
  370.     jr    z,setstop    ; yes
  371.     ld    e,001h        ; try odd
  372.     cp    'O'
  373.     jr    z,setstop
  374.     ld    e,0        ; Indicate no parity
  375. setstop:
  376.     ld    a,(stop)    ; set stop bits
  377.     cp    2
  378.     ld    a,reg4ins    ; 16X baud rate, 1 stop bit, no parity
  379.     jr    nz,onestop
  380.     or    00ch        ; set bits 2 and 3
  381. onestop:
  382.     or    e        ; put parity bits in the register
  383. ;
  384.     out    (sport),a    ; Send to status port
  385. ;
  386.     ld    a,3        ; Select register 3
  387.     out    (sport),a    ; Send to status port
  388. ;
  389.     ld    a,(data)    ; get data bits parameter field
  390.     cp    7        ; is 7 required
  391.     ld    a,reg3ins    ; 8 Rx bits, Rx enable
  392.     jr    nz,setbr
  393.     and    07fh
  394. setbr:
  395.     out    (sport),a    ; Set Rx bits
  396.     ld    a,5        ; Select register 5
  397.     out    (sport),a    ; Send to status port
  398.     ld    a,(reg5)    ; Get register 5 settings
  399.     out    (sport),a    ; Set tx bits
  400. ;
  401.     ld    a,1        ; Select register 1
  402.     out    (sport),a
  403.     ld    a,reg1ins    ; No interrupts
  404.     out    (sport),a    ; Send to status port
  405. ;
  406.     ld    a,(mspeed)    ; set baud rate: get index
  407.     ld    hl,brval
  408.     ld    e,a        ; rate to DE
  409.     ld    d,0
  410.     add    hl,de
  411.     ld    a,(hl)        ; get baud rate value
  412.     out    (bauda),a
  413.                 ; <== End of your own code
  414. initr:    ret
  415.  
  416. ;
  417. ; Baud rate factors, output to bauda to select baud rate
  418. ;
  419. bd10    equ    02h        ; 110 baud rate     0
  420. bd30    equ    05h        ; 300 baud rate     1
  421. bd12    equ    07h        ; 1200 baud rate    5
  422. bd24    equ    0ah        ; 2400 baud rate    6
  423. bd48    equ    0ch        ; 4800 baud rate    7
  424. bd96    equ    0eh        ; 9600 baud rate    8
  425. bd19k    equ    0fh        ; 19.2k baud rate    9
  426.  
  427.  
  428. ;Values for control reg for each baud rate: 0 if invalid
  429. brval:
  430. ;         0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  431.     db    00,01,00,00,00,07,10,12,14,15
  432.  
  433.                 ; <== End of your own code
  434.     ret
  435.  
  436. brate:    db    6,0        ; baud rate:
  437.                 ; 0 = 110 baud    1 = 300 baud    2 = 450 baud
  438.                 ; 3 = 600 baud    4 = 710 baud    5 = 1200 baud
  439.                 ; 6 = 2400 baud 7 = 4800 baud    8 = 9600 baud
  440.                 ; 9 = 19200 baud
  441. parity:    db    'N',0        ; parity (will be 'N', 'E' or 'O')
  442. data:    db    8,0        ; data bits (will be 7 or 8)
  443. stop:    db    1,0        ; stop bits (will be 1 or 2)
  444. reg5:    db    reg5ins
  445.  
  446. ;
  447. ; Set the port. ZMP supplies either 0 or 1 as a parameter.
  448. ;
  449. setport:
  450.     ld    hl,2        ; get port number
  451.     add    hl,sp
  452.     ex    de,hl
  453.     call    getparm        ; in HL (values are 0 and 1)
  454.  
  455.                 ; <== Insert your own code here
  456.  
  457.                 ; <== End of your own code
  458.     ret
  459. ;****************************************************************************
  460. ;Video terminal sequences: these are for ADM-3A: Modify as you wish
  461. ;Cursor addressing:
  462. cursadd:
  463.     ld    hl,2        ; get parameters
  464.     add    hl,sp
  465.     ex    de,hl
  466.     call    getparm        ; in HL
  467.     ld    (row),hl    ; row
  468.     call    getparm
  469.     ld    (col),hl    ; column
  470.                 ; <== Insert your own code here
  471.                 ; using values in row and col
  472.     call    print
  473.     db    esc,'=',0    ; ADM-3A leadin
  474.     ld    a,(row)        ; row first
  475.     add    a,' '        ; add offset
  476.     call    cout
  477.     ld    a,(col)        ; sane for column
  478.     add    a,' '
  479.     call    cout
  480.                 ; <== end of your own code
  481.     ret
  482.  
  483. row:    ds    2        ; row
  484. col:    ds    2        ; column
  485.  
  486.  
  487. ;Clear screen:
  488. cls:
  489.     call    print
  490.     db    01ah,0
  491.     ret
  492.  
  493. ;Inverse video on:
  494. invon:
  495.     call    print
  496.     db    esc,'B','0',esc,'B','1',0
  497.     ret
  498.  
  499. ;Inverse video off:
  500. invoff:
  501.     call    print
  502.     db    esc,'C','0',esc,'C','1',0
  503.     ret
  504.  
  505. ;Turn off cursor:
  506. hide:
  507.     call    print
  508.     db    esc,'C','4',0
  509.     ret
  510.  
  511. ;Turn on cursor:
  512. show:
  513.     call    print
  514.     db    esc,'B','4',0
  515.     ret
  516.  
  517. ;Save cursor position:
  518. savecu:
  519.     call    print
  520.     defb    esc,'B','6',0
  521.     ret
  522.  
  523. ;Restore cursor position:
  524. rescu:
  525.     call    print
  526.     defb    esc,'C','6',0
  527.     ret
  528.  
  529. ;****************************************************************************
  530.  
  531. ;Service modem interrupt:
  532. mint:
  533.     ret            ; my system doesn't need this
  534.  
  535. ;Initialise interrupt vectors:
  536. invec:
  537.     ret            ; ditto
  538.  
  539. ;De-initialise interrupt vectors:
  540. dinvec:
  541.     ret            ; ditto
  542.  
  543. ;****************** End of user-defined code ********************************
  544. ; Don't change anything below this point. We needed some assembly language
  545. ; stuff for speed, and this seemed like a good place to put it.
  546.  
  547. ;Modem character test for 100 ms
  548. mrd:
  549.     push    bc        ; save bc
  550.     ld    bc,100        ; set limit
  551. mrd1:
  552.     call    mirdy        ; character at modem?
  553.     jr    nz,mrd2        ; yes, exit
  554.     ld    hl,1        ; else wait 1ms
  555.     call    waitms
  556.     dec    bc        ; loop till done
  557.     ld    a,b
  558.     or    c
  559.     jr    nz,mrd1
  560.     ld    hl,0        ; none there, result=0
  561.     xor    a
  562. mrd2:
  563.     pop    bc
  564.     ret
  565.  
  566. ; Inline print routine: destroys A and HL
  567.  
  568. print:
  569.     ex    (sp),hl        ; get address of string
  570. ploop:
  571.     ld    a,(hl)        ; get next
  572.     inc    hl        ; bump pointer
  573.     or    a        ; done if zero
  574.     jr    z,pdone
  575.     call    cout        ; else print
  576.     jr    ploop        ; and loop
  577. pdone:
  578.     ex    (sp),hl        ; restore return address
  579.     ret            ; and quit
  580.  
  581. ;
  582. ;Output a character in A to the console
  583. ;
  584. cout:
  585.     push    bc        ; save regs
  586.     push    de
  587.     push    hl
  588.     ld    e,a        ; Save the character to E for BDOS routine
  589.     ld    c,2        ; BDOS conout routine
  590.     call    bdos        ; print it
  591.     pop    hl
  592.     pop    de
  593.     pop    bc
  594.     ret
  595.  
  596. ;Wait(seconds)
  597. wait:
  598.     ld    hl,2
  599.     add    hl,sp
  600.     ex    de,hl        ; get delay size
  601.     call    getparm
  602.                 ; fall thru to..
  603. ;Wait seconds in HL
  604. waits:
  605.     push    bc        ; save bc
  606.     push    de        ; de
  607.     push    ix        ; and ix
  608.     ld    ix,0        ; then point ix to 0
  609.                 ; so we don't upset memory-mapped i/o
  610.  
  611. ;Calculate values for loop constants. Need to have two loops to avoid
  612. ;   16-bit overflow with clock speeds above 9 MHz.
  613.  
  614. outerval    equ    (clkspd    / 10) +    1
  615. innerval    equ    (6667 /    outerval) * clkspd
  616.  
  617. wait10:
  618.     ld    b,outerval
  619.  
  620. wait11:
  621.     ld    de,innerval
  622.  
  623. wait12:
  624.     bit    0,(ix)        ; time-wasters
  625.     bit    0,(ix)
  626.     bit    0,(ix)        ; 20 T-states each
  627.     bit    0,(ix)
  628.     bit    0,(ix)
  629.     bit    0,(ix)
  630.     dec    de
  631.     ld    a,e
  632.     ld    a,d
  633.     or    e
  634.     jr    nz,wait12    ; 150 T-states per inner loop
  635.     djnz    wait11        ; decrement outer loop
  636.     dec    hl        ; ok, decrement count in hl
  637.     ld    a,h
  638.     or    l
  639.     jr    nz,wait10
  640.     pop    ix        ; done -- restore ix
  641.     pop    de        ; de
  642.     pop    bc        ; and bc
  643.     ret
  644.  
  645. ;Wait milliseconds
  646. mswait:
  647.     ld    hl,2
  648.     add    hl,sp
  649.     ex    de,hl        ; get delay size
  650.     call    getparm
  651.                 ; fall thru to..
  652. ;Wait milliseconds in HL
  653. waitms:
  654.     push    de
  655. w1ms0:
  656.     ld    de,39 *    clkspd
  657. w1ms1:
  658.     dec    de
  659.     ld    a,d
  660.     or    e
  661.     jr    nz,w1ms1
  662.     dec    hl
  663.     ld    a,h
  664.     or    l
  665.     jr    nz,w1ms0
  666.     pop    de
  667.     ret
  668.  
  669. ;Get next parameter from (de) into hl
  670. getparm:
  671.     ex    de,hl        ; get address into hl
  672.     ld    e,(hl)        ; get lo
  673.     inc    hl
  674.     ld    d,(hl)        ; then hi
  675.     inc    hl        ; bump for next
  676.     ex    de,hl        ; result in hl, address still in de
  677.     ret
  678.  
  679. ;Get address of user-defined variables
  680.  
  681. getvars:
  682.     ld    hl,uservars
  683.     ret
  684.  
  685. uservars:
  686.     dw    overdrive    ; .OVR etc. drive/user
  687.     dw    overuser
  688.  
  689.  
  690.      if    ($ - codebgn) gt ovsize
  691. toobig:    jp    errval        ; Overlay too large!
  692.      endif
  693.  
  694.     end
  695.