Welcome, Guest. Please login or register.

Author Topic: AmiDevCpp and Floats  (Read 1628 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline AmigaEdTopic starter

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
    • Show only replies by AmigaEd
AmiDevCpp and Floats
« on: January 18, 2006, 12:06:09 AM »
O.k. I'm trying to learn C and I've come up against something that I'm hoping someone can clarify for me.

From the Amiga C Manual tutorial. I have been working with ACM1/Gadgets/Example11.

Under gcc, I can compile Example11.c which contains the following line and then actually get the expected output.

[color=0000ff]    printf("Hor= %1.0f\n", (float) my_prop_info.HorizPot / MAXPOT * 32);[/color]

If I try to compile Example11.c with the above line under AmiDevCpp v0.5 It just does not seem to work. I suspect that the problem is with the float (%f) type? Is there some other type that I should be using when trying to compile with AmiDevCpp?

Thank you,
AmigaEd

"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - Prístino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebows
 

Offline Heinz

  • Full Member
  • ***
  • Join Date: Nov 2005
  • Posts: 154
    • Show only replies by Heinz
    • http://amidevcpp.amiga-world.de
Re: AmiDevCpp and Floats
« Reply #1 on: January 18, 2006, 06:19:52 PM »
Could you be more detailed, please ?

Does not seem to work means what ?
Compiler error ?
Executables crashes ?

You should also tell us for wich System you are Compiling (AmigaOS 3.x, OS4, MorphOS, Aros, Windows ?)
 

Offline AmigaEdTopic starter

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
    • Show only replies by AmigaEd
Re: AmiDevCpp and Floats
« Reply #2 on: January 19, 2006, 02:12:04 AM »
Hello Heinz,

When I compile the program for OS3.9 under AmiDevCpp...

The source compiles with no errors and the program runs without crashing. The problem is when I try to run the program the output to the console window does not work correctly.

The window appears with a proportional gadget that can be move hoizontally and vertically. The gadget can be move to any position within the window. The horizontal and vertical postion should be printed out in the console window.

Instead when you move the gadget with the mouse it just prints the following in the console window....

[color=008000]
Proportional gadget selected.
Hor= %1.0f
Ver= %1.0f

Proportional gadget selected.
Hor= %1.0f
Ver= %1.0f

Proportional gadget selected.
Hor= %1.0f
Ver= %1.0f

[/color]

The console window output should really look something like this when moving the gadget....

[color=008000]
Proportional gadget selected.
Hor= 1
Ver= 2

Proportional gadget selected.
Hor= 4
Ver= 10

Proportional gadget selected.
Hor= 11
Ver= 13

[/color]


Here is the source....
[color=0000ff]
/* Example11                                                          */
/* This program will open a normal window which is connected to the   */
/* Workbench Screen. The window will use all System Gadgets, and will */
/* close first when the user has selected the System gadget Close     */
/* window. Inside the window we have put a Proportional gadget where  */
/* the knob can be moved both horizontally and vertically.            */



#include



struct IntuitionBase *IntuitionBase;



/* THE PROPORTIONAL GADGET's STRUCTURES: */

/* We need to declare an Image structure for the knob, but since */
/* Intuition will take care of the size etc of the knob, we do not need */
/* to initialize the Image structure: */
struct Image my_image;


struct PropInfo my_prop_info=
{
  FREEHORIZ|      /* Flags, the knob should be able to movew both */
  FREEVERT|       /* horizontally and vertically. */
  AUTOKNOB,       /* Intuition should take care of the knob image. */
  0,              /* HorizPot, start position of the knob. */
  0,              /* VertPot, start position of the knob. */
  MAXBODY * 1/32, /* HorizBody, 32 steps. */
  MAXBODY * 1/10, /* VertBody, 10 steps. */

  /* These variables are initialized and maintained by Intuition: */

  0,              /* CWidth */
  0,              /* CHeight */
  0, 0,           /* HPotRes, VPotRes */
  0,              /* LeftBorder */
  0               /* TopBorder */
};


struct Gadget my_gadget=
{
  NULL,            /* NextGadget, no more gadgets in the list. */
  10,              /* LeftEdge, 10 pixels out. */
  20,              /* TopEdge, 20 lines down. */
  -20,             /* Width, always 20 pixels less than the wind. size. */
  -40,             /* Height, always 40 lines less than the wind. size. */
  GADGHCOMP|       /* Flags, complement the colours. */
  GRELWIDTH|       /* Width describes the size relative to the window. */
  GRELHEIGHT,      /* Height describes the size relative to the window*/
  GADGIMMEDIATE|   /* Activation, our program will recieve a message */
  RELVERIFY,       /* when the user has selected this gadget, and when */
                   /* the user has released it. */
  PROPGADGET,      /* GadgetType, a Proportional gadget. */
  (APTR) &my_image,/* GadgetRender, a pointer to our Image structure. */
                   /* (Intuition will take care of the knob image) */
                   /* (See chapter 3 GRAPHICS for more information) */
  NULL,            /* SelectRender, NULL since we do not supply the */
                   /* gadget with an alternative image. */
  NULL,            /* GadgetText, no text. */
  NULL,            /* MutualExclude, no mutual exclude. */
  (APTR) &my_prop_info, /* SpecialInfo, pointer to a PropInfo structure. */
  0,               /* GadgetID, no id. */
  NULL             /* UserData, no user data connected to the gadget. */
};



/* Declare a pointer to a Window structure: */
struct Window *my_window;

/* Declare and initialize your NewWindow structure: */
struct NewWindow my_new_window=
{
  50,            /* LeftEdge    x position of the window. */
  25,            /* TopEdge     y positio of the window. */
  320,           /* Width       320 pixels wide. */
  100,           /* Height      100 lines high. */
  0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
                 /*             user has selected the Close window gad, */
  GADGETDOWN|    /*             or a gadget has been pressed on, or */
  GADGETUP,      /*             a gadge has been released. */
  SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  WINDOWCLOSE|   /*             Close Gadget. */
  WINDOWDRAG|    /*             Drag gadget. */
  WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  WINDOWSIZING|  /*             Sizing Gadget. */
  ACTIVATE,      /*             The window should be Active when opened. */
  &my_gadget,    /* FirstGadget A pointer to the String gadget. */
  NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  "Proportional Window", /* Title Title of the window. */
  NULL,          /* Screen      Connected to the Workbench Screen. */
  NULL,          /* BitMap      No Custom BitMap. */
  100,           /* MinWidth    We will not allow the window to become */
  100,           /* MinHeight   smaller than 100 x 100, and not bigger */
  640,           /* MaxWidth    than 640 x 200. */
  200,           /* MaxHeight */
  WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
};



main()
{
  /* Boolean variable used for the while loop: */
  BOOL close_me;
 
  /* Declare a variable in which we will store the IDCMP flag: */
  ULONG class;

  /* Declare a pointer to an IntuiMessage structure: */
  struct IntuiMessage *my_message;



  /* Before we can use Intuition we need to open the Intuition Library: */
  IntuitionBase = (struct IntuitionBase *)
    OpenLibrary( "intuition.library", 0 );
 
  if( IntuitionBase == NULL )
    exit(0); /* Could NOT open the Intuition Library! */



  /* We will now try to open the window: */
  my_window = (struct Window *) OpenWindow( &my_new_window );
 
  /* Have we opened the window succesfully? */
  if(my_window == NULL)
  {
    /* Could NOT open the Window! */
   
    /* Close the Intuition Library since we have opened it: */
    CloseLibrary( IntuitionBase );

    exit(0);  
  }



  /* We have opened the window, and everything seems to be OK. */



  close_me = FALSE;

  /* Stay in the while loop until the user has selected the Close window */
  /* gadget: */
  while( close_me == FALSE )
  {
    /* Wait until we have recieved a message: */
    Wait( 1 << my_window->UserPort->mp_SigBit );

    /* We have now recieved one or more messages. */

    /* Since we may recieve several messages we stay in the while loop */
    /* and collect, save, reply and execute the messages until there is */
    /* a pause: */
    while(my_message=(struct IntuiMessage *)GetMsg( my_window->UserPort))
    {
      /* GetMsg will return a pointer to a message if there was one, */
      /* else it returns NULL. We will therefore stay in this while loop */
      /* as long as there are some messages waiting in the port. */
     
      /* After we have collected the message we can read it, and save */
      /* any important values which we maybe want to check later: */
      class = my_message->Class;      /* Save the IDCMP flag. */

      /* After we have read it we reply as fast as possible: */
      /* REMEMBER! Do never try to read a message after you have replied! */
      /* Some other process has maybe changed it. */
      ReplyMsg( my_message );

      /* Check which IDCMP flag was sent: */
      switch( class )
      {
        case CLOSEWINDOW:  /* The user selected the Close window gadget! */
               close_me=TRUE;
               break;
             
        case GADGETDOWN:   /* The user has selected the Prop. gadget: */
               printf("Proportional gadget selected.\n");
               break;
             
        case GADGETUP:     /* The user has released the Prop. gadget: */
               printf("Proportional gadget released.\n");
               break;
      }
    }
    printf("Hor= %1.0f\n", (float) my_prop_info.HorizPot / MAXPOT * 32);
    printf("Ver= %1.0f\n\n", (float) my_prop_info.VertPot / MAXPOT * 10);
  }

  /* We should always close the windows we have opened before we leave: */
  CloseWindow( my_window );



  /* Close the Intuition Library since we have opened it: */
  CloseLibrary( IntuitionBase );

  /* THE END */
}
[/color]


Thank you for the help,
AmigaEd
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - Prístino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebows
 

Offline Heinz

  • Full Member
  • ***
  • Join Date: Nov 2005
  • Posts: 154
    • Show only replies by Heinz
    • http://amidevcpp.amiga-world.de
Re: AmiDevCpp and Floats
« Reply #3 on: January 19, 2006, 09:49:09 AM »
Hmm, thats strange.
I compiled your source with AmiDevCpp for m68k-AmigaOS and this is a screenshot of your Program running on OS 3.9 with AfA (Aros for Amiga OS) installed:



Everything seems to work correctly. So I dont know how to help you here.

I forgot to say I am using AmiDevCpp v 0.9 but that should'nt make a difference for 68k Programs.

You should take a look to this Tutorial:

http://www.liquido2.com/tutorial/

This should work fine with AmiDevCpp.

I would be happy if you could Upload some Example Projects on the AmiDevCpp Site:

http://amidev.kilu.net/exampleupload.php3
 

Offline AmigaEdTopic starter

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
    • Show only replies by AmigaEd
Re: AmiDevCpp and Floats
« Reply #4 on: January 19, 2006, 12:44:01 PM »
Heinz,
I couldn't see your screen shot in the post.
I have PM'd you with my email address. Perhaps you can send it to me.

That example that I posted is taken from the Amiga C manual which I beleive can be found on Aminet.

But, yes I would be happy to post some examples of code once I start getting the bugs worked out.


Thank you,
Ed
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - Prístino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebows
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: AmiDevCpp and Floats
« Reply #5 on: January 19, 2006, 03:43:22 PM »
Ok, it appears to work for me under MorphOS aswell.



My guess is that you forgot -noixemul and that you have some old and incompatible ixemul.library installed.

Try adding -noixemul if you didn't already.

Another option: You have some weird libnix stdio that uses dos.library Printf or exec.library RawDoFmt for printf. dos and exec don't know about %f...
 

Offline AmigaEdTopic starter

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
    • Show only replies by AmigaEd
Re: AmiDevCpp and Floats
« Reply #6 on: January 20, 2006, 01:51:45 AM »
O.K. I got thinking about what you Heinz and Piru have said so I tried some reverse logic and I got the program to work.

Here is how AmiDevCpp is configured when it doesn't work...
Doesn't work with this Configuration

Here is how AmiDevCpp is configured when it does work.
I just unchecked the option to use -noixemul...
Does work with this configuration

Now perhaps someone can explain to me what -noixemul does. I don't have a clue.

and here it is working...
Here is the example working

Thank you for the help,
AmigaEd




"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - Prístino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebows
 

Offline AmigaEdTopic starter

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
    • Show only replies by AmigaEd
Re: AmiDevCpp and Floats
« Reply #7 on: January 20, 2006, 02:24:56 AM »
O.k. the links to the images should be working now.
-AmigaEd
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - Prístino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebows