home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / BIN / TIMER.ASM < prev    next >
Assembly Source File  |  1996-06-17  |  3KB  |  136 lines

  1. ; Example of installing new interrupt handler in protected mode
  2. ; This example will work with both the older NEAR and the new FLAT models
  3. ;
  4.     .386p
  5.  
  6.     include cw.inc
  7.  
  8. b    equ    byte ptr
  9. w    equ    word ptr
  10. d    equ    dword ptr
  11.  
  12. ;
  13. ;The segment name _NEAR isn't important here, it's the class 'near' that is.
  14. ;
  15. _NEAR    segment para public 'near' use32
  16.     assume cs:_NEAR, ds:_NEAR
  17.  
  18. ;-----------------------------------------------------------------------------
  19. ;
  20. ;On entry DS=ES=PSP as normal, SS=_NEAR
  21. ;
  22. start    proc    far
  23.     mov    ax,_NEAR        ;should yield a data selector
  24.     mov    ds,ax        ;with a limit of 4G. SS already
  25.     mov    es,ax        ;has this value so that could be
  26.     mov    fs,ax        ;used but this method shows that
  27.     mov    gs,ax        ;segments can still be used.
  28. ;
  29. ;CS=DS=ES=FS=GS=_NEAR  from this point on unless we're in interrupt code in which
  30. ;case we need to reload DS,ES,FS,GS. SS will be using a system stack for
  31. ;hardware interrupts or CallBack's but will otherwise already = _NEAR.
  32. ;
  33.  
  34. ;
  35. ;Want to play with IRQ 0 so we need to lock the new handler's memory.
  36. ;
  37.     mov    esi,offset Int08Handler
  38.     mov    ebx,offset Int08StuffEnd-Int08Handler
  39.     sys    LockMemNear
  40.     mov    edx,offset message1
  41.     jc    @@9
  42. ;
  43. ;Get old vector address.
  44. ;
  45.     mov    bl,8
  46.     sys    GetVect
  47.     mov    d[oldint08],edx
  48.     mov    w[oldint08+4],cx
  49. ;
  50. ;Set new handler address.
  51. ;
  52.     mov    edx,offset Int08Handler
  53.     mov    cx,cs
  54.     sys    SetVect
  55. ;
  56. ;shell to DOS so you can see hardware interrupts being resignaled from real
  57. ;mode to protected mode.
  58. ;
  59.     mov    edx,offset aname
  60.     mov    ebx,offset ptab
  61.     mov    ax,4b00h
  62.     int    21h
  63. ;
  64. ;Restore the old handler. Not strictly necesary but it's good practice.
  65. ;
  66.     mov    edx,d[oldint08]
  67.     mov    cx,w[oldint08+4]
  68.     mov    bl,8
  69.     sys    SetVect
  70. ;
  71. ;Print something to say we're back.
  72. ;
  73.     mov    edx,offset message2
  74. @@9:    mov    ah,9
  75.     int    21h
  76. ;
  77. ;Back to good old DOS.
  78. ;
  79.     mov    ax,4c00h
  80.     int    21h
  81. start    endp
  82.  
  83.  
  84. ;-----------------------------------------------------------------------------
  85. Int08Handler    proc    far
  86.     pushad
  87.     push    ds
  88.     mov    ax,_NEAR
  89.     mov    ds,ax
  90. ;
  91. ;Set new border color.
  92. ;
  93.     mov    ah,color
  94.     inc    color
  95.     and    color,63
  96.     mov    dx,3dah
  97.     in    al,dx
  98.     mov    dl,0c0h
  99.     mov    al,11h
  100.     out    dx,al
  101.     mov    al,ah
  102.     out    dx,al
  103.     mov    al,20h
  104.     out    dx,al
  105. ;
  106. ;chain to old handler.
  107. ;
  108.     pop    ds
  109.     popad
  110.     assume ds:nothing
  111.     jmp    oldint08
  112.     assume ds:_NEAR
  113. ;
  114. color    db ?
  115. oldint08    df ?
  116. Int08Handler    endp
  117. Int08stuffEnd    label byte
  118.  
  119.  
  120. ;-----------------------------------------------------------------------------
  121. message1    db 'Not enough physical memory to lock IRQ 0 handler.',13,10,'$'
  122. message2    db 'Back to the real world.',13,10,'$'
  123. ;
  124. aname    db 'c:\command.com',0    ; change 'c' to drive containing COMMAND.COM
  125. ptab    dw 0
  126.     dd ctab
  127.     dw _NEAR
  128.     dd 0
  129.     dw 0
  130.     dd 0
  131.     dw 0
  132. ctab    db 0,13
  133. ;
  134. _NEAR    ends
  135.     end    start
  136.