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-XE04.Z80 < prev    next >
Text File  |  1991-02-02  |  14KB  |  579 lines

  1. ;
  2. ; System-dependent installation overlay for ZMP
  3. ; Author: Ron Murray
  4. ; Xerox/Kaypro overlay written by S.V. Hovater
  5. ; 24 Sep 1988  Email: Houston NW Znode 713-937-8886
  6. ; -- this version sets up the UART.
  7. ;
  8. ; Modified to v1.3 standard rjm 12/10/88
  9. ; Modified to v1.4 standard rjm 11/12/88
  10. ;
  11. ;    Insert your own code as necessary in this file. Code contained herein
  12. ; has been written in Z80 code for use with M80. Once assembled,
  13. ; convert to hex with RELHEX and use MLOAD to overlay it over the main
  14. ; ZMPX.COM file to produce your very own ZMP.COM.
  15. ;
  16. ; Notes on modifying this file:
  17. ;    Hi-Tech C requires that functions do not change either index register
  18. ; (IX or IY). If your overlay requires either of these to be changed, ensure
  19. ; they are restored to their original values on return.
  20. ;    Since collecting parameters from C functions can be tricky, only change
  21. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  22. ; table at the start. Do NOT modify the entry/exit sections of each
  23. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  24. ;    Apart from defining modem functions, this file also defines terminal
  25. ; characteristics. Most have been set up for ADM-3A (with a few of my own
  26. ; additions). Modify to suit your own terminal. An inline print routine
  27. ; is provided for printing strings in the usual way: usage is
  28. ;
  29. ;    call    print
  30. ;    db    'required string',0
  31. ;
  32. ;    Don't forget to set your clock speed at the clkspd variable.
  33. ;
  34. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  35. ; you will have to re-compile the whole thing. Good luck. You might try
  36. ; informing us if you need to do this: if too many people need to do it, we
  37. ; haven't allowed enough room.
  38. ;
  39. ; Ron Murray 15/8/88
  40. ;
  41.  
  42. ;User-set variables:
  43.  
  44. ;Set the following two equates to the drive and user area which will contain
  45. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  46. ;   (null) to locate them on the drive from which ZMP was invoked.
  47.  
  48. overdrive    equ    'A'    ; Drive to find overlay files on ('A'-'P')
  49. overuser    equ    0    ; User area to find files
  50.  
  51. clkspd    equ    4        ; Processor clock speed in MHz
  52. mspeed    equ    003ch        ; Current baud rate: as used by BYE etc
  53.                 ; This MUST be the same as Mspeed in
  54.                 ; ZMP.H
  55.  
  56.  
  57. PORT    equ     04H             ; Xerox base port (data or status)        
  58. MDCTL1  equ     PORT+2          ; Modem control port
  59. MDDATP  equ     PORT            ; Modem data port
  60. MDRCV   equ     01H             ; Modem receive ready
  61. MDSND   equ     04H             ; Modem send ready bit
  62. MDTXE   equ     01H             ; Modem send buffer empty, holding buffer empty
  63. BRPORT  equ     00H             ; 8116 port for baudrate
  64.  
  65.  
  66. userdef    equ    00145h        ; origin of this overlay: get this value
  67.                 ; from the .SYM file produced when ZMP.COM
  68.                 ; is linked
  69. ovsize    equ    0400h        ; max size of this overlay
  70.  
  71.     .z80            ; use z80 code
  72.     aseg            ; absolute
  73.  
  74.     org    userdef
  75.  
  76. esc    equ    1bh
  77. ctrlq    equ    11h
  78. cr    equ    0dh
  79. lf    equ    0ah
  80. bdos    equ    5
  81.  
  82.  
  83. ;Jump table for the overlay: do NOT change this
  84. jump_tab:
  85.     jp    scrnpr        ; screen print
  86.     jp    mrd        ; modem read with timeout
  87.     jp    mchin        ; get a character from modem
  88.     jp    mchout        ; send a character to the modem
  89.     jp    mordy        ; test for tx buffer empty
  90.     jp    mirdy        ; test for character received
  91.     jp    sndbrk        ; send break
  92.     jp    cursadd        ; cursor addressing
  93.     jp    cls        ; clear screen
  94.     jp    invon        ; inverse video on
  95.     jp    invoff        ; inverse video off
  96.     jp    hide        ; hide cursor
  97.     jp    show        ; show cursor
  98.     jp    savecu        ; save cursor position
  99.     jp    rescu        ; restore cursor position
  100.     jp    mint        ; service modem interrupt
  101.     jp    invec        ; initialise interrupt vectors
  102.     jp    dinvec        ; de-initialise interrupt vectors
  103.     jp    mdmerr        ; test uart flags for error
  104.     jp    dtron        ; turn DTR on
  105.     jp    dtroff        ; turn DTR OFF
  106.     jp    init        ; initialise uart
  107.     jp    wait        ; wait seconds
  108.     jp    mswait        ; wait milliseconds
  109.     jp    userin        ; user-defined entry routine
  110.     jp    userout        ; user-defined exit routine
  111.     jp    getvars        ; get system variables
  112. ;
  113.     jp    spare        ; spare for later use
  114.     jp    spare        ; spare for later use
  115.     jp    spare        ; spare for later use
  116.     jp    spare        ; spare for later use
  117.     jp    spare        ; spare for later use
  118.  
  119. ;
  120. ; Main code starts here
  121. ;
  122. codebgn    equ    $
  123. ;
  124. ;Screen print function
  125. scrnpr:
  126.                 ; <== Insert your own code here
  127.     call    print
  128.     db    'This function not supported.',cr,lf,0
  129.                 ; <== End of your own code
  130. spare:
  131.     ret
  132.  
  133. ; User-defined entry routine
  134. userin:
  135.     ret
  136.  
  137. ; User-defined exit routine
  138. userout:
  139.     ret
  140.  
  141. ;Get a character from the modem: return in HL
  142. ; It is not necessary to test for status
  143. mchin:
  144.     push    bc
  145. ;-- Add code specific to Xerox
  146.         in     a,(MDDATP)       ; get the character in A
  147. ;-- End of this block of machine specific code
  148.     ld    l,a        ; put in HL
  149.     ld    h,0
  150.     or    a        ; set/clear Z
  151.     pop    bc
  152.     ret
  153.  
  154. ;Send a character to the modem
  155. mchout:
  156.     ld    hl,2        ; get the character
  157.     add    hl,sp
  158.     ld    a,(hl)        ; in A
  159. ;-- Add code specific to Xerox
  160.         push    bc
  161.         ld      c,a
  162. mchout1:
  163.         in      a,(MDCTL1)
  164.         and     MDSND
  165.         jr      z,mchout1
  166.         ld      a,c
  167.         out     (MDDATP),a
  168.         pop     bc
  169. ;-- End of this block of machine specific code
  170.     ret            ; done
  171.  
  172. ;Test for output ready: return TRUE (1) in HL if ok
  173. mordy:
  174. ;-- Add code specific to Xerox 
  175.         in      a,(MDCTL1)
  176.         and     MDTXE
  177.         jr      z,mordyx
  178.         ld      l,1
  179.         ld      h,0
  180. mordyx:
  181. ;-- End of this block of machine specific code
  182.     ld    a,l        ; set/clear Z
  183.     or    a
  184.     ret
  185.  
  186. ;Test for character at modem: return TRUE (1) in HL if so
  187. mirdy:
  188. ;-- Add code specific to Xerox
  189.         in      a,(MDCTL1)
  190.         and     MDRCV
  191.         jr      z,mirdy1
  192.         ld      l,1
  193.         jr      mirdyx
  194. mirdy1:
  195.         ld      l,0
  196. mirdyx:
  197.         ld      h,00H
  198. ;-- End of this block of machine specific code
  199.     ld    a,l        ; set/clear Z
  200.     or    a
  201.     ret
  202.  
  203. ;Send a break to the modem: leave empty if your system can't do it
  204. sndbrk:
  205. ;-- Add code specific to Xerox
  206.         ld      a,5
  207.         out     (MDCTL1),a       ; Send to the status port
  208.         ld      a,0F8H           ; DTR normal, send break tone
  209.         out     (MDCTL1),a
  210. ;-- End of this block of machine specific code
  211.     ld    hl,300
  212.     call    waithlms    ; wait 300 mS
  213. ;-- Add code specific to Xerox
  214.         ld      a,5             ; Restore normal, 8 bits, DTR on, etc.
  215.         out     (MDCTL1),a
  216.         ld      a,0E8H
  217.         out     (MDCTL1),a
  218. ;-- End of this block of machine specific code
  219.     ret
  220.  
  221. ;Test UART flags for error: return TRUE (1) in HL if error
  222. mdmerr:
  223. ;-- Add code specific to Xerox
  224.         ld      a,010H          ; Register 0, reset interrupts
  225.         out     (MDCTL1),a
  226.         in      a,(MDCTL1)
  227. ;-- End of this block of machine specific code
  228.     ld    a,l        ; set/clear Z
  229.     or    a
  230.     ret
  231.  
  232. ;Turn DTR (and optionally RTS) ON.
  233. dtron:
  234. ;-- Add code specific to Xerox
  235.         ld      a,05H
  236.         out     (MDCTL1),a
  237.         ld      a,0E8H
  238.         out     (MDCTL1),a
  239. ;-- End of this block of machine specific code
  240.     ret
  241.  
  242. ;Turn DTR ( and RTS?) OFF
  243. dtroff:
  244. ;-- Add code specific to Xerox
  245.         ld      a,05H
  246.         out     (MDCTL1),a
  247.         ld      a,078H
  248.         out     (MDCTL1),a
  249. ;-- End of this block of machine specific code
  250.     ret
  251.  
  252. ;Initialise the UART
  253. init:
  254.     ld    hl,2        ; get parameters
  255.     add    hl,sp
  256.     ex    de,hl
  257.     call    getparm        ; in HL
  258.     ld    (brate),hl    ; baud rate
  259.     call    getparm
  260.     ld    (parity),hl    ; parity
  261.     call    getparm
  262.     ld    (data),hl    ; data bits
  263.     call    getparm
  264.     ld    (stop),hl    ; stop bits
  265.                 ; <== Insert your own code here
  266. ;-- Add code specific to Xerox
  267.         push    bc
  268.         ld      a,0             ; select register
  269.         out     (MDCTL1),a
  270.         ld      a,018H           ; Throw out of mode
  271.         out     (MDCTL1),a
  272.         ld      a,04H           ; Select register
  273.         out     (MDCTL1),a   
  274.         ld      a,044H           ; Set ASCII parameters (44=1, 4C=2 stop)
  275.         out     (MDCTL1),a
  276.         ld      a,03H           ; Select register
  277.         out     (MDCTL1),a 
  278.         ld      a,0C1H           ; Enable receive
  279.         out     (MDCTL1),a
  280.         ld      a,05H           ; Select register
  281.         out     (MDCTL1),a
  282.         ld      a,0EAH          ; enable send, 'DTR', RTS'
  283.         out     (MDCTL1),a
  284.  
  285.         ld      a,(MSPEED)      ; Get the selected value
  286.         cp      1               ; 300 bps
  287.         jp      z,OK300
  288.         cp      5               ; 1200 bps
  289.         jp      z,OK1200
  290.         cp      6               ; 2400 bps
  291.         jp      z,OK2400
  292.         cp      8               ; 9600 bps
  293.         jp      z,OK9600
  294.         cp      9               ; 19.2k bps
  295.         jp      z,OK19200         
  296.         jr      setbrx        ; not valid
  297. OK300:
  298.         ld      a,1             ; MSPEED 300 bps value
  299.         ld      b,BD300
  300.         jp      LOADED
  301. OK1200:
  302.         ld      a,5             ; 
  303.         ld      b,BD1200
  304.         jp      LOADED
  305. OK2400:
  306.         ld      a,6
  307.         ld      b,BD2400
  308.         jp      LOADED
  309. OK9600:
  310.         ld      a,8
  311.         ld      b,BD9600
  312.         jp      LOADED
  313. OK19200:
  314.         ld      a,9
  315.         ld      b,BD19200
  316. LOADED:
  317.         ld      (MSPEED),a      ; change time-to-send baudrate
  318.         ld      a,b
  319.         out     (BRPORT),a
  320.     ld    a,(brate)    ; tell zmp it's ok
  321.     ld    (mspeed),a
  322. setbrx:
  323.         pop     bc
  324. ;-- End of this block of machine specific code
  325.     ret
  326.  
  327. BD300   equ     5
  328. BD1200  equ     7
  329. BD2400  equ    10
  330. BD9600  equ    14
  331. BD19200 equ    15
  332.                 ; using values below
  333.  
  334.                 ; <== End of your own code
  335.     ret
  336.  
  337. brate:    ds    2        ; baud rate:
  338.                 ; 0 = 110 baud    1 = 300 baud    2 = 450 baud
  339.                 ; 3 = 600 baud    4 = 710 baud    5 = 1200 baud
  340.                 ; 6 = 2400 baud    7 = 4800 baud    8 = 9600 baud
  341.                 ; 9 = 19200 baud
  342. parity:    ds    2        ; parity (will be 'N', 'E' or 'O')
  343. data:    ds    2        ; data bits (will be 7 or 8)
  344. stop:    ds    2        ; stop bits (will be 1 or 2)
  345.  
  346.  
  347. ;****************************************************************************
  348. ;Video terminal sequences: these are for ADM-3A: Modify as you wish
  349. ;Cursor addressing: 
  350. cursadd:
  351.     ld    hl,2        ; get parameters
  352.     add    hl,sp
  353.     ex    de,hl
  354.     call    getparm        ; in HL
  355.     ld    (row),hl    ; row
  356.     call    getparm
  357.     ld    (col),hl    ; column
  358.                 ; <== Insert your own code here
  359.                 ; using values in row and col
  360.     call    print
  361.     db    esc,'=',0    ; ADM-3A leadin
  362.     ld    a,(row)        ; row first
  363.     add    a,' '        ; add offset
  364.     call    cout
  365.     ld    a,(col)        ; sane for column
  366.     add    a,' '
  367.     call    cout
  368.                 ; <== end of your own code
  369.     ret
  370.  
  371. row:    ds    2        ; row
  372. col:    ds    2        ; column
  373.  
  374.  
  375. ;Clear screen:
  376. cls:
  377.     call    print
  378.     db    01ah,0
  379.     ret
  380.  
  381. ;Inverse video on:
  382. invon:
  383.     call    print
  384.     db    esc,')',0
  385.     ret
  386.  
  387. ;Inverse video off:
  388. invoff:
  389.     call    print
  390.     db    esc,'(',0
  391.     ret
  392.  
  393. ;Turn off cursor:
  394. hide:
  395.     call    print
  396.     db    esc,'z',0
  397.     ret
  398.  
  399. ;Turn on cursor:
  400. show:
  401.     call    print
  402.     db    esc,'v',0
  403.     ret
  404.  
  405. ;Save cursor position:
  406. savecu:
  407.     ret
  408.  
  409. ;Restore cursor position:
  410. rescu:
  411.     ret
  412.  
  413. ;****************************************************************************
  414.  
  415. ;Service modem interrupt:
  416. mint:
  417.     ret            ; my system doesn't need this
  418.  
  419. ;Initialise interrupt vectors:
  420. invec:
  421.     ret            ; ditto
  422.  
  423. ;De-initialise interrupt vectors:
  424. dinvec:
  425.     ret            ; ditto
  426.  
  427. ;****************** End of user-defined code ********************************
  428. ; Don't change anything below this point. We needed some assembly language
  429. ; stuff for speed, and this seemed like a good place to put it.
  430.  
  431. ;Modem character test for 100 ms
  432. mrd:
  433.     push    bc        ; save bc
  434.     ld    bc,100        ; set limit
  435. mrd1:
  436.     call    mirdy        ; char at modem?
  437.     jr    nz,mrd2        ; yes, exit
  438.     ld    hl,1        ; else wait 1ms
  439.     call    waithlms
  440.     dec    bc        ; loop till done
  441.     ld    a,b
  442.     or    c
  443.     jr    nz,mrd1
  444.     ld    hl,0        ; none there, result=0
  445.     xor    a
  446. mrd2:
  447.     pop    bc
  448.     ret
  449.  
  450. ; Inline print routine: destroys A and HL
  451.  
  452. print:
  453.     ex    (sp),hl        ; get address of string
  454. ploop:
  455.     ld    a,(hl)        ; get next
  456.     inc    hl        ; bump pointer
  457.     or    a        ; done if zero
  458.     jr    z,pdone
  459.     call    cout        ; else print
  460.     jr    ploop        ; and loop
  461. pdone:
  462.     ex    (sp),hl        ; restore return address
  463.     ret            ; and quit
  464.  
  465. ;
  466. ;Output a character in A to the console
  467. ;
  468. cout:
  469.     push    bc        ; save regs
  470.     push    de
  471.     push    hl
  472.     ld    e,a        ; character to E
  473.     ld    c,2
  474.     call    bdos        ; print it
  475.     pop    hl
  476.     pop    de
  477.     pop    bc
  478.     ret
  479.  
  480. ;Wait(seconds)
  481. wait:
  482.     ld    hl,2
  483.     add    hl,sp
  484.     ex    de,hl        ; get delay size
  485.     call    getparm
  486.                 ; fall thru to..
  487. ;Wait seconds in HL
  488. waithls:
  489.     push    bc        ; save bc
  490.     push    de        ; de
  491.     push    ix        ; and ix
  492.     ld    ix,0        ; then point ix to 0
  493.                 ; so we don't upset memory-mapped i/o
  494.  
  495. ;Calculate values for loop constants. Need to have two loops to avoid
  496. ;   16-bit overflow with clock speeds above 9 MHz.
  497.  
  498. outerval    equ    (clkspd / 10) + 1
  499. innerval    equ    (6667 / outerval) * clkspd
  500.  
  501. wait10:
  502.     ld    b,outerval
  503.  
  504. wait11:
  505.     ld    de,innerval
  506.  
  507. wait12:
  508.     bit    0,(ix)        ; time-wasters
  509.     bit    0,(ix)
  510.     bit    0,(ix)        ; 20 T-states each
  511.     bit    0,(ix)
  512.     bit    0,(ix)
  513.     bit    0,(ix)
  514.     dec    de
  515.     ld    a,e
  516.     ld    a,d
  517.     or    e
  518.     jr    nz,wait12    ; 150 T-states per inner loop
  519.     djnz    wait11        ; decrement outer loop
  520.     dec    hl        ; ok, decrement count in hl
  521.     ld    a,h
  522.     or    l
  523.     jr    nz,wait10
  524.     pop    ix        ; done -- restore ix
  525.     pop    de        ; de
  526.     pop    bc        ; and bc
  527.     ret
  528.  
  529. ;Wait milliseconds
  530. mswait:
  531.     ld    hl,2
  532.     add    hl,sp
  533.     ex    de,hl        ; get delay size
  534.     call    getparm
  535.                 ; fall thru to..
  536. ;Wait milliseconds in HL
  537. waithlms:
  538.     push    de
  539. w1ms0:
  540.     ld    de,39 * clkspd
  541. w1ms1:
  542.     dec    de
  543.     ld    a,d
  544.     or    e
  545.     jr    nz,w1ms1
  546.     dec    hl
  547.     ld    a,h
  548.     or    l
  549.     jr    nz,w1ms0
  550.     pop    de
  551.     ret
  552.  
  553. ;Get next parameter from (de) into hl
  554. getparm:
  555.     ex    de,hl        ; get address into hl
  556.     ld    e,(hl)        ; get lo
  557.     inc    hl
  558.     ld    d,(hl)        ; then hi
  559.     inc    hl        ; bump for next
  560.     ex    de,hl        ; result in hl, address still in de
  561.     ret
  562.  
  563. ;Get address of user-defined variables
  564.  
  565. getvars:
  566.     ld    hl,uservars
  567.     ret
  568.  
  569. uservars:
  570.     dw    overdrive    ; .OVR etc. drive/user
  571.     dw    overuser
  572.  
  573.  
  574.      if    ($ - codebgn) gt ovsize
  575. toobig:    jp    errval        ; Overlay too large!
  576.      endif
  577.  
  578.     end
  579.