Author Topic: MasmBasic  (Read 153720 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Choose command
« Reply #285 on: October 06, 2015, 09:32:57 AM »
Update 6 October: Inspired by James Fuller, the Choose command was added to the library:

include \masm32\MasmBasic\MasmBasic.inc      ; download
.data
tx123      db "This is tx123", 0

  Init
  mov ecx, Chr$("ecx is a string")
  Dim My$()
  Let My$(0)="array element 0"
  Let My$(1)="array element 1"
  .While 1
      Inkey "Gimme a letter from a-z: "
      .Break .if eax==VK_ESCAPE
      xchg eax, ecx
      .if Choose(ecx-"a", 100, 101, 102, "abc", 124, 12345.67, 12345678.90123456789, offset tx123, ecx, My$(1), "the letter k")<=ChooseString
            .if eax==ChooseReal
                  Print Str$("You chose the real number %Jf\n", ST(0))
                  fstp st
            .elseif eax==ChooseError
                  PrintLine "You typed the letter ", Chr$(ecx), " - error..."
            .else
                  push eax
                  Print Str$("You chose the integer %i ", eax)
                  pop eax
                  PrintLine " (hex", Hex$(eax), ")"
            .endif
      .else
            PrintLine "You chose the string [", eax, "]"
      .endif
  .Endw
EndOfCode


P.S.: VB Choose Function on MSDN uses a double as the index - funny idea 8)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Plotting a map
« Reply #286 on: October 11, 2015, 10:35:59 PM »
MasmBasic update of 11 October improves on its GUI interface:

GuiParas equ "Plotting a sinus and a map", x30, y30, w1200, h700, bnone
include \masm32\MasmBasic\Res\MbGui.asm
  ToolTips                  ; initialise the tooltips, they will
  ToolTips end              ; show the country names
  ArrayLoadMap 0, "\masm32\MasmBasic\Res\europe.map"
Event Paint
  ArrayPlot hWnd, RgbCol(144, 240, 255)          ; init with window (or control) handle and background colour
  ArrayPlot 0, RgbCol(127, 127, 127), lines=2    ; display map #0 with grey borders 2px thick
  ArrayPlot exit, "Europe"                       ; finish with a title
  GuiTextBox 35.0, 92.0, 120, 32, "This application is sizeable - try it!!!!", fcol 0ffh, bcol RgbCol(204, 255, 204)
  GuiTextBox 29.0, 63.0, 85, 66, "Move the mouse over a country to see its name", fcol 0, bcol RgbCol(255, 255, 128)
Event Message
  .if uMsg==WM_MOUSEMOVE
      ArrayMapRegion(lParam, 0, hWnd)      ; activate tooltip if mouse enters a region
  .endif
GuiEnd


Screenshot below. It's heavily sized, to save bandwidth - the full version looks better ;-)

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #287 on: October 12, 2015, 09:48:59 AM »
i like the idea - but have no idea how it works - lol

i'd like to write a program that generates "great circle" maps (azimuthal equidistant)
they have them - they even have online generators, but i'd like my own
at any rate - no time to play with it for now   :(

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #288 on: October 12, 2015, 09:52:08 AM »
here's one, with the center on "some town" in France
they are different for every location in the world - lol

http://www4.plala.or.jp/nomrax/BM/Paris_l.gif

we use them to "aim" our antennas
some guy in France wants to talk to a guy in Alaska, he aims his antenna about 350 degrees

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Extracting data tables from Wikipedia
« Reply #289 on: October 14, 2015, 12:45:00 PM »
Once upon a time, MSIE had a function that allowed to extract a table to Excel (the only reason I ever used Explorer instead of Firefox). That seems to have stopped working a long time ago, so I wrote a little proggie (70 lines) that does the job.

It is not for general use, though; some manual adjustment will be needed to download other tables. Here is the main loop that generates the string array (full code & exe attached, requires MB of 14 October 2015)

GetElements:
  .While ct<maxcountries      ; xs mode: use in loop, exclude left and right search strings
      Let t$(ct, Rank)=Extract$(esi, '<td>', '</td>', xsLoop or xsExcL or xsExcR)
      Let t$(ct, Country)=Extract$(esi, 'title="', Chr$(34, 62), xsLoop or xsExcL or xsExcR)
      Let t$(ct, Int$)=Extract$(esi, '<td>', '</td>', xsLoop or xsExcL or xsExcR)
      inc ct
  .Endw


So if you are feeling strong in HTML, press Ctrl U in FF or MSIE and try to guess which left and right matches are suitable for extracting the table :P

P.S.: Download of the library appears to be disturbed today. I managed once to download and install with MSIE, but very, very slowly. FF downloads at under 3kB/s, and doesn't complete. Is it just my line, or have the Aussies been cut off from the Internet once more? The forum is also really slow today.

azdps

  • Regular Member
  • *
  • Posts: 33
Re: MasmBasic
« Reply #290 on: October 15, 2015, 01:52:02 AM »
I was attempting to install your masmbasic library but the install screen is too large for my laptop screen. The max resolution for my laptop is 1366 x 768. I'm unable to see any buttons at the bottom of the screen to press to install masmbasic. Here is a screenshot:



 Just used my desktop to install your library and copied the files onto my laptop. Couple things I noticed.

- The ReadMeMasmBasic.txt shows the download location for JWasm at "http://www.japheth.de/JWasm.html#jwdownload" which seems to be an invalid location now.

- After replacing ml.exe with Jwasm.exe I received  an error when attempting to assemble my program. Example of code where I encountered and error below:

Code: [Select]
.if eax == 1
     do this
.elseif
     do this
.endif

Now my .elseif should have been an .else in the first place but just wanted to let you know since it appears you wanted Jwasm to be a backwards compatible with microsofts ml.exe. Jwasm was just letting me know about my poor programming which microsofts ml.exe didn't care about.

Also just FYI. I'm sure you already know but Avast is throwing some fits about your installer.
« Last Edit: October 15, 2015, 03:20:34 AM by azdps »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #291 on: October 16, 2015, 11:14:32 AM »
I was attempting to install your masmbasic library but the install screen is too large for my laptop screen.

Thanks a lot for your feedback, azdps. The installer should be OK with version 16 October.

Quote
- The ReadMeMasmBasic.txt shows the download location for JWasm at "http://www.japheth.de/JWasm.html#jwdownload" which seems to be an invalid location now.

- After replacing ml.exe with Jwasm.exe I received an error

That ReadMe is obsolete and will disappear soon. Re JWasm, just hit F6 when you see the manual, RichMasm will install JWasm. If Avast allows it, of course :bgrin:

And indeed, JWasm is occasionally a bit stricter than ML, but that's a feature IMHO. You may try also Nidud's AsmC, it's incredibly fast and seems to work fine now.

Version 16 October 2015: Fixed a few minor glitches in RichMasm, and re-installed the possibility to concatenate FileRead$() as in the snippet below.

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  StringToArray FileRead$("\Masm32\include\Windows.inc")+FileRead$("http://masm32.com/board/index.php?action=help")+FileRead$("\Masm32\include\WinExtra.inc"), x$()
  push eax
  For_ ecx=0 To eax-1
      .if Instr_(x$(ecx), "<head>", 1)
            PrintLine "...", CrLf$, Str$(ecx), Tb$, "[", Left$(x$(ecx), 70), " ...]"      ; print one line of the embedded HTML code
      .endif
      mov edx, stack
      sub edx, 4
      .if ecx<5 || ecx>=edx      ; print first 5 and last 4 strings
            .if Zero?
                  PrintLine "..."
            .endif
            PrintLine Str$(ecx), Tb$, x$(ecx)
      .endif
  Next

  pop edx
  pop edx
  Store "ThreeFiles.txt", x$()      ; write all strings to disk
  ShEx "ThreeFiles.txt"      ; show the result in Notepad
EndOfCode

azdps

  • Regular Member
  • *
  • Posts: 33
Re: MasmBasic
« Reply #292 on: October 17, 2015, 03:56:53 PM »
jj2007 when testing the newest installer from the SetupMasmBasic17Oct15.zip the buttons now show at the bottom so it will install now. Just for testing purposes I pressed on the Masm32 Forum button and the program crashes and an error message box displays indicating the following: Setup.exe has stopped working. A problem caused the program to stop working correctly. Please close the program. I get the crash as well when clicking on close at the top right corner. The install button works without any issues.

I'm using Windows 8.1 32bit. Haven't tested it on my desktop which is running Windows 7 yet.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #293 on: October 18, 2015, 04:38:33 AM »
Thanks, azdps, for this information. It is indeed a bug, and I am trying to fix it right now.

EDIT: Fixed in version 19 October, please download and reinstall.

Extract$() has now a wildcard option:
Let t$(ct, subject)=Extract$(esi, Chr$('class="subject"*"', 62), '</a>', xsWildcard)

Useful if you want to extract e.g. The Campus from
<a class="subject" href="http://masm32.com/board/index.php?board=1.0" name="b1">The Campus</a>

With the attached example, this output can be obtained:
Code: [Select]
The Campus                  Today at 07:48:01 AM             Re: Calling an EXEs export functions
The Workshop                Today at 07:56:53 AM             Re: MasmBasic
The Laboratory              Today at 07:02:35 AM             Re: GetCpuFrequency Tests
The Soap Box                Today at 11:45:25 AM             Re: What base jumpers do when they grow up. :)
The Colosseum               Today at 11:50:13 AM             Re: Microsoft 'Accident' Forces Windows 10 Onto Windows 7, Windows
« Last Edit: October 19, 2015, 09:40:02 AM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Bug warning for MasmBasic before 20 Oct 2015
« Reply #294 on: October 20, 2015, 01:59:37 PM »
Please reinstall MasmBasic (safe, doesn't overwrite any user sources). This bug affects all versions before today:

include \masm32\MasmBasic\MasmBasic.inc      ; download the good version
  Init
  Let edi="LMR"
  Let esi=Mid$(edi, 2, 1)+Str$(0)+Mid$(edi, 2, 1)      ; M0M, OK
  PrintLine "[", esi, "]"      ; Mid$+Str$+Mid$ ok
  Let esi=Mid$(edi, 2, 1)+"/"+Mid$(edi, 2, 1)      ; crappy result
  PrintLine "[", esi, "]"      ; 2xMid$ etc failed miserably before 20.10.2015
  Exit
end start


In short, using Left$, Mid$ or Right$ twice with the same string as in Let My$=Left$(some$, somect)+Left$(some$, somect) caused trouble.

Sorry for the inconvenience. To compensate, I've improved the "Tiny GUI demo" that appears in menu File/New Masm source (34 lines of code, sizable window):

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Simple graphics
« Reply #295 on: October 23, 2015, 07:41:00 PM »
MasmBasic update of 23 October 2015 features major changes under the hood:
Code: [Select]
include \masm32\MasmBasic\Res\MbGui.asm ; OPT_Icon Plot
  Dim MySinus() As REAL8
  For_ ct=-400 To 400
SetFloat MySinus(ct+400)=Sinus(ct) ; *** a GUI demo in 24 lines of code ***
  Next
Event Paint
  ArrayPlot hWnd, RgbCol(192, 222, 255) ; init & set background
  ArrayPlot MySinus(), 0, lines=5, 00100204h ; draw the array
  ArrayPlot exit, "Playing with Sinus() plots" ; finish with a title
  For_ ct=20 To GuiWidth-20 Step 10
GuiLine 50.0, 3.0+25, ct, 99.0, RgbCol(255, 160, 160) ; the 'pink pyramid'
void Cosinus(ct) ; load cos(ct) into ST(0)
fimul GuiHeight
fiadd GuiHeight ; center
fmul FP4(0.4)
SetInt ecx ; convert result to integer
GuiText ct+30, ecx+60, Str$(ct), bcol RgbCol(192, 222, 255)
GuiCircle ct, ecx+70, 1.5, b Rand(0ffffffh), p RgbCol(80, 80, 80)
  Next
  GuiEllipse 32.0+9, 10.0+35, 7.0, 8.0, b RgbCol(255, 128, 128) ; RGB for n00bs
  GuiEllipse 60.0-9, 10.0+35, 7.0, 8.0, b 0FF2020h, p 808080h ; BGR for experts
  GuiTextBox 50.0-70, 40.0, 140, 96, Str$("Painting took %i ms. This is just a simple text box, you can do the same in other programming languages", GuiMs), bcol RgbCol(255, 255, 192)
  GuiCircle 50.0, 40.0+50, 12.0, p 0, b none ; none = hollow brush
EndOfCode

The window is sizable and flicker-free. The template is available via RichMasm's File/New Masm source list of templates, it's the "more" link behind "Tiny GUI demo".

RichMasm has now a full word search option, for distinguishing e.g. between edi and immediate. In the upper right corner, the FW check box switches it on (in case the toolbar is not wide enough to see the FW, press Ctrl G, type tbw=150 and hit Enter).

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #296 on: October 30, 2015, 12:54:53 PM »
Update 30 October 2015 features minor improvements, inter alia the recognition of quoted strings like "123" and '123' as valid number formats, see StringToArray in \Masm32\MasmBasic\MbGuide.rtf:

      ; convert string to a numerical array:
      include \masm32\MasmBasic\MasmBasic.inc
      SetGlobals a1$="123 27.5 28.49 -56.78 '20h' 0x40 11111b/123456789"      ; string with a wild mix of number formats
      Init
      Dim MyDw() As DWORD
      For_ ecx=0 To Fn(StringToArray a1$, MyDw())-1      ; strings to dwords conversion
            PrintLine Str$("MyDw(%i)=", ecx), Str$(MyDw(ecx))
      Next

      EndOfCode


Output:
Code: [Select]
MyDw(0)=123
MyDw(1)=28
MyDw(2)=28
MyDw(3)=-57
MyDw(4)=32
MyDw(5)=64
MyDw(6)=31
MyDw(7)=123456789

Notes:
- StringToArray returns #elements in eax; in For_ ... Next loops, you may use Fn(...)-1 as shown above
- numeric arrays must be declared (BYTE ... QWORD, REAL4/8/10), but there is no need to Dim a string array before

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #297 on: November 06, 2015, 12:23:31 PM »
Update 6 November changes the display of file timestamps (more). Files that were modified during Daylight Saving Time now show the correct time, identical to the one displayed by Windows Explorer (which is in contrast to time shown by DOS and some file managers).

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
Major update
« Reply #298 on: November 21, 2015, 01:25:28 PM »
MasmBasic update 21 Nov 2015 (download) features several improvements under the hood. Check (in MbGuide.rtf) in particular the TimeSF and IsoWeek functions.

The RichMasm editor crashed on rare occasions when inserting a hyperlink with Ctrl K. This is fixed now.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7753
  • Assembler is fun ;-)
    • MasmBasic
90 projects
« Reply #299 on: November 23, 2015, 11:34:05 AM »
Sometimes people post Hello World "projects" distributed over a dozen files. Apparently it looks more professional to put the three PROTO lines into separate include files.

When installing MasmBasic (e.g. the latest version), the first thing you'll see after clicking Accept & Install is the file MbGuide.rtf loaded with the RichMasm editor, as shown below (shortened).

Click the link "try 90+ snippets" to open MbSnippets.asc, a collection of over 90 "projects" (second image below). MasmBasic's editor has a very special feature: If the command Init is selected and you hit F6, it checks if there is an include ... line before and an end start or EndOfCode line afterwards. If both are found, the editor exports only the code between the two lines.

While the listbox has the focus, you can use cursor up/down to scroll through the "projects", which demonstrate some of the over 200 MasmBasic commands. If you see an interesting command, just hit F6 to see it in action :biggrin: