Author Topic: fsincos - draw a circle  (Read 11615 times)

jj2007

  • Member
  • *****
  • Posts: 11550
  • Assembler is fun ;-)
    • MasmBasic
fsincos - draw a circle
« on: October 01, 2013, 08:08:20 AM »
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.
« Last Edit: October 01, 2013, 08:49:10 PM by jj2007 »

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: fsincos - draw a circle
« Reply #1 on: October 01, 2013, 08:46:20 AM »
bresenham   :t

japheth

  • Guest
Re: fsincos - draw a circle
« Reply #2 on: October 01, 2013, 05:22:00 PM »

I'd say this is the wrong forum.

Should be moved to the Colloseum...

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: fsincos - draw a circle
« Reply #3 on: October 01, 2013, 10:28:12 PM »
The Colosseum is for non-programming debates
The Workshop \ MasmBasic, maybe

Gunther

  • Member
  • *****
  • Posts: 3723
  • Forgive your enemies, but never forget their names
Re: fsincos - draw a circle
« Reply #4 on: October 02, 2013, 04:42:53 AM »
Andreas,


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
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 11550
  • Assembler is fun ;-)
    • MasmBasic
Re: fsincos - draw a circle
« Reply #5 on: October 02, 2013, 07:09:55 AM »
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

  • Member
  • *****
  • Posts: 3723
  • Forgive your enemies, but never forget their names
Re: fsincos - draw a circle
« Reply #6 on: October 02, 2013, 07:54:40 AM »
Jochen,

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

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 11550
  • Assembler is fun ;-)
    • MasmBasic
Re: fsincos - draw a circle
« Reply #7 on: October 02, 2013, 08:10:42 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

  • Guest
Re: fsincos - draw a circle
« Reply #8 on: October 02, 2013, 03:35:13 PM »
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

  • Member
  • *****
  • Posts: 11550
  • Assembler is fun ;-)
    • MasmBasic
Re: fsincos - draw a circle
« Reply #9 on: October 02, 2013, 04:36:01 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

  • Member
  • *****
  • Posts: 3723
  • Forgive your enemies, but never forget their names
Re: fsincos - draw a circle
« Reply #10 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. 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.

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
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 11550
  • Assembler is fun ;-)
    • MasmBasic
Re: fsincos - draw a circle
« Reply #11 on: October 03, 2013, 01:08:14 AM »
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

  • Member
  • *****
  • Posts: 3723
  • Forgive your enemies, but never forget their names
Re: fsincos - draw a circle
« Reply #12 on: October 03, 2013, 02:48:55 AM »
Jochen,

your changes didn't help. LibreOffice was open and here is the output of the application:
Code: [Select]
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
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 11550
  • Assembler is fun ;-)
    • MasmBasic
Re: fsincos - draw a circle
« Reply #13 on: October 03, 2013, 07:18:17 AM »
Thanks, Gunther. It seems the LibreOffice DDE implementation is completely incompatible with Excel :(

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: fsincos - draw a circle
« Reply #14 on: October 03, 2013, 08:40:23 AM »
it's probably compatible with some version of excel
the problem is - there are so many flavours of exel   :P