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-EP05.Z80 < prev    next >
Text File  |  2000-06-30  |  14KB  |  620 lines

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