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-BB06.Z80 < prev    next >
Text File  |  1991-02-02  |  15KB  |  734 lines

  1. ;-----------------------------------------------------------------------------
  2. ;
  3. ;
  4. ;    Overlay for ZMP (Z-Modem Program)
  5. ;
  6. ;    Name    ZMO-BBxx.Z80
  7. ;
  8. ;    Dated   18 Sep 1988
  9. ;
  10. ;    Written by -
  11. ;      Ron Murray, c/o Z-Node 62, 061-9-450-0200, Perth, Western Australia.
  12. ;      Modified for the BBII by Lindsay Allen, sysop, Z-Node 62.
  13. ;      Modified to 1.4 standard, SIO init order changed, mdmerr fixed.
  14. ;      Modified to ZMP v1.5 standard rjm 25/3/89
  15. ;
  16. ;
  17. ;    Rename subsequent versions as ZMO-BBxx.Z80 etc
  18. ;
  19. ;
  20. ;    This overlay is set up for a BigBoardII using port B.
  21. ;     Uses a Z80SIO and Z80CTC.
  22. ;
  23. ;
  24. ;-----------------------------------------------------------------------------
  25. ;
  26. ;
  27. ;    System-dependent code overlay for ZMODEM
  28. ;
  29. ;
  30. ;
  31. ;    Insert your own code as necessary in this file. Code contained herein
  32. ; has been written in Z80 code for use with M80 or SLR. Assemble as follows:
  33. ;
  34. ;    SLR ZMO-BBxx/h
  35. ;    MLOAD ZMP.COM=ZMPX.COM,ZMO-BBxx.HEX
  36. ; or
  37. ;    M80 =ZMO-BBxx.Z80
  38. ;    RELHEX ZMO-BBxx
  39. ;    MLOAD ZMP.COM=ZMPX.COM,ZMO-BBxx.HEX
  40. ;
  41. ;
  42. ;       (Don't use L80 without changing the source for assembly as a
  43. ;         cseg file.)
  44. ;
  45. ;-----------------------------------------------------------------------------
  46. ;
  47. ;
  48. ; Notes on modifying this file:
  49. ;
  50. ;    C requires that functions do not change either index register
  51. ; (IX or IY), nor the BC register pair. If your overlay requires any of
  52. ; these to be changed, ensure they are restored to the original values
  53. ; on return.
  54. ;    Since collecting parameters from C functions can be tricky, only change
  55. ; the parts marked 'Insert your own code here'. Do NOT modify the jump
  56. ; table at the start. Do NOT modify the entry/exit sections of each
  57. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  58. ;    Apart from defining modem functions, this file also defines terminal
  59. ; characteristics. Most have been set up for ADM-3A (with a few of my own
  60. ; additions). Modify to suit your own terminal. An inline print routine
  61. ; is provided for printing strings in the usual way: usage is
  62. ;
  63. ;    call    print
  64. ;    db    'required string',0
  65. ;
  66. ;-----------------------------------------------------------------------------
  67. ;
  68. ;
  69. ;    Don't forget to set your clock speed at the clkspd variable.
  70. ;
  71. ;
  72. ;    If you find your overlay exceeds the maximum size (currently 0400h),
  73. ; you will have to contact me for another version. If too many people need 
  74. ; to do it, we haven't allowed enough room.
  75. ;
  76. ; Ron Murray 15/8/88
  77. ;
  78. ;
  79. ;
  80. ;
  81. ;
  82. ;
  83. ;
  84. ;
  85. ;
  86. ;
  87. ;-----------------------------------------------------------------------------
  88.  
  89. false    equ    0
  90. true    equ    not false
  91.  
  92.  
  93. ; User-set variables: ***********
  94.  
  95. clkspd    equ    4        ; Processor clock speed in MHz
  96.  
  97. debug    equ    false
  98.  
  99. ;Set the following two equates to the drive and user area which will
  100. ;   contain zmp's .OVR files, .CFG file and .FON file. Set both to zero
  101. ;   to locate them on the drive from which zmp is invoked.
  102.  
  103. overdrive    equ    'H'    ; Drive to find overlays on. Range is 'A'-'P'
  104. overuser    equ    15    ; User area to find overlays
  105.  
  106. userdef    equ    0145h        ; origin of this overlay
  107.                 ; This address may change with subsequent
  108.                 ;  revisions.
  109.  
  110. ovsize    equ    0400h        ; max size of this overlay
  111.  
  112.     .z80            ; use z80 code
  113.     aseg            ; absolute
  114.  
  115.      if    debug
  116.     org    100h        ; so you can debug it with cebug, zsid, etc
  117.      else
  118.     org    userdef
  119.      endif
  120.  
  121.  
  122. esc    equ    1bh
  123. ctrlq    equ    11h
  124. cr    equ    0dh
  125. lf    equ    0ah
  126. bdos    equ    5
  127.  
  128.  
  129. ; BBII specific equates  ******************************************
  130.  
  131. mdata    equ    082h
  132. mdctl    equ    083h
  133. rda    equ    0
  134. tbe    equ    2
  135. ctc    equ    88h
  136. mode    equ    47h
  137. onhook    equ    7Fh
  138. online    equ    80h
  139. error    equ    70h
  140. break    equ    0F8h
  141. reset    equ    30h
  142. ;            ******************************************
  143.  
  144. ;-------------------------------------------------------------------------
  145. ; Main code starts here
  146.  
  147. codebgn    equ    $
  148.  
  149. ;Jump table for the overlay: do NOT change this
  150. jump_tab:
  151.     jp    scrnpr        ; screen print
  152.     jp    mrd        ; modem read with timeout
  153.     jp    mchin        ; get a character from modem
  154.     jp    mchout        ; send a character to the modem
  155.     jp    mordy        ; test for tx buffer empty
  156.     jp    mirdy        ; test for character received
  157.     jp    sndbrk        ; send break
  158.     jp    cursadd        ; cursor addressing
  159.     jp    cls        ; clear screen
  160.     jp    invon        ; inverse video on
  161.     jp    invoff        ; inverse video off
  162.     jp    hide        ; hide cursor
  163.     jp    show        ; show cursor
  164.     jp    savecu        ; save cursor position
  165.     jp    rescu        ; restore cursor position
  166.     jp    mint        ; service modem interrupt
  167.     jp    invec        ; initialise interrupt vectors
  168.     jp    dinvec        ; de-initialise interrupt vectors
  169.     jp    mdmerr        ; test uart flags for error
  170.     jp    dtron        ; turn DTR on
  171.     jp    dtroff        ; turn DTR OFF
  172.     jp    init        ; initialise uart
  173.     jp    wait        ; wait seconds
  174.     jp    mswait        ; wait milliseconds
  175.     jp    userin        ; user-defined entry routine
  176.     jp    userout        ; user-defined exit routine
  177.     jp    getvars        ; get system variables
  178.     jp    setport        ; set port (1 or 2)
  179.  
  180. ; Spare jumps for compatibility with future versions
  181.     jp    spare        ; spare for later use
  182.     jp    spare        ; spare for later use
  183.     jp    spare        ; spare for later use
  184.     jp    spare        ; spare for later use
  185.     jp    spare        ; spare for later use
  186.     jp    spare        ; spare for later use
  187.  
  188.  
  189. spare:    ret
  190.  
  191. ;-------------------------------------------------------------------------
  192.  
  193.  
  194. ;Screen print function
  195. scrnpr:
  196.                 ; <== Insert your own code here
  197.     call    print
  198.     db    'This function not supported.',cr,lf,0
  199.                 ; <== End of your own code
  200.     ret
  201.  
  202.  
  203. ;Get a character from the modem: return in HL
  204. mchin:
  205.     push    bc
  206.                 ; <== Insert your own code here
  207.  
  208. mchin2:
  209.     in    a,(mdctl)    ; check for char waiting
  210.     bit    rda,a
  211.     jr    z,mchin2
  212.  
  213.     in    a,(mdata)    ; read the char
  214.  
  215.  
  216.                 ; <== End of your own code
  217.  
  218.  
  219.     ld    l,a        ; put in HL
  220.     ld    h,0
  221.     or    a        ; set/clear Z
  222.     pop    bc
  223.     ret
  224.  
  225. ;Send a character to the modem
  226. mchout:
  227.     ld    hl,2        ; get the character
  228.     add    hl,sp
  229.     ld    a,(hl)
  230.                 ; <== Insert your own code here
  231.  
  232.     push    bc
  233.     ld    b,a        ; save the char
  234.  
  235. mchout2:
  236.     in    a,(mdctl)    ; check for uart ready
  237.     bit    tbe,a
  238.     jr    z,mchout2
  239.  
  240.     ld    a,b        ; char in a
  241.     out    (mdata),a    ; send it
  242.     pop    bc
  243.  
  244.                 ; <== End of your own code
  245.     ret            ; done
  246.  
  247. ;Test for output ready: return TRUE (1) in HL if ok
  248. mordy:
  249.                 ; <== Insert your own code here
  250.  
  251.     ld    hl,0
  252.     in    a,(mdctl)
  253.     bit    tbe,a        ; transmit buffer empty
  254.     jr    z,mordy1
  255.     inc    hl
  256. mordy1:
  257.  
  258.                 ; <== End of your own code
  259.  
  260.     ld    a,l        ; set/clear Z
  261.     or    a
  262.     ret
  263.  
  264. ;Test for character at modem: return TRUE (1) in HL if so
  265. mirdy:
  266.                 ; <== Insert your own code here
  267.  
  268.     ld    hl,0
  269.     in    a,(mdctl)
  270.     bit    rda,a        ; received data available
  271.     jr    z,mirdy1
  272.     inc    hl
  273. mirdy1:
  274.  
  275.                 ; <== End of your own code
  276.     ld    a,l        ; set/clear Z
  277.     or    a
  278.     ret
  279.  
  280. ;Send a break to the modem: leave empty if your system can't do it
  281. sndbrk:
  282.                 ; <== Insert your own code here
  283.     ld    a,5
  284.     out    (mdctl),a
  285.     ld    a,break        ; F8
  286.     out    (mdctl),a
  287.  
  288.     ld    hl,01        ; a 1 second break
  289.     call    wait1s
  290.  
  291.     ld    a,5
  292.     out    (mdctl),a
  293.     ld    a,online    ; 68
  294.     out    (mdctl),a
  295.  
  296.     ld    a,3
  297.     out    (mdctl),a
  298.     ld    a,0E1h
  299.     out    (mdctl),a    ; E1
  300.  
  301.                 ; <== End of your own code
  302.     ret
  303. ;
  304. ;Test UART flags for error: return TRUE (1) in HL if error.
  305. mdmerr:
  306.                 ; <== Insert your own code here
  307.     ld    hl,0        ; assume no error
  308.     ld    a,1        ; select RR1
  309.     out    (mdctl),a
  310.     in    a,(mdctl)    ; read it
  311.     and    error        ; mask out the other bits
  312.     jr    z,noerr
  313.     ld    a,38h        ; error reset (latches)
  314.     out    (mdctl),a
  315.     inc    hl        ; tell ZMP that we have an error
  316. noerr:
  317.                 ; <== End of your own code
  318.     ld    a,l        ; set/clear Z
  319.     or    a
  320.     ret
  321.  
  322.  
  323.  
  324. ;Turn DTR ON
  325. dtron:
  326.                 ; <== Insert your own code here
  327.     ld    a,5
  328.     out    (mdctl),a
  329.  
  330.     ld    a,(combyt)    ; get the one we used last time
  331.     or    a,online    ; 80h - set bit 7 high
  332.     ld    (combyt),a    ; save it for next time
  333.     out    (mdctl),a    ; go
  334.  
  335.                 ; <== End of your own code
  336.     ret
  337.  
  338.  
  339.  
  340. ;Turn DTR OFF
  341. dtroff:
  342.                 ; <== Insert your own code here
  343.  
  344.     ld    a,5
  345.     out    (mdctl),a
  346.  
  347.     ld    a,(combyt)    ; get the one we used last time
  348.     and    onhook        ; 7Fh - clear bit 7
  349.     ld    (combyt),a    ; save it for next time
  350.     out    (mdctl),a    ; go
  351.  
  352.                 ; <== End of your own code
  353.     ret
  354.  
  355.  
  356.  
  357. ;Initialise the SIO +++
  358. ; The SIO is set up in four steps:
  359. ;     1)  Reset
  360. ;       2)  Reg 4 - clock, stop bits, parity
  361. ;    3)  Reg 3 - Rx bits, RxEn
  362. ;    4)  Reg 5 - dtr, Tx bits, Brk, TxEn, rts
  363.  
  364. init:
  365.  
  366.     ld    hl,2        ; get parameters
  367.     add    hl,sp
  368.     ex    de,hl
  369.     call    getparm        ; in HL
  370.     ld    (brate),hl    ; baud rate
  371.     ld    a,l
  372.     ld    (003Ch),a    ; save the baud rate in 3C for later as per IMP
  373.     call    getparm
  374.     ld    (parity),hl    ; parity
  375.     call    getparm
  376.     ld    (data),hl    ; data bits
  377.     call    getparm
  378.     ld    (stop),hl    ; stop bits
  379.  
  380.  
  381.                 ; <== Insert your own code here
  382.                 ; using values below
  383.  
  384.     push    bc
  385.  
  386.     ld    a,0
  387.     out    (mdctl),a    ; point to reg 0
  388.     ld    a,18h        ; reset
  389.     out    (mdctl),a    ;                *** step 1
  390.  
  391.     ld    a,4        ; point to wrt reg 4
  392.     out    (mdctl),a
  393.     ld    e,44h        ; assume  x16, 1 stop, No parity
  394.     ld    a,(stop)    ; get stop bit setting
  395.     cp    2        ; need 2 ?
  396.     jr    nz,setpar    ; no - 1 stop bit already set
  397.     set    3,e        ; yes - set 2 stop bits
  398.  
  399. setpar:
  400.     ld    a,(parity)    ; set parity bits
  401.     cp    'O'        ; want ODD parity ?
  402.     jr    nz,setpa2    ; no
  403.     set    0,e        ; yes - set ODD parity
  404.     jr    setpa3        ; parity set so skip setpa2
  405.  
  406. setpa2:    cp    'E'        ; want EVEN parity ?
  407.     jr    nz,setpa3    ; no - "NONE" already set
  408.     set    0,e        ; yes - set EVEN parity
  409.     set    1,e        ;
  410.  
  411. setpa3:    ld    a,e
  412.     out    (mdctl),a    ;                *** step 2
  413.  
  414.  
  415.  
  416.     ld    a,3        ; point to wrt reg 3
  417.     out    (mdctl),a
  418.     ld    e,0C1h        ; assume 8 Rx data bits
  419.     ld    a,(data)    ; get required setting
  420.     cp    7        ; seven ?
  421.     jr    nz,setbi3    ; no - eight Rx data bits already set
  422.     res    7,e        ; set 7 Rx data bits
  423.  
  424. setbi3:    ld    a,e
  425.     out    (mdctl),a    ;                *** step 3
  426.  
  427.     ld    a,5        ; point to wrt reg 5 - dtr, Tx bits, etc
  428.     out    (mdctl),a
  429.     ld    e,0EAh        ; assume dtr, Tx 8 bits, TxEn, rts
  430.     ld    a,(data)    ; number of Tx data bits required
  431.     cp    7        ; seven ?
  432.     jr    nz,setbi2    ; no
  433.     res    6,e        ; yes - set 7 Tx data bits
  434.  
  435. setbi2:    ld    a,e
  436.     out    (mdctl),a    ;                *** step 4
  437.     
  438.  
  439. setbrate:
  440.     ld    a,mode        ; 47h
  441.     out    (ctc),a        ; select the correct timer and mode of the CTC
  442.     ld    de,(brate)    ; get baud rate value (0-10)
  443.     ld    hl,brval
  444.     add    hl,de
  445.     ld    a,(hl)
  446.     out    (ctc),a
  447.  
  448.     pop    bc
  449.     ret
  450.  
  451.  
  452.  
  453. brate:    dw    6        ; baud rate:
  454. parity:    dw    'N'        ; parity
  455. data:    dw    8        ; data bits
  456. stop:    dw    1        ; stop bits
  457. combyt:    db    0EAh        ; save it here
  458.  
  459. ;Values for Z80CTC control reg for each baud rate: 0 if invalid
  460. brval:
  461.     db     0    ;   110        0
  462.     db    80h    ;   300        1
  463.     db     0    ;   450        2
  464.     db    40h    ;   600        3
  465.     db     0    ;   710        4
  466.     db    20h    ;  1200        5
  467.     db    10h    ;  2400        6
  468.     db    08h    ;  4800        7
  469.     db    04h    ;  9600        8
  470.     db    02h    ; 19200        9
  471.  
  472.  
  473. ;
  474. ; Set the port. ZMP supplies either 0 or 1 as a parameter. You're on your
  475. ; own here -- your system is bound to be different from any other! You may
  476. ; implement a software switch on all the modem-dependent routines, or perhaps
  477. ; you can have one or two centralised routines for accessing the UARTs and
  478. ; modify the code from this routine to select one or the other. (Who said
  479. ; there was anything wrong with self-modifying code?). If you have only one
  480. ; UART port, or if you don't want to go through all the hassles, just have
  481. ; this routine returning with no changes made. Note that ZMP calls this
  482. ; routine with both values for the port on initialisation.
  483. ;
  484. setport:
  485.     ld    hl,2        ; get port number
  486.     add    hl,sp
  487.     ex    de,hl
  488.     call    getparm        ; in HL (values are 0 and 1)
  489.  
  490.                 ; <== Insert your own code here
  491.  
  492.                 ; <== End of your own code
  493.     ret
  494.  
  495. port:    ds    1
  496.  
  497. ;*****************************************************************************
  498.  
  499. ;My system needs a BIOS call to access the UART. If yours doesn't, you don't
  500. ;  need anything here. Otherwise write your own.
  501. calmod:
  502.  
  503.             ; not required for most computers
  504.  
  505. ;****************************************************************************
  506. ;Video terminal sequences: these are for ADM-3A: Modify as you wish
  507. ;Cursor addressing: 
  508. cursadd:
  509.     ld    hl,2        ; get parameters
  510.     add    hl,sp
  511.     ex    de,hl
  512.     call    getparm        ; in HL
  513.     ld    (row),hl    ; row
  514.     call    getparm
  515.     ld    (col),hl    ; column
  516.                 ; <== Insert your own code here
  517.                 ; using values in row and col
  518.     call    print
  519.     db    esc,'=',0    ; ADM-3A leadin
  520.     ld    a,(row)        ; row first
  521.     add    a,' '        ; add offset
  522.     call    cout
  523.     ld    a,(col)        ; sane for column
  524.     add    a,' '
  525.     call    cout
  526.                 ; <== end of your own code
  527.     ret
  528.  
  529. row:    ds    2        ; row
  530. col:    ds    2        ; column
  531.  
  532.  
  533. ;Clear screen:
  534. cls:
  535.     call    print
  536.     db    esc,'*',0
  537.     ret
  538.  
  539. ;Inverse video on:
  540. invon:
  541.     call    print
  542.     db    esc,'G4',0
  543.     ret
  544.  
  545. ;Inverse video off:
  546. invoff:
  547.     call    print
  548.     db    esc,'G0',0
  549.     ret
  550.  
  551. ;Turn off cursor:
  552. hide:
  553. ;    call    print
  554. ;    db    esc,'.1',0
  555.     ret
  556.  
  557. ;Turn on cursor:
  558. show:
  559. ;    call    print
  560. ;    db    esc,'.3',0
  561.     ret
  562.  
  563. ;Save cursor position:
  564. savecu:
  565.     ret
  566.  
  567. ;Restore cursor position:
  568. rescu:
  569.     ret
  570.  
  571. ;User-defined entry routine: leave empty if not used
  572. userin:
  573.     ret
  574.  
  575. ;User-defined exit routine: leave empty if not used
  576. userout:
  577.     ret
  578.  
  579.  
  580. ;****************************************************************************
  581.  
  582. ;Service modem interrupt:
  583. mint:
  584.     ret            ; my system doesn't need this
  585.  
  586. ;Initialise interrupt vectors:
  587. invec:
  588.     ret            ; ditto
  589.  
  590. ;De-initialise interrupt vectors:
  591. dinvec:
  592.     ret            ; ditto
  593.  
  594. ;****************** End of user-defined code ********************************
  595. ;        Do not change anything below here.
  596.  
  597. mrd:
  598.     push    af
  599.     push    bc
  600.  
  601.     ld    hl,1            ; "character waiting"
  602.     ld    bc,7600        ; empirical value, found by timing tests
  603. mrd1:
  604.     in    a,(mdctl)    ; check for char waiting
  605.     bit    rda,a
  606.     jr    nz,mrd2
  607.  
  608.     dec    bc
  609.     ld    a,b
  610.     or    c
  611.     jr    nz,mrd1
  612.  
  613.     ld    hl,0            ; "no character"
  614.  
  615. mrd2:
  616.     pop    bc
  617.     pop    af
  618.  
  619.     ret
  620.  
  621. ; Inline print routine: destroys A and HL
  622.  
  623. print:
  624.     ex    (sp),hl        ; get address of string
  625. ploop:
  626.     ld    a,(hl)        ; get next
  627.     inc    hl        ; bump pointer
  628.     or    a        ; done if zero
  629.     jr    z,pdone
  630.     call    cout        ; else print
  631.     jr    ploop        ; and loop
  632. pdone:
  633.     ex    (sp),hl        ; restore return address
  634.     ret            ; and quit
  635.  
  636. ;
  637. ;Output a character in A to the console
  638. ;
  639. cout:
  640.     push    bc        ; save regs
  641.     push    de
  642.     push    hl
  643.     ld    e,a        ; character to E
  644.     ld    c,2
  645.     call    bdos        ; print it
  646.     pop    hl
  647.     pop    de
  648.     pop    bc
  649.     ret
  650.  
  651. ;Wait(seconds)
  652. wait:
  653.     ld    hl,2
  654.     add    hl,sp
  655.     ex    de,hl        ; get delay size
  656.     call    getparm
  657.                 ; fall thru to..
  658. ;Wait seconds in HL
  659. wait1s:
  660.     push    de
  661. wait10:
  662.     ld    de,6667 * clkspd
  663. wait11:
  664.     bit    0,(ix)        ; time-wasters
  665.     bit    0,(ix)
  666.     bit    0,(ix)        ; 20 T-states each
  667.     bit    0,(ix)
  668.     bit    0,(ix)
  669.     bit    0,(ix)
  670.     dec    de
  671.     ld    a,e
  672.     ld    a,d
  673.     or    e
  674.     jr    nz,wait11    ; 150 T-states per loop
  675.     dec    hl
  676.     ld    a,h
  677.     or    l
  678.     jr    nz,wait11
  679.     pop    de
  680.     ret
  681.  
  682. ;Wait milliseconds
  683. mswait:
  684.     ld    hl,2
  685.     add    hl,sp
  686.     ex    de,hl        ; get delay size
  687.     call    getparm
  688.                 ; fall thru to..
  689. ;Wait milliseconds in HL
  690. wait1ms:
  691.     push    de
  692. w1ms0:
  693.     ld    de,39 * clkspd
  694. w1ms1:
  695.     dec    de
  696.     ld    a,d
  697.     or    e
  698.     jr    nz,w1ms1
  699.     dec    hl
  700.     ld    a,h
  701.     or    l
  702.     jr    nz,w1ms0
  703.     pop    de
  704.     ret
  705.  
  706. ;Get next parameter from (de) into hl
  707. getparm:
  708.     ex    de,hl        ; get address into hl
  709.     ld    e,(hl)        ; get lo
  710.     inc    hl
  711.     ld    d,(hl)        ; then hi
  712.     inc    hl        ; bump for next
  713.     ex    de,hl        ; result in hl, address still in de
  714.     ret
  715.  
  716. getvars:
  717.     ld    hl,uservars
  718.     ret
  719.  
  720.  
  721.     ds    ($ or 0Fh) - $ + 1,0
  722.     db    'OVERLAYS',0
  723. uservars:
  724.     dw    overdrive    ; all integer
  725.     dw    overuser
  726.  
  727.     ds    ovsize + codebgn - $,0
  728.  
  729.      if    ($ - codebgn) gt ovsize
  730. toobig:    jp    errval        ; Overlay too large!
  731.      endif
  732.  
  733.     end
  734.