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

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ;    Overlay for ZMP (Z-Modem Program)
  4. ;
  5. ;    Name    ZMO-C802.Z80
  6. ;
  7. ;    Dated October 4, 1988
  8. ;
  9. ;    Written by -
  10. ;      Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia.
  11. ;      Modified for the Commodore 128 by Ron Murray
  12. ;    Modified to v1.4 standard rjm 11/12/88
  13. ;
  14. ;
  15. ;    Rename subsequent versions as ZMO-C8xx.Z80 etc
  16. ;
  17. ;
  18. ;    This overlay is set up for a Commodore 128 running CP/M+. Modem
  19. ;        routines are based on Irv Hoff's IMP overlay for the 128.
  20. ;
  21. ;
  22. ;-----------------------------------------------------------------------------
  23. ;
  24. ;
  25. ;    System-dependent code overlay for ZMODEM
  26. ;
  27. ;
  28. ;
  29. ;    Insert your own code as necessary in this file. Code contained herein
  30. ; has been written in Z80 code for use with M80 or SLR. Assemble as follows:
  31. ;
  32. ;    SLR ZMO-C801/h
  33. ;    MLOAD ZMP.COM=ZMODEM.COM,ZMO-C801.HEX
  34. ; or
  35. ;    M80 =ZMO-C801.Z80
  36. ;    RELHEX ZMO-C801
  37. ;    MLOAD ZMP.COM=ZMODEM.COM,ZMO-C801.HEX
  38. ;
  39. ;
  40. ;       (Don't use L80 without changing the source for assembly as a
  41. ;         cseg file.)
  42. ;
  43. ;-----------------------------------------------------------------------------
  44. ;
  45. ;
  46. ; Notes on modifying this file:
  47. ;
  48. ;    C requires that functions do not change either index register
  49. ; (IX or IY), nor the BC register pair. If your overlay requires any of
  50. ; these to be changed, ensure they are restored to the original values
  51. ; on return.
  52. ;    Since collecting parameters from C functions can be tricky, only change
  53. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  54. ; table at the start. Do NOT modify the entry/exit sections of each
  55. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  56. ;    Apart from defining modem functions, this file also defines terminal
  57. ; characteristics. Most have been set up for ADM-3A (with a few of my own
  58. ; additions). Modify to suit your own terminal. An inline print routine
  59. ; is provided for printing strings in the usual way: usage is
  60. ;
  61. ;    call    print
  62. ;    db    'required string',0
  63. ;
  64. ;-----------------------------------------------------------------------------
  65. ;
  66. ;
  67. ;    Don't forget to set your clock speed at the clkspd variable.
  68. ;
  69. ;
  70. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  71. ; you will have to contact me for another version. If too many people need 
  72. ; to do it, we haven't allowed enough room.
  73. ;
  74. ; Ron Murray 15/8/88
  75. ;
  76. ;
  77. ;
  78. ;
  79.  
  80. false    equ    0
  81. true    equ    not false
  82.  
  83.  
  84. ; User-set variables: ***********
  85.  
  86. ;Set the following two equates to the drive and user area which will contain
  87. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  88. ;   (null) to locate them on the drive from which ZMP was invoked.
  89.  
  90. overdrive    equ    'A'    ; Drive to find overlay files on ('A'-'P')
  91. overuser    equ    0    ; User area to find files
  92.  
  93. clkspd    equ    2        ; Processor clock speed in MHz
  94.  
  95. debug    equ    false
  96.  
  97. ;Don't change the following three equates!!
  98.  
  99. userdef    equ    00145h        ; origin of this overlay
  100.                 ; This address may change with subsequent
  101.                 ;  revisions.
  102.  
  103. mspeed    equ    003ch        ; place to store baud rate id to allow
  104.                 ; re-entry as per IMP. This MUST be the same
  105.                 ; as that set in ZMP
  106. ovsize    equ    0400h        ; max size of this overlay
  107.  
  108.     .z80            ; use z80 code
  109.     aseg            ; absolute
  110.  
  111.      if    debug
  112.     org    100h        ; so you can debug it with cebug, zsid, etc
  113.      else
  114.     org    userdef
  115.      endif
  116.  
  117.  
  118. esc    equ    1bh
  119. ctrlq    equ    11h
  120. cr    equ    0dh
  121. lf    equ    0ah
  122. bdos    equ    5
  123.  
  124.  
  125. ; C128 specific equates  ***************************************************
  126.  
  127. port        equ    6
  128. XxDconfig    equ    0fd4eh
  129. rs232_stat    equ    XxDconfig+1
  130. xmit_data    equ    XxDconfig+2
  131. recv_data    equ    XxDconfig+3
  132. mdrcv        equ    01h        ; Modem receive ready
  133. mdsndb        equ    80h        ; bit to test for send
  134. mdsndr        equ    00h        ; value when send ready
  135. d2pra        equ    0dd00h        ; cia #2: rs-232 tx data etc
  136. d2prb        equ    d2pra+1        ; cia #2: rs-232 status/data bits
  137.  
  138. ;            ******************************************
  139.  
  140. ;
  141. ; Main code starts here
  142. ;
  143. codebgn    equ    $
  144.  
  145. ;Jump table for the overlay: do NOT change this
  146. jump_tab:
  147.     jp    scrnpr        ; screen print
  148.     jp    mrd        ; modem read with timeout
  149.     jp    mchin        ; get a character from modem
  150.     jp    mchout        ; send a character to the modem
  151.     jp    mordy        ; test for tx buffer empty
  152.     jp    mirdy        ; test for character received
  153.     jp    sndbrk        ; send break
  154.     jp    cursadd        ; cursor addressing
  155.     jp    cls        ; clear screen
  156.     jp    invon        ; inverse video on
  157.     jp    invoff        ; inverse video off
  158.     jp    hide        ; hide cursor
  159.     jp    show        ; show cursor
  160.     jp    savecu        ; save cursor position
  161.     jp    rescu        ; restore cursor position
  162.     jp    mint        ; service modem interrupt
  163.     jp    invec        ; initialise interrupt vectors
  164.     jp    dinvec        ; de-initialise interrupt vectors
  165.     jp    mdmerr        ; test uart flags for error
  166.     jp    dtron        ; turn DTR on
  167.     jp    dtroff        ; turn DTR OFF
  168.     jp    init        ; initialise uart
  169.     jp    wait        ; wait seconds
  170.     jp    mswait        ; wait milliseconds
  171.     jp    userin        ; user-defined entry routine
  172.     jp    userout        ; user-defined exit routine
  173.     jp    getvars        ; get system variables
  174.  
  175. ; Spare jumps for compatibility with future versions
  176.     jp    spare        ; spare for later use
  177.     jp    spare        ; spare for later use
  178.     jp    spare        ; spare for later use
  179.     jp    spare        ; spare for later use
  180.     jp    spare        ; spare for later use
  181.     jp    spare        ; spare for later use
  182.  
  183. ;
  184. ;Screen print function
  185. scrnpr:
  186.                 ; <== Insert your own code here
  187.     call    print
  188.     db    'This function not supported.',cr,lf,0
  189.                 ; <== End of your own code
  190. spare:
  191.     ret
  192.  
  193. ; User-defined entry routine: leave empty if not needed
  194. userin:
  195.     ret
  196.  
  197. ; User-defined exit routine: leave empty if not needed
  198. userout:
  199.     ret
  200.  
  201.  
  202. ;Get a character from the modem: return in HL
  203. mchin:
  204.     push    bc
  205.                 ; <== Insert your own code here
  206.  
  207.     ld    a,(recv_data)    ; get the data byte
  208.     ld    hl,rs232_stat
  209.     res    0,(hl)        ; reset bit 0 of status byte
  210.  
  211.                 ; <== End of your own code
  212.  
  213.     ld    l,a        ; put in HL
  214.     ld    h,0
  215.     or    a        ; set/clear Z
  216.     pop    bc
  217.     ret
  218.  
  219. ;Send a character to the modem
  220. mchout:
  221.     ld    hl,2        ; get the character
  222.     add    hl,sp
  223.     ld    a,(hl)
  224.                 ; <== Insert your own code here
  225.  
  226.     ld    (xmit_data),a    ; store it
  227.     ld    hl,rs232_stat    ; and set the bit
  228.     set    7,(hl)
  229.  
  230.                 ; <== End of your own code
  231.     ret            ; done
  232.  
  233. ;Test for output ready: return TRUE (1) in HL if ok
  234. mordy:
  235.                 ; <== Insert your own code here
  236.  
  237.     ld    hl,0        ; assume not ready
  238.     ld    a,(rs232_stat)    ; get status byte
  239.     and    mdsndb
  240.     cp    mdsndr        ; if bit ready,
  241.     jr    nz,mordy1
  242.     inc    hl        ; bump hl
  243. mordy1:
  244.  
  245.                 ; <== End of your own code
  246.  
  247.     ld    a,l        ; set/clear Z
  248.     or    a
  249.     ret
  250.  
  251. ;Test for character at modem: return TRUE (1) in HL if so
  252. mirdy:
  253.                 ; <== Insert your own code here
  254.  
  255.     ld    hl,0
  256.     ld    a,(rs232_stat)    ; get status byte
  257.     and    mdrcv        ; mask off rx bit
  258.     cp    mdrcv        ; if ok,
  259.     jr    nz,mirdy1
  260.     inc    hl        ; hl = 1
  261. mirdy1:
  262.  
  263.                 ; <== End of your own code
  264.     ld    a,l        ; set/clear Z
  265.     or    a
  266.     ret
  267.  
  268. ;Send a break to the modem: leave empty if your system can't do it
  269. sndbrk:
  270.                 ; <== Insert your own code here
  271.     push    bc
  272.     ld    bc,d2pra
  273.     in    a,(c)        ; get current value of port
  274.     push    af        ; save it
  275.     xor    04h        ; toggle TxD
  276.     out    (c),a
  277.  
  278.     ld    hl,300
  279.     call    waithlms    ; wait 300 mS
  280.  
  281.     pop    af        ; restore original value
  282.     ld    bc,d2pra
  283.     out    (c),a
  284.     pop    bc
  285.                 ; <== End of your own code
  286.     ret
  287. ;
  288. ;Test UART flags for error: return TRUE (1) in HL if error.
  289. mdmerr:
  290.                 ; <== Insert your own code here
  291.  
  292.     ld    hl,1        ; assume none
  293.     ld    a,(rs232_stat)    ; get status byte
  294.     and    018h        ; mask off unwanted bits
  295.     jr    z,mdmerr1
  296.     dec    hl        ; ok, we got some
  297. mdmerr1:
  298.  
  299.                 ; <== End of your own code
  300.     ld    a,l        ; set/clear Z
  301.     or    a
  302.     ret
  303.  
  304.  
  305.  
  306. ;Turn DTR ON
  307. dtron:
  308.                 ; <== Insert your own code here
  309.  
  310.     push    bc
  311.     ld    bc,d2prb    ; get rs-232 bits
  312.     in    a,(c)
  313.     or    6        ; set DTR and RTS
  314.     out    (c),a
  315.     pop    bc
  316.  
  317.                 ; <== End of your own code
  318.     ret
  319.  
  320.  
  321.  
  322. ;Turn DTR OFF
  323. dtroff:
  324.                 ; <== Insert your own code here
  325.  
  326.     push    bc
  327.     ld    bc,d2prb    ; get rs-232 bits
  328.     in    a,(c)
  329.     and    0f9h        ; drop DTR and RTS
  330.     out    (c),a
  331.     pop    bc
  332.  
  333.                 ; <== End of your own code
  334.     ret
  335.  
  336.  
  337.  
  338. ;Initialise the (fake) UART
  339.  
  340. init:
  341.  
  342.     ld    hl,2        ; get parameters
  343.     add    hl,sp
  344.     ex    de,hl
  345.     call    getparm        ; in HL
  346.     ld    (brate),hl    ; baud rate
  347.     call    getparm
  348.     ld    (parity),hl    ; parity
  349.     call    getparm
  350.     ld    (data),hl    ; data bits
  351.     call    getparm
  352.     ld    (stop),hl    ; stop bits
  353.  
  354.  
  355.                 ; <== Insert your own code here
  356.                 ; using values below
  357.  
  358.     push    bc
  359.     ld    a,(parity)    ; get parity ID
  360.     ld    c,0        ; assume none
  361.     cp    'N'        ; which is what we have if N
  362.     jr    z,setpar
  363.     ld    c,0c0h        ; ok, assume even
  364.     cp    'E'
  365.     jr    z,setpar    ; yep, that's it
  366.     ld    c,0e0h        ; no, odd
  367. setpar:
  368.     ld    a,(data)    ; test data bits
  369.     and    0fh        ; (never sure if ASCII or binary!)
  370.     cp    7        ; if not 7,
  371.     jr    z,setstop
  372.     inc    c        ; bump C
  373. setstop:
  374.     ld    a,(stop)    ; now do stop bits
  375.     and    0fh
  376.     cp    2        ; if 2,
  377.     jr    nz,setpars
  378.     inc    c        ; add 2
  379.     inc    c
  380. setpars:
  381.     ld    a,c        ; store it
  382.     ld    (XxDconfig),a
  383.     ld    a,(brate)    ; get baud rate
  384.     ld    c,a
  385.     ld    b,0        ; in bc
  386.     ld    hl,brval    ; add to base
  387.     add    hl,bc
  388.     ld    a,(hl)        ; and get divisor
  389.     or    a        ; don't do if zero
  390.     jr    z,setpar1
  391.     push    af        ; ok, save for now
  392.     ld    a,c
  393.     ld    (mspeed),a    ; save the baud rate in 3C for later as per IMP
  394.     ld    hl,(0001)    ; get BIOS address
  395.     ld    de,57
  396.     add    hl,de
  397.     call    dopchl        ; get address of char dev tbl
  398.     ld    de,port*8+7    ; offset to rs-232 baud rate
  399.     add    hl,de        ; address in hl
  400.     pop    af        ; restore divisor
  401.     ld    (hl),a        ; store it
  402.     ld    hl,(0001)    ; get BIOS address
  403.     ld    de,60        ; get port init address
  404.     add    hl,de
  405.     ld    c,port
  406.     call    dopchl        ; initialise
  407. setpar1:
  408.     pop    bc
  409.                 ; <== End of your own code
  410.     ret
  411.  
  412. dopchl:
  413.     jp    (hl)
  414.  
  415. ;--------------------------------------------------------------------------
  416.  
  417. stop:    dw    1        ; stop bits
  418. parity:    dw    'N'        ; parity
  419. data:    dw    8        ; data bits
  420. brate:    dw    7        ; baud rate:
  421.  
  422. ;--------------------------------------------------------------------------
  423. ;Values for fake 6551 control reg for each baud rate
  424. ; Note that only rates up to 1200 will work in a C128
  425.  
  426. brval:
  427.     db     3    ;   110        0
  428.     db     6    ;   300        1
  429.     db     0    ;   450        2
  430.     db     7    ;   600        3
  431.     db     0    ;   710        4
  432.     db     8    ;  1200        5
  433.     db     9    ;  2400        6    .. you never know ..
  434.     db     0    ;  4800        7
  435.     db     0    ;  9600        8
  436.     db     0    ; 19200        9
  437.     db     0    ; 38400        10
  438.     db     0    ; 57600        11
  439.     db     0    ; 76800        12
  440.  
  441. ;****************************************************************************
  442. ;Video terminal sequences: these are for ADM-3A: Modify as you wish
  443. ;Cursor addressing: 
  444. cursadd:
  445.     ld    hl,2        ; get parameters
  446.     add    hl,sp
  447.     ex    de,hl
  448.     call    getparm        ; in HL
  449.     ld    (row),hl    ; row
  450.     call    getparm
  451.     ld    (col),hl    ; column
  452.                 ; <== Insert your own code here
  453.                 ; using values in row and col
  454.     call    print
  455.     db    esc,'=',0    ; ADM-3A leadin
  456.     ld    a,(row)        ; row first
  457.     add    a,' '        ; add offset
  458.     call    cout
  459.     ld    a,(col)        ; sane for column
  460.     add    a,' '
  461.     call    cout
  462.                 ; <== end of your own code
  463.     ret
  464.  
  465. row:    ds    2        ; row
  466. col:    ds    2        ; column
  467.  
  468.  
  469. ;Clear screen:
  470. cls:
  471.     call    print
  472.     db    01ah,0
  473.     ret
  474.  
  475. ;Inverse video on:
  476. invon:
  477.     call    print
  478.     db    esc,'G4',0
  479.     ret
  480.  
  481. ;Inverse video off:
  482. invoff:
  483.     call    print
  484.     db    esc,'G0',0
  485.     ret
  486.  
  487. ;Turn off cursor:
  488. hide:
  489.     ret
  490.  
  491. ;Turn on cursor:
  492. show:
  493.     ret
  494.  
  495. ;Save cursor position:
  496. savecu:
  497.     ret
  498.  
  499. ;Restore cursor position:
  500. rescu:
  501.     ret
  502.  
  503. ;****************************************************************************
  504.  
  505. ;Service modem interrupt:
  506. mint:
  507.     ret            ; my system doesn't need this
  508.  
  509. ;Initialise interrupt vectors:
  510. invec:
  511.     ret            ; ditto
  512.  
  513. ;De-initialise interrupt vectors:
  514. dinvec:
  515.     ret            ; ditto
  516.  
  517. ;****************** End of user-defined code ********************************
  518. ;        Do not change anything below here.
  519.  
  520. ;Modem character test for 100 ms
  521. mrd:
  522.     push    bc        ; save bc
  523.     ld    bc,100        ; set limit
  524. mrd1:
  525.     call    mirdy        ; char at modem?
  526.     jr    nz,mrd2        ; yes, exit
  527.     ld    hl,1        ; else wait 1ms
  528.     call    waithlms
  529.     dec    bc        ; loop till done
  530.     ld    a,b
  531.     or    c
  532.     jr    nz,mrd1
  533.     ld    hl,0        ; none there, result=0
  534.     xor    a
  535. mrd2:
  536.     pop    bc
  537.     ret
  538.  
  539. ; Inline print routine: destroys A and HL
  540.  
  541. print:
  542.     ex    (sp),hl        ; get address of string
  543. ploop:
  544.     ld    a,(hl)        ; get next
  545.     inc    hl        ; bump pointer
  546.     or    a        ; done if zero
  547.     jr    z,pdone
  548.     call    cout        ; else print
  549.     jr    ploop        ; and loop
  550. pdone:
  551.     ex    (sp),hl        ; restore return address
  552.     ret            ; and quit
  553.  
  554. ;
  555. ;Output a character in A to the console
  556. ;
  557. cout:
  558.     push    bc        ; save regs
  559.     push    de
  560.     push    hl
  561.     ld    e,a        ; character to E
  562.     ld    c,2
  563.     call    bdos        ; print it
  564.     pop    hl
  565.     pop    de
  566.     pop    bc
  567.     ret
  568.  
  569. ;Wait(seconds)
  570. wait:
  571.     ld    hl,2
  572.     add    hl,sp
  573.     ex    de,hl        ; get delay size
  574.     call    getparm
  575.                 ; fall thru to..
  576. ;Wait seconds in HL
  577. waithls:
  578.     push    bc        ; save bc
  579.     push    de        ; de
  580.     push    ix        ; and ix
  581.     ld    ix,0        ; then point ix to 0
  582.                 ; so we don't upset memory-mapped i/o
  583.  
  584. ;Calculate values for loop constants. Need to have two loops to avoid
  585. ;   16-bit overflow with clock speeds above 9 MHz.
  586.  
  587. outerval    equ    (clkspd / 10) + 1
  588. innerval    equ    (6667 / outerval) * clkspd
  589.  
  590. wait10:
  591.     ld    b,outerval
  592.  
  593. wait11:
  594.     ld    de,innerval
  595.  
  596. wait12:
  597.     bit    0,(ix)        ; time-wasters
  598.     bit    0,(ix)
  599.     bit    0,(ix)        ; 20 T-states each
  600.     bit    0,(ix)
  601.     bit    0,(ix)
  602.     bit    0,(ix)
  603.     dec    de
  604.     ld    a,e
  605.     ld    a,d
  606.     or    e
  607.     jr    nz,wait12    ; 150 T-states per inner loop
  608.     djnz    wait11        ; decrement outer loop
  609.     dec    hl        ; ok, decrement count in hl
  610.     ld    a,h
  611.     or    l
  612.     jr    nz,wait10
  613.     pop    ix        ; done -- restore ix
  614.     pop    de        ; de
  615.     pop    bc        ; and bc
  616.     ret
  617.  
  618.  
  619. ;Wait milliseconds
  620. mswait:
  621.     ld    hl,2
  622.     add    hl,sp
  623.     ex    de,hl        ; get delay size
  624.     call    getparm
  625.                 ; fall thru to..
  626. ;Wait milliseconds in HL
  627. waithlms:
  628.     push    de
  629. w1ms0:
  630.     ld    de,39 * clkspd
  631. w1ms1:
  632.     dec    de
  633.     ld    a,d
  634.     or    e
  635.     jr    nz,w1ms1
  636.     dec    hl
  637.     ld    a,h
  638.     or    l
  639.     jr    nz,w1ms0
  640.     pop    de
  641.     ret
  642.  
  643. ;Get next parameter from (de) into hl
  644. getparm:
  645.     ex    de,hl        ; get address into hl
  646.     ld    e,(hl)        ; get lo
  647.     inc    hl
  648.     ld    d,(hl)        ; then hi
  649.     inc    hl        ; bump for next
  650.     ex    de,hl        ; result in hl, address still in de
  651.     ret
  652.  
  653. ;Get address of user-defined variables
  654.  
  655. getvars:
  656.     ld    hl,uservars
  657.     ret
  658.  
  659. uservars:
  660.     dw    overdrive    ; .OVR etc. drive/user
  661.     dw    overuser
  662.  
  663.  
  664.      if    ($ - codebgn) gt ovsize
  665. toobig:    jp    errval        ; Overlay too large!
  666.      endif
  667.  
  668.     end
  669.