home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Fortran.51 / DISK5 / OS2 / NMSGHDR.AS$ / NMSGHDR.bin
Text File  |  1989-08-31  |  3KB  |  179 lines

  1.     page    ,132
  2.     title    nmsghdr - OS/2 near message handler and finder
  3. ;***
  4. ;nmsghdr.asm - OS/2 near message handler and finder
  5. ;
  6. ;    Copyright (c) 1986-1990, 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. .list
  21.  
  22. createSeg _TEXT, code,    word,    public, CODE,    <>
  23.  
  24. createSeg _DATA, data,    word,    public, DATA,    DGROUP
  25.  
  26. createSeg HDR,    nhdr,    byte,    public, MSG,    DGROUP
  27. createSeg MSG,    nmsg,    byte,    public, MSG,    DGROUP
  28. createSeg PAD,    npad,    byte,    common, MSG,    DGROUP
  29. createSeg EPAD, nepad,    byte,    common, MSG,    DGROUP
  30.  
  31. defGrp    DGROUP            ; define DGROUP
  32.  
  33. codeOFFSET equ    offset _TEXT:
  34. dataOFFSET equ    offset DGROUP:
  35.  
  36. extrn    DOSWRITE:far
  37.  
  38. sBegin    nhdr
  39. assumes ds,data
  40.  
  41. nmsgst    db    '<<NMSG>>'
  42. ;ljk    dw    dataOFFSET nmsgst
  43. ;ljk    dw    dataOFFSET stpad
  44. ;ljk    dw    dataOFFSET endpad
  45.  
  46. stnmsg    label    byte
  47.  
  48. sEnd
  49.  
  50. SBegin    npad
  51. assumes ds,data
  52.  
  53. stpad    dw    -1        ; message padding marker
  54.  
  55. sEnd
  56.  
  57. sBegin    nepad
  58. assumes ds,data
  59.  
  60.     db    -1
  61. ;ljk    endpad    label    byte
  62.  
  63. sEnd
  64.  
  65.  
  66. sBegin    code
  67. assumes cs,code
  68. assumes ds,data
  69.  
  70. page
  71. ;***
  72. ;__NMSG_TEXT(messagenumber) - finds message for given messagenumber
  73. ;
  74. ;Purpose:
  75. ;    This routine returns a near pointer to the message associated with
  76. ;    messagenumber.    If the message does not exist, then a 0 is returned.
  77. ;
  78. ;    This routine reestablishes DS = ES = DGROUP
  79. ;
  80. ;Entry:
  81. ;    ==PASCAL CALLING CONVENTIONS==
  82. ;    messagenumber    = WORD number of desired error message
  83. ;
  84. ;Exit:
  85. ;    AX = number of message or 0.
  86. ;
  87. ;Uses:
  88. ;
  89. ;Exceptions:
  90. ;
  91. ;*******************************************************************************
  92.  
  93. cProc    __NMSG_TEXT,<PUBLIC>,<si,di>  ; pascal calling
  94.  
  95. parmW    msgt
  96.  
  97. cBegin
  98.     mov    ax,DGROUP
  99.     mov    ds,ax        ; ds = DGROUP (force it always)
  100.     mov    es,ax        ; es = ds
  101.     mov    dx,msgt     ; dx = message number
  102.     mov    si,dataOFFSET stnmsg ; start of near messages
  103.  
  104. tloop:
  105.     lodsw            ; ax = current message number
  106.     cmp    ax,dx
  107.     je    found        ;   found it - return address
  108.     inc    ax
  109.     xchg    ax,si
  110.     jz    found        ;   at end and not found - return 0
  111.     xchg    di,ax
  112.     xor    ax,ax
  113.     mov    cx,-1
  114.     repne    scasb        ; skip until 00
  115.     mov    si,di
  116.     jmp    tloop        ; try next entry
  117.  
  118. found:
  119.     xchg    ax,si
  120. cEnd
  121.  
  122. page
  123. ;***
  124. ;__NMSGWRITE(messagenumber) - write a given message to stderr
  125. ;
  126. ;Purpose:
  127. ;    This routine writes the message associated with messagenumber
  128. ;    to stderr.
  129. ;
  130. ;Entry:
  131. ;    ==PASCAL CALLING CONVENTIONS==
  132. ;    messagenumber    = number of desired message to print.
  133. ;
  134. ;Exit:
  135. ;
  136. ;Uses:
  137. ;
  138. ;Exceptions:
  139. ;
  140. ;*******************************************************************************
  141.  
  142. cProc    __NMSG_WRITE,<PUBLIC>,<di>  ; pascal calling
  143.  
  144. parmW    msgw
  145.  
  146. cBegin
  147.     push    msgw
  148.     callcrt __NMSG_TEXT    ; find near text pointer
  149.     or    ax,ax
  150.     jz    nowrite     ; don't write anything if not there
  151.  
  152.     xchg    dx,ax        ; ds:dx = string address
  153.     mov    di,dx
  154.     xor    ax,ax
  155.     mov    cx,-1
  156.     repne    scasb        ; es = ds from __NMSG_TEXT
  157.     not    cx
  158.     dec    cx        ; cx = string length
  159.  
  160.     push    ax        ;** vvv
  161.     mov    ax,sp        ; allocate space for return count
  162.  
  163.     mov    bx,2
  164.     push    bx        ; file handle (standard error)
  165.     push    ds
  166.     push    dx        ; address of buffer
  167.     push    cx        ; number of bytes to write
  168.     push    ss
  169.     push    ax        ; address for return count
  170.     call    DOSWRITE
  171.     pop    bx        ;** ^^^     ; clean-up stack
  172.  
  173. nowrite:
  174. cEnd
  175.  
  176. sEnd
  177.  
  178.     end
  179.