home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / programming / c / awin / awin.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-17  |  10.6 KB  |  357 lines

  1. #ifndef _AWINAWIN_H
  2. #define _AWINAWIN_H
  3.  
  4. /* awin.h
  5.  
  6.   defines, structures and prototypes for awin
  7.  
  8.   IMPORTANT: everything is subject to change!
  9.   Do NOT rely on old object files!
  10.   Always recompile files #including awin.h if awin.h
  11.   has changed!
  12.  
  13.   All structure entries should be at longword aligned
  14.   position for maximum speed and compatibility (68k<->ppc).
  15.  
  16. */
  17.  
  18. #include <exec/exec.h>
  19. #include <devices/timer.h>
  20. #include <graphics/gfx.h>
  21. #include <graphics/text.h>
  22. #include <intuition/intuition.h>
  23. #include <intuition/screens.h>
  24. #include <dos/dos.h>
  25. #include <dos/rdargs.h>
  26. #include <workbench/icon.h>
  27. #include <workbench/workbench.h>
  28. #include <graphics/gfxbase.h>
  29. #include <intuition/intuitionbase.h>
  30.  
  31. typedef ULONG(*AWIDCMPHOOK_PTR)(struct IntuiMessage *);
  32.  
  33. typedef enum awports {
  34.   AW_WRITEPORT=0,
  35.   AW_DISPPORT,
  36.   AW_NUMPORTS} awports;
  37.  
  38. typedef enum awdebugl {
  39.   AWD_QUIET=0,
  40.   AWD_VERBOSE,
  41.   AWD_DEBUG} awdebugl;
  42.  
  43. typedef enum awidha {
  44.   AWIDHA_NOP=0} awidha;
  45.  
  46. #define AW_VPRINT(a) if (display->debug) printf(a);
  47. #define AW_VPRINT1(a,x) if (display->debug) printf(a,x);
  48. #define AW_DPRINT(a) if (display->debug>=AWD_DEBUG) printf(a);
  49. #define AW_DPRINT1(a,x) if (display->debug>=AWD_DEBUG) printf(a,x);
  50.  
  51. /* rrrrrggg gggbbbbb 565 -> rrrgggbb 332 */
  52. #define awrgb16to332(x) ( (((x)>>8)&(7<<5)) | (((x)>>6)&(7<<2)) | (((x)>>3)&3) )
  53.  
  54. /* rrrrrggg gggbbbbb 565 -> 00000000rrrrr000gggggg00bbbbb000 0888 */
  55. #define awrgb16to0888(x) ( (((x)&0xf800)<<8) | (((x)&0x7e0)<<5) | (((x)&0x1f)<<3) )
  56.  
  57.  
  58. #if defined(AW_PPC)
  59. #  define sub64p(a,b) \
  60.      { ((ULONG *)(a))[0]=((ULONG *)(b))[0]-((ULONG *)(a))[0] \
  61.          -(((ULONG *)(b))[1]<((ULONG *)(a))[1]?1:0); \
  62.        ((ULONG *)(a))[1]=((ULONG *)(b))[1]-((ULONG *)(a))[1]; }
  63.  
  64. #  if defined(__SASC)
  65.  
  66. #    define ppcgettimerobject(a,b,c) \
  67.        (PPCGetTimerObject((a),(b),(ULONG *)(c)))
  68. #    define ppcsettimerobject(a,b,c) \
  69.        (PPCSetTimerObject((a),(b),(ULONG *)(c)))
  70. #    define ppcneg64p(a) \
  71.        (PPCNeg64p((int *)(a)))
  72. #    define ppcmuls64p(a,b) \
  73.        (PPCMuls64p((int *)(a),(int *)(b)))
  74. #    define ppcmulu64p(a,b) \
  75.        (PPCMulu64p((int *)(a),(int *)(b)))
  76. #    define ppcdivu64p(a,b) \
  77.        (PPCDivu64p((int *)(a),(int *)(b)))
  78.  
  79. #  else
  80. #    if defined(__GNUC__)
  81.  
  82. #      define ppcgettimerobject(a,b,c) \
  83.          (PPCGetTimerObject((a),(b),(long long *)(c)))
  84. #      define ppcsettimerobject(a,b,c) \
  85.          (PPCSetTimerObject((a),(b),(long long *)(c)))
  86. #      define ppcneg64p(a) \
  87.          (*((long long *)(a))=PPCNeg64(*((long long *)(a))))
  88. #      define ppcmuls64p(a,b) \
  89.          (*((long long *)(a))=PPCMuls64(*((long long *)(a)),*((long long *)(b))))
  90. #      define ppcmulu64p(a,b) \
  91.          (*((long long *)(a))= \
  92.          PPCMulu64(*((long long *)(a)),*((long long *)(b))))
  93. #      define ppcdivu64p(a,b) \
  94.          (*((long long *)(a))= \
  95.          PPCDivu64(*((long long *)(a)),*((long long *)(b))))
  96.  
  97. #    else
  98. #      error unknown compiler
  99. #    endif
  100. #  endif
  101. #endif
  102.  
  103. /* struct awodargs flags */
  104.  
  105. #define AWODAF_INITWINDOW    0x00000001 /* initially open as window */
  106. #define AWODAF_DONTUPDATEINA 0x00000002 /* don't update if inactive */
  107. #define AWODAF_NODBUFFER     0x00000004 /* don't do double buffering */
  108. #define AWODAF_FORCENATIVE   0x00000008 /* force native mode */
  109. #define AWODAF_DIRECTDRAW    0x00000010 /* use directdraw with CGFX */
  110. #define AWODAF_USEHAM        0x00000020 /* use ham for 16bit if applicable, if
  111.                                            not defined uses 256col emulation */
  112. #define AWODAF_WAITSWAP      0x00000040 /* wait dbuffer safetoswap, this limits
  113.                                            fps to hz/2 */
  114. #define AWODAF_USECGXVIDEO   0x00000080 /* use cgxvideo.library if possible */
  115. #define AWODAF_ABSPOS        0x00000100 /* use absolute window positioning */
  116. #define AWODAF_USEARGB16     0x00000200 /* use ARGB for depth 16 */
  117.  
  118.  
  119. /* specifying AWODAF_FORCENATIVE clears AWODAF_DIRECTDRAW.
  120. */
  121.  
  122. /* this structure is used to handle awin settings,
  123.    all public rw:
  124. */
  125. struct awodargs {
  126.   ULONG version;      /* 0 for now */
  127.  
  128.   ULONG flags;        /* initial flags, see defines above */
  129.  
  130.   ULONG modeid8;      /* explicit modeid to use for 8bit screen
  131.                          mode, 0 means find best mode */
  132.  
  133.   ULONG modeid16;     /* explicit modeid to use for 16bit screen
  134.                          mode, 0 means find best mode */
  135.  
  136.   ULONG width,height; /* initial display width and height
  137.                          also always screen dimension */
  138.  
  139.   LONG x,y;           /* relative window displacement on pubscreen,
  140.                          normally window is centered to
  141.                          middle of visible part of a pubscreen.
  142.                          use these offsets to move it relative
  143.                          to that position. if AWODAF_ABSPOS is set
  144.                          indicates absolute window left & top. */
  145.  
  146.   const char *title;  /* optional window title */
  147.  
  148.   const char *pubscreen;
  149.                       /* optional pubscreen name to open window to,
  150.                          NULL to open on default pubscreen */
  151.   ULONG unused0;      /* this should be NULL for now */
  152. };
  153.  
  154. /* returned by awreadargs,
  155.    all private:
  156. */
  157. struct awrdargs {
  158.   struct Library *DOSBase;
  159.   LONG *array;
  160.   struct RDArgs *rda;  /* has two meanings really */
  161.   ULONG wb;
  162. };
  163.  
  164. /* used by awin awreadargs wb tooltypes wrapper
  165.    if awreadargs is called from WB started app, rda
  166.    points to struct awwbrdargs instead of struct RDArgs.
  167.    all private:
  168. */
  169. struct awwbrdargs {
  170.   struct Library *IconBase;
  171.   struct DiskObject *dobj;
  172.   ULONG num;
  173.   char *tlate;
  174.   char **name;
  175.   LONG *type;
  176. };
  177.  
  178. /* returned by awcreatetimer
  179.    all private:
  180. */
  181. struct awtimer {
  182. #if defined(AW_PPC)
  183.   void *timerobject;
  184.   ULONG tickspersec[2];
  185.   ULONG start[2];
  186. #else
  187.   struct Library *timerbase;
  188.   ULONG tickspersec;
  189.   struct EClockVal start;
  190. #endif
  191. };
  192.  
  193. /* returned by awloadfile
  194. */
  195. struct awfile {
  196.   ULONG size;  /* public r */
  197.   void *data;  /* public r */
  198.   ULONG buflen;
  199.   void *memory;
  200. };
  201.  
  202. /* returned by awinitchunkystruct/awallocchunky
  203. */
  204. struct awchunky {
  205.   ULONG width,width_align,height; /* public r */
  206.   ULONG depth;                    /* public r */
  207.   UBYTE *framebuffer;             /* public rw */
  208.   void *memory;
  209. };
  210.  
  211. /* sucks a bit here, should have better system.. :) */
  212. #define awscreensum(sc) (((ULONG)(sc))+((sc)->Width<<16)+(sc)->Height)
  213.  
  214. /* this struture is returned by awcreatedisplay,
  215.    all private:
  216. */
  217. struct awdisplay {
  218.   struct ExecBase *SysBase;
  219.   struct GfxBase *GfxBase;
  220.   struct IntuitionBase *IntuitionBase;
  221.   struct Library *UtilityBase;
  222.   struct Library *TimerBase;
  223.   struct Library *CyberGfxBase;
  224.   struct Library *CGXVideoBase;
  225.   struct Library *DOSBase;
  226.  
  227.   struct Screen *screen;
  228.   struct Window *window;
  229.   struct MsgPort *sbports[AW_NUMPORTS];
  230.   struct ScreenBuffer *sbuf[2];
  231.   struct BitMap *fblitptrbm,*tempbm;
  232.   APTR pointerobject;
  233.   void *memory;
  234.   UBYTE *framebuffer;
  235.   void *c2pplanes[2];
  236.   UBYTE *remap332;
  237.   AWIDCMPHOOK_PTR idcmphook;
  238.  
  239.   ULONG left,top;                       /* window position */
  240.   ULONG width,width_align,
  241.         pixperrow,scrwidth;             /* width */
  242.   ULONG height;                         /* height */
  243.   ULONG origw,origh;
  244.   ULONG prevwidth,prevheight;           /* old window dimensions */
  245.   ULONG widthaligner;
  246.   ULONG modeid8,modeid16;
  247.   LONG xdisp,ydisp;
  248.  
  249.   ULONG native,cgfx,truecolor,fblit,v40,
  250.     stoprender,rendering,wlutpa,safetochange,safetowrite,
  251.     curbuffer,slowwpa8,dbuffer,islinearmem,
  252.     isrgb16,cgfx16bit,cgfx16bitf,gfxcard,debug,isham6,
  253.     usehamf,doham;
  254.  
  255.   ULONG windowmode,dontupdateinactive,nodbuffer,waitswap,
  256.     forcenative,directdraw,useham,usecgxvideo,abspos,
  257.     useargb16;
  258.  
  259.   ULONG srcdepth,dstdepth;
  260.   ULONG palentries;
  261.   ULONG prevscreen;
  262.   ULONG idcmpflags;
  263.  
  264.   ULONG vlwidth,vlheight;
  265.   APTR vlhandle;
  266.  
  267.   struct BitMap c2pbitmap[2];      /* sizeof(struct BitMap) = 40 */
  268.   struct RastPort temprp,renderrp; /* sizeof(struct RastPort) = 100 */
  269.  
  270.   ULONG palette[256];
  271.   ULONG pal332[256];
  272.   UBYTE remap[256]; /* <- be 4 byte aligned here! */
  273.   UBYTE penal[256];
  274.  
  275.   char title[80];
  276.   char pubscreen[MAXPUBSCREENNAME+1];
  277. };
  278.  
  279. #define awalign(x,a) ((((ULONG)(x))+(a)-1)&-(a))
  280.  
  281.  
  282. /* prototypes for public (well mostly;) functions */
  283.  
  284. ULONG awsetdebuglevel(struct awdisplay *display,UBYTE level);
  285.  
  286. struct awrdargs *awreadargs(struct awdisplay *display,
  287.   struct awodargs *odargs,const char *template, LONG *array);
  288. void awfreeargs(struct awrdargs *args);
  289.  
  290. ULONG awscreenmodereq(struct awdisplay *display,ULONG *modeid,
  291.   ULONG depth,ULONG *w,ULONG *h,ULONG dodim);
  292.  
  293. struct awtimer *awcreatetimer(struct awdisplay *display);
  294. void awrestarttimer(struct awtimer *timer);
  295. ULONG awreadtimer(struct awtimer *timer);
  296. ULONG awreadtimer_us(struct awtimer *timer);
  297. void awdeletetimer(struct awtimer *timer);
  298.  
  299. ULONG awtoinnerw(struct awdisplay *display, ULONG width);
  300. ULONG awtowindoww(struct awdisplay *display, ULONG width);
  301. ULONG awtoinnerh(struct awdisplay *display, ULONG height);
  302. ULONG awtowindowh(struct awdisplay *display, ULONG height);
  303.  
  304. AWIDCMPHOOK_PTR awsetidcmphook(struct awdisplay *display,
  305.   AWIDCMPHOOK_PTR idcmphook);
  306. ULONG awsetidcmpflags(struct awdisplay *display,
  307.   ULONG idcmpflags);
  308.  
  309. struct BitMap *awallocbm(ULONG x,ULONG y,ULONG d,ULONG f,struct BitMap *b,
  310.   ULONG fblit);
  311.  
  312. void awfreechunky(struct awchunky *chunky);
  313. struct awchunky *awinitchunkystruct(struct awdisplay *display,
  314.   ULONG width,ULONG height,ULONG depth);
  315. struct awchunky *awallocchunky(struct awdisplay *display,ULONG width,
  316.   ULONG height,ULONG depth);
  317.  
  318. void awclosedisplay(struct awdisplay *display);
  319. void awdeletedisplay(struct awdisplay *display);
  320. void awremap(struct awdisplay *display);
  321. ULONG awsetpalette(struct awdisplay *display,ULONG *palette,ULONG n);
  322. void *awiallocbitmap(struct awdisplay *display,struct BitMap *bm,
  323.   ULONG width,ULONG height,ULONG depth,ULONG memtype);
  324. ULONG awreopen(struct awdisplay *display);
  325. struct awdisplay *awcreatedisplay(void);
  326. ULONG awgetvisiblerect(struct awdisplay *display,
  327.   struct Rectangle *rect);
  328. ULONG awgetaspectratio(struct awdisplay *display,ULONG modeid,
  329.   ULONG *xa,ULONG *ya);
  330. ULONG awgetpropertyflags(struct awdisplay *display,ULONG modeid,
  331.   ULONG *flags);
  332. ULONG awgetmaxdepth(struct awdisplay *display,ULONG modeid,
  333.   ULONG *maxdepth);
  334. void awgetwindimension(struct awdisplay *display,
  335.   ULONG *width,ULONG *height);
  336.  
  337. ULONG awsetflags(struct awdisplay *display,ULONG flags);
  338.  
  339. ULONG awopendisplay(struct awdisplay *display,
  340.   struct awodargs *odargs);
  341.  
  342. ULONG awsetdisplaysize(struct awdisplay *display,
  343.   ULONG width,ULONG height);
  344.  
  345. ULONG awhandleinput(struct awdisplay *display);
  346.  
  347.  
  348. void awrenderchunky(struct awdisplay *display,struct awchunky *chunky);
  349.  
  350. void awrenderchunky_show(struct awdisplay *display,
  351.   struct awchunky *chunky);
  352.  
  353. void awfreefile(struct awfile *file);
  354. struct awfile *awloadfile(const char *name);
  355.  
  356. #endif /* _AWINAWIN_H */
  357.