home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 13.ddi / RTLSYS.ZIP / WLIB.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-10-28  |  2.2 KB  |  116 lines

  1.  
  2. ; *******************************************************
  3. ; *                            *
  4. ; *     Turbo Pascal Run-time Library                   *
  5. ; *    Windows Library Main Module            *
  6. ; *                            *
  7. ; *     Copyright (c) 1988,92 Borland International     *
  8. ; *                            *
  9. ; *******************************************************
  10.  
  11.     TITLE    WLIB
  12.  
  13.     INCLUDE    SE.ASM
  14.  
  15. DATA    SEGMENT WORD PUBLIC
  16.  
  17. ; Externals
  18.  
  19.     EXTRN    ExitCode:WORD,HInstance:WORD,CmdLine:DWORD
  20.     EXTRN    HeapAllocFlags:WORD,Input:BYTE,Output:BYTE
  21.     EXTRN    SelectorInc:WORD,Test8086:BYTE
  22.  
  23. DATA    ENDS
  24.  
  25. ; Windows entry points
  26.  
  27.     EXTRN    LocalInit:FAR,GetWinFlags:FAR,__AHIncr:ABS
  28.  
  29. CODE    SEGMENT    BYTE PUBLIC
  30.  
  31.     ASSUME    CS:CODE,DS:DATA
  32.  
  33. ; Externals
  34.  
  35.     EXTRN    DoExitProcs:NEAR
  36.  
  37. ; Publics
  38.  
  39.     PUBLIC    LibEntry,LibExit,LibExitProc
  40.  
  41. ; Library entry code. Every .DLL executable starts with a call
  42. ; to this routine.
  43.  
  44. LibEntry:
  45.  
  46.     ENTRY    WINFAR
  47.     MOV    HInstance,DI        ;Save library parameters
  48.     MOV    CmdLine.ofs,SI
  49.     MOV    CmdLine.seg,ES
  50.     JCXZ    @@1            ;Skip if no local heap
  51.     XOR    AX,AX            ;Initialize local heap
  52.     PUSH    DS
  53.     PUSH    AX
  54.     PUSH    CX
  55.     CALL    LocalInit
  56.     OR    AX,AX            ;Exit if it failed
  57.     JE    @@3
  58. @@1:    CALL    GetWinFlags        ;Determine CPU type
  59.     XOR    DX,DX
  60.     TEST    AL,0C0H            ;wf_CPU086 + wf_CPU186
  61.     JNE    @@2
  62.     INC    DX
  63.     TEST    AL,02H            ;wf_CPU286
  64.     JNE    @@2
  65.     INC    DX
  66. @@2:    MOV    Test8086,DL
  67.     MOV    HeapAllocFlags,2002H    ;gmem_Moveable + gmem_DDEShare
  68.     MOV    SelectorInc,__AHIncr
  69.     MOV    ExitCode,1        ;Default exit code is 1
  70.     EXIT
  71. @@3:    MOV    BP,SP            ;Remove stack frame
  72.     POP    BP
  73.     DEC    BP
  74.     POP    CX            ;Remove return address
  75.     POP    CX
  76.     RETF                ;Return to Windows
  77.  
  78. ; Library exit code. Every .DLL executable ends with a call to
  79. ; this routine.
  80.  
  81. LibExit:
  82.  
  83.     POP    AX            ;Remove return address
  84.     POP    AX
  85.     MOV    AX,ExitCode        ;Get exit code
  86.     MOV    DI,HInstance        ;Restore DI
  87.     RETF                ;Return to windows
  88.  
  89. ; Library exit procedure (automatically exported as 'WEP')
  90.  
  91. LibExitProc:
  92.  
  93.     MOV    AX,DS            ;Exported function
  94.     NOP
  95.     INC    BP
  96.     PUSH    BP
  97.     MOV    BP,SP
  98.     PUSH    DS
  99.     PUSH    SI
  100.     PUSH    DI
  101.     MOV    DS,AX
  102.     MOV    AX,[BP+6]        ;Get WEP parameter
  103.     MOV    ExitCode,AX        ;Store in ExitCode
  104.     CALL    DoExitProcs        ;Execute exit procedures
  105.     MOV    AX,1            ;Successful termination
  106.     POP    DI
  107.     POP    SI
  108.     POP    DS
  109.     POP    BP
  110.     DEC    BP
  111.     RETF    2
  112.  
  113. CODE    ENDS
  114.  
  115.     END
  116.