Author Topic: MasmBasic  (Read 144284 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #135 on: October 11, 2013, 09:22:25 AM »
Update 10 October (download):
RichMasm can now handle a collection of snippets in one file, as in the attached file containing 40 examples of simple console mode code. In the editor, it is sufficient to select the Init of any examples and then hit F6 to assemble, link & run the example.

EDIT: See update in Reply #147
« Last Edit: October 24, 2013, 08:53:03 PM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
FolderOpen$()
« Reply #136 on: October 19, 2013, 01:23:04 AM »
Update 18 October (download):

1. Analogous to FileOpen$(), MasmBasic has now a comfortable wrapper for SHBrowseForFolder called FolderOpen$():

include \masm32\MasmBasic\MasmBasic.inc        ; RichMasm: select Init and hit F6 to test the examples
  Init                          ; FolderOpen$(prompt [, title] [, path] [, BIF flags])
  Let esi=FolderOpen$()        ; no args = use Windows defaults, start with current folder
  Print "Selected: [", esi, "]", CrLf$        ; if the user cancelled, esi will be an empty string
  PrintLine "Selected: ", FolderOpen$("Pick a folder:", "Masm32 is great")        ; a prompt and a nice title, start with current folder
  PrintLine "Selected: ", FolderOpen$("Pick a folder:",, "\Masm32\Examples")        ; just a prompt, default title, specific folder
  PrintLine "Selected: ", FolderOpen$("9Pick a big folder:")                ; a big prompt (font 9), default title, current folder
  ; prompt, title, path with environment variables, flags
  Let esi=FolderOpen$("What is the edit box for?","Locate Office:", "%ProgramFiles%\Microsoft Office", BIF_USENEWUI)
  PrintLine esi
  PrintLine "Selected folder=[", FolderOpen$("Where are your tools?",, "D:\Masm32\bin"), "]"        ; fully qualified initial path
;   if you need to check whether the user cancelled, use void and check the zero flag:
  void FolderOpen$("5Pick the bin folder, please:","Getting help", "\Masm32\bin")        ; use current drive plus initial path
  .if !Zero?
        MsgBox 0, Launch$(Cat$(eax+"\link.exe /Lib")), "Library manager help:", MB_OK
  .else
        PrintLine "Nothing selected: [", eax, "]"        ; Zero? set = user cancelled, eax points to a Null$
  .endif
  Exit
end start


2. Minor bugfix: Str$() can now also handle LARGE_INTEGER values properly.

3. See also Monitoring WM_nnnn messages.

P.S.: There is a pretty fat and pretty stupid SHBrowseForFolder bug in Windows 7. Grateful for feedback if FolderOpen$() works properly on all Windows versions from XP upwards. XP and Win7-32 seem to work AFAIK.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
SHBrowseForFolder bug
« Reply #137 on: October 19, 2013, 03:24:55 AM »
If you can give that MamBasic in zip package without installer, i may test it.
I made the installer precisely because many people have forgotten how to extract an archive properly. The installer creates one folder (\Masm32\MasmBasic) and does not modify the registry.

What do you typically do if Adobe or Microsoft or Sun ask you to run a *.msi file? Do you have any reason to trust me less than, ehm, Microsoft?

Quote
P.S.: There is a pretty fat and pretty stupid SHBrowseForFolder bug in Windows 7. Grateful for feedback if FolderOpen$() works properly on all Windows versions from XP upwards. XP and Win7-32 seem to work AFAIK.
What problem ?
That example code works in my Win7 32/64-bit

Just google for SHBrowseForFolder bug in Windows 7 - many hits, and most mention that it does "not always" scroll down. Your code works fine on XP, can't test it on Win7 right now, but I have seen the no-scroll problem often enough in action on Win7. Need an official Microsoft site? BFFM_SETSELECTION does not work with SHBrowseForFolder on Windows 7

TWell

  • Member
  • ****
  • Posts: 748
Re: SHBrowseForFolder bug
« Reply #138 on: October 19, 2013, 04:09:05 AM »
Just google for SHBrowseForFolder bug in Windows 7 - many hits, and most mention that it does "not always" scroll down. Your code works fine on XP, can't test it on Win7 right now, but I have seen the no-scroll problem often enough in action on Win7. Need an official Microsoft site? BFFM_SETSELECTION does not work with SHBrowseForFolder on Windows 7
Thanks for that link, now i see that problem, it starts showing from Destop and selected folder isn't visible as in WinXP, so no scrolling to that.

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #139 on: October 19, 2013, 04:17:44 AM »
the MasmBasic installer is benign - and a good way to go
it can be a little confusing to install it manually

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Re: SHBrowseForFolder bug
« Reply #140 on: October 19, 2013, 08:33:56 AM »
Here is code example to fix that problem:

Thanks, I know that example, and I wouldn't have posted a new MasmBasic version if I had not already fixed the problem. Still, grateful for feedback if MB OpenFolder$() works, because I took a slightly different road (the code you posted failed occasionally on my Win7-32 system).

Attached an exe for testing. The source is lines 372ff of MbFuide.rtf (also included, you have it already at \Masm32\MasmBasic\MbGuide.rtf in case you downloaded MasmBasic).

TWell

  • Member
  • ****
  • Posts: 748
Re: SHBrowseForFolder bug
« Reply #141 on: October 19, 2013, 07:22:57 PM »
Still, grateful for feedback if MB OpenFolder$() works, because I took a slightly different road (the code you posted failed occasionally on my Win7-32 system).

Attached an exe for testing. The source is lines 372ff of MbFuide.rtf (also included, you have it already at \Masm32\MasmBasic\MbGuide.rtf in case you downloaded MasmBasic).
OpenFolder works nicely in Win7 64-bit.
Avast don't let me download that zip.

BYE

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Setting multiple clipboard entries
« Reply #142 on: October 24, 2013, 09:24:04 AM »
Major update of MasmBasic, 24 October 2013 (download):

1. Put multiple formats on the clipboard (full example attached, MS Word should be running):

        SetClip #start        ; ---- set multiple clipboard formats ----
        SetHtmlClip$ "Text in <font color='blue'>HTML</font> format"        ; for Thunderbird and Excel
        SetClip 100, CF_BITMAP        ; 100 = ID of bitmap resource
        SetClip$ offset txTest, CF_RTF        ; Rich Text Format
        SetClip$ wRes$(123)        ; use resource string #123, "This is a sub-title" in Russian (Unicode)
        SetClip$ "This is ANSI text"
        SetClip #end        ; ---- end of multiple clipboard formats ----

2. Improved DDE to Excel macros, inter alia for writing Unicode (the real thing, e.g. Chinese etc from resources), pasting HTML format etc. - screenshot (example attached) below.

P.S.: The attached MbSnippets.asc, when opened in \Masm32\MasmBasic\RichMasm.exe, allows to build & run over 40 "snippets", i.e. short examples showing what the MB macros can do. Just click one of the Init entries in the listbox (or select an Init by hand), then hit F6 to see the result. Test it, for example, with the ## Unicode with wRes$ ## snippet in line 468.
« Last Edit: October 24, 2013, 08:48:13 PM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
StackBuffer()
« Reply #143 on: October 30, 2013, 11:05:27 AM »
Update 30 October 2013 (download):

StackBuffer
        MyTest proc uses edi esi ebx arg1:DWORD, arg2:RECT
        LOCAL rc:RECT, sbuf1, sbuf2, sbuf3, whatever[100]:BYTE
         ; optional: ClearLocals        ; first line after the LOCALs
          mov sbuf1, StackBuffer(100000)        ; allocate two fat buffers, and make sure
          mov sbuf2, StackBuffer(4000h)        ; they are 16-byte aligned for use with SSE2
          invoke GetFileSize, hFile, 0        ; you may use a register or any other variable to specify the buffer size
          mov sbuf3, StackBuffer(eax, nz)        ; option nz means "no zeroing" - much faster (the buffer end is zeroed anyway)
          PrintLine "Start buffer 1:", Tb$, Hex$(sbuf1)
          PrintLine "Start buffer 2:", Tb$, Hex$(sbuf2)
          StackBuffer()        ; release all buffers (sb without args = free the buffer)
          ret
        MyTest endp

Rem     - buffer size is limited by start address of stack; normally, you can use close to one MB
        - the start address is aligned to 64 bytes for use with SIMD instructions
        - you can use StackBuffer anywhere (not only at proc start & end), but make sure esp is unchanged
        - StackBuffer zero-inits the buffer, unless option nz is specified (much faster)
        - with option nz, only the end of the buffer (+/- 2 bytes, one DWORD) is zeroed
        - can be combined with ClearLocals
        - StackBuffer does the stack probing for you; up to about half a megabyte, it is significantly faster than HeapAlloc


EDIT: Version MbSetup30Oct2013d.zip fixes a problem with the Launch$() timeout. In the new version, Launch$() throws an error when there is no read activity for more than n milliseconds, which is a better behaviour with apps that give slow feedback in bits and pieces, e.g. zippers or even ML.exe (the old Launch$() version stopped when the timeout was reached overall).

Example:
a) slowly printing app:
include \masm32\MasmBasic\MasmBasic.inc
  Init
  push 15
  .Repeat
        Print Str$("sp%i ", stack)
        mov ecx, 100
        .if stack==5 || stack==10
                mov ecx, 2000        ; the app "chokes" two seconds with element 5+10
        .endif
        invoke Sleep, ecx
        dec stack
  .Until Sign?
  Print "BYE", 13, 10        ; No inkey, please
  Exit
end start


b) Launcher:
include \masm32\MasmBasic\MasmBasic.inc
  Init

  PrintLine "## Launch Nr. 1 ##"
  Let esi=Launch$("SlowPrint", SW_RESTORE, 1000)        ; SlowPrint is an app that ... prints slowly
  PrintLine "First attempt, timeout=1000: ", Tb$, esi

  PrintLine "## Launch Nr. 2 ##"
  Let esi=Launch$("SlowPrint", SW_RESTORE, 1500)
  PrintLine "Second attempt, timeout=1500: ", Tb$, esi

  PrintLine "## Launch Nr. 3 ##"
  Let esi=Launch$("SlowPrint", SW_RESTORE, 2000)
  Inkey "Third attempt, timeout=2000: ", Tb$, esi

  Exit
end start


Output:
## Launch Nr. 1 ##
First attempt, timeout=1000:    La$?
## Launch Nr. 2 ##
Second attempt, timeout=1500:   La$?
## Launch Nr. 3 ##
Third attempt, timeout=2000:    sp15 sp14 sp13 sp12 sp11 sp10 sp9 sp8 sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 BYE
« Last Edit: October 30, 2013, 10:20:19 PM by jj2007 »

Farabi

  • Member
  • ****
  • Posts: 970
  • Neuroscience Fans
Re: MasmBasic - a fast and easy-to-use library
« Reply #144 on: November 08, 2013, 05:39:13 PM »
 :t Impressive, it become more and more usefull. I'll use MASM BASIC started from now and forever.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

  • Member
  • ****
  • Posts: 970
  • Neuroscience Fans
Re: MasmBasic - a fast and easy-to-use library
« Reply #145 on: November 08, 2013, 06:16:32 PM »
What does it is mean ? "D:\Masm32\Include\MasmBasic.inc(168) : error A2052: forced error"
My other project did not yield this error, what causing it?
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #146 on: November 08, 2013, 11:39:16 PM »
What does it is mean ? "D:\Masm32\Include\MasmBasic.inc(168) : error A2052: forced error"
My other project did not yield this error, what causing it?

Hi Farabi,

What else does the error message say? To which source code line does it refer? Can you post these lines (+/- 10 lines)?

There are several "forced" errors in the library, some because you can't use the old ML 6.14 assembler, others because of syntax problems...

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Bug warning
« Reply #147 on: November 10, 2013, 12:35:55 PM »
There was a nasty little bug since the introduction of ArraySet():

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  Dim My3Pts(5) As REAL4        ; create an array with 3 XY pairs, i.e. 6 elements (0 .. 5)
  ArraySet My3Pts() = 1.0, 100.0, 2.0, 300.0, 4.0, 150.0        ; assign XY values
  Inkey "ok"
  Exit
end start


The macro started one step above its HeapAlloc'ed area, and thus on rare occasions could cause an exception. This bug showed up with REAL4 and REAL8 but not with DWORD arrays.

Apologies - it's fixed now, download here

Other changes concern only DosBasic, the little 16-bit brother of MasmBasic.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #148 on: November 11, 2013, 10:16:52 AM »
A small addition for version 11.11.2013 (download): CL$(?) returns the number of commandline arguments.
Note that CL$(0), i.e. the name of the executable, is not counted here, which is a minor inconsistency with regard to
  Dim My$(9)
  Print Str$("There are %i elements in the array\n", My$(?))
returning There are 10 elements in the array, i.e. 0...9

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7559
  • Assembler is fun ;-)
    • MasmBasic
Qtrim$, Extract$()
« Reply #149 on: December 11, 2013, 10:16:31 AM »
Update 11 December 2013:

- a completely redesigned installer (well, under the hood ;))

- Qtrim$():
        Let My$=Qtrim$(Chr$(9, '  "quoted"  ', 13, 10))        ; returns quoted
        Let My$=Qtrim$(CL$())                ; same for complete quoted commandline

- Extract$() has a new flag, xsEscape, meaning translate \n to CrLf and \t to a tab:
  ; exclude left pattern, case-insensitive, trim whitespace, right pattern is default aka CrLf; in short: grab the line after =
  xsDefault=xsExcL or xsCaseI or xsTrim or xsEscape
  Let Title$=Extract$(esi, "title=")

.. where esi is a buffer containing this text:

This is a simple text file, and we want to extract the part below after "=":
Title=Hello\nWorld\nhow are you?
Let title$=Extract$(esi, "Title") will yield only the hello world part (in three lines), provided the right flags are set. For details, see \Masm32\MasmBasic\MbGuide.rtf


Several new snippets were added, see attachment. When opened with RichMasm, each of them can be built and run by selecting Init and hitting F6. This works also when the Find string is Init, and the user selects one of the entries in the listbox. In a way, this is multiple projects in a single source file ;)