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 / ENTERPRS / CPM / TERMS / ZMP-SRC.LZH / ZMPOVL.MAC < prev    next >
Text File  |  2000-06-30  |  13KB  |  583 lines

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