[comp.sys.amiga.programmer] Why does this GURU???

bosman@fwi.uva.nl (Dr.D) (06/13/91)

I have here a little program (small part of a larger one) that
gurus. But I can't figure out why..

Maybe some of you guys see what I do wrong..
it gurus at the WritePixel.....
------------------------------------------------------
#include "exec/types.h"
#include "intuition/intuition.h"

struct Window *NoBorder;
struct RastPort *r;
struct GfxBase *GfxBase;
struct Screen *Scrn;

main()
{
  char c;
  ULONG flags;
  SHORT x,y,w,h,d,c0,c1;

  USHORT mode;
  VOID delay_func();

  OpenAll();

  /* open a hires custom screen  */

  y=0;
  w=640;
  h=400;
  d=4;
  c0=0x00;
  c1=0x01;
  mode=HIRES;
  Scrn = (struct Screen *)make_screen(y,w,h,d,c0,c1,mode,"TESTSCREEN"); 
  /*  Open a borderless window  */

  x=y=40;
  w=500;
  h=200;
  flags=ACTIVATE|SMART_REFRESH;
 NoBorder = (struct Window *)make_window(x,y,w,h,"window",flags,NULL,-1,-1,Scrn); 
  if (NoBorder == NULL) {printf("errortje"); exit(1); }


  c=getchar();
  WritePixel(NoBorder->RPort,(long)20,(long)20);
  c=getchar();
  /* delay for a bit */
  delay_func(100);

  /* Close down everything */
  CloseWindow(NoBorder);
  CloseScreen(Scrn);

}

VOID delay_func(factor)
int factor;
{
  int loop;

  for(loop=0;loop<factor*1000;loop++)
    ;

}
#include <graphics/display.h>
make_screen(y,w,h,d,color0,color1,mode,name)
SHORT y,w,h,d;
UBYTE color0,color1,*name;
USHORT mode;

{
  struct NewScreen NS;

  NS.LeftEdge=0;
  NS.TopEdge=y;
  NS.Width=w;
  NS.Height=h;
  NS.Depth=d;
  NS.DetailPen=color0;
  NS.BlockPen=color1;
  NS.ViewModes=mode;
  NS.Type=CUSTOMSCREEN;
  NS.Font=NULL;
  NS.DefaultTitle=name;
  NS.Gadgets=NULL;
  NS.CustomBitMap=NULL;

  return(OpenScreen(&NS));
}

make_window(x,y,w,h,name,flags,iflags,color0,color1,screen)
SHORT x,y,w,h;
UBYTE *name,color0,color1;
ULONG flags;
USHORT iflags;
struct Screen *screen;
{
  struct NewWindow NW;

  NW.LeftEdge=x;
  NW.TopEdge=y;
  NW.Width=w;
  NW.Height=h;
  NW.DetailPen=color0;
  NW.BlockPen=color1;
  NW.Title=name;
  NW.Flags=flags;
  NW.IDCMPFlags=iflags;
  NW.Type=CUSTOMSCREEN;
  NW.Screen = screen;
  NW.FirstGadget=NULL;
  NW.CheckMark=NULL;
  NW.Screen=screen;
  NW.BitMap=NULL;
  NW.MinWidth=0;
  NW.MinHeight=0;
  NW.MaxWidth=0;
  NW.MaxHeight=0;

  return(OpenWindow(&NW));
}

struct IntuitionBase *IntuitionBase;

#define INTUITION_REV 33L

OpenAll()
{
  IntuitionBase=(struct IntuitionBase *)
                   OpenLibrary("intuition.library",INTUITION_REV);

  if(IntuitionBase == NULL)
    exit(FALSE);
}

-- 
|bosman@fwi.uva.nl_   //    |  Honest Officer , had I known my health       |
|-----------------\\ //AMIGA|  stood in jeopardy I would never had lit one. |
|   [  PE  ]       \//      |              -MAXIM (of the Hells Angels)-    |
|__________ Quickly Scotty,beam me up.There is no ox..y..ge...______________|

peter@cbmvax.commodore.com (Peter Cherna) (06/13/91)

In article <1991Jun13.113948.3806@fwi.uva.nl> bosman@fwi.uva.nl (Dr.D) writes:
>I have here a little program (small part of a larger one) that
>gurus. But I can't figure out why..
>
>Maybe some of you guys see what I do wrong..
>it gurus at the WritePixel.....

You're not opening graphics.library.  WritePixel() is a graphics function,
not an Intuition one.


>|bosman@fwi.uva.nl_   //    |  Honest Officer , had I known my health       |

     Peter
--
Peter Cherna, Operating Systems Development Group, Commodore-Amiga, Inc.
{uunet|rutgers}!cbmvax!peter    peter@cbmvax.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"Gosh, didn't he have anything positive to say at all?"

cunniff@hpfcso.FC.HP.COM (Ross Cunniff) (06/14/91)

In article <1991Jun13.113948.3806@fwi.uva.nl> bosman@fwi.uva.nl writes:

>I have here a little program (small part of a larger one) that
>gurus. But I can't figure out why..

>Maybe some of you guys see what I do wrong..
>it gurus at the WritePixel.....

You forgot to say:

struct GfxBase
    *GfxBase;

OpenAll()
{
    GfxBase = OpenLibrary( "graphics.library", 33L );
}

				Ross Cunniff
				Hewlett-Packard Colorado Language Lab
				cunniff@hpfcla

ahh@glyph.kingston.ny.us (Andy Heffernan) (06/23/91)

In article <1991Jun13.113948.3806@fwi.uva.nl> bosman@fwi.uva.nl (Dr.D) writes:
>I have here a little program (small part of a larger one) that
>gurus. But I can't figure out why..
>
>Maybe some of you guys see what I do wrong..
>it gurus at the WritePixel.....

You've gotten your answer already, but I wanted to point out that
you're playing silly buggers with pointers, and that some day all
of your code will start to fail, violently.

>struct Screen *Scrn;

Now, Scrn is a pointer.

>  Scrn = (struct Screen *)make_screen(y,w,h,d,c0,c1,mode,"TESTSCREEN"); 

Scrn is being set to whatever thing make_screen returns, but is coerced
into a pointer, perhaps to keep the compiler from complaining.
Hmmm, this looks suspicious.  What does make_screen return?

>make_screen(y,w,h,d,color0,color1,mode,name)
>SHORT y,w,h,d;
>UBYTE color0,color1,*name;
>USHORT mode;

make_screen returns an int.  Pointers and ints are not the same thing.
You need a pointer, therefore make_screen (and by extension OpenScreen)
should return pointers.  OpenScreen does already, that's the way it was
written.  You must declare it correctly, however, before it is used.
The same holds for make_screen as well, except that you must also define
it correctly.  The right thing to do is:

struct Screen *Scrn;
struct Screen *OpenScreen();
struct Screen *make_screen();

... much code ...

Scrn = make_screen(y,w,h,d,c0,c1,mode,"TESTSCREEN"); 

... much code ...

struct Screen *make_screen(y,w,h,d,color0,color1,mode,name)
SHORT y,w,h,d;
UBYTE color0,color1,*name;
USHORT mode;

... everything else ...

Do the same thing with your window variable and code.

-- 
-------------------------------------------------------------------------
  Andy Heffernan		$BJ8;z(J		uunet!glyph!ahh