From: falcovorbis <fal...@us...> - 2024-10-09 23:51:08
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 5170f0311e07c888631138720cf1ee2673166586 (commit) from 4dd3433c258cb1e7bf3de599c50c49ad5181e851 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5170f0311e07c888631138720cf1ee2673166586 Author: Andy Barajas <and...@gm...> Date: Wed Oct 9 16:50:38 2024 -0700 Add pvr palette related examples (#802) ----------------------------------------------------------------------- Summary of changes: doc/CHANGELOG.md | 2 + examples/dreamcast/pvr/palette/4bpp/4bpp.c | 181 +++++++++++++++++++ .../{filesystem/pty => pvr/palette/4bpp}/Makefile | 10 +- examples/dreamcast/pvr/palette/8bpp/8bpp.c | 173 ++++++++++++++++++ .../{filesystem/pty => pvr/palette/8bpp}/Makefile | 10 +- .../pty => pvr/palette/wormhole}/Makefile | 9 +- examples/dreamcast/pvr/palette/wormhole/wormhole.c | 198 +++++++++++++++++++++ examples/dreamcast/readme.md | 1 + 8 files changed, 569 insertions(+), 15 deletions(-) create mode 100644 examples/dreamcast/pvr/palette/4bpp/4bpp.c copy examples/dreamcast/{filesystem/pty => pvr/palette/4bpp}/Makefile (76%) create mode 100644 examples/dreamcast/pvr/palette/8bpp/8bpp.c copy examples/dreamcast/{filesystem/pty => pvr/palette/8bpp}/Makefile (76%) copy examples/dreamcast/{filesystem/pty => pvr/palette/wormhole}/Makefile (81%) create mode 100644 examples/dreamcast/pvr/palette/wormhole/wormhole.c diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index f987f66f..736668db 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -9,6 +9,8 @@ Platform-specific changes are prefixed with the platform name, otherwise the cha - Enabled hybrid PVR DR/DMA vertex submission in driver + sped up pvr_prim() [FG] - Add thread priority boosting system [Paul Cercueil = PC] - Add performance monitor API [PC] +- Add/Fixed stat() implementations for all filesystems [AB] +- **Dreamcast**: Add network speedtest and pvr palette examples [AB] ## KallistiOS version 2.1.0 - Cleaned up generated stubs files on a make clean [Lawrence Sebald == LS] diff --git a/examples/dreamcast/pvr/palette/4bpp/4bpp.c b/examples/dreamcast/pvr/palette/4bpp/4bpp.c new file mode 100644 index 00000000..04cebaf0 --- /dev/null +++ b/examples/dreamcast/pvr/palette/4bpp/4bpp.c @@ -0,0 +1,181 @@ +/* KallistiOS ##version## + + 4bpp.c + Copyright (C) 2024 Andress Barajas +*/ + +/* + 4bpp example that is a variation of the 8bpp example written by + Tvspelsfreak. + + This demo showcases the use of 4-bit palette-based textures on the Dreamcast. + The demo generates a radial gradient texture in RAM and uploads it to VRAM. + Since the texture uses 4bpp (16 colors), the palette consists of 16 entries, + and the texture is rendered as a static image. The colors in the palette are + continuously cycled through a smooth transition effect, creating an animated + appearance for the static gradient. + + The palette animation is driven by a sine wave function that modulates the + red, green, and blue color channels based on the frame number. The player can + press the START button to exit the demo. +*/ + +#include <stdlib.h> +#include <math.h> + +#include <dc/pvr.h> +#include <dc/maple.h> +#include <dc/fmath.h> +#include <dc/maple/controller.h> + +#define TEXTURE_WIDTH 256 +#define TEXTURE_HEIGHT 256 +#define PALETTE_ENTRY_COUNT 16 + +static pvr_poly_hdr_t hdr; + +static void draw_screen(void) { + pvr_vertex_t vert; + + pvr_prim(&hdr, sizeof(hdr)); + + vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f); + vert.oargb = 0; + vert.flags = PVR_CMD_VERTEX; + + vert.x = 0.0f; + vert.y = 0.0f; + vert.z = 1.0f; + vert.u = 0.0f; + vert.v = 0.0f; + pvr_prim(&vert, sizeof(vert)); + + vert.x = 640.0f; + vert.y = 0.0f; + vert.z = 1.0f; + vert.u = 1.0f; + vert.v = 0.0f; + pvr_prim(&vert, sizeof(vert)); + + vert.x = 0.0f; + vert.y = 480.0f; + vert.z = 1.0f; + vert.u = 0.0f; + vert.v = 1.0f; + pvr_prim(&vert, sizeof(vert)); + + vert.x = 640.0f; + vert.y = 480.0f; + vert.z = 1.0f; + vert.u = 1.0f; + vert.v = 1.0f; + vert.flags = PVR_CMD_VERTEX_EOL; + pvr_prim(&vert, sizeof(vert)); +} + +static float distance(float x0, float y0, float x1, float y1) { + const float dx = x1 - x0; + const float dy = y1 - y0; + + return fsqrt(dx * dx + dy * dy); +} + +static pvr_ptr_t generate_texture(uint32_t width, uint32_t height) { + int i, j, mid_x, mid_y; + float max_dist; + + uint8_t *texbuf; + pvr_ptr_t texptr; + + /* Calculate texture midpoint and greatest distance from the + midpoint to another point for future usage */ + + mid_x = width / 2; + mid_y = height / 2; + max_dist = distance(0, 0, mid_x, mid_y); + + /* Allocate temp storage in RAM to generate texture in */ + texbuf = calloc(width * height / 2, sizeof(uint8_t)); + + /* Generate the texture */ + for(i = 0; i < height; i++) + for(j = 0; j < width; j++) { + uint8_t color = (fsin((distance(j, i, mid_x, mid_y) / max_dist) * F_PI) * 16.0f); + if (j % 2 == 0) + /* Store in high nibble for even pixels */ + texbuf[i * (width / 2) + (j / 2)] = color << 4; + else + /* Store in low nibble for odd pixels */ + texbuf[i * (width / 2) + (j / 2)] |= color; + } + + /* Allocate VRAM for the texture and upload it, twiddling it in the process */ + texptr = pvr_mem_malloc(width * height / 2); + pvr_txr_load_ex(texbuf, texptr, width, height, PVR_TXRLOAD_4BPP); + + /* As the texture is now residing in VRAM, we can free the temp storage + and return the VRAM pointer */ + free(texbuf); + + return texptr; +} + +static void animate_palette(uint32_t frame) { + uint32_t i, val; + + for(i = 0; i < PALETTE_ENTRY_COUNT; i++) { + /* Palette cycling, with a larger step between colors */ + val = (frame + i * 16) & 0xFF; + pvr_set_pal_entry(i, 0xFF00003F | (val << 16) | (val / 2 << 8)); + } +} + +static int check_start(void) { + MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st) + + if(st->buttons & CONT_START) + return 1; + + MAPLE_FOREACH_END() + return 0; +} + +int main(int argc, char** argv) { + uint32_t frame; + pvr_ptr_t texptr; + pvr_poly_cxt_t cxt; + + pvr_init_defaults(); + + /* First select a palette format */ + pvr_set_pal_format(PVR_PAL_ARGB8888); + + /* Initialize the texture */ + texptr = generate_texture(TEXTURE_WIDTH, TEXTURE_HEIGHT); + + /* Setup PVR context */ + pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_PAL4BPP | + PVR_TXRFMT_4BPP_PAL(0), TEXTURE_WIDTH, TEXTURE_HEIGHT, + texptr, PVR_FILTER_BILINEAR); + pvr_poly_compile(&hdr, &cxt); + + frame = 0; + while(!check_start()) { + frame = (frame + 1) % 256; + animate_palette(frame); + + pvr_wait_ready(); + pvr_scene_begin(); + + pvr_list_begin(PVR_LIST_OP_POLY); + + draw_screen(); + + pvr_list_finish(); + pvr_scene_finish(); + } + + pvr_mem_free(texptr); + + return 0; +} diff --git a/examples/dreamcast/filesystem/pty/Makefile b/examples/dreamcast/pvr/palette/4bpp/Makefile similarity index 76% copy from examples/dreamcast/filesystem/pty/Makefile copy to examples/dreamcast/pvr/palette/4bpp/Makefile index 4b6182d5..7cf22c02 100644 --- a/examples/dreamcast/filesystem/pty/Makefile +++ b/examples/dreamcast/pvr/palette/4bpp/Makefile @@ -1,12 +1,11 @@ # -# fs_pty test program -# +# PVR Palette 4bpp example +# Copyright (C) 2011 Tvspelsfreak # Copyright (C) 2024 Andress Barajas # -TARGET = pty.elf - -OBJS = pty.o +TARGET = 4bpp.elf +OBJS = 4bpp.o all: rm-elf $(TARGET) @@ -27,3 +26,4 @@ run: $(TARGET) dist: $(TARGET) -rm -f $(OBJS) $(KOS_STRIP) $(TARGET) + diff --git a/examples/dreamcast/pvr/palette/8bpp/8bpp.c b/examples/dreamcast/pvr/palette/8bpp/8bpp.c new file mode 100644 index 00000000..4adb4489 --- /dev/null +++ b/examples/dreamcast/pvr/palette/8bpp/8bpp.c @@ -0,0 +1,173 @@ +/* KallistiOS ##version## + + 8bpp.c + Copyright (C) 2011 Tvspelsfreak + Copyright (C) 2024 Andress Barajas +*/ + +/* + 8bpp example written by Tvspelsfreak + + This demo showcases a simple use of 8-bit palette-based textures on the + Dreamcast. The demo generates a radial gradient texture in RAM and uploads + it to VRAM. The gradient texture is rendered as a static image, but the colors + in the palette are continuously cycled through a smooth transition effect, + making the gradient appear to animate over time. + + The palette animation is driven by a simple sine wave, with the red, green, + and blue channels modulating based on the frame number. The player can press + the START button to exit the demo. +*/ + +#include <stdlib.h> +#include <math.h> + +#include <dc/pvr.h> +#include <dc/maple.h> +#include <dc/fmath.h> +#include <dc/maple/controller.h> + +#define TEXTURE_WIDTH 256 +#define TEXTURE_HEIGHT 256 +#define PALETTE_ENTRY_COUNT 256 + +static pvr_poly_hdr_t hdr; + +static void draw_screen(void) { + pvr_vertex_t vert; + + pvr_prim(&hdr, sizeof(hdr)); + + vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f); + vert.oargb = 0; + vert.flags = PVR_CMD_VERTEX; + + vert.x = 0.0f; + vert.y = 0.0f; + vert.z = 1.0f; + vert.u = 0.0f; + vert.v = 0.0f; + pvr_prim(&vert, sizeof(vert)); + + vert.x = 640.0f; + vert.y = 0.0f; + vert.z = 1.0f; + vert.u = 1.0f; + vert.v = 0.0f; + pvr_prim(&vert, sizeof(vert)); + + vert.x = 0.0f; + vert.y = 480.0f; + vert.z = 1.0f; + vert.u = 0.0f; + vert.v = 1.0f; + pvr_prim(&vert, sizeof(vert)); + + vert.x = 640.0f; + vert.y = 480.0f; + vert.z = 1.0f; + vert.u = 1.0f; + vert.v = 1.0f; + vert.flags = PVR_CMD_VERTEX_EOL; + pvr_prim(&vert, sizeof(vert)); +} + +static float distance(float x0, float y0, float x1, float y1) { + const float dx = x1 - x0; + const float dy = y1 - y0; + + return fsqrt(dx * dx + dy * dy); +} + +static pvr_ptr_t generate_texture(uint32_t width, uint32_t height) { + int i, j, mid_x, mid_y; + float max_dist; + + uint8_t *texbuf; + pvr_ptr_t texptr; + + /* Calculate texture midpoint and greatest distance from the + midpoint to another point for future usage */ + + mid_x = width / 2; + mid_y = height / 2; + max_dist = distance(0, 0, mid_x, mid_y); + + /* Allocate temp storage in RAM to generate texture in */ + texbuf = calloc(width * height, sizeof(uint8_t)); + + /* Generate the texture */ + for(i = 0; i < height; i++) + for(j = 0; j < width; j++) + texbuf[i * width + j] = fsin((distance(j, i, mid_x, mid_y) / max_dist) * F_PI) * 256.0f; + + /* Allocate VRAM for the texture and upload it, twiddling it in the process */ + texptr = pvr_mem_malloc(width * height); + pvr_txr_load_ex(texbuf, texptr, width, height, PVR_TXRLOAD_8BPP); + + /* As the texture is now residing in VRAM, we can free the temp storage + and return the VRAM pointer */ + free(texbuf); + + return texptr; +} + +static void animate_palette(uint32_t frame) { + uint32_t i, val; + + for(i = 0;i < PALETTE_ENTRY_COUNT; i++) { + val = (frame + i) & 0xFF; + pvr_set_pal_entry(i, 0xFF00003F | ( val << 16 ) | ( val/2 << 8 )); + } +} + +static int check_start(void) { + MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st) + + if(st->buttons & CONT_START) + return 1; + + MAPLE_FOREACH_END() + return 0; +} + +int main(int argc, char** argv) { + uint32_t frame; + pvr_ptr_t texptr; + pvr_poly_cxt_t cxt; + + pvr_init_defaults(); + + /* First select a palette format */ + pvr_set_pal_format(PVR_PAL_ARGB8888); + + /* Initialize the texture */ + texptr = generate_texture(TEXTURE_WIDTH, TEXTURE_HEIGHT); + + /* Setup PVR context */ + pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_PAL8BPP | + PVR_TXRFMT_8BPP_PAL(0), TEXTURE_WIDTH, TEXTURE_HEIGHT, + texptr, PVR_FILTER_BILINEAR); + pvr_poly_compile(&hdr, &cxt); + + frame = 0; + while(!check_start()) { + frame = (frame + 1) % 256; + + animate_palette(frame); + + pvr_wait_ready(); + pvr_scene_begin(); + + pvr_list_begin(PVR_LIST_OP_POLY); + + draw_screen(); + + pvr_list_finish(); + pvr_scene_finish(); + } + + pvr_mem_free(texptr); + + return 0; +} diff --git a/examples/dreamcast/filesystem/pty/Makefile b/examples/dreamcast/pvr/palette/8bpp/Makefile similarity index 76% copy from examples/dreamcast/filesystem/pty/Makefile copy to examples/dreamcast/pvr/palette/8bpp/Makefile index 4b6182d5..62b1b554 100644 --- a/examples/dreamcast/filesystem/pty/Makefile +++ b/examples/dreamcast/pvr/palette/8bpp/Makefile @@ -1,12 +1,11 @@ # -# fs_pty test program -# +# PVR Palette 8bpp example +# Copyright (C) 2011 Tvspelsfreak # Copyright (C) 2024 Andress Barajas # -TARGET = pty.elf - -OBJS = pty.o +TARGET = 8bpp.elf +OBJS = 8bpp.o all: rm-elf $(TARGET) @@ -27,3 +26,4 @@ run: $(TARGET) dist: $(TARGET) -rm -f $(OBJS) $(KOS_STRIP) $(TARGET) + diff --git a/examples/dreamcast/filesystem/pty/Makefile b/examples/dreamcast/pvr/palette/wormhole/Makefile similarity index 81% copy from examples/dreamcast/filesystem/pty/Makefile copy to examples/dreamcast/pvr/palette/wormhole/Makefile index 4b6182d5..03765f07 100644 --- a/examples/dreamcast/filesystem/pty/Makefile +++ b/examples/dreamcast/pvr/palette/wormhole/Makefile @@ -1,12 +1,10 @@ # -# fs_pty test program -# +# PVR Palette wormhole example # Copyright (C) 2024 Andress Barajas # -TARGET = pty.elf - -OBJS = pty.o +TARGET = wormhole.elf +OBJS = wormhole.o all: rm-elf $(TARGET) @@ -27,3 +25,4 @@ run: $(TARGET) dist: $(TARGET) -rm -f $(OBJS) $(KOS_STRIP) $(TARGET) + diff --git a/examples/dreamcast/pvr/palette/wormhole/wormhole.c b/examples/dreamcast/pvr/palette/wormhole/wormhole.c new file mode 100644 index 00000000..e8be75f6 --- /dev/null +++ b/examples/dreamcast/pvr/palette/wormhole/wormhole.c @@ -0,0 +1,198 @@ +/* KallistiOS ##version## + + wormhole.c + Copyright (C) 2024 Andress Barajas +*/ + +/* + This demo demonstrates the use of 8-bit palette-based textures to generate + and animate a wormhole effect on the Dreamcast. The pallete texture is created + programmatically in RAM, simulating a wormhole with radial distortion based + on distance and angle from the center, and then uploaded to VRAM for rendering. + + The wormhole texture consists of grayscale colors ranging from white to dark + gray, while the background remains black. The colors in the wormhole are + continuously cycled in the palette, creating the appearance of a swirling + motion. The palette cycling is handled using a simple offset mechanism, + where the wormholeâs color indices shift over time based on the current frame. + + This effect demonstrates how to use 8-bit textures with dynamic palette + animation, giving the appearance of a smoothly animated wormhole. The player + can press the START button on the controller to exit the demo. +*/ + +#include <stdlib.h> +#include <math.h> ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |