home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / modem / zmo-ov05.azm < prev    next >
Encoding:
Text File  |  1993-06-08  |  14.3 KB  |  640 lines

  1. ; User-set variables:
  2.  
  3. CLKSPD    EQU    4        ; Processor clock speed in MHz
  4.  
  5. ;Set the following two equates to the drive and user area which will contain
  6. ;   ZMP's .OVR files, .CFG file, .FON file and .HLP file. Set both to zero
  7. ;   (null) to locate them on the drive from which ZMP was invoked.
  8.  
  9. OVERDRIVE EQU    0        ; Drive to find overlay files on ('A'-'P')
  10. OVERUSER EQU    0        ; User area to find files
  11.  
  12. ;------------------------------------------------------------------------------
  13. ;
  14. ;
  15. YES    EQU    0FFH
  16. NO    EQU    0
  17. ;
  18. PORT    EQU    30H
  19. MDCTRL    EQU    PORT+1
  20. MDDATA    EQU    PORT
  21. MDRCV    EQU    02H
  22. MDSND    EQU    01H
  23. MDTXE    EQU    05H
  24. ;
  25. MDMODE    EQU    82H
  26. MDRSET    EQU    42H
  27. MDSET1    EQU    4EH
  28. MDSET2    EQU    0CEH
  29. MDCOM    EQU    37H
  30. ;
  31. AJUMP    EQU    0C3H
  32. BDOS    EQU    0005H
  33. BIOS    EQU    0001H
  34. EXITCPM EQU    2C80H
  35. INTVEC    EQU    0EFFEH
  36. ;
  37. ;============================================================================
  38. ; NOT user-set variables
  39.  
  40. USERDEF EQU    0145H        ; Origin of this overlay.  This address may
  41.                 ; change with subsequent revisions.
  42. MSPEED    EQU    05CH        ; location of current baud rate. 
  43. OVSIZE    EQU    0400H        ; max size of this overlay
  44.  
  45. ESC    EQU    1BH
  46. CR    EQU    0DH
  47. LF    EQU    0AH
  48.  
  49.     ORG    USERDEF
  50.  
  51. CODEBGN EQU    $
  52.  
  53. ;Jump table for the overlay: do NOT change this
  54. JUMPTAB:
  55.     JP    SCRNPR        ; screen print
  56.     JP    MRD        ; modem read with timeout
  57.     JP    MCHIN        ; get a character from modem
  58.     JP    MCHOUT        ; send a character to the modem
  59.     JP    MORDY        ; test for tx buffer empty
  60.     JP    MIRDY        ; test for character received
  61.     JP    SNDBRK        ; send break
  62.     JP    CURSADD        ; cursor addressing
  63.     JP    CLS        ; clear screen
  64.     JP    INVON        ; inverse video on
  65.     JP    INVOFF        ; inverse video off
  66.     JP    HIDE        ; hide cursor
  67.     JP    SHOW        ; show cursor
  68.     JP    SAVECU        ; save cursor position
  69.     JP    RESCU        ; restore cursor position
  70.     JP    MINT        ; service modem interrupt
  71.     JP    INVEC        ; initialise interrupt vectors
  72.     JP    DINVEC        ; de-initialise interrupt vectors
  73.     JP    MDMERR        ; test uart flags for error
  74.     JP    DTRON        ; turn DTR on
  75.     JP    DTROFF        ; turn DTR OFF
  76.     JP    INIT        ; initialise uart
  77.     JP    WAIT        ; wait seconds
  78.     JP    MSWAIT        ; wait milliseconds
  79.     JP    USERIN        ; user-defined entry routine
  80.     JP    USEROUT        ; user-defined exit routine
  81.     JP    GETVARS        ; get system variables
  82.     JP    SETPORT        ; Set port (0 or 1)
  83. ;
  84. ; Spare jumps for compatibility with future versions
  85. ;
  86.     JP    SPARE        ; spare for later use
  87.     JP    SPARE        ; spare for later use
  88.     JP    SPARE        ; spare for later use
  89.     JP    SPARE        ; spare for later use
  90.     JP    SPARE        ; spare for later use
  91.     JP    SPARE        ; spare for later use
  92. ;====================================================================
  93. ;
  94. I$MDCTRL:
  95.     DI
  96.     IN    A,(MDCTRL)
  97.     EI
  98.     RET
  99. ;
  100. I$MDTXE:
  101.     DI
  102.     IN    A,(MDCTRL)
  103.     EI
  104.     RET
  105. ;
  106. I$MDDATA:
  107.     DI
  108.     IN    A,(MDDATA)
  109.     EI
  110.     RET
  111. ;
  112. O$MDDATA:
  113.     EI
  114.     OUT    (MDDATA),A
  115.     DI
  116.     RET
  117. ;
  118. A$MDRCV:
  119.     AND    MDRCV
  120.     RET
  121. ;
  122. C$MDRCV:
  123.     CP    MDRCV
  124.     RET
  125. ;
  126. A$MDSND:
  127.     AND    MDSND
  128.     RET
  129. ;
  130. C$MDSND:
  131.     CP    MDSND
  132.     RET
  133. ;
  134. A$MDTXE:
  135.     AND    MDTXE
  136.     RET
  137. ;
  138. C$MDTXE:
  139.     CP    MDTXE
  140.     RET
  141. ;
  142. J$EXITVEC:
  143.     JP    DINVEC
  144. ;
  145. ;============================================================================
  146. ; Main code starts here
  147. ;
  148. ;Screen print function
  149. SCRNPR:
  150.     CALL    PRINT
  151.     DEFB    'Zmodem v1.5 overlay for Osborne Vixen '
  152.     DEFB    ' v0.1  dated  8 December 1989',CR,LF
  153.     DEFB    'Print screen function is not supported.',CR,LF,0
  154. SPARE:
  155.     RET            ; This ret used by both scrnpr and spare
  156.  
  157. ; User-defined entry routine: 
  158. ; Install a new function key table for the Sanyo MBC-1200/1250
  159. USERIN:
  160.     RET
  161.  
  162. ; User-defined exit routine: Reinstall normal function key table
  163. USEROUT:
  164.     RET
  165.  
  166.  
  167. ;============================================================================
  168. ;    Modem control area:   UART 8251  No baud rate generator
  169. ;  -------------------------------------------------
  170. ;  | DSR | syn |  FE |  OE |  PE | TxE | RxR | TxR |  Stauts format
  171. ;  -------------------------------------------------
  172. ;  | EH  | IR  | RTS |  ER | SBRK| RxE | DTR | TxE |  Command format
  173. ;  -------------------------------------------------
  174. ;  | S2  | S1  |  EP | PEN |  L2 |  L1 |  B2 |  B1 |  Commands
  175. ;  -------------------------------------------------
  176. ;   
  177. ;  S2 S1 Bits   EP      PEN         L2 L1 Bits   B2 B1 Rate
  178. ;   0  0  ?     0 Odd    0 Disable    0  0  5      0  0   ?
  179. ;   0  1  1     1 Even  1 Enable     0  1  6      0  1  X1
  180. ;   1  0  1.5                        1  0  7      1  0  X16
  181. ;   1  1  2                          1  1  8      1  1  X64
  182. ;
  183. ;Get a character from the modem: return in HL
  184. MCHIN:                ; <== Insert your own code here
  185.     IN    A,(MDDATA)
  186.                 ; <== End of your own code
  187.     LD    L,A        ; put in HL
  188.     LD    H,0
  189.     OR    A        ; set/clear Z
  190.     RET
  191.  
  192. ;Send a character to the modem
  193. MCHOUT:
  194.     LD    HL,2        ; get the character
  195.     ADD    HL,SP
  196.     LD    A,(HL)
  197.                 ; <== Insert your own code here
  198.     OUT    (MDDATA),A
  199.                 ; <== End of your own code
  200.     RET            ; done
  201.  
  202. ;Test for output ready: return TRUE (1) in HL if ok
  203. MORDY:                ; <== Insert your own code here
  204.     LD    HL,0
  205.     IN    A,(MDCTRL)
  206.     BIT     0,A
  207.     JR    Z,MORDY1
  208.     INC    HL
  209.                 ; <== End of your own code
  210. MORDY1:    LD    A,L        ; set/clear Z
  211.     OR    A
  212.     RET
  213.  
  214. ;Test for character at modem: return TRUE (1) in HL if so
  215. MIRDY:                ; <== Insert your own code here
  216.     LD    HL,0
  217.     IN    A,(MDCTRL)
  218.     BIT     1,A
  219.     JR    Z,MINDY1
  220.     INC    HL
  221.                 ; <== End of your own code
  222. MINDY1:    LD    A,L        ; set/clear Z
  223.     OR    A
  224.     RET
  225.  
  226. ;Send a break to the modem: leave empty if your system can't do it
  227. SNDBRK:
  228.     LD    A,00001000B
  229.     OUT    (MDCTRL),A
  230.     LD    HL,300        ; wait 300 mS
  231.     CALL    WTHLMS
  232.     LD    A,00110111B
  233.     OUT    (MDCTRL),A
  234.     RET
  235.  
  236. ;Test UART flags for error: return TRUE (1) in HL if error.
  237. MDMERR:                ; <== Insert your own code here
  238.     LD    HL,0
  239.     IN    A,(MDCTRL)
  240.     BIT     4,A
  241.     JR    Z,MDMER1
  242.     LD    A,00110111B    ; if error reset UART
  243.     OUT    (MDCTRL),A
  244.     INC    HL
  245.                 ; <== End of your own code
  246. MDMER1:    LD    A,L        ; set/clear Z
  247.     OR    A
  248.     RET
  249.  
  250. ;Turn DTR ON
  251. DTRON:
  252.     LD    A,00110111B
  253.     OUT    (MDCTRL),A
  254.     RET
  255.  
  256. ;Turn DTR OFF
  257. DTROFF:
  258.     LD    A,00110101B
  259.     OUT    (MDCTRL),A
  260.     RET
  261.  
  262. ;Initialise the uart
  263. INIT:
  264.     LD    HL,2        ; get parameters
  265.     ADD    HL,SP
  266.     EX    DE,HL
  267.     CALL    GETPARM        ; in HL and save it in ..
  268.     LD    (BRATE),HL    ; baud rate
  269.     CALL    GETPARM
  270.     LD    (PARITY),HL    ; parity
  271.     CALL    GETPARM
  272.     LD    (DATA),HL    ; data bits (BINARY 7 or 8)
  273.     CALL    GETPARM
  274.     LD    (STOP),HL    ; stop bits (BINARY 1 or 2)
  275.                 ; <== Insert your own code here
  276.     LD    A,5        ; load mspeed with the current (default)
  277.     LD    (MSPEED),A    ; brate value if the new rate is valid
  278.     LD    A,01000010B    ; reset 8251 and leave DTR on
  279.     OUT    (MDCTRL),A
  280.     LD    A,01001110B    ; 1 stop bit, parity disabled, 8 bits, X16
  281.     CALL    INIT2        ; change UART default settings 
  282.     OUT    (MDCTRL),A
  283.     LD    A,00110111B    ; FIX, no reset, RTS on, Error reset,
  284.     OUT    (MDCTRL),A    ; no break, RX enable, DTR on, TX enable
  285.     RET            ; <== End of your own code
  286.  
  287. ; Change default UART settings to those set by ZMP escape commands
  288. INIT2:
  289.     LD    E,A        ; save default settings 01001110b
  290.     LD    A,(BRATE)
  291.     CP    1        ; if 300 baud; set bit 0, X64
  292.     JR    NZ,INIT3
  293.     SET    0,E
  294.     LD    (MSPEED),A    ; change mspeed value for new baud rate
  295. INIT3:
  296.     LD    A,(DATA)
  297.     CP    7        ; if 7 data bits; reset bit 2
  298.     JR    NZ,INIT4
  299.     RES     2,E
  300. INIT4:
  301.     LD    A,(PARITY)
  302.     CP    'O'        ; if Odd parity; set bit 4, reset bit 5
  303.     JR    NZ,INIT5
  304.     SET    4,E
  305.     RES     5,E
  306. INIT5:
  307.     CP    'E'        ; if Even parity; set bits 4 and 5
  308.     JR    NZ,INIT6
  309.     SET    4,E
  310.     SET    5,E
  311. INIT6:
  312.     LD    A,(STOP)
  313.     CP    2        ; if 2 stop bits; set bit 7
  314.     JR    NZ,INIT7
  315.     SET    7,E
  316. INIT7:
  317.     LD    A,E        ; load new mode back in register a
  318.     RET
  319.  
  320. ;--------------------------------------------------------------------------
  321.  
  322. STOP:    DEFW    1        ; stop bits:  1 or 2
  323. PARITY:    DEFW    'N'        ; parity:     N, O or E
  324. DATA:    DEFW    8        ; data bits:  7 or 8
  325. BRATE:    DEFW    6        ; baud rate:  see below
  326.  
  327. ;--------------------------------------------------------------------------
  328. ; Values of brate for each baud rate allowed
  329. ;
  330. ; brate   baud rate       brate   baud rate       brate   baud rate
  331. ;   0        110            5       1200            9       19200
  332. ;   1        300            6       2400           10       38400
  333. ;   2        450            7       4800           11       57600
  334. ;   3        600            8       9600           12       76800
  335. ;   4        710
  336. ;
  337. ; Set the port. ZMP supplies either 0 or 1 as a parameter.
  338. ;
  339. SETPORT:
  340.     LD    HL,2        ; get port number
  341.     ADD    HL,SP
  342.     EX    DE,HL
  343.     CALL    GETPARM        ; in HL (values are 0 and 1)
  344.  
  345.                 ; <== Insert your own code here
  346.  
  347.                 ; <== End of your own code
  348.     RET
  349. ;
  350. ;============================================================================
  351. ;    Video terminal sequences for the Osborne VIXEN
  352. ;Cursor addressing: 
  353. CURSADD:
  354.     LD    HL,2        ; get parameters
  355.     ADD    HL,SP
  356.     EX    DE,HL
  357.     CALL    GETPARM        ; in HL
  358.     LD    (ROW),HL    ; row
  359.     CALL    GETPARM
  360.     LD    (COL),HL    ; column
  361.                 ; <== Insert your own code here
  362.                 ; using values in row and col
  363.     CALL    PRINT
  364.     DEFB    ESC,'=',0    ; Sanyo leadin characters
  365.     LD    A,(ROW)        ; row first
  366.     ADD    A,' '        ; add offset
  367.     CALL    COUT
  368.     LD    A,(COL)        ; same for column
  369.     ADD    A,' '
  370.     CALL    COUT
  371.                 ; <== end of your own code
  372.     RET
  373.  
  374. ROW:    DEFW    0        ; row
  375. COL:    DEFW    0        ; column
  376.  
  377. ;Clear screen:
  378. CLS:
  379.     CALL    PRINT
  380.     DEFB    1AH,0
  381.     RET
  382.  
  383. ;Inverse video on:
  384. INVON:
  385.     RET
  386.  
  387. ;Inverse video off:
  388. INVOFF:
  389.     RET
  390.  
  391. ;Turn off cursor:
  392. HIDE:
  393.     RET
  394.  
  395. ;Turn on cursor:
  396. SHOW:
  397.     RET
  398.  
  399. ;Save cursor position:
  400. SAVECU:
  401.     RET
  402.  
  403. ;Restore cursor position:
  404. RESCU:
  405.     RET
  406.  
  407. ;****************************************************************************
  408.  
  409. ;Service modem interrupt:
  410. MINT:
  411.     RET            ; Not used by the Osborne VIXEN
  412.  
  413. ;Initialise interrupt vectors:
  414. INVEC:
  415.     LD    C,7        ; Use BDOS to obtain current IOBYTE
  416.     CALL    BDOS        ; 
  417.     LD    (OLDIOB),A    ; Save old IOBYTE
  418.     AND    3FH        ; 
  419.     OR    80H        ; Make CEN: port new LST: device
  420.     LD    E,A
  421.     LD    C,8
  422.     CALL    BDOS        ; Use BDOS to place new IOBYTE in first
  423.                 ;   page of memory
  424. ;
  425.     DI            ; DISABLE interrupts
  426.     LD    HL,(INTVEC)    ; Get serial port interrupt processor
  427.                 ;   address
  428.     LD    (OLDVEC),HL    ; Save serial port interrupt processor
  429.                 ;   address
  430.     DEC    HL
  431.     DEC    HL
  432.     DEC    HL        ; HL = next interrupt processor address
  433.     LD    (INTVEC),HL    ; Now have first interrupt processor
  434.                 ;   rather than second
  435. ;
  436. ;
  437. ; Initialize the interrupt vector system
  438. ;
  439.     LD    HL,(BIOS)    ; Find start of BIOS
  440.     LD    L,3CH        ; Displacement of baud rate byte from
  441.                 ;   start of BIOS
  442.     LD    (OLDBAUD),A    ; Save original baud rate byte
  443.  
  444.     LD    L,3BH        ; Displacement of 8251 mode byte from
  445.                 ;   start of bios
  446.     LD    A,(HL)        ; Old mode byte set by ROM is 2sb, no
  447.                 ;   parity, 8db, x16 clock
  448.     LD    (OLDMODE),A    ; Save original 8251 mode byte
  449. ;
  450.     LD    B,L
  451.     LD    A,MDSET1    ; 1 sb, np, 8 db, x16 clock mode byte
  452.     CALL    IORESET        ; Use extended bios jump to reset 8251
  453.     LD    A,MDCOM        ; RTS, DTR, Txd, Rxd on
  454.     OUT    (31H),A        ; Send it to 8251 control port
  455.     LD    A,3        ; Select 8155 port C
  456.     OUT    (21H),A        ; 
  457.     IN    A,(28H)        ; Get miscellaneous information byte
  458.     LD    (OLDMSC),A    ; Save miscellaneous information byte
  459. ;
  460. ;
  461. ; Disable ring detect interrupt, Rxd interrupt, Txd
  462. ;
  463.     OR    0FH
  464.     LD    E,A        ; Interrupt, enable internal clock
  465.     LD    A,3
  466.     OUT    (21H),A        ; Select 8155 port C
  467.     LD    A,E
  468.     OUT    (28H),A        ; Send new control byte to 8155 port c
  469.     EI            ; RESTORE interrupts
  470.     RET            
  471.  
  472. ;De-initialise interrupt vectors:
  473. DINVEC:
  474.     LD    A,(OLDIOB)    ; Get original IOBYTE
  475.     LD    C,8
  476.     LD    E,A        ; Use BDOS to restore original IOBYTE
  477.     CALL    BDOS
  478. ;
  479.     DI            ; DISABLE interrupts
  480.     LD    A,15H        ; RTS, DTR off
  481.     LD    HL,(OLDVEC)    ; Get original interrupt service address
  482.     LD    (INTVEC),HL    ; Restore orig interrupt service address
  483.     LD    A,3        ; Select 8155 port C
  484.     OUT    (21H),A
  485.     IN    A,(28H)        ; Get miscellaneous information byte for
  486.                 ;   controlling interrupt lines
  487.     AND    030H        ; Zero the least significant four bits
  488.     LD    E,A
  489.     LD    A,(OLDMSC)    ; Get original misc. 8155 control byte
  490.     AND    0FH        ; Zero the most significant four bits
  491.     OR    E        ; Combine everything
  492.     LD    E,A        ; Store temporarily
  493. ;
  494.     LD    A,3
  495.     OUT    (21H),A        ; Select 8155 port C, again
  496.     LD    A,E        ; Store the value held in "E"
  497.     OUT    (28H),A        ; Restore original 8155 control byte
  498.     EI            ; RESTORE interrupts
  499. ;
  500.     LD    B,3CH
  501.     LD    A,(OLDBAUD)    ; Restore original baud rate byte
  502.     CALL    IORESET        ; Do an 8251 reset
  503. ;
  504.     LD    B,3BH
  505.     LD    A,(OLDMODE)    ; Restore original mode byte
  506.     CALL    IORESET        ; Do an 8251 reset
  507.     RET
  508. ;.....
  509. ;
  510. ;
  511. IORESET:
  512.     LD    HL,(BIOS)    ; Find base of BIOS
  513.     LD    L,B
  514.     LD    (HL),A
  515.     LD    L,36H        ; Displacement in BIOS for 8251 reset
  516.                 ;   function
  517.     LD    (EXTFUN),HL
  518.     CALL    BIFUNC        ; Subroutine call of BIOS 8251 reset
  519.                 ;   function
  520.     RET
  521. ;.....
  522. ;
  523. OLDIOB:    DEFB    0        ; Orig    IOBYTE
  524. OLDMSC:    DEFB    0        ; Orig misc. ctl byte for 8155 port C
  525. OLDVEC:    DEFB    0,0        ; Orig interrupt service vector
  526. OLDMODE:DEFB    1        ; Orig 8251 mode byte from BIOS
  527. OLDBAUD:DEFB    1        ; Orig baud rate byte for 8251 from BIOS
  528. BIFUNC:    DEFB    AJUMP        ; Absolute jump to following memory addr
  529. EXTFUN:    DEFB    0,0        ; Bios extended function address
  530.  
  531. ;****************** End of user-defined code ********************************
  532. ;        Do not change anything below here.
  533.  
  534. ;Modem character test for 100 ms
  535. MRD:
  536.     PUSH     BC        ; save bc
  537.     LD    BC,100        ; set limit
  538. MRD1:
  539.     CALL    MIRDY        ; char at modem?
  540.     JR    NZ,MRD2        ; yes, exit
  541.     LD    HL,1        ; else wait 1ms
  542.     CALL    WTHLMS
  543.     DEC    BC        ; loop till done
  544.     LD    A,B
  545.     OR    C
  546.     JR    NZ,MRD1
  547.     LD    HL,0        ; none there, result=0
  548.     XOR    A
  549. MRD2:
  550.     POP     BC
  551.     RET
  552.  
  553. ; Inline print routine: destroys A and HL
  554. PRINT:
  555.     EX    (SP),HL        ; get address of string
  556. PLOOP:
  557.     LD    A,(HL)        ; get next
  558.     INC    HL        ; bump pointer
  559.     OR    A        ; done if zero
  560.     JR    Z,PDONE
  561.     CALL    COUT        ; else print
  562.     JR    PLOOP        ; and loop
  563. PDONE:
  564.     EX    (SP),HL        ; restore return address
  565.     RET            ; and quit
  566.  
  567. ;Output a character in A to the console
  568. COUT:
  569.     PUSH     BC        ; save regs
  570.     PUSH     DE 
  571.     PUSH     HL
  572.     LD    E,A        ; character to E
  573.     LD    C,2
  574.     CALL    BDOS        ; print it
  575.     POP     HL
  576.     POP     DE
  577.     POP     BC
  578.     RET
  579.  
  580. ; Wait(seconds)
  581. WAIT:
  582.     LD    HL,2
  583.     ADD    HL,SP
  584.     EX    DE,HL        ; get delay size
  585.     CALL    GETPARM
  586.                 ; fall thru to..
  587. ; Wait seconds in HL
  588. WAITHLS:
  589.     PUSH     BC        ; save bc
  590.     PUSH     DE        ; de
  591.     PUSH     IX        ; and ix
  592.     LD     IX,0        ; then point ix to 0
  593.                 ; so we don't upset memory-mapped i/o
  594.  
  595. ; Wait milliseconds
  596. MSWAIT:
  597.     LD    HL,2
  598.     ADD    HL,SP
  599.     EX    DE,HL        ; get delay size
  600.     CALL    GETPARM
  601.                 ; fall thru to..
  602. ; Wait milliseconds in HL
  603. WTHLMS:
  604.     PUSH     DE
  605. W1MS0:
  606.     LD    DE,39*CLKSPD
  607. W1MS1:
  608.     DEC    DE
  609.     LD    A,D
  610.     OR    E
  611.     JR    NZ,W1MS1
  612.     DEC    HL
  613.     LD    A,H
  614.     OR    L
  615.     JR    NZ,W1MS0
  616.     POP     DE
  617.     RET
  618.  
  619. ; Get next parameter from (de) into hl
  620. GETPARM:
  621.     EX    DE,HL        ; get address into hl
  622.     LD    E,(HL)        ; get lo
  623.     INC    HL
  624.     LD    D,(HL)        ; then hi
  625.     INC    HL        ; bump for next
  626.     EX    DE,HL        ; result in hl, address still in de
  627.     RET
  628. ;
  629. ;Get address of user-defined variables
  630. ;
  631. GETVARS:
  632.     LD    HL,USERVARS
  633.     RET
  634. USERVARS:
  635.     DEFW    OVERDRIVE    ; .OVR etc. drive/user
  636.     DEFW    OVERUSER
  637.  
  638.     END
  639.  
  640.