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 / ZMP15.ARC / ZMP-BLNK.Z80 < prev    next >
Text File  |  1990-09-20  |  12KB  |  573 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.                 ; <== Insert your own code here
  220.  
  221.  
  222.                 ; <== End of your own code
  223.     ld    a,l        ; set/clear Z
  224.     or    a
  225.     ret
  226.  
  227. ;Send a break to the modem: leave empty if your system can't do it
  228. sndbrk:
  229.                 ; <== Insert your own code here
  230.  
  231.     ld    hl,300        ; wait 300 mS
  232.     call    waithlms
  233.  
  234.                 ; <== End of your own code
  235.     ret
  236. ;
  237. ;Test UART flags for error: return TRUE (1) in HL if error.
  238. mdmerr:
  239.                 ; <== Insert your own code here
  240.  
  241.                 ; <== End of your own code
  242.     ld    a,l        ; set/clear Z
  243.     or    a
  244.     ret
  245.  
  246.  
  247.  
  248. ;Turn DTR ON
  249. dtron:
  250.                 ; <== Insert your own code here
  251.  
  252.                 ; <== End of your own code
  253.     ret
  254.  
  255.  
  256.  
  257. ;Turn DTR OFF
  258. dtroff:
  259.                 ; <== Insert your own code here
  260.  
  261.  
  262.                 ; <== End of your own code
  263.     ret
  264.  
  265.  
  266.  
  267. ;Initialise the uart
  268.  
  269. init:
  270.  
  271.     ld    hl,2        ; get parameters
  272.     add    hl,sp
  273.     ex    de,hl
  274.     call    getparm        ; in HL
  275.     ld    (brate),hl    ; baud rate
  276.     call    getparm
  277.     ld    (parity),hl    ; parity
  278.     call    getparm
  279.     ld    (data),hl    ; data bits (BINARY 7 or 8)
  280.     call    getparm
  281.     ld    (stop),hl    ; stop bits (BINARY 1 or 2)
  282.  
  283.  
  284.                 ; <== Insert your own code here
  285.                 ; using values below
  286.     ld    (mspeed),a    ; don't forget to load mspeed with the
  287.                 ; current brate value if the new rate is
  288.                 ; valid. See table of values below.
  289.                 ; <== End of your own code
  290.     ret
  291. ;--------------------------------------------------------------------------
  292.  
  293. stop:    dw    1        ; stop bits
  294. parity:    dw    'N'        ; parity
  295. data:    dw    8        ; data bits
  296. brate:    dw    7        ; baud rate:
  297.  
  298. ;--------------------------------------------------------------------------
  299. ;Values of brate for each baud rate
  300. ;
  301. ; baud rate    brate
  302. ;
  303. ;   110         0
  304. ;   300         1
  305. ;   450         2
  306. ;   600         3
  307. ;   710         4
  308. ;  1200         5
  309. ;  2400         6
  310. ;  4800         7
  311. ;  9600         8
  312. ; 19200         9
  313. ; 38400        10
  314. ; 57600         11
  315. ; 76800         12
  316.  
  317. ;
  318. ; Set the port. ZMP supplies either 0 or 1 as a parameter. You're on your
  319. ; own here -- your system is bound to be different from any other! You may
  320. ; implement a software switch on all the modem-dependent routines, or perhaps
  321. ; you can have one or two centralised routines for accessing the UARTs and
  322. ; modify the code from this routine to select one or the other. (Who said
  323. ; there was anything wrong with self-modifying code?). If you have only one
  324. ; UART port, or if you don't want to go through all the hassles, just have
  325. ; this routine returning with no changes made. Note that ZMP calls this
  326. ; routine with both values for the port on initialisation.
  327. ;
  328. setport:
  329.     ld    hl,2        ; get port number
  330.     add    hl,sp
  331.     ex    de,hl
  332.     call    getparm        ; in HL (values are 0 and 1)
  333.  
  334.                 ; <== Insert your own code here
  335.  
  336.                 ; <== End of your own code
  337.     ret
  338.  
  339. port:    ds    1
  340.  
  341.  
  342. ;****************************************************************************
  343. ;Video terminal sequences: these are for ADM-3A: Modify as you wish
  344. ;Cursor addressing: 
  345. cursadd:
  346.     ld    hl,2        ; get parameters
  347.     add    hl,sp
  348.     ex    de,hl
  349.     call    getparm        ; in HL
  350.     ld    (row),hl    ; row
  351.     call    getparm
  352.     ld    (col),hl    ; column
  353.                 ; <== Insert your own code here
  354.                 ; using values in row and col
  355.     call    print
  356.     db    esc,'=',0    ; ADM-3A leadin
  357.     ld    a,(row)        ; row first
  358.     add    a,' '        ; add offset
  359.     call    cout
  360.     ld    a,(col)        ; sane for column
  361.     add    a,' '
  362.     call    cout
  363.                 ; <== end of your own code
  364.     ret
  365.  
  366. row:    ds    2        ; row
  367. col:    ds    2        ; column
  368.  
  369.  
  370. ;Clear screen:
  371. cls:
  372.     call    print
  373.     db    1ah,0
  374.     ret
  375.  
  376. ;Inverse video on:
  377. invon:
  378.     call    print
  379.     db    esc,'G4',0
  380.     ret
  381.  
  382. ;Inverse video off:
  383. invoff:
  384.     call    print
  385.     db    esc,'G0',0
  386.     ret
  387.  
  388. ;Turn off cursor:
  389. hide:
  390.     call    print
  391.     db    esc,'.1',0
  392.     ret
  393.  
  394. ;Turn on cursor:
  395. show:
  396.     call    print
  397.     db    esc,'.3',0
  398.     ret
  399.  
  400. ;Save cursor position:
  401. savecu:
  402.     ret
  403.  
  404. ;Restore cursor position:
  405. rescu:
  406.     ret
  407.  
  408. ;****************************************************************************
  409.  
  410. ;Service modem interrupt:
  411. mint:
  412.     ret            ; my system doesn't need this
  413.  
  414. ;Initialise interrupt vectors:
  415. invec:
  416.     ret            ; ditto
  417.  
  418. ;De-initialise interrupt vectors:
  419. dinvec:
  420.     ret            ; ditto
  421.  
  422. ;****************** End of user-defined code ********************************
  423. ;        Do not change anything below here.
  424.  
  425. ;Modem character test for 100 ms
  426. mrd:
  427.     push    bc        ; save bc
  428.     ld    bc,100        ; set limit
  429. mrd1:
  430.     call    mirdy        ; char at modem?
  431.     jr    nz,mrd2        ; yes, exit
  432.     ld    hl,1        ; else wait 1ms
  433.     call    waithlms
  434.     dec    bc        ; loop till done
  435.     ld    a,b
  436.     or    c
  437.     jr    nz,mrd1
  438.     ld    hl,0        ; none there, result=0
  439.     xor    a
  440. mrd2:
  441.     pop    bc
  442.     ret
  443.  
  444. ; Inline print routine: destroys A and HL
  445.  
  446. print:
  447.     ex    (sp),hl        ; get address of string
  448. ploop:
  449.     ld    a,(hl)        ; get next
  450.     inc    hl        ; bump pointer
  451.     or    a        ; done if zero
  452.     jr    z,pdone
  453.     call    cout        ; else print
  454.     jr    ploop        ; and loop
  455. pdone:
  456.     ex    (sp),hl        ; restore return address
  457.     ret            ; and quit
  458.  
  459. ;
  460. ;Output a character in A to the console
  461. ;
  462. cout:
  463.     push    bc        ; save regs
  464.     push    de
  465.     push    hl
  466.     ld    e,a        ; character to E
  467.     ld    c,2
  468.     call    bdos        ; print it
  469.     pop    hl
  470.     pop    de
  471.     pop    bc
  472.     ret
  473.  
  474. ;Wait(seconds)
  475. wait:
  476.     ld    hl,2
  477.     add    hl,sp
  478.     ex    de,hl        ; get delay size
  479.     call    getparm
  480.                 ; fall thru to..
  481. ;Wait seconds in HL
  482. waithls:
  483.     push    bc        ; save bc
  484.     push    de        ; de
  485.     push    ix        ; and ix
  486.     ld    ix,0        ; then point ix to 0
  487.                 ; so we don't upset memory-mapped i/o
  488.  
  489. ;Calculate values for loop constants. Need to have two loops to avoid
  490. ;   16-bit overflow with clock speeds above 9 MHz.
  491.  
  492. outerval    equ    (clkspd / 10) + 1
  493. innerval    equ    (6667 / outerval) * clkspd
  494.  
  495. wait10:
  496.     ld    b,outerval
  497.  
  498. wait11:
  499.     ld    de,innerval
  500.  
  501. wait12:
  502.     bit    0,(ix)        ; time-wasters
  503.     bit    0,(ix)
  504.     bit    0,(ix)        ; 20 T-states each
  505.     bit    0,(ix)
  506.     bit    0,(ix)
  507.     bit    0,(ix)
  508.     dec    de
  509.     ld    a,e
  510.     ld    a,d
  511.     or    e
  512.     jr    nz,wait12    ; 150 T-states per inner loop
  513.     djnz    wait11        ; decrement outer loop
  514.     dec    hl        ; ok, decrement count in hl
  515.     ld    a,h
  516.     or    l
  517.     jr    nz,wait10
  518.     pop    ix        ; done -- restore ix
  519.     pop    de        ; de
  520.     pop    bc        ; and bc
  521.     ret
  522.  
  523. ;Wait milliseconds
  524. mswait:
  525.     ld    hl,2
  526.     add    hl,sp
  527.     ex    de,hl        ; get delay size
  528.     call    getparm
  529.                 ; fall thru to..
  530. ;Wait milliseconds in HL
  531. waithlms:
  532.     push    de
  533. w1ms0:
  534.     ld    de,39 * clkspd
  535. w1ms1:
  536.     dec    de
  537.     ld    a,d
  538.     or    e
  539.     jr    nz,w1ms1
  540.     dec    hl
  541.     ld    a,h
  542.     or    l
  543.     jr    nz,w1ms0
  544.     pop    de
  545.     ret
  546.  
  547. ;Get next parameter from (de) into hl
  548. getparm:
  549.     ex    de,hl        ; get address into hl
  550.     ld    e,(hl)        ; get lo
  551.     inc    hl
  552.     ld    d,(hl)        ; then hi
  553.     inc    hl        ; bump for next
  554.     ex    de,hl        ; result in hl, address still in de
  555.     ret
  556.  
  557. ;Get address of user-defined variables
  558.  
  559. getvars:
  560.     ld    hl,uservars
  561.     ret
  562.  
  563. uservars:
  564.     dw    overdrive    ; .OVR etc. drive/user
  565.     dw    overuser
  566.  
  567.  
  568.      if    ($ - codebgn) gt ovsize
  569. toobig:    jp    errval        ; Overlay too large!
  570.      endif
  571.  
  572.     end
  573.