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

  1.     page    ,132
  2.     title    nmsghdr - near message handler and finder
  3. ;***
  4. ;nmsghdr.asm - near message handler and finder
  5. ;
  6. ;    Copyright (c) 1986-1992, Microsoft Corporation.  All rights reserved.
  7. ;
  8. ;Purpose:
  9. ;    Near message handler and finder.
  10. ;
  11. ;*******************************************************************************
  12.  
  13.  
  14. ?DF=    1            ; this is special for c startup
  15. include version.inc
  16. ?PLM=    1            ; pascal calling conventions
  17. .xlist
  18. include cmacros.inc
  19. include msdos.inc
  20. include defsegs.inc
  21. .list
  22.  
  23. ifndef _WINDOWS
  24.     _DEBUGSCREEN equ 1        ; debug screen swapping
  25. endif
  26.  
  27. ;
  28. ; segment definitions
  29. ;
  30.  
  31. CrtDefSegs  <code,data>
  32. CrtDefSegs  <nmsg>
  33. CrtDefSegs  <dbdata>
  34.  
  35. codeOFFSET equ    <offset _TEXT:>
  36. dataOFFSET equ    <offset DGROUP:>
  37.  
  38. ;
  39. ; data segments
  40. ;
  41.  
  42. sBegin    nhdr
  43. assumes ds,data
  44.  
  45.     db    '<<NMSG>>'
  46.  
  47. stnmsg    label    byte
  48.  
  49. sEnd
  50.  
  51. sBegin    npad
  52. assumes ds,data
  53.  
  54.     dw    -1        ; message padding marker
  55.  
  56. sEnd
  57.  
  58. sBegin    nepad
  59. assumes ds,data
  60.  
  61.     db    -1
  62.  
  63. sEnd
  64.  
  65. ifdef _QWIN
  66. sBegin    data
  67. assumes ds,data
  68. extrn    __nfile:word        ; Maximum number of file handles
  69. extrn    __qwinused:word     ; QWIN used/notused flag
  70. sEnd
  71. endif    ; _QWIN
  72.  
  73. ifdef _DEBUGSCREEN
  74. sBegin    dbdata                ;
  75.     assumes ds,data         ; Used to do the running under
  76. externW     ___aDBswpflg        ; a debugger screen swapping
  77. externW     ___aDBswpchk        ;
  78. sEnd    dbdata                ;
  79.     extrn    __aDBdoswp:ABS        ;
  80. endif    ; _DEBUGSCREEN
  81.  
  82.  
  83. ;
  84. ; external functions
  85. ;
  86.  
  87. ifdef _QWIN
  88. externNP   __wwrite        ; Write to QWIN window handle
  89. endif
  90.  
  91. ifdef    _WINDEBUG
  92. externFP OUTPUTDEBUGSTRING        ; debug output call
  93. endif
  94.  
  95.  
  96. sBegin    code
  97. assumes cs,code
  98. assumes ds,data
  99.  
  100. page
  101. ;***
  102. ;__NMSG_TEXT(messagenumber) - find message for given message number
  103. ;
  104. ;Purpose:
  105. ;    This routine returns a near pointer to the message associated with
  106. ;    messagenumber.    If the message does not exist, then a 0 is returned.
  107. ;
  108. ;    This routine assumes DS = DGROUP
  109. ;
  110. ;Entry:
  111. ;    ==PASCAL CALLING CONVENTIONS==
  112. ;    messagenumber = WORD message number of desired message
  113. ;
  114. ;Exit:
  115. ;    AX    = pointer to message text or 0 if no message exists.
  116. ;
  117. ;Uses:
  118. ;
  119. ;Exceptions:
  120. ;
  121. ;*******************************************************************************
  122.  
  123. cProc    __NMSG_TEXT,<PUBLIC>,<si,di>  ; pascal calling
  124.  
  125.     parmW    msgt
  126.  
  127. cBegin
  128.     push    ds
  129.     pop    es
  130.     mov    dx,msgt     ; dx = message number
  131.     mov    si,dataOFFSET stnmsg ; start of near messages
  132.  
  133. tloop:
  134.     lodsw            ; ax = current message number
  135.     cmp    ax,dx
  136.     je    found        ;   found it - return address
  137.     inc    ax
  138.     xchg    ax,si
  139.     jz    found        ;   at end and not found - return 0
  140.     xchg    di,ax
  141.     xor    ax,ax
  142.     mov    cx,-1
  143.     repne    scasb        ; skip until 00
  144.     mov    si,di
  145.     jmp    tloop        ; try next entry
  146.  
  147. found:
  148.     xchg    ax,si
  149. cEnd
  150.  
  151.  
  152. page
  153. ;***
  154. ;__NMSGWRITE(messagenumber) - writes message on stderr
  155. ;
  156. ;Purpose:
  157. ;    This routine writes the message associated with messagenumber
  158. ;    to stderr.
  159. ;
  160. ;
  161. ifdef _WINDOWS
  162. ;    NOTES:
  163. ;
  164. ;    (1) _WINDOWS = Only output if under QuickWin (no stderr
  165. ;    otherwise).
  166. ;
  167. ;    (2) _WINDLL = Can't do any output (no stderr).
  168. ;
  169. ifdef _WINDEBUG
  170. ;    (3) _WINDEBUG = Send output to OUTPUTDEBUGSTRING.  Can't
  171. ;    use this for standard libs because that call sends output
  172. ;    to AUX port if no debugger present (bogus popup on users
  173. ;    screen about attempting to write to AUX).
  174. ;
  175. endif    ;_WINDEBUG
  176. endif    ;_WINDOWS
  177. ;
  178. ;Entry:
  179. ;    ==PASCAL CALLING CONVENTIONS==
  180. ;    messagenumber = WORD number of desired message
  181. ;
  182. ;Exit:
  183. ;
  184. ;Uses:
  185. ;
  186. ;Exceptions:
  187. ;
  188. ;*******************************************************************************
  189.  
  190. cProc    __NMSG_WRITE,<PUBLIC>,<di>  ; pascal calling
  191.  
  192.     parmW    msgw
  193.  
  194. cBegin
  195.  
  196. ifndef _WINDLL
  197.  
  198. ifdef _QWIN
  199.     cmp    [__qwinused],0    ; QWIN enabled ??
  200.     je    nowrite     ; nope, can't write to stderr
  201. endif
  202.     push    msgw
  203.     callcrt __NMSG_TEXT    ; find near text pointer
  204.     or    ax,ax
  205.     jz    nowrite     ; don't write anything if not there
  206.  
  207.     xchg    dx,ax        ; ds:dx = string address
  208.     mov    di,dx
  209.     xor    ax,ax
  210.     mov    cx,-1
  211.     repne    scasb        ; es = ds from __NMSG_TEXT
  212.     not    cx
  213.     dec    cx        ; cx = string length
  214. ifdef _QWIN
  215.     mov    bx,[__nfile]    ; bx = __nfile (QWIN std file handle)
  216.     call    __wwrite    ; QWIN call
  217. else
  218.     mov    bx,2        ; bx = stderr
  219. ifdef _DEBUGSCREEN
  220.     cmp    ___aDBswpflg,__aDBdoswp ; Aware debugger as parent?
  221.     jne    @F            ; No -- skip
  222.     call    ___aDBswpchk        ; Yes -- see if we need to swap screens
  223. @@:
  224. endif    ; _DEBUGSCREEN
  225.  
  226.     callos    write        ; write to stderr
  227. endif
  228.  
  229.  
  230. endif    ;!_WINDLL
  231.  
  232. nowrite:
  233.  
  234. ifdef _WINDEBUG
  235.  
  236.     ;
  237.     ; Put out the message to the system debugger,
  238.     ; (message goes to AUX port if no debugger).
  239.     ;
  240.  
  241.     push    msgw
  242.     callcrt __NMSG_TEXT        ; find near text pointer
  243.     or    ax,ax
  244.     jz    endwrite        ; don't write anything if not there
  245.  
  246.     push    ds
  247.     push    ax
  248.     call    OUTPUTDEBUGSTRING    ; OUTPUTDEBUGSTRING(errormsg)
  249.  
  250. endwrite:
  251.  
  252. endif    ;_WINDEBUG
  253.  
  254. cEnd
  255.  
  256. sEnd
  257.  
  258.     end
  259.