Author Topic: MasmBasic  (Read 260704 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #120 on: August 29, 2013, 03:31:44 AM »
i know - you don't want a batch file

That's brute force, Dave :eusa_naughty:

Great, now I've got a "last" chance! However, a bit strange because I didn't realized that I've had any chance before that one ;)

You found the elifo, so you had more than one chance ;-)

Update 30 August:
- default buffer for GetRegVal is now 128k
- The Gf...() family returns for index=-1 or no argument the values for the file identified by the last Exist():

GfSize, GfDate$, GfTime$, GfAgeHours, GfAgeMinutes, GfAgeMs, GfLastWrite
        GetFiles *.asm        ; get all sources in the current folder and its subfolders
        xchg eax, ecx        ; save #files
        For_ ebx=0 To ecx-1
                .if GfAgeHours(ebx)<=24                ; pick your latest code
                        mov esi, Cat$(Files$(ebx)+Space$(20))        ; we simulate LSET
                        Print Str$("\n#%i ", ebx+1), GfDate$(ebx), ", ", GfTime$(ebx), Spc2$, Str$("%i bytes", edx::GfSize(ebx))        ; edx::eax for QUADWORD size
                .endif
        Next
Rem        - all GetFiles special arrays return a DWORD in eax, except for GfLastWrite, which returns
          in xmm0 the ftLastWriteTime FILETIME member of the WIN32_FIND_DATA structure
        - GfSize returns the high quad in edx
        - Gf....(-1I or Gf...(), i.e. index -1 or no arg: all functions return data for the last Exist()
        - GfAge...() is calculated from the moment when GetFiles was launched, except for index=-1, which returns age
          relative to the time of the last Exist() call
« Last Edit: August 30, 2013, 07:33:21 PM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #121 on: September 27, 2013, 11:08:21 PM »
Update 27 September 2013:
- Fixed a rare bug in Hex$()
- Clip$(): the optional parameter is now working properly
- QSort works now also for dynamic string arrays
- ShEx for those who can't memorise the 5 ShellExecute args (=myself :biggrin:)

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  Dim My$()        ; create a dynamic string array
  xor ecx, ecx
  .Repeat
        Let My$(ecx)=Str$("String %i", Rand(20)+1000)
        inc ecx
  .Until ecx>=20
  QSort My$()                ; sort all elements allocated so far
  For_ ebx=0 To ecx-1
        PrintLine Str$("Line %i =\t", ebx), My$(ebx)
  Next


  if 0        ; New: ShellExecute for dummies
        FileWrite "~tmp.txt", Cat$("Hello, it's "+Time$)        ; create a text file
        ShEx "~tmp.txt"        ; you can add e.g. SW_MAXIMIZE if needed
  endif

  Exit
end start

dedndave

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #122 on: October 02, 2013, 06:42:00 PM »
i know this isn't where it started....

but, Bresenham circles are pretty simple
if you develop an ASM algo, you can plot 8 points with each calculation
for elipses, 4 points - and a little "flip" on the second group of octets

maybe some day, i will play with a full set of Bresenham lines and conics   :P
but, this will get you started...

http://people.cs.uchicago.edu/~kaharris/15200/Labs/lab3/circle.html

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #123 on: October 02, 2013, 08:10:10 PM »
but, Bresenham circles are pretty simple

You are the expert :t

But are they simpler than this? Or at least faster, in case it matters??

; This application draws a circle to the console
include \masm32\MasmBasic\MasmBasic.inc        ; download the library
  Init
  Enum 24:xScale, 16:yScale         ; define width and height of the circle
  push 0        ; start with zero degrees
  .Repeat
        fld FP4(0.0174533)        ; load 360/(2*PI)
        fimul stack        ; multiply with decimal degrees
        fsincos        ; get sinus and cosinus simultaneously
        push yScale        ; create a stack slot containing the vertical scale
        fimul stack        ; cosinus * yScale
        fistp stack        ; save to...
        pop eax        ; ... eax
        push xScale        ; create a stack slot with the horizontal scale
        fimul stack        ; sinus * xScale
        fistp stack        ; save to...
        pop ecx        ; ... ecx
        add eax, yScale+2
        add ecx, xScale+3
        Locate(ecx, eax)
        Print "#"
        inc stack
  .Until stack>=360        ; loop until the circle is complete
  pop eax        ; restore stack balance
  Locate(xScale/2+7, yScale/2+9)
  ConsoleColor cRed
  Inkey "Masm32 is great"
  Exit
end start

dedndave

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #124 on: October 02, 2013, 08:17:58 PM »
i would guess faster
well - in the old days, they were much faster
don't really know how they compare since ~P4 era

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Bresenham circle needs a SQRT?
« Reply #125 on: October 03, 2013, 08:00:13 AM »
Bresenham circle needs a SQRT, right?

Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (SSE3)
loop overhead is approx. 188/100 cycles

6678    cycles for 100 * Sqrt
11083   cycles for 100 * fsincos

6670    cycles for 100 * Sqrt
11072   cycles for 100 * fsincos

dedndave

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #126 on: October 03, 2013, 08:38:34 AM »
the whole idea behind Bresenham is to use integers, as opposed to floating point math

here is some decent "pseudo-code"
of course, you wouldn't want to use SetPixel
better to calculate DIB section addresses

Code: [Select]
int x,y,d,r;
y=r;
putpixel(x,y,1);
d=(3-2*r);
while(x<=y)
{
    if(d<=0)
        d += (4*x+6);
    else
    {
        d = d+4*(x-y)+10;
        y--;
    }
    x++;
    putpixel(x,y,1);
    putpixel(-x,y,1);
    putpixel(x,-y,1);
    putpixel(-x,-y,1);
    putpixel(y,x,1);
    putpixel(-y,x,1);
    putpixel(y,-x,1);
    putpixel(-y,-x,1);
}

http://www.asksatyam.com/2011/01/bresenhams-circle-algorithm_22.html

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #127 on: October 03, 2013, 05:05:56 PM »
the whole idea behind Bresenham is to use integers, as opposed to floating point math

here is some decent "pseudo-code"

int x,y,d,r;
y=r;
  <<<<<<<<<<<< assigns garbage

Doesn't fly. But I found one that works great, see attachment (you may have to maximise the console).

For BASIC illiterates: The only MasmBasic instruction is Locate(). If you have a decent Locate macro yourself, you can do it with Masm32 only.

dedndave

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #128 on: October 03, 2013, 05:46:45 PM »
i would assume "y" and "r" are initialized with the radius

not sure how you got bresenham.asm to assemble
Code: [Select]
end startstart is not defined - i am guessing at the Init call

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #129 on: October 03, 2013, 06:04:32 PM »
not sure how you got bresenham.asm to assemble
Don't be shy, it's just a library, like Masm32 ;-)

Quote
end start
start is not defined - i am guessing at the Init call
Good guess :t

dedndave

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: MasmBasic - a fast and easy-to-use library
« Reply #130 on: October 03, 2013, 06:20:59 PM »
the reason for it not assembling being "start" is undefinded   :P

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #131 on: October 08, 2013, 09:25:41 PM »
Update 8 October 2013 (download):

1. Some improvements of the DDE interface to Excel. Inter alia, there is a new xlsRC$() macro:
  xlsRC$(1, 2) returns "R1C2"

  See detailed example.

2. Win$() can now take as second argument the ID of a child window:

include \masm32\MasmBasic\MasmBasic.inc
  Init                       
  Launch "Notepad.exe \Masm32\include\bignumsdk.inc", SW_MINIMIZE
  Delay 200                ; give Notepad 200 ms to get ready
  .if WinByTitle("bignumsdk.inc - Note")
        xchg eax, ecx                ; ecx is the parent, 15 is the ID of the Notepad edit control
        wPrint "Content=", wTb$, wWin$(ecx, 15)        ; delete the w if you prefer ANSI
        ConsoleColor cYellow
        wInkey wCrLf$, "Title=", wWin$(ecx)
        invoke SendMessage, ecx, WM_CLOSE, 0, 0        ; close Notepad window
  .else
        Inkey "Notepad not ready - increase the delay?"
  .endif
  Exit
end start


3. GSL (GNU Scientific Library) example updated (see \Masm32\MasmBasic\GNUSCLIB\DLL\GslExample.asc)

4. New If_ ... Then ... macro (for details see this thread):
  If_ ebx==123 Then inc ebx : dec eax : call mytest

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
Re: MasmBasic - a fast and easy-to-use library
« Reply #132 on: October 11, 2013, 09:22:25 AM »
Update 10 October (download):
RichMasm can now handle a collection of snippets in one file, as in the attached file containing 40 examples of simple console mode code. In the editor, it is sufficient to select the Init of any examples and then hit F6 to assemble, link & run the example.

EDIT: See update in Reply #147
« Last Edit: October 24, 2013, 08:53:03 PM by jj2007 »

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
FolderOpen$()
« Reply #133 on: October 19, 2013, 01:23:04 AM »
Update 18 October (download):

1. Analogous to FileOpen$(), MasmBasic has now a comfortable wrapper for SHBrowseForFolder called FolderOpen$():

include \masm32\MasmBasic\MasmBasic.inc        ; RichMasm: select Init and hit F6 to test the examples
  Init                          ; FolderOpen$(prompt [, title] [, path] [, BIF flags])
  Let esi=FolderOpen$()        ; no args = use Windows defaults, start with current folder
  Print "Selected: [", esi, "]", CrLf$        ; if the user cancelled, esi will be an empty string
  PrintLine "Selected: ", FolderOpen$("Pick a folder:", "Masm32 is great")        ; a prompt and a nice title, start with current folder
  PrintLine "Selected: ", FolderOpen$("Pick a folder:",, "\Masm32\Examples")        ; just a prompt, default title, specific folder
  PrintLine "Selected: ", FolderOpen$("9Pick a big folder:")                ; a big prompt (font 9), default title, current folder
  ; prompt, title, path with environment variables, flags
  Let esi=FolderOpen$("What is the edit box for?","Locate Office:", "%ProgramFiles%\Microsoft Office", BIF_USENEWUI)
  PrintLine esi
  PrintLine "Selected folder=[", FolderOpen$("Where are your tools?",, "D:\Masm32\bin"), "]"        ; fully qualified initial path
;   if you need to check whether the user cancelled, use void and check the zero flag:
  void FolderOpen$("5Pick the bin folder, please:","Getting help", "\Masm32\bin")        ; use current drive plus initial path
  .if !Zero?
        MsgBox 0, Launch$(Cat$(eax+"\link.exe /Lib")), "Library manager help:", MB_OK
  .else
        PrintLine "Nothing selected: [", eax, "]"        ; Zero? set = user cancelled, eax points to a Null$
  .endif
  Exit
end start


2. Minor bugfix: Str$() can now also handle LARGE_INTEGER values properly.

3. See also Monitoring WM_nnnn messages.

P.S.: There is a pretty fat and pretty stupid SHBrowseForFolder bug in Windows 7. Grateful for feedback if FolderOpen$() works properly on all Windows versions from XP upwards. XP and Win7-32 seem to work AFAIK.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9939
  • Assembler is fun ;-)
    • MasmBasic
SHBrowseForFolder bug
« Reply #134 on: October 19, 2013, 03:24:55 AM »
If you can give that MamBasic in zip package without installer, i may test it.
I made the installer precisely because many people have forgotten how to extract an archive properly. The installer creates one folder (\Masm32\MasmBasic) and does not modify the registry.

What do you typically do if Adobe or Microsoft or Sun ask you to run a *.msi file? Do you have any reason to trust me less than, ehm, Microsoft?

Quote
P.S.: There is a pretty fat and pretty stupid SHBrowseForFolder bug in Windows 7. Grateful for feedback if FolderOpen$() works properly on all Windows versions from XP upwards. XP and Win7-32 seem to work AFAIK.
What problem ?
That example code works in my Win7 32/64-bit

Just google for SHBrowseForFolder bug in Windows 7 - many hits, and most mention that it does "not always" scroll down. Your code works fine on XP, can't test it on Win7 right now, but I have seen the no-scroll problem often enough in action on Win7. Need an official Microsoft site? BFFM_SETSELECTION does not work with SHBrowseForFolder on Windows 7