Author Topic: MasmBasic  (Read 143784 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Printing a sinus via the FPU, the CRT, the GSL, and Python
« Reply #240 on: April 03, 2015, 10:59:13 AM »
Update 3 April 15: How to steal goodies from other languages... before distributing or selling any of this, study the copyright situation 8)

include \masm32\MasmBasic\MasmBasic.inc
; libgsl.dll download : open Binaries zip, and extract the two files libgsl.dll and libgslcblas.dll to \masm32\MasmBasic\GnuScLib\DLL
  gsl double gsl_sf_sin (double x)      ; define your required gsl function using the syntax of the GNU Scientific Library Reference
  SetGlobals threezero:double=3.0

  Init

  Dll "python34"      ; needs Python 3.4.3 (direct link to MSI)
  Declare void Py_Initialize, C:0
  Declare void PyRun_SimpleString, C:1      ; can be used like the commandline version of Python
  Declare void Py_Finalize, C:0

  Py_Initialize()
  PyRun_SimpleString("print('Printing the sinus of 3.0 in various languages:')")      ; use Python in MasmBasic
  PyRun_SimpleString("import math")      ; the math library needs to be imported first
  PyRun_SimpleString('print("Sinus(3)=", math.sin(3), "   Python 3.4.3")')

  Print Str$("Sinus(3)= %Jf\tGSL, global var\n", gsl_sf_sin(threezero))
  fstp st                  ; since doubles are returned via the FPU, ST(0) must be popped
  Print Str$("Sinus(3)= %Jf\tGSL, immediate\n", gsl_sf_sin(3.0))
  fstp st

  Dll "msvcrt"            ; good ol' CRT
  Declare double sin, C:1
  Print Str$("Sinus(3)= %Jf\tCRT, global var\n", sin(threezero))
  fstp st
  Print Str$("Sinus(3)= %Jf\tCRT, immediate\n", sin(3.0))
  fstp st

  fld FP10(3.0)            ; finally, the traditional way, using the FPU
  fsin 
  Print Str$("Sinus(3)= %Jf\tAssembler/Fpu\n", ST(0))
  fstp st
  PrintLine "Exact:    0.14112000805986722210074480... Wolfram Alpha"      ; link
  Py_Finalize()
  Inkey "--- hit any key ---"
  Exit
EndOfCode


Output:
Code: [Select]
Printing the sinus of 3.0 in various languages:
Sinus(3)= 0.1411200080598672    Python 3.4.3
Sinus(3)= 0.1411200080598672135 GSL, global var
Sinus(3)= 0.1411200080598672135 GSL, immediate
Sinus(3)= 0.1411200080598672135 CRT, global var
Sinus(3)= 0.1411200080598672135 CRT, immediate
Sinus(3)= 0.1411200080598672221 Assembler/Fpu
Exact:    0.14112000805986722210074480... Wolfram Alpha

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MasmBasic
« Reply #241 on: April 03, 2015, 12:49:15 PM »
The only interaction the installer has with the OS apart from disk IO is the VBS script file that gives you the option of putting the editor on the desktop. There is no direct registry writes at all. This is done to ensure the SDK is fully portable.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #242 on: April 09, 2015, 08:28:47 AM »
Thanks, Hutch. So the registry entry that I found for qEditor was probably what I created myself when associating .asm with qEditor.

I have changed the installer accordingly. It checks now for the presence of x:\Masm32; if more than one installation exists, it checks the timestamps of x:\Masm32\Examples\*.exe, and picks the drive that has the more recent executables in the examples folder tree. Only GetDriveType = DRIVE_FIXED are checked.

So, hopefully the latest update of today, 9 April will work for everybody with a Masm32 installation. Please let me know if it works now.

There are also some improvements under the hood, notably I managed to speed up Len() a little bit:
Code: [Select]
Comparing Masm32 len() and MasmBasic Len()
Total=401700900  in   31 ms (Len)
Total=401700900  in  217 ms (len)

Total=401700900  in   32 ms (Len)
Total=401700900  in  217 ms (len)

Total=401700900  in   31 ms (Len)
Total=401700900  in  216 ms (len)

Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz

Testbed attached.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
StrLen timings
« Reply #243 on: April 10, 2015, 08:25:48 AM »
Version 2 - I've added CRT strlen and the "safe" version strnlen:
Code: [Select]
Comparing MasmBasic Len(), crt_strlen and Masm32 len()
Total bytes:
401700900 in  36 ms Len
401700900 in 229 ms crt strlen
401700900 in 428 ms crt strnlen
401700900 in 259 ms Masm32 len

401700900 in  37 ms Len
401700900 in 229 ms crt strlen
401700900 in 419 ms crt strnlen
401700900 in 261 ms Masm32 len

401700900 in  36 ms Len
401700900 in 227 ms crt strlen
401700900 in 419 ms crt strnlen
401700900 in 263 ms Masm32 len

Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz

P.S.: Version 10 April fixed a minor incompatibility with JWasm (the xlsPixels2Points macro used in the DDE demo \masm32\MasmBasic\Res\Masm2Excel.asc assembled fine with ML 6.15 .. 10 but choked with JWasm).
« Last Edit: April 10, 2015, 09:33:42 AM by jj2007 »

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #244 on: April 11, 2015, 01:46:49 AM »
error line (??)
the specified procedure could not be found

xp sp3

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #245 on: April 11, 2015, 03:39:28 AM »
Yep, I just verified with my old machine: strnlen is not available on XP... :(

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Sound command
« Reply #246 on: April 25, 2015, 05:10:19 PM »
I know feature overkill is a big problem, but I couldn't resist :redface:

Sound
  Sound "880:200"           ; plays 880Hz for 200 ms; separator can be space, tab, / or :
  Sound 111                 ; plays a wav resource with ID 111 (rc file: 111 WAVE "hello.wav")
  Sound "hello.wav"         ; plays a file directly (wav only)
  Sound "hello.mp3"         ; plays a file in its associated player
  Sound "大桥在混乱的水.mp3"  ; Unicode names are allowed


Download version 25 April 2015

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MasmBasic
« Reply #247 on: April 25, 2015, 10:57:37 PM »
Use the unsafe version, from memory its faster and you just use it correctly.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Farabi

  • Member
  • ****
  • Posts: 970
  • Neuroscience Fans
Re: MasmBasic
« Reply #248 on: April 26, 2015, 01:38:10 AM »
That is impressive Mr. Jochen  :t
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: Sound
« Reply #249 on: April 26, 2015, 03:05:36 AM »
Thanks, Onan :icon14:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Two-dimensional string arrays
« Reply #250 on: May 02, 2015, 11:55:18 AM »
The MasmBasic update of 23 May concerns basically string arrays with two dimensions, e.g. for use with spreadsheets. Example:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Dim My$(tab)      ; create a two-dimensional string array using tabs (csv: commas) as separators
  For_ row=0 To 7
      Let My$(row, 0)=Str$("Row %i", row)
      For_ col=1 To 7
            Let My$(row, col)=Str$("Col %i", col)
      Next
      Delete My$(row, 6)      ; cut out all even columns
      Delete My$(row, 4)
      Delete My$(row, 2)
  Next
  For_ row=0 To 7
      PrintLine My$(row)
  Next
  Exit
EndOfCode


Output:
Code: [Select]
Row 0   Col 1   Col 3   Col 5   Col 7
Row 1   Col 1   Col 3   Col 5   Col 7
Row 2   Col 1   Col 3   Col 5   Col 7
Row 3   Col 1   Col 3   Col 5   Col 7
Row 4   Col 1   Col 3   Col 5   Col 7
Row 5   Col 1   Col 3   Col 5   Col 7
Row 6   Col 1   Col 3   Col 5   Col 7
Row 7   Col 1   Col 3   Col 5   Col 7

EDIT: version 3 May adds the corresponding Insert command:

  Dim some$(tab)      : same for some$(csv)
  Let some$(0)=cfm$("rc00\trc01\trc02\trc03\trc04\trc05\trc06")
  Let some$(1)=cfm$("rc10\trc11\trc12\trc13\trc14\trc15\trc16")
  Insert some$(0, 3)
  Let some$(0, 3)="NEW r0c3"
« Last Edit: May 03, 2015, 09:07:04 AM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Bug warning
« Reply #251 on: May 05, 2015, 10:32:12 AM »
MasmBasic version 5 May 2015 fixes two bugs:
- Csv2Tab (converts an array loaded from a *.csv file to tab-delimited) had problems with malformed files;
- mov esi, some$(row, column) could produce garbage in loops with many thousand iterations (Let esi= was not affected; mov must be used only for read-only pointers).

Some new functions for the simplified GUI have been added:
output:


source:
GuiParas equ "Hello jj2007", x100, y100, w300, h180, b0F0F0A0h
GuiMenu      equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm
MakeFont hFontSmall, Height:15, Weight:FW_SEMIBOLD, "Arial"
MakeFont hFontBig, Height:36, "Script MT Bold"
MakeBrush hRed, RgbCol(255, 64, 64)            ; light red
MakeBrush hGB, RgbCol(0, 160, 64)            ; dark green
Event Menu
  MsgBox 0, Str$("You clicked menu #%i", MenuID), "Hi", MB_OK
Event Paint
  m2m ecx, 3            ; just to demonstrate how to use scaling
  GuiTextStyle font:hFontSmall, bcol=RgbCol(255, 255, 160), fcol RgbCol(0, 0, 255)
  GuiLine 70, 15, ecx*90+10, ecx*5      ; start x+y, end x+y
  GuiLine 280, 120      ; end x+y
  GuiLine 70, 120
  GuiLine 70, 15
  GuiSetFill hRed      ; use the red brush
  GuiEllipse 236, ecx*7+4, 40, 20      ; x, y, radius x, radius y
  GuiSetFill hGB
  GuiCircle ecx*80-4, 25, ecx*5      ; x, y, radius
  For_ ct=0 To 7
      GuiText 4, ct*15+4, Str$("Line %i ", ct+1)
  Next
  GuiTextBox "Добро пожаловать", ecx*4+75, ecx*2+20, ecx*4+250, ecx*2+120, font:hFontBig, bcol:0f0f0a0h, fcol:RgbCol(0, 255, 0)
GuiEnd

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Simple GUI app with toolbar
« Reply #252 on: May 19, 2015, 09:26:40 AM »
This one needs MasmBasic version 19 May 2015 (works with Unicode tooltips, too):

GuiParas equ "Editor demo", x40, y40, w900, h666
GuiMenu equ @File, &New, &Open, &Save as
include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyEdit, "richedit", y=0+37, h=1000-35, text "No valid commandline found"
  GuiControl MyTb, "Toolbar", resid 111
  SetGlobals MyEd$="Simple editor:", CurrentFile$
  SetGlobals
  Let CurrentFile$=CL$()      ; OPT_Arg1 SimpleEditor.asc      ; RichMasm: specify a commandline for testing
  .if Len(CurrentFile$)>1
      SetWin$(hMyEdit)=FileRead$(CurrentFile$))
  .endif
Event Menu
  Switch MenuID
  Case TB0, 0      ; first toolbar button or first menu entry
      MsgBox 0, "New doc?", MyEd$, MB_OKCANCEL
      .if eax==IDOK
            SetWin$ hMyEdit=Chr$(0)
      .endif
  Case 1, TB0+1      ; 2nd toolbar button or 2ndmenu entry
      .if FileOpen$("Standard Basic=*.bas|Oxygen=*.o2bas|SdlBasic=*.sdlbas|MasmBasic=*.asc", "Open source:")
            SetWin$ hMyEdit=FileRead$(FileOpen$())
      .endif
  Case 2, TB0+2
      .if Alert("WARNING: long files will\nbe truncated at 160kBytes", MyEd$, MB_OKCANCEL)==IDOK
            .if FileSave$("Standard Basic=*.bas|Oxygen=*.o2bas|SdlBasic=*.sdlbas")
                  FileWrite FileSave$(), Win$(hMyEdit)
            .endif
      .endif
  Case 3, TB0+3
      FileOpenSetFolder FolderOpen$("Pick a folder:", MyEd$, "\Masm32\Examples")
  Endsw
GuiEnd

Rsrc
32512 ICON "\\masm32\\MasmBasic\\icons\\Disc.ico"      ; Asm, House, Keys, Globe, Hammer, Setup, Disc, Eye, ...
1 24 "\\Masm32\\MasmBasic\\Res\\XpSimple.xml"
111 10 \Masm32\MasmBasic\Res\Tb4Res\SimpleToolbar.zip
Rsrc

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic
« Reply #253 on: May 19, 2015, 12:10:25 PM »
glad to see you got it going   :t

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic
« Reply #254 on: May 19, 2015, 12:41:45 PM »
Well, kind of: with a stripped down manifest. It looks ok, it behaves ok - see attached exe (and source). But it doesn't use the latest version of the common controls...