home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / INTS.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-10-26  |  2.9 KB  |  160 lines

  1. ;
  2. ; GRDB
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;
  8. ;
  9. ; INTS.ASM
  10. ;
  11. ; Function: Interrupt table management
  12. ;
  13.     .model small
  14.     .386
  15.     
  16. include eoptions.inc
  17. include eprints.inc
  18.  
  19.     public SetRMInts,IntSnapShot, UnLoadInts, ReleaseRMInts
  20.     public SetVectAttrib, IntPage, int21adr, orgpic, int20adr
  21.  
  22.     .data
  23. intpage    dw    0    ; segment of interrupt save page
  24. orgpic dw    0    ; original pic masks (high byte = 21h)
  25.  
  26.     .code
  27. int20adr    dd    0    ;NOT fully implemented
  28. int21adr    dd    0    ; their version of int 21h
  29. ;
  30. ; keep the VECTLIST upper bit in sync with the options code
  31. ;
  32. SetVectAttrib    PROC
  33.     mov    ah,al
  34.     lodsb
  35.     add    si,2
  36.     xchg    al,ah
  37.     cmp    ah,0ffh
  38.     jz    tv_End
  39.     and    ah,7fh
  40.     cmp    al,ah
  41.     jnz    SetVectAttrib
  42.     shl    bl,7
  43.     and    byte ptr [si-3],7fh
  44.     xor    bl,80h
  45.     or    byte ptr [si-3],bl
  46. tv_end:
  47.     ret
  48. SetVectAttrib    ENDP
  49. ;
  50. ; read vectlist and insert all our interrupts
  51. ;
  52. ; they are ONLY there during GO, tracing will bypass them
  53. ; and they won't be visible during idles
  54. ;
  55. SetRMInts    PROC
  56.     sub    ax,ax
  57.     mov    fs,ax
  58.     cli
  59. mi_lp:
  60.     lodsb                     ; vect num & addr
  61.     movzx    bx,al
  62.     lodsw
  63.     or    bl,bl
  64.     js    testdone        ; high bit means, don't modify
  65.     shl    bx,2              ; else overwrite
  66.     mov    fs:[bx],ax
  67.     mov    fs:[bx+2],cs
  68.     jmp    mi_lp
  69. testdone:
  70.     cmp    bl,0ffh
  71.     jnz    mi_lp
  72.     sti
  73.     ret
  74. SetRMInts    ENDP
  75. ;
  76. ; read vectlist and restore the old interrupts from the int page
  77. ;
  78. ReleaseRMInts    PROC
  79.     sub    ax,ax
  80.     mov    fs,ax
  81.     mov    gs,[intpage]
  82.     cli
  83. rmi_lp:
  84.     lodsb                  ; vect num & addr
  85.     movzx    bx,al
  86.     lodsw
  87.     or    bl,bl
  88.     js    rtestdone        ; high bit means, don't write
  89.     shl    bx,2                    ; else overrwrite
  90.     mov    ax,gs:[bx]
  91.     mov    fs:[bx],ax
  92.     mov    ax,gs:[bx+2]
  93.     mov    fs:[bx+2],ax
  94.     jmp    rmi_lp
  95. rtestdone:
  96.     cmp    bl,0ffh
  97.     jnz    rmi_lp
  98.     mov    eax,cs:[int20adr]    ; now restore int20h in case they
  99.     mov    fs:[20h*4],eax       ; changed it
  100.     mov    eax,cs:[int21adr]    ; now restore int21h in case they
  101.     mov    fs:[21h*4],eax       ; changed it
  102.     sti
  103.     ret
  104. ReleaseRMInts    ENDP
  105. ;
  106. ; take a snapshot of all interrupts at program start
  107. ;
  108. ; we will unload EVERYTHING when we exit or when the program ends
  109. ;
  110. IntSnapShot PROC
  111.     mov    bx,40h
  112.     mov    ah,48h
  113.     int    21h
  114.     jc    isn_err
  115.     mov    [intpage],ax
  116.     in    al,21h            ; get pic masks
  117.     xchg    al,ah
  118.     in    al,0a1h
  119.     mov    [orgpic],ax
  120.     sub    di,di
  121.     mov    bx,[intpage]
  122.     sub    si,si
  123.     push    ds
  124.     push    es
  125.     mov    es,bx
  126.     mov    ds,si
  127.     mov    cx,100h
  128.     rep    movsd
  129.     mov    eax,ds:[21h*4]        ; now back up int 21h
  130.     mov    cs:[int21adr],eax    ; to the changeable address
  131.     mov    eax,ds:[20h*4]        ; now back up int 21h
  132.     mov    cs:[int20adr],eax    ; to the changeable address
  133.     pop    es
  134.     pop    ds
  135.     clc
  136. isn_err:
  137.     ret
  138. IntSnapShot ENDP
  139. ;
  140. ; unload everything.  There is a generic resource release routine
  141. ; that will later release the memory
  142. UnLoadInts    PROC
  143.     push    ds
  144.     push    es
  145.     sub    di,di
  146.     sub    si,si
  147.     mov    es,di
  148.     mov    ds,[intpage]
  149.     mov    cx,100h
  150.     rep    movsd
  151.     pop    es
  152.     pop    ds
  153.     mov    ax,[orgpic]    ; restore pic mask
  154.     out    0a1h,al
  155.     xchg    al,ah
  156.     out    21h,al
  157.     ret
  158. UnLoadInts    ENDP
  159.     end