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

jj2007


qWord

Quote from: jj2007 on March 02, 2013, 11:14:45 AM
Quote from: qWord on March 02, 2013, 11:00:57 AM
BTW: what about double buffering?

What do you mean??
Sry, I was talking about the example with ArrayPlot - it flickers on resizing.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Yes, that's true. I wanted to keep the example simple. To reduce the flicker, do the following:

- line 135:
        mov wc.style, CS_BYTEALIGNWINDOW

- in line 238, add:

    .elseif uMsg == WM_SIZE
       invoke InvalidateRect, hWnd, 0, 0
    .elseif uMsg == WM_CREATE

qWord

It's much simpler: set the background brush to zero
mov wc.hbrBackground,  0

:biggrin:
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Good trick, but you still need the InvalidateRect in the WM_SIZE handler. Even better but CPU-hungry: InvalidateRect in the WM_SIZING handler.

qWord

Quote from: jj2007 on March 02, 2013, 11:33:01 AM
Good trick, but you still need the InvalidateRect in the WM_SIZE handler. Even better but CPU-hungry: InvalidateRect in the WM_SIZING handler.
your original example does not need that, because the window class has the CS_HREDRAW and CS_VREDRAW style.
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

i didn't think CS_BYTEALIGNWINDOW meant much on modern displays

jj2007

Quote from: qWord on March 02, 2013, 11:37:44 AM
your original example does not need InvalidateRect, because the window class has the CS_HREDRAW and CS_VREDRAW style.

That's right - CS_HREDRAW or CS_VREDRAW plus a zero background brush seems to give the best results. Thanks, the new version is uploaded above :t

The documentation is still incomplete; for example, you can add a margin and a legend:

    .elseif uMsg == WM_PAINT
        ArrayPlot hWnd, RgbCol(200, 255, 240)                ; init with window (or control) handle and background colour
        ArrayPlot 0, RgbCol(200, 200, 200), lines:2, 00001900h        ; plot map 0 as loaded above, with grey border and 2px lines, margin right=19h
        ArrayPlot Sinus()        ; plot the sinus curve defined above
        ArrayPlot NormalDist()
        ; ------ here you could add additional features, e.g. a legend ------
        invoke SetBkMode, APs.apMemDC, TRANSPARENT
        invoke SelectObject, APs.apMemDC, LegendFont
        invoke TextOut, APs.apMemDC, 380, 100, Chr$("Legend"), 6
        ArrayPlot exit, "Europe"        ; finish with a title

Gunther

Hi Jochen,

Quote from: jj2007 on March 02, 2013, 11:48:14 AM
Thanks, the new version is uploaded above :t

in which post? I'd like to test it.

Gunther
You have to know the facts before you can distort them.

jj2007

Hi Gunther,

It's always attached to the first post in this thread. Feedback welcome ;)

Gunther

You have to know the facts before you can distort them.

jj2007

Version 6 March uploaded here. It fixes a nasty little bug in the ArrayRead macro (the wrong file was closed). Usage:

        Dim rc4() As REAL4   ; can be REAL4, REAL8, DWORD, ... structures
        ArrayRead rc4(), "MyReal4.dat"

To compensate for this bug :redface:, I added ArrayMean:

                        ArrayMean MyR8()                            ; all array elements are added up, then the sum is divided by the count
                        Print Str$("Resall=\t%f\n", ST(0))      ; the resulting mean is left on the FPU
                        fstp st
                        ArrayMean MyR8(XY)                        ; same as before but we assume the array consists of x,y pairs
                        Print Str$("ResY=\t%f\n", ST(0))       ; the mean of the Y elements is returned in ST(0)
                        fstp st
                        Print Str$("ResX=\t%f\n", ST(0))       ; the mean of the X elements is returned in ST(1)
                        fstp st
Rem        returns mean(s) on the FPU and total number of elements in eax

jj2007

Version 24 March uploaded (download: top of thread)

New functions are ArraySet, SetPoly3 and GetPoly3, see example below and \Masm32\MasmBasic\MbGuide.rtf

As shown in the repeat loop below, AllPts(ecx+1) is now valid syntax (same for string arrays)

include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
        Dim My3Pts(5) As DWORD                ; create an array with 3 XY pairs, i.e. 6 elements (0 .. 5)
        ArraySet My3Pts() = 1, 100, 2, 300, 4, 150        ; assign XY values (ArraySet can be handy but any other array works, too)
        SetPoly3 My3Pts()                ; create coefficients for a 3-point polynomial, i.e. Y=a0+a1*X+a2*X2
        Dim AllPts(11) As REAL4                ; create a destination array with 12 elements
        Print "N", Tb$, "X", Tb$, "Y", Tb$, "Y(ecx)"        ; the last column uses the "direct" variant GetPoly3(X)
        GetPoly3(AllPts())                ; fill starting from X=0, create coefficients for Y=a0+a1*X+a2*X2
        add eax, eax
        push eax
        xor ecx, ecx
        .Repeat                ; print N, X, Y=f(x), Y=f(2*X)
                Print Str$("\n%i\t", ecx/2), Str$("%2f\t", AllPts(ecx)), Str$("%3f\t", AllPts(ecx+1)), Str$("%3f", GetPoly3(ecx))
                fstp st                ; pop the return value from the FPU
                add ecx, 2
        .Until ecx>=stack
        pop eax
        Inkey CrLf$, "ok"
        Exit
end start

Output:
N       X       Y       Y(ecx)
0       0.0     -283.0  -283.0
1       1.0     100.0   300.0
2       2.0     300.0   150.0
3       3.0     317.0   -733.0
4       4.0     150.0   -2.35e+03
5       5.0     -200.0  -4.70e+03


jj2007

Latest addition to MasmBasic is an interface to Excel - more in the Easter Egg thread.

Note that when you use the File, New Masm source menu in RichMasm, the interface is offered here:
Client & server                example for InterProcessCommunication (IPC)
Masm2Excel                an easy-to-use DDE interface to MS Excel
MasmBasic console app        more examples using BASIC syntax

However, the MB archive is at the 512kB limit, therefore I couldn't squeeze it in. Extract Masm2Excel.asc from post #1 of the Easter Egg thread to \Masm32\RichMasm\Res\Masm2Excel.asc to add this sample to the templates.

jj2007

With version 5 April, the xlsHotlink macro works now just fine :biggrin:
A little warning: All macros that write to Excel, whether VBA or XLA or MasmBasic, do not preserve the previous state, i.e. there is no undo. If you really need undo, use xlsRead$("yourselection") and handle it manually.

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  xlsConnect                ; no args=Excel, System
  .if !Zero?                  ; non-zero means success
        xlsOpen "\Masm32\RichMasm\Res\LifeExOecd.xls"                ; we open a sample spreadsheet
        .if !Zero?                ; non-zero signals success
                ; xlsCommand "[app.activate()]"                  ; optional: activate Excel
                xlsConnect "LE Males at birth"                ; tell Excel to which sheet you want to talk
                .if !Zero?                ; non-zero signals success
                        .if rv(GetConsoleWindow)                ; you may print to the console...
                                ConsoleColor cBlack, cYellow        ; make the spaces visible that Excel exports
                                Print "Current selection=[", xlsRead$(), "]", CrLf$        ; no args means current selection
                        .else
                                ifdef hEdit                ; this section would be typical for a GUI application
                                    SetWin$ hEdit='R1C1:R9C5=['+xlsRead$("R1C1:R9C5")+']'+CrLf$                ; ... or set window content
                                    AddWin$ hEdit="Extract #2=["+xlsRead$('R9C1:R12C5')+"]"+CrLf$                ; and add bits & pieces
                                    xlsHotlink "R5C1:R38C2", hEdit        ; see how user modifies a selected area
                                endif
                        .endif
                        ; writing is possible but attention, there is no undo (as for all modifications done by Excel macros)
                        xlsWrite "R1C1", Cat$("This sheet was modified on "+Date$+", "+Time$)
                .endif
                xlsClose 0                ; close the file without saving (0=don't save, 1=save, no arg: ask)
        .endif
        xlsDisconnect                ; say bye to Excel
  .endif
  Inkey "ok"
  Exit
end start