News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MasmBasic

Started by jj2007, October 06, 2009, 08:24:57 PM

Previous topic - Next topic

jj2007

Quote from: dedndave on January 16, 2010, 02:36:06 AM
you could always add a right-click context menu with a bunch of typing shortcuts, JJ

The keyboard shortcuts are toggled with Alt K and appear to the right where normally the bookmarks reside.
In case you mean the "expansion" strokes, e.g. ism ->invoke SendMessage, there are too many for a context menu. Below an excerpt from \masm32\RichMasm\RES\Keywords.ini

masmincs include \masm32\include\masm32rt.inc
mbincs include \masm32\MasmBasic\MasmBasic.inc §
clv ClearLocalVariables uses edi esi ebx ¨ PopUses §
exit §
clr §
s$( Str$(§
c$( Chr$(§
float$( Str$(§
string$(§
gf GetFiles *.asc §
exist(§
ex( Exist(§
kill §
opi Open "I", #1, §
opo Open "O", #1, §
lof( Lof(#1) §
inp1 Input #1, §
pri1 Print #1, §
pri Print §
fr$( FileRead$("¨")
new$(§
clo1 Close #1 ; file #1 closed §
clo Close §
dim Dim My$(ct) §
ins Insert My$(0) Let My$(0)="¨" §
del Delete My$(¨) §
erase Erase My$() §
swap §
let §
rec Recall "\Masm32\include\Windows.inc", L$() §
sto Store "MyFile.txt", L$(), ct ; write ct strings to file §
left$(§
right$(§
mid$(§
new$(§
win$(§
ltrim$(§
rtrim$(§
trim$(§
lower$(§
upper$(§
instr( Instr_(§
rinstr(§
asc(§
cvi(§
cvl(§
min( Min(eax, ¨) ; rv in edx §
max( Max(eax, ¨) ; rv in edx §
timer §
for_ For_ n=0 To ebx-1 ¨ Next §
ism invoke SendMessage,
mb MsgBox 0, "¨", "Hi", MB_OK
.rep .Repeat ¨ .Until 0
.whi .While 1 ¨ .Endw
deb deb 1, "¨", eax, ecx, edx ;, esi$, edi$
tmp$ tmp$ CATSTR <Myarg=>, <¨> % echo tmp$
ae ä
oe ö
ue ü
ret0 xor eax, eax ret
olly ExternDef f2sOlly:DWORD .if f2sOlly==123 INT 3 .endif §
alert( alert("Test ¨: ")

The ones I use most frequently are rep, deb and mb ;-)

hutch--

 :bg

JJ,

You may have to change the name of your project to WASMbasic if you are building it with JWASM.  :P
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

go for a comprimise, Jochen.....

JJwBasic     :8)

jj2007

#108
Quote from: hutch-- on January 17, 2010, 12:24:07 AM
You may have to change the name of your project to WASMbasic if you are building it with JWASM.  :P
Quote from: dedndave on January 17, 2010, 01:06:31 AM
go for a comprimise, Jochen.....

JJwBasic     :8)

The full name is actually "Inline Basic for use with Microsoft Macro Assembler" :wink
Anyway, I had googled for MasmBasic and didn't find hits, so I assume the copyright is with me :8)
If only I could convince myself to fix that bloody Val() problem... on the positive side, when trying to use the character table for the Val function, I got so upset about having to scroll all the time between the char table in the data section and the code section that I decided to add a new feature to RichMasm - The Pinboard:

Select some lines of code, press Control F12, and from then on these lines appear in a greyish extra window on top of the main text window. No need to scroll... try it out. Bug warning re Val() persists.

Another new feature: If in your code you select for example Print and press F1, the MasmBasic help will pop up. If you had selected CreateWindowEx, you'll get the corresponding page from \masm32\RichMasm\help\WIN32.HLP. The MB help is handled by RichMasm, so if it doesn't find the entry, it passes the request on to WinHelp.
:bg

dedndave

Quote"Inline Basic for use with Microsoft Macro Assembler"

Ibumma ? - nawwww

jj2007

#110
Loading big sources into a RichEdit 3.0 control can be quite slow. RichEdit 4.1 is about a factor ten faster, but all newer versions of RichEdit, included as MSFTEDIT.DLL in Win XP and as RichEd20.dll in Office 11/12 are broken: for SF_TEXT, their EM_STREAMOUT message skips occasionally some bytes, making them thus unusable for coding. The EM_GETSELTEXT message shows the same symptoms.

EM_GETTEXTRANGE seems to work, but it exports CR only instead of CRLF as next line characters.

Intensive researchTM has led to a breakthrough, though:

*** The EM_GETTEXTEX message seems NOT broken. ***

AT YOUR OWN RISK: To test them in RichMasm, copy one of these to

\masm32\RichMasm\dll\RichEditOffice.DLL

After loading an Asc or Rtf doc, you can press F8 to see loading time and dll version used.

Best choice is the Office 11/RichEdit 5.0, usually under
C:\Program Files\Common Files\Microsoft Shared\OFFICE11\RICHED20.DLL

Second best (half as fast) is Office 12/RichEdit 6.0, usually under
C:\Program Files\Common Files\Microsoft Shared\OFFICE12\RICHED20.DLL
The latter requires MSPTLS.DLL in the RichMasm.exe path.

in case you don't own MS Office: The Office 5 RichEd20.dll (18.06.2007, 1103280 bytes) is included in the free Word Viewer downloadable here.

Bug warning re Val() persists, but being able to use the newer dlls makes a difference in loading time...!

jj2007

#111
That copying of dlls stuff was horribly complicated, so I thought it would be easier if RichMasm.exe located that dll. Here is the new version, speedier than ever. It checks first if the user has installed a specific dll, then the availability of the Office 11 RichEd20.dll, then the (slower) Office 12 version, and finally, if all those fail, it uses the standard Windows riched20.dll.

Here is a snippet showing how it is done:
mov esi, offset LibNameOffice
invoke LoadLibrary, esi ; user-copied \masm32\RichMasm\Dll\RichEditOffice.DLL
.if eax==0
mov esi, RichEditV$
invoke ExpandEnvironmentStrings, chr$("%COMMONPROGRAMFILES%"), esi, MAX_PATH
mov ebx, eax
invoke lstrcat, esi, chr$("\Microsoft Shared\OFFICE11\RichEd20.DLL")
invoke LoadLibrary, esi ; RichEd20.dll, Office 11 version
.if eax==0
mov byte ptr [esi+ebx+24], "2" ; convert Office11 to Office12
invoke LoadLibrary, esi ; RichEd20.dll, Office 12 version
.if eax==0
mov esi, offset LibName
invoke LoadLibrary, esi ; RichEd20.dll for poor people
.endif
.endif
.endif
mov RichEditUsed, esi


EDIT: Attachment removed - the version on top of thread is more recent.

jj2007

A minor update to the MasmBasic library: Replace$, not yet well tested but it looks promising.

Quoteinclude \masm32\MasmBasic\MasmBasic.inc   ; get it here

.code
start:
   mov edi, chr$("\masm32\MasmBasic\WinIncs.htm")   ; the output file
   push Timer
   Open "O", #1, chr$("\masm32\MasmBasic\WinIncs.htm")
   Let ebx=FileRead$("\masm32\include\Windows.inc")+FileRead$("\masm32\include\WinExtra.inc")
   ; The '<' and '>' chars will be misinterpreted as html tags and must therefore be removed
   Let ebx=Replace$(ebx, chr$(60), "&lt;")      ; < = less than; src, search, repl [, case] [, count]
   Let ebx=Replace$(ebx, chr$(62), "&gt;")      ; > = greater than
   Let ebx="<html><head><title>Windows.inc and WinExtra.inc</title></head><body>"+ebx+"</body></html>"
   Let ebx=Replace$(ebx, CrLf$, chr$("<br>", 13, 10))   ; HTML needs <br>
   Let ebx=Replace$(ebx, "struct", "<font color='red'><b>Struct</b></font>", 1+4)      ; ignore case, find whole word only
   Let ebx=Replace$(ebx, "union", "<font color='red'><b>Union</b></font>", 1+4)
   Let ebx=Replace$(ebx, "qword", "<font color='blue'><b>qword</b></font>", 1+4)
   Print #1, Replace$(ebx, "PROTO", "Proto", 1+4)   ; MixedCase looks nicer ;-)
   Close
   
void Timer         ; replacing "<" and ">" slows this down a lot: on a P4, 600 ms instead of 80 without
   pop ecx
   sub eax, ecx
   Print Str$("%i ms for replacing text in wininc & winextra\nand writing it to", eax), edi
   Exit
end start

jj2007

New version attached at top of thread:

After some hesitation, I introduced AutoSave for the RichMasm editor. Testing assembler code is a recipe for serious crashes, and while RichMasm had already a "Last Good Version" feature (i.e. a copy of the last version that assembled without errors), it keeps now also the very latest version. After five seconds of no typing activity, and only if there were edits, a FileName.tmp will be saved. After a crash, if you open the latest FileName.asc, you can choose to use the saved tmp version.

Another new feature: The F1 key performs a chained search in a) the MasmBasic help file and b) \masm32\RichMasm\help\WIN32.HLP
For example, if Exit (a MasmBasic function) is selected, F1 will show the MasmBasic entry for Exit. If ExitProcess is selected, F1 checks in the MasmBasic guide, doesn't find it, and displays instead the Win32.hlp ExitProcess page.

The BASIC library has now over 60 functions, mostly in string handling and file I/O. Most recent additions are Space$() and a fast Rinstr. The FileRead$ and Replace$ functions are a bit more flexible now.  For example, this is perfectly legal code, i.e. it assembles fine with ml.exe and Jwasm (see previous post for a complete app):

Quote   Let esi=FileRead$("\masm32\include\Windows.inc")+FileRead$("\masm32\include\WinExtra.inc")
   Let ebx=Replace$(esi, "struct", "<font color='red'><b>Struct</b></font>", 1+4)   ; 1=ignore case, 4=find whole word only

jj2007

Update (attached at top of thread):
- minor bugfix with CrtDate$ and CrtTime$
- for reasons of consistency, New$ is now called with Let instead of mov, e.g. Let My$=New$(1024)
- small improvements of the editor:
@@: nop

Hitting Return after the nop produces now the correct indent, in spite of the label. Another change:
.if eax
nop
.endif

Hitting Shift Return after the nop produces the indent needed for .endif (while a normal Return will insert the same indent as nop).

jj2007

Update 25.3.10: RichMasm.exe now opens Unicode text files correctly. However, the preferred way to edit Unicode resource files is to embed them at the bottom of the *.asc source, see "New Masm source":

Controls with resources simple controls, rc embedded in main src
Controls with Unicode simple controls using Arabic Unicode


jj2007

Update 27.3.: Only a few lines had to be changed to make it print a qword directly:

include \masm32\MasmBasic\MasmBasic.inc

.code
MyQ dq 123456789123456789
start:
Print "A qWord integer: ", Str$(q:MyQ), CrLf$, CrLf$
inkey "press any key"
Exit
end start


The q: trick is needed because there is (to my knowledge) no way to distinguish between a qword and a real8 variable. If somebody knows a workaround, please let me know.

jj2007

29.3.: Inkey added:
Quote   Inkey Str$("\nThis file has %2f kBytes\nhit any key to get outta here", Lof("MbGuide.rtf")/1024)

Output:

This file has 67.0 kBytes
hit any key to get outta here

Inkey behaves exactly like Print but waits for a keystroke.

jj2007

#118
Version 9v (at the bottom of the first post) features two new functions for comparing strings and entire files. Their speed is competitive - about a factor five faster than their CRT equivalents for StringsDiffer.

QuoteStringsDiffer
   .if StringsDiffer("Hello", "Hallo")
      MsgBox 0, "The two strings are different", "Hi", MB_OK
   .endif
   test eax, StringsDiffer("Hello", "Hallo")
   .if Zero?
      MsgBox 0, "The two strings are equal", "Hi", MB_OK
   .endif
Rem[/color]   returns DWORD in eax
Key   -
FilesDiffer
   .if FilesDiffer("MyFileA.txt", "MyFileB.txt")
      MsgBox 0, "The two files are different", "Hi", MB_OK
   .endif
   Let esi="MyFileA.txt"
   test eax, StringsDiffer(esi, offset MyFileB)
   .if Zero?
      MsgBox 0, "The two files are equal", "Hi", MB_OK
   .else
      MsgBox 0, "The two files are different", "Hi", MB_OK
   .endif
Rem[/color]   returns DWORD in eax
Timings:
Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (SSE3)
5802    cycles for StringsDiffer
27860   cycles for crt_strcmp
179912  cycles for lstrcmp

7363    cycles for StringsDiffer (case-insensitive)
32968   cycles for crt__stricmp
179374  cycles for lstrcmpi


EDIT: New version with pre-P4 brand string and improved SSE check

MichaelW

A 5X difference between StringsDiffer and crt_strcmp is more than a little surprising, but the 1000X difference running on my P3 system suggests that something is wrong.

58      cycles for StringsDiffer
61084   cycles for crt_strcmp
52757   cycles for lstrcmp

56      cycles for StringsDiffer
60943   cycles for crt_strcmp
52862   cycles for lstrcmp

51      cycles for StringsDiffer
61150   cycles for crt_strcmp
52673   cycles for lstrcmp

eschew obfuscation