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

#225
Sometimes I need a prompt asking for input from a console app. Version 4 March has it:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Let esi=NoTag$(FileRead$("http://masm32.com/board/index.php?action=unread;all;start=0"))
  Print "[", Prompt$("Type something, please:", esi), "]"
  Exit
end start

See Input$() for comparison.

Other changes: For... Next loops with float counters act now, like their integer equivalents, rejecting if start>end.

P.S.: Version 9 March fixes a minor issue with UnzipFile.

jj2007

Version 16 March 2015 has improvements under the hood. Inter alia, Recall can now read files directly from the Internet, including csv and tab-delimited files. Unix format (i.e. LF only) will automatically be recognised, Unicode files are translated to UTF-8 text arrays.

Attached a gift for the U.S. members: A 100-lines application that
- reads an archive from the Internet
- extracts a database in csv format
- allows the user to enter:
  - either the name of a city, and get its LatLong coordinates
  - or LatLong coordinates, and get the nearest three cities

Let me know if it works.

include \masm32\MasmBasic\MasmBasic.inc      ; download
  SetGlobals firstUse, best, second, third, xc:REAL4, yc:REAL4, xNow, xyMin, OneMio:REAL4=1000000.0, zipfile$="ZipCodes.zip", tmp$="~FrLocal.tmp"
  Init
  .if !Exist(zipfile$)
      void FileRead$("http://www.boutell.com/zipcodes/zipcode.zip")
      .if Exist(tmp$)
            Rename tmp$, zipfile$
            inc firstUse      ; flag fresh download, show the MsgBox
      .endif
  .endif
  .if Exist(zipfile$)
      UnzipInit zipfile$
      ... -> see attachment

jj2007

#227
Please install version 17 March of the MasmBasic library.
Older versions have a problem with the translation of *.csv (comma-separated values) into a two-dimensional string array: If the very first column (see Bonaire, Saint below) contained quoted strings with embedded commas, they were interpreted as two columns. This is fixed now, and the snippet below (source and exe attached) will work just fine (as long as WHO provides the database, of course 8)) 

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Recall "https://extranet.who.int/tme/generateCSV.asp?ds=mdr_estimates", who$(), csv
  Print Str$("%i records downloaded", eax)
  For_ ct=0 To who$(?)-1
      Print CrLf$, who$(ct, 0)
      Print At(33, Locate(y)) Spc2$, who$(ct, 4), Space$(40)
      For_ ecx=8 To 14      ; columns 8...14 contain the data
            Print At(ecx*8-25, Locate(y)) Spc2$, who$(ct, ecx)
      Next
  Next
  Exit
end start


Output:

217 records downloaded
country                            year  e_new_  e_new_  e_new_  e_new_  e_new_  e_new_  source_mdr_ret
Afghanistan                        2013  3.7     2.5     4.9     820     560     1100    Model
Albania                            2013  0.58    0.02    3.2     2       0       10      Surveillance
...
Bonaire, Saint Eustatius and Saba  2013  2.2     1.3     3.1     0       0       0       Surveillance
Bosnia and Herzegovina             2013  0       0       0.57    0       0       6       Surveillance
Botswana                           2013  2.5     1.5     3.5     120     70      160     Survey
Brazil                             2013  1.4     1       1.8     840     600     1100    Survey


P.S.: Just stumbled over a public database on crime records. Interesting, but guess what? The database is neither Windows nor Linux, apparently it's MAC - carriage returns only! So I felt morally obliged to add the Mac format to Recall's autodetect feature. That cost a whopping 40 bytes or so extra but it works like a charm. Go to http://masm32.com/board/index.php?topic=94.0 and re-install MasmBasic, so that you can test the snippet below :biggrin:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Recall "http://samplecsvs.s3.amazonaws.com/SacramentocrimeJanuary2006.csv", Crime$(), csv
  For_ ct=0 To Crime$(?)-1
      .if Instr_(Crime$(ct), "card info", 1) || ct==0
            xor esi, esi
            For_ ecx=0 To 8
                  Print At(esi, Locate(y)) Spc2$, Crime$(ct, ecx), Space$(8)
                  add esi, 8
                  .if ecx==1 || ecx==5
                        add esi, 18
                        .if ecx==5
                            add esi, 10
                        .endif
                  .endif
            Next
            Print
      .endif
  Next
  Print Str$("\n%i records received from Sacramento", Crime$(?))
  Exit
end start

jcfuller

Jochen,
  I figured it was about time I gave masmbasic a try but I am unable to install.
I double click on the exe and I get a window with a title:
"Last chance - show me where macro.asm sits and then a messagebox that says I should google Visual Basic??

James

jj2007

James,

Sorry for that. To deter the script kiddies, the installer tests if you have Masm32 installed, via the registry. If it doesn't find exactly what it expects, it gives you a "last chance" to select the macros.asm file in your Masm32 installation. It sits in the dedicated Masm32 folder. Please let me know if it works; I am also curious why it doesn't find the registry entries.

Thanks,
Jochen

dedndave

i might be wrong, but i think the masm32 install only writes to the registry if the user elects to use QE as the default ASM editor

jj2007

You might be right, Dave :biggrin:

jcfuller

It is now available.

James

jj2007

Great :t

GuiParas equ "Hello James", x650, y20, w200, h200, sWS_CAPTION OR WS_POPUPWINDOW, cblack, b00FFFFD0h
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm
Event Message
  inc msgCount
  deb 4, "msg", chg:msgCount      ; , wParam, lParam      ; see deb
GuiEnd

jj2007

Update 24 March 2015:

- gsl interface improved (see original gsl example program):

include \masm32\MasmBasic\MasmBasic.inc
  gsl double gsl_sf_bessel_J0 (double x)      ; double x means a REAL8 is required as input
  Init                  ; ## GNU Scientific Library: Bessel function ##
  Print Str$("Bessel(5)=%Jf \n", gsl_sf_bessel_J0(FP8(5.0)))
  fstp st                  ; see a detailed gsl example here
  Exit
EndOfCode


- SetGlobals understands C-style declarations:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  SetGlobals OWORD xx0, xx1, xx2, xx3, xx4, xx5, xx6, xx7
  Init
  mov eax, 11111111
  movd xmm0, eax
  movaps xx0, xmm0

  add eax, 11111111
  movd xmm1, eax
  movaps xx1, xmm1
  Exit
end start

jj2007

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:
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--

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.

jj2007

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:
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

#238
Version 2 - I've added CRT strlen and the "safe" version strnlen:
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).

dedndave

error line (??)
the specified procedure could not be found

xp sp3