Author Topic: MasmBasic  (Read 153544 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
GetProcessArray()
« Reply #300 on: November 26, 2015, 10:32:53 AM »
As a complement to GetRegKeyArray and GetRegArray:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Print "ct", Tb$, "ID", Tb$, "path"
  For_ n=0 To GetProcessArray(?)-1
      Print Str$("\n%i\t", n), Str$(MbProcID(n)), Tb$, MbProc$(n)
  Next
  Inkey CrLf$, "--- hit any key ---"
EndOfCode


Output:
Code: [Select]
ct      ID      path
1       324     \Device\HarddiskVolume3\Windows\System32\smss.exe
2       692     \Device\HarddiskVolume3\Windows\System32\wininit.exe
3       752     \Device\HarddiskVolume3\Windows\System32\services.exe
4       772     \Device\HarddiskVolume3\Windows\System32\lsass.exe
5       780     \Device\HarddiskVolume3\Windows\System32\lsm.exe
6       888     \Device\HarddiskVolume3\Windows\System32\winlogon.exe
7       924     \Device\HarddiskVolume3\Windows\System32\svchost.exe
8       992     \Device\HarddiskVolume3\Windows\System32\nvvsvc.exe
...

Source & exe attached, building requires latest MasmBasic version.

Oliver Scantleberry

  • Guest
Re: MasmBasic
« Reply #301 on: November 28, 2015, 03:08:25 PM »
MasmBasic is a library that allows to use BASIC syntax in assembler. . .

This is absolutely brilliant! I have been programming Intel processors in Assembly Language since 1975. In fact, hand-assembling the first few years. What I have always dreamed of, is using Microsoft 4k Basic syntax in assembly. Wow! This guy JJ is just awesome! He knows what everybody wants! I am thrilled!

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #302 on: November 28, 2015, 08:14:34 PM »
i think Jochen has a new fan   :biggrin:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #303 on: November 28, 2015, 08:26:52 PM »
At least one :P

He knows what everybody wants! I am thrilled!

Thanks, although I am not so convinced ::)
I would be stinkin' rich if that bold statement was true :bgrin:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
WebCam and Scintilla
« Reply #304 on: December 02, 2015, 11:04:53 AM »
MasmBasic version 2 December '15 features two new templates called Scintilla+RichEdit and WebCam. The latter is a bit long to post here, but here is a choice of three edit controls (plus a listbox) in less than 20 lines:

include \masm32\MasmBasic\Res\MbGui.asm      ; OPT_Icon Smiley
  GuiControl MySci, "scintilla", h 333, w 750, text "Привет, это контроль Scintilla"      ; h 333 = 1/3 of height
  GuiControl MyEdit, "edit", y 336, h 333, w 750, text "Это нормальная управления редактирования."
  GuiControl MyRich, "richedit", y 672, h 333, w 750, text "Это контрольный RichEdit."
  GuiControl MyListbox, "listbox", x 750, w 250
  GetFiles *.asm             ; fill Files$() array
  SortFiles                  ; most recent on top
  SetListbox "** select a file **"
  SetListbox Files$()
  SetGlobals cursel, f$
Event Command
  .if IsTrue(LbSel ne cursel) && signed LbSel>0
      m2m cursel, LbSel
      Let f$=FileRead$(LbSel$)
      SetWin$ hMySci=f$, sci
      SetWin$ hMyEdit=f$
      SetWin$ hMyRich=f$
  .endif
GuiEnd


As you can see above, Unicode is fine for these controls, and with MasmBasic's RichMasm editor you can type Chinese or Russian or whatever directly into the source code.

The snippet assumes \Masm32\wscite\SciLexer.dll; add YOUR path before the GuiControl if needed, for example:
ScintillaPath equ "\Masm32\bin\SciLexer.dll"

The Scintilla DLL is available here, see "A full download (1200K) includes the SciTE executable, any required DLLs". Extract to \Masm32\ to get the wscite folder and SciLexer.dll (the only file you need from the package to run the three edit controls example)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
GetFiles is now UTF-8
« Reply #305 on: December 12, 2015, 11:28:29 AM »
MasmBasic update 12 Dec 2015 features a major change under the hood: GetFiles returns now UTF-8 file names. This has no effect on file names using only Ansi characters, but it is a major improvement for those who use Russian, Chinese or Arabic file names (and that is quite a lot of people...). The snippet below shows its usage:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  SetCpUtf8
  GfCallback MyCb      ; set callback function for GetFiles
  GetFiles \Masm32\*.bas|*.inc|*.as?|*.rc      ; fill the Files$() array
  PrintLine Str$("\n%i files found. Newest files:\n", eax)
  SortFiles                  ; new files on top
  For_ ecx=0 To eax-1
      lea edx, [Files$(?)-10]      ; somearray(?) means #elements
      .if ecx<10 || ecx>=edx
            If_ Zero? Then PrintLine CrLf$, "Oldest files:"
            PrintLine Str$(GfSize(ecx)), Tb$, GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$, Files$(ecx)
      .endif
  Next
  Inkey "---- hit any key ----"
  Exit

MyCb:            ; simple callback: ecx is file counter, esi current file in Unicode format
  If_ wInstr(esi, wChr$("msv"), 1) Then wPrintLine esi      ; demo for filtering output
  ret
end start


Output (shortened):
Code: [Select]
comsvcs.inc
msv1_0.inc
msvcrt.inc
msvcrt.inc
msvcrt

8868 files found. Newest files:
327013  12.12.2015  01:14:55    \Masm32\MasmBasic\MasmBasic.inc
1985    12.12.2015  01:13:22    \Masm32\MasmBasic\AscUser\NewSources.asc
1032520 11.12.2015  11:25:24    \Masm32\RichMasm\RichMasm.asc
620     11.12.2015  08:18:32    \Masm32\MasmBasic\TestMasmBasic.rc

Oldest files:
288     07.09.1998  14:17:58    \Masm32\examples\exampl01\filtinpt\rsrc.rc
288     07.09.1998  14:17:58    \Masm32\examples\exampl01\comctls\rsrc.rc
288     07.09.1998  14:17:58    \Masm32\examples\exampl01\dll\loaddll\rsrc.rc
288     07.09.1998  14:17:58    \Masm32\examples\exampl01\3dframes\rsrc.rc
288     07.09.1998  14:17:58    \Masm32\examples\exampl01\dll\calldll\rsrc.rc

The snippet shows also how to use a callback function for GetFiles. If you return -111 in ecx, the current file will not be added to the Files$() array. Source & exe attached. Feedback, in particular from non-English members, appreciated :t

Oliver Scantleberry

  • Guest
Re: GetFiles is now UTF-8
« Reply #306 on: December 14, 2015, 01:33:13 PM »
MasmBasic update 12 Dec 2015 features a major change under the hood: GetFiles returns now UTF-8 file names. This has no effect on file names using only Ansi characters, but it is a major improvement for those who use Russian, Chinese or Arabic file names (and that is quite a lot of people...). . .

If I ever decide to program in assembly using Russian, Chinese, or Arabic, I will definitely give MbasicBasic a try. I'm right on top of Russian and Chinese but I need a little more work with Arabic. I keep reading it left to right.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
Unicode
« Reply #307 on: December 23, 2015, 04:49:47 PM »
MasmBasic update of 23 December 2015 improves and simplifies the use of Unicode & UTF-8 encoded charsets. This example shows recent sources in a listbox, and you can open them by double-clicking on an entry (source & exe attached):

include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyLb, "listbox", y60, h940
  GuiControl MyEd, "static", text "Double-click to open a file - Дважды щелкните, чтобы открыть файл", h50
  GetFiles *.as?|*.rc      ; asc, asm, rc
  SortFiles                 ; latest files on top
  SetListbox Files$()      ; Fill the listbox with UTF-8 encoded file names
Event Command
  If_ NotifyCode==LBN_DBLCLK Then uShEx LbSel$   ; open selected file with ShellExecuteW (u=assume UTF-8 for LbSel$)
GuiEnd


Second example (screenshot below, source attached) shows three edit controls: Scintilla, ordinary "edit" and RichEdit. The program is resizable, and the controls adjust their sizes proportionally based on this simple syntax:

  GuiControl MySci, "scintilla", h500, x250, w300, text "... initial text ..."
  GuiControl MyEdit, "edit", y500, h500, x250, w300, text "..."
  GuiControl MyRich, "richedit", x550, w450, text "..."
  GuiControl MyListbox, "listbox", w250


MyEdit, for example, is positioned at x=25% of client area, y=50%, 30% wide and 50% high.
MyListbox is positioned at default x+y positions, i.e. top left, full height and 25% width.

guga

  • Member
  • ****
  • Posts: 826
  • Assembly is a state of art.
    • RosAsm
Re: MasmBasic
« Reply #308 on: December 24, 2015, 06:41:11 AM »
All i can say is WOW !!!!!

How you managed to hide the code from the rtf on right click ?

And the sinus example ! Loved it !
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Grincheux

  • Member
  • ***
  • Posts: 328
  • Never be pleased, Always improve
    • Asm for fun
Re: MasmBasic
« Reply #309 on: December 24, 2015, 07:06:49 AM »
I launched NewSources and it told me

Quote

0 files found. Newest files:

---- hit any key ----

Does not like Frenchies this program!!!

The two others programs run OK.
Kenavo (Bye)
----------------------
Asm for Fun
My Links
"La garde meurt mais ne rend pas"
Cambronne à Waterloo

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #310 on: December 24, 2015, 07:08:57 AM »
Thank you, Guga, that was a nice feedback :P

But what do you mean with "hide the code from the rtf on right click" ?

guga

  • Member
  • ****
  • Posts: 826
  • Assembly is a state of art.
    • RosAsm
Re: MasmBasic
« Reply #311 on: December 24, 2015, 11:02:08 AM »
Hmm...I found this feature while reading MasmBasic guide. The feature is the same behaviour as in Radasm.

In Radasm, when you click on a token or a macro ("If" macro or the ones marked with a "+" sign), the text is hidden. Ex:
Code: [Select]
If eax = 5
   mov eax 1558
End_If

When you click in the "If" string, the text is hidden and it displays only this:

Code: [Select]
If eax = 5
End_If

Yours interface is different then in Radasm, but the behaviour is similar. What i liked on yours is the way we can actually read things on the richedit control. The ability to read the hyperlinks is great, and the way the help is displayed on certain mouse clicks, such this "hidden" of part of the text, or when you click on a string that may be a defined token and shows up a sort of help of what it is

On yours, I did this...before clicking on the word "Init"

Code: [Select]
include \masm32\MasmBasic\MasmBasic.inc
;   hit F6 to assemble, link & run the Hello World example
  Init
  ; to test examples, replace the white line with your test code and press F6
  MsgBox 0, "Wow, it works!!!!", "Hi", MB_OK ; It worked? Use a template, or try 90+ snippets
  Print CrLf$, "OK - press any key" ; It choked? Read below about JWasm.
  Exit
end start

After waiting 2 seconds, the mouse pointer changed to a question mark and  it displayed this on a different color. (Also, the new text that shows can be scrolled. I simply loved that !:


Code: [Select]
include \masm32\MasmBasic\MasmBasic.inc
;   hit F6 to assemble, link & run the Hello World example
  Init
------------------------------------------------------------------------------------------------- <-------- This showed and it can be scrolled
Init This is perhaps the smallest possible complete Masm application:
include \masm32\MasmBasic\MasmBasic.inc
Init
Inkey "Hello World"
Exit
end start
Rem - the Init macro inserts the following two lines:
-------------------------------------------------------------------------------------------------<-------- This showed and it can be scrolled

  ; to test examples, replace the white line with your test code and press F6
  MsgBox 0, "Wow, it works!!!!", "Hi", MB_OK ; It worked? Use a template, or try 90+ snippets
  Print CrLf$, "OK - press any key" ; It choked? Read below about JWasm.
  Exit
end start


How you managed to do that on a richedit control ?????
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #312 on: December 24, 2015, 08:14:38 PM »
After waiting 2 seconds, the mouse pointer changed to a question mark and  it displayed this on a different color. (Also, the new text that shows can be scrolled. I simply loved that !:
..
How you managed to do that on a richedit control ?????

Well, two richedit controls ;-)

When you hover over a keyword, e.g. GetFiles *.asm, and you right-click when the cursor changes to ?, RichMasm displays, overlapping the main control, a second borderless richedit control containing the MbGuide.rtf content. If you are fast enough, you can even left-click into that content and actually copy the example code. I use that several times a day, it's much easier than typing the stuff... try it with SortFiles ;-)

Btw inserting a hyperlink is very easy: copy the URL, select a word in the comment area, hit Ctrl K, OK.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
Advanced string sorting
« Reply #313 on: December 31, 2015, 12:36:08 PM »
This year's last MasmBasic version does not only care for an exotic bug in the JWasm and AsmC assemblers (or is ML wrong? who knows  ::)), it also adds an interesting feature to the QSort string sort: You may use an index array to keep track of a string's original line number. Note this is not my idea, GfaBasic had it already in the mid-eighties; but MasmBasic is a bit faster: in case-insensitive mode, skipping leading spaces and using an index array, the routine sorts a Million strings in roughly one second on my Core i5 8)

include \masm32\MasmBasic\MasmBasic.inc
  SetGlobals c1, c2, c3
  Init                  ; ## create a dynamic string array and sort it ##
  Dim My$()
  xor ecx, ecx
  PrintLine "line", Tb$, "random string"
  .Repeat
      Let My$(ecx)=Str$("String %i", Rand(20)+1000)
      PrintLine Str$(ecx), Tb$, My$(ecx)
      inc ecx
  .Until ecx>=10
  QSortMode cis, sls, MyKeys()      ; case-insensitive, skip leading spaces, use an index array
  PrintLine CrLf$, "line", Tb$, "sorted string", Tb$, "was line"
  QSort My$()            ; sort all elements allocated so far
  For_ esi=0 To ecx-1
      PrintLine Str$("%i\t", esi), My$(esi), Str$("\t%i", MyKeys(esi))
  Next
  For_ esi=0 To ecx-1
      Rand("A", "Z", c1)      ; create three
      Rand("a", "z", c2)      ; random
      Rand("a", "z", c3)      ; chars
      Let My$(esi)=Chr$(c1, c2, c3, "_")+Mid$(My$(esi), 6)      ; rewrite string
  Next
  QSort My$()            ; sort all elements allocated so far
  PrintLine CrLf$, "line", Tb$, "resorted string", Tb$, "was line"
  For_ esi=0 To ecx-1
      PrintLine Str$("%i\t", esi), My$(esi), Str$("\t%i", MyKeys(esi))
  Next
  Inkey "OK?"
EndOfCode


Output:
Code: [Select]
line    random string
0       String 1009
1       String 1001
2       String 1002
3       String 1017
4       String 1013
5       String 1016
6       String 1004
7       String 1015
8       String 1000
9       String 1010

line    sorted string   was line
0       String 1000     8
1       String 1001     1
2       String 1002     2
3       String 1004     6
4       String 1009     0
5       String 1010     9
6       String 1013     4
7       String 1015     7
8       String 1016     5
9       String 1017     3

line    resorted string was line
0       Ebw_g 1017      3
1       Kia_g 1015      7
2       Ojo_g 1000      8
3       Olr_g 1002      2
4       Qgd_g 1001      1
5       Tvx_g 1010      9
6       Vdf_g 1009      0
7       Vny_g 1016      5
8       Xjo_g 1013      4
9       Ype_g 1004      6

Source + exe attached, plus an extended example showing how to use GuiImage:

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

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7750
  • Assembler is fun ;-)
    • MasmBasic
ZipMyProject
« Reply #314 on: January 12, 2016, 01:07:20 PM »
Inspired by Pelles C, I have written a plugin for RichMasm that zips the current source (including .rc, .inc etc if in the same folder) and copies the name of the zip file to the clipboard. It requires some zipper, e.g. 7-Zip, and a recent MasmBasic installation.

The attachment contains:
- a new version of RichMasm.exe, to be extracted as \Masm32\MasmBasic\RichMasm.exe
- ZipTheProject.dll and the source, to be extracted to \Masm32\MasmBasic\Plugins\ZipTheProject.dll

The plugin appears as last item in the System & plugins menu. For now, I have tested it with my 7z installation, and it works fine. Unicode file names work, too, but the name of the zip file will be e.g. ~tmpFile_12Jan.zip because 7z doesn't like UTF8 in the name of the archive.

Note that with 7-zip you can also use the extension .7z, with much better compression.

Work in progress, use at your own risk etc, feedback welcome 8)