render: parametrize existence of dmode in config.h

This is the first of many steps designed to reduce gint's reliance on
the FX9860G and FXCG50 macros by describing the compile target more
symbolically. The goal is to allow both for g3a compilation of fx-API
code and for a potential CP port.
This commit is contained in:
Lephe 2024-03-19 18:36:59 +01:00
parent e0ac25fbb0
commit bc74586a2c
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
11 changed files with 75 additions and 49 deletions

View File

@ -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 */

View File

@ -11,6 +11,7 @@
#include <stdlib.h>
#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. */

View File

@ -1,5 +1,5 @@
#include <gint/display.h>
#include "render-fx.h"
#include "../render/render.h"
/* dclear() - fill the screen with a single color */
void dclear(color_t color)

View File

@ -1,6 +1,6 @@
#include <gint/display.h>
#include <gint/defs/types.h>
#include "render-fx.h"
#include "../render/render.h"
int dgetpixel(int x, int y)
{

View File

@ -1,6 +1,6 @@
#include <gint/display.h>
#include <gint/defs/types.h>
#include "render-fx.h"
#include "../render/render.h"
/* dpixel() - change a pixel's color */
void dpixel(int x, int y, int color)

View File

@ -1,5 +1,6 @@
#include <gint/defs/util.h>
#include <gint/display.h>
#include "../render/render.h"
#include "render-fx.h"
void drect(int x1, int y1, int x2, int y2, int color)

View File

@ -1,4 +1,5 @@
#include <gint/display.h>
#include "../render/render.h"
#include "render-fx.h"
#include "bopti-asm.h"

View File

@ -1,6 +1,6 @@
#include <gint/display.h>
#include <gint/drivers/t6k11.h>
#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];

View File

@ -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 */

View File

@ -2,9 +2,6 @@
#include <gint/defs/util.h>
#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;
}

View File

@ -5,6 +5,7 @@
#ifndef RENDER_COMMON
#define RENDER_COMMON
#include <gint/config.h>
#include <gint/display.h>
/* 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 */