home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctchnqs / 1992 / number1 / msdosdll.asm < prev    next >
Assembly Source File  |  1992-02-19  |  4KB  |  116 lines

  1. TITLE   MSDOS.ASM -- MS-DOS interface DLL
  2.         .286P
  3.         .MODEL MEDIUM
  4.  
  5.         PUBLIC LibEntry     ; Required entry routine
  6.         PUBLIC WEP          ; Required exit routine
  7.         PUBLIC MsDos        ; Call MS-DOS
  8.         PUBLIC SegOf        ; Get segment/selector of a variable
  9.         PUBLIC OfsOf        ; Get offset of a variable
  10.  
  11.         EXTRN Dos3Call:FAR  ; This is the "hook" into the Windows
  12.                             ; kernel that lets a program call DOS
  13.  
  14.         .DATA
  15.  
  16. Filler  db      16 DUP(?)
  17.  
  18.         .CODE
  19.  
  20. LibEntry PROC FAR PASCAL; Fall through to code below
  21. LibEntry ENDP
  22.  
  23. WEP     PROC FAR
  24.         nop          ; Prevent overwriting of the MOV AX,xxxx in
  25.                      ; Real Mode (VB doesn't run in Real Mode, but
  26.                      ;   this may be useful for other languages.)
  27.         mov ax,1     ; Leaf routine, so no prologue or epilogue
  28.         ret
  29. WEP     ENDP
  30.  
  31. MsDos   PROC FAR
  32.         cld             ; Just to be sure
  33.         inc bp          ; Inc & push bp for the benefit of Windows
  34.         push bp
  35.         push ds         ; Save registers that must be preserved
  36.         push si         ; (Windows DLLs preserve si, di, ds, and bp
  37.         push di         ;   by convention)
  38.         mov bp,sp
  39.         lds si,[bp+12]  ; Parameter address is above original 
  40.                         ; ds+si+di, incremented bp, and return
  41.                         ; address (12 bytes)
  42.         lodsw           ; Get new ax
  43.         push ax         ; Push it while we're using lodsw
  44.         lodsw
  45.         mov bx,ax       ; Get new bx
  46.         lodsw
  47.         mov cx,ax       ; cx
  48.         lodsw
  49.         mov dx,ax       ; dx
  50.         lodsw
  51.         mov bp,ax       ; bp
  52.         lodsw
  53.         push ax         ; Push new si while using lodsw
  54.         lodsw
  55.         mov di,ax       ; Get new di
  56.         lodsw
  57.         push ax         ; Push new ds while using lodsw
  58.         lodsw
  59.         mov es,ax       ; Get new es
  60.         pop ds          ; Retrieve new ds,si,ax
  61.         pop si
  62.         pop ax
  63.         call Dos3Call   ; Call DOS via special Windows API
  64.         pushf           ; Save flags right away
  65.         cld             ; Just to be sure
  66.         push es         ; Save es,di during stosw instructions
  67.         push di
  68.         push bp         ; And bp while finding parameter again
  69.         mov bp,sp       ; Load bp from sp, then account for pushed
  70.         les di,[bp+20]  ; bp, di, es, flags *and* the 12 bytes
  71.                         ; that were there before (18 bytes total)
  72.         stosw           ; Store ax
  73.         mov ax,bx
  74.         stosw           ; bx
  75.         mov ax,cx
  76.         stosw           ; cx
  77.         mov ax,dx
  78.         stosw           ; dx
  79.         pop ax
  80.         stosw           ; bp (from stack)
  81.         mov ax,si
  82.         stosw           ; si
  83.         pop ax
  84.         stosw           ; di (from stack)
  85.         mov ax,ds
  86.         stosw           ; ds
  87.         pop ax
  88.         stosw           ; es (from stack)
  89.         pop ax
  90.         stosw           ; Flags (from stack)
  91.         pop di          ; Restore original registers as required
  92.         pop si
  93.         pop ds
  94.         pop bp
  95.         dec bp          ; Fix up bp
  96.         ret 4           ; Return, popping the address
  97. MsDos   ENDP
  98.  
  99. SegOf   PROC FAR
  100.         push bp         ; Leaf routine, so just push & restore bp
  101.         mov bp,sp       ;  (no increment/decrement necessary)
  102.         mov ax,[bp+8]   ; Segment of parameter is above return
  103.         pop bp          ; address and the parameter's offset (6
  104.                         ;  bytes up on stack)
  105.         ret 4
  106. SegOf   ENDP
  107.  
  108. OfsOf   PROC FAR
  109.         push bp         ; Leaf routine, so just push & restore bp
  110.         mov bp,sp       ;  (no increment/decrement necessary)
  111.         mov ax,[bp+6]   ; Offset of parameter is above return
  112.         pop bp          ; address (4 bytes up on stack)
  113.         ret 4
  114. OfsOf   ENDP
  115.         END LibEntry
  116.