home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / SCCVEC.ASM < prev    next >
Assembly Source File  |  1990-03-21  |  6KB  |  246 lines

  1. ; Modified from the PE1CHL version to work with NOS.
  2. ; This file cannot be used with the PE1CHL sources.
  3. ; 1/21/90
  4. ; Ken Mitchum, KY3B   km@speedy.cs.pitt.edu km@cadre.dsl.pitt.edu
  5. ; SCC interrupt handler for IBM-PC
  6.  
  7.     .MODEL    MEMMOD,C
  8.     LOCALS
  9.     %MACS
  10.     .LALL
  11.  
  12.     extrn    Stktop,Spsave,Sssave,doret:proc,scctim:proc,eoi:proc
  13.     extrn    porg:proc
  14.     extrn    Sccvecloc,Sccpolltab,Sccmaxvec:byte
  15.  
  16. ifdef    LARGEDATA
  17.     extrn    Sccchan:dword
  18. else
  19.     extrn    Sccchan:word
  20. endif
  21.     
  22.     .CODE
  23. dbase    dw    @Data        ; save loc for ds (must be in code segment)
  24.  
  25. ; sccvec is the interrupt handler for SCC interrupts using INTACK
  26.  
  27.     public sccvec
  28.     label    sccvec    far
  29.  
  30.     cli            ; this code is not re-entrant, so make sure it
  31.                 ; is not interrupted. some multi-taskers
  32.                 ; intercept interrupt handlers, so be careful!
  33.  
  34.  
  35.     push    ds        ; save on user stack
  36.  
  37.     mov    ds,cs:dbase
  38.  
  39.     mov    Sssave,ss    ; stash user stack context
  40.     mov    Spsave,sp
  41.  
  42.     mov    ss,cs:dbase        ; set up interrupt stack
  43.     lea    sp,Stktop
  44.  
  45.     push    ax        ; save user regs on interrupt stack
  46.     push    bx        
  47.     push    cx
  48.     push    dx
  49.     push    bp
  50.     push    si
  51.     push    di
  52.     push    es
  53.     call    eoi
  54. ifndef    LARGEDATA
  55.     mov    es,ax        ; small data assumes ES == DS
  56. endif
  57.     cld            ; in case "movsb" or "movsw" is used
  58.  
  59.  
  60. ; Read SCC interrupt vector and check it
  61.  
  62. sccint: mov    dx,Sccvecloc
  63.     out    dx,al            ; Generate INTACK
  64.     jmp    short d1        ; Delay
  65. d1:    jmp    short d2
  66. d2:    jmp    short d3
  67. d3:    in    al,dx            ; Read the vector
  68.     cmp    al,Sccmaxvec        ; Check for a legal vector
  69.     jnc    clrret            ; It should not be >= the maximum
  70.                     ; If it is, ignore the interrupt
  71.  
  72. ; Extract channel number and status from vector. Determine handler address.
  73.  
  74.     mov    bl,al            ; Copy vector (need it later for status)
  75.     shr    bl,1            ; Discard least significant bit
  76.     jc    clrret            ; It should not be a 1
  77.     and    bx,7ch            ; Isolate channel number (and make word)
  78.     xor    bl,04h            ; Toggle A/B channel bit
  79. ifdef    LARGEDATA
  80.     les    si,Sccchan[bx]    ; Read address of channel structure
  81. else
  82.     shr    bl,1            ; Discard another bit
  83.     mov    si,Sccchan[bx]        ; Read address of channel structure
  84. endif
  85. ifdef    LARGEDATA        ; Test for NULL
  86.     push    ax
  87.     mov        ax,es
  88.     test    ax,ax
  89.     pop        ax
  90.     jne    nn0
  91. endif
  92.     test    si,si            ; Test for NULL
  93.     je    clrret            ; No channel struct, ignore it
  94. nn0:
  95.     and    ax,06h            ; Isolate status info from vector
  96.     add    ax,ax            ; Make index in FAR PTR array
  97.     mov    bx,ax            ; It must be in BX
  98.  
  99. ; Call the handler (defined in C), with Sccchan struct as a parameter
  100.  
  101.     push    es
  102.     push    si            ; Put channel struct as a parameter
  103. ifdef    LARGEDATA
  104.     call    dword ptr es:[bx+si]    ; Call the handler
  105. else
  106.     call    dword ptr [bx+si]    ; Call the handler
  107. endif
  108.     pop    si            ; Get channel struct back
  109.     pop    es
  110.  
  111. ; Reset highest priority interrupt
  112.  
  113. ifdef    LARGEDATA
  114.     mov    dx,es:16[si]        ; Get control register address
  115. else
  116.     mov    dx,16[si]        ; Get control register address
  117. endif
  118.     mov    al,38h            ; "Reset Highest IUS" opcode
  119.     out    dx,al            ; to WR0
  120.     jmp    short d4    ; settling delay
  121. d4:    jmp    short d5
  122. d5:
  123.  
  124. ; Determine if more interrupt requests are coming in from the SCCs
  125.  
  126.     jmp    sccint            ; keep trying until no vector returned
  127.  
  128. ; Clear the ISR bit in the PIC and return from interrupt
  129.  
  130. clrret:    
  131.         jmp    doret            ; execute code in pcint.asm
  132.  
  133. ;    sccvec    endproc
  134.  
  135. ; sccnovec is the interrupt handler for SCC interrupts using polling
  136.  
  137.     public sccnovec
  138.     label sccnovec far
  139.     
  140.     cli            ; this code is not re-entrant, so make sure it
  141.                 ; is not interrupted. some multi-taskers
  142.                 ; intercept interrupt handlers, so be careful!
  143.  
  144.  
  145.     push    ds        ; save on user stack
  146.     mov    ds,cs:dbase
  147.  
  148.     mov    Sssave,ss    ; stash user stack context
  149.     mov    Spsave,sp
  150.  
  151.     mov    ss,cs:dbase        ; set up interrupt stack
  152.     lea    sp,Stktop
  153.  
  154.     push    ax        ; save user regs on interrupt stack
  155.     push    bx        
  156.     push    cx
  157.     push    dx
  158.     push    bp
  159.     push    si
  160.     push    di
  161.     push    es
  162.     call    eoi
  163. ifndef    LARGEDATA
  164.     mov    es,ax        ; small data assumes ES == DS
  165. endif
  166.  
  167.     cld            ; in case "movsb" or "movsw" is used
  168.  
  169.  
  170. ; Find the SCC generating the interrupt by polling all attached SCCs
  171. ; reading RR3A (the interrupt pending register)
  172.  
  173. sccintnv:
  174.     lea    si,Sccpolltab        ; Point to polling table
  175. sccpoll:
  176.     mov    dx,[si]            ; Get chan A CTRL address
  177.     inc    si
  178.     inc    si
  179.     test    dx,dx            ; End of table without finding it
  180.     je    clrret            ; Then return from interrupt
  181.     mov    al,3            ; Select RR3A
  182.     out    dx,al
  183.     jmp    short d6    ; Delay
  184. d6:    jmp    short d7
  185. d7:    jmp    short d8
  186. d8:    in    al,dx
  187.     test    al,al            ; Test if a nonzero IP here
  188.     jnz    sccip            ; Yes, handle it
  189.     inc    si            ; No, next A CTRL
  190.     inc    si
  191.     jmp    sccpoll
  192.  
  193. ; Read SCC interrupt vector from RR2B, it should always be correct
  194. ; Extract channel number and status from vector. Determine handler address.
  195.  
  196. sccip:    mov    dx,[si]            ; Read B CTRL address
  197.     mov    al,2            ; Select RR2B
  198.     out    dx,al
  199.     jmp    short d9    ; Delay
  200. d9:    jmp    short d10
  201. d10:    jmp    short d11
  202. d11:    in    al,dx        ; Read the vector
  203.     mov    bl,al            ; Copy vector (need it later for status)
  204.     shr    bl,1            ; Discard least significant bit
  205.     and    bx,7ch            ; Isolate channel number (and make word)
  206.     xor    bl,04h            ; Toggle A/B channel bit
  207. ifdef    LARGEDATA
  208.     les si,Sccchan[bx]
  209. else
  210.     shr    bl,1            ; Discard another bit (Sccchan=words)
  211.     mov    si,Sccchan[bx]        ; Read address of channel structure
  212. endif
  213. ifdef    LARGEDATA        ; Test for NULL
  214.     push    ax
  215.     mov        ax,es
  216.     test    ax,ax
  217.     pop        ax
  218.     jne nn1
  219. endif
  220.     test    si,si            ; Test for NULL
  221.     je    clrret            ; No channel struct, ignore it
  222. nn1:
  223.     and    ax,06h            ; Isolate status info from vector
  224.     add    ax,ax            ; Make index in FAR PTR array
  225.     mov    bx,ax            ; It must be in BX
  226.  
  227. ; Call the handler (defined in C), with Sccchan struct as a parameter
  228.  
  229.     push    es
  230.     push    si            ; Put channel struct as a parameter
  231. ifdef    LARGEDATA
  232.     call    dword ptr es:[bx+si]    ; Call the handler
  233. else
  234.     call    dword ptr [bx+si]    ; Call the handler
  235. endif
  236.     pop    si            ; Remove parameter from stack
  237.     pop    es
  238.  
  239. ; Check for more interrupt pending bits
  240.  
  241.     jmp    sccintnv
  242.  
  243. ;    sccnovec    endproc
  244.  
  245.     end
  246.