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

  1. ;
  2. ;A demo of using AliasSel to access CODE seg variables.
  3. ;
  4.  
  5.     .386            ;This order of .386 and .model
  6.     .model small        ;ensures use32 segments.
  7.     .stack 1024        ;should be enough for most.
  8.  
  9.     include cw.inc        ;define CauseWay API
  10.  
  11.     .code
  12.  
  13. ;-------------------------------------------------------------------------------
  14. Start    proc    near
  15.     mov    ax,DGROUP        ;Make our data addressable.
  16.     mov    ds,ax
  17. ;
  18. ;Get old INT 21h handler address.
  19. ;
  20.     mov    bl,21h
  21.     sys    GetVect
  22. ;
  23. ;We need an alias of _TEXT to be able to store the old handler address in a
  24. ;variable that will be accessible to the new interrupt handler so that it can
  25. ;chain to the old handler for functions it is not interested in.
  26. ;
  27.     mov    bx,cs        ;Selector to Alias.
  28.     sys    AliasSel        ;Allocate an Alias selector.
  29.     jc    alias_error
  30.     push    ds
  31.     mov    ds,ax
  32.     assume ds:_TEXT
  33.     mov    dword ptr [OldInt21h],edx    ;Store the old handler address
  34.     mov    word ptr [OldInt21h+4],cx    ;so we can chain to it.
  35.     assume ds:DGROUP
  36.     pop    ds
  37. ;
  38. ;We can release the Alias selector now we're done with it but it could be
  39. ;stored in a variable for future access to _TEXT.
  40. ;
  41.     mov    bx,ax
  42.     sys    RelSel
  43.     jc    alias_error
  44. ;
  45. ;Now install the new INT 21h handler.
  46. ;
  47.     mov    bl,21h
  48.     mov    cx,cs
  49.     mov    edx,offset INT21hHandler
  50.     sys    SetVect
  51. ;
  52. ;Make the new handler work for a living.
  53. ;
  54.     mov    ah,255
  55.     mov    edx,offset HelloWorld
  56.     int    21h
  57. ;
  58. ;Restore the old INT 21h handler.
  59. ;
  60.     mov    edx,cs:dword ptr [OldInt21h]
  61.     mov    cx,cs:word ptr [OldInt21h+4]
  62.     mov    bl,21h
  63.     sys    SetVect
  64. ;
  65. ;Time to exit.
  66. ;
  67.     jmp    exit
  68. ;
  69. ;There wasn't a free selector available for the AliasSel function (very
  70. ;unlikely) so print an error message.
  71. ;
  72. alias_error:    mov    edx,offset AliasErrorText
  73.     mov    ah,9
  74.     int    21h
  75. ;
  76. ;Back to the real world.
  77. ;
  78. exit:    mov    ax,4c00h
  79.     int    21h
  80. Start    endp
  81.  
  82. ;-------------------------------------------------------------------------------
  83. ;
  84. ;The replacement INT 21h handler. Doesn't do anything useful in itself but helps
  85. ;to demonstrate use of AliasSel.
  86. ;
  87. INT21hHandler    proc    far
  88.     cmp    ah,255        ;Our dummy function?
  89.     jnz    to_old_int21h
  90. ;
  91. ;This is only a test of chaining so change to the normal function number and
  92. ;do an INT 21h again. Next time through here the handler will chain to the old
  93. ;handler and then come back to out IRET.
  94. ;
  95.     mov    ah,9
  96.     int    21h
  97.     iretd
  98. ;
  99. ;Chain to the old INT 21h handler via OldInt21h
  100. ;
  101. to_old_int21h:    jmp    cs:fword ptr [OldInt21h]
  102. ;
  103. ;Storage for the old INT 21h handler address.
  104. ;
  105. OldInt21h    df 0
  106. INT21hHandler    endp
  107.  
  108.     .data
  109. ;-------------------------------------------------------------------------------
  110. HelloWorld    db "Hello world",13,10,"$"
  111. AliasErrorText    db "Not enough selectors to allocate Alias selector.",13,10,"$"
  112.  
  113.     end    Start
  114.