home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK7 / SOURCE / STARTUP / WIN / QWCINIT.AS$ / QWCINIT
Encoding:
Text File  |  1991-11-06  |  5.1 KB  |  293 lines

  1.     page    ,132
  2.     title    qwcinit - QuickWin (QWIN) Init/Term
  3. ;***
  4. ;qwcinit.asm - QuickWin (QWIN) Init/Term
  5. ;
  6. ;    Copyright (c) 1990-1992, Microsoft Corporation.  All rights reserved.
  7. ;
  8. ;Purpose:
  9. ;    This source inits/terms the QWIN system.
  10. ;
  11. ;*******************************************************************************
  12.  
  13. ?DF = 1         ; tell cmacros.inc we want to define our own segments
  14.  
  15. include version.inc
  16. .xlist
  17. include cmacros.inc
  18. include cmsgs.inc
  19. include defsegs.inc
  20. include fcntl.inc
  21. include rterr.inc
  22. include stdlib.inc
  23. .list
  24.  
  25. ;
  26. ; Segments
  27. ;
  28.  
  29. CrtDefSegs  <code,data>
  30. CrtDefSegs  <xcseg>
  31.  
  32. codeOFFSET equ    offset _TEXT:
  33. dataOFFSET equ    offset DGROUP:
  34.  
  35. ;
  36. ; Terminator
  37. ;
  38.  
  39. sBegin    xcseg
  40.  
  41. if    sizeC
  42.     dd    _wcterm
  43. else
  44.     dw    _wcterm
  45. endif
  46.  
  47. sEnd
  48.  
  49. ;
  50. ; Externals
  51. ;
  52.  
  53. externFP    _QWINExit    ; Exit QWIN system
  54. externFP    _QWINInit    ; Init QWIN system
  55. externFP    _QWINOpen    ; Open QWIN windows
  56. externFP    _QWINSetExit    ; Set QWIN exit behavior
  57. externFP    _QWINTerm    ; Term QWIN system
  58.  
  59. externP     _splitpath    ; _splitpath() function
  60. externNP    _amsg_exit    ; fatal termination
  61.  
  62. ;
  63. ; Data
  64. ;
  65.  
  66. sBegin    data
  67. assumes ds,data
  68.  
  69. externW     _nfile        ; number of OS files
  70. externW     _wfile        ; number of QWIN files
  71. externDP    __argv        ; argument array
  72.  
  73. externW     _hInstance    ; instance handle
  74. externW     _cmdShow    ; win display parameter
  75.  
  76. globalW     _qwinused,1    ; non-zero means QWIN layer in use
  77.  
  78. ; default window title
  79.  
  80. stdname db    _WIN_CTITLE_TXT ; std file title
  81.  
  82. ; open window structures
  83.  
  84.     _wopen    _wopeninfo    <_WINVER, stdname, _WINBUFDEF>
  85.  
  86. sEnd
  87.  
  88.  
  89. sBegin    code
  90. assumes cs,code
  91.  
  92. page
  93. ;***
  94. ; _wcinit - QWIN C Initialization
  95. ;
  96. ;Purpose:
  97. ;    Init the QWIN system.
  98. ;
  99. ;Entry: <void>
  100. ;
  101. ;Exit:    <void>
  102. ;
  103. ;Uses:
  104. ;
  105. ;Exceptions:
  106. ;
  107. ;*******************************************************************************
  108.  
  109. cProc    _wcinit,<PUBLIC,NEAR>,<>
  110.  
  111. cBegin <nolocals>
  112.  
  113. ;
  114. ; Init the QWIN layer and child class
  115. ;
  116.  
  117.     ; use the root name of the exe for the QWIN title
  118.  
  119. if sizeD
  120.     push    ds
  121.     lds    bx,dword ptr (__argv)    ; ds:bx = __argv
  122.     assumes  ds,nothing
  123.     mov    ax,word ptr ds:[bx]
  124.     mov    dx,word ptr ds:[bx+2]    ; dx:ax = __argv[0]
  125.     pop    ds
  126.     assumes ds,data
  127. else
  128.     mov    bx,word ptr (__argv)    ; bx = __argv
  129.     mov    ax,word ptr [bx]
  130.     mov    dx,ds            ; dx:ax = __argv[0]
  131. endif
  132.  
  133.     ; _splitpath ( __argv[0], NULL, NULL, *filename, NULL)
  134.  
  135.     sub    sp,_MAX_FNAME        ; space for filename on stack
  136.     mov    bx,sp            ; bx = pointer to filename space
  137.     xor    cx,cx            ; cx = 0
  138. if sizeD
  139.     push    cx
  140.     push    cx            ; extension = NULL
  141.     push    ss
  142.     push    bx            ; * filename
  143.     push    cx
  144.     push    cx            ; directory = NULL
  145.     push    cx
  146.     push    cx            ; drive = NULL
  147.     push    dx
  148.     push    ax            ; __argv[0]
  149.     callcrt _splitpath
  150.     add    sp,20            ; clean stack
  151. else
  152.     push    cx            ; extension = NULL
  153.     push    bx            ; * filename
  154.     push    cx            ; directory = NULL
  155.     push    cx            ; drive = NULL
  156.     push    ax            ; __argv[0]
  157.     callcrt _splitpath
  158.     add    sp,10            ; clean stack
  159. endif
  160.     mov    ax,sp            ; ss:bx = *filename
  161.  
  162.     ; _QWINInit( (char far *) filename, _nfile, _wfile, hInstance, cmdShow )
  163.     ; [Note: _QWINInit makes its own copy of the filename string!]
  164.  
  165.     mov    bx,[_cmdShow]        ; _cmdShow
  166.     push    bx
  167.     mov    bx,[_hInstance]     ; _hInstance
  168.     push    bx
  169.     mov    bx,[_wfile]        ; # of windows file handles
  170.     push    bx
  171.     mov    bx,[_nfile]        ; 1st windows file handle
  172.     push    bx
  173.     push    ss
  174.     push    ax            ; *filename
  175.     call    _QWINInit
  176.     add    sp,(12+_MAX_FNAME)    ; clean off args and filename
  177.     or    ax,ax            ; ax = 0 = success
  178.     jnz    fatal_err
  179.  
  180. ;
  181. ; Open stdin/out/err windows
  182. ;
  183.     ; _QWINOpen ( (far *) _wopeninfo, (far *) _wsizeinfo )
  184.  
  185.     xor    ax,ax            ; NULL = default size info
  186.     push    ax
  187.     push    ax
  188.     mov    ax,dataOFFSET _wopen    ; ds:bx = *_wopeninfo
  189.     push    ds
  190.     push    ax
  191.     call    _QWINOpen
  192.     add    sp,8
  193.     cmp    ax,-1            ; ax = file handle
  194.     je    fatal_err
  195.  
  196.     ; Make sure the std file handle is what we expect
  197.     cmp    ax,[_nfile]
  198.     jne    fatal_err
  199.  
  200.  
  201. ;
  202. ; Set the default EXIT behavior
  203. ;
  204.  
  205. ;
  206. ; _QWINSetExit(_QWINEXITPERSIST)
  207. ;
  208.  
  209.     mov    ax,_WINEXITPERSIST
  210.     push    ax
  211.     call    _QWINSetExit
  212.     add    sp,2
  213.     or    ax,ax
  214.     jnz    fatal_err
  215.  
  216.  
  217. cEnd <nolocals>
  218.  
  219.  
  220. ;***
  221. ; _wcexit - QWIN C Exit
  222. ;
  223. ;Purpose:
  224. ;    Exit the QWIN system.
  225. ;
  226. ;    Exit the QWIN system.  We can't do this in the pre-terminators because
  227. ;    we want to make sure flushall() gets called before _QWINExit.
  228. ;
  229. ;Entry: <void>
  230. ;
  231. ;Exit:    <void>
  232. ;
  233. ;Uses:
  234. ;
  235. ;Exceptions:
  236. ;
  237. ;*******************************************************************************
  238.  
  239. cProc    _wcexit,<PUBLIC,NEAR>,<>
  240.  
  241.     parmW    status        ; exit code
  242.  
  243. cBegin <nolocals>
  244.  
  245.     mov    ax,[status]    ; exit code
  246.     push    ax
  247.     call    _QWINExit
  248.     add    sp,2
  249.  
  250. cEnd <nolocals>
  251.  
  252.  
  253. ;***
  254. ; _wcterm - QWIN C Termination
  255. ;
  256. ;Purpose:
  257. ;    Terminate the QWIN system.
  258. ;
  259. ;    Note: This routine is placed in the terminator table so it
  260. ;    is executed by both exit() and _exit().
  261. ;
  262. ;Entry: <void>
  263. ;
  264. ;Exit:    <void>
  265. ;
  266. ;Uses:
  267. ;
  268. ;Exceptions:
  269. ;
  270. ;*******************************************************************************
  271.  
  272. cProc    _wcterm,<PUBLIC>,<>
  273.  
  274. cBegin <nolocals>
  275.  
  276.     call    _QWINTerm     ; terminate windows package
  277.     cmp    ax,-1        ; error?
  278.     je    fatal_err    ; yup, die
  279.  
  280. cEnd <nolocals>
  281.  
  282.  
  283. ;
  284. ; --- Fatal Error ---
  285. ;
  286.  
  287. fatal_err:
  288.     mov    ax,_RT_QWIN    ; QuickWin error
  289.     jmp    _amsg_exit    ; die
  290.  
  291. sEnd
  292.     End
  293.