Author Topic: MasmBasic  (Read 217610 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
FileRead$("http://...")
« Reply #195 on: October 05, 2014, 12:50:06 PM »
Bugfix 5 October (download):

For a while, the FileRead$() function had "forgotten" how to read a file from the Internet - sorry :redface:

Now the snippet below works again. It downloads an attachment from this forum, checks the zip directory for the first *.asm file, and displays the first 1.8 k on the screen:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  ; assign contents of a well-known file to esi:
  Let esi=FileRead$("http://masm32.com/board/index.php?action=dlattach;topic=49.0;attach=30")
  FileWrite "tmp.zip", esi, LastFileSize      ; write contents to a temporary file
  UnzipInit "tmp.zip"      ; expects a filename, returns a comment (if present)
  .if Sign?
      Print eax      ; print an error message
  .else
      For_ ecx=0 To edx-1      ; #files returned in edx
            mov esi, Files$(ecx)
            .if Instr_(esi, ".asm", 1)      ; assembler source, plain text?
                PrintLine "## First 1800 chars of ", esi, " ################# : ", CrLf$, Left$(UnzipFile(ecx), 1800), " ..."
            .endif
      Next
      UnzipExit
  .endif
  Inkey "## Cute, isn't it? #################"
  Exit
end start

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Menus with tooltips
« Reply #196 on: October 15, 2014, 09:18:42 AM »
MasmBasic update of 15 October (download) concerns mainly improvements of the editor:

- plugins don't need to be registered in the menus.ini file, it is sufficient to build them in the plugin folder
- all menus allow now tooltips, as shown below; for plugins, they can be defined in the source using txName db "name in menu§description of\nthe plugin", 0

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Bugfix for MasmBasic
« Reply #197 on: October 27, 2014, 10:24:20 AM »
I know it's hard to believe but YES, MasmBasic had a bug: wLeft$/wRight$/wMid$ didn't work :redface:

The Ascii versions were ok but the wide (Unicode) versions returned drastically shortened strings. No idea when this regression crept in but now it's fixed. Test it e.g. with the "talk to Excel" example in \Masm32\MasmBasic\Res\Masm2ExcelCircle.asc, line 39:

      xlsFormat CF_UNICODETEXT      ; back to Unicode
      wPrint "Cur selection", wTb$, wMid$(xlsRead$(), 16), wCrLf$      ; get current selection, strip the string "Real Unicode":


Note that in order to see the Unicode strings returned by Excel properly, you need to set the console font to Lucida Console (in the console window's system menu, properties, font).

Other good news is that UnzipFile() (see \Masm32\MasmBasic\MbGuide.rtf - based on JibZ' Tiny Inflate Library) is now twice as fast (the bad news is I had to abandon Pelles C to achieve that :().

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
MasmBasic thread-safe?
« Reply #198 on: November 10, 2014, 12:52:49 PM »
Update 10 November: Launch$() is now thread-safe. This was never a problem in console apps, but GUI apps could occasionally choke. It's fixed.

Other changes:
- Dll accepts now environment variables such as %ProgramFiles% - works with non-English Windows versions, ok for Win7-64:

  Dll "%ProgramFiles%\FreeArc\Addons\InnoSetup\unarc"

- Err$() allows an optional text, and instead of throwing a runtime error, you can programmatically check the availability of a DLL or certain functions inside a DLL:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  DllRTE=1             ; 1=throw runtime error if LoadLibrary fails (default), 0=no runtime error, check eax instead
  Dll "shimgvw"        ; load the shell image view dll aka Windows Picture and Fax Viewer Library
  DecRTE=0             ; 1=throw runtime error if GetProcAddress fails (default), 0=check eax instead
  Declare void ImageView_Fullscreen, 4            ; ImageView_Fullscreen expects 4 dwords but returns nothing useful
  .if eax
      ImageView_Fullscreen(0, 0, wCL$(1), SW_SHOW)      ; we need the wide version of the commandline arg
      Err$(0, "ImgView:")            ; there is no retval - you may test here for errors
      ; Err$(0, L)            ; same but titled "Error in line xx:"
  .else
      PrintLine "Problem with procedure: [", Trim$(Err$()),"]"            ; use Err$() without args for printing
  .endif
  Exit
end start
« Last Edit: November 10, 2014, 10:48:11 PM by jj2007 »

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: MasmBasic
« Reply #199 on: November 10, 2014, 11:35:52 PM »
Jochen,

Update 10 November: Launch$() is now thread-safe. This was never a problem in console apps, but GUI apps could occasionally choke. It's fixed.

well done.  :t

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Unicode file I/O
« Reply #200 on: November 17, 2014, 12:04:39 PM »
The MasmBasic update of 17 November (download) features a number of improvements under the hood, in particular an almost fool-proof handling of Unicode filenames. Example:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Let esi=wCL$()
  .if wExist(esi)
      wOpen "I", #1, esi
      wLet edi=Input$(#1, Lof(#1))
      Close
      wMsgBox 0, edi, wCat$("Contents of "+LastFileName$+":"), MB_OK
  .else
      wMsgBox 0, esi, "No such file:", MB_OK
  .endif
  Exit
end start


Among other improvements, MasmBasic's preferred editor, \Masm32\MasmBasic\RichMasm.exe, can now build directly with non-Latin alphabets:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  uMsgBox 0, "Добро пожаловать", "Hi", MB_OK
  Exit
end start

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: MasmBasic
« Reply #201 on: November 19, 2014, 04:05:05 AM »
Jochen,

your Russian is getting better and better.  :t And MasmBasic, too. That's clear.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Russian & Unicode
« Reply #202 on: November 19, 2014, 05:19:46 AM »
your Russian is getting better and better.  :t And MasmBasic, too. That's clear.

Gunther,
Thanks :P
I use Russian for Unicode demos because the font is installed on most machines (unlike Chinese, for example), but as a matter of fact, I did speak Russian when I was young. Now I've forgotten everything, since I never practised it seriously.

habran

  • Member
  • *****
  • Posts: 1179
    • uasm
Re: MasmBasic
« Reply #203 on: November 19, 2014, 07:03:39 AM »
I know the filling, I used to speak German when I was young but when I come to Australia(1992) I was mixing German with English, so I had to push the German somewhere deep in my memory and now it is hard to dig it out :biggrin:
Cod-Father

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: MasmBasic
« Reply #204 on: November 19, 2014, 07:57:23 AM »
Jochen,

I use Russian for Unicode demos because the font is installed on most machines (unlike Chinese, for example), but as a matter of fact, I did speak Russian when I was young. Now I've forgotten everything, since I never practised it seriously.

Интересно, так что вы не говорите по-русски.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Callback for GetFolders() and GetFiles()
« Reply #205 on: December 06, 2014, 01:05:24 PM »
Update of 6 December:

GfCallback defines a callback function to monitor progress in GetFiles or GetFolders:

      include \masm32\MasmBasic\MasmBasic.inc
      Init      ; <<< select init and hit F6 to test this snippet
      Let esi=ExpandEnv$("%WINDIR%")      ; usually C:\Windows
      PrintLine "Searching ", esi
      GfCallback cbGetFiles      ; define a callback function
      GetFolders esi
      Print Str$("\n%i folders found\n", eax)
      Exit

cbGetFiles:
      test edx, 1023      ; file or folder counter
      .if Zero?
            Print "*"      ; console mode progress bar ;-)
      .endif
      ret
      end start


jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
ToolTips, FileRead$(), GfCallback, Dim syntax
« Reply #206 on: December 09, 2014, 11:13:46 AM »
Minor fixes in MasmBasic version 9 December 2014 (download)

- ToolTips don't use edi ebx any more, i.e. you can use them in a loop; keep away from esi, though, and note that ecx will exceptionally be trashed here.

- the GetFiles GfCallback (examples) gives access to WIN32_FIND_DATAW in ebx (edx=file counter, edi=last path of FindFirstFileEx)

- Dim MyArray() As dword will choke now, and invite you to use uppercase DWORD (or BYTE, REAL8, whatever); note also that Dim without specifying the number of elements, i.e. Dim whatever() As WHATEVERSTRUCT is perfectly legal - same for strings and other types: MasmBasic arrays are dynamic. Just make sure you assign elements incrementally starting with zero, i.e. Let My$(0)="..." or mov MyRect(0, left)=123 etc

- FileRead$() occasionally threw generic API errors when the file was not found; now it chokes correctly with "can't find thatfile.txt"

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #207 on: December 16, 2014, 11:09:41 AM »
Minor update of 16 December 2014 (download)

One new feature: Extract$() has a new flag called xsScan, which serves to extract substrings sequentially using the same delimiter to the left and right. Example:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Let esi="My car,is,red,but, if it  ,was,  green,  I,  would,still,drive,it."
  .While 1
      .Break .if !Extract$(esi, ",", ",", xsScan or xsTrim)
      PrintLine "[", eax, "]"
  .Endw

  Inkey "ok?"
  Exit
end start


Output:
Code: [Select]
[My car]
[is]
[red]
[but]
[if it]
[was]
[green]
[I]
[would]
[still]
[drive]
[it.]
ok?

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: MasmBasic
« Reply #208 on: December 16, 2014, 08:37:36 PM »
Interesting feature, Jochen.  :t Well done.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 8889
  • Assembler is fun ;-)
    • MasmBasic
Files$() array from commandline
« Reply #209 on: December 24, 2014, 11:14:07 AM »
Update 24.12.2014 (download):

In addition to the standard file pattern, GetFiles can now take special arguments:

1. GetFiles <pattern>

  GetFiles *.asm           ; simple: puts all filenames from the current folder into the Files$() array
  GetFiles C:\Windows\System32\msvc*.dll|nt*.dll|nt*.exe
  SortFiles                ; sort the Files$() array by date, most recent files first
  For_ ebx=0 To eax-1      ; print the detailed results
      PrintLine Str$(GfSize(ebx)), Tb$, GfDate$(ebx), Spc2$, GfTime$(ebx), Tb$, Files$(ebx)
  Next



2. GetFiles CL (or GetFiles wCL for Unicode file names):

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  GetFiles CL              ; put filenames in the commandline into the Files$() array
  For_ ebx=0 To eax-1      ; print the results
      PrintLine Str$(GfSize(ebx)), Tb$, GfDate$(ebx), Spc2$, GfTime$(ebx), Tb$, "[", Left$(Files$(ebx), 90), "]"
  Next
  Inkey Str$("%i files found in commandline", ebx)
  Exit
end start



3. GetFiles WM_DROPFILES (in WndProc, main window must have WS_EX_ACCEPTFILES style):

  CASE WM_DROPFILES
      GetFiles WM_DROPFILES
      For_ ebx=0 To eax-1      ; show the files in the edit control
            AddWin$ hEdit=Str$(GfSize(ebx))+Tb$+GfDate$(ebx)+Spc2$+GfTime$(ebx)+Tb$+Files$(ebx)+CrLf$
      Next


#2 is handy when the user drags a group of files from Explorer over the name of the executable (i.e. the files are passed via the commandline).

#3 does the same but with files dropped over the window itself. During installation, you will see the MasmBasic guide; on top of the page, click on "File" to the left of the usual disclaimers apply, and choose "New Masm source". In the green window, click on Simple window in the upper left corner, hit F6 to build the application, then select files in Explorer and drag them over the application.