home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / modem / zmp180b3.z80 < prev    next >
Encoding:
Text File  |  1994-09-02  |  15.4 KB  |  730 lines

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