News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

MasmBasic

Started by jj2007, May 23, 2012, 10:16:07 PM

Previous topic - Next topic

Rob260z

Yes... What a wonderful project. Extremely grateful for all the hard work and effort that has gone into developing this. Starting using the Rand function last week, but then I discovered Deb!, and it's been love at first site :)

Working with a lot of loops that involve the creation and use of indexed addressing. Can't recommend this function enough, especially the ability to output to a text file.

Keep up the good work :)

jj2007

Thanks, Rob - that is the kind of feedback I've been looking for the last 20 years :greensml:

Re deb: I rarely use deb 5 (to file) nowadays, but it can be useful. For monitoring a loop, try deb 7 or deb 30 - any number above 5 shows n times the result, then the loop continues. Also, deb 4, "The error:", eax, $Err$() is a very useful one in WinAPI programming ;-)

Rob260z

Cheers for the advice jj :)

deb 7 or 30 , I'll have to have a look. Excuse my ignorance , but these will require a Win32 console/window ? . Just had a quick read through the help file , but didn't see any info about these.

I'm using SDL2 , simply as a means of spitting out a custom texture , so I'm simply going into an Opengl/DirectX full screen mode. That's why I'm currently using the text file approach. Using the same approach to spit out any performance/benchmark info.


Cheers,
Rob

jj2007

Quote from: Rob260z on August 01, 2017, 07:06:52 PMso I'm simply going into a full screen Opengl mode.

So that doesn't allow a separate console window, right? Then deb 5 is the only solution indeed. Or deb 0...3, you can cancel the messageboxes separately.

; OPT_Susy Console ; forces console mode

Rob260z

Well...I can actually make it run in a windowed mode. I'm going to explore this a little further. Has real potential.

Real-time debugging is going to be really beneficial, once I move past this initial setup phase.

Cheers for the info.

jj2007

Quote from: Rob260z on August 01, 2017, 09:29:12 PMWell...I can actually make it run in a windowed mode. I'm going to explore this a little further. Has real potential.

Another trick:
  winX=150
  winW=900
  ifidni @Environ(oSusy), <console> ; OxPT_Susy Console ; RichMasm autodetect will pick Windows, delete the x to force console
winX=450  ; leave more space for console output
winW=600
deb 4, "Hey, we are using a console in parallel to a window", $wc.lpszClassName
  endif
  invoke CreateWindowEx, WS_EX_ACCEPTFILES, wc.lpszClassName, chr$("Hello World"), ; set window title here
     WS_OVERLAPPEDWINDOW or WS_VISIBLE,
     winX, 150, winW, 400, ; window position: x, y, width, height
     NULL, NULL, wc.hInstance, NULL

jj2007

Please download and run the 26 August 2017 version of the package. As always, you can just follow the instructions, the new installation does not change any of your sources or settings, does not write anything to the registry, and does not interfere with your Masm32 installation (I do reinstallations frequently myself when testing...).

Note that you can use an xmm reg as destination in QuadMath mode, but it has to be prefixed as MovVal q:xmm0, "123", otherwise, an ordinary 64-bit integer will be loaded:

include \masm32\MasmBasic\MasmBasic.inc         ; download
include \masm32\MasmBasic\Res\QuadMath.inc
  Init quad                                     ; requires C:\TDM-GCC-32\bin\libquadmath-0.dll
  mov esi, Chr$("1234567890123456789.0123456789012345678901234567890")
  MovVal xmm0, esi
  PrintLine "64-bit int: ", Tb$, Str$(xmm0)
  MovVal f:xmm0, esi
  PrintLine "double/Real8: ", Tb$, Str$(f:xmm0)
  MovVal q:xmm0, esi
  PrintLine "Quad float e:", Tb$, Quad$(xmm0)
  MovVal q:xmm0, esi
  PrintLine "Quad float g:", Tb$, Quad$(xmm0, "%*.33Qg")        ; formats
EndOfCode


Output:
64-bit int:     1234567890123456789
double/Real8:   1.23456789012346e+18
Quad float e:   1.23456789012345678901234567890123e+18
Quad float g:   1234567890123456789.01234567890123


The other aspect concerns UAsm: By default, RichMasm will from now on use the faster UAsm64 for building 32-bit as well as "dual" 64/32-bit sources. If UAsm64 is not present in \Masm32\bin, RichMasm will ask you if you want to install it, and download and extract a recent version.

jj2007

include \masm32\MasmBasic\MasmBasic.inc         ; download version 6 September
  Init
  GetFiles \Masm32\examples\unicode_generic\*.asm|*.inc|*.rc  ; use the "or" character to separate masks
  For_ each ecx in Files$() : <PrintLine Str$("file %_i\t", ForNextCounter), ecx>   ; one line is enough ;-)
EndOfCode


Output:file # 0        \Masm32\examples\unicode_generic\console\hello\hello.asm
file # 1        \Masm32\examples\unicode_generic\console\textio\textio.asm
file # 2        \Masm32\examples\unicode_generic\diskfile\diskfile.asm
file # 3        \Masm32\examples\unicode_generic\diskfile\WININC.INC
file # 4        \Masm32\examples\unicode_generic\multi_lingual\multi_lingual.asm
file # 5        \Masm32\examples\unicode_generic\multi_lingual\multi_lingual.inc
file # 6        \Masm32\examples\unicode_generic\multi_lingual\ansi.rc
file # 7        \Masm32\examples\unicode_generic\multi_lingual\rsrc - Copia.rc
file # 8        \Masm32\examples\unicode_generic\multi_lingual\rsrc.rc
file # 9        \Masm32\examples\unicode_generic\string_examples\append$\append$.asm
file #10        \Masm32\examples\unicode_generic\string_examples\cat$\cat$.asm
file #11        \Masm32\examples\unicode_generic\string_examples\find$\find$.asm
file #12        \Masm32\examples\unicode_generic\string_examples\switch$\switch$.asm
file #13        \Masm32\examples\unicode_generic\template\misc.asm
file #14        \Masm32\examples\unicode_generic\template\template.asm
file #15        \Masm32\examples\unicode_generic\template\template.inc
file #16        \Masm32\examples\unicode_generic\template\rsrc.rc

jj2007

MasmBasic update 12 September:
- ifdeb allows single lines that create code only in debug mode:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  usedeb=1
  For_ ecx=1 To 20
        ifdeb push ecx : Print "[": .if 0
       Print Str$("%_i ", ecx)
        ifdeb .endif : PrintLine "]" : pop ecx
  Next

EndOfCode

- RichMasm has got a more advanced "Obscure string" feature (more)
- an error will be thrown if the handle for ToolTips is passed in esi

- finally, dynamic string arrays got a bit speedier, they are now practically as fast as fixed Dim some$(100) arrays:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  PrintCpu 0
  Dim MyArray$()                ; create a dynamic array
  NanoTimer()                   ; start high resolution timer
  xor ecx, ecx
  .Repeat
        Let MyArray$(ecx) = Str$("This is string %i", ecx)
        inc ecx
  .Until ecx>=1000000
  Print Str$("%i ms", NanoTimer(ms)), Str$(", %i Million strings allocated\n", MyArray$(?)/1000000)

  Dim FixedArray$(1000000)      ; create a fixed size array
  NanoTimer()
  For_ each ecx in FixedArray$(): <Let FixedArray$(ForNextCounter) = Str$("This is string %i", ForNextCounter)>
  Inkey Str$("%i ms", NanoTimer(ms)), Str$(", %i Million strings allocated\n", FixedArray$(?)/1000000)
EndOfCode


Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
353 ms, 1 Million strings allocated
349 ms, 1 Million strings allocated

jj2007

Install the MasmBasic update 18 September 2017 to get this new feature inspired by the How to read Windows MFT thread:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Inkey "Dump of GetModuleHandle(0):", CrLf$, HexDump$(rv(GetModuleHandle, 0), 90h)
EndOfCode


Options are documented in MbGuide.rtf, as usual.

The other major change is that RichMasm got new menus (more), thanks to LiaoMi :icon14:

Tested on WinXP, Win7-64 (also with Aero, see screenshot below) and Win10, looks OK so far, but let me know if it can be improved :icon_mrgreen:

jj2007

Changes in version 26 October:
- online help is updated, e.g. for deb & friends (remember that in RichMasm, hovering over a keyword allows to access help with a right-click)
- see Graphics demo; handling of maps is strongly improved
- HexDump$() got a "dd" option:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Let esi=FileRead$("\Masm32\examples\exampl04\car\car.jpg")    ; Masm32 SDK
  PrintLine HexDump$(esi, 80)   ; show 80 bytes of jpg header
  Inkey HexDump$(esi, 80, dd)   ; same but for use with code
EndOfCode


Output:006337D0  FF D8 FF E0 00 10 4A 46 49 46 00 01 00 01 00 64 ÿØÿà..JFIF.....d
006337E0  00 64 00 00 FF FE 00 1F 4C 45 41 44 20 54 65 63 .d..ÿþ..LEAD Tec
006337F0  68 6E 6F 6C 6F 67 69 65 73 20 49 6E 63 2E 20 56 hnologies Inc. V
00633800  31 2E 30 31 00 FF DB 00 84 00 08 05 06 07 06 05 1.01.ÿÛ.,,.......
00633810  08 07 06 07 09 08 08 09 0C 14 0D 0C 0B 0B 0C 19 ................

db  0FFh, 0D8h, 0FFh, 0E0h, 000h, 010h, 04Ah, 046h, 049h, 046h, 000h, 001h, 000h, 001h, 000h, 064h
db  000h, 064h, 000h, 000h, 0FFh, 0FEh, 000h, 01Fh, 04Ch, 045h, 041h, 044h, 020h, 054h, 065h, 063h
db  068h, 06Eh, 06Fh, 06Ch, 06Fh, 067h, 069h, 065h, 073h, 020h, 049h, 06Eh, 063h, 02Eh, 020h, 056h
db  031h, 02Eh, 030h, 031h, 000h, 0FFh, 0DBh, 000h, 084h, 000h, 008h, 005h, 006h, 007h, 006h, 005h
db  008h, 007h, 006h, 007h, 009h, 008h, 008h, 009h, 00Ch, 014h, 00Dh, 00Ch, 00Bh, 00Bh, 00Ch, 019h


- the new MasmBasic version is again compatible with UAsm
- a bug in RichMasm was fixed (if a very big document was loaded, and user opened a small one in the same instance, it crashed)

jj2007

a) Version 29 October has now the "unique" feature for generation random numbers (->Unique random numbers):
Rand(-99, 100, SomeIntegerArray(ecx), unique) ; min, max, destination, unique flag

Full example:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  tests=100
  Dim SomeInteger() As DWORD
  PrintLine Str$("Possible range: %i ... ", -tests/2), Str$(tests/2)
  Let edi="unique numbers: "
  Rand()                                        ; set a seed value
  For_ ecx=0 To tests-1
       Rand(-tests/2, tests/2+1, SomeInteger(ecx), unique)     ; min, max, destination, flag
       Let esi=Str$(" %i ", SomeInteger(ecx))
        .if Instr_(edi, esi)
                inc  ebx                ; oops, we got that one already
        .else
                Let edi=edi+esi         ; remember the last number
        .endif
  Next
  if tests le 100
        PrintLine edi                   ; show the unique numbers
  endif
  Inkey Str$("-- %i errors, hit any key --", ebx)
EndOfCode


Output:Possible range: -50 ... 50
unique numbers:  -13  31  43  11  16  1  -14  -36  -6  21  34  -45  17  -2  -35  39  23  40  7  -1  -5  32  -25  -30  -28  -19  15  -26  0
-29  41  -10  27  -15  22  -33  44  35  -9  29  -12  -16  -24  13  -3  -38  26  -20  -21  20  4  18  -46  36  -23  47  37  49  -34  19  14
10  -37  9  -40  -49  -4  -32  -48  -27  -11  33  2  28  -17  -31  -39  -8  8  -41  -22  24  -50  38  25  -42  6  12  42  -47  48  -44  46
45  3  -7  -18  -43  50  30
-- 0 errors, hit any key --


If you find a duplicate, I owe you a beer, but you must come here to get it :bgrin:

Note that for high numbers of unique random numbers, e.g. tests=30000, it may take a few seconds.


b) another little feature: SetWin$ can now set the text of child controls. Example:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Launch "Notepad.exe SetChildWin.rc", SW_RESTORE, 100  ; give Notepad a few milliseconds to set the caption properly
  .if WinByTitle("SetChildWin.rc - ")
        xchg eax, ecx                   ; set the handle to ecx (MasmBasic won't touch ecx)
        SetWin$ ecx, 15=Replace$(Cat$(Win$(ecx, 15)), "Win$", "Win$#####", 0)   ; replace with an easy-to-spot string
  .endif
EndOfCode


Full project attached, tested with Win7-64 and WinXP. When you hit F6 in RichMasm, the fake rc file for Notepad gets generated from the text between the red Rsrc tags.

jj2007

Version 8 November 2017 is ready to be installed. Changes:

- updated help file, with now 400+ macros documented (also online - use Ctrl F to find commands; 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$() 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)


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

jj2007

HexDump$() got new options:

Let My$=HexDump$("SomeFile.exe", file, dq)  ; translate the file to a string ready for pasting

Attached source & exe of an application that translates any file into an include file. Limit is around 640kB for the *.inc file. The format is as follows (as an example, I translated \Masm32\MasmBasic\RichMasm.exe):.DATA
hdBytes=68608
RichMasmStart LABEL BYTE
.radix 16
dq 06172627261665A4D, 00000455068637375, 05A1809200001014C, 00000000000000000, 03202010B010F00E0, 000197A0000018400, 00000FE6800000000, 00000000C00001000
...
dq 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000, 00000000000000000
.radix 10
.code
; FileWrite "RichMasm.tmp", offset RichMasmStart, hdBytes


include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  .if Exist(CL$())
        Let edi=HexDump$(Exist$, file, dq)
        Let esi=Extract$(CL$(), "\", ".", xsRinstrL)+".inc"
        Let ecx=Str$("%i bytes translated to ", LastFileSize)+esi+CrLf$+CrLf$+Left$(edi, 200)+\
          CrLf$+"..."+CrLf$+Right$(edi, 200)+CrLf$+CrLf$+"Create inc (NO=copy to clipboard)?"
        If_ Exist(esi) Then Let ecx="Attention, "+esi+" exists!!!!"+CrLf$+ecx
        MsgBox 0, ecx, "File to *.inc:", MB_YESNOCANCEL or MB_ICONQUESTION
        .if eax==IDYES
                FileWrite esi, edi
        .elseif eax==IDNO
                SetClip$ edi
        .endif
  .else
        If_ Rinstr(CL$(0), "\") Then inc eax
        MsgBox 0, Cat$("Drag a file over "+eax), "File to *.inc:", MB_OK
  .endif
EndOfCode

OPT_Arg1        \Masm32\MasmBasic\RichMasm.exe  ; just for fun, translate the editor to .DATA ;-)

jj2007

MasmBasic updated, please reinstall version 19 December 2017. Minor changes, inter alia:

- Cpu$():
include \masm32\MasmBasic\MasmBasic.inc
  Init
  MsgBox 0, Cat$("My CPU: "+Cpu$()), "Hi:", MB_OK
EndOfCode


NanoTimer() has been improved, see the new timings thread.

- Delay until (-> full example):

        Delay 1000                      ; standard version: wait a second
       PrintLine fTime$(0, "HH:mm:ss.fff"), Tb$, "started"
        Delay until fTime$(s:1, "HH:mm:ss.123")         ; use time$(current plus one second)
       PrintLine fTime$(0, "HH:mm:ss.fff "), Tb$, NanoTimer$(), " restarted"
Rem    - uses Sleep but preserves ecx
        - the until variant uses a time string to wait until a precise moment; use e.g. fTime$(1, "HH:mm") to
          suspend running until the current minute is finished; fTime$(s:10, ...) would mean 10 seconds


- the "controls" snippet in the templates has been improved (-> File/New Masm source/console/window/controls)

Let me know if there are any problems (there might be some with Windows XP - I test thoroughly for Win7 and Win10 but for XP I only have a VM).