diff --git a/include/gint/config.h.in b/include/gint/config.h.in index c71c50d..6e3d500 100644 --- a/include/gint/config.h.in +++ b/include/gint/config.h.in @@ -16,6 +16,20 @@ 0x03f7c0a0 = Commit 3f7c0a0 */ #define GINT_HASH 0x@GINT_GIT_HASH@ +/* GINT_HW_{FX,CG}: Identifies the type of hardware running the program. */ +#if defined(FX9860G) +# define GINT_HW_FX 1 +# define GINT_HW_CG 0 +#elif defined(FXCG50) +# define GINT_HW_FX 0 +# define GINT_HW_CG 1 +#endif + +/* GINT_OS_{FX,CG}: Identifies the type of OS API we're assuming. Currently I + see no reason this would be different from hardware, but who knows. */ +#define GINT_OS_FX GINT_HW_FX +#define GINT_OS_CG GINT_HW_CG + /* GINT_NO_OS_STACK: Disables using a chunk of the OS stack as a heap. The top section covering 355/512 ko is otherwise used. (fx-CG 50) */ #cmakedefine GINT_NO_OS_STACK @@ -41,4 +55,8 @@ /* GINT_USB_DEBUG: Selects whether USB debug functions are enabled */ #cmakedefine GINT_USB_DEBUG +/* GINT_RENDER_DMODE: Selects whether the dmode override is available on + rendering functions. */ +#define GINT_RENDER_DMODE GINT_HW_FX + #endif /* GINT_CONFIG */ diff --git a/src/gray/engine.c b/src/gray/engine.c index 906887d..5e51e72 100644 --- a/src/gray/engine.c +++ b/src/gray/engine.c @@ -11,6 +11,7 @@ #include #include "../render-fx/render-fx.h" +#include "../render/render.h" /* Three additional video RAMS, allocated statically if --static-gray was set at configure time, or with malloc() otherwise. */ diff --git a/src/render-fx/dclear.c b/src/render-fx/dclear.c index bf68a60..3db7e80 100644 --- a/src/render-fx/dclear.c +++ b/src/render-fx/dclear.c @@ -1,5 +1,5 @@ #include -#include "render-fx.h" +#include "../render/render.h" /* dclear() - fill the screen with a single color */ void dclear(color_t color) diff --git a/src/render-fx/dgetpixel.c b/src/render-fx/dgetpixel.c index 0b10c1f..0d27be6 100644 --- a/src/render-fx/dgetpixel.c +++ b/src/render-fx/dgetpixel.c @@ -1,6 +1,6 @@ #include #include -#include "render-fx.h" +#include "../render/render.h" int dgetpixel(int x, int y) { diff --git a/src/render-fx/dpixel.c b/src/render-fx/dpixel.c index 375d9f9..6b9cd0b 100644 --- a/src/render-fx/dpixel.c +++ b/src/render-fx/dpixel.c @@ -1,6 +1,6 @@ #include #include -#include "render-fx.h" +#include "../render/render.h" /* dpixel() - change a pixel's color */ void dpixel(int x, int y, int color) diff --git a/src/render-fx/drect.c b/src/render-fx/drect.c index cc07f7c..7eb9f86 100644 --- a/src/render-fx/drect.c +++ b/src/render-fx/drect.c @@ -1,5 +1,6 @@ #include #include +#include "../render/render.h" #include "render-fx.h" void drect(int x1, int y1, int x2, int y2, int color) diff --git a/src/render-fx/dsubimage.c b/src/render-fx/dsubimage.c index 0063ad8..cbbd788 100644 --- a/src/render-fx/dsubimage.c +++ b/src/render-fx/dsubimage.c @@ -1,4 +1,5 @@ #include +#include "../render/render.h" #include "render-fx.h" #include "bopti-asm.h" diff --git a/src/render-fx/dupdate.c b/src/render-fx/dupdate.c index d519fb5..151a1a7 100644 --- a/src/render-fx/dupdate.c +++ b/src/render-fx/dupdate.c @@ -1,6 +1,6 @@ #include #include -#include "render-fx.h" +#include "../render/render.h" /* Standard video RAM for fx9860g is 1 bit per pixel */ GSECTION(".bss") GALIGNED(32) static uint32_t fx_vram[256]; diff --git a/src/render-fx/render-fx.h b/src/render-fx/render-fx.h index f21f3ed..2e272aa 100644 --- a/src/render-fx/render-fx.h +++ b/src/render-fx/render-fx.h @@ -50,38 +50,10 @@ void bopti_render_scsp(bopti_image_t const *img, struct rbox *rbox, uint32_t *v1, uint32_t *v2); //--- -// Alternate rendering modes +// Gray rendering functions for dmode //--- -/* The gray engine overrides the rendering functions by specifying a set of - alternate primitives that are suited to work with two VRAMs. To avoid - linking with them when the gray engine is not used, the display module - exposes a global state in the form of a struct rendering_mode and the gray - engine modifies that state when it runs. */ -struct rendering_mode -{ - /* Because the gray engine still has business to do after the call to - dgray(DGRAY_OFF), the original dupdate() is made to execute after - the replacement one if the replacement one returns 1. */ - int (*dupdate)(void); - /* Area rendering */ - void (*dclear)(color_t color); - void (*drect)(int x1, int y1, int x2, int y2, color_t color); - /* Point rendering */ - void (*dpixel)(int x, int y, color_t color); - int (*dgetpixel)(int x, int y); - void (*gint_dhline)(int x1, int x2, int y, int color); - void (*gint_dvline)(int y1, int y2, int x, int color); - /* Text and image rendering */ - void (*dtext_opt) - (int x, int y, int fg, int bg, int halign, int valign, - char const *str, int size); - void (*dsubimage) - (bopti_image_t const *image, struct rbox *r, int flags); -}; - -/* The alternate rendering mode pointer (initially NULL)*/ -extern struct rendering_mode const *dmode; +struct rbox; /* These are the corresponding gray rendering functions */ int gupdate(void); @@ -95,10 +67,4 @@ void gtext_opt(int x, int y, int fg, int bg, int halign, int valign, char const *str, int size); void gsubimage(bopti_image_t const *image, struct rbox *r, int flags); -/* Short macro to call the alternate rendering function when available */ -#define DMODE_OVERRIDE(func, ...) \ - if(dmode && dmode->func) { \ - return dmode->func(__VA_ARGS__); \ - } - #endif /* RENDER_FX */ diff --git a/src/render/dline.c b/src/render/dline.c index 098fd76..0a1a98f 100644 --- a/src/render/dline.c +++ b/src/render/dline.c @@ -2,9 +2,6 @@ #include #include "../render/render.h" -#ifdef FX9860G -#include "../render-fx/render-fx.h" -#endif /* dline(): Bresenham line drawing algorithm Remotely adapted from MonochromeLib code by Pierre "PerriotLL" Le Gall. @@ -18,19 +15,13 @@ void dline(int x1, int y1, int x2, int y2, int color) /* Possible optimizations */ if(y1 == y2) { - #ifdef FX9860G DMODE_OVERRIDE(gint_dhline, x1, x2, y1, color); - #endif - gint_dhline(x1, x2, y1, color); return; } if(x1 == x2) { - #ifdef FX9860G DMODE_OVERRIDE(gint_dvline, y1, y2, x1, color); - #endif - gint_dvline(y1, y2, x1, color); return; } diff --git a/src/render/render.h b/src/render/render.h index fcac146..888e439 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -5,6 +5,7 @@ #ifndef RENDER_COMMON #define RENDER_COMMON +#include #include /* gint_dhline(): Optimized horizontal line @@ -26,4 +27,51 @@ extern font_t const *topti_font; /* Default font */ extern font_t const *gint_default_font; +//--- +// Alternate rendering modes +//--- + +#if GINT_RENDER_DMODE + +/* The gray engine overrides the rendering functions by specifying a set of + alternate primitives that are suited to work with two VRAMs. To avoid + linking with them when the gray engine is not used, the display module + exposes a global state in the form of a struct rendering_mode and the gray + engine modifies that state when it runs. */ +struct rbox; +struct rendering_mode +{ + /* Because the gray engine still has business to do after the call to + dgray(DGRAY_OFF), the original dupdate() is made to execute after + the replacement one if the replacement one returns 1. */ + int (*dupdate)(void); + /* Area rendering */ + void (*dclear)(color_t color); + void (*drect)(int x1, int y1, int x2, int y2, color_t color); + /* Point rendering */ + void (*dpixel)(int x, int y, color_t color); + int (*dgetpixel)(int x, int y); + void (*gint_dhline)(int x1, int x2, int y, int color); + void (*gint_dvline)(int y1, int y2, int x, int color); + /* Text and image rendering */ + void (*dtext_opt) + (int x, int y, int fg, int bg, int halign, int valign, + char const *str, int size); + void (*dsubimage) + (bopti_image_t const *image, struct rbox *r, int flags); +}; + +/* The alternate rendering mode pointer (initially NULL)*/ +extern struct rendering_mode const *dmode; + +/* Short macro to call the alternate rendering function when available */ +#define DMODE_OVERRIDE(func, ...) \ + if(dmode && dmode->func) { \ + return dmode->func(__VA_ARGS__); \ + } + +#else +#define DMODE_OVERRIDE(func, ...) +#endif /* GINT_RENDER_DMODE */ + #endif /* RENDER_COMMON */