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-1804.Z80 next >
Text File  |  1991-02-02  |  17KB  |  762 lines

  1. ; ZMP180B1.Z80 -- SB180 computer overlay file for ZMP -- 09/27/88
  2. ;
  3. ; This file adapts ZMP14 to the SB180-FX computer; HD64180 ASCII port 0.
  4. ;
  5. ; This file is a BETA-TEST version, known only to work on 9 MHz 'FX.
  6. ; Assemble with ZAS.
  7. ;
  8. ; Modified to v1.3 standard rjm 13/10/88
  9. ; Modified to v1.4 standard rjm 11/12/88
  10. ;
  11. ; vB.2    Beta-test version 2            09/27/88  Bill Biersdorf
  12. ;    -- added conditionals for clock speeds
  13. ;    -- added equate 'dtrfx' for latch DTR on the 'FX
  14. ;    -- character framing may work on non-FX, not sure
  15. ;
  16. ; vB.1    Beta-test version 1            09/24/88  Bill Biersdorf
  17. ;    -- works with 9 MHz SB180-FX
  18. ;    -- no provisions for stop bit, word length, or paity change
  19. ;
  20. ;
  21. ; System-dependent installation overlay for ZMP
  22. ; Author: Ron Murray
  23. ;
  24. ;    Insert your own code as necessary in this file. Code contained herein
  25. ; has been written in HD64180 code for use with ZAS.  Assemble with the h
  26. ; option to create a .HEX file, and use MLOAD to overlay it over the main
  27. ; ZMPX.COM file to produce your very own ZMP.COM.
  28. ;
  29. ; Notes on modifying this file:
  30. ;    Hi-Tech C requires that functions do not change either index register
  31. ; (IX or IY). If your overlay requires either of these to be changed, ensure
  32. ; they are restored to their original values on return.
  33. ;    Since collecting parameters from C functions can be tricky, only change
  34. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  35. ; table at the start. Do NOT modify the entry/exit sections of each
  36. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  37. ;    Apart from defining modem functions, this file also defines terminal
  38. ; characteristics. Most have been set up for ADM-3A (with a few of my own
  39. ; additions). Modify to suit your own terminal. An inline print routine
  40. ; is provided for printing strings in the usual way: usage is
  41. ;
  42. ;    call    print
  43. ;    db    'required string',0
  44. ;
  45. ;    Don't forget to set your clock speed at the Select-a-speed section.
  46. ; Set only one of cpu12, cpu9, or cpu6 to true.  Set 'dtrfx' to true for
  47. ; your SB180-FX for proper DTR operation.
  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. ;Some fundamental truths
  58.  
  59. true    equ    0ffh
  60. false    equ    not true
  61.  
  62. ;Set the following two equates to the drive and user area which will contain
  63. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  64. ;   (null) to locate them on the drive from which ZMP was invoked.
  65.  
  66. overdrive    equ    'A'    ; Drive to find overlay files on ('A'-'P')
  67. overuser    equ    0    ; User area to find files
  68.  
  69.  
  70. ;Select-a-speed            ; NOTE: set only ONE of the following to true
  71.  
  72. cpu12    equ    false        ; 12.288 MHz HD64180
  73. cpu9    equ    true        ; 9.216 MHz HD64180
  74. cpu6    equ    false        ; 6.144 MHz HD64180
  75.  
  76. ;Control latch dtr
  77.  
  78. dtrfx    equ    false        ; Otherwise just use RTS code
  79.  
  80. ;User-set variables:
  81.  
  82. iport    equ    08h        ; MODEM data in port
  83. oport    equ    06h        ; MODEM data out port
  84. cport    equ    00h        ; MODEM control port
  85. mstat    equ    04h        ; MODEM status port
  86. bport    equ    02h        ; MODEM baudrate port
  87. mdrcv    equ    80h        ; receive ready bit
  88. mdsnd    equ    02h        ; send ready bit
  89.  
  90.       if    cpu12
  91. clkspd    equ    12
  92.       endif
  93.       if    cpu9
  94. clkspd    equ    9
  95.       endif
  96.       if    cpu6
  97. clkspd    equ    6        ; Processor clock speed in MHz
  98.       endif
  99.  
  100.  
  101. ;Leave the next three equates alone!
  102.  
  103. mspeed    equ    003ch        ; Current baud rate: as used by BYE etc
  104.                 ; This MUST be the same as Mspeed in
  105.                 ; ZMP.H
  106.  
  107. userdef    equ    00145h        ; origin of this overlay: get this value
  108.                 ; from the .SYM file produced when ZMP.COM
  109.                 ; is linked
  110. ovsize    equ    0400h        ; max size of this overlay
  111.  
  112.  
  113.     .hd64            ; use HD64180 code
  114. ;;    aseg            ; absolute
  115.  
  116.     org    userdef
  117.  
  118. esc    equ    1bh
  119. ctrlq    equ    11h
  120. cr    equ    0dh
  121. lf    equ    0ah
  122. bdos    equ    5
  123.  
  124.  
  125. ;Jump table for the overlay: do NOT change this
  126. jump_tab:
  127.     jp    scrnpr        ; screen print
  128.     jp    mrd        ; modem read with timeout
  129.     jp    mchin        ; get a character from modem
  130.     jp    mchout        ; send a character to the modem
  131.     jp    mordy        ; test for tx buffer empty
  132.     jp    mirdy        ; test for character received
  133.     jp    sndbrk        ; send break
  134.     jp    cursadd        ; cursor addressing
  135.     jp    cls        ; clear screen
  136.     jp    invon        ; highlight (inverse video) on
  137.     jp    invoff        ; highlight (inverse video) off
  138.     jp    hide        ; hide cursor
  139.     jp    show        ; show cursor
  140.     jp    savecu        ; save cursor position
  141.     jp    rescu        ; restore cursor position
  142.     jp    mint        ; service modem interrupt
  143.     jp    invec        ; initialise interrupt vectors
  144.     jp    dinvec        ; de-initialise interrupt vectors
  145.     jp    mdmerr        ; test uart flags for error
  146.     jp    dtron        ; turn DTR (and RTS) ON
  147.     jp    dtroff        ; turn DTR (and RTS) OFF
  148.     jp    init        ; initialise uart
  149.     jp    wait        ; wait seconds
  150.     jp    mswait        ; wait milliseconds
  151.     jp    userin        ; user-defined entry routine
  152.     jp    userout        ; user-defined exit routine
  153.     jp    getvars        ; get system variables
  154.  
  155. ;Spare jumps for compatibility with future versions
  156.     jp    spare        ; spares for later use
  157.     jp    spare        ; spares for later use
  158.     jp    spare        ; spares for later use
  159.     jp    spare        ; spares for later use
  160.     jp    spare        ; spares for later use
  161.  
  162. ;
  163. ; Main code starts here
  164. ;
  165. codebgn    equ    $
  166.  
  167. ;User-defined entry routine: leave empty if not used
  168. userin:
  169.     ret
  170.  
  171. ;User-defined exit routine: leave empty if not used
  172. userout:
  173.     ret
  174.  
  175. ;
  176. ;Screen print function
  177. scrnpr:
  178.                 ; <== Insert your own code here
  179.     call    print
  180.     db    cr,lf
  181.     db    'Screen-print function not supported.',cr,lf,lf
  182.     db    0
  183.                 ; <== End of your own code
  184. spare:
  185.     ret
  186.  
  187.  
  188. ;Get a character from the modem: return in HL
  189. ; It is not necessary to test for status
  190. mchin:
  191.     push    bc
  192.                 ; <== Insert your own code here
  193.     in0    a,(iport)    ; to get the character in A
  194.                 ; <== End of your own code
  195.     ld    l,a        ; put in HL
  196.     ld    h,0
  197.     or    a        ; set/clear Z
  198.     pop    bc
  199.     ret
  200.  
  201. ;Send a character to the modem
  202. mchout:
  203.     ld    hl,2        ; get the character
  204.     add    hl,sp
  205.     ld    a,(hl)        ; in A
  206.                 ; <== Insert your own code here
  207.     out0    (oport),a
  208.                 ; <== End of your own code
  209.     ret            ; done
  210.  
  211. ;Test for output ready: return TRUE (1) in HL if ok
  212. mordy:
  213.                 ; <== Insert your own code here
  214.  
  215.     ld    hl,00h        ; assume not ready for now
  216.     in0    a,(mstat)    
  217.     in0    a,(mstat)    ; do twice for valid DCD
  218.     and    mdsnd
  219.     jr    z,mordy1    ; still not ready
  220.     inc    hl        ; ready, so set HL
  221.  
  222. mordy1:                ; <== End of your own code
  223.     ld    a,l        ; set/clear Z
  224.     or    a
  225.     ret
  226.  
  227. ;Test for character at modem: return TRUE (1) in HL if so
  228. mirdy:
  229.                 ; <== Insert your own code here
  230.  
  231.     ld    hl,00h        ; assume not ready for now
  232.     in0    a,(mstat)    
  233.     in0    a,(mstat)    ; do twice for valid DCD
  234.     and    mdrcv
  235.     jr    z,mirdy1    ; still not ready
  236.     inc    hl        ; ready, so set HL
  237.  
  238. mirdy1:                ; <== End of your own code
  239.  
  240.                 ; <== End of your own code
  241.     ld    a,l        ; set/clear Z
  242.     or    a
  243.     ret
  244.  
  245. ;Send a break to the modem: leave empty if your system can't do it
  246. sndbrk:
  247.                 ; <== Insert your own code here
  248.                 ; to go to 'break' level
  249.                 ; <== End of your own code
  250.     ld    hl,300
  251.     call    waithlms    ; wait 300 mS
  252.  
  253.                 ; <== Insert your own code here
  254.                 ; to restore
  255.                 ; <== End of your own code
  256.     ret
  257.  
  258. ;Test UART flags for error: return TRUE (1) in HL if error
  259. mdmerr:
  260.                 ; <== Insert your own code here
  261.  
  262.     xor    a        ; not yet implemented
  263.  
  264.                 ; <== End of your own code
  265.     ld    a,l        ; set/clear Z
  266.     or    a
  267.     ret
  268.  
  269. ;Turn DTR (and RTS) ON. (reset)
  270. dtron:
  271.                 ; <== Insert your own code here
  272.  
  273.     in0    a,(cport)
  274.     and    0efh        ; RTS on
  275.     out0    (cport),a
  276.  
  277.       if    dtrfx
  278.  
  279.     call    dtrstat        ; pull control latch
  280.     ld    a,10111111b    ; mask off DTR bit
  281.     and    b        ; and it out
  282.     ld    b,a
  283.     ld    a,0ffh        ; set up for write
  284.     ld    hl,(1)        ; get address of BIOS
  285.     ld    l,3fh        ; add offset for control latch
  286.     ld    de,dtrdone
  287.     push    de        ; save return vector
  288.     jp    (hl)        ; go to the latch routine
  289.  
  290.       endif
  291.  
  292.       if not dtrfx
  293.     ret
  294.       endif
  295.                 ; <== End of your own code
  296.  
  297. ;Turn DTR (and RTS) OFF. (set)
  298. dtroff:
  299.                 ; <== Insert your own code here
  300.  
  301.     in0    a,(cport)
  302.     or    10h        ; RTS off
  303.     out0    (cport),a
  304.  
  305.       if    dtrfx
  306.  
  307.     call    dtrstat        ; pull control latch
  308.     ld    a,01000000b    ; mask off DTR bit
  309.     or    b        ; or it in
  310.     ld    b,a
  311.     ld    a,0ffh        ; set up for write
  312.     ld    hl,(1)        ; get address of BIOS
  313.     ld    l,3fh        ; add offset for control latch
  314.     ld    de,dtrdone
  315.     push    de        ; save return vector
  316.     jp    (hl)        ; go to the latch routine
  317.  
  318.       endif
  319.  
  320.       if not dtrfx
  321.     ret
  322.       endif
  323.  
  324.                 ; <== End of your own code
  325. dtrdone:
  326.     ret
  327.  
  328. ;Needed to prevent changes to other control latch registers.
  329.  
  330.       if    dtrfx
  331. dtrstat:
  332.     xor    a
  333.     ld    hl,(1)        ; get address of BIOS
  334.     ld    l,3fh        ; add offset of control latch
  335.     jp    (hl)        ; go get status
  336.  
  337.       endif
  338.  
  339. ;Initialise the UART
  340. init:
  341.     ld    hl,2        ; get parameters
  342.     add    hl,sp
  343.     ex    de,hl
  344.     call    getparm        ; in HL
  345.     ld    (brate),hl    ; baud rate
  346.     call    getparm
  347.     ld    (parity),hl    ; parity
  348.     call    getparm
  349.     ld    (data),hl    ; data bits
  350.     call    getparm
  351.     ld    (stop),hl    ; stop bits
  352.  
  353.                 ; <== Insert your own code here
  354.  
  355.     call    initsio        
  356.     call    setbaud        ; go set baud
  357. ;;    call    setprty        ; "  "   parity
  358. ;;    call    setstop        ; "  "   stop bits
  359. ;;    call    wlength        ; "  "   word length
  360.  
  361.     call    print
  362.     db    cr,lf,0
  363.  
  364.     ret            ; continue
  365.  
  366.  
  367. initsio:            ; using values below
  368.     in0    a,(cport)
  369.     and    0efh        ; RTS on
  370.     or    68h        ; enable xmit, receive; clear errors
  371.     out0    (cport),a
  372.  
  373.     ret
  374.  
  375.  
  376. setbaud:      
  377.     ld    a,(brate)    ; get BRATE into A
  378.     ld    e,a        ; and DE
  379.     ld    d,0
  380.     ld    hl,divisors    ; get offset into baudrate divisor table
  381.     add    hl,de
  382.     ld    a,(hl)        ; fetch code
  383.     or    a        ; 00h means upsupported code
  384.     jr    z,sbexit    ; exit if bad
  385.     out0    (bport),a    ; else set baud
  386.     ld    a,(brate)    ; tell zmp it's ok
  387.     ld    (mspeed),a
  388. sbexit:
  389.     ret
  390.  
  391. divisors:
  392.  
  393.       if cpu12        ; 12.288 MHz clock
  394.     db    00h, 0eh, 00h    ; 0 = 110 baud    1 = 300 baud    2 = 450 baud
  395.     db    0dh, 00h, 06h    ; 3 = 600 baud    4 = 710 baud    5 = 1200 baud
  396.     db    05h, 04h, 03h    ; 6 = 2400 baud    7 = 4800 baud    8 = 9600 baud
  397.     db    02h        ; 9 = 19200 baud
  398.       endif
  399.  
  400.       if cpu9        ; 9.216 MHz clock
  401.     db    00h, 26h, 00h    ; 0 = 110 baud    1 = 300 baud    2 = 450 baud
  402.     db    25h, 00h, 24h    ; 3 = 600 baud    4 = 710 baud    5 = 1200 baud
  403.     db    23h, 22h, 21h    ; 6 = 2400 baud    7 = 4800 baud    8 = 9600 baud
  404.     db    20h        ; 9 = 19200 baud
  405.       endif
  406.  
  407.       if cpu6        ; 6.144 MHz clock
  408.     db    00h, 0dh, 00h    ; 0 = 110 baud    1 = 300 baud    2 = 450 baud
  409.     db    06h, 00h, 05h    ; 3 = 600 baud    4 = 710 baud    5 = 1200 baud
  410.     db    04h, 03h, 02h    ; 6 = 2400 baud    7 = 4800 baud    8 = 9600 baud
  411.     db    01h        ; 9 = 19200 baud
  412.       endif
  413.  
  414.     db    0,0,0        ; 10 = 38400 baud  11 = 57600 baud
  415.                 ; 12 = 76800 baud
  416.  
  417.  
  418. ;        Parity is controlled by bit 1 of CPORT and
  419. ;        bit 4 of BPORT as follows:
  420. ;
  421. ;                BPORT       CPORT
  422. ;           Parity    Bit 4       Bit 1
  423. ;                 Off          -          0
  424. ;              Odd      1         1
  425. ;             Even      0         1
  426. ;
  427.  
  428. setprty:
  429. ;;    ld    a,(parity)    ; get parity into A
  430. ;;    cp    'E'
  431. ;;    jr    z,prevn        ; even
  432. ;;    cp    'O'
  433. ;;    jr    z,prodd        ; odd
  434. ;;
  435. ;;                ; else assume none
  436. ;;proff:    in0    a,(cport)
  437. ;;    and    0fdh        ; reset bit 1
  438. ;;    push    af        ; save
  439. ;;    in0    a,(bport)
  440. ;;    jr    prnxt
  441. ;;
  442. ;;prevn:    in0    a,(cport)
  443. ;;    or    02h        ; set bit 1
  444. ;;    push    af        ; save
  445. ;;    in0    a,(bport)
  446. ;;    and    0efh        ; reset bit 4
  447. ;;    jr    prnxt
  448. ;;
  449. ;;prodd:    in0    a,(cport)
  450. ;;    or    02h        ; set bit 1
  451. ;;    push    af        ; save
  452. ;;    in0    a,(bport)
  453. ;;    or    10h        ; set bit 4
  454. ;;
  455. ;;prnxt:    
  456. ;;    out0    (bport),a    ; set for (even) or (odd)
  457. ;;    pop    af
  458. ;;    out0    (cport),a    ; set for (even/odd) or (none)
  459. ;;    call    initsio        ; reset the UART
  460.  
  461.     ret
  462.  
  463. ;        The number of stop bits is controlled by bit
  464. ;        0 of CPORT, as follows:
  465. ;
  466. ;            Stop bits       Bit 0
  467. ;            1         0
  468. ;            2         1
  469. ;
  470.  
  471. ;;setstop:
  472. ;;    ld    a,(stop)    ; get stopbits into A
  473. ;;    cp    2
  474. ;;    jr    z,stop2        ; two
  475. ;;
  476. ;;                ; assume one
  477. ;;stop1:    in0    a,(cport)
  478. ;;    and    0feh        ; reset bit 0
  479. ;;    jr    ssnxt
  480. ;;
  481. ;;stop2:    in0    a,(cport)
  482. ;;    or    01h        ; set bit 0
  483. ;;
  484. ;;ssnxt:    out0    (cport),a
  485. ;;    call    initsio        ; reset the UART
  486.  
  487.     ret
  488.  
  489. ;        The number of bits per character is controlled by
  490. ;        bit 2 of CPORT as follows:
  491. ;
  492. ;            BPC        Bit 2
  493. ;             7          0
  494. ;             8          1
  495. ;
  496.  
  497. ;;wlength:
  498. ;;    ld    a,(data)    ; get word length
  499. ;;    cp    7
  500. ;;    jr    z,wlen7        ; 7
  501. ;;
  502. ;;                ; assume 8
  503. ;;wlen8:    in0    a,(cport)
  504. ;;    or    04h        ; set bit 2
  505. ;;    jr    wlnxt
  506. ;;
  507. ;;wlen7:    in0    a,(cport)
  508. ;;    and    0fbh        ; reset bit 2
  509. ;;
  510. ;;wlnxt:    out0    (cport),a
  511. ;;    call    initsio        ; reset the UART
  512.  
  513.     ret
  514.  
  515.  
  516.                 ; <== End of your own code
  517.     ret
  518.  
  519. brate:    ds    2        ; baud rate:
  520.                 ; 0 = 110 baud    1 = 300 baud    2 = 450 baud
  521.                 ; 3 = 600 baud    4 = 710 baud    5 = 1200 baud
  522.                 ; 6 = 2400 baud    7 = 4800 baud    8 = 9600 baud
  523.                 ; 9 = 19200 baud
  524. parity:    ds    2        ; parity (will be 'N', 'E' or 'O')
  525. data:    ds    2        ; data bits (will be 7 or 8)
  526. stop:    ds    2        ; stop bits (will be 1 or 2)
  527.  
  528.  
  529. ;****************************************************************************
  530. ; Video terminal sequences: these are for Televideo 950 -- Modify as you wish
  531.  
  532. ;Cursor addressing: 
  533. cursadd:
  534.     ld    hl,2        ; get parameters
  535.     add    hl,sp
  536.     ex    de,hl
  537.     call    getparm        ; in HL
  538.     ld    (row),hl    ; row
  539.     call    getparm
  540.     ld    (col),hl    ; column
  541.                 ; <== Insert your own code here
  542.                 ; using values in row and col
  543.     call    print
  544.     db    esc,'=',0    ; ADM-3A leadin
  545.     ld    a,(row)        ; row first
  546.     add    a,' '        ; add offset
  547.     call    cout
  548.     ld    a,(col)        ; same for column
  549.     add    a,' '
  550.     call    cout
  551.                 ; <== end of your own code
  552.     ret
  553.  
  554. row:    ds    2        ; row
  555. col:    ds    2        ; column
  556.  
  557.  
  558. ;Clear screen:
  559. cls:
  560.     call    print
  561.     db    01ah,0
  562.     ret
  563.  
  564. ;Highlight on:
  565. invon:
  566.     call    print
  567.     db    esc,')',0
  568.     ret
  569.  
  570. ;Highlight off:
  571. invoff:
  572.     call    print
  573.     db    esc,'(',0
  574.     ret
  575.  
  576. ;Turn off cursor:
  577. hide:
  578.     call    print
  579.     db    esc,'.0',0
  580.     ret
  581.  
  582. ;Turn on cursor:
  583. show:
  584.     call    print
  585.     db    esc,'.2',0
  586.     ret
  587.  
  588. ;Save cursor position:
  589. savecu:
  590.     ret
  591.  
  592. ;Restore cursor position:
  593. rescu:
  594.     ret
  595.  
  596. ;****************************************************************************
  597.  
  598. ;Service modem interrupt:
  599. mint:
  600.     ret            ; my system doesn't need this
  601.  
  602. ;Initialise interrupt vectors:
  603. invec:
  604.     ret            ; ditto
  605.  
  606. ;De-initialise interrupt vectors:
  607. dinvec:
  608.     ret            ; ditto
  609.  
  610. ;****************** End of user-defined code ********************************
  611. ; Don't change anything below this point.  We needed some assembly language
  612. ; stuff for speed, and this seemed like a good place to put it.
  613.  
  614. ;Modem character test for 100 ms
  615. mrd:
  616.     push    bc        ; save bc
  617.     ld    bc,100        ; set limit
  618. mrd1:
  619.     call    mirdy        ; char at modem?
  620.     jr    nz,mrd2        ; yes, exit
  621.     ld    hl,1        ; else wait 1ms
  622.     call    waithlms
  623.     dec    bc        ; loop till done
  624.     ld    a,b
  625.     or    c
  626.     jr    nz,mrd1
  627.     ld    hl,0        ; none there, result=0
  628.     xor    a
  629. mrd2:
  630.     pop    bc
  631.     ret
  632.  
  633. ; Inline print routine: destroys A and HL
  634.  
  635. print:
  636.     ex    (sp),hl        ; get address of string
  637. ploop:
  638.     ld    a,(hl)        ; get next
  639.     inc    hl        ; bump pointer
  640.     or    a        ; done if zero
  641.     jr    z,pdone
  642.     call    cout        ; else print
  643.     jr    ploop        ; and loop
  644. pdone:
  645.     ex    (sp),hl        ; restore return address
  646.     ret            ; and quit
  647.  
  648. ;
  649. ;Output a character in A to the console
  650. ;
  651. cout:
  652.     push    bc        ; save regs
  653.     push    de
  654.     push    hl
  655.     ld    e,a        ; character to E
  656.     ld    c,2
  657.     call    bdos        ; print it
  658.     pop    hl
  659.     pop    de
  660.     pop    bc
  661.     ret
  662.  
  663. ;Wait(seconds)
  664. wait:
  665.     ld    hl,2
  666.     add    hl,sp
  667.     ex    de,hl        ; get delay size
  668.     call    getparm
  669.                 ; fall thru to..
  670. ;Wait seconds in HL
  671. waithls:
  672.     push    bc        ; save bc
  673.     push    de        ; de
  674.     push    ix        ; and ix
  675.     ld    ix,0        ; then point ix to 0
  676.                 ; so we don't upset memory-mapped i/o
  677.  
  678. ;Calculate values for loop constants. Need to have two loops to avoid
  679. ;   16-bit overflow with clock speeds above 9 MHz.
  680.  
  681. outerval    equ    (clkspd / 10) + 1
  682. innerval    equ    (6667 / outerval) * clkspd
  683.  
  684. wait10:
  685.     ld    b,outerval
  686.  
  687. wait11:
  688.     ld    de,innerval
  689.  
  690. wait12:
  691.     bit    0,(ix)        ; time-wasters
  692.     bit    0,(ix)
  693.     bit    0,(ix)        ; 20 T-states each
  694.     bit    0,(ix)
  695.     bit    0,(ix)
  696.     bit    0,(ix)
  697.     dec    de
  698.     ld    a,e
  699.     ld    a,d
  700.     or    e
  701.     jr    nz,wait12    ; 150 T-states per inner loop
  702.     djnz    wait11        ; decrement outer loop
  703.     dec    hl        ; ok, decrement count in hl
  704.     ld    a,h
  705.     or    l
  706.     jr    nz,wait10
  707.     pop    ix        ; done -- restore ix
  708.     pop    de        ; de
  709.     pop    bc        ; and bc
  710.     ret
  711.  
  712. ;Wait milliseconds
  713. mswait:
  714.     ld    hl,2
  715.     add    hl,sp
  716.     ex    de,hl        ; get delay size
  717.     call    getparm
  718.                 ; fall thru to..
  719. ;Wait milliseconds in HL
  720. waithlms:
  721.     push    de
  722. w1ms0:
  723.     ld    de,39 * clkspd
  724. w1ms1:
  725.     dec    de
  726.     ld    a,d
  727.     or    e
  728.     jr    nz,w1ms1
  729.     dec    hl
  730.     ld    a,h
  731.     or    l
  732.     jr    nz,w1ms0
  733.     pop    de
  734.     ret
  735.  
  736. ;Get next parameter from (de) into hl
  737. getparm:
  738.     ex    de,hl        ; get address into hl
  739.     ld    e,(hl)        ; get lo
  740.     inc    hl
  741.     ld    d,(hl)        ; then hi
  742.     inc    hl        ; bump for next
  743.     ex    de,hl        ; result in hl, address still in de
  744.     ret
  745.  
  746. ;Get address of user-defined variables
  747.  
  748. getvars:
  749.     ld    hl,uservars
  750.     ret
  751.  
  752. uservars:
  753.     dw    overdrive    ; .OVR etc. drive/user
  754.     dw    overuser
  755.  
  756.  
  757.      if    ($ - codebgn) gt ovsize
  758. toobig:    jp    errval        ; Overlay too large!
  759.      endif
  760.  
  761.     end
  762.