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-OX05.ZZ0 / ZMO-OX05.Z80
Text File  |  2000-06-30  |  13KB  |  618 lines

  1. ; ZMOOX5.Z80 for ZMP 1.3                     Nov 24, '88
  2. ;
  3. ; 89/04/12 - Modified to ZMP v1.5        - George Conover
  4. ;    Updated to ver 1.4 by Ken Reid
  5. ;      Adapted from I2OX-2.ASM by Ken Reid       
  6. ;           Email: Houston NW Znode 713-937-8886
  7. ;       Slight modifications By W. H. Pearre 11/19/88              
  8. ; Modified to v1.3 standard Ron Murray Oct 12, 88
  9. ;
  10. ;-----------------------------------------------------------------------
  11. ;
  12. ;    System-dependent code overlay for ZMODEM
  13. ;
  14. ;   Insert your own code as  necessary    in  this  file.  Code  contained
  15. ; herein  has been written in Z80 code for use with M80 or SLR. Assemble
  16. ; as follows:
  17. ;
  18. ;    SLR ZMO-OX05/h
  19. ;    MLOAD ZMP.COM=ZMODEM.COM,ZMO-OX05.HEX
  20. ;  or
  21. ;    M80 =ZMOOX05.Z80
  22. ;    RELHEX ZMOOX05
  23. ;    MLOAD ZMP.COM=ZMPX.COM,ZMOOX05.HEX
  24. ;
  25. ;
  26. ; (Don't use L80 without changing the source  for  assembly  as  a  CSEG
  27. ; file.)
  28. ;
  29. ;-----------------------------------------------------------------------
  30. ;
  31. ; Notes on modifying this file:
  32. ;
  33. ;    C    requires  that functions do not change either index register (IX
  34. ; or IY). If your overlay requires either of these to be changed, ensure
  35. ; they are restored to the original values on return.
  36. ;
  37. ;    Since  collecting    parameters  from C functions can be tricky, only
  38. ; change the parts marked 'Insert your own code here'. Do NOT modify the
  39. ; jump table at the start. Do NOT modify the entry/exit sections of each
  40. ; function. Do NOT pass 'GO'. Do NOT collect $200.
  41. ;
  42. ;    Apart  from  defining  modem  functions,  this  file  also  defines
  43. ; terminal characteristics. Examples provided are for ADM-3A (with a few
  44. ; of my own additions). Modify to suit    your  own  terminal.  An  inline
  45. ; print routine is provided for printing strings in the usual way, usage
  46. ; is:
  47. ;
  48. ;              CALL    PRINT
  49. ;              DB    'required string',0
  50. ;
  51. ;-----------------------------------------------------------------------
  52. ;
  53. ;    Don't forget to set your clock speed at the clkspd variable.
  54. ;
  55. ;    If you find  your    overlay  exceeds  the  maximum    size  (currently
  56. ; 0400h),  you    will have to contact me for another version. If too many
  57. ; people need to do it, we haven't allowed enough room.
  58. ;
  59. ; Ron Murray Aug 15, 88
  60. ;
  61. ;-----------------------------------------------------------------------
  62. ;
  63. NO    EQU    0
  64. YES    EQU    NOT NO
  65. ;
  66. ; User-set variables
  67. ;
  68. CLKSPD    EQU    4        ; Processor clock speed in MHz
  69. ;
  70. DEBUG    EQU    NO
  71. ;
  72. ;Set the following two equates to the drive and user area which will contain
  73. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  74. ;   (null) to locate them on the drive from which ZMP was invoked.
  75.  
  76. OVERDRIVE      EQU     'E'     ; Drive to find overlay files on ('A'-'P')
  77. OVERUSER       EQU     15      ; User area to find files
  78. ;
  79. USERDEF    EQU    0145H        ; Origin of this overlay.  This address
  80. ;                ;   may change with subsequent revisions
  81. ; NOT user-set variables
  82. ;
  83. MSPEED    EQU    03CH        ; Location of current baud rate. 3CH IS NORMAL
  84. OVSIZE    EQU    0400H        ; Max size of this overlay
  85. ;
  86.     .Z80            ; Use z80 code
  87.     ASEG            ; Absolute
  88. ;
  89.      IF    DEBUG
  90.     ORG    100H        ; So you can debug it with CEBUG, ZSID,
  91. ;                ;   etc.
  92.      ELSE
  93.     ORG    USERDEF
  94.      ENDIF            ; DEBUG
  95. ;
  96. ESC    EQU    1BH
  97. CTRLQ    EQU    11H
  98. CR    EQU    0DH
  99. LF    EQU    0AH
  100. BDOS    EQU    5
  101. ;
  102. PORT    EQU    0CH    ; Your base port (data or status)
  103. MDCTL1    EQU    PORT+1    ; Modem control port
  104. MDDATP    EQU    PORT    ; Modem data port
  105. MDRCV    EQU    01H    ; Modem receive ready
  106. MDSND    EQU    04H    ; Modem send ready bit
  107. MDTXE    EQU    01H    ; Modem send buffer empty, holding buffer empty
  108. BRPORT    EQU    04H    ; CTC timer port to set baudrate
  109.  
  110. ; Jump table for the overlay: do NOT change this
  111. ;
  112. CODEBGN    EQU    $
  113. ;
  114. JUMPTAB:JP    SCRNPR        ; Screen print
  115.     JP    MRD        ; Modem read with timeout
  116.     JP    MCHIN        ; Get a character from modem
  117.     JP    MCHOUT        ; Send a character to the modem
  118.     JP    MORDY        ; Test for tx buffer empty
  119.     JP    MIRDY        ; Test for character received
  120.     JP    SNDBRK        ; Send break
  121.     JP    CURSADD        ; Cursor addressing
  122.     JP    CLS        ; Clear screen
  123.     JP    INVON        ; Inverse video on
  124.     JP    INVOFF        ; Inverse video off
  125.     JP    HIDE        ; Hide cursor
  126.     JP    SHOW        ; Show cursor
  127.     JP    SAVECU        ; Save cursor position
  128.     JP    RESCU        ; Restore cursor position
  129.     JP    MINT        ; Service modem interrupt
  130.     JP    INVEC        ; Initialise interrupt vectors
  131.     JP    DINVEC        ; De-initialise interrupt vectors
  132.     JP    MDMERR        ; Test uart flags for error
  133.     JP    DTRON        ; Turn DTR on
  134.     JP    DTROFF        ; Turn DTR OFF
  135.     JP    INIT        ; Initialise uart
  136.     JP    WAIT        ; Wait seconds
  137.     JP    MSWAIT        ; Wait milliseconds
  138.     JP    USERIN        ; User-defined entry routine
  139.     JP    USEROUT        ; User-defined exit routine
  140.     JP    GETVARS        ; Get system variables
  141.       JP    SETPORT        ; Set port (0 or 1)
  142.     JP    SPARE        ; Spare for later use
  143.     JP    SPARE        ; Spare for later use
  144.     JP    SPARE        ; Spare for later use
  145.     JP    SPARE        ; Spare for later use
  146.     JP    SPARE        ; Spare for later use
  147.     JP    SPARE        ; Spare for later use
  148. ;
  149. ; Screen print function
  150. ;
  151. SCRNPR:    DS    0    
  152. ;
  153. ; <== Insert your own code here
  154. ;
  155. ;    CALL    PRINT
  156. ;    DB    'This function not supported.',CR,LF,0
  157. ;       
  158.     RET
  159. ; <== End of your own code
  160. ;
  161. SPARE:    RET
  162. ;
  163. ; User-defined entry routine
  164. ;
  165. USERIN:    RET
  166. ;
  167. ; User-defined exit routine
  168. ;
  169. USEROUT:RET
  170. ;
  171. ; Get a character from the modem: return in HL
  172. ; It is not necessary to test for status
  173. ;
  174. MCHIN:    PUSH    BC
  175. ;
  176.     IN    A,(MDDATP)    ; Get the character in A
  177. ;
  178.     LD    L,A        ; Put in HL
  179.     LD    H,0
  180.     OR    A        ; Set/clear Z
  181.     POP    BC
  182.     RET
  183. ;
  184. ;Send a character to the modem
  185. ;
  186. MCHOUT:    LD    HL,2        ; Get the character
  187.     ADD    HL,SP
  188.     LD    A,(HL)        ; In A
  189. ;
  190.     PUSH    BC
  191.     LD    C,A
  192. ;
  193. MCHOUT1:IN    A,(MDCTL1)
  194.     AND    MDSND
  195.     JR    Z,MCHOUT1
  196.     LD    A,C
  197.     OUT    (MDDATP),A
  198.     POP    BC
  199.     RET            ; Done
  200. ;
  201. ;Test for output ready: return TRUE (1) in HL if ok
  202. ;
  203. MORDY:    DS    0
  204. ;
  205.     IN    A,(MDCTL1)
  206.     AND    MDTXE
  207.     JR    Z,MORDYX
  208.     LD    L,1
  209.     LD    H,0
  210. ;
  211. MORDYX:    DS    0
  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. ;
  219. MIRDY:    DS    0
  220. ;
  221.     IN    A,(MDCTL1)
  222.     AND    MDRCV
  223.     JR    Z,MIRDY1
  224.     LD    L,1
  225.     JR    MIRDYX
  226. ;
  227. MIRDY1:    LD    L,0
  228. ;
  229. MIRDYX:    LD    H,00H
  230. ;
  231.     LD    A,L        ; Set/clear Z
  232.     OR    A
  233.     RET
  234. ;
  235. ;Send a break to the modem: leave empty if your system can't do it
  236. ;
  237. SNDBRK:    DS    0
  238. ;
  239.     LD    A,5
  240.     OUT    (MDCTL1),A    ; Send to the status port
  241.     LD    A,0F8H        ; DTR normal, send break tone
  242.     OUT    (MDCTL1),A
  243. ;
  244.     LD    HL,300
  245.     CALL    WAITHLMS    ; Wait 300 milliseconds
  246. ;
  247.     LD    A,5        ; Restore normal, 8 bits, DTR on, etc.
  248.     OUT    (MDCTL1),A
  249.     LD    A,0E8H
  250.     OUT    (MDCTL1),A
  251.     RET
  252. ;
  253. ; Test UART flags for error: return TRUE (1) in HL if error
  254. ;
  255. MDMERR:    DS    0
  256. ;
  257.     LD    A,010H        ; Register 0, reset interrupts
  258.     OUT    (MDCTL1),A
  259.     IN    A,(MDCTL1)
  260. ;
  261.     LD    A,L        ; Set/clear Z
  262.     OR    A
  263.     RET
  264. ;
  265. ; Turn DTR (and optionally RTS) ON
  266. ;
  267. DTRON:    DS    0
  268. ;
  269.     LD    A,05H
  270.     OUT    (MDCTL1),A
  271.     LD    A,0E8H
  272.     OUT    (MDCTL1),A
  273. ;
  274.     RET
  275. ;
  276. ; Turn DTR ( and RTS?) OFF
  277. ;
  278. DTROFF:    DS    0
  279. ;
  280.     LD    A,05H
  281.     OUT    (MDCTL1),A
  282.     LD    A,078H
  283.     OUT    (MDCTL1),A
  284. ;
  285.     RET
  286. ;
  287. ;Initialise the UART
  288. ;
  289. INIT:    LD    HL,2        ; Get parameters
  290.     ADD    HL,SP
  291.     EX    DE,HL
  292.     CALL    GETPARM        ; In HL
  293.     LD    (BRATE),HL    ; Baud rate
  294.     CALL    GETPARM
  295.     LD    (PARITY),HL    ; Parity
  296.     CALL    GETPARM
  297.     LD    (DATA),HL    ; Data bits
  298.     CALL    GETPARM
  299.     LD    (STOP),HL    ; Stop bits
  300. ;
  301.     PUSH    BC
  302.     LD    A,0        ; Select register
  303.     OUT    (MDCTL1),A
  304.     LD    A,018H        ; Throw out of mode
  305.     OUT    (MDCTL1),A
  306.     LD    A,04H        ; Select register
  307.     OUT    (MDCTL1),A
  308.     LD    A,044H        ; Set ASCII parameters (44=1, 4C=2 stop)
  309.     OUT    (MDCTL1),A
  310.     LD    A,03H        ; Select register
  311.     OUT    (MDCTL1),A
  312.     LD    A,0C1H        ; Enable receive
  313.     OUT    (MDCTL1),A
  314.     LD    A,05H        ; Select register
  315.     OUT    (MDCTL1),A
  316.     LD    A,0EAH        ; Enable send, 'DTR', RTS'
  317.     OUT    (MDCTL1),A
  318. ;
  319.         LD    A,(BRATE)    ; minor correction - DIW
  320.     CP    1        ; 300 bps
  321.     JP    Z,OK300
  322.     CP    5        ; 1200 bps
  323.     JP    Z,OK1200
  324.     CP    6        ; 2400 bps
  325.     JP    Z,OK2400
  326.     CP    8        ; 9600 bps
  327.     JP    Z,OK9600
  328.     JR    SETBRX        ; Not valid
  329. ;
  330. ;
  331. OK300:    LD    A,1        ; MSPEED 300 baud value
  332.     LD    HL,BD300
  333.     JP    LOADBD
  334. ;
  335. OK1200:    LD    A,5
  336.     LD    HL,BD1200
  337.     JP    LOADBD
  338. ;
  339. OK2400:    
  340.     LD    A,6
  341.     LD    HL,BD2400
  342.     JP    LOADBD
  343. ;
  344. OK9600:    LD    A,8
  345.     LD    HL,BD9600
  346. ;
  347. LOADBD:    LD    (MSPEED),A    ; Change time-to-send to match baudrate
  348.     LD    A,L        ; Get "LSP" baud rate byte
  349.     OUT    (BRPORT),A
  350.     LD    A,H        ; Get "MSP" baud rate byte
  351.     OUT    (BRPORT),A
  352.     RET
  353.  
  354. SETBRX:    POP    BC
  355.     XOR    A
  356.     LD    (MSPEED),A
  357.     RET
  358. ;
  359. BD300    EQU    384        ; 300 baud
  360. BD1200    EQU    96        ; 1200 baud
  361. BD2400    EQU    48        ; 2400 baud
  362. BD9600    EQU    12        ; 9600 baud
  363. ;
  364. ;
  365. BRATE:    DS    2        ; Baud rate:
  366.                 ; 0 = 110 baud    1 = 300 baud    2 = 450 baud
  367.                 ; 3 = 600 baud    4 = 710 baud    5 = 1200 baud
  368.                 ; 6 = 2400 baud 7 = 4800 baud    8 = 9600 baud
  369.                 ; 9 = 19200 baud
  370. PARITY:    DW    'N'        ; Parity (will be 'N', 'E' or 'O')
  371. DATA:    DW    '8'        ; Data bits (will be 7 or 8)
  372. STOP:    DS    '1'        ; Stop bits (will be 1 or 2)
  373. ;
  374. ;-----------------------------------------------------------------------
  375. ;
  376. ; Set the port. ZMP supplies either 0 or 1 as a parameter.
  377. ;
  378. setport:
  379.     ld    hl,2        ; get port number
  380.     add    hl,sp
  381.     ex    de,hl
  382.     call    getparm        ; in HL (values are 0 and 1)
  383.  
  384.                 ; <== Insert your own code here
  385.  
  386.                 ; <== End of your own code
  387.     ret
  388. ;
  389. ; Video terminal sequences: these are for ADM-3A: Modify as you wish
  390. ;
  391. ; Cursor addressing
  392. ;
  393. CURSADD:LD    HL,2        ; Get parameters
  394.     ADD    HL,SP
  395.     EX    DE,HL
  396.     CALL    GETPARM        ; In HL
  397.     LD    (ROW),HL    ; Row
  398.     CALL    GETPARM
  399.     LD    (COL),HL    ; Column
  400. ;
  401. ; <== Insert your own code here, using values in row and column
  402. ;
  403.     CALL    PRINT
  404.     DB    ESC,'=',0    ; ADM-3A leadin
  405.     LD    A,(ROW)        ; Row first
  406.     ADD    A,' '        ; Add offset
  407.     CALL    COUT
  408.     LD    A,(COL)        ; Sane for column
  409.     ADD    A,' '
  410.     CALL    COUT
  411. ;
  412. ; <== end of your own code
  413. ;
  414.     RET
  415. ;
  416. ROW:    DS    2        ; Row
  417. COL:    DS    2        ; Column
  418. ;
  419. ;Clear screen
  420. ;
  421. CLS:    CALL    PRINT
  422.     DB    01AH,0
  423.     RET
  424. ;
  425. ; Inverse video on
  426. ;
  427. INVON:    CALL    PRINT
  428.     DB    ESC,'j',0
  429.     RET
  430. ;
  431. ; Inverse video off
  432. ;
  433. INVOFF:    CALL    PRINT
  434.     DB    ESC,'k',0
  435.     RET
  436. ;
  437. ; Turn off cursor
  438. ;
  439. HIDE:    CALL    PRINT
  440.     DB    ESC,'z',0
  441.     RET
  442. ;
  443. ; Turn on cursor
  444. ;
  445. SHOW:    CALL    PRINT
  446.     DB    ESC,'v',0
  447.     RET
  448. ;
  449. ; Save cursor position
  450. ;
  451. SAVECU:    RET
  452. ;
  453. ; Restore cursor position
  454. ;
  455. RESCU:    RET
  456. ;
  457. ;-----------------------------------------------------------------------
  458. ;
  459. ; Service modem interrupt
  460. ;
  461. MINT:    RET            ; My system doesn't need this
  462. ;
  463. ; Initialise interrupt vectors
  464. ;
  465. INVEC:    RET            ; Ditto
  466. ;
  467. ; De-initialise interrupt vectors
  468. ;
  469. DINVEC:    RET            ; Ditto
  470. ;
  471. ;------------------- End of user-defined code --------------------------
  472. ;         Do not change anything below here
  473. ;
  474. ; Modem character test for 100 ms
  475. ;
  476. MRD:    PUSH    BC        ; Save BC
  477.     LD    BC,100        ; Set limit
  478. ;
  479. MRD1:    CALL    MIRDY        ; Char at modem?
  480.     JR    NZ,MRD2        ; Yes, exit
  481.     LD    HL,1        ; Else wait 1 ms
  482.     CALL    WAITHLMS
  483.     DEC    BC        ; Loop till done
  484.     LD    A,B
  485.     OR    C
  486.     JR    NZ,MRD1
  487.     LD    HL,0        ; None there, result=0
  488.     XOR    A
  489. ;
  490. MRD2:    POP    BC
  491.     RET
  492. ;
  493. ; Inline print routine: destroys A and HL
  494. ;
  495. PRINT:    EX    (SP),HL        ; Get address of string
  496. ;
  497. PLOOP:    LD    A,(HL)        ; Get next
  498.     INC    HL        ; Bump pointer
  499.     OR    A        ; Done if zero
  500.     JR    Z,PDONE
  501.     CALL    COUT        ; Else print
  502.     JR    PLOOP        ; And loop
  503. ;
  504. PDONE:    EX    (SP),HL        ; Restore return address
  505.     RET            ; And quit
  506. ;
  507. ; Output a character in A to the console
  508. ;
  509. COUT:    PUSH    BC        ; Save registers
  510.     PUSH    DE
  511.     PUSH    HL
  512.     LD    E,A        ; Character to E
  513.     LD    C,2
  514.     CALL    BDOS        ; Print it
  515.     POP    HL
  516.     POP    DE
  517.     POP    BC
  518.     RET
  519. ;
  520. ; Wait(seconds)
  521. ;
  522. WAIT:    LD    HL,2
  523.     ADD    HL,SP
  524.     EX    DE,HL        ; Get delay size
  525.     CALL    GETPARM
  526. ;                ; Fall thru to...
  527. ; Wait seconds in HL
  528. ;
  529. WAITHLS:PUSH    BC        ; Save BC
  530.     PUSH    DE        ; DE
  531.     PUSH    IX        ; And IX
  532.     LD    IX,0        ; Then point IX to 0
  533. ;                ;   so we don't upset memory-mapped I/O
  534. ;
  535. ; Calculate values for loop constants. Need to have two loops to avoid
  536. ; 16-bit overflow with clock speeds above 9 MHz.
  537. ;
  538. OUTERVAL EQU    (CLKSPD    / 10) +    1
  539. ;
  540. INNERVAL EQU    (6667 /    OUTERVAL) * CLKSPD
  541. ;
  542. WAIT10:    LD    B,OUTERVAL
  543. ;
  544. WAIT11:    LD    DE,INNERVAL
  545. ;
  546. WAIT12:    BIT    0,(IX)        ; Time-wasters
  547.     BIT    0,(IX)
  548.     BIT    0,(IX)        ; 20 T-states each
  549.     BIT    0,(IX)
  550.     BIT    0,(IX)
  551.     BIT    0,(IX)
  552.     DEC    DE
  553.     LD    A,E
  554.     LD    A,D
  555.     OR    E
  556.     JR    NZ,WAIT12    ; 150 T-states per inner loop
  557.     DJNZ    WAIT11        ; Decrement outer loop
  558.     DEC    HL        ; Ok, decrement count in HL
  559.     LD    A,H
  560.     OR    L
  561.     JR    NZ,WAIT10
  562.     POP    IX        ; Done -- restore IX
  563.     POP    DE        ; DE
  564.     POP    BC        ; And BC
  565.     RET
  566. ;
  567. ; Wait milliseconds
  568. ;
  569. MSWAIT:    LD    HL,2
  570.     ADD    HL,SP
  571.     EX    DE,HL        ; Get delay size
  572.     CALL    GETPARM
  573. ;
  574. ; Wait milliseconds in HL
  575. ;
  576. WAITHLMS:
  577.     PUSH    DE
  578. ;
  579. W1MS0:    LD    DE,39 *    CLKSPD
  580. ;
  581. W1MS1:    DEC    DE
  582.     LD    A,D
  583.     OR    E
  584.     JR    NZ,W1MS1
  585.     DEC    HL
  586.     LD    A,H
  587.     OR    L
  588.     JR    NZ,W1MS0
  589.     POP    DE
  590.     RET
  591. ;
  592. ; Get next parameter from (DE) into HL
  593. ;
  594. GETPARM:EX    DE,HL        ; Get address into HL
  595.     LD    E,(HL)        ; Get low
  596.     INC    HL
  597.     LD    D,(HL)        ; Then hihi
  598.     INC    HL        ; Bump for next
  599.     EX    DE,HL        ; Result in HL, address still in DE
  600.     RET
  601. ;
  602. ;
  603. ;Get address of user-defined variables
  604. ;
  605. getvars:
  606.        ld      hl,uservars
  607.        ret
  608. ;
  609. uservars:
  610.        dw      overdrive       ; .OVR etc. drive/user
  611.        dw      overuser
  612. ;
  613.      IF    ($ - CODEBGN) GT OVSIZE
  614. TOOBIG:    JP    ERRVAL        ; Overlay is too large
  615.      ENDIF
  616. ;
  617.     END
  618.