vxKernel/src/drivers/screen/R61524/r61524.c

173 lines
3.8 KiB
C

#include <vhex/defs/types.h>
#include <vhex/driver.h>
#include <vhex/driver/screen/r61524.h>
#include <vhex/display/stack.h>
//---
// R61524 driver API
//---
/* r61524_clear_surface() - optimal way to clear the draw and render surface */
VINLINE void r61524_clear_surface(struct dshader_surface *surface)
{
//TODO: check cache behaviour:
// > full xram then yram
// > xram and yram
// > yram and xram
// > restrict / non-restrict
uint32_t * restrict xram = surface->draw;
uint32_t * restrict yram = surface->frag;
for (int i = 0; i < 1980; ++i) {
xram[i] = 0x00010001;
yram[i] = 0x00000000;
}
}
/* r61524_frame_start() - prepar the screen and reset surfaces */
int r61524_frame_start(struct dshader_surface *surface)
{
/* Set the windows size */
r61524_select(horizontal_ram_start);
r61524_write(0);
r61524_select(horizontal_ram_end);
r61524_write(395);
r61524_select(vertical_ram_start);
r61524_write(0);
r61524_select(vertical_ram_end);
r61524_write(223);
/* Set the RAM position */
r61524_select(ram_address_horizontal);
r61524_write(0);
r61524_select(ram_address_vertical);
r61524_write(0);
/* Bind address 0xb4000000 to the data write command */
r61524_select(write_data);
/* initialize surface information */
surface->draw = (void*)0xe5007000;
surface->frag = (void*)0xe5017000;
surface->width = 396;
surface->height = 10;
surface->x = 0;
surface->y = 0;
/* reset the two surfaces */
r61524_clear_surface(surface);
return (0);
}
int r61524_frame_frag_next(struct dshader_surface *surface)
{
//TODO: perf if culling at the end (220)
surface->y += 10;
if (surface->y >= 224) {
surface->y -= 10;
return (-1);
}
r61524_clear_surface(surface);
return (0);
}
int r61524_frame_frag_send(struct dshader_surface *surface)
{
//static int counter = 0;
//TODO: assembly
//TODO: check cache behaviour:
// > full xram then yram
// > xram and yram
// > yram and xram
// > restrict / non-restrict
uint16_t pixel;
uint16_t * restrict xram = surface->draw;
uint16_t * restrict yram = surface->frag;
for (int i = 0; i < 3960; ++i) {
pixel = xram[i];
if (pixel & 0x0001) {
r61524_write(yram[i]);
continue;
}
r61524_write((pixel & 0xffc0) | ((pixel & 0x003e) >> 1));
}
return (0);
}
int r61524_frame_end(struct dshader_surface *surface)
{
(void)surface;
return (0);
}
//---
// Driver definition
//---
/* R61524 display (graphics RAM range) */
struct r61524_ctx {
uint16_t HSA;
uint16_t HEA;
uint16_t VSA;
uint16_t VEA;
};
static void __r61524_configure(struct r61524_ctx *s)
{
s->HSA = 0;
s->HEA = 395;
s->VSA = 0;
s->VEA = 223;
}
static void __r61524_hsave(struct r61524_ctx *s)
{
r61524_select(horizontal_ram_start);
s->HSA = r61524_read();
r61524_select(horizontal_ram_end);
s->HEA = r61524_read();
r61524_select(vertical_ram_start);
s->VSA = r61524_read();
r61524_select(vertical_ram_end);
s->VEA = r61524_read();
}
static void __r61524_hrestore(struct r61524_ctx const *s)
{
r61524_select(horizontal_ram_start);
r61524_write(s->HSA);
r61524_select(horizontal_ram_end);
r61524_write(s->HEA);
r61524_select(vertical_ram_start);
r61524_write(s->VSA);
r61524_select(vertical_ram_end);
r61524_write(s->VEA);
}
static struct dstack_drv_interface drv_r61524_dstack = {
.frame_start = &r61524_frame_start,
.frame_frag_next = &r61524_frame_frag_next,
.frame_frag_send = &r61524_frame_frag_send,
.frame_end = &r61524_frame_end,
.display_width = 396,
.display_height = 224
};
struct vhex_driver drv_r61524 = {
.name = "R61524",
.hsave = (void*)&__r61524_hsave,
.hrestore = (void*)&__r61524_hrestore,
.configure = (void*)&__r61524_configure,
.state_size = sizeof(struct r61524_ctx),
.flags = {
.DISPLAY = 1,
.SHARED = 0,
.UNUSED = 0,
},
.module_data = &drv_r61524_dstack
};
VHEX_DECLARE_DRIVER(16, drv_r61524);