News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

MasmBasic

Started by jj2007, May 23, 2012, 10:16:07 PM

Previous topic - Next topic

dedndave

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

Quote from: dedndave on October 02, 2013, 06:42:00 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

i would guess faster
well - in the old days, they were much faster
don't really know how they compare since ~P4 era

jj2007

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

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

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

Quote from: dedndave 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"

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

i would assume "y" and "r" are initialized with the radius

not sure how you got bresenham.asm to assemble
end start
start is not defined - i am guessing at the Init call

jj2007

Quote from: dedndave on October 03, 2013, 05:46:45 PM
not sure how you got bresenham.asm to assemble
Don't be shy, it's just a library, like Masm32 ;-)

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

dedndave

the reason for it not assembling being "start" is undefinded   :P

jj2007

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

#130
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

jj2007

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

Quote from: TWell on October 19, 2013, 02:49:45 AMIf 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
Quote from: jj2007 on October 19, 2013, 01:23:04 AM
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

TWell

Quote from: jj2007 on October 19, 2013, 03:24:55 AM
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
Thanks for that link, now i see that problem, it starts showing from Destop and selected folder isn't visible as in WinXP, so no scrolling to that.

dedndave

the MasmBasic installer is benign - and a good way to go
it can be a little confusing to install it manually