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

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