The MASM Forum

Projects => MasmBasic & the RichMasm IDE => Topic started by: jj2007 on April 28, 2016, 10:09:34 PM

Title: A guide to the RichMasm editor
Post by: jj2007 on April 28, 2016, 10:09:34 PM
When you install MasmBasic (http://masm32.com/board/index.php?topic=94.0) (a library that allows to use Basic syntax in assembler), the first thing you'll see after clicking OK is the file MbGuide.rtf in MasmBasic's editor called "RichMasm", a special editor for working with assembler source code.

To see your first "Hello World" program running, simply hit F6.

RichMasm has been designed for long sources, and concentrates on effective navigation rather than on beauty and/or abundance of features. The package includes a number of easy-to-use "skeletons", including dll and library examples.

On a green background, some simple instructions to build your first Hello World are shown.

In the right half of the screen, you can click into a listbox with "found matches", in this case: all ca. 500 occurrences of the Find string _Mb (an internal code to identify help topics). For example, if you change the string to _Mb*file and hit Enter, the find box will contain all 19 help entries dealing with files. The wildcard * means "find a line that contains both strings"; the string push eax*****pop would mean "find a line that contains push eax and has a pop on the same line or within the next 4 lines".

To the right, there are also a few bookmarks; you can click into them to jump e.g. to the "StringToArray" section. Bookmarks are defined by selecting a (meaningful) text, e.g. start: or Parser proc, and hitting Ctrl D. In contrast to so-called "bookmarks" in other editors, RichMasm bookmarks will be saved with the text, so that you can work with them next time you open the document. Press Alt K to toggle between keys and bookmarks view.

Another way to navigate in the text are the left and right arrows in the upper right corner: The document's history is stored with the source, and by clicking on the left arrow, you can go to sections that you edited earlier. Hitting the Alt Left or Alt Right keys will do the same.

To explore the menus, please go to the top of MbGuide.rtf and left-click on try 90+ snippets as shown below:
(http://www.jj2007.eu/pics/RmGuide.jpg)

A new document opens, MbSnippets.asc.
- Hover over the File menu, it will open without clicking:

(http://www.jj2007.eu/pics/RmMenu1.jpg)

As usual, Open, Save, Save as are on top; what you will most frequently need is New Masm source, the F6 and F7 keys, the Guide to MasmBasic, and the recent files list. Hopefully, you will never need the Last good version entry 8)

Some notes:

- New Masm source opens the file Template.asc; click on any link to "create a new project" (hint: "MessageBox" in the upper left corner opens a simple Hello World with really boring grey on black colours). Just edit according to your needs. When you try to save your work, you will be prompted to choose a new name, i.e. you are not allowed to overwrite the template.

- The yellow area "to build any"... on top is an optional extra window that serves to keep a portion of the document visible independently of the current edit position. Imagine you have a structure defined somewhere near the top, and you'd like to see the definition while working with it near the end of the document; just select the lines you want to see and press Ctrl F12 (if nothing is selected, the window disappears).

- The word Init is selected. If you hit F6 (=build & run), RichMasm will search backwards to "include..." and forward to either end start or EndOfCode, and if they are present, it will conclude that user wants to build only the section that contains Init. The whole document has 94 such "snippets", you can build and run them all either by selecting Init by hand, or by clicking into the "94 matches" listbox and hitting F6.

- In the upper right corner under "Find:", the text L1200... indicates Line1200, Column 3, +4 characters selected, 73d is the decimal Ascii code of the selected "I", while 49 6E 69 74h is the hexadecimal representation of Init.

- Now hover over the Edit & Format menu:
There are a number of formatting options, like colours, tabs and fonts, plus functions for exporting selected text. You will need the F4 (comment) key fairly often; when selecting several lines of text, the whole block gets commented out. Pressing F4 again turns comments into code, and in addition colours MasmBasic commands in blue, while push/pop pairs are formatted in red, for obvious reasons.

Hint for those who are scared of coloured code: Press Ctrl A (select all), then twice Ctrl E. The whole text will be black.

(http://www.jj2007.eu/pics/RmMenu2.jpg)

- Finally, the menus System & Plugins, Help and AutoCode can be defined in \Masm32\MasmBasic\Res\menus.ini:
 
(http://www.jj2007.eu/pics/RmMenu3.jpg)

Note that the help files, where technically possible, receive the currently selected text for jumping to their dedicated help page.

Here is an example of the output window, which can be toggled pressing the F7 key:

(http://www.jj2007.eu/pics/RmOutput.jpg)

The code contains an error, so when hitting F6, RichMasm highlights the error message in the output window and jumps to the error line in the main edit window.
Title: Re: A guide to the RichMasm editor
Post by: satpro on April 30, 2016, 05:01:39 AM
GREAT post jj.  Keep 'em coming.
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on April 30, 2016, 08:04:20 AM
Thanks, satpro ;)

One element of the RichMasm philosophy is that a "project" doesn't need to be distributed over a dozen tiny little files. If possible, why not use one single file? Why, for example, should we use a separate resource file, if it can be integrated into the main source? Attached a simple example - a single *.asc file. Open it in RichMasm, edit a resource string (e.g. change "Welcome" to "Good night") and hit F6.

(http://www.jj2007.eu/pics/RmRsrc.jpg)

As you can see in the screenshot, the AutoCode menu has an entry "Resource section". Just put the cursor behind GuiEnd (or end start/EndOfCode, wherever your source ends), click this entry and voilà, you have now an editable resource section. Every little change that you make can immediately be tested, you don't even have to save first (but do save it when you feel the code is OK 8)).
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on May 20, 2016, 11:29:21 AM
As of version 19 May 2016 (http://masm32.com/board/index.php?topic=94.0), RichMasm can assign keystrokes to menu functions:

- hover over a menu title, e.g. System & Plugins
- move down until the desired function is highlighted, e.g. "Find on disk" (a plugin)
- hold Shift and right-click into the highlighted menu item
- the menu closes, and you see "Press a key" in the status bar in the upper right corner
- press a key, e.g. f

Afterwards, the key sequence F12, f will do exactly what the menu would do. Hitting F12 twice will toggle between the list of shortcut keys and your bookmarks (try also pressing Alt K repeatedly).

Note this is saved immediately, and your shortcuts will not be overwritten by a re-installation of MasmBasic.
(http://www.jj2007.eu/pics/RmMenuF12.png)
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on June 17, 2016, 12:12:05 PM
RichMasm beta: extract to \Masm32\MasmBasic\RichMasm.exe (you might rename the old one before).
Attachment removed, the beta has been promoted and is now included in the normal release (http://masm32.com/board/index.php?topic=94.0) :icon_cool:

Main feature is a much speedier (20*) load of files in the megabyte range. The culprit was the EM_LINEINDEX message. You may test the difference with the F9 key, which displays a file info message:
QuoteFile info (when opened):
17.06.2016, 03:14:35, 1720890 bytes in 29146 lines

Loading MasmBasic.asc took 0.70 seconds

Other changes:
- in case of assembly errors, the jump to the offending line is now more precise for large files
- searching has become much faster; for example, finding 3483 times eax in the 18,000 lines of the RichMasm source takes now about 50ms on the i5, counted from hitting Return to seeing the listbox; in short: it's immediate
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on July 01, 2016, 09:22:42 AM
With RichMasm, you don't normally need any options - most of the \Masm32\examples sources, for example, build just fine by hitting F6. The editor detects fairly accurately if your source is a GUI application (/subsystem:Windows) or a console program. And yet, you can set quite a number of options. They consist of an uppercase OPT_SomeKeyword and are embedded in the source. Thus, they are available also when you copy the file to another computer, or you post it in the forum.

Here is a loose collection. In practice, OPT_Arg1, OPT_Wait and OPT_Icon are the most frequently needed options.

OPT_Assembler   ml                      ; mlv9, Jwasm, asmc, ... whatever is in \masm32\bin\
OPT_Linker      link                    ; polink, ...
OPT_Olly        1                       ; 0...9: use \masm32\OllyDbg\OLLYDB1.EXE (default is OllyDbg.exe)
OPT_DebugA      /Fl /Sn                 ; add items to the assembler commandline
OPT_DebugL      /verbose xfile.obj      ; add items to the linker commandline
OPT_Debug       1                       ; enable the heap debugger (useful if you suspect heap corruption; console only)
OPT_Susy        WINDOWS                 ; force subsystem: windows or console (but autodetect rarely fails)
OPT_Out         somepath.exe            ; force a different output file
OPT_Run         dosomething.exe with args
OPT_Res         someresourcefile        ; default are rsrc and ThisFile; no .rc extension please
OPT_Icon        smiley                  ; see \Masm32\MasmBasic\icons
OPT_Arg1        pass some arguments to the exe
OPT_Arg2        pass even more arguments
OPT_DelDef      0                       ; do not delete def files
OPT_DelExp      0
OPT_DelLib      1
OPT_DelPdb      1
OPT_DelLst      1
OPT_DelObj      1
OPT_DelTmp      0                       ; do not delete Tmp_File.asm
OPT_DelRes      1
OPT_DelBatch    1
OPT_Verbose     1                       ; show related files after building
OPT_BatA   SayHello                      ; run any bat or exe, e.g. SayHello.bat after assembling
OPT_BatL   congrats                      ; run any bat or exe, e.g. congrats.exe after linking
OPT_Wait        0                       ; do not wait for a keypress (useful e.g. for Windows apps with subsystem console)
OPT_Tmp2Asm     0                       ; create MyFile.asm
OPT_Tgt         dll                     ; default is exe, otherwise dll or rml aka RichMasm Lib


When they appear inside the code, use ; OPT_something, or
if 0
  OPT_Wait 0
  OPT_Susy Console
endif


Note that when building a project with RichMasm, all options become temporary environment variables. You can use them in your code with Masm's built-in @Environ macro, for example:
; OPT_Arg1 These are 'some arguments'
tmp$ CATSTR <Print "Arg1=[>, @Environ(oArg1), <]">
tmp$
Title: 64-bit assembly with RichMasm
Post by: jj2007 on August 30, 2016, 10:40:40 PM
Step-by-step instructions to build 64-bit assembly programs:
1. install the latest MasmBasic version from here (http://masm32.com/board/index.php?topic=94.0)
2. after clicking Accept & Install, you'll see the MasmBasic help file (light green background)
3. select Init below the -- same as 64-bit code: -- line
4. hit F6 to see your first 64-bit program build and run

More examples are in menu File/New Masm source. Note that the deb macro has some limitations, as compared against its big 32-bit brother (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1019). Inter alia, it works only in console applications:

deb 1, "Testing the debug macro:", rax, rcx, rsi, xmm0, xmm1, ST(0), ST(1), ST(2), ST(3)

Let me know if you run into any trouble (AntiVirus, ...) 8)
Title: Adding db " and ", 0
Post by: jj2007 on November 26, 2016, 11:39:29 AM
With MasmBasic version 26 Nov 2016 (http://masm32.com/board/index.php?topic=94.0), RichMasm has a new feature, inspired by Hutch:

Imagine some boring
text that you would
like to turn into a
Masm-readable bunch
of db declarations.


- select the text
- hit Alt R (replace)
- in the edit control in the upper right corner, enter db "]#[", 0
- hit Enter to confirm
- click Yes in the MsgBox and see this:

db "Imagine some boring", 0
db "text that you would", 0
db "like to turn into a", 0
db "Masm-readable bunch", 0
db "of db declarations.", 0


The ]#[ marker is a placeholder for the line content. For adding text only to the left, use e.g. $Data]#[ (i.e. no text on the right).

You may use this for a new variant of the Data (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1290) macro with a leading $ sign, meaning "no quotes needed to recognise this as a string":

include \masm32\MasmBasic\MasmBasic.inc
$Data Imagine some boring
$Data text that you would
$Data like to turn into an
$Data easy-to-use array of
$Data strings for display.

  Init
  Read my$()
  For_ ecx=0 To eax-1
      PrintLine my$(ecx)
  Next
  Inkey "... simple, right?"
EndOfCode


Output:
Imagine some boring
text that you would
like to turn into an
easy-to-use array of
strings for display.
... simple, right?
Title: Integrated debugging
Post by: jj2007 on January 23, 2017, 11:59:38 PM
Wouldn't it be nice if you could hit F6 to build your project, and see immediately the debugger?

include \masm32\include\masm32rt.inc ; plain Masm32 for the fans of pure assembler

.code ; make sure Olly sits in \Masm32\OllyDbg\ollydbg.exe
start:
  mov eax, chr$("Welcome to OllyDbg") ; you will see this text in Olly
  mov eax, chr$("Hit F9 to advance to the breakpoint")
  xor ebx, ebx ; argument counter
  .While 1
mov esi, cmd$(ebx)
int 3 ; set a breakpoint for Olly
.Break .if ecx!=1 ; read the Masm32 help on cmd$() to understand why
print "arg #"
print str$(ebx), ":", 9
print esi, 13, 10
inc ebx
  .Endw
  inkey
  exit

end start

OPT_Symbols 1 ; create symbols for OllyDbg
OPT_Arg1 "Hello Masm32 Forum"
OPT_Arg2 what's going on today?


When opened in RichMasm, the snippet (attached) builds as console application when hitting F6, but instead of running the exe directly, OllyDbg will be launched. Hit F9 and see what happens at the breakpoint.

If you comment out the breakpoint: ; int 3, RichMasm understands that you don't want to debug, and launches the executable normally.

Note also that for console applications, RichMasm takes care to activate OllyDbg instead of the console output window - a minor feature maybe, but if you have to activate the debugger a hundred times because the console is always in front, you may start to appreciate RichMasm's little service ;-)
Title: Plug-ins for the RichMasm editor
Post by: jj2007 on February 01, 2017, 10:25:46 AM
RichMasm has a comfortable plug-in interface, giving access to e.g. the selected text, the handle to the RichEdit control, etc.

Attached are two examples:
- FindOnDisk allows to quickly search files for two search patterns
- CompileBasic is for compiling sources written in various BASIC dialects, plus some C/C++ variants.

Both need to be extracted to \Masm32\MasmBasic\Plugins
After a restart of RichMasm, they appear in System & Plugins menu.
Title: Working with Unicode file names
Post by: jj2007 on February 11, 2017, 12:42:37 PM
Most people never need filenames in exotic languages, but sometimes it might be necessary.
Attached is an example of a source with an Arabic name and an Arabic MsgBox.
Open it in RichMasm (version 11 February 2017 or later (http://masm32.com/board/index.php?topic=94.0)) and hit F6 to build the demo.
Title: Re: A guide to the RichMasm editor
Post by: mabdelouahab on February 11, 2017, 06:21:24 PM
Hi jj
Quoteyou need \masm32\bin\HJWasm32.exe ...
Why?
I have Windows 8.1 X64 Arabic, And I use HJWasm64.exe To create 32/64 application
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on February 11, 2017, 08:50:28 PM
Hi mabdelouahab,

Probably, RichMasm saw a very old ML.exe in your \bin and suggested to download & install HJWasm32.exe. You can indeed use any MASM-compatible assembler except the old one (6.14) that comes with the Masm32 package.

In the example I posted above, there are OPT_* lines. Change them according to your needs, for example:
OPT_Assembler mlv615
OPT_Linker linkv614


Assuming, of course, there are \Masm32\bin\mlv615.exe and \Masm32\bin\linkv614.exe on your disk. If there are no OPT_* lines, or they are disabled with e.g. OxPT..., RichMasm uses HJWasm32 and polink.

I attach a 64-bit example, with OPT_Linker linkv10 (version 6.14 and polink won't work with an Arabic filename and 64-bit code)
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on February 14, 2017, 12:43:44 PM
Update 14 Feb 2017: RichMasm (http://masm32.com/board/index.php?topic=94.0) works now also with Unicode file names and 64-bit code, see attachment. The restrictions regarding assemblers and linkers are no longer valid, i.e. it works fine with ML, HJWasm32, AsmC and various linkers including polink.

include \Masm32\MasmBasic\Res\JBasic.inc      ; ## console demo, builds in 32- or 64-bit mode with ML, AsmC, JWasm, HJWasm ##
  Init            ; OPT_64 1      ; put 0 for 32 bit, 1 for 64 bit assembly
  PrintLine Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format")
  wMsgBox 0, 'This is a "text" for a Unicode MessageBox', "Title:", MB_OK
  wMsgBox 0, "Это окно с сообщением", "Это название:", MB_OK
  wMsgBox 0, "هذا هو مربع الرسالة.", "أهلا بك", MB_OK
  wMsgBox 0, '这是一个消息框。', "这是一个标题:", MB_OK
EndOfCode
Title: Re: A guide to the RichMasm editor
Post by: mabdelouahab on February 14, 2017, 04:23:46 PM
hi JJ, I've downloaded Update .
How do I deal with this?

** Start C:\Masm32\MasmBasic\Res\bldallRM.bat **
*** user-defined OPT_xx variables: ***
Page de codes activeÿ: 65001
**** 64-bit assembly ****

OPT_Arg1:
OPT_Arg2:
OPT_Out:  Tmp_File.exe
OPT_Res:  Tmp_file


*** Assemble, link and run صندوÙ, رساÙ,,Ø© ***

*** Assemble using \masm32\bin\HJWasm32 /c /Zp8 -win64 tmp_file.asm ***
HJWasm v2.17, Dec  5 2016, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

Error A2106: Cannot open file: "tmp_file.asm" [ENOENT]
*** Assembly Error ***
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on February 14, 2017, 08:09:42 PM
Quote from: mabdelouahab on February 14, 2017, 04:23:46 PMHow do I deal with this?
Error A2106: Cannot open file: "tmp_file.asm" [ENOENT]

Sorry for that, mabdelouahab :icon14:

It works for me with Win7-64 and Win10, Italian versions. Now the question is why RichMasm can't open (or can't find) your tmp_file.asm :(

Does your folder name contain non-Ansi characters? If yes, then version 14 Feb 2017 (http://masm32.com/board/index.php?topic=94.0) should work for you. I just uploaded it, there was a SetCurrentDirectoryA that made the assembly fail if the path contained "true" Unicode. Please let me know if it works now.

Anybody else having this kind of problems?
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on February 15, 2017, 07:44:48 PM
Rock solid here JJ.

By the way, did you notice this line in his report:

Quote*** Assemble, link and run صندوÙ, رساÙ,,Ø© ***

Title: Re: A guide to the RichMasm editor
Post by: jj2007 on February 15, 2017, 10:42:39 PM
Quote from: LordAdef on February 15, 2017, 07:44:48 PM
Rock solid here JJ.

Thanks :biggrin:

QuoteBy the way, did you notice this line in his report:

Quote*** Assemble, link and run صندوÙ, رساÙ,,Ø© ***

Yes indeed, RichMasm used Ansi filenames - call it a bug. The latest version (15 Feb (http://masm32.com/board/index.php?topic=94.0)) handles it correctly (F9 produces the big MessageBox):

(http://www.jj2007.eu/pics/BuildUnicodeFiles.png)

Project attached, needs MasmBasic 15 Feb 2017 (http://masm32.com/board/index.php?topic=94.0).
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on March 21, 2017, 05:59:50 AM
The attached beta has a new version of RichMasm allowing, inter alia, to translate hyperlinks very directly into source code - see second attachment.

GuiParas      equ "ToolTips for the SysLink control", w300, h80
include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl GetHelp, "syslink", h0+20, "Click here (http://masm32.com/board/index.php?topic=94.0) to download MasmBasic, or here (http://www.jj2007.eu/MasmBasicQuickReference.htm) for online help"
  GuiControl VisitMoscow, "syslink", y0+20, h0+40, "Get info on Moscow (http://xn----ctbgb7bh2ave3d.xn--p1ai): Развлечения, история, музеи, рестораны-кафе, гостиницы, информация"

Event Command
  .if NotifyCode==NM_CLICK && (wParam==GetHelp || wParam==VisitMoscow)
      wMsgBox 0, Link$(), "Open this page?", MB_OKCANCEL
      If_ eax==IDOK Then <wShEx Link$()>
  .endif
GuiEnd
Rsrc
#include "resource.h"
IDI_APPLICATION ICON      "\\Masm32\\MasmBasic\\icons\\Smiley.ico"
01 RT_MANIFEST      "\\Masm32\\MasmBasic\\Res\\XpManifest.xml"
Rsrc

This is how it looks in the editor:(http://www.jj2007.eu/pics/SysLinkDemo.png)

EDIT: Beta removed, the current version (http://masm32.com/board/index.php?topic=94.0) has the new features now.
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on May 01, 2017, 09:47:06 AM
As Edsger Wybe Dijkstra (https://en.wikiquote.org/wiki/Edsger_W._Dijkstra) once noted,
QuoteIt is practically impossible to teach good programming to students that have had a prior exposure to Visual Studio: as potential programmers they are mentally mutilated beyond hope of regeneration.

For these poor beings, who spread their PROTOs and MACROs over a dozen tiny files in order to call their mess a "project", there is HELP now: The attached RichMasm beta extends the search feature (select a word, hit F3) to files that are INCLUDEd in the source.

This is limited to those files that are included by an UPPERCASE INCLUDE at the moment when the file was opened. So to test it, change the desired include to INCLUDE, then save and reload the file:

include \masm32\MasmBasic\MasmBasic.inc
; include \masm32\include\masm32rt.inc
INCLUDE mymacros.inc
INCLUDElib msvcrt.lib

Here, only mymacros.inc is included in the search.
Title: Re: A guide to the RichMasm editor
Post by: TWell on May 01, 2017, 12:41:44 PM
QuoteIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.
At that time BASIC was weak with subroutines and structured programming. Quick Basic and Turbo Basic correct some problems.

Asm programmers needs those little files when creating libraries as ml don't have support for COMDAT.

EDIT: forgot to say [h]jwasm and asmc have support for it.

A good IDE's have a 'Find in files' feature, like poide.exe has.
Title: Re: A guide to the RichMasm editor
Post by: hutch-- on May 01, 2017, 01:53:25 PM
I wonder what capacity the COMDAT (common data) has that cannot be done with MASM's "PUBLIC" keyword. It is routine to make something PUBLIC in MASM and access it from other modules.
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on May 02, 2017, 03:00:21 AM
Quote from: TWell on May 01, 2017, 12:41:44 PMA good IDE's have a 'Find in files' feature, like poide.exe has.

Pelle's IDE is among the better ones, but the "find in files" feature is a joke. Check out the RichMasm beta to see the difference.
Title: Re: A guide to the RichMasm editor
Post by: TWell on May 02, 2017, 03:48:26 AM
I tried to download it, but Avast ate it.
So what kind of feature it should be?
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on May 02, 2017, 04:00:51 AM
Tim, bypass Avast for 10 minutes and download it. Avast is not asm community friend  :icon_redface:
Title: Re: A guide to the RichMasm editor
Post by: LiaoMi on May 02, 2017, 04:20:39 AM
Hi!

I compared the toolbar by looking at the picture in this top and noticed that only my menu is so badly displayed ... About how it looks like you can see below - https://ibb.co/bWF8Lk (https://ibb.co/bWF8Lk)
(https://preview.ibb.co/h32YmQ/masmbasic_gui.jpg)

Maybe this problem has already happened?

Thankeee!
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on May 02, 2017, 05:36:26 AM
Quote from: LiaoMi on May 02, 2017, 04:20:39 AMonly my menu is so badly displayed

The menu font is a problem indeed. One day I will have to find a solution :(

Reason is that when the Aero themes came out, the old GetWindowDC trick stopped working.

@Tim: really, can't you disable Avast for 5 minutes?? Btw Jotti shows that 16 out of 19 AVs are OK with that RM beta. (https://virusscan.jotti.org/en-US/filescanjob/lu046rsxpu) For the unpacked version, it's 18/19 OK. (https://virusscan.jotti.org/en-US/filescanjob/gudbybij3c)
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on May 02, 2017, 03:33:34 PM
Working fine here JJ
Title: Detecting and debugging heap corruption
Post by: jj2007 on May 22, 2017, 09:36:45 PM
EDIT: As discovered in the HeapAlloc vs HeapReAlloc (http://masm32.com/board/index.php?topic=7018.0) thread, the Debugging Tools for Windows used here disable the Low Fragmentation Heap (LFH). As a consequence, allocating huge amounts (100,000+) of small buffers may take several seconds.

A simple demo showing how to detect heap corruption:

include \masm32\include\masm32rt.inc ; plain Masm32

.code
txString db "Hello, this is a simple string, 50 characters long", 0
start:
  mov esi, rv(HeapAlloc, rv(GetProcessHeap), HEAP_ZERO_MEMORY, 22h) ; 22h=34 bytes, not enough for txString

  print "before doing illegal things to esi="
  print hex$(esi), 13, 10

  invoke lstrcpy, esi, addr txString ; this is commonly called "buffer overflow"
  print " after doing illegal things", 13, 10, 10, "[" ; but it works just fine, because the heap
  print esi, "]", 13, 10, 10 ; doesn't yet know that it's "corrupt" now ;-)

  print "----- OK, we are now freeing esi, and strange things will happen: -----"
  invoke HeapFree, rv(GetProcessHeap), 0, esi
  inkey "----- buffer was freed -----"
  exit

end start ; OPT_Debug 1 ; this option requires RichMasm


When hitting F6 in RichMasm (MasmBasic's IDE (http://masm32.com/board/index.php?action=unread)), you will see this output:before doing illegal things to esi=002A5920
after doing illegal things

[Hello, this is a simple string, 50 characters long]

----- OK, we are now freeing esi, and strange things will happen: -----
## HEAP[HeapCorruption.exe]:
## Heap block at 002A5918 modified at 002A5942 past requested size of 22

## HEAP[HeapCorruption.exe]:
## Invalid address specified to RtlFreeHeap( 002A0000, 002A5920 )
----- buffer was freed -----


Project attached. Let me know if it can be improved.
Title: Rich text to the forum
Post by: jj2007 on July 11, 2017, 10:37:19 PM
With MasmBasic version 11 July 2017, the formatted output has been improved: select text, hit F11, paste in a reply. Example:

include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
  if 0  ; copy the line below, then hit F6 to get the db version
        chartab                 dw "10","01","12","21","13","31"
        ; expected output:
        chartab                 db "0","1","1","0","2","1","1","2","3","1","1","3"
  endif
  Init                          ; *** translate Masm dw format to db for use with UAsm ***
  Let esi=Clip$()               ; get string from clipboard (limit is about 160k)
  lea ecx, [2*Len(esi)]         ; the byte format is longer, so we need a bigger buffer
  Let edi=New$(ecx)
  push esi
  push edi
  .Repeat
        lodsb
        If_ al=="w" Then mov al, "b"    ; dw->db
        stosb
        .Break .if !al
        .if al==34
                push [esi]
                lodsb
                movsb           ; first digit
                mov al, 34
                stosb
                mov al, ","
                stosb
                mov al, 34
                stosb
                pop eax
                stosb           ; second digit
                movsb           ; second quote
        .endif
  .Until 0
  pop edi
  pop esi
  Inkey "Before: ", esi, CrLf$, "After:  ", edi, CrLf$, "Copy to clipboard? (y)", CrLf$
  If_ eax=="y" Then SetClip$ edi
EndOfCode
Title: Re: A guide to the RichMasm editor
Post by: FORTRANS on July 12, 2017, 02:01:10 AM
Hi,

   Just for feedback, a screenshot.

HTH,

Steve
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on July 12, 2017, 04:12:43 AM
Hi Steve,

The lines are wrapped. What's your screen resolution? Mine is 1366x768, and even with enlarged fonts they are not long enough to wrap. Or did you mean something else?

Jochen
Title: Re: A guide to the RichMasm editor
Post by: FORTRANS on July 12, 2017, 05:10:38 AM
Hi Jochen,

Quote from: jj2007 on July 12, 2017, 04:12:43 AM
The lines are wrapped. What's your screen resolution?

   Usually 1024x768.  Sometimes higher, though not very often.

QuoteMine is 1366x768, and even with enlarged fonts they are not long enough to wrap. Or did you mean something else?

   Well, yes the lines wrap, but I just thought you might find it
useful to see your work on another's system.  Maybe the colors
and fonts are different for instance.  You may try to have all your
computers set up similarly.  I used to do that a while back, and
had some odd results when one of my programs was used on
someone else's computer.  (Code page different I think.)

Regards,

Steve N.
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on July 12, 2017, 05:25:26 AM
Quote from: FORTRANS on July 12, 2017, 05:10:38 AMWell, yes the lines wrap, but I just thought you might find it useful to see your work on another's system.  Maybe the colors and fonts are different for instance.

Colours and fonts look similar, but 1024x768 is indeed a bit low for today's standards. Anyway, it's the browser who decides when to wrap lines.

But I understand the problem very well. Often, pages just look garbled, OK buttons are below the visible area, etc - messy sites made by professional web developers who only made one small mistake: to assume that the user also has that great 4k screen that a decent IT professional is entitled to enjoy 8)
Title: Re: A guide to the RichMasm editor
Post by: HSE on July 12, 2017, 06:40:19 AM
Good practice is:
include \masm32\MasmBasic\MasmBasic.inc         ; download
  if 0  ; copy the line below, then hit F6 to get the db version
        chartab                 dw "10","01","12","21","13","31"
        ; expected output:
        chartab                 db "0","1","1","0","2","1","1","2","3","1","1","3"
  endif
  Init                          ; *** translate Masm dw format to db for use with UAsm ***
  Let esi=Clip$()               ; get string from clipboard (limit is about 160k)
  lea ecx, [2*Len(esi)]         ; the byte format is longer, so we need a bigger buffer
  Let edi=New$(ecx)
  push esi
  push edi
  .Repeat
        lodsb
        If_ al=="w" Then mov al, "b"    ; dw->db
        stosb
        .Break .if !al
        .if al==34
                push [esi]
                lodsb
                movsb           ; first digit
                mov al, 34
                stosb
                mov al, ","
                stosb
                mov al, 34
                stosb
                pop eax
                stosb           ; second digit
                movsb           ; second quote
        .endif
  .Until 0
  pop edi
  pop esi
  Inkey "Before: ", esi, CrLf$, "After:  ", edi, CrLf$, "Copy to clipboard? (y)", CrLf$
  If_ eax=="y" Then SetClip$ edi
EndOfCode
And everybody can to choose colors :biggrin:
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on July 12, 2017, 07:12:00 AM
Quote from: HSE on July 12, 2017, 06:40:19 AM
Good practice is:

So why do almost all IDEs and many programming sites come along with syntax highlighting? Bad practice?
Title: Re: A guide to the RichMasm editor
Post by: HSE on July 12, 2017, 08:11:17 AM
In the box is more easy to copy!!

LATER: I also have configurated 1024x768
Title: Re: A guide to the RichMasm editor
Post by: FORTRANS on July 12, 2017, 10:28:40 PM
Hi,

   BTW, if I have a choice of wrapped comments or uncommented
code, I choose having wrapped comments.  Many denizens of
this forum seem to like uncommented code though.  Maybe they
have a phobia of wrapping.  <g>

Cheers,

Steve
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on July 13, 2017, 12:36:56 AM
Quote from: HSE on July 12, 2017, 08:11:17 AM
In the box is more easy to copy!!

That was before the Mozilla "coders" decided to disable the Code: [Select] function :(

Quote from: FORTRANS on July 12, 2017, 10:28:40 PM
I have a choice of wrapped comments or uncommented code, I choose having wrapped comments.

The code box doesn't wrap them, that may look better but to read them you have to click the horizontal scroll bar. Not the best solution either :icon13:

  Recall Utf8$(wCL$()), L$()    ; translate the file supplied through the (Unicode) commandline to a text array (if the file is Unicode, the strings will be in UTF-8 format; if needed, you can get Unicode back with wRec$(L$(n)) - see also ConvertCp$)


  Recall Utf8$(wCL$()), L$() ; translate the file supplied through the (Unicode) commandline to a text array (if the file is Unicode, the strings will be in UTF-8 format; if needed, you can get Unicode back with wRec$(L$(n)) - see also ConvertCp$)
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on October 10, 2017, 02:47:44 AM
I am trying to figure out if it's worthwhile to look for the debugger paths when doing a fresh install of MasmBasic. Currently, the default paths are hardcoded (see: integrated debugging (http://masm32.com/board/index.php?topic=5314.msg63302#msg63302)) to

\Masm32\x64Dbg\release\x64\x64dbg.exe for 64-bit debugging
\Masm32\OllyDbg\ollydbg.exe for 32-bit code.

Therefore the question: Where are your debuggers located?
Title: Re: A guide to the RichMasm editor
Post by: Biterider on October 10, 2017, 04:45:27 AM
Hi
only as a hint, Visual Studio stores the debugger location here:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]


Biterider
Title: Re: A guide to the RichMasm editor
Post by: LiaoMi on October 10, 2017, 05:39:20 AM
Quote from: jj2007 on October 10, 2017, 02:47:44 AM
I am trying to figure out if it's worthwhile to look for the debugger paths when doing a fresh install of MasmBasic. Currently, the default paths are hardcoded (see: integrated debugging (http://masm32.com/board/index.php?topic=5314.msg63302#msg63302)) to

\Masm32\x64Dbg\release\x64\x64dbg.exe for 64-bit debugging
\Masm32\OllyDbg\ollydbg.exe for 32-bit code.

Therefore the question: Where are your debuggers located?

Unchangeable folder paths in this case better  :P
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on October 10, 2017, 06:03:27 AM
include \masm32\MasmBasic\MasmBasic.inc
  Init
  PrintLine GetRegVal("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug", "Debugger")
  SetReg64
  Inkey GetRegVal("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug", "Debugger")
EndOfCode


yields
"C:\Masm32\OllyDbg\ollydbg.exe" -AEDEBUG %ld %ld
"C:\Masm32\x64Dbg\release\x64\x64dbg.exe" -a %ld -e %ld

I attach the project. These are the just-in-time debuggers, should be fine :t

Btw a pretty old key: The AeDebug subkey stores user preferences for Dr. Watson and other debugging tools that run on Windows 2000 (https://technet.microsoft.com/en-us/library/cc939482.aspx)

No such key on Win10, but Olly shows up at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RADAR\HeapLeakDetection\DiagnosedApplications\ollydbg.exe  :bgrin:

Quote from: LiaoMi on October 10, 2017, 05:39:20 AMUnchangeable folder paths in this case better  :P

Why that?
Title: Re: A guide to the RichMasm editor
Post by: LiaoMi on October 10, 2017, 10:45:30 PM
Quote from: jj2007 on October 10, 2017, 06:03:27 AM

Quote from: LiaoMi on October 10, 2017, 05:39:20 AMUnchangeable folder paths in this case better  :P

Why that?

Hi,

the debugger often receives updates, sometimes there are errors that you need to debug. I have three versions, clean current release, stable version for work, and the current version with plug-ins, this package is always updated by adding plugins or changing the settings. Therefore, the exact binding for me is better  :biggrin:
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on October 11, 2017, 01:05:44 AM
Quote from: LiaoMi on October 10, 2017, 10:45:30 PMI have three versions, clean current release, stable version for work, and the current version with plug-ins, this package is always updated by adding plugins or changing the settings. Therefore, the exact binding for me is better  :biggrin:

OK, so the best solution will be to
- test if a debugger is already set in RichMasm's prefs
- if not, check for the registry key
- if there is none, see if there is *dbg*.exe inside the \Masm32 tree.

I guess that will add a few hundred bytes to RichMasm's 72kB :(
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on December 20, 2017, 10:35:37 AM
hi JJ,

Would you refresh my poor memory? How do we actually change colours? it was something like col= ....
I can't find the post.
Cheers
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on December 20, 2017, 12:51:59 PM
Hi Axel,
There should be a bubble help when you move the cursor over the Ctrl G field - you don't see it? Anyway, it's udc=... i.e. user-defined colours.
Cheers & thanks for the feedback.
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on December 22, 2017, 09:19:13 AM
Quote from: jj2007 on December 20, 2017, 12:51:59 PM
Hi Axel,
There should be a bubble help when you move the cursor over the Ctrl G field - you don't see it? Anyway, it's udc=... i.e. user-defined colours.
Cheers & thanks for the feedback.

There is one in fact! I never noticed it. But I now remember what I was looking for: the "?" trick to open the colour picker!

But thanks!
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on January 05, 2018, 08:02:46 AM
Hi Johen,

Is there any plan for future enhancements regarding Richmasm?
Cheers Alex
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 05, 2018, 08:14:39 AM
Right now I am happy with it.
Did you know that you can hit Ctrl F and type e.g. api:CreateW, Return?
Or that hitting F4 twice autoformats a whole para?
Or that Ctrl D inserts a hyperlink if there is a URL on the clipboard?
Or that \Masm32\MasmBasic\Res\Keywords.ini holds interesting info, e.g. on swi<blank> or .rep<blank>?
Or that Shift Tab on a block of selected text does not the same as Right Shift Tab?

Seriously: Do you miss something?
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on January 05, 2018, 08:49:50 AM
Thanks Johen,

Richmasm is fine as it is, seriously. There are a couple of things here and there, as it´s always the case. I could maybe write it down some of the things I would find useful based on my daily experience. Since we all use and like different things, everyone would have some different needs.

1. I use col=? all the time. But it would be nice the colour picker could save the custom colours (as of now, it keeps them as long as RM is open).
2. Concerning col=? at al, I wished there were some window buttons we can simply clic it instead of typing col=?
3. Any way .asm files could be rich edited too, as with .asc?
4. I wish it could make me coffee too!  :eusa_dance:

My question was mainly out of curiosity. You´re playing with some windows toys, I thought implementing some windows interface like buttons would be in your future plans.
Title: Re: A guide to the RichMasm editor
Post by: hutch-- on January 05, 2018, 11:25:17 AM
Alex,

I asked about the coffee machine as well but no success yet.  :P
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 05, 2018, 12:37:13 PM
Quote from: LordAdef on January 05, 2018, 08:49:50 AM1. I use col=? all the time. But it would be nice the colour picker could save the custom colours (as of now, it keeps them as long as RM is open).
2. Concerning col=? at al, I wished there were some window buttons we can simply clic it instead of typing col=?
3. Any way .asm files could be rich edited too, as with .asc?
4. I wish it could make me coffee too!  :eusa_dance:

My question was mainly out of curiosity. You´re playing with some windows toys, I thought implementing some windows interface like buttons would be in your future plans.

Hi Alex,
extract your personal beta from the attachment, then:
1.+2: Shift-click on the light blue up button to the left of "Case" (->OK for foreground, Shift OK for background colour)
3. You can misuse the .asm ending, but inside it's either rich or poor...
4. If Hutch promises to ... ehm, no blackmailing, sorry, but no coffee either 8)
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on January 05, 2018, 05:57:25 PM
NICE!!

JJ, Thanks you, really!

One extra nice feature would be a "shift F4". Instead of the current F4, shift F4 would insert a " COMMENT # code   #". So we don´t loose our formating. :t
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 05, 2018, 08:57:31 PM
Have a look at \Masm32\MasmBasic\Res\menus.ini, section [AutoCode]. If you add your own snippets, copy the file to \Masm32\MasmBasic\Res\UserDef\menus.ini - the original \Masm32\MasmBasic\Res\menus.ini gets overwritten with a new installation, but RM will load the UserDef version if it finds one.

Btw I never use COMMENT #whatever#

if 0  ; more efficient:
  This code
  is supposed to
  do something
endif

You can change it to if 1 to make it run, or even use a constant like if usedeb

Another version:
  newversion=1
  if newversion
xchg eax, ecx
  else
mov eax, ecx
  endif


If the old branch is big, I select the whole block and apply menu Edit & Format/Small font 8)
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 10, 2018, 05:50:44 AM
For RichMasm users, attached a beta that allows to use own AutoCode snippets. Extract manually as follows:
\Masm32\MasmBasic\RichMasmBeta.exe
\Masm32\MasmBasic\Res\MenusRM.ini
\Masm32\MasmBasic\Plugins\ac*.asc

The ac* files contain a description for the menus and tooltips, followed by the autocode to be inserted. Example:

#desc[MessageBox#inserts invoke MessageBox, ...]#
        pushad
        MsgBox 0, str$(eax), chr$("Title"), MB_OK
        popad

Users can add their own AutoCode, provided they sit in the MasmBasic\Plugins folder and the name fits the ac*.asc pattern.

The example above appears as follows in the AutoCode menu (of course, the #desc[menu text#tooltip text]# sequence gets skipped when you click the menu, and only the pushad ... popad gets inserted); clicking would insert a MessageBox in the line below some$():

(http://www.jj2007.eu/pics/MenusRM.png)
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on January 24, 2018, 04:44:43 AM
hi Johen,

I thought it would be a great side project to write a plug in for RichMasm. This way I could dig into MasmBasic and also contribute to Richmasm  :icon_redface:.

Would you explain how this plugin works and what can I access?
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 24, 2018, 06:55:19 AM
You are ambitious :t
There is one in the templates, third-last row, but I just discovered that it doesn't work properly. It assembles, but RichMasm doesn't recognise it as a plugin. Probably a small problem, but I will have to investigate. Tomorrow.

P.S.: Attached a version that works, but the documentation is partly wrong. Note that after the first build, you have to restart the editor to see the plugin.
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on January 24, 2018, 08:30:31 AM
I meant to start with something really 'basic', with 'masmBasic'  :biggrin:
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 24, 2018, 11:12:08 AM
I thought that was really "basic" ;)

Attached a polished version. Extract all three files to \Masm32\MasmBasic\Plugins\
These two lines show what the editor passes to the plugin:

mov ecx, piBookmarks   ; points to an array of handles
fdeb 1, "Paras received:", hRE, piHandle, piCbMain, piCbRE, piSrcType, $piContent, $Win$(piAux), $Win$(piOut), $piPath, $piOptions, $piStart, piLen, $Win$(piFind), $Win$(piReplace), piNumBM, $Win$([ecx]), $Win$([ecx+4]), piDirty

hRE   handle to the main RichEdit control
piCbMain   pointer to the plugin's WndProc hook (if set, there you get all messages from RichMasm's WndProc)
piCbRE   same but for the subclassed RichEdit control
piContent   pointer to plain text content
piAux   pointer to plain text content of aux window (the Ctrl F12 thing)
piOut    pointer to content of output window
piPath   pointer to document path
piOptions   pointer the OPT_xxx options
piStart   pointer to selected plain text
piLen    length of selected text
piFind   handle of Find window
piReplace   handle of Replace window
piBookmarks   pointer to an array of the bookmark handles

Some of this is pretty useless, but it gives you an idea what is possible.
Title: Re: A guide to the RichMasm editor
Post by: LordAdef on January 25, 2018, 08:39:07 AM
here is the idea, let me know what you think about it:

Create a TreeView with a couple of parents:

Structures
Procedures
Macros
...search the code and populate the childs with.


Possible?
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 25, 2018, 08:57:42 AM
Yes, that's possible. EM_FINDTEXT is your friend...

I just checked if you can create controls, too - yes, it works, see attachment.
Title: GDI+ bubble help
Post by: jj2007 on April 26, 2018, 10:04:10 PM
The flat GdiPlus API has been added to RichMasm's bubble help feature - example below. See the RichMasm beta with bubble help for WinAPI (http://masm32.com/board/index.php?topic=6055.msg73521#msg73521) post for details.
(http://www.jj2007.eu/pics/GdiPlusBubbles.png) (http://masm32.com/board/index.php?topic=6055.msg73521#msg73521)
Title: Re: A guide to the RichMasm editor
Post by: HSE on July 05, 2018, 01:07:27 AM
Work this RichMasm.ini part ?:ColFg=0AAAAAAh ; default text colour
Fg8=0B0B0B0h ; light gray
Fg16=0A0h ; dark red
Fg24=0A00000h ; dark blue
Fg32=0aaaah ; dark yellow
Fg40=0ffffffh ; white
Fg48=0FFFFFh ; green


Thanks
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on February 12, 2019, 10:08:50 PM
Yes it works. Open \Masm32\MasmBasic\Res\RichMasm.ini and edit as follows:

ColBg=0FFFFE0h ; default, turquois **** DO NOT CHANGE THE ORDER OF THESE ENTRIES! ****
...
ColFg=0 ; default text colour


New version:
ColBg=0 ; pitch black **** DO NOT CHANGE THE ORDER OF THESE ENTRIES! ****
...
ColFg=ffffh ; default text colour YELLOW in BGR notation!


Restart RichMasm to see the effect.
Title: Images in RichMasm
Post by: jj2007 on August 03, 2019, 05:56:55 PM
Sometimes I feel the need to embed an image into a source. Here, for example, an image showing the format of a REAL10 number is useful in the context of the Fcmp macro (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1201):

(http://www.jj2007.eu/images/MbFloatCmp.png)

How is it done? In RichMasm,
- put the text cursor to the end of a comment
- click menu "Open" and select an image
- say "yes" to the "Insert image?" box
- say "OK" to the "Click and move now" box
- click into the image and move it
- when it's at the right position, click again 8)
Title: All opcodes in a handy format
Post by: jj2007 on February 21, 2020, 12:23:39 AM
Attached a slightly updated version of the AllOpcodes.rtf document. You can open it in WordPad or MS Word or any other editor that understands Rich Text Format.

Of course, I use RichMasm. If the rtf hangs around at \Masm32\RichMasm\Help\AllOpcodes.rtf, it will appear in RichMasm's Help menu: Select an instruction, e.g. add, then hover over the Help menu until it opens and click All Opcodes. The listbox will fill as follows:
ADD Add
ADDPD Packed Double-Precision Floating-Point Add
ADDPS Packed Single-Precision Floating-Point Add
ADDSD Scalar Double-Precision Floating-Point Add
ADDSS Scalar Single-Precision Floating-Point Add
ADDSUBPD Packed Double-FP Add/Subtract
ADDSUBPS Packed Single-FP Add/Subtract
FADD/FADDP/FIADD Add
FADD/FADDP/FIADD Add
FADD/FADDP/FIADD Add
HADDPD Packed Double-FP Horizontal Add
HADDPS Packed Single-FP Horizontal Add
PADDB/PADDW/PADDD Packed Add
PADDB/PADDW/PADDD Packed Add
PADDB/PADDW/PADDD Packed Add
PADDQ Packed Quadword Add
PADDSB/PADDSW Packed Add with Saturation
PADDSB/PADDSW Packed Add with Saturation
PADDUSB/PADDUSW Packed Add Unsigned with Saturation
PADDUSB/PADDUSW Packed Add Unsigned with Saturation
PMADDWD Packed Multiply and Add


Another technique that I often use for my libraries is to make a comment, e.g. ; opcodes, then select opcodes and press Ctrl K to insert a hyperlink. In this case, as shown in the screenshot below, it could be \masm32\RichMasm\help\AllOpcodes.rtf#fptan--, where the red part instructs RichMasm to open the rtf, then search immediately for the string fptan--. With one click on the link, you go straight to the entry where the fptan instruction is explained.
Title: Re: A guide to the RichMasm editor
Post by: TioPepperoni on April 02, 2020, 02:38:44 PM
Hey guys, I'm running into issues with RichMasm in general, I have been trying to get this to work but, sadly, it's misbehaving for me, first of all, I have installed MASM32, and it installed just fine, I got everything successfully compiled and up to the ending success message... So following that, I got the latest MasmBasic from this post over here: http://masm32.com/board/index.php?topic=94.msg264#msg264

After I followed all the instructions line by line, I got to install it under `\Masm32\` where Masm32 is located and where it was recommended.

I open RichMasm and was excited enough to finally give it a try when, it started to misbehave... for starters, clicking links, won't follow the actual link, it will just open `\Res\` directory, for anything that I click on the green area... (Main Guide), so I said, what the heck, let me try now with another thing, I followed some steps on how to create a new simple Masm app, by going to `File -> New File/Masm Source` and tried that, with no avail, it simply won't work.. I'm frustrated, because I really wanted to give this a try... any ideas what I did wrong or what could possibly went wrong, or why does it simply works for me?

System Specs:
- OS: Windows 10 Pro (x64)
- Version: 1903
- Build: 18362.720
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on April 02, 2020, 07:31:01 PM
Hi Tio,

Sorry for that. It seems that your Windows version does something odd concerning links (note I don't blame your Windows installation, but it works on mine, including Windows 10, so I'd like to understand what's wrong...). Three short questions:

- when you hit F6 in the main help file, does it build and show the box "Wow, it works"?

- When you click the menu File/New Masm source, does it open a greenish box to the right that starts with Click to open a template, then hit F6 to run it:?

- is the editor at ?:\Masm32\MasmBasic\RichMasm.exe?

Thanks for your feedback :thup:
Title: Re: A guide to the RichMasm editor
Post by: TioPepperoni on April 03, 2020, 11:05:28 AM
HI JJ!!! IT WORKS NOW!!! (uppercaps intended because I'm overly excited! hahaha)

(https://i.imgur.com/AE00Tty.png)

All I had to do was to install FileFormatConverter downloaded from: https://download.cnet.com/Microsoft-Office-Compatibility-Pack-for-Word-Excel-and-PowerPoint-File-Formats/3000-18483_4-10648733.html

and everything works like a charm now!! WOOOW! I always skipped that little messagebox at the beginning of loading the actual `MbGuide.rtf` so I would never thought that was the only thing that would make it work!

I think this would be a good remark to bring up in a troubleshoot thread or something!

Thanks again!  :thumbsup:

Viva MasmBasic!
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on April 03, 2020, 11:36:43 AM
Great job, Tio - and thanks again for the feedback :thup:

I will have to investigate why the file converter is needed. All it does for RichMasm is actually provide a more advanced RichEd20.dll :cool:

Another candidate for the RichEd20.DLL bugs (http://masm32.com/board/index.php?topic=6563.0) thread :tongue:
Title: Re: A guide to the RichMasm editor
Post by: TioPepperoni on April 03, 2020, 11:48:23 AM
Quote from: jj2007 on April 03, 2020, 11:36:43 AM
Great job, Tio - and thanks again for the feedback :thup:

My pleasure! - I fell in love this project at first sight!

Quote from: jj2007 on April 03, 2020, 11:36:43 AM
I will have to investigate why the file converter is needed. All it does for RichMasm is actually provide a more advanced RichEd20.dll :cool:

Another candidate for the RichEd20.DLL bugs (http://masm32.com/board/index.php?topic=6563.0) thread :tongue:

:greensml:
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on September 19, 2023, 11:07:32 AM
Let's say you have a typical resource file:
#include "resource.h"
IDI_APPLICATION ICON "\\Masm32\\MasmBasic\\icons\\Smiley.ico"
01 RT_MANIFEST "\\Masm32\\MasmBasic\\Res\\XpManifest.xml"
#define IDC_MENU 100
#define IDM_SAYHELLO 101
#define IDM_GETTEXT 102
#define IDM_CLEAR 103
#define IDM_EXIT 104
IDC_MENU  MENU
BEGIN
    POPUP "The menu"
    BEGIN
        MENUITEM "Say Hello", IDM_SAYHELLO
        MENUITEM "Get Text", IDM_GETTEXT
        MENUITEM "Clear Edit Box", IDM_CLEAR
        MENUITEM "", , MFT_SEPARATOR
        MENUITEM "E&xit", IDM_EXIT
    END
END

To work with it in the main code, you need this:
IDC_MENU= 100
IDM_SAYHELLO= 101
IDM_GETTEXT= 102
IDM_CLEAR= 103
IDM_EXIT= 104

Wow, that's a lot of stupid typing, right? There is a less known function in RichMasm: select some text and press Ctrl N (N like "Number"). For example, 12345678h yields this:
Dec: 305419896
Hex: 12345678h
00010010001101000101011001111000b
10987654321098765432109876543210

Now, if you select the #define block of text above, Ctrl N will rightly recognise that you want more than one number, and invite you to put the IDC_MENU=100 etc version on the clipboard.

The new RichMasm version comes with MasmBasic 19.9.23 (http://masm32.com/board/index.php?topic=94.0). Enjoy :thup:
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 07, 2024, 01:32:30 AM
Fighting with the incredibly opaque documentation for ADODB. Everyone writes different stories, and compilers do strange things :cool:

pSchema = pCon->OpenSchema(adSchemaTables);... translates to ...
push OFFSET ?vtMissing@@3V_variant_t@@A ; vtMissing = pointers to linefeeds (!)
push OFFSET ?vtMissing@@3V_variant_t@@A ; vtMissing
push 20 ; 00000014H, adSchemaTables
// _pCon$ = -48/-30h ; size = 4
// _pSchema$ = -44/-2Ch ; size = 4
// _sheetName$ = -40/28h ; size = 24
// ??? = -30 = -64 _this$ = -64
lea edx, DWORD PTR $T10[ebp] ; $T10 = -236
push edx
lea ecx, DWORD PTR _pCon$[ebp]
; 00000515- ... = IID_Connection15
call ??C?$_com_ptr_t@V?$_com_IIID@U_Connection@@$1?_GUID_00001550_0000_0010_8000_00aa006d2ea4@@3U__s_GUID@@B@@@@QBEPAU_Connection@@XZ ; _com_ptr_t<_com_IIID<_Connection,&_GUID_00001550_0000_0010_8000_00aa006d2ea4> >::operator->
mov ecx, eax
stack0
call ?OpenSchema@Connection15@@QAE?AV?$_com_ptr_t@V?$_com_IIID@U_Recordset@@$1?_GUID_00001556_0000_0010_8000_00aa006d2ea4@@3U__s_GUID@@B@@@@W4SchemaEnum@@ABV_variant_t@@1@Z ; Connection15::OpenSchema
stack+30h
mov DWORD PTR tv289[ebp], eax ; tv289=-64=-40h
mov eax, DWORD PTR tv289[ebp] ; ???
push eax
lea ecx, DWORD PTR _pSchema$[ebp] ; -44=-2Ch (empty, gets filled by call but it's not a string)
call ??4?$_com_ptr_t@V?$_com_IIID@U_Recordset@@$1?_GUID_00001556_0000_0010_8000_00aa006d2ea4@@3U__s_GUID@@B@@@@QAEAAV0@$$QAV0@@Z ; _com_ptr_t<_com_IIID<_Recordset,&_GUID_00001556_0000_0010_8000_00aa006d2ea4> >::operator=
lea ecx, DWORD PTR $T10[ebp] ; -68=-44h=$T10
call ??1?$_com_ptr_t@V?$_com_IIID@U_Recordset@@$1?_GUID_00001556_0000_0010_8000_00aa006d2ea4@@3U__s_GUID@@B@@@@QAE@XZ ; _com_ptr_t<_com_IIID<_Recordset,&_GUID_00001556_0000_0010_8000_00aa006d2ea4> >::~_com_ptr_t<_com_IIID<_Recordset,&_GUID_00001556_0000_0010_8000_00aa006d2ea4> >
(http://www.jj2007.eu/pics/OpenSchemaRM.png)
Title: Re: A guide to the RichMasm editor
Post by: TimoVJL on January 07, 2024, 06:43:30 AM
Quote from: jj2007 on January 07, 2024, 01:32:30 AMFighting with the incredibly opaque documentation for ADODB. Everyone writes different stories, and compilers do strange things :cool:

pSchema = pCon->OpenSchema(adSchemaTables);
C it this way
pSchema = pCon->lpVtbl->OpenSchema(pCon, adSchemaTables, v1, v2, &pRst);
EDIT: needs three four parameters
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 07, 2024, 07:01:52 AM
Quote from: TimoVJL on January 07, 2024, 06:43:30 AMC it this way
Code Select Expand
pSchema = pCon->lpVtbl->OpenSchema(pSchema, adSchemaTables);

Thanks, Timo. The problem here is that you can find three versions of OpenSchema on the web:
- with one argument
- with two args (most frequent)
- with 36 bytes on the stack, like two VARIANTs by value plus one DWORD

The first two crash in Assembly, simply because the stack is not balanced. The third one returns "invalid parameter". Apparently, it needs a SAFEARRAY as second argument, in which VARIANTs are embedded. But passing a SAFEARRAY by value is no good for the stack balance, ditto for passing it byref :cool: 
Title: Re: A guide to the RichMasm editor
Post by: TimoVJL on January 07, 2024, 07:10:33 AM
OpenSchema method (ADO) (https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/openschema-method-ado)C++ don't always need all parameters, as some can be default


EDIT:
Visual C++ ADO programming (https://learn.microsoft.com/en-us/sql/ado/guide/appendixes/visual-c-ado-programming?view=sql-server-ver16)

from Pelles C compiled code:
73:            hr = pCon->lpVtbl->OpenSchema(pCon, adSchemaTables, vtCriteria, vtMissing, &pRst);
  [0000014B] 8D45F8                lea              eax,[ebp-8]
  [0000014E] 50                    push              eax
  [0000014F] 8D4DD8                lea              ecx,[ebp-28]
  [00000152] 83EC10                sub              esp,10
  [00000155] 8B01                  mov              eax,dword ptr [ecx]
  [00000157] 890424                mov              dword ptr [esp],eax
  [0000015A] 8B4104                mov              eax,dword ptr [ecx+4]
  [0000015D] 89442404              mov              dword ptr [esp+4],eax
  [00000161] 8B4108                mov              eax,dword ptr [ecx+8]
  [00000164] 89442408              mov              dword ptr [esp+8],eax
  [00000168] 8B410C                mov              eax,dword ptr [ecx+C]
  [0000016B] 8944240C              mov              dword ptr [esp+C],eax
  [0000016F] 8D4DB8                lea              ecx,[ebp-48]
  [00000172] 83EC10                sub              esp,10
  [00000175] 8B01                  mov              eax,dword ptr [ecx]
  [00000177] 890424                mov              dword ptr [esp],eax
  [0000017A] 8B4104                mov              eax,dword ptr [ecx+4]
  [0000017D] 89442404              mov              dword ptr [esp+4],eax
  [00000181] 8B4108                mov              eax,dword ptr [ecx+8]
  [00000184] 89442408              mov              dword ptr [esp+8],eax
  [00000188] 8B410C                mov              eax,dword ptr [ecx+C]
  [0000018B] 8944240C              mov              dword ptr [esp+C],eax
  [0000018F] 6A14                  push              14
  [00000191] FF75FC                push              dword ptr [ebp-4]
  [00000194] 8B45FC                mov              eax,dword ptr [ebp-4]
  [00000197] 8B00                  mov              eax,dword ptr [eax]
  [00000199] FF908C000000          call              dword ptr [eax+8C]
73:            hr = pCon->lpVtbl->OpenSchema(pCon, adSchemaTables, vtCriteria, vtMissing, &pRst);
  [00000000000001FD] 488D8424B8000000            lea              rax,[rsp+B8]
  [0000000000000205] 4889442420                  mov              qword ptr [rsp+20],rax
  [000000000000020A] 488D7C2440                  lea              rdi,[rsp+40]
  [000000000000020F] 488DB42488000000            lea              rsi,[rsp+88]
  [0000000000000217] B918000000                  mov              ecx,18
  [000000000000021C] F3A4                        rep movsb       
  [000000000000021E] 488D7C2428                  lea              rdi,[rsp+28]
  [0000000000000223] 488D742458                  lea              rsi,[rsp+58]
  [0000000000000228] B918000000                  mov              ecx,18
  [000000000000022D] F3A4                        rep movsb       
  [000000000000022F] 488B8C24C0000000            mov              rcx,qword ptr [rsp+C0]
  [0000000000000237] BA14000000                  mov              edx,14
  [000000000000023C] 4C8D442428                  lea              r8,[rsp+28]
  [0000000000000241] 4C8D4C2440                  lea              r9,[rsp+40]
  [0000000000000246] 488B8424C0000000            mov              rax,qword ptr [rsp+C0]
  [000000000000024E] 488B00                      mov              rax,qword ptr [rax]
  [0000000000000251] FF9018010000                call              qword ptr [rax+118]
Title: Re: A guide to the RichMasm editor
Post by: jj2007 on January 07, 2024, 08:19:07 AM
Quote from: TimoVJL on January 07, 2024, 07:10:33 AMOpenSchema method (ADO) (https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/openschema-method-ado)C++ don't always need all parameters, as some can be default

OpenSchema is only happy with 9 DWORDs on the stack :cool: