News:

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

Main Menu

fsincos - draw a circle

Started by jj2007, October 01, 2013, 08:08:20 AM

Previous topic - Next topic

jj2007

This application establishes a DDE connection to MS Excel and draws a circle into a new sheet (requires MasmBasic of 1 Oct 2013 or later):

include \masm32\MasmBasic\MasmBasic.inc ; download the library
  Init
  Enum 5:xScale, 16:yScale              ; define width and height of the circle
  xlsConnect                            ; no args=connect to System
  je @Bye
  xlsCommand "[App.Restore()]"          ; set Excel to restored state
  xlsCommand "[App.Move(80, 0)]"        ; leave a margin to the left for error messages
  xlsCommand "[App.Size(660, 600)]"     ; get a big window for a big circle
  xlsCommand "[App.Activate()]"         ; put Excel to the foreground
  xlsCommand "[new(1)]"                 ; create a new workbook (works fine on non-English Excel versions!)
  Let esi=xlsSysRead$("Topics")         ; we must find the sheet
  mov ecx, Instr_(esi, "[Book")         ; this will fail for a non-English version - use e.g. [Cartella for Italian Excel
  .if Instr_(ecx, esi, Tb$)             ; connect to the new sheet
        xlsConnect Mid$(esi, ecx, edx-ecx)
        xlsCommand '[Select("R16C4")]'
        xlsWrite "Masm32 is great"
        xlsCommand '[Font.Properties("", "Bold Italic", 28)]'
        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
                push yScale        ; create a stack slot, fill with vertical scale
                fimul stack        ; cosinus * yScale
                fistp stack        ; save to...
                pop eax            ; ... eax
                push xScale        ; create a stack slot, fill with horizontal scale
                fimul stack        ; sinus * xScale
                fistp stack        ; save to...
                pop ecx            ; ... ecx
                ; no negative Row/Column values in Excel, so we need to add the radius:
                xlsWrite xlsRC$(eax+yScale+1, ecx+xScale+1), "@"        ; draw the circle
                inc stack
        .Until stack>=360          ; loop until the circle is complete
        pop eax            ; restore stack balance
        Delay 3000        ; we want to see "Masm32 is great" ;-)
        xlsClose         ; no arg = close current workbook, ask if changes should be saved
  .endif
  xlsDisconnect        ; say bye bye to Excel
@Bye:
  Exit
end start


Source attached, including a simpler example drawing a circle to the console.

dedndave


japheth


I'd say this is the wrong forum.

Should be moved to the Colloseum...

dedndave

The Colosseum is for non-programming debates
The Workshop \ MasmBasic, maybe

Gunther

Andreas,

Quote from: japheth on October 01, 2013, 05:22:00 PM

I'd say this is the wrong forum.

Should be moved to the Colloseum...

that's a bad joke.

Andreas and Jochen, you both shouldn't hold on like grim death.

Gunther
You have to know the facts before you can distort them.

jj2007

Hey Gunther,
Don't worry, we are just joking. Andreas is a bit frustrated that his internal spellchecker isn't working ("Colloseum"), that's all :P

Gunther

Jochen,

do you really think that Andreas needs an internal spell checker? I don't think so.

Gunther
You have to know the facts before you can distort them.

jj2007

Quote from: Gunther on October 02, 2013, 07:54:40 AM
do you really think that Andreas needs an internal spell checker? I don't think so.

Frankly speaking, I would find a nice code example showing the Bresenham circle far more interesting than Andreas' problems.

I am a bit fed up that each and every programming thread gets destroyed by certain forum members' personal problems. Herewith I invite the moderator to move the part of this thread below Dave's post to the Colosseum, as suggested by Japheth.

japheth

Quote from: Gunther on October 02, 2013, 04:42:53 AM
that's a bad joke.

Yes, it's partly a joke. But only partly, because this sub-forum is supposed to be reserved for assembly newbies wanting to ask questions.

And I don't think that's the OP is an "assembly newbie" - not to mention that there is no question at all.


jj2007

Quote from: japheth on October 02, 2013, 03:35:13 PM
Yes, it's partly a joke. But only partly, because this sub-forum is supposed to be reserved for assembly newbies wanting to ask questions.

Since Andreas is partly right, could we move this thread? Partly to the Workshop (posts 1+2), partly to the Colosseum? Thanks.

Gunther

Jochen,

I've tested your applications. My impression is that the console application isn't appropriate, because the circle appears only partially. A native GUI application would probably do a better job. I've regrettably only LibreOffice installed and the other program didn't work under that circumstances, because it's specifically designed for Excel usage. Bad luck.

Quote from: japheth on October 02, 2013, 03:35:13 PM
And I don't think that's the OP is an "assembly newbie" - not to mention that there is no question at all.

That is not my point of view. Andreas, could you explain, please, why some graphics primitives (drawing lines, circles, and ellipses with the well known Bresenham algorithm) should not be interesting for members which doing the first and second steps with assembly language? Such finger exercises are also necessary. The Campus isn't only there for such questions like: What means eax? It's discussable if the entire thread would be better placed inside the Workshop or the Laboratory, but the Colosseum is a bad joke and nothing else.

Gunther
You have to know the facts before you can distort them.

jj2007

Quote from: Gunther on October 02, 2013, 08:48:00 PM
Jochen,

I've tested your applications. My impression is that the console application isn't appropriate, because the circle appears only partially.

Thanks for testing, Gunther. If the circle is too big, reduce xScale and yScale proportionally, or make the console bigger. Re Libre Office, "Soffice" should do the job:

  Enum 5:xScale, 16:yScale         ; define width and height of the circle
  mov xlsServer$, Chr$("Soffice")
  xlsConnect                ; no args=connect to System

Source & exe attached. I am curious to see whether it works.

Gunther

Jochen,

your changes didn't help. LibreOffice was open and here is the output of the application:

c:\tmp11>Masm2ExcelCirclleLibreOffice.exe
#### ERROR Command: [App.Restore()] ####
#### ERROR Command: [App.Move(80, 0)] ####
#### ERROR Command: [App.Size(660, 600)] ####
#### ERROR Command: [App.Activate()] ####
#### ERROR Command: [new(1)] ####
c:\tmp11>


You can see: the application falls back to the command line. I hope that helps.

Gunther
You have to know the facts before you can distort them.

jj2007

Thanks, Gunther. It seems the LibreOffice DDE implementation is completely incompatible with Excel :(

dedndave

it's probably compatible with some version of excel
the problem is - there are so many flavours of exel   :P