Author Topic: MasmBasic  (Read 143012 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Unicode editor with multilingual user interface
« Reply #255 on: May 21, 2015, 01:32:19 AM »
Just for fun - needs MasmBasic version 20 May 2015:



Source (28 lines of code :icon_mrgreen:) included in the package: when the help file pops up, click on "Try a GUI app" in line 15.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Multilingual GUI apps
« Reply #256 on: May 23, 2015, 12:30:25 PM »
What I always missed with M$ Office (and Windows in general) was an option to switch the language of the user interface. Here is one way to do it: Instead of writing ...
Code: [Select]
invoke AppendMenu, esi, MF_POPUP, edi, chr$("&File")... you use ...
Code: [Select]
invoke AppendMenu, esi, MF_POPUP, edi, Mlg$(File)... and depending on the language chosen by the user, the menu appears as File or Fichier or Datei.

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Mlg$(File:"\Masm32\MasmBasic\Res\Tb4Res\Sample.tab")      ; file:"path" loads the multilingual matrix
  For_ ct=0 To 5
      Mlg$(Language: Mid$("ENESBRITDEFR", ct*2+1, 2))      ; example: Mlg$(Lang:IT) sets Italian
      PrintLine Mlg$(LgTx), ":", CrLf$, Tb$, Mlg$(_ASM), CrLf$, Tb$, Mlg$("_BEL")
      PrintLine Tb$, Mlg$("_USA"), CrLf$, Tb$, Mlg$(_AUS), CrLf$, Tb$, Mlg$(_AUT)
  Next
  Exit
EndOfCode


Output (shortened):
Code: [Select]
English:
        American Samoa
        Belgium
        United States
        Australia
        Austria
Español:
        Samoa americana
        Bélgica
        Estados Unidos
        Australia
        Austria

Format of the tab file:
Code: [Select]
Line 0 = comment, Tb$, ID1, Tb$, Id2, ...
Line 1...n: 3 or 4 letter ID (here: understroke+ISO 3 letter code), Tb$, text, Tb$, text, Tb$, etc.
 
Do not change this line EN ES BR IT DE FR
LgTxt English Español Português (BR) Italiano Deutsch Français
_ASM American Samoa Samoa americana Samoa Americana Samoa Americane Amerikanisch-Samoa Samoa Américaines
_AUS Australia Australia Austrália Australien Australie
_AUT Austria Austria Áustria Österreich Autriche
_BEL Belgium Bélgica Bélgica Belgio Belgien Belgique
_FRA France Francia França Francia Frankreich
_USA United States Estados Unidos Estados Unidos Stati Uniti d'America Vereinigte Staaten von Amerika Etats-Unis

Example attached, requires MasmBasic of 23 May 2015

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Toolbar with embedded controls
« Reply #257 on: May 29, 2015, 10:26:05 AM »
Source (ca. 70 lines) is in \Masm32\MasmBasic\Res\MiniGui.asc (MasmBasic of 29 May)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Windows 8.1
« Reply #258 on: June 11, 2015, 08:29:21 AM »
Since I finally have a machine with Windows 8.1 installed, I managed to fix a bug in RichMasm. As of version 11 June 15 (download), MasmBasic's IDE is fit for Win 8 :t

Note that before installing MasmBasic, you need a valid Masm32 installation. One known issue with Win 8.1 is that you will see these messages several times:
- inc2l.exe: can't find ordinal 200 in windir\AppPatch\AcGenral.dll
- inc2l.exe: can't find ordinal 202 in windir\AppPatch\AcLayers.dll

Masm32 will work just fine, in spite of these error messages.

Note also that Win 8 will display a message "PC protected by Windows" saying that "SmartScreen" has stopped the launch of an unknown application. This is a nasty trick to force coders to buy signatures. Click on "more info" and "Run anyway".

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #259 on: June 11, 2015, 08:33:29 AM »
you wanna tell us about the bug ?   :biggrin:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #260 on: June 11, 2015, 08:47:17 AM »
you wanna tell us about the bug ?   :biggrin:

It's actually quite weird. There was an access violation in RichMasm, due to a fairly fat bug - sh*t happens. Windows 7-64 has the strange habit to "fix" such problems somehow, so I never noticed (and I should check why I didn't see it on the XP machine). Win 8 made it crash.

First, I thought it had to do with SEH, but the example in \Masm32\MasmBasic\Res\SkelTryCatch.asc works just fine both in Win 8.1 and in Win 7, so I really don't know why the exception made it crash in Win 8.1 ::)

Another problem was RichMasm's habit to be stingy, pardon: parsimonious with the screen real estate: It uses the caption for the menu titles. That works fine from XP to Win7, but Win 8.1 re-introduced a design feature that will certainly be loved by the fans of Windows 3.1: the captions are centered. So to avoid overlap of menus and title, I had to cheat the OS by padding the caption with spaces to the right. To avoid doing that in Win 7, too, I had to get the OS version. I really wonder when they will retire the person who is responsible for the GetVersion mess, it's incredible. Google for GetVersionEx deprecated manifest, and you'll even find postings that make fun of M$. Richmond, still sleeping...?

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #261 on: June 12, 2015, 01:23:15 AM »
what i was looking for was code to avoid
i (we) write code, testing under XP
it would be nice if we could learn the pitfalls to avoid to allow the code to run under win8+

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #262 on: June 12, 2015, 07:35:28 PM »
what i was looking for was code to avoid

So far,  the only oddity when passing from Win7-64 to Win 8.1-64 was the access violation in RichMasm, which was swallowed by the OS in Win7. So it seems it's always a good idea to test release code with Olly, because the latter catches the access violations.

A bigger problem was the nasty discovery that the 64-bit OS versions trash xmm regs in 32-bit code, while the 32-bit OS versions leave them intact. In MasmBasic, I eventually solved that with
Code: [Select]
fxsave MbXs
...
fxrstor MbXs
pairs. The impact on performance is negligible because it concerns only Win API calls.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
New Switch macro creates jump table
« Reply #263 on: August 29, 2015, 08:13:45 AM »
MasmBasic update of 29 August 2015:

Switch_, Case_, Default_, Endsw_
The Masm32 Switch macro is more powerful than its C or GfaBasic equivalents, since it can handle even variables or registers in the "cases". The MasmBasic Switch_ (note the understroke) cannot handle variables, i.e. the cases can be integer constants only. However, under the hood it creates a jump table that is for long lists of cases much faster than the Masm32 macro. Below an example for MasmBasic Switch_:

      include \masm32\MasmBasic\MasmBasic.inc
      Init                  ; ## Switch with jump table ##
      m2m ecx, -5
      PrintLine "------- testing the new MasmBasic Switch_ macro -------"
      .Repeat
            Print Str$(ecx), Tb$
            Switch_ ecx
            Case_ -2
                  PrintLine "Case -2"
            Case_ 0
                  PrintLine "Case NULL"
            Case_ 10
                  PrintLine "Case 10"
            Case_ 18
                  PrintLine "Case 18"
            Case_ 14 .. 16
                  PrintLine "Case 14 .. 16"
            Default_
                  PrintLine "---"
            Endsw_
            inc ecx
      .Until signed ecx>20
      Exit
      EndOfCode
Rem      Switch_ trashes edx but not eax; do not forget the understroke

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Bug warning
« Reply #264 on: August 30, 2015, 10:26:54 PM »
There was a little bug in ImgPaint - fixed in MasmBasic of 30 August 02:13:56

Here is a tiny (50 lines, source attached) image viewer:

include \masm32\MasmBasic\Res\MbGui.asm      ; included in the MasmBasic package
  SetGlobals ImgCounter, MaxCount, c$, f$      ; simple image viewer - OPT_Icon Eye
  Let c$=CL$()            ; check commandline; if there is none, search current directory
  .if c$
      xchg eax, edi
      mov ecx, Rinstr(edi, "\")
      invoke SetCurrentDirectory, Cat$(Left$(edi, ecx-1))
  .endif
  GfNoRecurse=1      ; limit search to current folder
  GetFiles *.jpg|*.png|*.gif      ; search for images
  SortFiles date, asc      ; sort by date, oldest on top
  xchg eax, ecx
  dec ecx
  .if Sign?
      MsgBox 0, Cat$("No images found in "+CurDir$(0)+", sorry"), "ImageViewLite:", MB_OK
      invoke SendMessage, hWnd, WM_CLOSE, 0, 0
  .endif
  mov MaxCount, ecx
  .Repeat
      .Break .if !c$
      .if Instr_(c$, Files$(ecx))
            mov ImgCounter, ecx
      .endif
      dec ecx
  .Until Sign?
  ImgPaintInfo 1, Files$(ImgCounter)
  invoke MoveWindow, hWnd, 5, 5, eax, edx, 0

Event Paint
  Let f$=Files$(ImgCounter)
  SetWin$ hWnd=GfDate$(ImgCounter)+", "+GfTime$(ImgCounter)+" - "+Mid$(f$, Rinstr(f$, "\")+1)+Str$(" - #%i of ", ImgCounter+1)+Str$(MaxCount+1)
  ImgPaint hWnd, ImgCounter+1, Files$(ImgCounter)

Event Key
  .if VKey==VK_DOWN
      mov eax, MaxCount
      .if ImgCounter<eax
            inc ImgCounter      ; arrow key down
      .endif
  .elseif VKey==VK_UP
      .if ImgCounter>0
            dec ImgCounter      ; arrow key up
      .endif
  .elseif VKey==VK_HOME
      Clr ImgCounter
  .elseif VKey==VK_END
      m2m ImgCounter, MaxCount
  .endif
  invoke InvalidateRect, hWnd, 0, 1      ; force a Paint event, 1=redraw background
GuiEnd

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Basic-style Data and Read
« Reply #265 on: September 01, 2015, 03:39:24 AM »
For the fans of "real" BASIC, I have added Data and Read statements to MasmBasic. Example:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Data 123, "Hello World, how are you?", 'single quotes are allowed', My$, sq$, 456
  SetGlobals My$, sq$, c1$, c2$, MyByte, MyDword, MyR4:REAL4, MyR8:REAL8, Last$, MyQ:QWORD
  Data 789, 111, 1234567890123456789, 1234567890.123456789, 12345.6789, 12345.6789
  Init
  Data 33333, "Last string item"         ; Data statements can go almost everywhere...
  Read ecx, My$, sq$, c1$, c2$, eax      ; once My$+sq$ are read, c1$ and c2$ can be copied
  Read edx
  Read esi     
  Data 1234567890123456789               ; ... but values must be defined before they are read
  Read xmm0, f:xmm1, MyR8, MyR4, edi, Last$, MyQ
  deb 4, "Read variables:", ecx, eax, $My$, $sq$, $c1$, $c2$, edx, esi, xmm0, f:xmm1, MyR8, MyR4, edi, MyQ, $Last$
  Exit
EndOfCode

Output:
Read variables:
ecx             123
eax             456
$My$            Hello World, how are you?
$sq$            single quotes are allowed
$c1$            Hello World, how are you?
$c2$            single quotes are allowed
edx             789
esi             111
xmm0            1234567890123456789
f:xmm1          1234567890.123457
MyR8            12345.67890000000
MyR4            12345.68
edi             33333
MyQ             1234567890123456789
$Last$          Last string item

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
MasmBasic bug fix
« Reply #266 on: September 02, 2015, 08:28:06 AM »
QSort misbehaved - fixed in version 2 September:

qsmb proc
  push esi
  push esi edi
  push ebx 8)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
9/11
« Reply #267 on: September 12, 2015, 12:06:14 AM »
I rewrote the Gui interface a little bit. Of course, it looks horribly BASIC, but traces of pure assembler indicate what is under the hood. And it also offers some eye candy ;D

Oh, and btw - this window is resizable 8)

Assembling requires version 9/11 of MasmBasic.

GuiParas equ "MasmBasic is easy to use", x50, y50, w1200, h666
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm

  Dim MySinus() As REAL8
  For_ ct=-400 To 400
      SetFloat MySinus(ct+400)=Sinus(ct)      ; ******* a GUI demo in 30 lines of code *******
  Next

Event Menu
  MsgBox 0, Str$("You clicked into menu entry #%i", MenuID), "Hello:", MB_OK

Event Paint
  ArrayPlot hWnd, RgbCol(255, 255, 128)            ; init & set background
  ArrayPlot MySinus(), 0, lines=5                  ; draw the array
  ArrayPlot exit, "Playing with Sinus() plots"     ; finish with a title
  For_ ct=20 To GuiWidth-20 Step 10
      GuiLine 50.0, 8.0, ct, 99.0, RgbCol(255, 160, 160)            ; the 'pink pyramid'
      void Cosinus(ct)
      fimul GuiHeight
      fiadd GuiHeight       ; center
      fmul FP4(0.4)
      push eax              ; create a slot
      fistp stack           ; convert to integer
      pop ecx               ; retrieve as ecx
      GuiText ct+30, ecx+50, Str$(ct), bcol RgbCol(255, 255, 128)
      GuiCircle ct, ecx+60, 1.5, b Rand(0ffffffh), p RgbCol(80, 80, 80)
  Next
  GuiEllipse 32.0+9, 20.0, 7.0, 8.0, b RgbCol(255, 128, 128)            ; RGB for n00bs
  GuiEllipse 60.0-9, 20.0, 7.0, 8.0, b 0FF2020h, p 808080h              ; BGR for experts
  GuiTextBox 50.0-60, 40.0, 120, 100, "This is just a simple text box, try to do the same in other programming languages", bcol RgbCol(255, 255, 255)
  GuiCircle 50.0, 40.0+50, 12.0, p 0, b none                  ; none = hollow brush

EndOfCode


jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7542
  • Assembler is fun ;-)
    • MasmBasic
Editor background colour
« Reply #268 on: September 18, 2015, 09:49:27 AM »
Somebody complained about RichMasm not being configurable, so in version 18 September I added the option to change the RichEdit control's background colour.

See ColBg in \Masm32\MasmBasic\Res\RichMasm.ini for a list of available background and foreground colours (you may change the ini file, but the next installation will overwrite your changes, so keep a backup please).

To change the background colour for a document, press Ctrl G and enter e.g. udc=2. Available colours:
Code: [Select]
ColBg=0FFFFE0h ; default, turquois
Bg1=0F0F0F0h ; almost white
Bg2=0C0FFB0h ; greenish
Bg3=0C0C0FFh ; light red
Bg4=0B0FFFFh ; light yellow
Bg5=0FFB0FFh ; pink
Bg6=202020h ; grey; 1=almost black, 0 picks default colour ColBg
BgH=0AAFFFFh ; reserved for hilite colour

ColFg=0 ; default text colour
Fg8=0B0B0B0h ; light gray
Fg16=0A0h ; dark red
Fg24=0A00000h ; dark blue
Fg32=0aaaah ; dark yellow
Fg40=0ffffffh ; white
Fg48=8000h ; green

udc=14 would pick dark grey background with light gray text colour. While the background changes as soon as you hit Enter, the text colour will change only if you select all text and then hit Ctrl E twice.

Among the templates, "Editor with toolbar" has been improved, and the first on top of the list when clicking menu File/New Masm source called "MessageBox only" looks now a bit different, thanks to a radical redesign of RichMasm:
« Last Edit: September 18, 2015, 11:02:04 PM by jj2007 »

HSE

  • Member
  • ****
  • Posts: 532
  • <AMD>< 7-32>
Re: MasmBasic
« Reply #269 on: September 19, 2015, 10:12:14 AM »
Hi jj!

A lot better.

I don't remember if was posible to open asm files in RichMasm from the explorer. Now it's no posible.

Regards. HSE