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-H805.Z80 < prev    next >
Text File  |  2000-06-30  |  19KB  |  743 lines

  1.     TITLE    System-dependent installation overlay for ZMP
  2.     SUBTTL    Author: Ron Murray
  3.  
  4. ; System-dependent installation overlay for ZMP
  5. ; Author: Ron Murray
  6.  
  7. ;    Name    ZMPOVH89.Z80
  8.  
  9. ;    Dated Nov 11, 1988
  10.  
  11. ;    Written by - Ron Murray, c/o Z-Node 62, 061-9-450-0200
  12. ;             Perth, Western Australia.
  13.  
  14. ;    Modified by - Ted May,  116B Laval St., Vanier, Ont., Canada
  15. ;                (613)741-0862
  16. ;                for the H89-H19 terminal
  17. ;                with a Hays compatable 2400 baud modem
  18. ;                (US Robotics Courier 2400)
  19.  
  20. ; 89/04/12 - Modified to ZMP v1.5        - George Conover
  21. ;    Modified to ZMP v1.4 standard Ron Murray Nov 11, 88
  22. ;    Modified to ZMP v1.3 standard Ron Murray Oct 11, 88
  23. ;    Modified to ZMP v1.2 standard Ron Murray Sept 15, 88
  24. ;
  25. ;-----------------------------------------------------------------------
  26. ;
  27. ;    System-dependent code overlay for ZMODEM
  28. ;
  29. ;   Insert your own code as  necessary    in  this  file.  Code  contained
  30. ; herein  has been written in Z80 code for use with M80 or SLR programs.
  31. ; Assemble as follows:
  32.  
  33. ;    SLR ZMO-MH01/h
  34. ;    MLOAD ZMP.COM=ZMODEM.COM,ZMO-MH01.HEX
  35. ;  or
  36. ;    M80 =ZMO-MH01.Z80
  37. ;    RELHEX ZMO-MH01
  38. ;    MLOAD ZMP.COM=ZMODEM.COM,ZMO-MH01.HEX
  39.  
  40.  
  41. ; (Don't use L80 without changing the source  for  assembly  as  a  CSEG
  42. ; file.)
  43.  
  44. ;-----------------------------------------------------------------------
  45.  
  46. ;    Code contained herein has been written in Z80 code for use with M80.
  47. ; Once assembled, convert to hex with RELHEX and use MLOAD to overlay it
  48. ; over the main ZMPX.COM file to produce your very own ZMP.COM.
  49.  
  50. ;-----------------------------------------------------------------------
  51.  
  52. ; Notes on modifying this file:
  53.  
  54. ;    Hi-Tech C requires that functions do not change either index register
  55. ; (IX or IY). If your overlay requires either of these to be changed, ensure
  56. ; they are restored to their original values on return.
  57. ;    Since collecting parameters from C functions can be tricky, only change
  58. ; the parts marked 'Insert your own code here'.  Do NOT modify the jump
  59. ; table at the start.  Do NOT modify the entry/exit sections of each
  60. ; function.  Do NOT pass 'GO'.  Do NOT collect $200.
  61. ;    Apart from defining modem functions, this file also defines terminal
  62. ; characteristics.  Most have been set up for ADM-3A (with a few of my own
  63. ; additions).  Modify to suit your own terminal.  An inline print routine
  64. ; is provided for printing strings in the usual way: usage is
  65.  
  66. ;    CALL    PRINT
  67. ;    DEFB    'required string',0
  68.  
  69. ;    Don't forget to set your clock speed at the clkspd variable.
  70.  
  71. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  72. ; you will have to re-compile the whole thing.  Good luck.  You might try
  73. ; informing us if you need to do this: if too many people need to do it, we
  74. ; haven't allowed enough room.
  75.  
  76. ; Ron Murray Aug 15, 88
  77.  
  78. ;-----------------------------------------------------------------------
  79.  
  80. NO    EQU    0
  81. YES    EQU    NOT NO
  82.  
  83.  
  84. CLKSPD    EQU    2        ; Processor clock speed in MHz
  85. DEBUG    EQU    NO        ; To allow debugging of overlay with
  86.                 ; Z8E etc.
  87.  
  88. ; Set the following two equates to the drive and user area which will
  89. ; contain ZMP's .OVR files, .CFG file, .FON file and .HLP file.  Set
  90. ; both to zero (null) to locate them on the drive from which ZMP was
  91. ; invoked.
  92.  
  93. OVERDRIVE EQU    0        ; Drive to find overlay files on ('A'-'P')
  94. OVERUSER EQU    0        ; User area to find files
  95.  
  96. ;-----------------------------------------------------------------------
  97.  
  98. ; NOT user-set variables
  99.  
  100.  
  101. USERDEF    EQU    0145H        ; Origin of this overlay.  This address
  102.                 ; should not change with subsequent
  103.                 ; revisions.
  104. MSPEED    EQU    003CH        ; Location of current baud rate.
  105. OVSIZE    EQU    0400H        ; Maximum size of this overlay
  106.  
  107.     .Z80            ; use z80 code
  108.  
  109.     ASEG            ; absolute
  110.  
  111.      IF    DEBUG
  112.     ORG    100H        ; So you can debug it with CEBUG, ZSID, etc.
  113.      ELSE
  114.     ORG    USERDEF
  115.      ENDIF
  116.  
  117. ESC    EQU    1BH
  118. CTRLQ    EQU    11H
  119. CR    EQU    0DH
  120. LF    EQU    0AH
  121. BDOS    EQU    5
  122.  
  123. ; The following define the H8/89 SIO Modem Port addresses...
  124.  
  125. DPORT    EQU    0D8H        ; Data port (base port)
  126. LSPDIV    EQU    DPORT        ; LSP baud rate divisor if DLAB set
  127. IENREG    EQU    DPORT+1        ; Interupt Enable register
  128. MSPDIV    EQU    DPORT+1        ; MSP baud rate divisor if DLAB set
  129. IIDREG    EQU    DPORT+2        ; Interrupt identification register (r/o)
  130. LCPORT    EQU    DPORT+3        ; Line Control register
  131. MCPORT    EQU    DPORT+4        ; Modem Control register
  132. LSPORT    EQU    DPORT+5        ; Line Status register
  133. MSPORT    EQU    DPORT+6        ; Modem Status register
  134.  
  135. ; Line Control (LCPORT) bits - - - - - - - - - - - - - - - - -
  136.  
  137. WLS0    EQU    00000001B    ; Word length select 0
  138. WLS1    EQU    00000010B    ; Word length select 1
  139. STB    EQU    00000100B    ; Stop bit select
  140. PEN    EQU    00001000B    ; Parity Enable (0 for disabled)
  141. PES    EQU    00010000B    ; Even parity select (0 for odd)
  142. SPE    EQU    00100000B    ; Stick parity
  143. BRKS    EQU    01000000B    ; Break set (set break)
  144. DLAB    EQU    10000000B    ; Divisor Latch Access Bit
  145.  
  146. ; Modem Control (MCPORT) bits - - - - - - - - - - - - - - - - -
  147.  
  148. MCBASE    EQU    00000000B    ; Basic setup: no DTR or RTS
  149. DTR    EQU    00000001B    ; Data Terminal Ready
  150. RTS    EQU    00000010B    ; Request To Sent
  151. OUT1     EQU    00000100B    ; Aux Output #1
  152. OUT2     EQU    00001000B    ; Aux Output #2
  153. TSTLP    EQU    00010000B    ; Sets 8250 Test Loop condition
  154.  
  155. ; Line Status (LSPORT) bits - - - - - - - - - - - - - - - - - -
  156.  
  157. DAV    EQU    00000001B    ; Data Available (and bit to test)
  158. ORUN    EQU    00000010B    ; Overrun Error (rec'd was char overwritten
  159. RPERR    EQU    00000100B    ; Parity Error
  160. FERR    EQU    00001000B    ; Framing Error (checks for valid stop bit)
  161. BRKD    EQU    00010000B    ; Break Detect
  162. TBMT    EQU    00100000B    ; Transmit Buffer Empty (and bit to test)
  163. TSRE    EQU    01000000B    ; Transmit Shift Register Empty (r/o)
  164.  
  165. ; Modem Status (MSPORT) bits - - - - - - - - - - - - - - - - - -
  166.  
  167. DCTS    EQU    00000001B    ; Delta Clear To Send
  168. DDSR    EQU    00000010B    ; Delta Data Set Ready
  169. TERI    EQU    00000100B    ; Trailing Edge Ring Indicator
  170. DRLSD    EQU    00001000B    ; Delta Receive Line Signal Detect
  171. CTS    EQU    00010000B    ; Clear To Send
  172. DSR    EQU    00100000B    ; Data Set Ready
  173. RDET    EQU    01000000B    ; Ring Detect
  174. RLSD    EQU    10000000B    ; Carrier Detect
  175. RESET    EQU    00000001B    ; Output Reset Code
  176.  
  177. ; Baud rate divisor values - - - - - - - - - - - - - - - - - - -
  178.  
  179. BD110    EQU    1047        ; 110    bps
  180. BD300    EQU    384        ; 300    bps
  181. BD450    EQU    256        ; 450    bps
  182. BD600    EQU    192        ; 600    bps
  183. BD710    EQU    162        ; 710    bps
  184. BD1200    EQU    96        ; 1200   bps
  185. BD2400    EQU    48        ; 2400   bps
  186. BD4800    EQU    24        ; 4800   bps
  187. BD9600    EQU    12        ; 9600   bps
  188. BD19200    EQU    6        ; 19,200 bps
  189. BD38400 EQU    3        ; 38,400 bps
  190. BD57600 EQU    2        ; 57,600 bps
  191.  
  192. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  193.  
  194. ;Jump table for the overlay: do NOT change this
  195. JUMPTAB:
  196.     JP    SCRNPR        ; screen print
  197.     JP    MRD        ; modem read with timeout
  198.     JP    MCHIN        ; get a character from modem
  199.     JP    MCHOUT        ; send a character to the modem
  200.     JP    MORDY        ; test for tx buffer empty
  201.     JP    MIRDY        ; test for character received
  202.     JP    SNDBRK        ; send break
  203.     JP    CURSADD        ; cursor addressing
  204.     JP    CLS        ; clear screen
  205.     JP    INVON        ; inverse video on
  206.     JP    INVOFF        ; inverse video off
  207.     JP    HIDE        ; hide cursor
  208.     JP    SHOW        ; show cursor
  209.     JP    SAVECU        ; save cursor position
  210.     JP    RESCU        ; restore cursor position
  211.     JP    MINT        ; service modem interrupt
  212.     JP    INVEC        ; initialise interrupt vectors
  213.     JP    DINVEC        ; de-initialise interrupt vectors
  214.     JP    MDMERR        ; test uart flags for error
  215.     JP    DTRON        ; turn DTR on
  216.     JP    DTROFF        ; turn DTR OFF
  217.     JP    INIT        ; initialise uart
  218.     JP    WAIT        ; wait seconds
  219.     JP    MSWAIT        ; wait milliseconds
  220.     JP    USERIN        ; User-defined entry routine
  221.     JP    USEROUT        ; User-defined exit routine
  222.     JP    GETVARS        ; Get system variables
  223.       JP    SETPORT        ; Set port (0 or 1)
  224. ;
  225. ; Spare jumps for compatibility with future versions
  226. ;
  227.     JP    SPARE        ; Spares for later use
  228.     JP    SPARE        ; Spares for later use
  229.     JP    SPARE        ; Spares for later use
  230.     JP    SPARE        ; spares for later use
  231.     JP    SPARE        ; spares for later use
  232.     JP    SPARE        ; spares for later use
  233.  
  234.  
  235. ; Main code starts here
  236.  
  237.  
  238. VERSN:    DEFB    '===> Ver. 1.5.1520.24.11.88.ZMPOVL <==='
  239.  
  240. ; Screen print function
  241.  
  242. SCRNPR:
  243.                 ; <== Insert your own code here
  244.     CALL    PRINT
  245.     DB    'This function not supported.',CR,LF,0
  246.                 ; <== End of your own code
  247. SPARE:    RET
  248.  
  249. ; User-defined entry routine: leave empty if not needed
  250.  
  251. USERIN:    RET
  252.  
  253. ; User-defined exit routine: leave empty if not needed
  254.  
  255. USEROUT:RET
  256.  
  257.  
  258. ; Get a character from the modem: return in HL
  259. ; (It is not necessary to test for status)
  260.  
  261. MCHIN:
  262.                 ; <== Insert your own code here
  263.     IN    A,(DPORT)    ; to get the character in A
  264.                 ; <== End of your own code
  265.     LD    L,A        ; put in HL
  266.     LD    H,0
  267.     OR    A        ; set/clear Z
  268.     RET
  269.  
  270. ;Send a character to the modem
  271.  
  272. MCHOUT:
  273.     LD    HL,2        ; get the character
  274.     ADD    HL,SP
  275.     LD    A,(HL)        ; in A
  276.                 ; <== Insert your own code here
  277.     OUT    (DPORT),A
  278.                 ; <== End of your own code
  279.     RET            ; done
  280.  
  281. ;Test for output ready: return TRUE (1) in HL if ok
  282.  
  283. MORDY:
  284.                 ; <== Insert your own code here
  285.     LD    HL,0        ; Assume that the Transmit Buffer is full
  286.     IN    A,(LSPORT)    ; Get Line Status
  287.     AND    TBMT        ; Is the Transmit Buffer Empty?
  288.     JR    Z,TB.BUSY    ; No, skip
  289.     LD    L,1        ; Yes, HL = 1 (TRUE)
  290. TB.BUSY:            ; <== End of your own code
  291.     LD    A,L        ; Set/clear Z
  292.     OR    A
  293.     RET
  294.  
  295. ;Test for character at modem: return TRUE (1) in HL if so
  296.  
  297. MIRDY:
  298.                 ; <== Insert your own code here
  299.     LD    HL,0        ; Assume that no data is available
  300.     IN    A,(LSPORT)    ; Get Line Status
  301.     AND    DAV        ; Is Data Available?
  302.     JR    Z,NO.DAV    ; No, skip
  303.     LD    L,1        ; Yes, HL = 1 (TRUE)
  304. NO.DAV:                ; <== End of your own code
  305.     LD    A,L        ; set/clear Z
  306.     OR    A
  307.     RET
  308.  
  309. ;Send a break to the modem: leave empty if your system can't do it
  310.  
  311. SNDBRK:
  312.                 ; <== Insert your own code here
  313.  
  314. ; This routine sends a 300 ms Break Tone and sets DTR low for the 
  315. ; same length of time to disconnect the modem at both ends
  316.  
  317.     XOR    A        ; Clear reg A to
  318.     OUT    (MCPORT),A    ; Set DTR and RTS low
  319.     LD    A,BRKS        ; Set Break Tone
  320.     OUT    (LCPORT),A    ; to go to 'break' level
  321.         
  322.  
  323.     LD    HL,300        ; wait 300 ms
  324.     CALL    WAITHLMS
  325.  
  326. DSP    EQU    $+1        ; Inline code modification (data, stop, parity)
  327.     LD    A,WLS0+WLS1    ; Set 8 data bits, 1 stop bit, no parity
  328.     OUT    (LCPORT),A
  329.     LD    A,DTR        ; Set DTR for proper Modem output level
  330.     OUT    (MCPORT),A
  331.                 ; to restore
  332.                 ; <== End of your own code
  333.     RET
  334.  
  335. ;Test UART flags for error: return TRUE (1) in HL if error
  336.  
  337. MDMERR:
  338.                 ; <== Insert your own code here
  339.     LD    HL,0        ; Set HL = FALSE (0)
  340.                 ; <== End of your own code
  341.     LD    A,L        ; set/clear Z
  342.     OR    A
  343.     RET
  344.  
  345. ;Turn DTR (and optionally RTS) ON.
  346.  
  347. DTRON:
  348.                 ; <== Insert your own code here
  349.     LD    A,DTR        ; Set DTR
  350.     OUT    (MCPORT),A
  351.                 ; <== End of your own code
  352.     RET
  353.  
  354. ;Turn DTR ( and RTS?) OFF
  355.  
  356. DTROFF:
  357.                 ; <== Insert your own code here
  358.     XOR    A        ; Clear reg A to
  359.     OUT    (MCPORT),A    ; Set DTR and RTS low
  360.                 ; <== End of your own code
  361.     RET
  362.  
  363. ;Initialise the UART
  364.  
  365. INIT:
  366.     LD    HL,2        ; get parameters
  367.     ADD    HL,SP
  368.     EX    DE,HL
  369.     CALL    GETPARM        ; in HL
  370.     LD    (BRATE),HL    ; baud rate
  371.     CALL    GETPARM
  372.     LD    (PARITY),HL    ; parity
  373.     CALL    GETPARM
  374.     LD    (DATA),HL    ; data bits
  375.     CALL    GETPARM
  376.     LD    (STOP),HL    ; stop bits
  377.                 ; <== Insert your own code here
  378.     DI            ; Disable CPU Interrupts
  379.     LD    A,(BRATE)    ; A = Baud rate number (see table below)
  380.     CP    11+1        ; Allow speeds to 57,600 bps
  381.     JR    NC,BADRATE    ; Skip if invalid baud rate
  382.     LD    (MSPEED),A    ;  else save for current BRATE
  383.     LD    E,A
  384.     LD    D,0        ; DE = Baud rate number
  385.     LD    HL,BAUD.RATES    ; HL -> Start of baudrate divisor table    
  386.     ADD    HL,DE        ; Add it twice, each
  387.     ADD    HL,DE        ;  Divisor value occupies two bytes
  388.     LD    A,(HL)        ; HL -> Desired divisor value, load HL
  389.     INC    HL        ;     indirect through HL [(HLIHL)]
  390.     LD    H,(HL)
  391.     LD    L,A        ; HL = Divisor value
  392.     LD    A,D        ; A = 0
  393.     OUT    (IENREG),A    ; Disable 8250 interrupts
  394.     LD    A,DLAB        ; Set DLAB so we can use the baud rates
  395.     OUT    (LCPORT),A    ;  divisors
  396.     LD    A,L        ; A = LSP of divisor
  397.     OUT    (LSPDIV),A    ; Write divisor's "LSP"
  398.     LD    A,H        ; A = MSP of divisor
  399.     OUT    (MSPDIV),A    ; Write divisor's "MSP"
  400.     LD    A,(DATA)    ; Get data bits count (7 or 8)
  401.     CP    7        ; Is it 7 data bits?
  402.     LD    A,10B        ; Assume it is
  403.     JR    Z,IS7BITS    ; Yes, skip
  404.     LD    A,11B        ; No, is 8 data bits, A = 11B
  405. IS7BITS:
  406.     LD    D,A        ; Save data bits
  407.     LD    A,(STOP)    ; Get number of desired stop bits (1 or 2)
  408.     CP    1        ; Want one stop bit?
  409.     LD    A,0        ; Assume so
  410.     JR    Z,ONE.STOP    ; Yes, skip
  411.     LD    A,100B        ; No, set bit 2 - 2 stop bits wanted
  412. ONE.STOP:
  413.     OR    D        ; OR in data bits info
  414.     LD    D,A        ;  and save data bits and stop bit info
  415.     LD    A,(PARITY)    ; Get desired parity indicator (N, E or O)
  416.     LD    E,A        ;  and save it for possible later use
  417.     CP    'N'        ; Want no parity?
  418.     LD    A,D        ; Assume so, A = data, stop, and parity (D,S,P)
  419.     JR    Z,HAVE.BITS    ; Yes, skip
  420.     LD    A,E        ; Get back desired parity indicator
  421.     CP    'E'        ; Want Even parity?
  422.     LD    A,PEN+PES    ; Assume so, set even parity
  423.     OR    D        ;  and OR in data bits and stop bit info
  424.     JR    Z,HAVE.BITS    ; Yes, skip
  425.     LD    A,PEN        ; No, has to be Odd parity, set it
  426.     OR    D        ;  and OR in data bits and stop bit info
  427. HAVE.BITS:
  428.     LD    (DSP),A        ; Set it for resetting after disconnect
  429.     OUT    (LCPORT),A    ; Set desired word, stop and parity
  430.     LD    A,DTR        ; Set DTR for proper MODEM operation
  431.     OUT    (MCPORT),A
  432. BADRATE:            ; Skips above to here if baud rate bad
  433.     EI            ; Restore CPU interrupts
  434.                 ; using values below
  435.                 ; <== End of your own code
  436.     RET
  437.  
  438. STOP:    DEFW    1        ; Stop bits (will be 1 or 2)
  439. PARITY:    DEFW    'N'        ; Parity (will be 'N', 'E' or 'O')
  440. DATA:    DEFW    8        ; Data bits (will be 7 or 8)
  441. BRATE:    DEFW    6        ; Baud rate:
  442.  
  443. ;-----------------------------------------------------------------------
  444.  
  445. ; Values of BRATE for each baud rate
  446.  
  447. ; baud rate    BRATE
  448.  
  449. ;   110      0
  450. ;   300      1
  451. ;   450      2
  452. ;   600      3
  453. ;   710      4
  454. ;  1200      5
  455. ;  2400      6
  456. ;  4800      7
  457. ;  9600      8
  458. ; 19200      9
  459. ; 38400     10
  460. ; 57600     11
  461.  
  462. ;-----------------------------------------------------------------------
  463.  
  464. ; Baud rate divisor table
  465.  
  466. BAUD.RATES:
  467.     DEFW    BD110        ;  0 -    110 baud
  468.     DEFW    BD300        ;  1 -    300
  469.     DEFW    BD450        ;  2 -    450
  470.     DEFW    BD600        ;  3 -    600
  471.     DEFW    BD710        ;  4 -    710
  472.     DEFW    BD1200        ;  5 -  1,200
  473.     DEFW    BD2400        ;  6 -  2,400
  474.     DEFW    BD4800        ;  7 -  4,800
  475.     DEFW    BD9600        ;  8 -  9,600
  476.     DEFW    BD19200        ;  9 - 19,200
  477.     DEFW    BD38400        ; 10 - 38,400
  478.     DEFW    BD57600        ; 11 - 57,600
  479.  
  480. ;
  481. ; Set the port. ZMP supplies either 0 or 1 as a parameter.
  482. ;
  483. setport:
  484.     ld    hl,2        ; get port number
  485.     add    hl,sp
  486.     ex    de,hl
  487.     call    getparm        ; in HL (values are 0 and 1)
  488.  
  489.                 ; <== Insert your own code here
  490.  
  491.                 ; <== End of your own code
  492.     ret
  493. ;****************************************************************************
  494. ;Video terminal sequences: these are for ADM-3A: Modify as you wish
  495. ;Cursor addressing:     (modified for H19/89)
  496.  
  497. CURSADD:
  498.     LD    HL,2        ; get parameters
  499.     ADD    HL,SP
  500.     EX    DE,HL
  501.     CALL    GETPARM        ; in HL
  502.     LD    (ROW),HL    ; row
  503.     CALL    GETPARM
  504.     LD    (COL),HL    ; column
  505.                 ; <== Insert your own code here
  506.                 ; using values in row and col
  507.     CALL    PRINT
  508.     DEFB    ESC,'Y',0    ; H19/89 leadin
  509.     LD    A,(ROW)        ; row first
  510.     ADD    A,' '        ; add offset
  511.     CALL    COUT
  512.     LD    A,(COL)        ; sane for column
  513.     ADD    A,' '
  514.     CALL    COUT
  515.                 ; <== end of your own code
  516.     RET
  517.  
  518. ROW:    DEFS    2        ; row
  519. COL:    DEFS    2        ; column
  520.  
  521.  
  522. ;Clear screen:
  523.  
  524. CLS:
  525.     CALL    PRINT
  526.     DEFB    ESC,'E',0
  527.     RET
  528.  
  529. ;Inverse video on:
  530.  
  531. INVON:
  532.     CALL    PRINT
  533.     DEFB    ESC,'p',0
  534.     RET
  535.  
  536. ;Inverse video off:
  537.  
  538. INVOFF:
  539.     CALL    PRINT
  540.     DEFB    ESC,'q',0
  541.     RET
  542.  
  543. ;Turn off cursor:
  544.  
  545. HIDE:
  546.     CALL    PRINT
  547.     DEFB    ESC,'x5',0
  548.     RET
  549.  
  550. ;Turn on cursor:
  551.  
  552. SHOW:
  553.     CALL    PRINT
  554.     DEFB    ESC,'y5',0
  555.     RET
  556.  
  557. ;Save cursor position:
  558.  
  559. SAVECU:
  560.     CALL    PRINT
  561.     DEFB    ESC,'j',0
  562.     RET
  563.  
  564. ;Restore cursor position:
  565.  
  566. RESCU:
  567.     CALL    PRINT
  568.     DEFB    ESC,'k',0
  569.     RET
  570.  
  571. ;****************************************************************************
  572.  
  573. ;Service modem interrupt:
  574.  
  575. MINT:
  576.     RET            ; my system doesn't need this
  577.  
  578. ;Initialise interrupt vectors:
  579.  
  580. INVEC:
  581.     RET            ; ditto
  582.  
  583. ;De-initialise interrupt vectors:
  584.  
  585. DINVEC:
  586.     RET            ; ditto
  587.  
  588. ;****************** End of user-defined code ********************************
  589. ; Don't change anything below this point. We needed some assembly language
  590. ; stuff for speed, and this seemed like a good place to put it.
  591.  
  592. ;Modem character test for 100 ms
  593.  
  594. MRD:
  595.     PUSH    BC        ; save bc
  596.     LD    BC,100        ; set limit
  597. MRD1:
  598.     CALL    MIRDY        ; char at modem?
  599.     JR    NZ,MRD2        ; yes, exit
  600.     LD    HL,1        ; else wait 1ms
  601.     CALL    WAITHLMS
  602.     DEC    BC        ; loop till done
  603.     LD    A,B
  604.     OR    C
  605.     JR    NZ,MRD1
  606.     LD    HL,0        ; none there, result=0
  607.     XOR    A
  608. MRD2:
  609.     POP    BC
  610.     RET
  611.  
  612. ; Inline print routine: destroys A
  613.  
  614. PRINT:
  615.     EX    (SP),HL        ; get address of string
  616. PLOOP:
  617.     LD    A,(HL)        ; get next
  618.     INC    HL        ; bump pointer
  619.     OR    A        ; done if zero
  620.     JR    Z,PDONE
  621.     CALL    COUT        ; else print
  622.     JR    PLOOP        ; and loop
  623. PDONE:
  624.     EX    (SP),HL        ; restore return address
  625.     RET            ; and quit
  626.  
  627. ;
  628. ;Output a character in A to the console
  629. ;
  630. COUT:
  631.     PUSH    BC        ; save regs
  632.     PUSH    DE
  633.     PUSH    HL
  634.     LD    E,A        ; character to E
  635.     LD    C,2
  636.     CALL    BDOS        ; print it
  637.     POP    HL
  638.     POP    DE
  639.     POP    BC
  640.     RET
  641.  
  642. ;Wait(seconds)
  643.  
  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.  
  652. WAITHLS:
  653.     PUSH    BC        ; Save BC
  654.     PUSH    DE        ; DE
  655.     PUSH    IX        ; And IX
  656.     LD    IX,0        ; Then point IX to 0
  657.                 ; So we don't upset memory-mapped I/O
  658. ;
  659. ; Calculate values for loop constants. Need to have two loops to avoid
  660. ; 16-bit overflow with clock speeds above 9 MHz.
  661. ;
  662. OUTERVAL EQU    (CLKSPD/10)+1
  663. INNERVAL EQU    (6667/OUTERVAL)*CLKSPD
  664. ;
  665. WAIT10:    LD    B,OUTERVAL
  666. ;
  667. WAIT11:    LD    DE,INNERVAL
  668. ;
  669. WAIT12:    BIT    0,(IX)        ; Time-wasters
  670.     BIT    0,(IX)
  671.     BIT    0,(IX)        ; 20 T-states each
  672.     BIT    0,(IX)
  673.     BIT    0,(IX)
  674.     BIT    0,(IX)
  675.     DEC    DE
  676.     LD    A,E
  677.     LD    A,D
  678.     OR    E
  679.     JR    NZ,WAIT12    ; 150 T-states per inner loop
  680.     DJNZ    WAIT11        ; Decrement outer loop
  681.     DEC    HL        ; Ok, decrement count in hl
  682.     LD    A,H
  683.     OR    L
  684.     JR    NZ,WAIT10
  685.     POP    IX        ; Done -- restore ix
  686.     POP    DE        ; De
  687.     POP    BC        ; And bc
  688.     RET
  689.  
  690. ;Wait milliseconds
  691.  
  692. MSWAIT:
  693.     LD    HL,2
  694.     ADD    HL,SP
  695.     EX    DE,HL        ; get delay size
  696.     CALL    GETPARM
  697.                 ; fall thru to..
  698. ;Wait milliseconds in HL
  699.  
  700. WAITHLMS:
  701.     PUSH    DE
  702. W1MS0:
  703.     LD    DE,39 * CLKSPD
  704. W1MS1:
  705.     DEC    DE
  706.     LD    A,D
  707.     OR    E
  708.     JR    NZ,W1MS1
  709.     DEC    HL
  710.     LD    A,H
  711.     OR    L
  712.     JR    NZ,W1MS0
  713.     POP    DE
  714.     RET
  715.  
  716. ;Get next parameter from (de) into hl
  717.  
  718. GETPARM:
  719.     EX    DE,HL        ; get address into hl
  720.     LD    E,(HL)        ; get lo
  721.     INC    HL
  722.     LD    D,(HL)        ; then hi
  723.     INC    HL        ; bump for next
  724.     EX    DE,HL        ; result in hl, address still in de
  725.     RET
  726.  
  727.  
  728. ; Get address of user-defined variables
  729.  
  730. GETVARS:
  731.     LD    HL,USERVARS
  732.     RET
  733.  
  734. USERVARS:
  735.     DEFW    OVERDRIVE    ; OVR etc. drive/user
  736.     DEFW    OVERUSER
  737.  
  738.      IF    ($ - JUMPTAB) GT OVSIZE
  739. TOOBIG:    JP    ERRVAL        ; Overlay too large!
  740.      ENDIF
  741.  
  742.     END
  743.