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-AM01.Z80 < prev    next >
Text File  |  1991-02-02  |  22KB  |  949 lines

  1.  .comment \
  2.  
  3.     zmp 1.4 overlay, version 1.0
  4.     computer: ampro lb+
  5.     terminal: wyse 50   (optional)
  6.  
  7.     - works with or without nzcom present.
  8.     - displays baud rate, data bits, stop bits and parity in the
  9.       wyse 50's host field (top line, above scrollable screen)
  10.           if you set the equate hostline true. otherwise these are
  11.       just shown on your screen when set.
  12.     - provides a dtrexit equate which, when set true, will prompt
  13.       you to see if you want DTR signal turned off when you exit
  14.       ZMP. i have an old bell dataphone 1200 modem, and the only
  15.       way i've found to keep it from answering my phone automatically
  16.       when i don't want it to is to keep DTR off except when in a
  17.       modem program. DTR is automatically turned on on entry to ZMP
  18.       in any case. the prompt allows you to exit a terminal session 
  19.       temporarily to your o/s level for whatever reason, without
  20.       disconnecting your session.
  21.     - screen print function not currently implemented.
  22.     - be sure to set ALL config equates (in praticular the disk/user
  23.       for overlay files).
  24.  
  25.                         al grabauskas
  26.                         12/6/88
  27.  
  28.             i'm reachable at:    lillipute z-nodes 1&2
  29.                         (312) 649-1730
  30.                         (312) 664-1730
  31.  
  32.                         the advocate
  33.                         (312) 939-4411
  34.  
  35. \
  36.  
  37. ;-----------------------------------------------------------------------------
  38. ;
  39. ;    Sample Overlay for ZMP (Z-Modem Program)
  40. ;
  41. ;    Name    ZMO-BLNK.Z80
  42. ;
  43. ;    Dated Sep 14, 1988
  44. ;
  45. ;    Written by -
  46. ;      Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia.
  47. ;
  48. ;    Modified to ZMP v1.2 standard rjm 15/9/88
  49. ;    Modified to ZMP v1.3 standard rjm 11/10/88
  50. ;    Modified to ZMP v1.4 standard rjm 20/11/88
  51. ;
  52. ;
  53. ;-----------------------------------------------------------------------------
  54. ;
  55. ;
  56. ;    System-dependent code overlay for ZMODEM
  57. ;
  58. ;
  59. ;
  60. ;    Insert your own code as necessary in this file. Code contained herein
  61. ; has been written in Z80 code for use with M80 or SLR. Assemble as follows:
  62. ;
  63. ;    SLR ZMO-xx01/h
  64. ;    MLOAD ZMP.COM=ZMODEM.COM,ZMO-xx01.HEX
  65. ; or
  66. ;    M80 =ZMO-xx01.Z80
  67. ;    RELHEX ZMO-xx01
  68. ;    MLOAD ZMP.COM=ZMODEM.COM,ZMO-xx01.HEX
  69. ;
  70. ;
  71. ;       (Don't use L80 without changing the source for assembly as a
  72. ;         cseg file.)
  73. ;
  74. ;-----------------------------------------------------------------------------
  75. ;
  76. ;
  77. ; Notes on modifying this file:
  78. ;
  79. ;    C requires that functions do not change either index register (IX or IY).
  80. ; If your overlay requires either of these to be changed, ensure they are
  81. ; restored to the original values on return.
  82. ;    Since collecting parameters from C functions can be tricky, only change
  83. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  84. ; table at the start. Do NOT modify the entry/exit sections of each
  85. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  86. ;    Apart from defining modem functions, this file also defines terminal
  87. ; characteristics. Examples provided are for ADM-3A (with a few of my own
  88. ; additions). Modify to suit your own terminal. An inline print routine
  89. ; is provided for printing strings in the usual way: usage is
  90. ;
  91. ;    call    print
  92. ;    db    'required string',0
  93. ;
  94. ;-----------------------------------------------------------------------------
  95. ;
  96. ;
  97. ;    Don't forget to set your clock speed at the clkspd variable.
  98. ;
  99. ;
  100. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  101. ; you will have to contact me for another version. If too many people need 
  102. ; to do it, we haven't allowed enough room.
  103. ;
  104. ; Ron Murray 15/8/88
  105. ;
  106. ;
  107. ;
  108. ;---------------------------------------------------------------------------
  109.  
  110. false    equ    0
  111. true    equ    not false
  112.  
  113. ;------------------------------------------------------------------------------
  114.  
  115. ; User-set variables: 
  116.  
  117. ; configuration equates for ampro overlay
  118. dtrexit    equ    true        ; if true, the userout: routine will prompt
  119.                 ; you to see if you want to turn off DTR
  120.                 ; completely on exiting ZMP. DTR is automati-
  121.                 ; cally turned on when entering ZMP. turning
  122.                 ; DTR off prevents some modems from auto-
  123.                 ; answering the phone. the prompt allows you
  124.                 ; to leave a session temporarily to your o/s
  125.                 ; and not disconnect.
  126.  
  127. hostline    equ    true        ; controls whether your line parameters are
  128.                 ; displayed in the host field of a wyse 
  129.                 ; terminal at all times in ZMP, or if they
  130.                 ; are simply echoed to the screen when set.
  131.  
  132. clkspd    equ    4        ; Processor clock speed in MHz
  133. debug    equ    false        ; to allow debugging of overlay with Z8E etc.
  134. ; end configuration equates for ampro overlay
  135.  
  136. ;Set the following two equates to the drive and user area which will contain
  137. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  138. ;   (null) to locate them on the drive from which ZMP was invoked.
  139.  
  140. overdrive    equ    'F'    ; Drive to find overlay files on ('A'-'P')
  141. overuser    equ    15    ; User area to find files
  142.  
  143. ;------------------------------------------------------------------------------
  144.  
  145.  
  146. ; NOT user-set variables
  147.  
  148. userdef    equ    0145h        ; origin of this overlay
  149.                 ; This address should not change with
  150.                 ; subsequent revisions.
  151. mspeed    equ    03ch        ; location of current baud rate. 
  152. ovsize    equ    0400h        ; max size of this overlay
  153.  
  154. ; ampro definitions
  155.  
  156. ioint    equ    57        ;BIOS call of initialization routine
  157. siob    equ    52h        ;Relative location in bios
  158. siob1    equ    53h        ;*eag*
  159. siob3    equ    55h        ;*eag*
  160. siob5    equ    57h        ;*eag*
  161. ct1    equ    42h        ;*eag*
  162.  
  163. ;    port definitions
  164.  
  165. modctl    equ    8ch        ; modem control port b
  166. moddat    equ    88h        ; modem data port b
  167.  
  168. ;    bit definitions
  169.  
  170. mdrcvb    equ    01h        ; Modem receive ready bit (dav)
  171. mdsndb    equ    04h        ; Modem send ready bit
  172.  
  173. mdparer    equ    010h        ; parity error
  174. mdovrrn    equ    020h        ; overrun error
  175. mdfram    equ    030h        ; framing error
  176. mderrf    equ    mdparer+mdovrrn+mdfram ; *eag*
  177.  
  178. mddtrof    equ    068h        ; turn off dtr, rts
  179. mddtron    equ    0eah        ; restore normal, 8 bits, rts on, etc.
  180.  
  181. ; end ampro specific equates
  182.  
  183. esc    equ    1bh
  184. ctrlq    equ    11h
  185. cr    equ    0dh
  186. lf    equ    0ah
  187. bdos    equ    5
  188.  
  189.     .z80            ; use z80 code
  190.     aseg            ; absolute
  191.  
  192.      if    debug
  193.     org    100h        ; so you can debug it with cebug, zsid, etc
  194.      else
  195.     org    userdef
  196.      endif
  197.  
  198.  
  199. esc    equ    1bh
  200. ctrlq    equ    11h
  201. cr    equ    0dh
  202. lf    equ    0ah
  203. bdos    equ    5
  204.  
  205. codebgn    equ    $
  206.  
  207. ;Jump table for the overlay: do NOT change this
  208. jump_tab:
  209.     jp    scrnpr        ; screen print
  210.     jp    mrd        ; modem read with timeout
  211.     jp    mchin        ; get a character from modem
  212.     jp    mchout        ; send a character to the modem
  213.     jp    mordy        ; test for tx buffer empty
  214.     jp    mirdy        ; test for character received
  215.     jp    sndbrk        ; send break
  216.     jp    cursadd        ; cursor addressing
  217.     jp    cls        ; clear screen
  218.     jp    invon        ; inverse video on
  219.     jp    invoff        ; inverse video off
  220.     jp    hide        ; hide cursor
  221.     jp    show        ; show cursor
  222.     jp    savecu        ; save cursor position
  223.     jp    rescu        ; restore cursor position
  224.     jp    mint        ; service modem interrupt
  225.     jp    invec        ; initialise interrupt vectors
  226.     jp    dinvec        ; de-initialise interrupt vectors
  227.     jp    mdmerr        ; test uart flags for error
  228.     jp    dtron        ; turn DTR on
  229.     jp    dtroff        ; turn DTR OFF
  230.     jp    init        ; initialise uart
  231.     jp    wait        ; wait seconds
  232.     jp    mswait        ; wait milliseconds
  233.     jp    userin        ; user-defined entry routine
  234.     jp    userout        ; user-defined exit routine
  235.     jp    getvars        ; get system variables
  236.  
  237. ; Spare jumps for compatibility with future versions
  238.     jp    spare        ; spare for later use
  239.     jp    spare        ; spare for later use
  240.     jp    spare        ; spare for later use
  241.     jp    spare        ; spare for later use
  242.     jp    spare        ; spare for later use
  243.     jp    spare        ; spare for later use
  244.  
  245. ;
  246. ; Main code starts here
  247. ;
  248. ;Screen print function
  249. scrnpr:
  250.                 ; <== Insert your own code here
  251.     call    print
  252.     db    'This function not supported.',cr,lf,0
  253.                 ; <== End of your own code
  254. spare:
  255.     ret
  256.  
  257. ; User-defined entry routine: leave empty if not needed
  258.  
  259. ;------------------------------------------------------------------------------
  260. ; this is a routine that locates the warm boot address whether nz-com is
  261. ; running or not and stores it at the word biospt. this allows access to 
  262. ; ampro specific offsets in the bios. (note that this is bios base addr+3).
  263. ;
  264. ; note that this assumes the nz-com bios released with nz-src.lbr (vers. 1.4)
  265. ; if that isn't what you have you'll likely need to modify what's below.
  266.  
  267. eyectof    equ    5ah        ; Offset to "NZ-COM" eyecatcher
  268.                 ;   from virtual bios base.
  269. nzceye:    db    'NZ-COM'    ; Eyecatcher to match
  270. eyelen    equ    $-nzceye    ; Length of eyecatcher
  271.  
  272. ; end most likely user mods    ----------------------------------------------
  273.  
  274. userin:
  275.     push    hl
  276.     push    de
  277.     push    bc
  278.     push    af
  279.  
  280.     ld    hl,(1)        ; This is some bios address..
  281.     ld    l,eyectof    ; Hl = ptr to "NZ-COM" eyecatcher
  282.     ld    de,nzceye    ; Ptr to an internal copy of it
  283.     ld    b,eyelen    ; Length
  284.  
  285. nzckloop:
  286.     ld    a,(de)        ; Get a char
  287.     cp    (hl)        ; Compare to char at hl
  288.     jr    nz,nonzc    ; No nz-com
  289.     inc    hl        ; Bump ptr
  290.     inc    de        ; Bump ptr
  291.     dec    b        ; Decrement length
  292.     jr    nz,nzckloop    ; Repeat if apropos
  293.  
  294.     ld    a,(109h)    ; get pointer to ENV descriptor
  295.     ld    l,a
  296.     ld    a,(10ah)
  297.     ld    h,a
  298.     inc    hl        ; bump past jp opcode to console stat vector
  299.     ld    e,(hl)        ; Get real console status vector
  300.     inc    hl
  301.     ld    d,(hl)
  302.     ex    de,hl        ; Put it in hl
  303.     dec    hl        ; Convert to warm boot vector
  304.     dec    hl
  305.     dec    hl
  306.     jr    biosret        ; And return bios addr in biospt
  307.  
  308. nonzc:
  309.     ld    hl,(1)        ; Get original pointer
  310.  
  311. biosret:
  312.     ld    (biospt),hl    ; and save it
  313.     call    initall        ; set up rest of the details
  314.     call    dtron        ; make sure DTR is set
  315.     pop    af        ; Restore regs and return
  316.     pop    bc
  317.     pop    de
  318.     pop    hl
  319.     ret
  320.  
  321. ; User-defined exit routine: leave empty if not needed
  322. userout:
  323.     call    print        ; kill host message display on wyse
  324.     db    esc,'A31',cr,0    ; host msg field = dim underscore
  325.  
  326.      if    dtrexit
  327.     call    print        ; dtr off yet?
  328.     db    'Kill DTR? (default no) ',0
  329.     call    cyn        ; get yes/no answer
  330.     ret    nz        ; not a "yes"
  331.     jp    dtroff        ; do it
  332.      else
  333.     ret
  334.      endif            ; if dtrexit
  335.  
  336. ;
  337. ; Y/N input from console
  338. ;
  339. cyn:
  340.     push    bc        ; save regs
  341.     push    de
  342.     push    hl
  343.     ld    c,1
  344.     call    bdos        ; print it
  345.     or    a,' '        ; make small case
  346.     cp    a,'y'        ; yes?
  347.     pop    hl
  348.     pop    de
  349.     pop    bc
  350.     ret
  351.  
  352. ;Get a character from the modem: return in HL
  353. mchin:
  354.     push    bc
  355.                 ; <== Insert your own code here
  356.  
  357.     in    a,(moddat)    ; in modem data port
  358.  
  359.                 ; <== End of your own code
  360.  
  361.     ld    l,a        ; put in HL
  362.     ld    h,0
  363.     or    a        ; set/clear Z
  364.     pop    bc
  365.     ret
  366.  
  367. ;Send a character to the modem
  368. mchout:
  369.     ld    hl,2        ; get the character
  370.     add    hl,sp
  371.     ld    a,(hl)
  372.                 ; <== Insert your own code here
  373.  
  374.     out    (moddat),a    ; out modem data port
  375.  
  376.                 ; <== End of your own code
  377.     ret            ; done
  378.  
  379. ;Test for output ready: return TRUE (1) in HL if ok
  380. mordy:
  381.                 ; <== Insert your own code here
  382.  
  383.     in    a,(modctl)    ; in modem control port
  384.     and    mdsndb        ; bit to test for send ready
  385.     jr    z,monr        ; modem not ready
  386.     ld    hl,1        ; indicate ready
  387.     jr    mordyret
  388. monr:    ld    hl,0        ; indicate not ready
  389. mordyret:
  390.                 ; <== End of your own code
  391.  
  392.     ld    a,l        ; set/clear Z
  393.     or    a
  394.     ret
  395.  
  396. ;Test for character at modem: return TRUE (1) in HL if so
  397. mirdy:
  398.                 ; <== Insert your own code here
  399.  
  400.     in    a,(modctl)    ; in modem control port
  401.     and    mdrcvb        ; bit to test for receive ready
  402.     jr    z,minr        ; modem not ready
  403.     ld    hl,1        ; indicate ready
  404.     jr    mirdyret
  405. minr:    ld    hl,0        ; indicate not ready
  406. mirdyret:
  407.                 ; <== End of your own code
  408.     ld    a,l        ; set/clear Z
  409.     or    a
  410.     ret
  411.  
  412. ;Send a break to the modem: leave empty if your system can't do it
  413. sndbrk:
  414.                 ; <== Insert your own code here
  415.  
  416.     ld    a,5        ; *eag*
  417.     out    (modctl),a    ; send to the status port
  418.     ld    a,mddtrof    ; turn off dtr, rts, send break
  419.     out    (modctl),a    ; *eag*
  420.  
  421.                 ; <== end of your own code
  422.  
  423.     ld    hl,300        ; wait 300 mS
  424.     call    waithlms
  425.  
  426.                 ; <== insert your own code here
  427.                 ; To restore
  428.  
  429.  
  430.                 ; <== End of your own code
  431.     ret
  432.  
  433.  
  434. ;Test UART flags for error: return TRUE (1) in HL if error.
  435. mdmerr:
  436.                 ; <== Insert your own code here
  437.  
  438.     in    a,(modctl)    ; in modem control port
  439.     and    mderrf        ; bits to test: parity, overrun, framing
  440.     jr    z,mnerr        ; no error
  441.     ld    hl,1        ; indicate error
  442.     jr    merrret
  443. mnerr:    ld    hl,0        ; indicate no error
  444. merrret:
  445.                 ; <== End of your own code
  446.     ld    a,l        ; set/clear Z
  447.     or    a
  448.     ret
  449.  
  450. ;Turn DTR ON
  451. dtron:
  452.                 ; <== Insert your own code here
  453.  
  454.     ld    a,5        ; *eag*
  455.     out    (modctl),a    ; *eag*
  456.     ld    a,mddtron    ; restore normal, 8 bits, rts on, etc.
  457.     out    (modctl),a    ; *eag*
  458.  
  459.                 ; <== End of your own code
  460.     ret
  461.  
  462. ;Turn DTR OFF
  463. dtroff:
  464.                 ; <== Insert your own code here
  465.  
  466.     ld    a,5        ; *eag*
  467.     out    (modctl),a    ; send to the status port
  468.     ld    a,mddtrof    ; turn off dtr, rts, send break
  469.     out    (modctl),a    ; *eag*
  470.  
  471.                 ; <== End of your own code
  472.     ret
  473.  
  474.  
  475.  
  476. ;Initialise the uart
  477.  
  478. init:
  479.  
  480.     ld    hl,2        ; get parameters
  481.     add    hl,sp
  482.     ex    de,hl
  483.     call    getparm        ; in HL
  484.     ld    (brate),hl    ; baud rate
  485.     call    getparm
  486.     ld    (parity),hl    ; parity
  487.     call    getparm
  488.     ld    (data),hl    ; data bits (BINARY 7 or 8)
  489.     call    getparm
  490.     ld    (stop),hl    ; stop bits (BINARY 1 or 2)
  491.  
  492.  
  493.                 ; <== Insert your own code here
  494.                 ; using values below
  495. ;*eag*    begin insertion
  496.  
  497. initall:            ; alternate entry point for userin
  498.     ld    de,(brate)    ; Code to de
  499.     ld    hl,baudtb    ; Offset into table
  500.     add    hl,de
  501.     ld    a,(hl)        ; Fetch code
  502.     or    a        ; 0? (means unsupported code)
  503.     jp    z,pbexit    ; exit if so
  504.     ld    (bsave1),a    ; Save it
  505.  
  506.     ld    a,(brate)    ; get brate
  507.     ld    (mspeed),a    ; don't forget to load mspeed with the
  508.                 ; current brate value if the new rate is
  509.                 ; valid. 
  510.  
  511.     ld    hl,baudtx    ; Offset into second table
  512.     add    hl,de
  513.     ld    a,(hl)        ; Get second value
  514.     ld    (bsave2),a    ; Save it also
  515.  
  516.     ld    hl,(biospt)    ; Get location of bios
  517.     ld    l,ct1        ; Add 42h to reach ct1 in i/o table
  518.     ld    a,47h
  519.     ld    (hl),a
  520.     inc    hl        ; Move to next location
  521.     ld    a,(bsave1)    ; Get first table value
  522.     ld    (hl),a        ; Store it
  523.     ld    a,(bsave2)    ; Get second table value
  524.     ld    b,a        ; And save it
  525.     ld    l,siob1        ; Move ahead to siob+1 values
  526.     ld    a,(hl)        ; Get current value
  527.     and    3fh
  528.     or    b        ; Or it with second value
  529.     ld    (hl),a        ; Store it in work table
  530.     inc    hl
  531.     inc    hl
  532.     ld    a,(hl)        ; Get last value and make
  533.     or    80h        ; Sure msb is set
  534.     ld    (hl),a        ; Put it back in working table
  535.  
  536.     ld    a,(data)    ; 7 or 8 data bits
  537.     sbc    a,7        ; kill offset
  538.     ld    h,0
  539.     ld    l,a
  540.     ld    de,bittbl    ; Load lookup table
  541.     add    hl,de        ; get bit pattern
  542.     ld    c,(hl)        ; Save selection value
  543.     ld    hl,(biospt)    ; Get bios address
  544.     ld    l,siob3        ; Move to siob+3
  545.     ld    a,(hl)        ; Wr5 info
  546.     and    9fh        ; Mask
  547.     or    c        ; Add selection
  548.     ld    (hl),a        ; Store it
  549.     ld    a,c        ; Get selection
  550.     rla
  551.     ld    c,a        ; Shift selection left
  552.     ld    l,siob5        ; Move to siob+5
  553.     ld    a,(hl)        ; Wr3 info
  554.     and    3fh        ; Mask
  555.     or    c
  556.     ld    (hl),a        ; Store it
  557.  
  558.     ld    a,(parity)    ; get parity
  559.     cp    'N'
  560.     jr    z,parno
  561.     cp    'E'
  562.     jr    z,parev
  563.     cp    'O'
  564.     jr    z,parod
  565.     jp    pbexit
  566.  
  567. parno:    ld    c,00h
  568.     jr    setpar
  569.  
  570. parev:    ld    c,03h
  571.     jr    setpar
  572.  
  573. parod:    ld    c,01h
  574.  
  575. setpar:    ld    hl,(biospt)    ; Get bios address
  576.     ld    l,siob1        ; Go to siob+1
  577.     ld    a,(hl)
  578.     and    0fch
  579.     or    c
  580.     ld    (hl),a
  581.  
  582.     ld    a,(stop)    ; stop bits
  583.     sbc    a,1        ; kill offset
  584.     ld    h,0
  585.     ld    l,a
  586.     ld    de,stptbl    ; bit patterns
  587.     add    hl,de        ; ptr to bit pattern
  588.     ld    c,(hl)        ; get result
  589.     ld    hl,(biospt)    ; Get bios address
  590.     ld    l,53h        ; Shift to bios+1
  591.     ld    a,(hl)
  592.     and    0f3h
  593.     or    c
  594.     ld    (hl),a
  595.  
  596.     ld    hl,(brate)    ; get baud code
  597.     sla    l        ; *2
  598.     sla    l        ; *4
  599.     ld    de,pbauds    ; base of printable baud table
  600.     add    hl,de        ; printable baud
  601.     ld    de,baudshw    ; dest
  602.     ld    bc,4        ; len
  603.     ldir            ; move it
  604.  
  605.     ld    a,(parity)    ; display that
  606.     ld    (parshw),a
  607.  
  608.     ld    a,(data)    ; display that
  609.     add    a,'0'        ; make ascii
  610.     ld    (bitshw),a
  611.  
  612.     ld    a,(stop)    ; display that
  613.     add    a,'0'        ; make ascii
  614.     ld    (stopshw),a
  615.  
  616.     call    print        ; display stuff on wyse
  617.  
  618. ;    the next few lines set the host message field on the wyse-50
  619. ;    to the following string, which displays your currently set
  620. ;    line parameters (baud, bits, parity and stop bits) in a 
  621. ;    permanent host field at the top of your terminal. if hostline
  622. ;    equate is not set true, they will just be shown on the screen
  623. ;    whenever they are set.
  624.  
  625.      if    hostline
  626.     db    esc,'A3p'    ; host msg field = dim underscore
  627.     db    esc,"F"        ; set set message
  628.      endif
  629.  
  630.     db    '          Baud: '
  631. baudshw:
  632.     db    '    '        ; printable baud rate
  633.     db    ' Bits: '
  634. bitshw:
  635.     db    ' '        ; bits per char
  636.     db    ' Parity: '
  637. parshw:
  638.     db    ' '        ; parity
  639.     db    ' Stop: '
  640. stopshw:
  641.     db    ' '        ; stop bits
  642.  
  643.     db    cr,lf,0
  644.  
  645.     jp    ioinit        ; Do the initialization
  646.  
  647. ;*eag*    end insertion
  648.  
  649.                 ; <== End of your own code
  650.     ret
  651.  
  652. ;*eag*    begin insertion
  653.  
  654. ioinit:
  655.  
  656.     ld    a,ioint        ; Offset into bios jump table
  657.     ld    hl,(biospt)    ; Address of bios in hl
  658.     ld    l,a        ; Add offset
  659.     jp    (hl)        ; Go there with auto return
  660.  
  661. ;    routine to handle unsupported baud rates
  662.  
  663. pbexit:
  664.     call print
  665.     db    'Unsupported.',cr,lf,0
  666.     ret
  667.  
  668. ; table of baud rate divisors for supported rates
  669.  
  670. baudtb:    db    0,208,139    ; 110,300,450
  671.     db    208,0,104    ; 600,710,1200
  672.     db    52,26,13,0    ; 2400,4800,9600,19200
  673.  
  674. baudtx:    db    0,80h,80h
  675.     db    40h,0,40h
  676.     db    40h,40h,40h,0
  677.  
  678. pbauds:    db    ' 110',' 300',' 450',' 600',' 710'
  679.     db    '1200','2400','4800','9600',' 19K'
  680.  
  681. bsave1:    db    0        ; Current setting from
  682. bsave2:    db    0        ; Tables - uninitialized
  683.  
  684. bittbl:    db    20h,60h        ; 7 or 8 data bits
  685.  
  686. stptbl:    db    04h,0ch        ; 1 or 2 stop bits
  687.  
  688. biospt:    dw    0
  689.  
  690. ;*eag*    end insertion
  691.  
  692. ;--------------------------------------------------------------------------
  693.  
  694. stop:    dw    1        ; stop bits
  695. parity:    dw    'N'        ; parity
  696. data:    dw    8        ; data bits
  697. brate:    dw    5        ; baud rate:
  698.  
  699. ;--------------------------------------------------------------------------
  700. ;Values of brate for each baud rate
  701. ;
  702. ; baud rate    brate
  703. ;
  704. ;   110         0
  705. ;   300         1
  706. ;   450         2
  707. ;   600         3
  708. ;   710         4
  709. ;  1200         5
  710. ;  2400         6
  711. ;  4800         7
  712. ;  9600         8
  713. ; 19200         9
  714. ; 38400        10
  715. ; 57600         11
  716. ; 76800         12
  717. ;
  718.  
  719. ;****************************************************************************
  720. ;Video terminal sequences: these are for ADM-3A: Modify as you wish
  721. ;Cursor addressing: 
  722. cursadd:
  723.     ld    hl,2        ; get parameters
  724.     add    hl,sp
  725.     ex    de,hl
  726.     call    getparm        ; in HL
  727.     ld    (row),hl    ; row
  728.     call    getparm
  729.     ld    (col),hl    ; column
  730.                 ; <== Insert your own code here
  731.                 ; using values in row and col
  732.     call    print
  733.     db    esc,'=',0    ; ADM-3A leadin
  734.     ld    a,(row)        ; row first
  735.     add    a,' '        ; add offset
  736.     call    cout
  737.     ld    a,(col)        ; sane for column
  738.     add    a,' '
  739.     call    cout
  740.                 ; <== end of your own code
  741.     ret
  742.  
  743. row:    ds    2        ; row
  744. col:    ds    2        ; column
  745.  
  746. ;clear screen:
  747. cls:
  748.     call    print
  749.     db    01ah,0
  750.     ret
  751.  
  752. ;inverse video on:
  753. invon:
  754.     call    print
  755.     db    esc,')',0
  756.     ret
  757.  
  758. ;inverse video off:
  759. invoff:
  760.     call    print
  761.     db    esc,'(',0
  762.     ret
  763.  
  764. ;turn off cursor:
  765. hide:
  766.     call    print
  767.     db    esc,'`0',0    ; wyse 50 cursor off
  768.     ret
  769.  
  770. ;turn on cursor:
  771. show:
  772.     call    print
  773.     db    esc,'`1',0    ; wyse 50 cursor on
  774.     ret
  775.  
  776. ;save cursor position:
  777. savecu:
  778.     ret
  779.  
  780. ;restore cursor position:
  781. rescu:
  782.     ret
  783.  
  784. ;****************************************************************************
  785.  
  786. ;Service modem interrupt:
  787. mint:
  788.     ret            ; my system doesn't need this
  789.  
  790. ;Initialise interrupt vectors:
  791. invec:
  792.     ret            ; ditto
  793.  
  794. ;De-initialise interrupt vectors:
  795. dinvec:
  796.     ret            ; ditto
  797.  
  798. ;****************** End of user-defined code ********************************
  799. ;        Do not change anything below here.
  800.  
  801. ;Modem character test for 100 ms
  802. mrd:
  803.     push    bc        ; save bc
  804.     ld    bc,100        ; set limit
  805. mrd1:
  806.     call    mirdy        ; char at modem?
  807.     jr    nz,mrd2        ; yes, exit
  808.     ld    hl,1        ; else wait 1ms
  809.     call    waithlms
  810.     dec    bc        ; loop till done
  811.     ld    a,b
  812.     or    c
  813.     jr    nz,mrd1
  814.     ld    hl,0        ; none there, result=0
  815.     xor    a
  816. mrd2:
  817.     pop    bc
  818.     ret
  819.  
  820. ; Inline print routine: destroys A and HL
  821.  
  822. print:
  823.     ex    (sp),hl        ; get address of string
  824. ploop:
  825.     ld    a,(hl)        ; get next
  826.     inc    hl        ; bump pointer
  827.     or    a        ; done if zero
  828.     jr    z,pdone
  829.     call    cout        ; else print
  830.     jr    ploop        ; and loop
  831. pdone:
  832.     ex    (sp),hl        ; restore return address
  833.     ret            ; and quit
  834.  
  835. ;
  836. ;Output a character in A to the console
  837. ;
  838. cout:
  839.     push    bc        ; save regs
  840.     push    de
  841.     push    hl
  842.     ld    e,a        ; character to E
  843.     ld    c,2
  844.     call    bdos        ; print it
  845.     pop    hl
  846.     pop    de
  847.     pop    bc
  848.     ret
  849.  
  850. ;Wait(seconds)
  851. wait:
  852.     ld    hl,2
  853.     add    hl,sp
  854.     ex    de,hl        ; get delay size
  855.     call    getparm
  856.                 ; fall thru to..
  857. ;Wait seconds in HL
  858. waithls:
  859.     push    bc        ; save bc
  860.     push    de        ; de
  861.     push    ix        ; and ix
  862.     ld    ix,0        ; then point ix to 0
  863.                 ; so we don't upset memory-mapped i/o
  864.  
  865. ;Calculate values for loop constants. Need to have two loops to avoid
  866. ;   16-bit overflow with clock speeds above 9 MHz.
  867.  
  868. outerval    equ    (clkspd / 10) + 1
  869. innerval    equ    (6667 / outerval) * clkspd
  870.  
  871. wait10:
  872.     ld    b,outerval
  873.  
  874. wait11:
  875.     ld    de,innerval
  876.  
  877. wait12:
  878.     bit    0,(ix)        ; time-wasters
  879.     bit    0,(ix)
  880.     bit    0,(ix)        ; 20 T-states each
  881.     bit    0,(ix)
  882.     bit    0,(ix)
  883.     bit    0,(ix)
  884.     dec    de
  885.     ld    a,e
  886.     ld    a,d
  887.     or    e
  888.     jr    nz,wait12    ; 150 T-states per inner loop
  889.     djnz    wait11        ; decrement outer loop
  890.     dec    hl        ; ok, decrement count in hl
  891.     ld    a,h
  892.     or    l
  893.     jr    nz,wait10
  894.     pop    ix        ; done -- restore ix
  895.     pop    de        ; de
  896.     pop    bc        ; and bc
  897.     ret
  898.  
  899. ;Wait milliseconds
  900. mswait:
  901.     ld    hl,2
  902.     add    hl,sp
  903.     ex    de,hl        ; get delay size
  904.     call    getparm
  905.                 ; fall thru to..
  906. ;Wait milliseconds in HL
  907. waithlms:
  908.     push    de
  909. w1ms0:
  910.     ld    de,39 * clkspd
  911. w1ms1:
  912.     dec    de
  913.     ld    a,d
  914.     or    e
  915.     jr    nz,w1ms1
  916.     dec    hl
  917.     ld    a,h
  918.     or    l
  919.     jr    nz,w1ms0
  920.     pop    de
  921.     ret
  922.  
  923. ;Get next parameter from (de) into hl
  924. getparm:
  925.     ex    de,hl        ; get address into hl
  926.     ld    e,(hl)        ; get lo
  927.     inc    hl
  928.     ld    d,(hl)        ; then hi
  929.     inc    hl        ; bump for next
  930.     ex    de,hl        ; result in hl, address still in de
  931.     ret
  932.  
  933. ;Get address of user-defined variables
  934.  
  935. getvars:
  936.     ld    hl,uservars
  937.     ret
  938.  
  939. uservars:
  940.     dw    overdrive    ; .OVR etc. drive/user
  941.     dw    overuser
  942.  
  943.  
  944.      if    ($ - codebgn) gt ovsize
  945. toobig:    jp    errval        ; Overlay too large!
  946.      endif
  947.  
  948.     end
  949.