Second version og statif16.dif plus some more stuff: - inline functions defined as macro and non-inline versions - BGI number of colors for DOS / BCC limited to < 15bpp - BGI aspect ratio fixed for 16-bit systems (DOS / BCC) - _BGI_INLINE_ moved to fldfill.c, the only module that uses it now - inline functions in text4.c replaced with macros, please check it - test\bgi\colortst.c fixed to use getch() not getchar() Compiled and tested with DOS / BCC only. Will test with Linux ASAP.
diff -Nru3 grx245-1/include/libbcc.h grx/include/libbcc.h --- grx245-1/include/libbcc.h Sat Dec 22 14:02:42 2001 +++ grx/include/libbcc.h Fri Jun 28 16:18:52 2002 @@ -495,217 +495,317 @@ #endif
/* ----------------------------------------------------------------- */ -#ifdef __cplusplus -#define _BGI_INLINE_ inline -#elif defined(__GNUC__) -#define _BGI_INLINE_ __inline__ -#elif defined(_MSC_VER) -#define _BGI_INLINE_ _inline -#else -#define _BGI_INLINE_ -#endif +/* --- API functions with macro equivalents --- */ +/* --- (for inlining) --- */ /* ----------------------------------------------------------------- */ +void restorecrtmode(void); +int getgraphmode(void); +int getmaxmode(void); +void getmoderange(int gd, int *lomode, int *himode); +int graphresult(void); +int getx(void); +int gety(void); +void moveto(int x, int y); +void moverel(int dx, int dy); +int getbkcolor(void); +int getcolor(void); +void cleardevice(void); +void setbkcolor(int color); +void setcolor(int color); +void line(int x1, int y1, int x2, int y2); +void linerel(int dx, int dy); +void lineto(int x, int y); +void drawpoly(int numpoints, void *polypoints); +void bar(int left, int top, int right, int bottom); +void circle(int x, int y, int radius); +void ellipse( int x, int y, int stangle, int endangle, + int xradius, int yradius ); +void arc(int x, int y, int stangle, int endangle, int radius); +void getaspectratio(int *xasp, int *yasp); +void setaspectratio( int xasp, int yasp ); +void getfillsettings(struct fillsettingstype *fillinfo); +void getfillpattern(char *pattern); +void sector( int x, int y, int stangle, int endangle, + int xradius, int yradius ); +void pieslice(int x, int y, int stangle, int endangle, int radius); +unsigned setgraphbufsize(unsigned bufsize); +struct palettetype *getdefaultpalette(void); +int installbgidriver(char *name, void *detect); +int registerfarbgidriver(void *driver); +int registerfarbgifont(void *font); +void textlinestyle(int on); +void setpalette(int colornum, int color); +void set_BGI_mode_pages(int p); +int get_BGI_mode_pages(void); +void set_BGI_mode_whc(int *gd, int *gm, int width, int height, int colors); +int getmodemaxcolor(int mode); +int getmodemaxx(int mode); +int getmodemaxy(int mode); +int setrgbcolor(int r, int g, int b); +void setactivepage(int p); +int getactivepage(void); +void setvisualpage(int p); +int getvisualpage(void); + +/* ----------------------------------------------------------------- */ +#define restorecrtmode() __gr_restorecrtmode() +#define getgraphmode() (__gr_INIT ? __gr_Mode : (__gr_Result=grNoInitGraph)) +#define getmaxmode() (__gr_set_up_modes(), __gr_MaxMode) +#define getmoderange(gd, lomode, himode) \ + __gr_getmoderange((gd),(lomode),(himode)) +/* graphresult() uses local variable res */ +#define getx() (__gr_X+0) +#define gety() (__gr_Y+0) +#define moveto(x, y) do { __gr_X = (x); __gr_Y = (y); } while(0) +#define moverel(dx, dy) moveto(getx()+(dx),gety()+(dy)) +#define getbkcolor() (__gr_colorbg+0) +#define getcolor() (__gr_color+0) +#define cleardevice() __gr_cleardevice() +#define setbkcolor(color) do __gr_colorbg = (color); while(0) +#define setcolor(color) do __gr_color = (color); while(0) +#define line(x1, y1, x2, y2) __gr_line((x1),(y1),(x2),(y2)) +#define linerel(dx, dy) __gr_line(getx(),gety(),getx()+(dx),gety()+(dy)) +#define lineto(x, y) __gr_line(getx(),gety(),(x),(y)) +#define drawpoly(numpoints, polypoints) \ + __gr_drawpol((numpoints), (polypoints), FALSE) +#define bar(left, top, right, bottom) __gr_bar((left),(top),(right),(bottom)) +#define circle(x, y, radius) __gr_circle((x),(y),(radius)) +#define ellipse(x, y, stangle, endangle, xradius, yradius) \ + __gr_ellipse((x),(y),(stangle),(endangle),(xradius),(yradius)) +/* arc() uses radius twice */ +#define getaspectratio(xasp, yasp) \ + do { *(xasp) = __gr_Xasp; *(yasp) = __gr_Yasp; } while(0) +#define setaspectratio(xasp, yasp ) \ + do { __gr_Xasp = (xasp); __gr_Yasp = (yasp); } while(0) +/* getfillsettings() uses fillinfo twice */ +#define getfillpattern(pattern) __gr_getfillpattern(pattern) +#define sector(x, y, stangle, endangle, xradius, yradius) \ + __gr_sector((x),(y),(stangle),(endangle),(xradius), (yradius)); +/* pieslice() uses radius twice */ +#define setgraphbufsize(bufsize) __gr_setgraphbufsize(bufsize) +#define getdefaultpalette() (&__gr_EGAdef) +#define installbgidriver(name, detect) __gr_installbgidriver((name), (detect)) +#define registerfarbgidriver(driver) __gr_registerfarbgidriver(driver) +#define registerfarbgifont(font) registerbgifont(font) +#define textlinestyle(on) do __gr_TextLineStyle = on; while(0); +#define setpalette(colornum, color) __gr_setpalette((colornum),(color)) +#define set_BGI_mode_pages(p) __gr_set_BGI_mode_pages(p) +#define get_BGI_mode_pages() __gr_get_BGI_mode_pages() +#define set_BGI_mode_whc(gd, gm, width, height, colors) \ + do { \ + __gr_set_BGI_mode_pages(1); \ + __gr_BGI_w = (width); \ + __gr_BGI_h = (height); \ + __gr_BGI_c = (colors); \ + *(gd) = NATIVE_GRX; \ + *(gm) = GRX_BGI_EMULATION; \ + } while(0) +#define getmodemaxcolor(mode) __gr_getmodemaxcolor(mode) +#define getmodemaxx(mode) __gr_getmodemaxx(mode) +#define getmodemaxy(mode) __gr_getmodemaxx(mode) +#define setrgbcolor(r, g, b) __gr_setrgbcolor((r),(g),(b)) +#define setactivepage(p) __gr_setactivepage(p) +#define getactivepage() __gr_getactivepage() +#define setvisualpage(p) __gr_setvisualpage(p) +#define getvisualpage() __gr_getvisualpage() + +#ifdef __BCCGRX_C
/* ----------------------------------------------------------------- */ -/* --- The following functions work line macros with gcc, each --- */ -/* --- function <func> has a compatible direct linkable variant --- */ -/* --- __gr_<func> that is fully compatible --- */ -/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void restorecrtmode(void) { +void (restorecrtmode)(void) { __gr_restorecrtmode(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getgraphmode(void) { +int (getgraphmode)(void) { return (__gr_INIT ? __gr_Mode : (__gr_Result=grNoInitGraph)); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmaxmode(void) { +int (getmaxmode)(void) { __gr_set_up_modes(); return __gr_MaxMode; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getmoderange(int gd, int *lomode, int *himode) { +void (getmoderange)(int gd, int *lomode, int *himode) { __gr_getmoderange(gd, lomode, himode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int graphresult(void) { +int (graphresult)(void) { int res = (__gr_INIT ? __gr_Result : grNoInitGraph); __gr_Result = grOk; return res; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getx(void) { +int (getx)(void) { return __gr_X; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int gety(void) { +int (gety)(void) { return __gr_Y; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void moveto(int x, int y) { +void (moveto)(int x, int y) { __gr_X = x; __gr_Y = y; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void moverel(int dx, int dy) { +void (moverel)(int dx, int dy) { moveto( getx()+dx, gety()+dy); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getbkcolor(void) { +int (getbkcolor)(void) { return __gr_colorbg; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getcolor(void) { +int (getcolor)(void) { return __gr_color; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void cleardevice(void) { +void (cleardevice)(void) { __gr_cleardevice(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setbkcolor(int color) { +void (setbkcolor)(int color) { __gr_colorbg= color; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setcolor(int color) { +void (setcolor)(int color) { __gr_color= color; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void line(int x1, int y1, int x2, int y2) { +void (line)(int x1, int y1, int x2, int y2) { __gr_line(x1,y1,x2,y2); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void linerel(int dx, int dy) { +void (linerel)(int dx, int dy) { register int x = getx(); register int y = gety(); __gr_line(x,y,x+dx,y+dy); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void lineto(int x, int y) { +void (lineto)(int x, int y) { __gr_line( getx(), gety(), x, y); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void drawpoly(int numpoints, void *polypoints) { +void (drawpoly)(int numpoints, void *polypoints) { __gr_drawpol(numpoints, polypoints, FALSE); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void bar(int left, int top, int right, int bottom) { +void (bar)(int left, int top, int right, int bottom) { __gr_bar(left,top,right, bottom); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void circle(int x, int y, int radius) { +void (circle)(int x, int y, int radius) { __gr_circle(x,y,radius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void ellipse( int x, int y, int stangle, int endangle, - int xradius, int yradius ) { +void (ellipse)( int x, int y, int stangle, int endangle, + int xradius, int yradius ) { __gr_ellipse( x, y, stangle, endangle, xradius, yradius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void arc(int x, int y, int stangle, int endangle, int radius) { +void (arc)(int x, int y, int stangle, int endangle, int radius) { __gr_ellipse(x,y,stangle,endangle,radius,radius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getaspectratio(int *xasp, int *yasp) { +void (getaspectratio)(int *xasp, int *yasp) { *xasp = __gr_Xasp; *yasp = __gr_Yasp; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setaspectratio( int xasp, int yasp ) { +void (setaspectratio)( int xasp, int yasp ) { __gr_Xasp = xasp; __gr_Yasp = yasp; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getfillsettings(struct fillsettingstype *fillinfo) { +void (getfillsettings)(struct fillsettingstype *fillinfo) { fillinfo->pattern = __gr_fpatno; fillinfo->color = __gr_colorfill; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void getfillpattern(char *pattern) { +void (getfillpattern)(char *pattern) { __gr_getfillpattern(pattern); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void sector( int x, int y, int stangle, int endangle, - int xradius, int yradius ) { +void (sector)( int x, int y, int stangle, int endangle, + int xradius, int yradius ) { __gr_sector(x,y,stangle,endangle,xradius, yradius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void pieslice(int x, int y, int stangle, int endangle, int radius) { +void (pieslice)(int x, int y, int stangle, int endangle, int radius) { __gr_sector(x,y,stangle,endangle,radius,radius); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ unsigned setgraphbufsize(unsigned bufsize) { +unsigned (setgraphbufsize)(unsigned bufsize) { return __gr_setgraphbufsize(bufsize); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ struct palettetype *getdefaultpalette(void) { +struct palettetype *(getdefaultpalette)(void) { return &__gr_EGAdef; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int installbgidriver(char *name, void *detect) { +int (installbgidriver)(char *name, void *detect) { return __gr_installbgidriver(name, detect); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int registerfarbgidriver(void *driver) { +int (registerfarbgidriver)(void *driver) { return __gr_registerfarbgidriver(driver); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int registerfarbgifont(void *font) { +int (registerfarbgifont)(void *font) { return registerbgifont(font); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void textlinestyle(int on) { +void (textlinestyle)(int on) { __gr_TextLineStyle = on; }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setpalette(int colornum, int color) { +void (setpalette)(int colornum, int color) { __gr_setpalette(colornum,color); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void set_BGI_mode_pages(int p) { +void (set_BGI_mode_pages)(int p) { __gr_set_BGI_mode_pages(p); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int get_BGI_mode_pages(void) { +int (get_BGI_mode_pages)(void) { return __gr_get_BGI_mode_pages(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void set_BGI_mode_whc(int *gd, int *gm, - int width, int height, int colors) { +void (set_BGI_mode_whc)(int *gd, int *gm, int width, int height, int colors) { __gr_set_BGI_mode_pages(1); __gr_BGI_w = width; __gr_BGI_h = height; @@ -715,48 +815,49 @@ }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmodemaxcolor(int mode) { +int (getmodemaxcolor)(int mode) { /* works like getmaxcolor() for mode */ return __gr_getmodemaxcolor(mode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmodemaxx(int mode) { +int (getmodemaxx)(int mode) { /* works like getmaxx() for mode */ return __gr_getmodemaxx(mode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getmodemaxy(int mode) { +int (getmodemaxy)(int mode) { /* works like getmaxy() for mode */ return __gr_getmodemaxx(mode); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int setrgbcolor(int r, int g, int b) { +int (setrgbcolor)(int r, int g, int b) { return __gr_setrgbcolor(r,g,b); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setactivepage(int p) { +void (setactivepage)(int p) { __gr_setactivepage(p); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getactivepage(void) { +int (getactivepage)(void) { return __gr_getactivepage(); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void setvisualpage(int p) { +void (setvisualpage)(int p) { __gr_setvisualpage(p); }
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int getvisualpage(void) { +int (getvisualpage)(void) { return __gr_getvisualpage(); }
+#endif /* __BCCGRX_C */ /* ----------------------------------------------------------------- */
#endif diff -Nru3 grx245-1/src/bgi/bccgrx.c grx/src/bgi/bccgrx.c --- grx245-1/src/bgi/bccgrx.c Thu Apr 19 04:20:52 2001 +++ grx/src/bgi/bccgrx.c Fri Jun 28 16:08:50 2002 @@ -176,6 +176,9 @@ ++fmode ) { mp = GrFirstVideoMode(fmode); while (mp != NULL) { +#if defined(__TURBOC__) && defined(__MSDOS__) + if(mp->bpp < 15) +#endif NewMode(mp->width, mp->height, 1<<mp->bpp); mp = GrNextVideoMode(mp); } @@ -324,7 +327,7 @@ __gr_clip = TRUE;
__gr_Xasp = 10000; - __gr_Yasp = __gr_Xasp * ((VR+1)*3) / ((VB+1)*4); + __gr_Yasp = __gr_Xasp * ((VR+1)*3L) / ((VB+1)*4L);
__gr_lstyle = SOLID_LINE; LNE.lno_pattlen = 0; diff -Nru3 grx245-1/src/bgi/bccgrx00.h grx/src/bgi/bccgrx00.h --- grx245-1/src/bgi/bccgrx00.h Thu Apr 19 04:20:52 2001 +++ grx/src/bgi/bccgrx00.h Fri Jun 28 14:35:44 2002 @@ -103,7 +103,24 @@ #define IMAGE_CONTEXT_SIZE (((sizeof(GrContext)+15)&~15)+4)
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ void __gr_Reset_ClipBox(void) +#ifdef GRX_VERSION +#define GrResetClipBox() GrSetClipBox( 0, PY, getmaxx(), getmaxy()+PY) +#endif + +void __gr_Reset_ClipBox(void); +#define __gr_Reset_ClipBox() \ + do { \ + if (__gr_clip) GrSetClipBox( VL, VT+PY, VR, VB+PY); \ + else GrResetClipBox(); \ + } while(0) + +#ifdef GRX_VERSION +#undef GrResetClipBox +#endif + +#ifdef __BCCGRX_C + +void (__gr_Reset_ClipBox)(void) { if (__gr_clip) GrSetClipBox( VL, VT+PY, VR, VB+PY); else @@ -113,6 +130,8 @@ GrResetClipBox(); #endif } + +#endif
/* ----------------------------------------------------------------- */
diff -Nru3 grx245-1/src/bgi/fldfill.c grx/src/bgi/fldfill.c --- grx245-1/src/bgi/fldfill.c Thu Apr 19 04:42:56 2001 +++ grx/src/bgi/fldfill.c Fri Jun 28 14:28:54 2002 @@ -67,6 +67,16 @@ #define calc_high_bits(x) ( (~((element)0)) << ((x)&(bits_per_element-1))) #define calc_ofs(x) ((x) / offset_div)
+/* ----------------------------------------------------------------- */ +#if defined(__GNUC__) +#define _BGI_INLINE_ __inline__ +#elif defined(_MSC_VER) +#define _BGI_INLINE_ _inline +#else +#define _BGI_INLINE_ +#endif +/* ----------------------------------------------------------------- */ + /* -------- internal line buffer functions ** ** (x,y) scaled to (0..mx,0..my) diff -Nru3 grx245-1/src/bgi/text4.c grx/src/bgi/text4.c --- grx245-1/src/bgi/text4.c Sun Dec 23 03:15:42 2001 +++ grx/src/bgi/text4.c Fri Jun 28 14:11:04 2002 @@ -25,14 +25,8 @@ #include "text.h"
/* ----------------------------------------------------------------- */ -static _BGI_INLINE_ int xoff(_ushort x) { - /* Csaba did it this way, well done */ - return ((int)(signed char)((x) << 1) >> 1); -} - -static _BGI_INLINE_ int yoff(_ushort y) { - return - ((int)(signed char)((y) >> 7) >> 1); -} +#define xoff(x) ((int)(signed char)(((_ushort) (x)) << 1) >> 1) +#define yoff(y) (-((int)(signed char)(((_ushort) (y)) >> 7) >> 1))
/* ----------------------------------------------------------------- */ void __gr_text_vec(int *xx, int *yy, int XX, int YY, int len, uchar *txt) diff -Nru3 grx245-1/test/bgi/colortst.c grx/test/bgi/colortst.c --- grx245-1/test/bgi/colortst.c Thu Jun 27 12:50:54 2002 +++ grx/test/bgi/colortst.c Fri Jun 28 16:13:34 2002 @@ -7,6 +7,14 @@
#include "libbcc.h"
+#ifdef __DJGPP__ +#include <conio.h> +#include <pc.h> +#else +extern int getch(void); +extern int getkey(void); +extern int kbhit(void); +#endif
static void testmode(int mode) { int xmax, ymax; @@ -89,7 +97,7 @@ settextjustify( CENTER_TEXT, BOTTOM_TEXT ); outtextxy(getmaxx()/2, getmaxy(), mn); } - getchar(); + getch();
if (oldmode != mode) setgraphmode(oldmode);