Author Topic: MasmBasic  (Read 153344 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #360 on: December 29, 2016, 01:03:01 PM »
It's not a bug, it's a feature :P

Seriously: MbGuide.rtf is a special document, it will only minimise if you try close it. But if you close it while it is minimised, it will indeed close (besides, it will also close if no other docs are open in RichMasm).

The reason for this special behaviour is that it also serves as "F1 help". Select a keyword, then hit F1:
- if it's a MasmBasic keyword like Print, the paragraph on Print will be displayed in MbGuide.rtf
- if it's not found in MbGuide.rtf, e.g. CreateWindowEx, RichMasm will pass on the request to the program that follows in \Masm32\MasmBasic\Res\menus.ini, i.e. Win32.hlp:

Code: [Select]
[&Help]
&Basic,\masm32\MasmBasic\MbGuide.rtf#Mb
&WinHLP32,\Masm32\RichMasm\Help\WIN32.HLP

Thus, you get most of the time the help you expect, simply by selecting the keyword and hitting F1.

Note that for the MasmBasic keywords, about 200, RichMasm has another mechanism: Hover over the keyword, e.g. GetFiles, until the mouse cursor turns into a question mark. Then right-click (I'm afraid this is case-sensitive, so getfiles will work only with F1).

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Printing the content of an edit control on paper
« Reply #361 on: January 05, 2017, 01:12:48 PM »
Just found a lengthy article on Printing text in Win32 can be a little complicated posted by Paul Brennick over 8 years ago - I wish I had seen it earlier, it would have saved me a lot of work :(

Anyway, here is a simple method to print the content of a RichEdit control. This snippet reads a file from the commandline, and if you hit Ctrl P, its contents get printed - not in the sense of console print, but in the sense of: on real paper. Here is the source:

include \masm32\MasmBasic\Res\MbGui.asm      ; download (version 5 January 2017 or later)
  GuiControl MyEdit, "RichEdit"             ; create a RichEdit control
  If_ wExist(wCL$()) Then <SetWin$(hMyEdit)=wFileRead$(wExist$)>
Event Key
  If_ KeyCtrl && (VKey==VK_P || VKey==-VK_P) Then <MsgBox 0, Str$("%i pages printed", PrintRtf(hMyEdit, 2)), "PrintRtf:", MB_OK>
GuiEnd


Full project attached. The PrintRtf() macro needs a handle to a RichEdit control, and takes optional parameters as follows (excerpt from \Masm32\MasmBasic\MbGuide.rtf):

 - if text is selected, then only the selection will be printed
 - optional second arg: 0=use default printer, 1=use once the printer dialog, 2=use it always
 - optional: margins in mm, e.g. void PrintRtf(hMyEdit, 0, 20, 20, 15, 20)       ; left, top, right, bottom
 - printer settings like orientation etc are kept for the program's duration

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Download & Unzip
« Reply #362 on: January 11, 2017, 12:42:48 PM »
include \masm32\MasmBasic\MasmBasic.inc      ; download (version 11 January 2017 required)
  Init
  UnzipInit "http://www.terraspace.co.uk/hjwasm217_x86.zip"
  .if Sign?
      Print eax            ; print an error message
  .else
      For_ ecx=0 To edx-1      ; #files returned in edx
            mov esi, Files$(ecx)
            .if Rinstr(esi, "/")     ; zipfiles use forward slashes
                  xchg eax, esi      ; we don't display the full path
                  inc esi
            .endif
            PrintLine Str$(GfSize(ecx)), Tb$, GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$, esi
            .if Instr_(esi, ".pdf", 1)
                  UnzipFile(ecx, Cat$(Left$(MbExeFolder$)+":\Masm32\bin\"))
                  ShEx Cat$("\Masm32\bin\"+esi)
            .endif
      Next
      UnzipExit
  .endif
EndOfCode

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Bugfix for Recall
« Reply #363 on: January 27, 2017, 10:30:53 AM »
With certain types of Unicode text files, Recall added garbage to the last string read. This is fixed with MasmBasic version 27 Jan 2017 - please reinstall. The following will work properly now:

include \masm32\MasmBasic\Res\MbGui.asm      ; download
  Recall "http://www.webalice.it/jj2006/DemoChinese.dat", L$()
Event Paint
  For_ ct=0 To L$(?)-1
      GuiText 7, ct*16+7, Str$("# %i ", ct+1)
      GuiText 90, ct*16+7, L$(ct)
  Next
GuiEnd


The snippet above downloads the text from my personal website. Here is a variant where Chinese text is used in $Data statements:

GuiParas equ "A Chinese Poem", x300, y70, w300, h125, bRgbCol(255, 255, 222)
include \masm32\MasmBasic\Res\MbGui.asm
$Data 月夜
$Data 霜风呼呼地吹着,
$Data 月光明明地照着。
$Data 我和一株顶高的树并排立着
$Data 却没有靠着  。
Read poem$()            ; translate $Data elements to a string array
Event Paint
  For_ ct=0 To poem$(?)-1
      GuiText 7, ct*16+7, Str$("# %i ", ct+1)      ; display the array elements
      GuiText 60, ct*16+7, poem$(ct)
  Next
GuiEnd


The screenshot shows how it looks like in RichMasm and in the little window created by the above code.
Projects attached, feedback welcome of course.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #364 on: February 01, 2017, 10:40:11 AM »
Update 1 February fixes two bugs:
1. One minor bug with Chr$("The letter is ", reg32): if reg32 was edi, the displayed letter was wrong. This works now (attached):

GuiParas equ "Key events only", x50, y50, w100, h60, s0
include \masm32\MasmBasic\Res\MbGui.asm
GuiControl MyStatic, "static"
Event Key
  SetWin$ hMyStatic=Chr$("You pressed ", VKey)            ; requires MasmBasic of 1 February 2017
GuiEnd


2. Val() and MovVal() returned -127 (error) in edx for the string 0 if there was text after the zero delimiter, e.g. sometext db "0", 0, "more text"

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
FindProcess
« Reply #365 on: February 08, 2017, 02:48:59 AM »
New FindProcess() function:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  .if FindProcess("Explоrer.exe")
      Inkey Str$("FindProcess returned ID %i\n", [eax.PROCESSENTRY32.th32ProcessID])
  .else
      Inkey "Process not found, error: ", Err$()
  .endif
EndOfCode


Attached a demo: Extract all files to a folder and launch first Explorer.exe (don't close the MsgBox), then the FindProcessDemo.exe

The macro is still based on Tim's example, although I managed to bring it down to exactly 80 bytes, using three (!) times the extremely old xchg instruction :biggrin:

Don't worry, the explorer.exe won't do any harm to your machine. Really :P
You can see it in Olly if you don't trust me; or look at Jotti's scan results
Sorry, no manifest, no vcb, "0/18 scanners reported malware" ... although, an intelligent AV should indeed shout foul 8)

EDIT: Explorer source added
« Last Edit: February 09, 2017, 06:51:05 AM by jj2007 »

anta40

  • Member
  • ***
  • Posts: 293
Re: MasmBasic
« Reply #366 on: February 16, 2017, 01:01:21 PM »
Pardon my ignorance. How to quit the RichMasm gracefullly? 
I assume you need not to use the Task Manager :redface:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #367 on: February 16, 2017, 07:07:29 PM »
Hit Alt F4
« Last Edit: February 22, 2017, 01:39:54 AM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Missing feature
« Reply #368 on: February 22, 2017, 01:41:18 AM »
For a while, RichMasm had forgotten how to display tooltips :(
Fixed with version 21 Feb 2017 - please reinstall.

an intelligent AV should indeed shout foul 8)
Interesting that nobody asked why... check the filename Explorer.exe very, very carefully. You may find out that the o is not the usual one. The whole AV battery at Jotti's found nothing to complain, which confirms my theory that they cooperate closely with the malware scene. It's called a "business model" :P

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #369 on: February 25, 2017, 02:26:51 PM »
Since full Unicode support was introduced some days ago, RichMasm had a problem with commandline arguments: If there was e.g. an OPT_Arg1 test.gif in the text, it created files named myname.exe test.exe instead of myname.exe

Fixed with MasmBasic update of 25 February, please reinstall

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #370 on: March 01, 2017, 12:31:49 PM »

LordAdef

  • Member
  • ***
  • Posts: 264
Re: MasmBasic
« Reply #371 on: March 02, 2017, 06:10:59 PM »
Hi JJ,

I wrote this little prog for my Ascii game. It compresses the txt file even more than I got the last time (original= 89.999, new size= 4.323).

I´s all good but I have a question.

I´m using (for the first time) the Switch case MACRO from MasmBasic (masm32 didn´t like how I did it):

Quote
Quote
   ;========== FILTER UNWANTED CHARS ====================
          xor edi, edi      
     filter:
           mov   bl, BYTE Ptr  [esi + edi]
      Switch_ bl
      Case_ '='
         mov bl, " "
      Case_ 60, 62
         mov bl, '@'                        ; chars < , > (bombers)
      Endsw_
      
   add    edi, 1               ;add counter
   cmp   edi, tLen                ;end of file?
   jnz     filter   

All good except from one thing: My file got 23kb fatter with MasmBasic. 26kb as opposed to 3kb with masm32rt.
Am I missing something?

By the way, check this colour set up, it´s really nice to work with.
Cheers,
Alex

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #372 on: March 02, 2017, 08:52:11 PM »
All good except from one thing: My file got 23kb fatter with MasmBasic. 26kb as opposed to 3kb with masm32rt.

It's the 20k overhead of common functions like e.g. array handling. In exchange, you get interesting stuff like the Recall and Store pair, or, most important, the deb macro ;)


Quote
By the way, check this colour set up, it´s really nice to work with.

Looks nice indeed.

Btw, compliments, you are making big progress. Coding RLE in assembler is not a beginner's job :t

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #373 on: March 03, 2017, 06:58:34 PM »
Update 3 March:
- RichMasm works again as it should under Windows XP (F6 used to build code, but it wouldn't run it...); there were no problems under Win7 and Win10
- ComCtl32$() takes now an optional format string:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Inkey ComCtl32$("This program uses ComCtr32.dll version %3f\ncheck your manifest if you expected a higher version")
EndOfCode


Without a manifest, you will see the old pre-XP version of the common controls dll:
Code: [Select]
This program uses ComCtr32.dll version 5.82
In RichMasm,
- go to the end of the file
- click on menu AutoCode, Resources: manifest (this inserts a Rsrc section, including a manifest)
- hit F6 again to see
Code: [Select]
This program uses ComCtr32.dll version 6.16
As mentioned in the Manifests in 64-bit land thread, the same manifest works also for 64-bit assembly. Even the 32-bit example that uses 64-bit code works fine with this manifest.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7740
  • Assembler is fun ;-)
    • MasmBasic
FileProp$() array
« Reply #374 on: March 06, 2017, 01:01:38 PM »
Update 6 March brings a new feature: the FileProp$() array.

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Print "Searching ", ExpandEnv$("%ProgramFiles%"), " ..."
  GetFiles ExpandEnv$("%ProgramFiles%\ms*.exe|ms*.dll")      ; limit to all executables starting with ms
  deb 4, "** files found", eax
  For_ ct=0 To Min(999, eax-1)            ; max 1000 files
            mov ecx, Files$(ct)
            GetFileProps ecx
            .if FileProp$(?)>1            ; more than one file property found
                  .if Rinstr(ecx, "\")
                        inc eax            ; put eax after the \
                        xchg eax, ecx            ; we don't show the full path
                  .endif
                  Print ecx            ; the filename
                  PrintLine At(40) FileProp$(FileDescription)
            .endif
  Next
  PrintLine CrLf$, "Finally, all properties of the current file:"
  GetFileProps            ; no args = current file
  For_ ecx=0 To FileProp$(?)-1
      Print Str$("%_i  ", ecx), FilePropName$(ecx)
      PrintLine At(30) FileProp$(ecx)
  Next
  Inkey "ok?"
EndOfCode


Typical output:
Code: [Select]
Searching C:\Program Files (x86) ...
** files found      eax             630
msvcp60.dll                             Microsoft (R) Visual C++
msvcp71.dll                             Microsoft® Visual Studio .NET
msvcr71.dll                             Microsoft® Visual Studio .NET
msvcp80.dll                             Microsoft® Visual Studio® 2005
msvcr80.dll                             Microsoft® Visual Studio® 2005
msvcp71.dll                             Microsoft® Visual Studio .NET
msvcp80.dll                             Microsoft® Visual Studio® 2005
msvcr71.dll                             Microsoft® Visual Studio .NET
msvcr80.dll                             Microsoft® Visual Studio® 2005
msvcp71.dll                             Microsoft® Visual Studio .NET
msvcr71.dll                             Microsoft® Visual Studio .NET
MSVCP60.DLL                             Microsoft (R) Visual C++
msvcrt.dll                              Microsoft (R) Visual C++
MSDEUI.DLL                              Microsoft Data Environment 1.0
MSADDNDR.DLL                            AddInDesigner Object Library
MSDE.DLL                                Microsoft Data Environment 1.0
MSDERUN.DLL                             Microsoft Data Environment Runtime 1.0
MSHTMPGD.DLL                            DHTMLPageDesigner Object Library
MSHTMPGR.DLL                            DHTMLPageDesigner Object Library
MSWCRUN.DLL                             WebClass Runtime Object Library
MSOEURO.DLL                             Microsoft Office 2003
mshwgst.dll                             Microsoft® Windows® Operating System
mshwLatin.dll                           Sistema operativo Microsoft® Windows®
MSPFLTRS.DLL                            Microsoft Office Document Imaging
...
MSSP7SW.DLL                             Natural Language Components
mssp7tr.dll                             Natural Language Components
msoe.dll                                Microsoft® Windows® Operating System
MSOERES.dll                             Sistema operativo Microsoft® Windows®

Finally, all properties of the current file:
 0  Lang                      080904B0
 1  Comments                  This is a comment
 2  InternalName              Internal name
 3  ProductName               Jochen's Assembly Tools Collection
 4  CompanyName               MasmBasic
 5  LegalCopyright            © 2017 Jochen@Masm32
 6  ProductVersion            Release version 6 March 2017
 7  FileDescription           Testing FilePropDemo
 8  LegalTrademarks           ?
 9  PrivateBuild              ?
10  FileVersion               1.0
11  OriginalFilename          FilePropDemo
12  SpecialBuild              ?

Demo attached. Open in RichMasm, hit F6 to build it. Remove the "ms" in GetFiles to get all executables 8)