home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / sercom / intinit.asm < prev    next >
Encoding:
Assembly Source File  |  1986-09-04  |  3.0 KB  |  138 lines

  1. ; INTINIT.ASM
  2. ;
  3. ; Copyright (c) 1986 Peter W. Gofton
  4. ; Interrupt handler for IBM PC Serial i/o
  5. ; Designed to interface with Microsoft 'C'
  6. ; Compile as: MASM INTHAND;
  7. ;
  8.  
  9.  
  10. PORT_AD    equ 03F8H            ; 02F8H for COM2
  11. RX         equ 03F8H
  12. TX         equ 03F8H
  13. INT_EN     equ 03F9H
  14. INT_ID     equ 03FAH
  15. LCONT      equ 03FBH
  16. MCONT      equ 03FCH
  17. LSTAT      equ 03FDH
  18. MSTAT      equ 03FEH
  19.  
  20. COM_INT    equ 0CH              ; 0BH for COM2     
  21.  
  22. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  23. _TEXT    ENDS
  24. CONST    SEGMENT  WORD PUBLIC 'CONST'
  25. CONST    ENDS
  26. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  27. _BSS    ENDS
  28. _DATA    SEGMENT  WORD PUBLIC 'DATA'
  29. _DATA    ENDS
  30. DGROUP    GROUP    CONST,    _BSS,    _DATA
  31.     ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  32.  
  33. _TEXT SEGMENT
  34.  
  35. EXTRN _inthand: NEAR
  36.  
  37. PUBLIC _myds
  38. _myds DW "DS"
  39.  
  40. ;--------------------------------------------------------------------------
  41. PUBLIC _intinit
  42.  
  43. _intinit    PROC NEAR
  44.  
  45. ; This function is called from 'C' as intinit().
  46. ; It sets up the interrupt handler below to be called automatically when
  47. ; an i/o interrupt occurs.
  48. ;
  49. ; First we want to save our DS in an area in CS so we can find it later
  50.  
  51.     MOV    SI, OFFSET _myds
  52.     MOV    CS:[SI], DS
  53.  
  54.  
  55. ; Now we use the DOS Set Interrupt Vector call to point INT 0C to
  56. ; our interrupt handler.
  57.  
  58.     PUSH   DS           ; Save DS
  59.  
  60.     PUSH   CS           ; To load into CS
  61.     POP    DS           ; Load CS into DS
  62.  
  63.     LEA    DX, _inthand ; Address of the interrupt handler
  64.     MOV    AH, 025H     ; Function call to set vector
  65.     MOV    AL, COM_INT  ; Vector to set.
  66.     INT    21H          ; DOS interrupt
  67.  
  68.     POP    DS           ; Restore DS
  69.  
  70. ; Now we enable the interrupts on the Programmable Interrupt Controller
  71.  
  72.     CLI
  73.  
  74.     MOV    DX, PORT_AD
  75.     ADD    DX, 4        ; Modem Control Register
  76.     MOV    AL, 3        ; DTR, RTS
  77.     OUT    DX, AL       ; Enable handshaking
  78.     
  79.     MOV    DX, 21H      ; Address of the PIC
  80.     IN     AL, DX       ; Get contents
  81.     AND    AL, NOT 10H  ; Set off the bit for IRQ4. NOT 8 for IRQ3
  82.     OUT    DX, AL       ; Sent it out to the controller
  83.  
  84.     STI
  85.  
  86. ; Reset the serial interface by reading all the registers
  87.  
  88.     MOV    DX, INT_EN
  89.     MOV    AL, 0
  90.     OUT    DX, AL
  91.  
  92.     MOV    DX, LSTAT
  93.     IN     AL, DX
  94.  
  95.     MOV    DX, MSTAT
  96.     IN     AL, DX
  97.  
  98.     MOV    DX, RX
  99.     IN     AL, DX
  100.  
  101.     MOV    DX, INT_ID
  102.     IN     AL, DX
  103.         
  104. ; Now we enable the interrupts on the serial interface
  105.  
  106.     MOV    DX, INT_EN
  107.     MOV    AL, 0FH     ; Enable all four interrupts
  108.     OUT    DX, AL
  109.  
  110.     MOV    DX, PORT_AD
  111.     IN     AL, DX       
  112.  
  113.     ADD    DX, 5        ; Line status
  114.     IN     AL, DX
  115.     IN     AL, DX
  116.  
  117.     INC    DX           ; Modem status
  118.     IN     AL, DX
  119.     IN     AL, DX
  120.          
  121.  
  122.     MOV    DX, 20H    
  123.     MOV    AL, 20H
  124.     OUT    DX, AL       ; Reset the PIC            
  125.  
  126.     RET
  127.  
  128. _intinit endp
  129.  
  130. _TEXT ends
  131.  
  132. END
  133.  
  134.  
  135. ; Figure 17.1: Interrupt Handler Initialization 
  136.  
  137.  
  138.