home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / hookkbsm.zip / DOSWIN32.MAC < prev    next >
Text File  |  1993-07-28  |  22KB  |  711 lines

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