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

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