home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / tools / hookbsm / doswin32.mac < prev    next >
Encoding:
Text File  |  1993-01-01  |  21.5 KB  |  710 lines

  1. ;--------------------------------------------------------------------
  2. ;doswin32.mac  Begun:Sat  08-22-1992  Revised:Fri  01-01-1993
  3. ;
  4. ;These Macros are more general purpose in definition and serve both
  5. ;DOS and WIN calls
  6. ;
  7. ;--------------------------------------------------------------------
  8. ;
  9. ;QMSG    STRUC
  10. ;qmsg_hwnd       DD      ?
  11. ;qmsg_msg        DD      ?
  12. ;qmsg_mp1        DD      ?
  13. ;qmsg_mp2        DD      ?
  14. ;qmsg_time       DD      ?
  15. ;qmsg_ptl        DB      SIZE POINTL DUP (?)
  16. ;qmsg_reserved   DD      ?
  17. ;QMSG    ENDS
  18. ;
  19. ;POINTL  STRUC
  20. ;ptl_x   DD      ?
  21. ;ptl_y   DD      ?
  22. ;POINTL  ENDS
  23.  
  24. ;---------------- Switch List Structures in PMSHL.INC
  25. ;SWCNTRL STRUC   ;size = 96                        ;OFFSET FROM 0
  26. ;swctl_hwnd      DD      ?                              8  Handle of Frame of Active Program
  27. ;swctl_hwndIcon  DD      ?                             12
  28. ;swctl_hprog     DD      ?                             16
  29. ;swctl_idProcess DD      ?                             20
  30. ;swctl_idSession DD      ?                             24
  31. ;swctl_uchVisibility     DD      ?                     28
  32. ;swctl_fbJump    DD      ?                             32
  33. ;swctl_szSwtitle DB      MAXNAMEL+4 DUP (?)            36  this is 60 long
  34. ;swctl_bProgType DD      ?                             96
  35. ;SWCNTRL ENDS
  36.  
  37. ;SWENTRY STRUC   ;size = 4 + 96
  38. ;swent_hswitch   DD      ?                              4 SwitchListEntryHandle
  39. ;swent_swctl     DB      SIZE SWCNTRL DUP (?)           8
  40. ;SWENTRY ENDS
  41.  
  42. ;SWBLOCK STRUC   ;size = 4 + (4+96)                ;
  43. ;swblk_cswentry  DD      ?                         ;    0  Count of Entries
  44. ;swblk_aswentry  DB      SIZE SWENTRY * 1 DUP (?)  ;    4
  45. ;SWBLOCK ENDS
  46. swblksize          equ  100     ; Size of SwitchList Structure
  47.  
  48. ;equates related to message structure
  49. hwnd           equ   quemsg.qmsg_hwnd
  50. msg            equ   quemsg.qmsg_msg
  51. mp1            equ   quemsg.qmsg_mp1
  52. mp2            equ   quemsg.qmsg_mp2
  53.  
  54. HWND_DESKTOP   equ   1               ;needed for  WinErrorMessage macro
  55. msgBoxErrStyle equ   (MB_ERROR OR MB_CANCEL)
  56. msgBoxInfStyle equ   (MB_INFORMATION OR MB_ENTER)
  57. ;---------------- I/O DOS Calls Only---------------
  58. stdin          equ   0
  59. stdout         equ   1
  60. stderr         equ   2
  61.  
  62. ;---------------- Useful ---------------
  63. cr             equ   0dh
  64. lf             equ   0ah
  65. nl             equ   0dh,0ah   ;cr+lf
  66. BEL            equ   07h
  67. NULL           equ   0000h
  68.  
  69. ;External declarations for DOS (Control Program) Functions (Used So Far)
  70. EXTRN    DosAllocMem:near,DosAllocSharedMem:near,DosBeep:near,DosClose:near
  71. EXTRN    DosCreateThread:near,DosDevConfig:near,DosDevIOCtl:near
  72. EXTRN    DosExecPgm:near,DosExit:near,DosFreeMem:near,DosFreeModule:near
  73. EXTRN    DosGetInfoBlocks:near,DosGetNamedSharedMem:near,DosKillThread:near
  74. EXTRN    DosLoadModule:near,DosOpen:near,DosPutMessage:near
  75. EXTRN    DosQueryModuleHandle:near,DosQueryModuleName:near,DosQueryProcAddr:near
  76. EXTRN    DosQueryProcType:near,DosRead:near,DosSleep:near,DosSetFilePtr:near
  77. EXTRN    DosSetFileSize:near,DosStartSession:near,DosSetPriority:near
  78. EXTRN    DosWrite:near
  79.  
  80. ;External declarations for Window (PM) Functions (Used So Far)
  81. EXTRN    WinAlarm:near,WinBeginPaint:near,WinBeginEnumWindows:near
  82. EXTRN    WinBroadcastMsg:near,WinChangeSwitchEntry:near
  83. EXTRN    WinCreateMsgQueue:near,WinCreateStdWindow:near,WinDefWindowProc:near
  84. EXTRN    WinDestroyMsgQueue:near,WinDestroyWindow:near,WinDispatchMsg:near
  85. EXTRN    WinDrawText:near,WinEnableWindow:near,WinEndEnumWindows:near
  86. EXTRN    WinEndPaint:near,WinFillRect:near
  87. EXTRN    WinFocusChange:near,WinFreeErrorInfo:near
  88. EXTRN    WinGetCurrentTime:near,WinGetErrorInfo:near,WinGetKeyState:near
  89. EXTRN    WinGetMsg:near,WinGetLastError:near,WinGetNextWindow:near,WinGetPS:near
  90. EXTRN    WinGetScreenPS:near,WinInitialize:near,WinInvalidateRect:near
  91. EXTRN    WinLockWindowUpdate:near,WinMessageBox:near
  92. EXTRN    WinOpenWindowDC:near,WinPostMsg:near,WinQueryAccelTable:near
  93. EXTRN    WinQueryActiveWindow:near
  94. EXTRN    WinQueryAnchorBLock:near,WinQueryCapture:near,WinQueryClassName:near
  95. EXTRN    WinQueryDesktopWindow:near,WinQueryFocus:near,WinQueryMsgTime:near
  96. EXTRN    WinQueryPointerPos:near
  97. EXTRN    WinQuerySwitchList:near,WinQueryWindow:near,WinQueryWindowModel:near
  98. EXTRN    WinQueryWindowPos:near,WinQueryWindowRect:near
  99. EXTRN    WinRegisterClass:near,WinReleaseHook:near,WinReleasePS:near
  100. EXTRN    WinSetActiveWindow:near,WinSetCapture:near,WinSetFocus:near
  101. EXTRN    WinSetHook:near,WinSendMsg:near
  102. EXTRN    WinSetPointerPos:near
  103. EXTRN    WinSetWindowPos:near,WinSetWindowText:near
  104. EXTRN    WinShutdownSystem:near,WinSwitchToProgram:near,WinTerminate:near
  105. EXTRN    WinUpdateWindow:near,WinWindowFromPoint:near
  106.  
  107. ;External declarations for Window (GPI) Functions (Used So Far)
  108. EXTRN    GpiCharStringAt:near,GpiCreatePS:near,GpiCreateLogFont:near,GpiLoadFonts:near
  109. EXTRN    GpiQueryDevice:near,GpiQueryFonts:near,GpiSetCharSet:near
  110. EXTRN    GpiSetColor:near,GpiSetDrawingMode:near
  111.  
  112. ;External declarations for Window (DEV) Functions (Used So Far)
  113. EXTRN    DevQueryCaps:near
  114.  
  115. ;----------------------------------------------------------
  116. ;DEFINE Macros for DATA SEgment
  117.  
  118. ;Define Buffers used for Storage and for Num conversion
  119. $DefineNumBufs  MACRO
  120.     B_Buf       BYTE  3 dup(?)
  121.     W_Buf       BYTE  5 dup(?)
  122.     DW_Buf      BYTE 10 dup(0)
  123.     DW_BUFHex   BYTE  9 dup(0)
  124.     Bit8Str     BYTE  8 dup(?)
  125.     Bit16Str    BYTE  16 dup(?)
  126.     Bit32Str    BYTE  32 dup(?)
  127.     ten        DWORD  10         ;used for AsciiToWord
  128.     lth        DWORD  ?          ;used for AsciiToWord
  129.     errId      DWORD  ?
  130. ENDM
  131.  
  132. ;some standard strings and other vars for Data segment
  133. $DOSErrorMessages  MACRO
  134.     DosErrorMsg     BYTE   " Error calling Dos CP Function "
  135.     DosErrOpts      BYTE   "Enter Q to Quit Program - Any other Key to Continue"
  136.     DosReadErr      BYTE   ?,?    ;required for DOS read
  137.     newline         BYTE   13,10
  138.     nwritten       DWORD   ?      ;required for DOS Write
  139. ENDM
  140.  
  141. ;This macro allows the calling of any function subject only to the fact
  142. ;that it has no more than 10 parameters and that all are either DWORD
  143. ;long or are 32 bit offsets - i.e. it is a Full PUSH
  144. ;Enter Arguments in same order as listed in OS/2 2.0 Technical Library
  145. $Call MACRO fname,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
  146.     ctr = 0
  147.     IFNB <arg9>
  148.        push  arg9
  149.        ctr = ctr + 4
  150.     ENDIF
  151.     IFNB <arg8>
  152.        push  arg8
  153.        ctr = ctr + 4
  154.     ENDIF
  155.     IFNB <arg7>
  156.        push  arg7
  157.        ctr = ctr + 4
  158.     ENDIF
  159.     IFNB <arg6>
  160.        push  arg6
  161.        ctr = ctr + 4
  162.     ENDIF
  163.     IFNB <arg5>
  164.        push  arg5
  165.        ctr = ctr + 4
  166.     ENDIF
  167.     IFNB <arg4>
  168.        push  arg4
  169.        ctr = ctr + 4
  170.     ENDIF
  171.     IFNB <arg3>
  172.        push  arg3
  173.        ctr = ctr + 4
  174.     ENDIF
  175.     IFNB <arg2>
  176.        push  arg2
  177.        ctr = ctr + 4
  178.     ENDIF
  179.     IFNB <arg1>
  180.        push  arg1
  181.        ctr = ctr + 4
  182.     ENDIF
  183.     IFNB <arg0>
  184.        push  arg0
  185.        ctr = ctr + 4
  186.     ENDIF
  187.     call   fname
  188.     add    esp,ctr
  189. ENDM
  190.  
  191. $NewLine     equ    $DosWriteMsg <cr,lf>
  192.  
  193. $Printf0 MACRO  typ,prm  ;typ : b/w/s = BYTE/WORD/STRING whose value is val
  194.     local    msgname,xit     ;bb/bw/ = 8bitstring,16bitstring representation of #
  195.     pusha                    ;bx/wx/dwx =  Byte/Word/DWord to Hex
  196.     IFIDNI  <typ>,<x>    ;default - nothing entered - exit
  197.         jmp   xit
  198.     ENDIF
  199.     IFIDNI  <typ>,<b>    ;b/w/ followed by b/h is in Binary/Hex representation
  200.         xor  edx,edx
  201.         mov  dl,prm
  202.         $DWordToAscii edx,DW_Buf
  203.         $DosWriteMsgAT DW_Buf
  204.         jmp   xit
  205.     ENDIF
  206.     IFIDNI  <typ>,<w>
  207.         xor  edx,edx
  208.         mov  dx,prm
  209.         $DWordToAscii edx,DW_Buf
  210.         $DosWriteMsgAT DW_Buf
  211.         jmp   xit
  212.     ENDIF
  213.     IFIDNI  <typ>,<dw>
  214.         $DWordToAscii prm,DW_Buf
  215.         $DosWriteMsgAT DW_Buf
  216.         jmp   xit
  217.     ENDIF
  218.     IFIDNI  <typ>,<bx>    ;b/w/ followed by b/h is in Binary/Hex representation
  219.         xor  edx,edx
  220.         mov  dl,prm
  221.         $DWordToHex edx,DW_Buf
  222.         $DosWriteMsgAT DW_Buf
  223.         jmp   xit
  224.     ENDIF
  225.     IFIDNI  <typ>,<wx>
  226.         xor  edx,edx
  227.         mov  dx,prm
  228.         $DWordToHex edx,DW_Buf
  229.         $DosWriteMsgAT DW_Buf
  230.         jmp   xit
  231.     ENDIF
  232.     IFIDNI  <typ>,<dwx>
  233.         $DWordToHex prm,DW_Buf
  234.         $DosWriteMsgAT DW_Buf
  235.         jmp   xit
  236.     ENDIF
  237.     IFIDNI  <typ>,<bb>
  238.         mov   al,prm
  239.         $ByteToBitString
  240.         $DosWriteMsgAT  Bit8Str
  241.         jmp   xit
  242.     ENDIF
  243.     IFIDNI  <typ>, <wb>
  244.         mov   ax,prm
  245.         $WordToBitString
  246.         $DosWriteMsgAT  Bit16Str
  247.         jmp   xit
  248.     ENDIF
  249.     IFIDNI  <typ>, <s>
  250.     $DosWriteMsg prm
  251.         jmp   xit
  252.     ENDIF
  253. xit:popa
  254. ENDM
  255.  
  256. $Printf MACRO  t1,p1,t2:=<x>,p2,t3:=<x>,p3,t4:=<x>,p4,t5:=<x>,p5,t6:=<x>,p6,t7:=<x>,p7
  257.     $Printf0  t1,p1
  258.     $Printf0  t2,p2
  259.     $Printf0  t3,p3
  260.     $Printf0  t4,p4
  261.     $Printf0  t5,p5
  262.     $Printf0  t6,p6
  263.     $Printf0  t7,p7
  264. ENDM
  265.  
  266.  
  267. $CLS  MACRO     ;clear screen with DosWrite
  268.     local cxc
  269.     mov         cx,24
  270.     cxc:
  271.                 $DosWriteMsg cr
  272.                 $DosWriteMsg lf
  273.     loop        cxc
  274. ENDM
  275.  
  276. $DosReadKB MACRO  numreq,char_in_buf
  277.     .DATA
  278.     IFNDEF    bytesread
  279.         bytesread DWORD   0
  280.     ENDIF
  281.     .CODE
  282.     push     offset bytesread
  283.     pushd    numreq
  284.     push     offset char_in_buf
  285.     pushd     stdin
  286.     call     DosRead
  287.     add      esp,16
  288. ENDM
  289.  
  290. ; Write a message to console at current cursor
  291. $DosWriteMsg MACRO  messag
  292.     local    idmessag
  293.     .DATA
  294. ;    IFNDEF   messag
  295.       idmessag   BYTE  messag
  296. ;    ENDIF
  297.     .CODE
  298.     push     offset nwritten
  299.     push     LENGTHOF idmessag
  300.     push     offset idmessag
  301.     push     stdout      ;unsigned long
  302.     call     DosWrite
  303.     add      esp,16      ;restore stack pointer
  304. ENDM
  305.  
  306. ; Write to console the message stored AT location
  307. ; ofset is the offset from start of string "location" to start writing
  308. ; devised to get around printing leading spaces in numerical conversions
  309. $DosWriteMsgAT MACRO  location ,ofset:=<0>   ;0 is default
  310.     push     offset nwritten
  311.     mov      eax,LENGTHOF location
  312.     sub      eax,ofset
  313.     push     eax
  314.     mov      eax,offset location
  315.     add      eax,ofset
  316.     push     eax
  317.     pushd    stdout      ;unsigned long
  318.     call     DosWrite
  319.     add      esp,16      ;restore stack pointer
  320. ENDM
  321.  
  322.  
  323. $Alarm0  MACRO     ;Makes a nice up and down sound
  324.     $Call DosBeep,200,75
  325.     $Call DosBeep,400,75
  326.     $Call DosBeep,200,75
  327. ENDM
  328.  
  329. ; Concantenate String S2 to end of String S1 and place at S3
  330. ; S3 buffer must be long enough to hold S1+S2. S3 is 0 terminated
  331. ; copy S1 to buffer S3 and then add S2 at end
  332. $ConcantS1andS2toS3  MACRO  S1,S2,S3
  333.      pusha
  334.      mov     edi,offset S3
  335.      mov     esi,offset S1
  336.      mov     ecx,LENGTHOF S1
  337.      rep     movsb           ;copy to S3
  338.      mov     esi,offset S2
  339.      mov     ecx,LENGTHOF S2 ;continue copy to S3
  340.      rep     movsb
  341.      inc     edi
  342.      mov     byte ptr [edi],0    ;NULL Terminate
  343.      popa
  344. ENDM
  345.  
  346. ;This is useful for BEEPING
  347. $DosBeep equ  $Call DosBeep,500,500   ;frequency,duration
  348.  
  349. ;Useful for exiting
  350. $DosExit equ  $Call DosExit,1,0  ;return 0 and all threads
  351.  
  352. ;useful for Carriage ReturnLine Feeds - requires newline definition in .DATA
  353. $NewLine equ  $Call DosWrite,stdout,offset newline,LENGTHOF newline,offset nwritten
  354.  
  355. $NumSwitchListEntries  equ  $Call  WinQuerySwitchList,hab,0,0    ;eax has number of entries
  356.  
  357. ;Used for Displaying Error Messages forDOS functions
  358. ;Called right after a $Call call of a DOS function if Error trapping desired
  359. ;The user passes the FuncName to be displayed
  360. ;It should be the Name of the Function used in $Call
  361. ;If error is detected, after displaying error number and function
  362. ;User is offered option of exiting or continuing
  363. $DosErrMsg  MACRO  FuncName   ;FuncName passed in calling macros
  364.     local  exitDEM,  msgFuncName
  365.     pusha
  366.     .IF  eax == 0
  367.         jmp  exitDEM
  368.     .ENDIF
  369.     IFNDEF  FuncName
  370.       .DATA
  371.        msgFuncName   BYTE FuncName
  372.       .CODE
  373.     ENDIF
  374. ;    $DWordToAscii eax,DW_Buf
  375.     $DWordToHex eax,DW_Buf
  376.     $NewLine
  377.     $Call DosWrite,stdout,offset DW_Buf,LENGTHOF DW_BUF,offset nwritten
  378.     $Call DosWrite,stdout,offset DosErrorMsg,LENGTHOF DosErrorMsg,offset nwritten
  379.     $Call DosWrite,stdout,offset msgFuncName,LENGTHOF msgFuncName,offset nwritten
  380.     $DosBeep
  381.     $NewLine
  382.     $Call DosWrite,stdout,offset DosErrOpts,LENGTHOF DosErrOpts,offset nwritten
  383.     $Call DosRead,stdin,offset DosReadErr,1,offset nwritten
  384.     mov    al,DosReadErr
  385. .IF     al == 'q' || al == 'Q'
  386.      $DosExit
  387. .ENDIF
  388. exitDEM:  popa
  389. ENDM
  390.  
  391. $WinDebugMessage MACRO arg      ;Display Message = arg, # in eax before call
  392.     pusha
  393.     IFNDEF  concanted
  394.        .DATA
  395.         Concanted   BYTE 84 dup(0)     ;buffer to hold concanted strings
  396.     ENDIF
  397.     IFNDEF  msginfo
  398.        .DATA
  399.        msginfo   BYTE  "Debug Info",0
  400.     ENDIF
  401.     .CODE
  402.     $DWordToHex eax,DW_BufHex
  403.     $Alarm0
  404.     $ConcantS1andS2ToS3 DW_BufHex,arg,Concanted
  405.     $Call WinMessageBox,HWND_DESKTOP,HWND_DESKTOP,offset Concanted,offset msgInfo,0,msgBoxInfStyle
  406.     popa
  407. ENDM
  408.  
  409. ;Information Message for PM applications - Pass the Function name as String in ""
  410. $WinInfMsg MACRO FuncName0      ;sound alarm and display error box
  411.     local   msgFuncName0
  412.     pusha
  413.     IFNDEF  FuncName0
  414.       .DATA
  415.        msgFuncName0   BYTE FuncName0,0
  416.     ENDIF
  417.     IFNDEF  msgjustinfo
  418.       .DATA
  419.       msgjustInfo        BYTE "For Your Info",0
  420.     ENDIF
  421.     IFNDEF  concanted
  422.        .DATA
  423.         Concanted   BYTE 84 dup(0)     ;buffer to hold concanted strings
  424.     ENDIF
  425.     .CODE
  426. ;    $DWordToAscii eax,DW_Buf
  427.     $DWordToHex eax,DW_BufHex
  428.     $Alarm0
  429.     $ConcantS1andS2ToS3 DW_BufHex,msgFuncName0,Concanted
  430.     $Call WinMessageBox,HWND_DESKTOP,HWND_DESKTOP,offset Concanted,offset msgjustInfo,0,msgBoxInfStyle
  431.     popa
  432. ENDM
  433.  
  434. ;--- Display Error Information for WIN programs
  435. ;--- Call with eax holding address of error structure
  436. ;    ERRINFO_STRUC
  437. ;       erri_cbFixedErrInfo  DD
  438. ;       erri_idError         DD
  439. ;       erri_cDetailLevel    DD
  440. ;       erri_offaoffszMsg    DD      offset of message
  441. ;       erri_offBinaryData   DD      offset of Binary Data
  442. ;    ERRINFO ENDS
  443. ; Error Number returned has Error# in lower 16 bits and severity in higher
  444. $WinErrMSG MACRO FuncName
  445.     local   msgFuncName ;,ErrInfo
  446.     pusha
  447.     IFNDEF  FuncName
  448.       .DATA
  449.        msgFuncName   BYTE FuncName,0
  450.     ENDIF
  451.     IFNDEF  concanted
  452.        .DATA
  453.         Concanted   BYTE 84 dup(0)     ;buffer to hold concanted strings
  454.     ENDIF
  455. ;    IFNDEF  ErrInfo
  456. ;       ErrInfo   DWORD   ?
  457. ;    ENDIF
  458.     .CODE
  459.     $Call WinGetLastError,hab     ;error # for code in lower 16 bits of eax
  460.     xor   ebx,ebx
  461.     mov   bx,ax
  462.     xor   eax,eax
  463.     mov   ax,bx                   ;eax now has error number
  464. ;    $Call WinGetErrorInfo,hab     ;returns address of structure in eax
  465. ;    .IF eax == 0
  466. ;        $WinInfMsg  "No Error Info Available"
  467. ;    .ELSE
  468. ;        mov   ErrInfo,eax         ;save address here
  469. ;        mov   esi,eax
  470. ;        mov   eax,[esi+4]         ;idError
  471. ;        mov   eax,[esi+12]        ;offset of message
  472. ;        mov   edi,eax
  473. ;        $DWordToAscii eax,DW_Buf
  474. ;        $Alarm0
  475. ;        $ConcantS1andS2ToS3 DW_BUF,msgFuncName,Concanted
  476. ;        $Call WinMessageBox,HWND_DESKTOP,HWND_DESKTOP,offset Concanted,offset msgInfo,0,msgBoxInfStyle
  477. ;        $Call WinMessageBox,HWND_DESKTOP,HWND_DESKTOP,edi,offset msgInfo,0,msgBoxInfStyle
  478. ;        $Call WinFreeErrorInfo,ErrInfo
  479. ;    .ENDIF
  480. ;        $DWordToAscii eax,DW_Buf
  481.         $DWordToHex eax,DW_BufHex
  482. ;        $Alarm0
  483.         $ConcantS1andS2ToS3 DW_BUFHex,msgFuncName,Concanted
  484.         $Call WinMessageBox,HWND_DESKTOP,HWND_DESKTOP,offset Concanted,offset msgInfo,0,msgBoxInfStyle
  485.         popa
  486. ENDM
  487.  
  488. $GetCmdLine  MACRO  ;on return esi has offset of Command Line
  489.     .DATA
  490.     IFNDEF  ppTIB
  491.         ppTIB    DWORD  ?   ;To Hold Address of Thread   InfoBlock
  492.         ppPIB    DWORD  ?   ;To Hold Address of  Process InfoBlock
  493.     ENDIF
  494.     .CODE
  495.     push      offset ppPIB
  496.     push      offset ppTIB
  497.     call      DosGetInfoBlocks
  498.     add       esp,8          ;update ESP
  499.     mov       ebx,[ppPIB]    ;ebx = address of the PIB
  500.     mov       esi,[ebx+12]   ;esi is offset of command line
  501. ENDM
  502.  
  503. IFDEF NUMBUFS
  504. ;---------- Binary -> Ascii and Ascii -> Binary Conversions  ---------------
  505. ;Is Passed buffer name - tests to see if all characters in buffer are digits
  506. ;If not returns error message and aborts else returns number in eax
  507. ;skips over leading and trailing spaces
  508. $GetNumDigits MACRO  digbuf
  509.     push     esi
  510.     push     edi
  511.     mov      esi,offset digbuf
  512.     mov      edi,0
  513.     .WHILE 1
  514.         .WHILE byte ptr [esi] == 32    ;skip over leading spaces
  515.             inc esi
  516.         .ENDW
  517.         .IF  byte  ptr [esi] >= 30h
  518.             .IF byte ptr [esi] <= 39h
  519.                 inc edi
  520.                 inc esi
  521.              .ELSE
  522.                 .BREAK
  523.             .ENDIF
  524.          .ELSE
  525.             .BREAK
  526.          .ENDIF
  527.     .ENDW           ;on exit edi has number of bytes read
  528.     .IF edi == 0    ;no valid input
  529.          $DosBeep 500,500
  530.          IFDEF NOWIN    ;not a PM application
  531.              $NewLine
  532.              $Call DosWrite,"Invalid Input for ASCIIToDWord - Aborting"
  533.              $NewLine
  534.              $DosExit
  535.          ELSE
  536.              mov   eax,0
  537.              $WinDebugMessage
  538.              call ExitWin
  539.              $DosExit
  540.          ENDIF
  541.     .ENDIF
  542.     mov    eax,edi
  543.     pop    edi
  544.     pop    esi
  545. ENDM
  546.  
  547. ;Convert DWORD to ASCII string at xx BYTE buffer at digits
  548. ;Number to convert moved into EAX, esi points to buffer
  549. $DWordToAscii MACRO  num,buf
  550.     pusha
  551.     mov      eax,num
  552.     mov      esi,offset buf
  553.     call     DWordToAscii
  554.     popa
  555. ENDM
  556.  
  557. ;Convert DWORD to Hex string at 10 BYTE buffer at digits
  558. ;Number to convert moved into EAX, esi points to buffer
  559. $DWordToHex MACRO  num,buf
  560.     push     esi
  561.     mov      eax,num
  562.     mov      esi,offset buf
  563.     call     DWordToHex
  564.     pop      esi
  565. ENDM
  566.  
  567. ;convert string representing BYTE in BUFF to numeric DWORD
  568. ;result returned in EAX)
  569. $AsciiToDWord  MACRO  Buff
  570.     $GetNumDigits Buff  ;checks on validity of characters in buffer as well
  571.     mov      lth,eax
  572.     push     ebx
  573.     push     ecx
  574.     push     edx
  575.     push     edi
  576.     push     esi
  577.     mov      esi,offset Buff
  578.     call     AsciitoDWord
  579.     pop      esi
  580.     pop      edi
  581.     pop      edx
  582.     pop      ecx
  583.     pop      ebx
  584. ENDM
  585.  
  586. ;Convert BYTE to Binary Bit String
  587. ;Byte to convert in AL
  588. $ByteToBitString MACRO
  589.     pusha
  590.     mov     edi,offset Bit8Str
  591.     call    ByteToBitString
  592.     popa
  593. ENDM
  594.  
  595. ;Byte to convert in AX
  596. $WordToBitString MACRO
  597.     pusha
  598.     mov     edi,offset Bit16Str
  599.     call    WordToBitString
  600.     popa
  601. ENDM
  602.  
  603. ;----------- Procedures here ---------------
  604.  
  605. .CODE
  606. ;--- Call with esi pointing to buffer to store digit string
  607. DWordToAScii  Proc
  608.     mov      edi,10
  609.     xor      edx,edx
  610.     mov      ecx,10
  611. d0: div      edi
  612.     add      edx,30h
  613.     push     edx          ;save on stack
  614.     xor      edx,edx
  615.     loop     d0           ;on exit top of stack has first digit, etc.
  616.     mov      ecx,10
  617. d1: pop      edx
  618.     mov      [esi],dl     ;esi has address of buffer
  619.     inc      esi
  620.     loop     d1
  621.     ; now get rid of leading 0's
  622.     sub      esi,10       ;back to start of string
  623.     mov      ecx,10
  624.     .WHILE   byte ptr [esi] == "0"
  625.          mov byte ptr [esi]," "
  626.          inc esi
  627.          dec ecx
  628.     .ENDW
  629.     .IF  cx == 0          ; all spaces
  630.          dec esi
  631.          mov byte ptr [esi] ,'0'
  632.     .ENDIF
  633.      ret
  634. DWordToAscii   endp
  635.  
  636. AsciiToDWord  proc
  637.     mov      eax,1
  638.     xor      edi,edi
  639.     xor      ebx,ebx
  640.     mov      ecx,lth
  641.     dec      lth
  642.     add      esi,lth       ;offset is lnth -1 from 0
  643. w0: push     eax
  644.     sub      byte ptr [esi],30h
  645.     mov      bl,[esi]
  646.     mul      bl            ;result in EAX
  647.     add      edi,eax
  648.     pop      eax
  649.     mul      ten        ;10 x previous value in AX now
  650.     dec      esi
  651.     loopd    w0
  652.     mov      eax,edi
  653.     ret
  654. AsciiToDWord  endp
  655.  
  656. ;--- Call with esi pointing to buffer to store digit string
  657. DWordToHex  Proc
  658.     pusha
  659.     mov      edi,16
  660.     xor      edx,edx
  661.     mov      ecx,8
  662. d0: div      edi
  663.     .IF      edx <= 9
  664.         add      edx,30h
  665.     .ELSE
  666.         add      edx,55   ;use caps
  667.     .ENDIF
  668.     push     edx          ;save on stack
  669.     xor      edx,edx
  670.     loop     d0           ;on exit top of stack has first digit, etc.
  671.     mov      ecx,8
  672. d1: pop      edx
  673.     mov      [esi],dl     ;esi has address of buffer
  674.     inc      esi
  675.     loop     d1
  676.     mov      byte ptr [esi],'H'
  677.     popa
  678.      ret
  679. DWordToHex   endp
  680.  
  681. WordToBitString  proc  ;called with edi set to offset of string and # in ax
  682.     mov     cx,16
  683.     dec     edi
  684. wb0:inc     edi
  685.     shl     ax,1             ;move most significant bit to carry flag
  686.     jc      wb1              ;if set copy '1'
  687.     mov     byte ptr [edi],'0'       ;else copy '0'
  688.     jmp     wb2
  689. wb1:mov     byte ptr [edi],'1'
  690. wb2:loop    wb0
  691.     ret
  692. WordToBitString endp
  693.  
  694. .CODE
  695. ByteToBitString  proc        ; al has the number
  696.     mov     cx,8             ;called with edi set to offset of string
  697.     dec     edi
  698. bb0:inc     edi
  699.     shl     al,1             ;move most significant bit to carry flag
  700.     jc      bb1              ;if set copy '1'
  701.     mov     byte ptr [edi],'0'       ;else copy '0'
  702.     jmp     bb2
  703. bb1:mov     byte ptr [edi],'1'
  704. bb2:loop    bb0
  705.     ret
  706. ByteToBitString  endp
  707.  
  708. ENDIF
  709.  
  710.