home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PASCAL / EXIO.ZIP / EXIO.ASM
Assembly Source File  |  1989-03-20  |  8KB  |  245 lines

  1.     INCLUDE    TITLE.MAC
  2.     .TITLE    <EXIO -- Extended I/O Functions>
  3.     .SBTTL    Declarations
  4.  
  5. ; exio.asm  15 Nov 83  Craig Milo Rogers at USC/ISI
  6. ;    Converted to PDP-11-style TITLEs.
  7. ; exio.asm  25 Oct 83  Craig Milo Rogers at USC/ISI
  8. ;    Converted to multi-model Lattice C.
  9. ; exio.asm  8 Sep 83  Craig Milo Rogers at USC/ISI
  10. ;    This module defines extended I/O subroutines.
  11. ;
  12.  
  13. IF1
  14.     INCLUDE    DOS.MAC            ; C segments.
  15.     INCLUDE    BMAC.MAC        ; C procedure calls.
  16. ENDIF
  17.  
  18.  
  19. DMA_CMD    EQU    8            ; I8237 DMA chip command register.
  20.  
  21.     PSEG                ; All the rest is program code.
  22.  
  23.     .SBHED    <OUTOUTP -- Output Two Values in a Row>
  24.  
  25. ; name        outoutp -- output two values in a row
  26. ;
  27. ; synopsis    (void) outoutp(port, reg, val);
  28. ;        int port;    I/O port
  29. ;        int reg;    internal register address
  30. ;        int val;    register value
  31. ;
  32. ; description    This function handles chips such as the Zilog 8530.
  33. ;        Two output instructions are executed for each access.
  34. ;        The first output addresses a register on the chip.
  35. ;        The second output gives the register a value.
  36.  
  37.     BENTRY    OUTOUTP <PORT,REGX,VAL>
  38.  
  39.     MOV    DX,PORT        ; Get port address.
  40.     MOV    AX,REGX        ; Get register number.
  41.     CLI            ; ******* Disable Interrupts *******
  42.     OUT    DX,AL        ;;; Address the register.
  43.     MOV    AX,VAL        ;;; Get register value.
  44.     OUT    DX,AL        ;;; Store the value.
  45.     STI            ;;; ******* Enable Interrupts *******
  46.                 ;;; (Next instruction, too)
  47.     BEND    OUTOUTP
  48.  
  49.     .SBHED    <OUTINP -- Output Then Input>
  50.  
  51. ; name        outinp -- output then input
  52. ;
  53. ; synopsis    val = outinp(port, reg);
  54. ;        int port;    I/O port
  55. ;        int reg;    internal register address
  56. ;        int val;    register value
  57. ;
  58. ; description    This function handles chips such as the Zilog 8530.
  59. ;        Two I/O instructions are executed for each access.
  60. ;        The first output addresses a register on the chip.
  61. ;        The second is an input to read the value.
  62.  
  63.     BENTRY    OUTINP <PORT,REGX>
  64.  
  65.     MOV    DX,PORT        ; Get port address.
  66.     MOV    AX,REGX        ; Get register number.
  67.     CLI            ; ******* Disable Interrupts *******
  68.     OUT    DX,AL        ;;; Address the register.
  69.     IN    AL,DX        ;;; Read the value.
  70.     STI            ;;; ******* Enable Interrupts *******
  71.     XOR    AH,AH        ;;; Clear high half.
  72.  
  73.     BEND    OUTINP
  74.  
  75.     .SBHED    <OUTP2X -- Output Two Values to Different Ports>
  76.  
  77. ; name        outp2x -- output two values to different ports
  78. ;
  79. ; synopsis    (void) outp2x(port1, val1, port2, val2);
  80. ;        int port1;    first I/O port
  81. ;        int val1;    register value
  82. ;        int port2;    second I/O port
  83. ;        int val2;    register value
  84. ;
  85. ; description    This routine is designed for situations where two
  86. ;        devices need to be started simultaneously.  One
  87. ;        example is in starting DMA on an SCC channel in
  88. ;        SDLC mode.
  89. ;
  90.     BENTRY    OUTP2X <PORT1,VAL1,PORT2,VAL2>
  91.  
  92.     MOV    DX,PORT1    ; Get port address.
  93.     MOV    AX,VAL1        ; Get register number.
  94.     CLI            ; ******* Disable Interrupts *******
  95.     OUT    DX,AL        ;;; Store first value.
  96.     MOV    DX,PORT2    ;;; Get port address.
  97.     MOV    AX,VAL2        ;;; Get register number.
  98.     OUT    DX,AL        ;;; Store second value.
  99.     STI            ;;; ******* Enable Interrupts *******
  100.                 ;;; (Next instruction, too)
  101.     BEND    OUTP2X
  102.  
  103.     .SBHED    <OUTPD -- Output with DMA Interlock>
  104.  
  105. ; name        outpd -- output with DMA interlock
  106. ;
  107. ; synopsis    outpd(port, val);
  108. ;        int port;    I/O port
  109. ;        int val;    value to output
  110. ;
  111. ; description    This function does output with DMA turned off.  This
  112. ;        caters to slow chips like the Zilog 8530, which cannot
  113. ;        tolerate sequential accesses by the CPU and DMA.  So,
  114. ;        it is necessary to temporarily shut off DMA when accessing
  115. ;        the device.
  116. ;
  117.     BENTRY    OUTPD <PORT,VAL>
  118.  
  119.     MOV    DX,PORT        ; Get port address.
  120.     MOV    CX,VAL        ; Get value to output.
  121.     MOV    AL,4        ; Bit to disable all DMA (incl. refresh).
  122.     CLI            ; ******* Disable Interrupts *******
  123.     OUT    DMA_CMD,AL    ;;; Mask off all DMA (incl. refresh).
  124.     MOV    AL,CL        ;;; Fetch the data to output.
  125.     OUT    DX,AL        ;;; Send it to the external device.
  126.     XOR    AL,AL        ;;; Command to reenable DMA.
  127.     OUT    DMA_CMD,AL    ;;; Restore the DMA channels.
  128.     STI            ;;; ******* Enable Interrupts *******
  129.                 ;;; (Next instruction, too)
  130.     BEND    OUTPD
  131.  
  132.     .SBHED    <INPD -- Input with DMA Interlock>
  133.  
  134. ; name        inpd -- input with DMA interlock
  135. ;
  136. ; synopsis    val = inpd(port);
  137. ;        int port;    I/O port
  138. ;        int val;    value which was input
  139. ;
  140. ; description    This function does input with DMA turned off.  This
  141. ;        caters to slow chips like the Zilog 8530, which cannot
  142. ;        tolerate sequential accesses by the CPU and DMA.  So,
  143. ;        it is necessary to temporarily shut off DMA when accessing
  144. ;        the device.
  145. ;
  146.     BENTRY    INPD <PORT>
  147.  
  148.     MOV    DX,PORT        ; Get port address.
  149.     MOV    AL,4        ; Bit to disable all DMA (incl. refresh).
  150.     CLI            ; ******* Disable Interrupts *******
  151.     OUT    DMA_CMD,AL    ;;; Mask off all DMA (incl. refresh).
  152.     IN    AL,DX        ;;; Read data from the external device.
  153.     MOV    CL,AL        ;;; Store data in a safer place.
  154.     XOR    AL,AL        ;;; Command to reenable DMA.
  155.     OUT    DMA_CMD,AL    ;;; Restore the DMA channels.
  156.     STI            ;;; ******* Enable Interrupts *******
  157.     MOV    AL,CL        ;;; Pickup saved input value.
  158.     XOR    AH,AH        ; Clear high half.
  159.  
  160.     BEND    INPD
  161.  
  162.     .SBHED    <OUTOUTPD -- Output Two Values with DMA Interlock>
  163.  
  164. ; name        outoutpd -- output two values with DMA interlock
  165. ;
  166. ; synopsis    outoutpd(port, reg, val);
  167. ;        int port;    I/O port
  168. ;        int reg;    internal register address
  169. ;        int val;    register value
  170. ;
  171. ; description    This function handles chips such as the Zilog 8530.
  172. ;        Two output instructions are executed for each access.
  173. ;        The first output addresses a register on the chip.
  174. ;        The second output gives the register a value.
  175. ;        DMA is masked during I/O to keep slow devices happy.
  176. ;
  177.     BENTRY    OUTOUTPD <PORT,REGX,VAL>
  178.     
  179.     MOV    DX,PORT        ; Get port address.
  180.     MOV    BX,REGX        ; Get register number.
  181.     MOV    CX,VAL        ; Get register value.
  182.     MOV    AL,4        ; Bit to disable all DMA (incl. refresh).
  183.     CLI            ; ******* Disable Interrupts *******
  184.     OUT    DMA_CMD,AL    ;;; Mask off all DMA (incl. refresh).
  185.     MOV    AL,BL        ;;; Get the register number.
  186.     OUT    DX,AL        ;;; Address the register.
  187.     XOR    AL,AL        ;;; Command to reenable DMA.
  188.     OUT    DMA_CMD,AL    ;;; Restore the DMA channels.
  189.     NOP            ;;; Give refresh and DMA a chance.
  190.     NOP            ;;; Give refresh and DMA a chance.
  191.     NOP            ;;; Give refresh and DMA a chance.
  192.     MOV    AL,4        ;;; Bit to disable all DMA (incl. refresh).
  193.     OUT    DMA_CMD,AL    ;;; Mask off all DMA (incl. refresh).
  194.     MOV    AL,CL        ;;; Get register value.
  195.     OUT    DX,AL        ;;; Store the value.
  196.     XOR    AL,AL        ;;; Command to reenable DMA.
  197.     OUT    DMA_CMD,AL    ;;; Restore the DMA channels.
  198.     STI            ;;; ******* Enable Interrupts *******
  199.                 ;;; (Next instruction, too)
  200.     BEND    OUTOUTPD
  201.  
  202.     .SBHED    <OUTINPD -- Output then Input with DMA Interlock>
  203.  
  204. ; name        outinpd -- output then input with DMA interlock
  205. ;
  206. ; synopsis    val = outinpd(port, reg);
  207. ;        int port;    I/O port
  208. ;        int reg;    internal register address
  209. ;        int val;    register value
  210. ;
  211. ; description    This function handles chips such as the Zilog 8530.
  212. ;        Two I/O instructions are executed for each access.
  213. ;        The first output addresses a register on the chip.
  214. ;        The second is an input to read the value.
  215. ;
  216. ;
  217.     BENTRY    OUTINPD <PORT,REGX>
  218.  
  219.     MOV    DX,PORT        ; Get port address.
  220.     MOV    BX,REGX        ; Get register number.
  221.     MOV    AL,4        ; Bit to disable all DMA (incl. refresh).
  222.     CLI            ; ******* Disable Interrupts *******
  223.     OUT    DMA_CMD,AL    ;;; Mask off all DMA (incl. refresh).
  224.     MOV    AL,BL        ;;; Get the register number.
  225.     OUT    DX,AL        ;;; Address the register.
  226.     XOR    AL,AL        ;;; Command to reenable DMA.
  227.     OUT    DMA_CMD,AL    ;;; Restore the DMA channels.
  228.     NOP            ;;; Give refresh and DMA a chance.
  229.     NOP            ;;; Give refresh and DMA a chance.
  230.     NOP            ;;; Give refresh and DMA a chance.
  231.     MOV    AL,4        ;;; Bit to disable all DMA (incl. refresh).
  232.     OUT    DMA_CMD,AL    ;;; Mask off all DMA (incl. refresh).
  233.     IN    AL,DX        ;;; Read the value.
  234.     MOV    CL,AL        ;;; Store data in a safer place.
  235.     XOR    AL,AL        ;;; Command to reenable DMA.
  236.     OUT    DMA_CMD,AL    ;;; Restore the DMA channels.
  237.     STI            ;;; ******* Enable Interrupts *******
  238.     MOV    AL,CL        ;;; Pickup saved input value.
  239.     XOR    AH,AH        ; Clear high half.
  240.  
  241.     BEND    OUTINPD
  242. ;
  243.     ENDPS            ; Close the code segment.
  244.     END
  245.