gray, r61524: gray engine for r61524

gray/engine.c looks terrible by now and it will have to be cleaned up in
the future, with the whole video modes abstraction.
This commit is contained in:
Lephe 2024-03-24 08:53:12 +01:00
parent 3a42b5d386
commit 946d4d9a6f
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
3 changed files with 60 additions and 9 deletions

View file

@ -55,6 +55,12 @@ void r61524_display_rect(uint16_t *vram, int xmin, int xmax, int ymin,
TODO: Make that a video mode. */ TODO: Make that a video mode. */
void r61524_display_mono_128x64(uint32_t *vram); void r61524_display_mono_128x64(uint32_t *vram);
/* r61524_display_mono_128x64(): Display a gray-style VRAM
This experimental function updates the display with the contents of a 128x64
gray VRAM pair, used with the fxg3a compilation target.
TODO: Make that a video mode. */
void r61524_display_gray_128x64(uint32_t *light, uint32_t *dark);
/* r61524_start_frame(): Prepare the display for a region update /* r61524_start_frame(): Prepare the display for a region update
This function sets up the display driver to receive graphics data to update This function sets up the display driver to receive graphics data to update

View file

@ -14,8 +14,12 @@
#include "../render/render.h" #include "../render/render.h"
#include <gint/config.h> #include <gint/config.h>
// TODO: Move the gray "engine" into the T6K11 driver. #if GINT_HW_CG
#if GINT_RENDER_MONO && GINT_HW_FX #include <gint/drivers/r61524.h>
#endif
// TODO: Move the gray "engine" part into the T6K11 driver.
#if GINT_RENDER_MONO
/* Three additional video RAMS, allocated statically if --static-gray was set /* Three additional video RAMS, allocated statically if --static-gray was set
at configure time, or with malloc() otherwise. */ at configure time, or with malloc() otherwise. */
@ -26,6 +30,8 @@ GBSS static uint32_t gvrams[3][256];
/* Four VRAMs: two to draw and two to display */ /* Four VRAMs: two to draw and two to display */
static uint32_t *vrams[4] = { NULL, NULL, NULL, NULL }; static uint32_t *vrams[4] = { NULL, NULL, NULL, NULL };
#if GINT_HW_FX
/* Current VRAM pair used for drawing; the value can either be 0 (draws to /* Current VRAM pair used for drawing; the value can either be 0 (draws to
VRAMs 0 and 1) or 2 (draws to VRAMs 2 and 3). */ VRAMs 0 and 1) or 2 (draws to VRAMs 2 and 3). */
static int volatile st = 0; static int volatile st = 0;
@ -40,6 +46,10 @@ static int runs = 0;
/* Delays of the light and dark frames for the above setting */ /* Delays of the light and dark frames for the above setting */
GBSS static int delays[2]; GBSS static int delays[2];
static int gray_int(void);
#endif
/* The alternate rendering mode structure used to override d*() */ /* The alternate rendering mode structure used to override d*() */
static struct rendering_mode const gray_mode = { static struct rendering_mode const gray_mode = {
.dupdate = gupdate, .dupdate = gupdate,
@ -68,13 +78,16 @@ static struct rendering_mode const gray_exit_mode = {
// Engine control (init/quit and start/stop) // Engine control (init/quit and start/stop)
//--- //---
static int gray_int(void);
static void gray_quit(void); static void gray_quit(void);
/* gray_isinit(): Check whether the engine is initialized and ready to run */ /* gray_isinit(): Check whether the engine is initialized and ready to run */
static int gray_isinit(void) static int gray_isinit(void)
{ {
return (vrams[0] && vrams[1] && vrams[2] && vrams[3] && timer >= 0); return (vrams[0] && vrams[1] && vrams[2] && vrams[3]
#if GINT_HW_FX
&& timer >= 0
#endif
);
} }
/* gray_init(): Initialize the engine /* gray_init(): Initialize the engine
@ -95,6 +108,7 @@ GCONSTRUCTOR static void gray_init(void)
vrams[3] = malloc(1024); vrams[3] = malloc(1024);
#endif /* GINT_STATIC_GRAY */ #endif /* GINT_STATIC_GRAY */
#if GINT_HW_FX
/* Default delays from Graph 35+E II are different from other models */ /* Default delays from Graph 35+E II are different from other models */
if(gint[HWCALC] == HWCALC_G35PE2) if(gint[HWCALC] == HWCALC_G35PE2)
{ {
@ -110,6 +124,7 @@ GCONSTRUCTOR static void gray_init(void)
/* Try to obtain the timer right away */ /* Try to obtain the timer right away */
timer = timer_configure(GRAY_TIMER | GRAY_CLOCK, 1000, timer = timer_configure(GRAY_TIMER | GRAY_CLOCK, 1000,
GINT_CALL(gray_int)); GINT_CALL(gray_int));
#endif
/* On failure, release the resources that we obtained */ /* On failure, release the resources that we obtained */
if(!gray_isinit()) gray_quit(); if(!gray_isinit()) gray_quit();
@ -128,10 +143,13 @@ GDESTRUCTOR static void gray_quit(void)
vrams[3] = NULL; vrams[3] = NULL;
#endif /* GINT_STATIC_GRAY */ #endif /* GINT_STATIC_GRAY */
#if GINT_HW_FX
if(timer >= 0) timer_stop(timer); if(timer >= 0) timer_stop(timer);
timer = -1; timer = -1;
#endif
} }
#if GINT_HW_FX
/* gray_start(): Start the gray engine */ /* gray_start(): Start the gray engine */
static void gray_start(void) static void gray_start(void)
{ {
@ -148,6 +166,7 @@ static void gray_stop(void)
runs = 0; runs = 0;
st = 0; st = 0;
} }
#endif
//--- //---
// Dynamic udpate and rendering mode // Dynamic udpate and rendering mode
@ -201,6 +220,7 @@ int dgray(int mode)
return 0; return 0;
} }
#if GINT_HW_FX
/* gray_int(): Interrupt handler */ /* gray_int(): Interrupt handler */
int gray_int(void) int gray_int(void)
{ {
@ -232,6 +252,19 @@ int gupdate(void)
st ^= 2; st ^= 2;
return 0; return 0;
} }
#elif GINT_HW_CG
int gupdate(void)
{
if(dmode == &gray_exit_mode)
{
dmode = NULL;
return 1;
}
r61524_display_gray_128x64(vrams[0], vrams[1]);
return 0;
}
#endif
//--- //---
// Query and configuration functions // Query and configuration functions
@ -243,6 +276,7 @@ int dgray_enabled(void)
return (dmode == &gray_mode); return (dmode == &gray_mode);
} }
#if GINT_HW_FX
/* dgray_setdelays(): Set the gray engine delays */ /* dgray_setdelays(): Set the gray engine delays */
void dgray_setdelays(uint32_t light, uint32_t dark) void dgray_setdelays(uint32_t light, uint32_t dark)
{ {
@ -274,5 +308,12 @@ void dgray_getscreen(uint32_t **light, uint32_t **dark)
if(light) *light = vrams[base & 2]; if(light) *light = vrams[base & 2];
if(dark) *dark = vrams[base | 1]; if(dark) *dark = vrams[base | 1];
} }
#elif GINT_HW_CG
void dgray_getvram(uint32_t **light, uint32_t **dark)
{
*light = vrams[0];
*dark = vrams[1];
}
#endif
#endif /* GINT_RENDER_MONO && GINT_HW_FX */ #endif /* GINT_RENDER_MONO && GINT_HW_FX */

View file

@ -238,12 +238,13 @@ void r61524_display_mono_128x64(uint32_t *vram)
write(border); write(border);
} }
void r61524_display_gray_128x64(uint32_t *vram) void r61524_display_gray_128x64(uint32_t *light, uint32_t *dark)
{ {
dma_transfer_wait(0); dma_transfer_wait(0);
r61524_start_frame(0, 395, 0, 223); r61524_start_frame(0, 395, 0, 223);
int border = 0xe71c; /* C_RGB(28, 28, 28) */ int border = 0xe71c; /* C_RGB(28, 28, 28) */
int colors[] = { 0x0000, 0x528a, 0xad55, 0xffff };
for(int i = 0; i < 16 * 396; i++) for(int i = 0; i < 16 * 396; i++)
write(border); write(border);
@ -256,11 +257,13 @@ void r61524_display_gray_128x64(uint32_t *vram)
/* longword-x position */ /* longword-x position */
for(int lwx = 0; lwx < 4; lwx++) { for(int lwx = 0; lwx < 4; lwx++) {
int32_t i = vram[lwx]; int32_t il = light[lwx];
int32_t id = dark[lwx];
/* sub-x position */ /* sub-x position */
for(int sx = 0; sx < 32; sx++) { for(int sx = 0; sx < 32; sx++) {
int color = ~(i >> 31); int color = colors[(id >= 0) * 2 + (il >= 0)];
i <<= 1; il <<= 1;
id <<= 1;
write(color); write(color);
write(color); write(color);
write(color); write(color);
@ -270,7 +273,8 @@ void r61524_display_gray_128x64(uint32_t *vram)
for(int i = 0; i < 6; i++) for(int i = 0; i < 6; i++)
write(border); write(border);
} }
vram += 4; light += 4;
dark += 4;
} }
for(int i = 0; i < 16 * 396; i++) for(int i = 0; i < 16 * 396; i++)