RetroBASIC

Basicprogramming(.org) => Community news and announcements => Topic started by: jj2007 on December 23, 2015, 06:41:56 pm

Title: MasmBasic
Post by: jj2007 on December 23, 2015, 06:41:56 pm
Hello everybody,

For those who don't yet know me from bp.org: I am Jochen, and my hobby is a particular dialect of BASIC:

MasmBasic "compiles" with the standard Microsoft macro assembler aka MASM (and some clones like JWasm (https://sourceforge.net/projects/jwasm/files/latest/download) and AsmC (https://sourceforge.net/projects/doszip/files/tools/asmc214.zip/download)).

The latest version is always available here at the Masm32 forum (http://masm32.com/board/index.php?topic=94.0). You can find a badly organised overview of the commands here (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm).

MasmBasic is extremely fast and strong on strings (including Unicode) but somewhat weak on arithmetics. Since it is an assembler library, you can do absolutely everything with it, provided your OS is Windows and an Intel or AMD CPU are working under the hood.

Latest features can always be found at the end of the Masm32 thread, currently here. (http://masm32.com/board/index.php?topic=94.msg61603#msg61603)

Here is a screenshot of an application showing three types of edit controls (Scintilla, ordinary Windows edit control, RichEdit) in a resizable window. The source code (here (http://masm32.com/board/index.php?topic=94.msg53140#msg53140)) is a whopping 18 lines long:(http://masm32.com/board/index.php?action=dlattach;topic=94.0;attach=4983;image)

P.S.: My sincere thanks to the Retrogamecoding Forum for hosting the "leftovers" of bp.org









Title: Re: MasmBasic
Post by: Richly on December 23, 2015, 11:05:52 pm
Hi JJ

Glad you found your way here too.

I didn't have your contact details to let you know about this place after BP.org expired but all's well that ends well  :)
Title: Sorting one Million strings per second
Post by: jj2007 on December 31, 2015, 08:40:28 am
MasmBasic update of 31.12.15 features ultra-fast Advanced string sorting (http://masm32.com/board/index.php?topic=94.msg53398#msg53398), plus a new function for the GUI fans:

include \masm32\MasmBasic\Res\MbGui.asm
Event Paint
  GuiImage "\Masm32\examples\exampl04\car\car.jpg", fit      ; fit=use full window
GuiEnd


All commands here (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm), step-by-step installation instructions here (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm).
Title: Re: Sorting one Million strings per second
Post by: Ed Davis on December 31, 2015, 01:30:46 pm
MasmBasic update of 31.12.15 features ultra-fast Advanced string sorting (http://masm32.com/board/index.php?topic=94.msg53398#msg53398),

How hard would it be for you to produce a version that is called as so:

sort input-file output-file

Reads input file, sorts it, and writes it back out to output-file.

Sorting should be case insensitive and stable.

I'd like to benchmark it against a few of my sorts, just to see how slow/fast mine are.

Thanks in any case!

Title: Re: Sorting one Million strings per second
Post by: jj2007 on December 31, 2015, 05:52:44 pm
Reads input file, sorts it, and writes it back out to output-file.

Sorting should be case insensitive and stable.

Hi Ed,

Despite its name, QSort is a stable merge sort. Here it is:

include \masm32\MasmBasic\MasmBasic.inc      ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  NanoTimer()
  Recall CL$(), L$()    ; CL$() = use commandline
  .if eax>1
      QSortMode cis
      QSort L$()
  .endif
  Store "Sorted.tmp", L$()
  Inkey Str$("%i lines written to Sorted.tmp", L$(?)), Str$(", %i ms incl. reading & writing", NanoTimer(ms))
EndOfCode


26902 lines written to Sorted.tmp, 12 ms incl. reading & writing

Note that this includes disk operations, so comparability may be low. Use a really fat file, e.g. bible.txt, and repeat the action two or three times to make sure the file content is in the disk cache.

QSortMode cis means case-insensitive
QSortMode cis, sls, MyIndexArray() would mean case-insensitive, skip leading spaces, use MyIndexArray() to keep track of original line index.

Let me know how it works out. And don't forget to celebrate the New Year ;-)

P.S.: New thread A simple chessboard (http://masm32.com/board/index.php?topic=4969.0), see second attachment.
Title: Gdi+
Post by: jj2007 on February 08, 2016, 09:52:01 am
Beta available here. (http://masm32.com/board/index.php?topic=5076.msg54935#msg54935) I hope the interface is intuitive and simple enough to qualify as "BASIC" ;-)

The new functions are not yet published at the Quick Reference (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm), but during the installation the help file opens. You may search for .MbMake

(http://masm32.com/board/index.php?action=dlattach;topic=5076.0;attach=5188;image)
Title: Re: MasmBasic
Post by: jj2007 on August 30, 2016, 11:35:35 am
MasmBasic was updated, download here (http://masm32.com/board/index.php?topic=94.0).

Latest changes:

- more complete dual 64/32 bit include files (no external libraries required)

- GetHash function:

include \masm32\MasmBasic\MasmBasic.inc
      Init
      Let esi=FileRead$("\Masm32\qEditor.exe")
      .if GetHash(esi, LastFileSize, sha)     ; FileRead$ sets LastFileSize, also for binary files
            PrintLine "The SHA of qEditor.exe is   ", Tb$, Hex$(xmm0), " ", Hex$(ecx)
      .else
            PrintLine "Hashing failed: ", Err$()
      .endif
      void GetHash(esi, LastFileSize)
      mov ecx, edx                              ; fifth word returned in edx
      Print "Fast MD5 of qEditor.exe is ", Tb$, Hex$(xmm0), CrLf$
      GetHashRev=1                              ; use official MD5 byte order
      .if GetHash(FileRead$("\Masm32\qEditor.exe"))   ; MD5, len of string will be calculated
            PrintLine "qEditor, byte order MD5 specs: ", Tb$, Hex$(xmm0)
      .endif
EndOfCode


- returns success (1) or failure (0) in eax
- four dwords are returned in xmm0
- in case of SHA, the fifth dword will be in edx
- results can be displayed as a Hex$(xmm0), plus Hex$(edx) for SHA. The byte order will be reversed, compared to
  online hash calculators. You may use GetHashRev=1 to follow the MD5 specs, but more code will be generated
- with only one para, GetHash calculates the length; this is meaningful only for text files

Output for the snippet:
Code: [Select]
The SHA of qEditor.exe is       F383E693 1F7D6EB5 B34F2B52 A30186C1 64050000
Fast MD5 of qEditor.exe is      A6869EAB 7FF88A6B 4E1F20CC 4F8E7DF7
qEditor, byte order MD5 specs:  F77D8E4F CC201F4E 6B8AF87F AB9E86A6
Title: Re: MasmBasic
Post by: jj2007 on November 07, 2016, 05:47:58 pm
Update 7 November (http://masm32.com/board/index.php?topic=94.msg61553#msg61553) got a few new features for displaying (and changing) images.

Simple example:
Code: [Select]
include \masm32\MasmBasic\Res\MbGui.asm
Event Paint
  GuiImage wCL$(), fit ; show what was passed via the commandline, fit to window size
GuiEnd

Works with Unicode file names, too.
Title: Re: MasmBasic
Post by: Mike Lobanovsky on November 07, 2016, 10:24:37 pm
Quote from: JJ on MASM32 forum
GuiImage "Это тест.jpg", fit     ; Unicode is allowed

Jochen,

Methinks you're under a wrong impression of the Russian-speaking world being someplace to the far east of you midway between Earth and Jupiter. :D

Russian per se does not require any Unicode excesses, and the 33 glyphs of Russian Cyrillic alphabet occupy the exact same placeholders in the Windows standard CP866, CP1251 and other non-Unicode code pages that your Italiano, Fran├žais and Deutsch accents, ligatures, umlauts and other diacritics would use in your respective national code pages for your own language-specific graphics exercises.

Does the Cyrillic alphabet really look to you so alien as e.g. Hiragana would? :D

BTW try to avoid using locale specific alphabets at all costs to store image files under because most of the professional-grade image processing packages would accept ASCII-only path and file names, and Windows ports of Linuxoid image processing software would also most likely fail with pathnames that contain space characters.


Quote from: JJ on MASM32 forum
MemState("WorkingSetSize, abs delta: %__i ", abs delta)

IMHO current GDI object counts would be much more characteristic of, and appropriate for, image processing operations in the app memory because there are lots of potential causes of memory leaks in a user application but GDI object/handle leaks would be directly related to the implementation quality of image processing strategies chosen.

Besides GDI object count would operate on much smaller figures that would make it easier for human perception.
Title: Re: MasmBasic
Post by: jj2007 on November 08, 2016, 12:44:54 am
BTW try to avoid using locale specific alphabets at all costs to store image files

Mike - I will avoid locale specific alphabets at all costs (I always did  :) )

But you pointed me to a little glitch that I fixed in version 8 November (http://masm32.com/board/index.php?topic=94.0), thanks ;)

I issued a bug warning here (http://masm32.com/board/index.php?topic=94.msg61643#msg61643).

Attached an image viewer and three images. Extract to a temp folder and start the exe. Arrow left/right scrolls through the images, r rotates right, l rotates left, s saves the rotated image (use at your own risk). Note it will not modify the timestamps when saving the image.

Btw how would you handle this in FBSL? Can you post a viewer that does the same?
Title: Re: MasmBasic
Post by: Mike Lobanovsky on November 08, 2016, 05:52:20 am
Mike - I will avoid locale specific alphabets at all costs (I always did  :) )

But you pointed me to a little glitch that I fixed in version 8 November (http://masm32.com/board/index.php?topic=94.0), thanks ;)

I issued a bug warning here (http://masm32.com/board/index.php?topic=94.msg61643#msg61643).

No Jochen,

I'm afraid you failed to take my advice for serious.

You see, Unicode is not a panacea. It is only as good as the codepages available on your computer. This is why FBSL v3.5 is ANSI and will remain ANSI for the time being. The cost of effort to move its handicrafted intrinsics to Unicode would be too high for me. I'm eager to spend the rest of my days on things in life more attractive than the failing patchwork of hotfixes that would need yet more and more crutches with every passing day. :)

Your message boxes don't display anything in Chinese that's not installed under my current system nor do your locale-specific Chinese and Arabic image files yield themselves for viewing unless of course they have eligible Russian names.

What regards pure Unicode-aware applications, they can be implemented in the current version of FBSL using Windows SDK style programming, even though FBSL's own intrinsics are ANSI only:

(http://www.fbsl.net/phpbb2/download/file.php?id=1956)

You can examine the relevant FBSL code here (http://www.fbsl.net/phpbb2/viewtopic.php?f=22&t=3087#p10778) but you'll be seeing what's in this snapshot only if you have both Hindi and rare Malayalam code pages and fonts installed on your PC.
Title: Re: MasmBasic
Post by: Mike Lobanovsky on November 08, 2016, 06:38:31 am
Btw how would you handle this in FBSL? Can you post a viewer that does the same?

1. I would handle that using the existing MMX-assisted DynAsm image processing library that's part of FBSL's 2D sprite engine. It allows for all sorts of anti-aliased transformations, including arbitrary angle rotation, of 32-bit translucent ARGB images in real time without resorting to 3rd party libraries like GDI+, which effectively makes it platform independent. It also offers 11 modes of color and alpha blending and lerping and pixel perfect collision detection of 2D sprite object instances built on top of that library.

2. No, I can't post an equivalent viewer because what I'd do would be, er, somewhat more elegant than your quick and dirty example. And it would be just as simple to build. Tell you what, have a look at my anti-aliased sprite resize example instead and don't hesitate to run the attached executable taking special note of the FPS rates on your PC. My readings for an original, minified and magnified cases within a 512x512 px area are shown below.

Here's the relevant code, hardly any longer or more complicated than yours for a Win SDK oriented programmer:

Code: [Select]
#Include <Include\Windows.inc>

' Sprite SDK
#Include "..\..\Library\CSprite2D.inc"
#Include "..\..\Library\Sprite2DLib.inc"

Dim Width As Integer = 512, Height As Integer = 512
Dim PS As String * 64, FPS As Integer
Dim Mx As Integer, My As Integer

' Fixed-size window
SetWindowLong(ME, GWL_STYLE, &H4C80000)(ME, GWL_EXSTYLE, &H40100)
Resize(ME, 0, 0, Width, Height, TRUE)

' Sprite instance creation
Dim SpBack As New CSprite2D(Width, Height)
Dim SpOrig As New CSprite2D
Dim SpTemp As New CSprite2D

' Texture load
SpOrig.LoadFromFile("..\Art\Auto.jpg")

Center(ME): Show(ME)

Begin Events
  Select Case CBMSG
    Case WM_COMMAND
      If CBWPARAM = IDCANCEL Then ' exit on VK_ESCAPE
        PostMessage(ME, WM_CLOSE, 0, 0)
        Return 0
      End If
    Case WM_MOUSEMOVE ' pic size follows mouse
      If LoWord(CBLPARAM) > 0 And HiWord(CBLPARAM) > 0 Then
        Mx = LoWord: My = HiWord
      End If
    Case WM_ERASEBKGND ' suppress flicker
      Return 1
    Case WM_PAINT ' render sprites
      Render(BeginPaint(ME, PS))
      EndPaint(ME, PS)
      InvalidateRect(ME, NULL, TRUE) ' initiate next render
      Return 0
    Case WM_CLOSE ' cleanup
      SpBack.Dispose()
      SpOrig.Dispose()
      SpTemp.Dispose()
  End Select
End Events
' ---------------------------------------------------------------------------------------------

Sub Render(hDC As Integer)
  Static NextTime, cb = ARgb(0, 0, 0, 0)
 
  Incr(FPS)
  If GetTickCount() > NextTime Then ' display info once a second
    NextTime = GetTickCount + 1000
    FbslSetText(ME, "Resize Sprite, FPS = " & FPS)
    FPS = 0
  End If
 
  SpBack.ClearBuffer(cb)
  SpTemp.LoadFromSprite(SpOrig, TrNone, Mx, My)
  SpBack.Draw(SpTemp, 0, 0)
  SpBack.PaintToDevice(hDC) ' copy to window
End Sub
Title: Re: MasmBasic
Post by: jj2007 on November 08, 2016, 07:45:57 am
This is why FBSL v3.5 is ANSI and will remain ANSI for the time being. The cost of effort to move its handicrafted intrinsics to Unicode would be too high for me. I'm eager to spend the rest of my days on things in life more attractive than the failing patchwork of hotfixes that would need yet more and more crutches with every passing day. :)

Mike,
I understand that would be a lot of work for you. Don't do it then.

Quote
Your message boxes don't display anything in Chinese that's not installed under my current system

Re the MessageBox example that you took from here (http://masm32.com/board/index.php?topic=94.msg61643#msg61643): Of course, if a language pack is not installed on your system, it won't display the text; but it launches the exe, apparently.

I tested your Resize.exe example, it works but the fan starts howling immediately, and one core is at 100%, even if I do nothing. Besides, it doesn't take other pictures when I drag them over the exe, it always shows auto.jpg, so I can't test it with the Chinese images. Is that desired behaviour?

Quote
nor do your locale-specific Chinese and Arabic image files yield themselves for viewing unless of course they have eligible Russian names.

Now that raises an interesting question: When you launch ImageViewAndRotate.exe in a folder with ???.jpg images, do you see the content of these images? I understand that the window titles don't display properly, but GetFiles (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1056) and the Files$() array should work independently of the installed code pages (because under the hood they use true Unicode); otherwise Windows itself is broken 8)
Title: Re: MasmBasic
Post by: Mike Lobanovsky on November 08, 2016, 07:47:44 pm
Re the MessageBox example that you took from here (http://masm32.com/board/index.php?topic=94.msg61643#msg61643): Of course, if a language pack is not installed on your system, it won't display the text; but it launches the exe, apparently.

Evening Jochen,

Yes, it does launch the Окносообщения.exe module but only because the Russian codepages are installed under my XP Sp3 Pro Rus and the system PE loader can make out the module file name's characters and tell them from a string of control characters of unknown origin and/or intent. Had the file been called 您可以将中文文本传递到应用程序。.exe, whatever that means, the PE loader would report file corruption with unpredictable consequences to the integrity of the system. (I wouldn't allow it to even attempt lauching your sample in this case though.)

Tell you more, file name corruption was widely popular as an exploit for the creation of unkillable bootable USB stick virii some half a decade ago or so. The virus would create a hidden System Volume Information folder (which is nothing unusual for Vista+ platforms) but with spaces denoted by unpermissible characters on a USB stick that never saw anything better than an XP! The spaces would make the "folder" undeletable and, moreover, unkillable even with the system's standard deep formatting! The system would just mark those USB sectors as bad but wouldn't delete the actual data written in them. So, the virus would then go dormant till the user decided to burn or copy a bootable ISO image onto their CD/DVD drive or USB stick/disk, in which case the virus would create a jump to the "bad" sectors from the stick's or disk's MBR (master boot record). The system being started from such an infected ISO image is yet unaware of any bad sectors in its data storage devices when it's still in the first 512 bytes of its MBR, so it would obediently jump over there to execute whatever the virus had to offer in its "System Volume Information" sectors. :o

Moreover, Ubuntu that's installed on one of my multi-bootable disks with shared folders would use its standard screen capture utility to save its screenshots under unique PNG names but in a YYYY:MM:DD:HH:MM:SS.PNG format with literal colons in it! The other Windows systems installed on the same physical disk wouldn't quite naturally accept those files as valid images but, what's the worst thing of all, they wouldn't allow me to rename, move or even delete them either! Bravo Linux and Linuxoids! You're halfway there to creating yet another virus on my Windows PC! ;)

Quote
I tested your Resize.exe example, it works but the fan starts howling immediately, and one core is at 100%, even if I do nothing. Besides, it doesn't take other pictures when I drag them over the exe, it always shows auto.jpg, so I can't test it with the Chinese images. Is that desired behaviour?

The desired behavior of this sample is to show off the real speed with which the library is able to perform anti-aliased transformations, rather than what damage can be done to the OS file system with compromised image file names and time stamps that meddle with the NTFS security layout.

100% on just one core out of four wouldn't do any harm to your laptop and is only 25% of the total, after all. As you can see from the code, only the following lines are responsible for rendering while all the rest is just Windows standard app launching/benchmarking stuff: (pseudocode!)

Code: [Select]
    Case WM_PAINT ' render sprites
      Render(BeginPaint(ME, PS))
          SpBack.ClearBuffer(cb)
          SpTemp.LoadFromSprite(SpOrig, TrNone, Mx, My)
          SpBack.Draw(SpTemp, 0, 0)
          SpBack.PaintToDevice(hDC) ' copy to window
      EndPaint(ME, PS)
      InvalidateRect(ME, NULL, TRUE) ' !!! THIS IMMEDIATELY INVALIDATES WHAT'S JUST BEEN PAINTED TO INITIATE NEXT RENDER WITHOUT ANY DELAYS TO COOL OFF YOUR CPU/GPU/WHATEVER !!!

That's a standard procedure for GDI benchmarking and that's effectively also how DirectX and OpenGL would operate when your GPU is set to favor speed over quality (no VSYNC-ing et al.)

Now open up your ImageViewAndRotate, drag some (Chinese) photo onto it, maximize the window and keep on pressing your R key for awhile only to see your CPU rise up to 25% and your fans go humming again. So, is your viewer in fact any better than mine? ;)

Quote
Now that raises an interesting question: When you launch ImageViewAndRotate.exe in a folder with ? ? ?.jpg images, do you see the content of these images? I understand that the window titles don't display properly, but GetFiles (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1056) and the Files$() array should work ...

No, the content of these images is never shown in either your viewer or my authentic ACDSee Photo Editor I used to pay a damned lot of hard cash for. (I thought you'd be able to read its blue window messages since you seem to be so fond of Russian sample stuff... :) ) It says it couldn't find the respective image files and that they probably had been moved or deleted before it could decode them etc., except of course for my avatar that it obediently shows in its preview.
Title: Re: MasmBasic
Post by: jj2007 on November 09, 2016, 12:34:00 am
Mike is pushing me to explore the limits of Unicode :)

Attached two new examples - extract to a new folder, launch
Code: [Select]
a) LaunchUnicodeExes.exe (should produce what's shown in the screenshot)
b) ImageViewAndRotate.exe
to test them. Grateful for feedback 8)

Sources are included as *.asc files, building requires Masm32 and the latest November 9 MasmBasic. (http://masm32.com/board/index.php?topic=94.0)
Title: Re: MasmBasic
Post by: Mike Lobanovsky on November 09, 2016, 02:35:02 am
Jochen,

I'm greatful for the invitation and also for choosing my avatar for your experimentation (I wish I could do the same in return on the FBSL forum) but I won't run your exe pack on my machines for the reasons I've stated earlier regarding the validity of executable file names and the uncertainty of the outcome of such experimentation from the file system integrity perspective.

I am sorry but that's the point I'm going to stand by, paranoia or schizophrenia, whatever. :)
Title: Re: MasmBasic
Post by: jj2007 on November 09, 2016, 10:17:58 am
validity of executable file names and the uncertainty of the outcome of such experimentation from the file system integrity perspective.

Mike,

These are absolutely valid Unicode file names. Microsoft takes pride in that, and if a Billion Chinese users had the same fear as you, it would be bad for their business.

At least on my Italian OS, none of these exes had any problems *)

You might check your views on locales. Afaik Windows Explorer doesn't care for locales, it just uses Unicode under the hood, even if it can't display the font. Do you see them in Explorer, actually? I see all file names properly, and I doubt that all these fonts are installed by default.

It is a problem, though, for non-Unicode file managers like my old FreeCommander version. When I double-click the ? ? ? ? ? ? ? ?.exe, nothing happens. However, even then, file integrity problems should be a phenomenon of the very very early days of Windows.

P.S.: I've had a look at MSDN, who confirm what I wrote on the use of Unicode above. There is one notable exception: The use of the Yen symbol in applications that work on FAT filesystems (https://msdn.microsoft.com/en-us/library/windows/desktop/dd374047(v=vs.85).aspx#SC_char_sets_in_file_names):
Quote
For security reasons, your applications should not typically allow the character U+00A5 in a Unicode string that might be converted for use as a FAT file name.

*) I just tested the PlayingWithUnicode.zip attached above also on a FAT32 USB stick. Everything works like a charm, including saving rotated images in Hindi, Chinese, Russian etc; I did a scandisk afterwards, no problems found.
Title: Re: MasmBasic
Post by: Mike Lobanovsky on November 09, 2016, 09:03:40 pm
This is a "clean" (of all localization packs; LCID=1033) installation of Win 7 Pro Sp1 I'm using for C/C++ development:
Title: Re: MasmBasic
Post by: jj2007 on November 10, 2016, 01:44:43 am
This is a "clean" (of all localization packs; LCID=1033) installation of Win 7 Pro Sp1 I'm using for C/C++ development:

Thanks, Mike. Weird that Explorer can handle Unicode filenames (the images are loaded etc) but can't display them, while the message boxes have a bad caption but Chinese text is displayed properly. Mysteries of Windows 8)
Title: Re: MasmBasic
Post by: Mike Lobanovsky on November 10, 2016, 07:42:42 am
Mysteries of Windows 8)

Yeah, there's also absolutely no problem with net browsing either. Prolly all major browsers have their own locale support utils to cover most if not all of the browser page text requests. I wish I knew how to handle those to be able to use them too on the installations that don't support those CPs and fonts officially. ;)
Title: Displaying animated GIF images
Post by: jj2007 on November 26, 2016, 09:43:56 am
Download update 26 Nov 16: (http://masm32.com/board/index.php?topic=94.0)

Inter alia, GuiImage handles now animated GIFs automatically; search \Masm32\MasmBasic\MbGuide.rtf for .MbGui

Example (a complete Windows GUI application with a sizeable window):
Code: [Select]
include \masm32\MasmBasic\Res\MbGui.asm
Event Paint
  GuiImage "http://retrogamecoding.org/board/index.php?action=dlattach;attach=1045;type=avatar", fit
GuiEnd

The more elaborate attached demo displays (provided MasmBasic is installed (http://masm32.com/board/index.php?topic=94.0))
- a static background car.jpg
- an avatar (members only, sorry :biggrin:)
- a smiley (the car needed a little decoration)
- and an animated GIF from the resources
Title: Re: MasmBasic
Post by: jj2007 on December 02, 2016, 09:14:24 am
MasmBasic update 2 December (http://masm32.com/board/index.php?topic=94.0) got several new features (see here for some examples (http://masm32.com/board/index.php?topic=94.msg61658#msg61658)), inter alia the StringToArray function (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1130) can now be fed with files from disk, from the internet, and with a text file embedded in the resouce section:

include \masm32\MasmBasic\MasmBasic.inc Init
  StringToArray 123, my$()            ; 123 is the resource ID
  For_ ct=0 To Min(39, eax)            ; loop max 40 times
      PrintLine Str$("Line %i\t", ct), my$(ct)
  Next
  Inkey "--- hit any key ---"
EndOfCode

Rsrc            ; when hitting F6, RichMasm exports this section to [filename].rc
123 RCDATA "\\Masm32\\MasmBasic\\MasmBasic.inc"
Rsrc
Title: MasmBasic hits the 400 commands mark
Post by: jj2007 on November 09, 2017, 08:38:41 am
Version 8 November 2017 is ready to be installed. (http://masm32.com/board/index.php?topic=94.0) Changes:

- updated help file, with now 400+ macros documented (also online - use Ctrl F to find commands (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm); but remember the best help option is to use RichMasm, hover over a keyword like Open, then right-click on the word and copy the line that fits your case)

- fDate$() and fTime$() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1267) can now take a third parameter to force any language:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Print "Right now, ", fDate$(0, "dddd dd MMMM yyyy "), fTime$(0, "HH:mm:ss"), Str$(", we are in ISO week %i\n", IsoWeek())
  Print fDate$(0, "dddd dd MMMM yyyy ", russian), fTime$(0, "HH:mm"), Str$(", мы находимся в ИСО неделе %i", IsoWeek())
  wMsgBox 0, wCat$(wfDate$(0, "dddd dd MMMM yyyy ", hindi)+wfTime$(0)), "This is Unicode:", MB_OK
EndOfCode

Output:
Right now, Wednesday 08 November 2017 04:55:26, we are in ISO week 45
среда 08 ноября 2017 04:55, мы находимся в ИСО неделе 45


- SetInt can now move the content of ST(0) to xmm0:
  fldpi
  Print Str$("PI=\t%Jf\n", ST(0))
  fmul FP4(100.0)
  SetInt ecx
  Print Str$("100*PI=\t %i\n", ecx)
  fldpi
  fmul FP8(10.0e16)
  SetInt xmm0
  Print Str$("100*PI=\t %i\n", xmm0)


Code: [Select]
Output:
PI=     3.141592653589793238
100*PI=  314
10e16*PI=314159265358979324

- finally, the ternary operator If? can now also take the Zero? and Carry? flags as input (testbed attached):

  xor ecx, ecx
  Print Str$("zero flag set: %i\txor ecx, ecx\n", If?(zero?, 111, 222))         ; prints first number, 111
  or ecx, -1
  Print Str$("zero flag set: %i\tor ecx, -1\n", If?(zero?, 111, 222))   ; prints second number, 222
  stc
  Print Str$("carry set: %i\tstc\n", If?(Carry?, 111, 222))     ; carry is set, prints 111
  clc
  Print Str$("carry set: %i\tclc\n", If?(Carry?, 111, 222))     ; carry clear, prints 222
Title: Re: MasmBasic
Post by: B+ on November 09, 2017, 06:19:37 pm
Hi JJ,

Congratulations! How do you count it when macro name is same but has optional parameter, one or two?
Title: Re: MasmBasic
Post by: jj2007 on November 09, 2017, 11:48:57 pm
Then it's normally one macro only. However, the wide versions (wOpen, wPrint, ...) count as separate macros.
Title: Re: MasmBasic
Post by: jj2007 on December 26, 2017, 01:09:14 am
MasmBasic got updated, see download and installation (http://masm32.com/board/index.php?topic=94.0). Inter alia, many standard Windows controls are now easily accessible via the GuiControl command:
Code: [Select]
include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyEdit, "richedit", NoTag$(FileRead$("http://retrogamecoding.org/board/index.php?board=17.0"))
GuiEnd

This is sufficient to create a full-fledged Windows application. Here is a more elaborate example (http://masm32.com/board/index.php?topic=94.msg72735#msg72735) of an application with 18 controls, like edit, static, richedit, syslink, date & time, progressbar, trackbar, etc.
(http://masm32.com/board/index.php?action=dlattach;topic=94.0;attach=7435;image)

Btw with 5319 characters in 80 lines, the source for this demo would have fit into the 100 Line-of-Code Programming Language Competition:
The limit is 255 characters X 100 lines = 25500 characters, that is a clear limit.
Title: Re: MasmBasic
Post by: jj2007 on November 28, 2018, 12:35:41 pm
News from the MasmBasic subforum: (http://masm32.com/board/index.php?topic=7552.0)

(http://www.webalice.it/jj2006/pics/PlottingData.png)

The source (requires the Masm32 SDK plus the MasmBasic library (http://masm32.com/board/index.php?topic=94.0)):

GuiParas equ "Plot sinus & cosinus curves", x600, y100, w600, h500, bRgbCol(192, 255, 255)
include \masm32\MasmBasic\Res\MbGui.asm
  Dim MySinus() As REAL4                       ; REAL4 precision is enough ...
  Dim MyCosinus() As REAL8                     ; ... but REAL8 is ok, too
  For_ ecx=0 To 359
        SetFloat MySinus(ecx)=Sinus(ecx)       ; fill an array
        SetFloat MyCosinus(ecx)=Cosinus(ecx)   ; you may use ArrayRead for reading data from a file
  Next
  MakeFont hHorzFont, Height:18, Weight:FW_SEMIBOLD, Italic:TRUE
  MakeFont hVertFont, Height:18, Weight:FW_SEMIBOLD, Escapement:900, Italic:FALSE
  MakePen hPenAxis, RgbCol(255, 0, 0)
  MakePen hPenGrid, RgbCol(255, 255, 222), width 2
  SetAxisX "degrees", s 0, d 15.0/3, grid 1, penx hPenAxis, peng hPenGrid, font hHorzFont, format "%i" ; s=start value, d=difference between gridlines
  SetAxisY "sinus & cosinus", s -1, d 0.2/5, grid 2, font hVertFont, format "%2f"
  $Data "Plotting an array of points is very easy: All you need is the array itself, plus a Paint event that draws it."
  $Data "The axes can be set using SetAxisX and SetAxisY, taking arguments as shown in the source. Now resize this window to see how it behaves"
  Read desc$()                          ; read a string array from $Data
  Event Paint
  ArrayPlot MySinus(), RgbCol(255, 222, 160), 2, 00000110h, 0, -1, 1    ; red sinus, 2px wide; use margins left top right bottom, min0, max-1, filled=1 ArrayPlot MyCosinus(), RgbCol(0, 0, 255)             ; plot the cosinus array in blue, same margins as previous plot
  ArrayPlot exit, 0150006028# "Sinus & Cosinus"        ; finish with a title; optional: xxxxyyyyFF#: x, y pos, font size
  GuiTextBox 12, 100.0-80, 440, 66, Join$(desc$(), " "), bcol RgbCol(192, 255, 192)
  GuiEnd


Project attached. To build it, open the *.asc file in \Masm32\MasmBasic\RichMasm.exe and hit F6.
Title: Re: MasmBasic
Post by: jj2007 on April 02, 2019, 02:47:24 am
(https://www.santamarinellaoggi.it/images/GlobalWarming.png)

Source (67 lines of code) and data are attached; building requires MasmBasic version 2 April 2019 or later (http://masm32.com/board/index.php?topic=94.0), plus the Masm32 SDK (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm)
Title: Re: MasmBasic
Post by: jj2007 on May 08, 2019, 02:13:12 pm
MasmBasic version 8 May 2019 (http://masm32.com/board/index.php?topic=94.0) features some improvements under the hood, plus more comfortable working with maps. Below a screenshot, these 14 lines of code are the source:

include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyMap, "canvas", w660
  GuiControl TheManual, "richedit", res:92, x660, w340, bcol RgbCol(255, 255, 222)
  GuiControl Sbar, "statusbar", bcol RgbCol(255, 0, 0), wRec$("Click into a country / Нажмите в страну / 點擊進入一個國家 - this toolbar uses common controls version "+ComCtl32$()), font -16:FW_SEMIBOLD
  ArrayLoadMap 0, 90                    ; Europe.dmi and Europe.map in resources
  MapColours(0, "abcdefghiabcdefghiabcdefghiabcdefghiabcdefghiabcdefghi")      ; set colours to map 0 (a=red, i=green)
Event CanvasPaint
  ArrayPlot RgbCol(0, 240, 255)         ; init and set background colour
  PaintMap RgbCol(127, 127, 127), lines=2       ; map with grey borders 2px thick
  ArrayPlot exit, "Europe"
  GuiTextBox 99.0-120, 52.0, 120, 60, "This program requires the file Europe.map", bcol LiteGreen, font -18:FW_NORMAL
Event Message
  If_ uMsg_==WM_MAPCLICKED Then <SetWin$ hSbar=If?(MapRegion ge 0, "You clicked on "+MapRegion$, Time$)>
GuiEnd


(https://www.santamarinellaoggi.it/images/MapViewer.png)
Title: Fast and powerful string sort
Post by: jj2007 on August 22, 2019, 12:01:05 pm
The new MasmBasic version of 20 August 2019 (http://masm32.com/board/index.php?topic=94.0) features an improved sort algo. Case-sensitive sorts are now over 20% faster, case-insensitive sorting is now almost a factor 3 faster.
Code: [Select]
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz

sorting 1000000 lines case-insensitive took 504 ms
AAaAHZybMJfIBMDPTlGpjvUIKUAUarYYBhwoQzXDbBiAcpCJBdWibuPGKXCeSrAcOsQVouKGLUtXF
aAABoYraUmtdbUjgRDbugWslpjAUIKuszBiOYgbGgDwawBsyfUTodDuktDyLUCdtDSYqIFfwxoBlKDfbiuHQ
aaadeaEoIYWvHUzkSOtliXprvQLwLRmQtZnACEWprRsosQEBCExqPRkIFHyxbkWHovUZtDOKw
...
ZZzyzetRGgWITClgQOTutTCdCiuHMxPNPuxGIsUFqStMIuIRPqlWpHdzyckcajQMCgNTbYzilNuy
zzZzcsrZGTHbiajufJIMXwWdbKFncznEBmlSLCGJBKFTHoixDzzNgeXSRohyfJHAQreI
zZZzToOoFStspcNrVaEIfjsxTNFZWUIwVWqxrzppJBjnxhbFgXmoCjUQxitzjpsLsmkTJefTDsKUKDj

sorting 1000000 lines case-sensitive took 444 ms
AAAJkbfOkQBObDHcbTIwHpqfZhoeEAOdznaOpVJqBwanparynNfGQbaMfZwqeWVzuereGocrnKWbAx
AAAKDBqCLIvtYhNOwRHDkUdYhtCnqVlAtRxBIyOmZtyRTJmmduoLcogeGKDYzS
AAANyurgtXuGMSDjUiphJpjDEIXsqWblivOefMURODFFRLEmyNHboCtnRgrrGsTpQXBZ
...
zzzMNTYBXQesyiSPhDSnEMllmqJyPOetjQASwTjPPdMGALxaTsXIBwpiDnRqaG
zzzWKRnlAPdJrfgIgiHjbJTvoMgrRnxVAukqhhjMqshOgVAuaGceqItZADoDlNBtykFZjwKyKuMhTJeu
zzzYZAgWBUtSZfUmlAWnFFRpDcGgwdOFndrhSJZcyMsgkvLnTOTRmUtwjKvNKJndDYagMFDBnZQduJzTADOTbIsyx

P.S.: A fat text file for testing sort algorithms is here (http://www.jj2007.eu/TextForSorting.zip). To test them, extract the exe attached below to a folder, then open a DOS prompt and run it e.g. as MbSortText.exe RandSheet.tab

The example text files are tab-delimited, so that they are useful to test the sort-by-column feature of QSort(). (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1175) With sort algos that do not have such a feature, they behave like a normal text file, i.e. the tabs will be ignored.
Title: Re: MasmBasic
Post by: Aurel on August 26, 2019, 11:09:15 am
Quote
Case-sensitive sorts are now over 20% faster

that sounds great JJ
now
i am wondering is it possible on reletive easy way to made fast tokenizer or maybe
even complete interpreter using MASM + MasmBasic to one standalone exe?
what you think about that?
Title: Re: MasmBasic
Post by: jj2007 on August 26, 2019, 12:59:23 pm
Hi Aurel,

MasmBasic is strong on strings (but a bit weak on numbers). So yes, a fast tokeniser would be possible.

With Recall somefile, some$() (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1172) you load your source into a string array, then you need to parse each line for labels, keywords, arguments etc.

Instr() (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1153) is your friend. And many more functions; besides, you can use plain assembler, too. These functions are really, really fast, about twice as fast as equivalent C code.

Do you have an example of a source using your interpreted language?
Title: Re: MasmBasic
Post by: Aurel on August 26, 2019, 01:32:09 pm
no i don't have
i have things written in o2
but then i can use o2 assembly even i think that is not fast as masm
and of course i don't know assembly programming
in first place i am just wondering...ok ?