The MASM Forum

General => The Campus => Topic started by: jj2007 on October 01, 2013, 08:08:20 AM

Title: fsincos - draw a circle
Post by: jj2007 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 (http://masm32.com/board/index.php?topic=94.0) 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.
Title: Re: fsincos - draw a circle
Post by: dedndave on October 01, 2013, 08:46:20 AM
bresenham   :t
Title: Re: fsincos - draw a circle
Post by: japheth on October 01, 2013, 05:22:00 PM

I'd say this is the wrong forum.

Should be moved to the Colloseum...
Title: Re: fsincos - draw a circle
Post by: dedndave on October 01, 2013, 10:28:12 PM
The Colosseum is for non-programming debates
The Workshop \ MasmBasic, maybe
Title: Re: fsincos - draw a circle
Post by: Gunther on October 02, 2013, 04:42:53 AM
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
Title: Re: fsincos - draw a circle
Post by: jj2007 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
Title: Re: fsincos - draw a circle
Post by: Gunther 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
Title: Re: fsincos - draw a circle
Post by: jj2007 on October 02, 2013, 08:10:42 AM
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.
Title: Re: fsincos - draw a circle
Post by: japheth on October 02, 2013, 03:35:13 PM
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.

Title: Re: fsincos - draw a circle
Post by: jj2007 on October 02, 2013, 04:36:01 PM
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.
Title: Re: fsincos - draw a circle
Post by: 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. 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
Title: Re: fsincos - draw a circle
Post by: jj2007 on October 03, 2013, 01:08:14 AM
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: (https://help.libreoffice.org/Calc/Spreadsheet_Functions#DDE)

  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.
Title: Re: fsincos - draw a circle
Post by: Gunther 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:

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
Title: Re: fsincos - draw a circle
Post by: jj2007 on October 03, 2013, 07:18:17 AM
Thanks, Gunther. It seems the LibreOffice DDE implementation is completely incompatible with Excel :(
Title: Re: fsincos - draw a circle
Post by: dedndave 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
Title: Re: fsincos - draw a circle
Post by: jj2007 on October 03, 2013, 03:21:10 PM
Quote from: dedndave 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
The MasmBasic interface works fine with Excel 2007, 2010 and even the Win7-64 starter edition (http://masm32.com/board/index.php?topic=94.msg17918#msg17918) of Excel. So the problem is clearly in LibreOffice's court :bgrin:
Title: Re: fsincos - draw a circle
Post by: japheth on October 03, 2013, 06:31:42 PM
Quote from: Gunther on October 02, 2013, 08:48:00 PM
... but the Colosseum is a bad joke and nothing else.

This "nothing else" term, isn't that the equivalent of "Basta!" in German ( and Italy )?  :icon_mrgreen:

IMO this sample is not even remotely suited as an example for someone who wants to learn assembly - to suggest the opposite as you did sounds like a funny joke to me.

Title: Re: fsincos - draw a circle
Post by: Gunther on October 03, 2013, 08:26:27 PM
Quote from: jj2007 on October 03, 2013, 03:21:10 PM
The MasmBasic interface works fine with Excel 2007, 2010 and even the Win7-64 starter edition (http://masm32.com/board/index.php?topic=94.msg17918#msg17918) of Excel. So the problem is clearly in LibreOffice's court :bgrin:

That seems so.

Quote from: japheth on October 03, 2013, 06:31:42 PM
This "nothing else" term, isn't that the equivalent of "Basta!" in German ( and Italy )?  :icon_mrgreen:

IMO this sample is not even remotely suited as an example for someone who wants to learn assembly - to suggest the opposite as you did sounds like a funny joke to me.

Basta is Basta. But joke apart. It's clear that the entire thread is about programming and it is probably better placed inside the Workshop. No question. But your Colosseum proposal is a bit weird (what else, to say it with George Clooney).

Gunther
Title: Re: fsincos - draw a circle
Post by: TWell on October 03, 2013, 08:41:17 PM
jj2007,

If you request 'selection' after command '[NEW(1)]' you can get [workbook]sheet name and correct letters for RxCx after '!' ?
Title: Re: fsincos - draw a circle
Post by: jj2007 on October 03, 2013, 10:34:24 PM
Quote from: TWell on October 03, 2013, 08:41:17 PM
jj2007,

If you request 'selection' after command '[NEW(1)]' you can get [workbook]sheet name and correct letters for RxCx after '!' ?

Try xlsSysRead$:
        xlsConnect Mid$(esi, ecx, edx-ecx)
        PrintLine "Select", Tb$, xlsSysRead$("Selection()")
        xlsCommand '[Select("R16C4")]'
        PrintLine "Select", Tb$, xlsSysRead$("Selection()")
        xlsWrite "Masm32 is great"

Output:
Select  [Book20]Sheet1!R1C1
Select  [Book20]Sheet1!R16C4


There is also xlsRead$() returning the content of the selection:
        xlsWrite "Masm32 is great"
        PrintLine "Content R2C1", Tb$, "[", xlsRead$("R2C1"), "]"        ; get content of RnCn
        PrintLine "Current sel ", Tb$, "[", xlsRead$(), "]"        ; get content current selection

Output:
Content R2C1    []
Current sel     [Masm32 is great]


I hope I understood your question correctly...?

P.S.: Even this works (i.e. select a table, print the first two columns):
  StringToArray xlsRead$(), rc$(), tab        ; get a two-dimensional string array
  For_ ecx=0 To eax-1
        Print Str$("Row %i\t: C1=", ecx), rc$(ecx, 0)
        Print Tb$, "C2=", rc$(ecx, 1), CrLf$
  Next
Title: Re: fsincos - draw a circle
Post by: TWell on October 03, 2013, 11:48:54 PM
I mean something like this:

  xlsCommand "[new(1)]"                 ; create a new workbook (works fine on non-English Excel versions!)
  Let esi=xlsSysRead$("Selection")         ; we must find the sheet

then you may get "[Book20]Sheet1!R1C1"
now split that string at '!'
now you have sheet name "[Book20]Sheet1"
and row/col format "R1C1" in Excel's native format in that language version
it can be like "R1S1" in another Excel language / version
now pick those letters for latter usage.


Title: Re: fsincos - draw a circle
Post by: jj2007 on October 04, 2013, 12:15:36 AM
Quote from: TWell on October 03, 2013, 11:48:54 PM
it can be like "R1S1" in another Excel language / version
now pick those letters for latter usage.

Interesting idea, thanks :t

So how does R2C2 look in Russian? с2с2? ::)

The Excel sheet has 20 rows and five columns.
La hoja de Excel tiene 20 filas y cinco columnas.
La feuille Excel dispose de 20 lignes et cinq colonnes.
Il foglio Excel dispone di 20 righe e cinque colonne.
Das Excel-Blatt hat 20 Zeilen und fünf Spalten.
Лист Excel имеет 20 строки и пять столбцов.