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 / ZMP-BLNK.Z80 < prev   
Text File  |  1991-02-02  |  12KB  |  575 lines

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