home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctcoll95.zip / BASTELST / PAPI020.ZIP / APIA.ASM < prev    next >
Assembly Source File  |  1993-10-06  |  3KB  |  151 lines

  1.     .MODEL    COMPACT
  2.     LOCALS
  3.     %MACS
  4.     .LALL
  5.  
  6.     .DATA
  7.     public    Intstk,Stktop,Spsave,Sssave
  8.     public    Timstk,Tstktop,Tspsave,Tssave
  9.  
  10. Spsave    dw    ?        ; Save location for SP during interrupts
  11. Sssave    dw    ?        ; Save location for SS during interrupts
  12. Intstk    dw    1024 dup(?)    ; Interrupt working stack
  13. Stktop    equ    $        ; SP set here when entering interrupt
  14.  
  15. Tspsave    dw    ?        ; Save location for SP during interrupts
  16. Tssave    dw    ?        ; Save location for SS during interrupts
  17. Timstk    dw    1024 dup(?)    ; Interrupt working stack
  18. Tstktop    equ    $        ; SP set here when entering interrupt
  19.  
  20.     .CODE
  21.     extrn    _apiint:near
  22.     extrn    _TimerTick:near
  23. dbase    dw    @Data
  24. apisema    db    0
  25. timsema    db    0
  26. apiprbl    dw    0
  27. timprbl    dw    0
  28.  
  29. ; dirps - disable interrupts and return previous state: 0 = disabled,
  30. ;    1 = enabled
  31.     public _dirps
  32. _dirps    proc
  33.     pushf            ; save flags on stack
  34.     pop    ax        ; flags -> ax
  35.     and    ax,200h        ; 1<<9 is IF bit
  36.     jz    @@1        ; ints are already off; return 0
  37.     mov    ax,1
  38.     cli            ; interrupts now off
  39. @@1:    ret
  40. _dirps    endp
  41.  
  42. ; restore - restore interrupt state: 0 = off, nonzero = on
  43.     public    _restore
  44. _restore proc
  45.     arg is:word
  46.     test    is,0ffffh
  47.     jz    @@1
  48.     sti
  49.     ret
  50. @@1:    cli    ; should already be off, but just in case...
  51.     ret
  52. _restore endp
  53.  
  54. ; apivec - ISDN CAPI interrupt handler #0
  55.     public    _apivec
  56.  
  57.     label    _apivec    far
  58.     push    ax        ; check for interpt in interpt
  59.     mov    al,1
  60.     xchg    al,cs:apisema
  61.     and    al,al
  62.     jz    @@1
  63.     inc    cs:apiprbl
  64.     pop    ax
  65.     iret
  66.  
  67. @@1:    push    ds        ; save on user stack
  68.     mov    ds,cs:dbase
  69.  
  70.     mov    Sssave,ss    ; stash user stack context
  71.     mov    Spsave,sp
  72.  
  73.     mov    ss,cs:dbase
  74.     lea    sp,Stktop
  75.                 ; save user regs on interrupt stack
  76.     push    bx
  77.     push    cx
  78.     push    dx
  79.     push    bp
  80.     push    si
  81.     push    di
  82.     push    es
  83.     mov    ax,cs:apiprbl
  84.     push    ax
  85.     call    _apiint
  86.     pop    ax
  87.     pop    es
  88.     pop    di
  89.     pop    si
  90.     pop    bp
  91.     pop    dx
  92.     pop    cx
  93.     pop    bx
  94.     mov    ss,Sssave
  95.     mov    sp,Spsave    ; restore original stack context
  96.     pop    ds
  97.     sub    al,al
  98.     xchg    al,cs:apisema
  99.     pop    ax
  100.     iret
  101.  
  102. ; timevec Timer interrupt handler
  103.     public    _timevec
  104.  
  105.     label    _timevec far
  106.     push    ax        ; check for interpt in interpt
  107.     mov    al,1
  108.     xchg    al,cs:timsema
  109.     and    al,al
  110.     jz    @@2
  111.     inc    timprbl
  112.     pop    ax
  113.     iret
  114.  
  115. @@2:    push    ds        ; save on user stack
  116.     mov    ds,cs:dbase
  117.  
  118.     mov    Tssave,ss    ; stash user stack context
  119.     mov    Tspsave,sp
  120.  
  121.     mov    ss,cs:dbase
  122.     lea    sp,Tstktop
  123.                 ; save user regs on interrupt stack
  124.     push    bx
  125.     push    cx
  126.     push    dx
  127.     push    bp
  128.     push    si
  129.     push    di
  130.     push    es
  131.     mov    ax,cs:timprbl
  132.     push    ax
  133.     call    _TimerTick
  134.     pop    ax
  135.     pop    es
  136.     pop    di
  137.     pop    si
  138.     pop    bp
  139.     pop    dx
  140.     pop    cx
  141.     pop    bx
  142.     mov    ss,Tssave
  143.     mov    sp,Tspsave    ; restore original stack context
  144.     pop    ds
  145.     sub    al,al
  146.     xchg    al,cs:timsema
  147.     pop    ax
  148.     iret
  149.  
  150.     end
  151.