From 7886a60ef29cbeafffebf9867a0499e1b1330edd Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 20 Aug 2025 21:56:42 -0500 Subject: [PATCH] add framebuffer, framebuffer_shaded, vo_border_col --- framebuffer.c | 36 ++++++++++++++++++++++++++++++++++++ framebuffer_shaded.c | 39 +++++++++++++++++++++++++++++++++++++++ vo_border_col.c | 18 ++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 framebuffer.c create mode 100644 framebuffer_shaded.c create mode 100644 vo_border_col.c diff --git a/framebuffer.c b/framebuffer.c new file mode 100644 index 0000000..f9aabc0 --- /dev/null +++ b/framebuffer.c @@ -0,0 +1,36 @@ +#include + +void main() +{ + volatile uint32_t * texture_memory32 = (volatile uint32_t *)(0x05000000 | 0xA0000000); + + int blue = 0x0000ff; + for (int i = 0; i < 640 * 480; i++) { + texture_memory32[i] = blue; + } + + volatile uint32_t * FB_R_CTRL = (volatile uint32_t*)(0x005F8044 | 0xA0000000); + + int vclk_div = 1; + int fb_depth = 0x3; // 0888 RGB 32 bit + int fb_enable = 1; + *FB_R_CTRL + = (vclk_div << 23) + | (fb_depth << 2 ) + | (fb_enable << 0 ); + + volatile uint32_t * FB_R_SOF1 = (volatile uint32_t*)(0x005F8050 | 0xA0000000); + // the framebuffer is at the start of texture memory (texture memory address 0) + *FB_R_SOF1 = 0; + + volatile uint32_t * FB_R_SIZE = (volatile uint32_t*)(0x005F805C | 0xA0000000); + + int fb_modulus = 1; + int fb_y_size = 480 - 1; + int bytes_per_pixel = 4; + int fb_x_size = ((640 * bytes_per_pixel) / 4) - 1; + *FB_R_SIZE + = (fb_modulus << 20) + | (fb_y_size << 10) + | (fb_x_size << 0 ); +} diff --git a/framebuffer_shaded.c b/framebuffer_shaded.c new file mode 100644 index 0000000..29c02fc --- /dev/null +++ b/framebuffer_shaded.c @@ -0,0 +1,39 @@ +#include + +void main() +{ + volatile uint32_t * texture_memory32 = (volatile uint32_t *)(0x05000000 | 0xA0000000); + + for (int y = 0; y < 480; y++) { + for (int x = 0; x < 640; x++) { + int red = (y % 255); + int blue = (x % 255); + + texture_memory32[y * 640 + x] = (red << 16) | (blue << 0); + } + } + + volatile uint32_t * FB_R_CTRL = (volatile uint32_t*)(0x005F8044 | 0xA0000000); + int vclk_div = 1; + int fb_depth = 0x3; // 0888 RGB 32 bit + int fb_enable = 1; + *FB_R_CTRL + = (vclk_div << 23) + | (fb_depth << 2 ) + | (fb_enable << 0 ); + + volatile uint32_t * FB_R_SOF1 = (volatile uint32_t*)(0x005F8050 | 0xA0000000); + // the framebuffer is at the start of texture memory (texture memory address 0) + *FB_R_SOF1 = 0; + + volatile uint32_t * FB_R_SIZE = (volatile uint32_t*)(0x005F805C | 0xA0000000); + + int fb_modulus = 1; + int fb_y_size = 480 - 1; + int bytes_per_pixel = 4; + int fb_x_size = ((640 * bytes_per_pixel) / 4) - 1; + *FB_R_SIZE + = (fb_modulus << 20) + | (fb_y_size << 10) + | (fb_x_size << 0 ); +} diff --git a/vo_border_col.c b/vo_border_col.c new file mode 100644 index 0000000..2c2c293 --- /dev/null +++ b/vo_border_col.c @@ -0,0 +1,18 @@ +#include + +typedef volatile uint32_t reg32; + +void main() +{ + reg32 * VO_BORDER_COL = (reg32 *)(0x005F8040 | 0xA0000000); + reg32 * FB_R_CTRL = (reg32 *)(0x005F8044 | 0xA0000000); + + int vclk_div = 1; + int fb_enable = 0; + *FB_R_CTRL + = (vclk_div << 23) + | (fb_enable << 0); + + int green = 0x00ff00; + *VO_BORDER_COL = green; +}