Author Topic: MasmBasic  (Read 440010 times)

TWell

  • Member
  • ****
  • Posts: 743
Re: SHBrowseForFolder bug
« Reply #135 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: 8828
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #136 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: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: SHBrowseForFolder bug
« Reply #137 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: 743
Re: SHBrowseForFolder bug
« Reply #138 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: 13945
  • Assembly is fun ;-)
    • MasmBasic
Setting multiple clipboard entries
« Reply #139 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: 13945
  • Assembly is fun ;-)
    • MasmBasic
StackBuffer()
« Reply #140 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: 968
  • Neuroscience Fans
Re: MasmBasic - a fast and easy-to-use library
« Reply #141 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: 968
  • Neuroscience Fans
Re: MasmBasic - a fast and easy-to-use library
« Reply #142 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: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #143 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: 13945
  • Assembly is fun ;-)
    • MasmBasic
Bug warning
« Reply #144 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: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #145 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: 13945
  • Assembly is fun ;-)
    • MasmBasic
Qtrim$, Extract$()
« Reply #146 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 ;)

anta40

  • Member
  • ***
  • Posts: 315
Re: MasmBasic - a fast and easy-to-use library
« Reply #147 on: December 11, 2013, 12:59:12 PM »
Hi jj,

I think there's a bug with the installer.
After I selected C:\masm32\macros\macros.asm, I could see this on the installer:

"The MasmBasic library will be installed to La$?"

"Can't create destination folder
La$?"

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #148 on: December 11, 2013, 05:12:01 PM »
Hi anta,

"La$?" is what Launch$("whatever.exe") returns if whatever.exe hangs and/or a timeout occurs. Apparently the default timeout is too short - I will fix this asap.

Thanks a lot for the feedback,
jj

EDIT: It's fixed, see version 11 Dec 2013b
« Last Edit: December 12, 2013, 04:12:14 AM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Bug in Str$() - and workaround
« Reply #149 on: December 15, 2013, 09:50:37 AM »
There is a problem with Str$() when used with .data section arrays - it will not digest e.g. Str$(MyArray[3*REAL8]):

include \masm32\MasmBasic\MasmBasic.inc

.data
MyArray        REAL8 1.23, 4.56, 7.89, 9.87

  Init

  Print Str$("Element 0 is %3f\n", MyArray)        ; Str$(REAL8_var) works, but only for element zero

  el1 equ MyArray[1*8]        ; workaround for other elements - no <brackets> please
  Print Str$("Element 1 is %3f\n", el1)

  mov ecx, offset MyArray+1*REAL8        ; use a register to access array elements
  Print Str$("Element 2 is %3f\n", real8 ptr [ecx+8])        ; OK if exactly one blank between ptr and [

  ; no problems with Basic-style arrays (byte/word/dword/qword/R4/r8/r10):
  Dim MyR8(3) As REAL10        ; create an array of long doubles (same for REAL4, REAL8)
  fldpi
  fstp MyR8(3)                ; put PI into element 3
  Print Str$("Element 3 is %Jf\n", MyR8(3))

  Inkey "ok"
  Exit
end start


I had found a fix, but unfortunately it chokes with JWasm, so for the time being, and if you really need it, use the equate.