The MASM Forum

General => The Campus => Topic started by: markallyn on March 06, 2018, 07:19:16 AM

Title: plotting in masm 32 bit
Post by: markallyn on March 06, 2018, 07:19:16 AM
Hello all,

I am looking for a plot library that is callable from masm.  If none such exists can someone come up with a relatively straightforward method for running gnuplot or similar from masm?

Regards,
Mark Allyn
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 06, 2018, 11:10:22 AM
I made a quick search, and there is a tutorial about the gnuplot dll (http://search.cpan.org/~ilyaz/Term-Gnuplot-0.5706/Gnuplot.pm#Runtime_link_with_gnuplot_DLL). Calling a DLL from Masm is easy, the difficult part is understanding their manual, I guess 8)

What exactly do you want to plot? For simple line plots, there is ArrayPlot, see screenshot below (a more elaborate example is here (http://masm32.com/board/index.php?topic=94.msg51060#msg51060)). Here is a very simple application plotting a MySinus() array:

include \masm32\MasmBasic\Res\MbGui.asm
  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ct=-400 To 400
        SetFloat MySinus(ct+400)=Sinus(ct)
  Next
Event Paint
  ArrayPlot RgbCol(192, 222, 255)               ; init & set background
  ArrayPlot MySinus(), 0, lines=2               ; draw the array with 2px lines
  ArrayPlot exit, "Playing with Sinus() plots"  ; finish with a title
EndOfCode


See also Graphics demo (http://masm32.com/board/index.php?topic=6631.msg71135#msg71135).

P.S.: I've spent some time now trying to find alternatives; it's a mess. Gnuplot is popular, but it's a commandline tool, no chance to use it for an embedded control. There are others like GeoGebra, DPlot, MathPlotLib, but I haven't seen a simple tool that allows to plot data on a Windows control or DC. If somebody knows a lightweight plotting library that does that, please let us know... Wikipedia has a Free_plotting_software (https://en.wikipedia.org/wiki/Category:Free_plotting_software) category, maybe it contains a hidden jewel.
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 06, 2018, 07:07:16 PM
I found one more in my archives:

GuiParas equ "Bessel functions", x20, y20, w900, h250, bnone
include \masm32\MasmBasic\Res\MbGui.asm
  gsl double gsl_sf_bessel_J0(double x)
  gsl double gsl_sf_bessel_Jn (int n, double x)
  SetGlobals fct:REAL8
  gsl_INIT
  Dim Bessel0() As REAL8
  Dim Bessel1() As REAL8
  Dim Bessel2() As REAL8
  xor ecx, ecx                          ; array index
  For_ fct=-10.0 To 40.0 Step 0.04
        SetFloat Bessel0(ecx)=gsl_sf_bessel_J0(fct)
        SetFloat Bessel1(ecx)=gsl_sf_bessel_Jn(1, fct)
        SetFloat Bessel2(ecx)=gsl_sf_bessel_Jn(-3, fct)
        inc ecx
  Next
Event Paint
  ArrayPlot hWnd, RgbCol(240, 240, 240)        ; init with window (or control) handle and background colour
  ArrayPlot Bessel0(), RgbCol(255, 64, 64)     ; red
  ArrayPlot Bessel1(), RgbCol(64, 255, 64)     ; green
  ArrayPlot Bessel2(), RgbCol(64, 64, 255)     ; blue
  ArrayPlot exit, "             GSL: Regular cylindrical Bessel functions"       ; finish with a title
GuiEnd
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 07, 2018, 01:51:35 AM
Good morning, Jochen,

Wow!  The GSL approach with MasmBasic produces exactly the sort of plots I'm interested in.  Unfortunately, I am not fluent in MasmBasic.  But, I will fool around with it.  I have it on my machine.

In your first response I note with interest the link to Gnuplot.  I'll check it out.

Thanks,
Mark
Title: Re: plotting in masm 32 bit
Post by: HSE on March 07, 2018, 02:09:27 AM
Hi Mark!

You can see also ObjAsm32\Examples\Demo8. I also make an example, but I don't remeber why it's not uploaded. It's here (http://masm32.com/board/index.php?topic=5244.msg57624#msg57624) . Requiere AsmC or Hjwasm with long lines (not .for, etc)
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 07, 2018, 03:10:59 AM
hello HSE.

I'm not familiar with objasm, but will investigate. 

I should have mentioned earlier to JJ that the plotting I want to do is to plot the numerical solution of ordinary differential equations.  What that entails is to take an array of doubles that are solution points and plot them.  The plots might make use of colors and different line styles plus axis labels (time, yout) and legends.  Nothing fancy.  JJ shows good examples above.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: HSE on March 07, 2018, 03:13:50 AM
That is my example  :t

    (not too easy, I'm afraid)
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 07, 2018, 05:05:53 AM
Quote from: markallyn on March 07, 2018, 01:51:35 AMThe GSL approach with MasmBasic produces exactly the sort of plots I'm interested in.  Unfortunately, I am not fluent in MasmBasic.  But, I will fool around with it.  I have it on my machine.

Hi Mark,

Use the 10 lines proggie in reply #1 as a template, it is a full-fledged Windows application. The syntax is unorthodox but not difficult. There is a lengthy thread on Event-driven programming (http://masm32.com/board/index.php?topic=5976.0) explaining the logic. Here is another short example:

GuiParas equ "MasmBasic: fast, compact and easy to use", x50, y50, w1200, h666
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste

include \masm32\MasmBasic\Res\MbGui.asm         ; this line replaces include \masm32\include\masm32rt.inc

  ; any startup code - this is indeed the WM_CREATE handler
  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ct=-400 To 400
        SetFloat MySinus(ct+400)=Sinus(ct)      ; there are other ways to populate the array
  Next

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

Event Paint
  ArrayPlot RgbCol(192, 222, 255)       ; init & set background
  ArrayPlot MySinus(), 0, lines=3, 00100204h   ; draw the array with 3px lines and left top right bottom margins
  ArrayPlot exit, "Playing with Sinus() plots"  ; finish with a title
  GuiTextBox 50.0-70, 40.0, 140, 96, Str$("Painting took %3f ms", GuiMs/1000), bcol RgbCol(160, 255, 192)
EndOfEvents    ; ----- end of event zone ----

MyAlgo proc    ; ----- start of user-defined procs ----
  ret
MyAlgo endp

EndOfCode
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 08, 2018, 01:03:26 AM
Good morning/afternoon, Jochen,

After studying your example a bit I realized it could be/should be a template for what I want to accomplish.  By the time that penetrated my thick skull it was too late in the day to do anything about it.   But today is a new day.

One point of clarification regarding gnuplot:  In my gnuplot distro there is no single gnuplot.dll.  There are a bunch of Linux derived .dll's (pango, etc.), but I don't see a gnuplot.dll.  So, what to load to do the job--should I wish to try it in this fashion--is problematic.

Second:  You obviously are fully aware of GSL and have used it.  I have too, but in C applications, never assembler.  I love GSL.  But, I don't see how I would use it.  There is also OCTAVE which has plot routines in it.  I haven't looked into how one might use them, however.

Thanks for taking an interest in this.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: LiaoMi on March 08, 2018, 04:14:41 AM
Quote from: markallyn on March 06, 2018, 07:19:16 AM
Hello all,

I am looking for a plot library that is callable from masm.  If none such exists can someone come up with a relatively straightforward method for running gnuplot or similar from masm?

Regards,
Mark Allyn

Hi markallyn,

look at the library - MathGL http://mathgl.sourceforge.net/doc_en/Main.html (http://mathgl.sourceforge.net/doc_en/Main.html)
Book  ::) - http://downloads.sourceforge.net/mathgl/mathgl-2.4.1.eng.pdf (http://downloads.sourceforge.net/mathgl/mathgl-2.4.1.eng.pdf)
MathGL utilities with all required DLL files for 32-bit and 64-bit versions of MS Windows http://downloads.sourceforge.net/mathgl/mgl_scripts-2.4.1.win32.7z (http://downloads.sourceforge.net/mathgl/mgl_scripts-2.4.1.win32.7z) and http://downloads.sourceforge.net/mathgl/mgl_scripts-2.4.1.win64.7z (http://downloads.sourceforge.net/mathgl/mgl_scripts-2.4.1.win64.7z)

(http://mathgl.sourceforge.net/png/dat_extra.png)

Pictures
http://mathgl.sourceforge.net/doc_en/Pictures.html#Pictures (http://mathgl.sourceforge.net/doc_en/Pictures.html#Pictures)

(http://mathgl.sourceforge.net/png/cont_xyz.png)

MathGL is ...
a library for making high-quality scientific graphics under Linux and Windows;
a library for the fast data plotting and data processing of large data arrays;
a library for working in window and console modes and for easy embedding into other programs;
a library with large and growing set of graphics.
Now MathGL has more than 35000 lines of code, more than 55 general types of graphics for 1d, 2d and 3d data arrays, including special ones for chemical and statistical graphics. It can export graphics to raster and vector (EPS or SVG) formats. It has Qt, FLTK, OpenGL interfaces and can be used even from console programs. It has functions for data processing and script MGL language for simplification of data plotting. Also it has several types of transparency and smoothed lightning, vector fonts and TeX-like symbol parsing, arbitrary curvilinear coordinate system and many over useful things. It can be used from code written on C++/C/Fortran/Python/Octave and many other languages. Finally it is platform independent and free (under GPL v.2.0 license).


Tutorial: How to compile a glut version of MathGL 2.2 with Visual Studio 2010 on Windows - https://groups.google.com/forum/#!topic/mathgl/t-X9eg-5joU (https://groups.google.com/forum/#!topic/mathgl/t-X9eg-5joU) You can transfer to a new build from 2017  :t

I still can not compile a smaller library, cmake gives a nonsense, when the smaller library is compiled, we can convert the headers  :icon_cool: and try in action on examples!
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 08, 2018, 04:36:45 AM
Quote from: LiaoMi on March 08, 2018, 04:14:41 AMlook at the library - MathGL http://mathgl.sourceforge.net/doc_en/Main.html (http://mathgl.sourceforge.net/doc_en/Main.html)

Looks interesting. Have you tried it yourself? For example, what would be the equivalent MathGL code to the demo below (exe attached)?

include \masm32\MasmBasic\Res\MbGui.asm
  Dim MySinus() As REAL8        ; prepare an array for being plotted (real4 or real8)
  Dim MyCosinus() As REAL4

  For_ ct=-400 To 400
        SetFloat MySinus(ct+400)=Sinus(ct)      ; fill two
        SetFloat MyCosinus(ct+400)=Cosinus(ct)  ; arrays
  Next

Event Paint
  ArrayPlot RgbCol(200, 255, 255)                      ; init & set background
  ArrayPlot MySinus(), RgbCol(255, 255, 0), lines=3    ; plot the sinus wave in yellow, 3px
  ArrayPlot MyCosinus(), RgbCol(0, 255, 0), lines=5    ; plot the cosinus wave in green, 5px
  ArrayPlot exit, "Sinus & Cosinus demo"               ; finish with a title
EndOfCode

Title: Re: plotting in masm 32 bit
Post by: LiaoMi on March 08, 2018, 04:53:48 AM
Hi jj2007,

I'll try as soon as I can compile the project  :icon_confused: Already now you can look at the api, which can be seen from the link "pictures". Here is an example

int sample(mglGraph *gr)
{
  mglData y;  mgls_prepare1d(&y); gr->SetOrigin(0,0,0);
  gr->SubPlot(2,2,0,"");  gr->Title("Plot plot (default)");
  gr->Box();  gr->Plot(y);

  gr->SubPlot(2,2,2,"");  gr->Title("'!' style; 'rgb' palette");
  gr->Box();  gr->Plot(y,"o!rgb");

  gr->SubPlot(2,2,3,"");  gr->Title("just markers");
  gr->Box();  gr->Plot(y," +");

  gr->SubPlot(2,2,1); gr->Title("3d variant");
  gr->Rotate(50,60);  gr->Box();
  mglData yc(30), xc(30), z(30);  z.Modify("2*x-1");
  yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)");
  gr->Plot(xc,yc,z,"rs");
  return 0;
}


the result is

(http://mathgl.sourceforge.net/png/plot.png)
Title: Re: plotting in masm 32 bit
Post by: LiaoMi on March 08, 2018, 05:04:17 AM
To exclude Qt and apply the code only with OpenGL, we need to compile a new VS17 project, two libraries can be used:

GLUT 3.7.6 pre-compiled libs (32 and 64): http://www.ece.lsu.edu/xinli/OpenGL/glut-3.7.6-bin-32and64.zip (http://www.ece.lsu.edu/xinli/OpenGL/glut-3.7.6-bin-32and64.zip)
GLUT 3.7.6 source codes: http://www.ece.lsu.edu/xinli/OpenGL/glut-3.7.6-src-32and64.zip (http://www.ece.lsu.edu/xinli/OpenGL/glut-3.7.6-src-32and64.zip)

freeglut 3.0.0 MSVC Package (32 and 64) https://www.transmissionzero.co.uk/files/software/development/GLUT/freeglut-MSVC.zip (https://www.transmissionzero.co.uk/files/software/development/GLUT/freeglut-MSVC.zip)
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 08, 2018, 06:27:26 AM
good afternoon/evening Jochen,

OK.  I downloaded uasm32, then copied your code as jjdraw.asm and ran a little .bat file (makejjdraw.bat).  Got an error in assembly step I don't understand.  Here's a copy of the assembler output:
Quote
UASM v2.46, Feb  1 2018, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

*** MasmBasic version 25.12.2017 ***
** SetProcessUserModeExceptionPolicy
\masm32\MasmBasic\Res\MbGui.asm(2339) : Error A2164: Empty (null) string
repargA(85)[MasmBasic.inc]: Macro called from
  uChr$(1)[MasmBasic.inc]: Macro called from
   \masm32\MasmBasic\Res\MbGui.asm(2339): Included by
    jjdraw.asm(1): Main line code
## MasmBasic GUI build ##
jjdraw.asm: 10 lines, 1 passes, 256 ms, 0 warnings, 1 errors
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file "jjdraw.obj"
Press any key to continue . . .

And here's a copy of the little .bat file:
Quote
@echo off
if exist jjdraw.obk del jjdraw.obj
..\uaSM32.exe /c /coff /Zi jjdraw.asm
..\bin\link.exe /subsystem:console /entry:main /debug /pdb:jjdraw.pdb /machine:X86 jjdraw.obj
pause

Could you suggest a "fix" to rid the code of bugs?

One other thing:  How would I plot an array of floats (output from a numerical integrator) using your nice masmbasic approach?

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 08, 2018, 06:42:42 AM
Good afternoon\evening, LiaoMi,

I will have to investigate more thoroughly later.  The drawings are really nice.  From the code you show, it looks like the calling program is in a high-level language similar to R, i.e. object-oriented, with arrows doing the assingments.  If so, there is most definitely a learning curve that is rather steep.  So, given that I wonder what the advantages might be compared to a scripting language like Gnuplot where the curve is quite shallow.

But, I will look more intensively.  Thanks for bringing this to my attention and also for the excellent examples.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: LiaoMi on March 08, 2018, 07:57:54 AM
Quote from: markallyn on March 08, 2018, 01:03:26 AM
Good morning/afternoon, Jochen,

After studying your example a bit I realized it could be/should be a template for what I want to accomplish.  By the time that penetrated my thick skull it was too late in the day to do anything about it.   But today is a new day.

One point of clarification regarding gnuplot:  In my gnuplot distro there is no single gnuplot.dll.  There are a bunch of Linux derived .dll's (pango, etc.), but I don't see a gnuplot.dll.  So, what to load to do the job--should I wish to try it in this fashion--is problematic.

Second:  You obviously are fully aware of GSL and have used it.  I have too, but in C applications, never assembler.  I love GSL.  But, I don't see how I would use it.  There is also OCTAVE which has plot routines in it.  I haven't looked into how one might use them, however.

Thanks for taking an interest in this.

Regards,
Mark

In this case, you can not use gnuplot directly, it's impossible, otherwise you have to write your own wrapper, just like here done https://github.com/raimundomartins/gnuplotcha (https://github.com/raimundomartins/gnuplotcha) All this is not so effective for the programmer in assembler :icon_redface:

I compiled separately dll and libraries for both processor modes https://mega.co.nz/#!1h4XgRbL!AAAAAAAAAAA9aMZukBleowAAAAAAAAAAPWjGbpAZXqM (https://mega.co.nz/#!1h4XgRbL!AAAAAAAAAAA9aMZukBleowAAAAAAAAAAPWjGbpAZXqM) Unfortunately, I did not make Headers and Includes for assembler, there are errors during the conversion of structures  :(

Title: Re: plotting in masm 32 bit
Post by: HSE on March 08, 2018, 09:36:56 AM
subsystem:windows
Try removing entry.
(IF you solve the assembling problem) 

The last JJ example only work from RichMasm!

Out of RichMasm, before MbGui.asm requiere:
GuiParas equ "MasmBasic: I have forgotten something", x50, y50, w1200, h666

Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 08, 2018, 01:40:58 PM
Quote from: markallyn on March 08, 2018, 06:27:26 AM
good afternoon/evening Jochen,

OK.  I downloaded uasm32, then copied your code as jjdraw.asm and ran a little .bat file (makejjdraw.bat).  Got an error in assembly step I don't understand.

Hi Mark,

I don't understand it either, it's weird - in principle, such code should build "as is" with qEditor or RichMasm. But HSE found the culprit: If it is not built with RichMasm, then the GuiParas line (see attached source) is needed. There is no logic in this, though :(

Anyway, attached two batch files for building projects with UAsm32, plus the demo code in *.asm, tested OK. In case you want to use qEditor.exe, add two lines in \Masm32\menus.ini before &Tools (but RichMasm is far easier to use IMHO - drag the *.asm or *.asc over \Masm32\MasmBasic\RichMasm.exe, hit F6, done...):

Build+Run Console,\MASM32\BldRunUAsmConsole.bat "{b}"
Build+Run Windows,\MASM32\BldRunUAsmConsole.bat "{b}"

[&Tools]


Re how to plot an array: Just use the loop in the demo with SetFloat MyArray(ct)=ST(0) (obviously with whatever you have in the FPU). If you have any difficulties with that, please post a few lines showing how you get your values, and we will sort it out.

Regards,
Jochen
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 09, 2018, 01:57:52 AM
good morning/afternoon/evening JJ2007, HSE, and LiaoMi,

Many thanks for your suggestions.  I would not have tumbled to the RichMasm notion without your assistance.  In addition, it may well be that I must use /subassembly:windows rather than /subsystem:console.  That alone might be required.  Later this morning I will play with it some more.

JJ2007--Thanks for the assistance with plotting arrays.  This should be sufficient to answer my question.

I will keep you all informed of progress.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 09, 2018, 03:56:11 AM
Good afternoon, JJ,

OK, I tried using bldrunuasmconsole.bat and got, unfortunately, the same error as I did using my .bat file.  Someone, HSE or LiaoMi wrote that it needed to be built with RichMasm, and I'd like to try that.  So I peeked in my download of MasmBasic and sure enough there is a listing there for RichMasm.exe.  However, the listing also shows that there are 0 bytes of code there and I get a nasty message from the sys informing me that the file isn't valid. 

Pest that I am, could you please tell me how to download richmasm?  I'll keep trying to find out on my own but if you happen to read this I'd be grateful.

Mark
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 09, 2018, 04:41:20 AM
Update-

It appears that my Norton firewall is preventing SetupMasmBasic.exe from installing RichMasm.exe.  I have tried to turn the filter off temporarily, but without any success.  It runs the Setup fine, but when setup tries to work its magic, Norton bars it.

I'll keep plugging away...

Mark
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 09, 2018, 07:39:45 AM
Quote from: markallyn on March 09, 2018, 04:41:20 AMIt appears that my Norton firewall is preventing SetupMasmBasic.exe from installing RichMasm.exe.  I have tried to turn the filter off temporarily, but without any success.  It runs the Setup fine, but when setup tries to work its magic, Norton bars it.

Most of us stumble sooner or later over false positives. Some AV allow to exclude e.g. C:\Masm32 and its subfolders, but I have no idea how Norton handles that. Anyway, I attach a non-packed version of RichMasm, to be extracted to ?:\Masm32\MasmBasic\RichMasm.exe - for Jotti, this version is absolutely clean. (https://virusscan.jotti.org/en-US/filescanjob/tcfgisxl61) In contrast, the packed version has 2 positives with ClamAV and F-Prot. (https://virusscan.jotti.org/en-US/filescanjob/e0ozdicugl). Norton is not in the list, though.

But the demo should assemble also with the batch files, provided the GuiParas line is in the right place:GuiParas equ "Sinus and Cosinus Demo"
include \masm32\MasmBasic\Res\MbGui.asm
...


If you got RichMasm working, note that it uses by default \Masm32\bin\UAsm64.exe (you have UAsm32, right?). You can force UAsm32 with a line
; OPT_Assembler UAsm32
... somewhere in your source, otherwise download UAsm64 (http://www.terraspace.co.uk/uasm.html#p2) if your OS is 64 bit.
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 09, 2018, 08:35:58 AM
JJ-

Thanks for the last message.  It answered the question I was about to ask.  Yes, I am running uasm32 and was getting a message telling me I needed to install uasm64. 

Bloody firewalls.  When I finally figured out how to breach it the installer ran perfectly.

Well, anyway, we seem to be getting there!

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: HSE on March 09, 2018, 08:50:35 AM
You need in some part of the code (no matter where, I think):
; OPT_Assembler UASM32
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 09, 2018, 09:26:39 AM
Hello HSE.

Yes, it is essential.  Thanks.

Mark
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 10, 2018, 02:12:39 AM
windows provides a function named PolyBezier

https://msdn.microsoft.com/en-us/library/dd162811(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/dd162811(v=vs.85).aspx)

you need to do some "pre-math" to convert an array of data points into an array of control points
then, pass the address of the control point array to PolyBezier and it will draw the graph

i wrote a routine to convert an array of data points to control points, using FPU code
the function is named "deBoorBezierSpline", and it calls a helper subroutine named "GetFirstControlPoints"

you can download a little demo program here

http://masm32.com/board/index.php?topic=1969.msg20671#msg20671 (http://masm32.com/board/index.php?topic=1969.msg20671#msg20671)

Title: Re: plotting in masm 32 bit
Post by: markallyn on March 10, 2018, 02:24:49 AM
Hello Dave,

Thanks for the tip and the code.  I will follow up on it.  I was completely unaware of the polybezier function.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 10, 2018, 02:34:22 AM
it works well - surprisingly fast  :t

i will give you a little heads-up
sometimes, the minima and maxima of the graph exceeds the range of data point values (not by a lot)
typically, it's ok - in fact, a good extrapolation of the real world data
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 10, 2018, 03:33:49 AM
Good morning/afternoon JJ:

Trying to figure out how to do the array plotting using your modified example 1.  Here is the code so far:

Quote
; OPT_Res   0      ; RichMasm thinks this code needs no resources - delete if rsrc.rc is needed
include \masm32\MasmBasic\Res\MbGui.asm
plotpoints   REAL4  1.1,2.2,3.3,4.4,5.5

;OPT_Assembler uasm32
  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  finit
  For_ ct=0 To 4
        fld  plotpoints(ct)
        SetFloat MySinus(ct)=st(0)
  Next
Event Paint
  ArrayPlot RgbCol(192, 222, 255)               ; init & set background
  ArrayPlot MySinus(), 0, lines=2               ; draw the array with 2px lines
  ArrayPlot exit, "Playing with Sinus() plots"  ; finish with a title
EndOfCode


As you can see I am just creating a very simple test array and then trying to print in a loop.  Unfortunately, I get an error when trying to build with richmasm.exe.  The error is:

Quote
Cannot add two relocatable labels
This is being emitted due to line 9 above.

What do you think?

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 10, 2018, 04:27:15 AM
Dave:

I downloaded the "little demo" code and was rather overwhelmed by its extent.  It is impressive and you are being (as usual) overly modest in sizing it.  I have to confess I really don't understand how to input a set of points to be plotted.  This could happen in at least one of two ways:  by passing an array of some sort, or by passing a function with x-coordinates to be evaluated.  How do you assign inputs?

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 10, 2018, 04:29:22 AM
Hi Mark,
you are almost there:include \masm32\MasmBasic\Res\MbGui.asm
.data
plotpoints   REAL4  1.1,2.2,3.0,4.0,5.5 ; OPT_Assembler uasm32
.code
  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ecx=0 To 4
        fld  plotpoints[4*ecx]
        SetFloat MySinus(ecx)=ST(0)
  Next
Event Paint
  ArrayPlot RgbCol(192, 222, 255)               ; init & set background
  ArrayPlot MySinus(), 0, lines=2               ; draw the array with 2px lines
  ArrayPlot exit, "Playing with Sinus() plots"  ; finish with a title
EndOfCode


This puts plotpoints in the .data section and uses ecx as a counter, so that plotpoints[4*ecx] can be used. Works fine  :biggrin:
I modified two values to avoid a straight line ;-)

P.S.: Here is a variant using StringToArray (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1129):

include \masm32\MasmBasic\Res\MbGui.asm

  Dim MyR4() As REAL4
  StringToArray FileRead$("MyData.tab"), MyR4()

Event Paint
  ArrayPlot RgbCol(192, 222, 255)                      ; init & set background
  ArrayPlot MyR4(), RgbCol(255, 0, 0), lines=2         ; draw the array with 2px lines
  ArrayPlot exit, "Data read from a tab file"          ; finish with a title
EndOfCode


Sample file attached, must be in the same folder as the exe.
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 10, 2018, 08:24:24 AM
Good evening, JJ,

Once again, I would never have come up with this solution.  But, I see now how it works.

Question: In your original post you referred to a sinus() function.  I assume this is a built-in in masmbasic.  If so, where can I find a list of others, for example, exp, tan, sqrt,, etc.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 10, 2018, 08:32:48 AM
Good evening once more,

You may disregard my question re masmbasic functions.  I found them by looking through masmbasic.inc.  It isn't really convenient, but it works.

Thanks again,
Mark
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 10, 2018, 10:21:09 AM
Quote from: markallyn on March 10, 2018, 08:32:48 AMI found them by looking through masmbasic.inc

In the RichMasm menu File, there is "Guide to MasmBasic", listing about 400 functions. Press Ctrl F to search, for example, Exp
But MasmBasic is relatively weak on math; you will still need to know the FPU and roll your own.
Title: Re: plotting in masm 32 bit
Post by: HSE on March 11, 2018, 01:45:35 AM
Quote from: markallyn on March 10, 2018, 08:24:24 AM
where can I find a list of others, for example, exp, tan, sqrt,, etc.

qWord's SmplMath  :t
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 12, 2018, 01:14:07 PM
the deBoorBezierSpline function wants to see an array of POINT structures
the values for each point are related to pixel locations in the window where the graph is to be drawn

the array is constructed of "knot points" and "control points"
the knot points are essentially your data points, converted into pixel locations
so, you create the array, then fill in the knot points, and pass the address to deBoorBezierSpline
you also tell the function the number of knot points in the array (must be at least 3)
the function will fill in the control points for you
when it's done, the array is suitable for use with the PolyBezier function (used in WM_PAINT code)

the total number of POINT structures in the array is Knots + 2 * (Knots - 1)

knot point
control point
control point
knot point
control point
control point
knot point
.
.
.
knot point
control point
control point
knot point


as i mentioned earlier, YOU initialize the knot points - the function fills in the control points for you
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 12, 2018, 02:01:48 PM
... in the demo program, i used an array with 36 knot points
so, there are 2*(36-1) = 70 control points
a total of 106 POINT structures in the array

i make up fake data by using a random number generator
the X step is always 10 pixels and the Y points are generated randomly
equal X spacing is not a requirement, it was just easy to generate that way

i used 2 arrays, one to hold the currently displayed array, one to generate new data
i flip back and forth between the 2 arrays
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 13, 2018, 07:26:04 AM
Dave and JJ,

I had to briefly abandon the plot problem due to traveling.  I'm back home now and will resume its solution--thanks to all of your help.

I will post a .zip file that contains a set of plot points that are the solution of a simple ordinary diff eqn.  This will give you a typical data set from the sort of math problems I enjoy solving.  In the past I have used C and called GnuScientificLibrary routines or Octave or similar.  I want to do the same thing in assembly.

Thanks.  Please keep tuned to this thread.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 13, 2018, 11:20:12 AM
Quote from: markallyn on March 13, 2018, 07:26:04 AMI will post a .zip file that contains a set of plot points that are the solution of a simple ordinary diff eqn.  This will give you a typical data set

Very good. If you want to try yourself, see reply #30:  Dim MySinus() As REAL4        ; prepare an array for being plotted (real4 or real8)
  For_ ecx=0 To 4
        fld plotpoints[4*ecx]    ; <<<< replace with whatever produces your values.
        SetFloat MySinus(ecx)=ST(0)   ; this pops the value from ST(0) to the array
  Next
Title: Re: plotting in masm 32 bit
Post by: aw27 on March 13, 2018, 04:15:31 PM
This may sound like a sacrilege but there pretty good online 2-D plotters. At least as good as others I have seen around here.
http://itools.subhashbose.com/grapher/index.php
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 14, 2018, 06:05:03 AM
Hello JJ and others, most recently aw27:

Apologies for being a little late to the party with a test data set:  rk4.zip contains values of time from 0 to 1 for the solution to dy/dt=1-2*y(2).  Y0 is 1.0.  A very simple function solved using 4th order runge-kutta technique.

First column of doubles is clearly t and second is y(t).

Thanks for all your inputs.

I'll check out the 2-D plotter mentioned by aw27.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 14, 2018, 06:06:48 AM
...OOPs.

Equation should read: 

Quote
dy/dt=1-2*y(t)

Lousy at typos!

Mark
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 14, 2018, 06:45:51 AM
i am currently working on a simplified form of the PolyBezier demo program
it is for a single static graph - you enter data points and assemble
i am adding a little complexity in that, when you re-size the window, it re-scales the graph
should finish it later today or tomorrow
i will use your data set  :t
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 14, 2018, 08:47:51 AM
Quote from: markallyn on March 14, 2018, 06:05:03 AMtest data set:  rk4.zip contains values of time from 0 to 1 for the solution to dy/dt=1-2*y(2).  Y0 is 1.0

include \masm32\MasmBasic\Res\MbGui.asm
  Dim rk() As REAL4             ; define a REAL4 array
  StringToArray 99, rk()        ; fill it; 99 is the resource ID for rk4.txt
Event Paint
  ArrayPlot RgbCol(192, 255, 255)                      ; init & set background
  ArrayPlot rk(XY), RgbCol(222, 0, 0), lines=2         ; draw the array with 2px red lines
  ArrayPlot exit, "Data read from a resource"          ; finish with a title
EndOfCode


Does it look correct? Project attached - to build it, rk4.txt must be in the same folder.
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 14, 2018, 09:07:30 AM
JJ, Dave, and aw27,

aw27:  Yes, there are a number of excellent 2-d plotters available.  Gnuplot is one, and it's excellent and opensource, but there are many others too.  What I am trying to accomplish is to write in assembly (masm, uasm, Jwasm, goasm, poasm,nasm,  etc.) a numerical integrator that can call a plotter written also in assembly.  Why?  I could write a c/c++ program, write results to a file, and then call a plotter.  It would be much easier, but not nearly as much fun or as instructive.

Dave:  Great news.  Go for it!

JJ:  Yup.  That's it!  Subsequent to the posting I ran the integrator again and generated plot points out to 2.0.  It clearly shows that the function asymptotes at 0.5.  Now, here's my challenge:  How to put labeled axes and tick marks on the plot.  Can it be done?

Regards,
Mark

Title: Re: plotting in masm 32 bit
Post by: dedndave on March 14, 2018, 10:19:29 AM
i would say so  :P
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 14, 2018, 04:49:56 PM
@DednDave: Very cute :t Can you post the source?

Quote from: markallyn on March 14, 2018, 09:07:30 AMHow to put labeled axes and tick marks on the plot.  Can it be done?

Everything can be done in assembler :P

But not everything is already implemented as a "SetLegends" macro (except for pie charts, see attachment). By hand, this is possible:

include \masm32\MasmBasic\Res\MbGui.asm
.data?
hPen    dd ?
.code
  MakeFont hHorzFont, Height:18, Weight:FW_SEMIBOLD
  MakeFont hVertFont, Height:18, Weight:FW_SEMIBOLD, Escapement:900
  Dim rk() As REAL4             ; define a REAL4 array
  Dim range(4) As REAL4         ; create another array
  ArraySet range()=-0.1, 1.0, 1.05, 0.0         ; set a plotting range
  StringToArray 99, rk()        ; fill it; 99 is the resource ID for rk4.txt
  mov hPen, rv(CreatePen, PS_SOLID, 3, RgbCol(0, 0, 80))

Event Paint
  ArrayPlot RgbCol(192, 255, 255)       ; init & set background
  ArrayPlot range(XY),,,, setrange     ; use a fake array to set the ranges
  ArrayPlot rk(XY), RgbCol(222, 0, 0), lines=2         ; draw the array with 2px red lines (try bars=40)
  ArrayPlot exit, "Data read from a resource"  ; finish with a title

  invoke SetBkColor, PtDC, RgbCol(192, 255, 255)
  GuiText 25, 400, "Hello, I am the Y axis", font hVertFont
  GuiLine 50, 50, 50, 600, hPen
  GuiText 420, 610, "And I am the X axis", font hHorzFont
  GuiLine 50, 600, 1100, 600, hPen
EndOfCode


GuiLine and GuiText are MasmBasic macros. However, you can roll your own legend using PtDC after the ArrayPlot exit line, for example:

invoke TextOut, PtDC, 300, 330, Chr$("Hello"), 5
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 15, 2018, 12:49:09 PM
Quote from: jj2007 on March 14, 2018, 04:49:56 PM
@DednDave: Very cute :t Can you post the source?

sorry Jochen - it may become proprietary source code
i may post a portion of it at some point, though
it has been my intention to make the custom button code available

attached is SimpleBezier (the png is just an image)
enter your own set of data points and assemble
re-size the window, and it re-scales the graph
Title: Re: plotting in masm 32 bit
Post by: raymond on March 16, 2018, 01:03:37 PM
QuoteWhat I am trying to accomplish is to write in assembly (masm, uasm, Jwasm, goasm, poasm,nasm,  etc.) a numerical integrator that can call a plotter written also in assembly.  Why?  I could write a c/c++ program, write results to a file, and then call a plotter.  It would be much easier, but not nearly as much fun or as instructive.

You are absolutely right with that last sentence.

If you want to use the FPU, a good library is available with the MASM32 SDK or you can download it from http://www.ray.masmcode.com/fpu.html#fpulib
Each of its functions has a lot of overhead to cater to the allowed types of input and output. With time, you may want to speed it up by writing your own code specifically designed for your own use. (The above download also includes the source code of each function.) An FPU tutorial is also available on the same site.

While you are at it, you may realize that you don't need all the precision available from the FPU. You might also want to experiment with fixed point math. Here again, a library is available for numerous functions (including all source code) at http://www.ray.masmcode.com/fixmath.html

I'm also attaching a small program (complete with source code) which I wrote some 20 years ago to display biorythms using fixed point math to draw the sinusoidal curves.

Title: Re: plotting in masm 32 bit
Post by: dedndave on March 16, 2018, 02:05:21 PM
always good to see you, Raymond  :t

Ray makes a good point about resolution or precision
the nicer display systems these days might have 12 bits of resolution
printers, maybe 8 bits
so, 32 bit integers are overkill, really
the FPU is nice to handle values over a wide range
or, if exponential or trigonometric functions are needed (of course)
otherwise, integer math is fast and easy
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 16, 2018, 02:51:01 PM
Quote from: raymond on March 16, 2018, 01:03:37 PMI'm also attaching a small program (complete with source code) which I wrote some 20 years ago to display biorythms using fixed point math to draw the sinusoidal curves.

Very nice indeed :t

I tried to build it but: Cannot open file: "\masm32\include\mix.inc"
Title: Re: plotting in masm 32 bit
Post by: markallyn on March 17, 2018, 01:53:11 AM
Good morning/afternoon/evening, Raymond, Dave, and Jochen:

Wow, you folks have really risen to the challenge.  Very impressive indeed.  I have saved all your zip files and will play with them this afternoon USA EDT time.  My guess is that I will encounter same problem with mix.inc that JJ did so I'm hoping Raymond will share this .inc or a workaround, if possible. 

JJ:  As you know I'm having problems running RichMasm on my 64 bit machine.  So, I can't try out your code on the 64 bit box until I've resolved the problem with masm32rt.inc and friends.  But, I can try it on my 32 bit box and it should run there.

Dave:  OK, you did the exponential curve (solution to dy/dt=1.0 - 2.0*y on [0,1]).  Very nice.  But, if I understand your response to JJ the source code is for the moment anyway proprietary.  How about creating a .dll that users can load and call with some nice interface that specifies the plot coordinates, axes, labels, ticks, and legend.  I for one would find this very cool.  I would award you the Alexander Nevsky prize.

Regards,
Mark
Title: Re: plotting in masm 32 bit
Post by: raymond on March 17, 2018, 03:04:37 AM
Quote from: jj2007 on March 16, 2018, 02:51:01 PM
Quote from: raymond on March 16, 2018, 01:03:37 PMI'm also attaching a small program (complete with source code) which I wrote some 20 years ago to display biorythms using fixed point math to draw the sinusoidal curves.

Very nice indeed :t

I tried to build it but: Cannot open file: "\masm32\include\mix.inc"

It is part of the package available at http://www.ray.masmcode.com/fixmath.html (indicated previously). Apart from that, you may have to modify the code to indicate where you effectively copy the required files if you don't have/want the used "masm32" folder tree.
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 17, 2018, 04:21:58 AM
Quote from: raymond on March 17, 2018, 03:04:37 AMIt is part of the package available at http://www.ray.masmcode.com/fixmath.html

Works perfectly if
- mix.inc goes to \Masm32\include\Mix.inc
- mix.lib goes to \Masm32\lib\Mix.lib
- line 40 of Mix.inc is modified as MixError EQU 80000000h (ERROR is already defined elsewhere; and it's not used in this source)
:t
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 17, 2018, 05:13:44 AM
Quote from: markallyn on March 17, 2018, 01:53:11 AM
But, if I understand your response to JJ the source code is for the moment anyway proprietary.  How about creating a .dll that users can load and call with some nice interface that specifies the plot coordinates, axes, labels, ticks, and legend.  I for one would find this very cool.  I would award you the Alexander Nevsky prize.

well - that program may be sold, at some point

as for making lines and hash-marks, it is easy-peazy

just use MoveToEx and LineTo

https://msdn.microsoft.com/en-us/library/dd145069(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/dd145029(v=vs.85).aspx

text is not as easy....
for the numbers, i used a 6x8 terminal font

;8 x 12  Terminal
;4 x 6   Terminal
;5 x 12  Terminal
;6 x 8   Terminal
;7 x 12  Terminal

;lfn           LOGFONT <8,6,,,,,,,OEM_CHARSET,,,,FIXED_PITCH,"Terminal">
; lfHeight          DWORD ?
; lfWidth           DWORD ?
; lfEscapement      DWORD ?
; lfOrientation     DWORD ?
; lfWeight          DWORD ?
; lfItalic          BYTE  ?
; lfUnderline       BYTE  ?
; lfStrikeOut       BYTE  ?
; lfCharSet         BYTE  ?
; lfOutPrecision    BYTE  ?
; lfClipPrecision   BYTE  ?
; lfQuality         BYTE  ?
; lfPitchAndFamily  BYTE  ?
; lfFaceName        BYTE  LF_FACESIZE dup(?)

    mov     edx,offset lfn
    mov dword ptr [edx].LOGFONT.lfFaceName,'mreT'
    mov dword ptr [edx].LOGFONT.lfFaceName+4,'lani'
    mov byte ptr [edx.LOGFONT.lfFaceName+8,0
    INVOKE  CreateFontIndirect,edx
    mov     hNumFont,eax


and, the following functions...

SetTextColor
https://msdn.microsoft.com/en-us/library/dd145093(v=vs.85).aspx

SetBkColor (actually, i used opaque mode, so didn't need this one)
https://msdn.microsoft.com/en-us/library/dd162964(v=vs.85).aspx

SetBkMode
https://msdn.microsoft.com/en-us/library/dd162965(v=vs.85).aspx

there are a few functions to display text, i use this one because it is relatively fast
ExtTextOut
https://msdn.microsoft.com/en-us/library/dd162713(v=vs.85).aspx

to make vertical text, i use the same font
at program initialization, i create a bitmap with the entire ASCII set
i rotate it 90 degrees, and use that to make vertical text   :P
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 17, 2018, 05:19:41 AM
i could show you more, but i hate to suck all the fun out of it  :lol:

;***********************************************************************************************

VtxtInit PROC USES EBX ESI EDI

;hNumFont must be initialized prior to call (6x8 terminal font)

;-----------------------------------------

    LOCAL   bmis        :BITMAPINFO256
    LOCAL   pvBits1     :LPVOID
    LOCAL   pvBits2     :LPVOID
    LOCAL   hbmpDib1    ;HBITMAP
    LOCAL   hbmpDib2    ;HBITMAP
    LOCAL   hbmpMem1    ;HBITMAP
    LOCAL   hbmpMem2    ;HBITMAP
    LOCAL   hdcMem1     :HDC
    LOCAL   hdcMem2     :HDC

;-----------------------------------------

;initialize 256-color BITMAPINFO structure

;BITMAPINFO256   STRUCT
;  bmiHeader       BITMAPINFOHEADER <>
;    biSize          dd ?               ;BITMAPINFOHEADER structure size
;    biWidth         dd ?               ;image width in pixels
;    biHeight        dd ?               ;signed image height in pixels
;    biPlanes        dw ?               ;= 1
;    biBitCount      dw ?               ;= 8
;    biCompression   dd ?               ;= BI_RGB = 0
;    biSizeImage     dd ?               ;image data bytes
;    biXPelsPerMeter dd ?               ;= 0
;    biYPelsPerMeter dd ?               ;= 0
;    biClrUsed       dd ?               ;= 0
;    biClrImportant  dd ?               ;= 0
;  bmiColors       RGBQUAD 256 dup(<>)

;initialize the BMP header structure, 1536x8 pixels, 256 colors

    xor     eax,eax
    mov     bmis.bmiHeader.biSize,sizeof BITMAPINFOHEADER
    mov     bmis.bmiHeader.biWidth,1536
    mov     bmis.bmiHeader.biHeight,8
    mov     bmis.bmiHeader.biPlanes,1
    mov     bmis.bmiHeader.biBitCount,8
    mov     bmis.bmiHeader.biCompression,eax     ;BI_RGB = 0
    mov     bmis.bmiHeader.biSizeImage,8*1536
    mov     bmis.bmiHeader.biXPelsPerMeter,eax
    mov     bmis.bmiHeader.biYPelsPerMeter,eax
    mov     bmis.bmiHeader.biClrUsed,eax
    mov     bmis.bmiHeader.biClrImportant,eax

;fill the palette with 256 colors, all plot bg color

;rgbbg = rrggbb
;crefbg = bbggrr

    mov     eax,RGB_PLOTBG
    lea     edi,bmis.bmiColors
    mov     ecx,256
    .repeat
        mov     [edi],eax
        dec     ecx
        lea     edi,[edi+4]
    .until ZERO?

;old standard: first color = text background, second color = text foreground

    mov dword ptr bmis.bmiColors+4,ecx

;get the desktop DC

    INVOKE  GetDC,HWND_DESKTOP
    xchg    eax,ebx                                                             ;EBX = hdcDesktop

;create DIB section 1, and select it into DC 1

    xor     ecx,ecx
    INVOKE  CreateDIBSection,ebx,addr bmis,DIB_RGB_COLORS,addr pvBits1,ecx,ecx
    xchg    eax,esi
    mov     hbmpDib1,esi
    INVOKE  CreateCompatibleDC,ebx
    xchg    eax,esi                                                             ;ESI = hdcMem1
    mov     hdcMem1,esi
    INVOKE  SelectObject,esi,eax
    mov     hbmpMem1,eax

;create DIB section 2, and select it into DC 2

    xor     ecx,ecx
    mov     bmis.bmiHeader.biWidth,8
    mov     bmis.bmiHeader.biHeight,1536
    INVOKE  CreateDIBSection,ebx,addr bmis,DIB_RGB_COLORS,addr pvBits2,ecx,ecx
    mov     hbmpDib2,eax
    INVOKE  CreateCompatibleDC,ebx
    mov     hdcMem2,eax
    INVOKE  SelectObject,eax,hbmpDib2
    mov     hbmpMem2,eax

;release the desktop DC

    INVOKE  ReleaseDC,HWND_DESKTOP,ebx

;draw the horizontal text into DC 1

    INVOKE  SelectObject,esi,hNumFont
    push    eax
    INVOKE  SetBkColor,esi,CREF_PLOTBG
    push    eax
    INVOKE  SetTextColor,esi,0
    push    eax
    INVOKE  SetBkMode,esi,OPAQUE
    mov     edi,3020100h
    push    eax
    xor     ebx,ebx
    .repeat
        push    edi
        xor     ecx,ecx
        mov     edx,esp
        INVOKE  ExtTextOut,esi,ebx,ecx,ecx,ecx,edx,4,ecx
        add     edi,4040404h
        pop     edx
        lea     ebx,[ebx+24]
    .until CARRY?
    push    esi
    CALL    SetBkMode
    push    esi
    CALL    SetTextColor
    push    esi
    CALL    SetBkColor
    push    esi
    CALL    SelectObject

;flip and rotate the text pixels from DIB 1 into DIB 2

    push    ebp
    mov     edi,pvBits2
    mov     esi,pvBits1
    mov     ebp,8
    add     edi,8*1535
    .repeat
        push    ebp
        mov     ebp,192
        .repeat
            mov     ax,[esi]
            mov     cx,[esi+2]
            mov     dx,[esi+4]
            mov     bx,[esi+6]
            mov     [edi],al
            mov     [edi-8],ah
            mov     [edi-16],cl
            mov     [edi-24],ch
            mov     [edi-32],dl
            mov     [edi-40],dh
            mov     [edi-48],bl
            mov     [edi-56],bh
            dec     ebp
            lea     esi,[esi+8]
            lea     edi,[edi-64]
        .until ZERO?
        pop     ebp
        add     edi,12289
        dec     ebp
    .until ZERO?
    pop     ebp

;switch the palette in DIB 1 for horizontal XOR text

    lea     edi,bmis.bmiColors
    mov     ecx,256
    xor     eax,eax
    mov     edx,edi
    rep     stosw
    mov dword ptr [edx+4],0FFFFFFh
    INVOKE  SetDIBColorTable,hdcMem1,eax,256,edx

;cleanup and exit with hbmpDib1, hbmpDib2, and pvBits2

    INVOKE  SelectObject,hdcMem1,hbmpMem1
    INVOKE  DeleteDC,hdcMem1
    INVOKE  SelectObject,hdcMem2,hbmpMem2
    INVOKE  DeleteDC,hdcMem2
    mov     ecx,hbmpDib1
    mov     eax,hbmpDib2
    mov     edx,pvBits2
    ret

VtxtInit ENDP

;***********************************************************************************************
Title: Re: plotting in masm 32 bit
Post by: avcaballero on March 17, 2018, 05:39:04 AM
Is it top secret? :lol:
A sign program
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 17, 2018, 06:46:25 AM
Reminds me a bit of my old PolyLine (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1124) demo ;)
Title: Re: plotting in masm 32 bit
Post by: daydreamer on March 18, 2018, 01:07:09 AM
Quote from: raymond on March 16, 2018, 01:03:37 PM

While you are at it, you may realize that you don't need all the precision available from the FPU. You might also want to experiment with fixed point math. Here again, a library is available for numerous functions (including all source code) at http://www.ray.masmcode.com/fixmath.html

nice program Raymond
actually dont you get little more precision with 32bit integer hold more digits than 23 bit float?,your function stored as 31bit decimal data MUL gives you 64bit results

in my youth some friends coded kinda multiplayer monopoly style game, but it was 1930's gangsta style and money was treated as integers with opposite offset as your description of fixed point,each output of player wealth the money integer was  ended with "000", and input divided money by 1000
before subtracting for example how much money player bought drugs,bodyguards etc for
counts as fixed point?

8bit Sine LUT which only hold decimals+conditional code for byte=255:sine=1.0 branch over MUL,if byte=0,store zero as result and branch over MUL
old 8bit cpu code performed a 16bit MUL PROC
counts as fixed point?
maybe should have done a reverse approach with load 8bit precalculated circle value in High byte and just a bitshift it to smaller value like old sprites just resized x1,x2,x4 in star raiders,when circle is small, load 8bit precalculated in low byte and bitshift to bigger
Title: Re: plotting in masm 32 bit
Post by: raymond on March 18, 2018, 03:14:22 AM
Quotedon't you get little more precision with 32bit integer hold more digits than 23 bit float?

Actually, the "23-bit float" really gives you 24 bits of precision; the initial bit is assumed. Another bit being used for the sign, this would leave only 7 bits in a 32-bit dword for the integer portion, leaving you a range of +/- 127. That would definitely not be sufficient to cover the usual screen size range for plotting with the same 'precision' as floats. Using dwords, every additional bit of precision would reduce that range by half.

The 32-bit integer will be more precise than the 23-bit float only when the integer portion exceeds 24 bits, i.e. 16,777,215. But then you don't have many bits left, if any, for the fractional portion.

The mix.lib library mentioned previously uses the lower 16 bits for the fraction, leaving 16 bits for the integer portion and sign for a range of +/- 32767.
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 24, 2018, 03:44:14 AM
Hi Mark,
I am working on the SetAxis macro. Work in progress 8)

The syntax for the X and Y axes will be as follows:  SetAxisX "You can use a different font for the abscissa", s 0, d 0.1, font hHorzFont ; s=start value, d=difference between gridlines
  SetAxisY "The ordinate can be as long as you want it to be", s 0, d 0.05, font hVertFont, penx hPenAxis, peng hPenGrid, format "%__f"
Title: Re: plotting in masm 32 bit
Post by: LiaoMi on March 25, 2018, 01:05:33 AM
Hi,

very interesting code - Source code for 'Practical WPF Charts and Graphics' by Jack Xu https://github.com/Apress/practical-wpf-charts-graphics (https://github.com/Apress/practical-wpf-charts-graphics)
its from the book
(https://github.com/Apress/practical-wpf-charts-graphics/raw/master/9781430224815.jpg)

Maybe, attempt to use together with AsmDotNet64, its also a good idea http://masm32.com/board/index.php?topic=6726.msg72401#msg72401 (http://masm32.com/board/index.php?topic=6726.msg72401#msg72401)
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 25, 2018, 02:36:41 AM
Quote from: LiaoMi on March 25, 2018, 01:05:33 AMvery interesting code - Source code for 'Practical WPF Charts and Graphics' by Jack Xu https://github.com/Apress/practical-wpf-charts-graphics (https://github.com/Apress/practical-wpf-charts-graphics)

Go ahead, Mark's text file with the values used below is attached here (http://masm32.com/board/index.php?topic=6953.msg74711#msg74711) :t
Title: Re: plotting in masm 32 bit
Post by: dedndave on March 26, 2018, 03:09:33 AM
very nice, Jochen  :t
Title: Re: plotting in masm 32 bit
Post by: hutch-- on March 26, 2018, 03:37:02 AM
If I remember correctly, old school GDI had some very good functions for doing multi point graphs. Its been that long since I have used them that I forget the details but writing it to a back buffer then using BitBlt for the client area display was very snappy in performance terms.
Title: Re: plotting in masm 32 bit
Post by: jj2007 on March 29, 2018, 01:11:23 PM
Here is version 4. Note that almost every aspect can be defined individually.