home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / SCSIDRV.ZIP / KLUDGE.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-11-06  |  2.4 KB  |  91 lines

  1. ;
  2. ; This code is needed because DOS insists on opening a char device
  3. ; in cooked mode.  The problem is that without adding code to every
  4. ; application that would ever use us, we have no way to alter this
  5. ; because the use of O_BINARY or setmode() do not affect char devices.
  6. ;
  7. ; The solution (kludge) is to watch open requests issued thru the
  8. ; INT 21 vector.  If we see a open request followed by a OPEN_DEV
  9. ; call to us, it must have been an open for us.  So during the return,
  10. ; force a call to the ioctl facility that will switch to raw mode.
  11. ;
  12.  
  13. ;
  14. ; The Original INT 21 Vector
  15. ;
  16. vect_int_21    equ    word ptr 4 * 21h
  17. orig_int_21    dd    ?            ;Original INT 21 Vector
  18.  
  19. ;
  20. ; OPEN_DEV flag is TRUE when we are opened
  21. ;
  22. opened_flag    db    FALSE
  23.  
  24. patch_us_in    proc    near
  25.         push    es
  26.         push    ax
  27.         mov    ax,0            ;Patch Ourselves into
  28.         mov    es,ax            ;the INT 21 Vector
  29.         mov    ax,es:[vect_int_21]    ;Offset
  30.         mov    word ptr orig_int_21,ax
  31.         lea    ax,our_int_21
  32.         mov    es:[vect_int_21],ax
  33.         mov    ax,es:[vect_int_21+2]    ;Segment
  34.         mov    word ptr orig_int_21+2,ax
  35.         mov    ax,cs
  36.         mov    es:[vect_int_21+2],ax
  37.         pop    ax
  38.         pop    es
  39.         ret
  40. patch_us_in    endp
  41.  
  42. our_int_21    proc    far
  43.         pushf                ;Save entry flags
  44.         cmp    ah,3Dh            ;Is it an open request?
  45.         jnz    not_open_req
  46.         popf                ;Restore entry flags
  47. ;
  48. ; We need to set things up so the 'iret' done by the INT 21
  49. ; code will have some the right stuff on the stack.
  50. ; #1 Flags with interrupts enabled
  51. ; #2 Return Address
  52. ;
  53.         sti                ;Allow interrupts
  54.         pushf                ;After the iret
  55.         cli                ;Shut interrupts off
  56.         call    cs:orig_int_21        ;While we Pass the request on
  57. ;
  58. ; Upon return, interrupts are enabled, so shut them off while we work
  59. ;
  60.         pushf
  61.         cli
  62.         cmp    cs:opened_flag,FALSE    ;Was it an open for us?
  63.         jz    not_our_open
  64.         mov    cs:opened_flag,FALSE    ;Clear for next time
  65. ;
  66. ; We need to forge a call to the ioctl interface
  67. ; to switch DOS to raw mode when it talks to us
  68. ;
  69.         pusha
  70.         mov    bx,ax            ;Save the Handle
  71.         mov    ax,4400h        ;Get Device Information
  72.         pushf
  73.         call    cs:orig_int_21
  74.         mov    dh,0            ;Setup
  75.         or    dl,20h            ;for RAW Mode
  76.         mov    ax,4401h        ;Set Device Information
  77.         pushf
  78.         call    cs:orig_int_21
  79.         popa
  80.  
  81. not_our_open:    popf                ;The Original Flags to return
  82. ;
  83. ; When we return, we need to pop the flags that the original INT 21
  84. ; call left on the stack, and return the flags we got back
  85. ;
  86.         ret    2            ;Return and discard flags
  87.  
  88. not_open_req:    popf                ;Pop the saved flags
  89.         jmp    cs:orig_int_21        ;Continue with original code
  90. our_int_21    endp
  91.