Author Topic: MasmBasic  (Read 144191 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #390 on: April 24, 2017, 08:28:07 AM »
Update 24 April features a new option for the RgbCol macro:
Quote
RgbCol, CgaCol, SysCol
      mov eax, RgbCol(ebx, 0, 0)            ; any mix of reg32, vars and immediates is allowed
      mov bl, 127            ; only bl will be used
      invoke SetTextColor, hDC, RgbCol(ebx, 0, 0)      ; Red Green Blue for Gdi32 functions
      invoke SetTextColor, hDC, SysCol(ebx)            ; use the system palette
      invoke SetTextColor, hDC, RgbCol(?)            ; use the colour picker
      mov hPG, rv(GdipCreatePen1, RgbCol(alpha, red, green, blue), FP4(3.0), UnitWorld, addr pPen)
Rem      - Gdi functions want RGB values, i.e. three parameters
      - in contrast, GdiPlus expects ARGB, i.e. four parameters; the first one, alpha, defines
        transparency ranging from 0=fully transparent to 255=opaque
      - CgaCol(index) may be used with console colours; see ConsoleColor for identifiers
      - SysCol(index) returns a GetSystemPaletteEntries colour for use in Gui applications

See Reply #393 above for an application in RichMasm - greetings to Alex :biggrin:

(the void avoids a mov eax, eax)

LordAdef

  • Member
  • ***
  • Posts: 255
Re: MasmBasic
« Reply #391 on: April 24, 2017, 10:05:12 PM »
===== THIS IS SO NICE JJ!!!! Thanks a lot ======


ps: edit to add: I mean this is reeeeally nice! Now I see RichMasm "flying clolours"  :greenclp: :eusa_clap: :eusa_dance:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #392 on: April 24, 2017, 10:18:43 PM »
Don't overdo it, Alex. Rich text is certainly better than poor text, but with a lot of experience, I limit the use of colour nowadays to MB keywords, push/pop pairs (easier to see if the stack is balanced), and a few very specific tricky code consequences. Btw you can see this "default use" when selecting a block of text and hitting F4 aka "comment" twice.

Another example - red for @Backwards, blue for @Forward jumps (I prefer .Repeat ... .Exit .if ... .Until, though):

            xchg eax, ebx
  @@:
  dec edx
            jl @F
            stosb                  ; insert new empty elements
            jmp @B
  @@:  xchg eax, edi
            pop ebx

This helps to grasp how the loop works. It is much more important to have this visual aid when the loop spans over 20 or 50 lines, of course.

Christmas tree looks nice at first sight, but it doesn't help to focus attention on the really important parts. Which applies, btw, also to the VS or Scintilla style automatic highlighting.

LordAdef

  • Member
  • ***
  • Posts: 255
Re: MasmBasic
« Reply #393 on: April 24, 2017, 10:28:42 PM »
Quote
Don't overdo it, Alex. Rich text is certainly better than poor text, but with a lot of experience, I limit the use of colour nowadays to MB keywords, push/pop pairs (easier to see if the stack is balanced), and a few very specific tricky code consequences.

Oh, don´t worry. In fact I never did it. But it´s invaluable for temporary modifications. I usually colour when trying things out. Later, when things look right, I bring them back to default.

I´m posting my game there at my thread, you will see it´s being used carefully.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #394 on: April 24, 2017, 11:09:20 PM »
it´s invaluable for temporary modifications

Exactly :t

What I frequently use:

if 1
  ... 50 lines of active code ...
else
  ... 50 lines of alternative code ...
endif

LordAdef

  • Member
  • ***
  • Posts: 255
Re: MasmBasic
« Reply #395 on: April 25, 2017, 09:03:16 PM »
JJ,

only FYI, a behaviour I don't recall from the previous 2 versions but now in place:

If you select some code and build (while the code is still selected) it generates an error. I found this by chance when selecting some code, F4 and build. The commented bit must be unselected now in order for the build to be successful.

Nothing out of this world,  but I thought I should let you know.



jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #396 on: April 25, 2017, 09:22:05 PM »
If you select some code and build (while the code is still selected) it generates an error. I found this by chance when selecting some code, F4 and build. The commented bit must be unselected now in order for the build to be successful.

It's not a bug, it's a feature :lol:

Insert this somewhere in one of your sources:
Code: [Select]
if 0
include \masm32\MasmBasic\MasmBasic.inc
  Init
  Inkey "Current time is ", Launch$("cmd /c time /t")
EndOfCode
endif

The if 0 ... endif comments it out, so it won't disturb building your source. But if you select the lines inside and hit F6, then only the lines include ... EndOfCode will be used for the assembly. Useful for testing little snippets, but I will add a warning to the output window explaining why there was an error...

LordAdef

  • Member
  • ***
  • Posts: 255
Re: MasmBasic
« Reply #397 on: April 27, 2017, 04:47:57 AM »
Updated as instructed! :dazzled:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Unicode is easy
« Reply #398 on: May 11, 2017, 04:37:47 PM »
MasmBasic update 11 May features several improvements of Unicode handling. Inter alia,
- you can write strings in any language directly in the editor;
- file names can be in any language, too;
- find & replace is now Unicode aware.

The snippet below is a full-fledged Windows application. Please test in particular the FileOpen() feature.

GuiParas equ "严重的软件应该使用Unicode!!!!", h400      ; in RichMasm, hit F6 to build this application
GuiMenu equ <@File, Open, Save, Save &as, E&xit>     ; requires MasmBasic
include \masm32\MasmBasic\Res\MbGui.asm
  MakeFont hFont, Height:24
  GuiControl MyEdit, "RichEdit", font hFont, wCat$("The commandline passed was"+CrLf$+wCL$())

Event Menu
  Switch_ MenuID
  Case_ 0            ; first menu item has index 0
      .if wFileOpen$("богатый источник=*.asc|Poor sauce=*.asm|资源=*.rc", "богатый источник")
            SetWin$ hMyEdit=wFileRead$(wFileOpen$())
      .endif
  Case_ 1, 2:      MsgBox 0, "Saving not implemented, sorry", "Hi", MB_OK
  Case_ 3:         invoke SendMessage, hWnd, WM_CLOSE, 0, 0            ; yes, you can use pure assembler ;-)
  Endsw_
GuiEnd


Demo attached. To test it, extract to \Masm32\MasmBasic, then drag the file with the exotic name over \Masm32\MasmBasic\UnicodeIsEasy.exe

LordAdef

  • Member
  • ***
  • Posts: 255
Re: MasmBasic
« Reply #399 on: May 11, 2017, 09:03:47 PM »
Quote
- find & replace is now Unicode aware.

Since you mentioned find & replace, let me report this one for FYI sake:

"find" now finds key words in INCLUDE files (with Capital letters) and shows them in the find window. But "Replace" can't replace them in the include files. So the replace doesn't run if everything is selected to be replaced.

I can understand why, I'm just letting you know for development sake.
Cheers Alex

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #400 on: May 12, 2017, 09:34:58 PM »
"find" now finds key words in INCLUDE files (with Capital letters) and shows them in the find window. But "Replace" can't replace them in the include files.

Thanks, Alex. Version 12 May has a warning now, please let me know if that is the right choice. It would be technically possible to replace strings in the include files, but updating include files is not something I would support - too risky.

Among the other changes:

- By holding Ctrl and moving the mousewheel, the RichEdit control can zoom the display. At my age and my eyesight, I need 110%, but there may be people who have brilliant eyes and want to see more code. Pressing Alt Z saves the current zoom level; this is a global setting, i.e. RichMasm remembers this when opening any document (it also affects the font in the Find listbox, but only after restarting RichMasm).

- introduced a new Event variable VKey2:

Event Key
  Switch_ VKey2
  Case_ VK_LEFT:      wAddWin$ hMyEdit=" текст", 44       ; insert Unicode text at position 44
  Case_ VK_RIGHT:      AddWin$ hMyEdit=" missed", 50, 57  ; insert Ansi text at position 50, overwrite 7 bytes
  Case_ VK_UP     
            Let My$=FileRead$("UnicodeIsEasy.asc")
            wAddWin$ hMyEdit=My$
  Case_ VK_DOWN:      <wAddWin$ hMyEdit=wRec$(cfm$("\nВведите\nтекст\nздесь\n"))>  ; append & use cfm$ for \n escapes
  Endsw_


Until now, VKey was available to test for e.g. VK_SPACE or whatever; and the rule was that a positive VKey comes from the main application, a negative one (.if VKey==-VK_SPACE) from the riched control. Now you can catch a keypress independently of whether the control has the focus or not. Full example attached.

The snippet above also demonstrates new optional arguments for AddWin$:
AddWin$ hRichEdit="Text" [, startpos][, endpos]

The online doc for AddWin$ says it's normal edit controls only, but that is wrong. I should update that page...

LordAdef

  • Member
  • ***
  • Posts: 255
Re: MasmBasic
« Reply #401 on: May 13, 2017, 02:39:46 AM »
Quote
Thanks, Alex. Version 12 May has a warning now, please let me know if that is the right choice. It would be technically possible to replace strings in the include files, but updating include files is not something I would support - too risky.

ok JJ.
One other issue for you, still on the Find:
  .Once I make a change in the include file and save it,
  . come back to Main source code and
  . search for something...
  . the result in the Find is not updated for the include files, and still shows the old expression

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #402 on: May 29, 2017, 11:35:41 AM »
Version 29 May is online. As usual, you can just reinstall the package, no need to delete old files or backup your own sources.

Pens and brushes can now be created to arrays. This creates 100 random circles in random colours (attached):

include \masm32\MasmBasic\Res\MbGui.asm
  Dim Pens() As DWORD
  Dim Brushes() As DWORD
  For_ ct=0 To 99
      MakePen Pens(ct), Rand(-1), width 10      ; use random colours
      MakeBrush Brushes(ct), Rand(-1)      ; also for the fill
  Next
  MakePath      123, Circle(200)      ; ID, type circle: radius 20%, i.e. n/1000 of window rect
Event Paint
  For_ ct=0 To 99  ; ID       pen/brush          x        y     scaleX      scaleY
      GuiDraw 123, <Pens(ct)/Brushes(ct)>, <Rand(850).>, <Rand(850).>, eax, <Rand(900)>      ; ScaleX is eax, same as scaleY
  Next
GuiEnd



the result in the Find is not updated for the include files, and still shows the old expression

Sorry, Alex, no time to fix that right now. You can reload, though: Shift F5

Good news: RichMasm works on Windows XP. Again. It had stopped working due to a hilarious Windows bug, see
Code pages and batch files - fun with XP.

As a side effect, I had to write a new macro:

include \masm32\MasmBasic\MasmBasic.inc
      Init
      Print Str$("This is Windows version %i", MbWinVersion()), Str$(".%i", ecx)
      void MbWinVersion()
      Print Str$(", build %i", dx)
EndOfCode
Rem      returns major version in eax, minor version in ecx, and build in dx


Output: This is Windows version 6.1, build 7601

Note this is the real Windows version, not what you declare via "compatibility settings".

Btw when building a project in RichMasm, the environment variable is accessible via
Code: [Select]
  ifidn @Environ(oWin), <5>
MsgBox 0, "Built on XP", "Hi", MB_OK
  endif

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #403 on: May 30, 2017, 02:24:47 AM »
Drag an avi file over the exe, for example Mikl's demo file - see Uncle Remus tales:#37a Animation.

GuiParas equ "SysAnimate32 demo", w452, h374, bRgbCol(255, 255, 160)
include \masm32\MasmBasic\Res\MbGui.asm            ; part of MasmBasic
GuiControl Avi, "SysAnimate32"
invoke SendMessage, hAvi, ACM_OPEN, 0, CL$()
invoke SendMessage, hAvi, ACM_PLAY, -1, 0FFFF0000h
GuiEnd


I was surprised how easy it is, but its usage is rather limited: no sound :(

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #404 on: May 31, 2017, 09:21:38 AM »
  . the result in the Find is not updated for the include files, and still shows the old expression

Implemented in version 31 May - please reinstall the whole package, there was also a bug in the Ansi version of FileOpen$().

Let me know if it's OK like that, Alex. In contrast to the current version, the "external" matches now respect also the "case" and "fw" checkboxes, i.e. case-sensitive and full word mode are working correctly for the include files now.