From: ljsebald <ljs...@us...> - 2024-01-29 01:05:13
|
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 e309ccb1c6363de8cbe8206a1ed7f307b27bef2d (commit) from b4f08e249a11a45bc25f7c824ce7f8d341ec37ea (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 e309ccb1c6363de8cbe8206a1ed7f307b27bef2d Author: Donald Haase <qu...@ya...> Date: Sun Jan 28 20:04:59 2024 -0500 Refactor Multibuffered video modes (#419) * Update video.c to remove the multibuffer duplication. * Add an example of multibuffer use. * Initialize the FB array generically * Updates to style, comments, changelog, authors, and color-generation for multibuffer * Translate all vid_mode values to be consistently in decimal. * Do away with explicit FBPOS values. Instead fill vram with as many framebuffers as possible. * Remove 800x600 * Clear merge conflict * Clarifying the setting of BITMAP_Y * If CT_VGA VID_INTERLACE is always cleared, so it's pointless here * Remove magic, group blanking functions * Clean up example and add it to the video folder makefile * Fix comment. * Correct video.h comment * Clean up example makefile * Add various convenience functions and update function documentation related to multibuffers. * Ensure fb_size is always set, remove magic, fix comments. * Restore border clearing and remove unused variable. * Cleaning up to stdint types. * Set up pixel mode enum. * Clean up some comments, formatting, and stray old format vars. * Forgot to update the exports with the new functions. * Clarifying a comment * Tiny Doxygen fix. - A subgroup of related #defines became an enum. * Update vid_enabled/vid_disabled * Update types for 8-bit color values * Correct type references I had missed * Clean up includes. * Apply suggestions from code review ----------------------------------------------------------------------- Summary of changes: AUTHORS | 2 +- doc/CHANGELOG | 2 + examples/dreamcast/video/Makefile | 3 + examples/dreamcast/video/multibuffer/Makefile | 28 ++ examples/dreamcast/video/multibuffer/multibuffer.c | 60 +++ kernel/arch/dreamcast/exports-naomi.txt | 14 +- kernel/arch/dreamcast/exports-pristine.txt | 14 +- kernel/arch/dreamcast/hardware/biosfont.c | 1 - kernel/arch/dreamcast/hardware/pvr/pvr_irq.c | 3 - kernel/arch/dreamcast/hardware/video.c | 448 +++++++-------------- kernel/arch/dreamcast/include/dc/video.h | 184 +++++---- 11 files changed, 381 insertions(+), 378 deletions(-) create mode 100644 examples/dreamcast/video/multibuffer/Makefile create mode 100644 examples/dreamcast/video/multibuffer/multibuffer.c diff --git a/AUTHORS b/AUTHORS index 163b5384..65244f5b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -27,7 +27,7 @@ Sam Steele: 2004 Gil Megidish: 2002 Florian Schulze: 2002 Walter van Niftrik: 2005 -Donald Haase: 2008, 2014 +Donald Haase: 2008, 2014, 2023 Andrew Kieschnick: 2000, 2001, 2002, 2003 Jordan DeLong: 2000, 2001, 2002 Bero: 2002 diff --git a/doc/CHANGELOG b/doc/CHANGELOG index cc074cd6..5ebce19b 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -213,6 +213,8 @@ KallistiOS version 2.1.0 ----------------------------------------------- - DC Improved performance of IRQ context save / restore [PC] - DC Increased resolution of TMU timers + date/time functions [FG && PC] - *** Increased resolution of clock() and CLOCKS_PER_SEC to microseconds [FG] +- DC Added centralized header for Dreamcast Memory map (arch/memory.h) [DH] +- DC Refactored multibuffer video modes and added example of their use [DH] - DC Created separate performance counter driver and enhanced API [FG] - *** Implemented _POSIX_CPUTIME in clock_gettime() using perf counter timer [FG] - *** Implemented scandir() and alphasort() POSIX functions from dirent.h [FG] diff --git a/examples/dreamcast/video/Makefile b/examples/dreamcast/video/Makefile index 9fc9ac7f..27c19c24 100644 --- a/examples/dreamcast/video/Makefile +++ b/examples/dreamcast/video/Makefile @@ -8,13 +8,16 @@ all: $(KOS_MAKE) -C bfont $(KOS_MAKE) -C palmenu $(KOS_MAKE) -C minifont + $(KOS_MAKE) -C multibuffer clean: $(KOS_MAKE) -C bfont clean $(KOS_MAKE) -C palmenu clean $(KOS_MAKE) -C minifont clean + $(KOS_MAKE) -C multibuffer dist: $(KOS_MAKE) -C bfont dist $(KOS_MAKE) -C palmenu dist $(KOS_MAKE) -C minifont dist + $(KOS_MAKE) -C multibuffer diff --git a/examples/dreamcast/video/multibuffer/Makefile b/examples/dreamcast/video/multibuffer/Makefile new file mode 100644 index 00000000..30b6b663 --- /dev/null +++ b/examples/dreamcast/video/multibuffer/Makefile @@ -0,0 +1,28 @@ +# KallistiOS ##version## +# +# video/multibuffer/Makefile +# Copyright (C) 2023 Donald Haase +# + +TARGET = multibuffer.elf +OBJS = multibuffer.o + +all: rm-elf $(TARGET) + +include $(KOS_BASE)/Makefile.rules + +clean: rm-elf + -rm -f $(OBJS) + +rm-elf: + -rm -f $(TARGET) + +$(TARGET): $(OBJS) + kos-cc -o $(TARGET) $(OBJS) + +run: $(TARGET) + $(KOS_LOADER) $(TARGET) + +dist: $(TARGET) + -rm -f $(OBJS) + $(KOS_STRIP) $(TARGET) diff --git a/examples/dreamcast/video/multibuffer/multibuffer.c b/examples/dreamcast/video/multibuffer/multibuffer.c new file mode 100644 index 00000000..8cf08f8e --- /dev/null +++ b/examples/dreamcast/video/multibuffer/multibuffer.c @@ -0,0 +1,60 @@ +/* KallistiOS ##version## + + multibuffer.c + Copyright (C) 2023 Donald Haase + +*/ + +/* + This example is based off a combination of the libdream video examples and + the bfont examples. It draws out four distinct framebuffers then rotates + between them until stopped. + + */ + +#include <kos.h> + +int main(int argc, char **argv) { + unsigned short x, y, mb; + char text_buff [20]; + + /* Press all buttons to exit */ + cont_btn_callback(0, CONT_START | CONT_A | CONT_B | CONT_X | CONT_Y, + (cont_btn_callback_t)arch_exit); + + + /* Set the video mode */ + vid_set_mode(DM_640x480 | DM_MULTIBUFFER, PM_RGB565); + + /* Cycle through each frame buffer populating it with different + patterns and text labelling it. */ + for(mb = 0; mb < vid_mode->fb_count; mb++) { + + for(y = 0; y < 480; y++) { + for(x = 0; x < 640; x++) { + int c = (x ^ y) & 0xff; + vram_s[y * 640 + x] = ( ((c >> 3) << 12) + | ((c >> 2) << 5) + | ((c >> 3) << (mb % 5))) & 0xffff; + } + } + + snprintf(text_buff, 20, "This is FB %u", (mb + 1) % vid_mode->fb_count); + bfont_draw_str(vram_s + (640 * BFONT_HEIGHT) + (BFONT_THIN_WIDTH * 2), 640, 1, text_buff); + + /* This tells the pvr to move to the framebuffer we've been drawing to, + then adjusts the vram_* pointers to the next one. */ + vid_flip(-1); + } + + printf("\n\nPress all buttons simultaneously to exit.\n"); + fflush(stdout); + + /* Now flip through each frame until stopped, waiting a bit each time. */ + while(1) { + vid_flip(-1); + timer_spin_sleep(1500); + } + + return 0; +} diff --git a/kernel/arch/dreamcast/exports-naomi.txt b/kernel/arch/dreamcast/exports-naomi.txt index 181b33c3..74591a67 100644 --- a/kernel/arch/dreamcast/exports-naomi.txt +++ b/kernel/arch/dreamcast/exports-naomi.txt @@ -141,19 +141,25 @@ snd_pcm8_split snd_adpcm_split # Video -vid_check_cable +vid_mode vram_s vram_l -vid_mode -vid_set_mode -vid_set_mode_ex +vid_check_cable +vid_set_vram vid_set_start +vid_get_start +vid_set_fb vid_flip vid_border_color vid_clear vid_empty +vid_get_enabled +vid_set_enabled vid_waitvbl +vid_set_mode +vid_set_mode_ex vid_init +vid_shutdown # Maple cont_btn_callback diff --git a/kernel/arch/dreamcast/exports-pristine.txt b/kernel/arch/dreamcast/exports-pristine.txt index 6b880627..976ca49d 100644 --- a/kernel/arch/dreamcast/exports-pristine.txt +++ b/kernel/arch/dreamcast/exports-pristine.txt @@ -184,19 +184,25 @@ snd_pcm8_split snd_adpcm_split # Video -vid_check_cable +vid_mode vram_s vram_l -vid_mode -vid_set_mode -vid_set_mode_ex +vid_check_cable +vid_set_vram vid_set_start +vid_get_start +vid_set_fb vid_flip vid_border_color vid_clear vid_empty +vid_get_enabled +vid_set_enabled vid_waitvbl +vid_set_mode +vid_set_mode_ex vid_init +vid_shutdown # Maple cont_btn_callback diff --git a/kernel/arch/dreamcast/hardware/biosfont.c b/kernel/arch/dreamcast/hardware/biosfont.c index e10c61d8..a8b9c3c1 100644 --- a/kernel/arch/dreamcast/hardware/biosfont.c +++ b/kernel/arch/dreamcast/hardware/biosfont.c @@ -9,7 +9,6 @@ #include <assert.h> #include <dc/biosfont.h> -#include <dc/video.h> #include <kos/dbglog.h> /* diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_irq.c b/kernel/arch/dreamcast/hardware/pvr/pvr_irq.c index 9259bb5b..1873076b 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_irq.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_irq.c @@ -7,7 +7,6 @@ #include <assert.h> #include <dc/pvr.h> -#include <dc/video.h> #include <dc/asic.h> #include <arch/cache.h> #include "pvr_internal.h" @@ -236,5 +235,3 @@ void pvr_int_handler(uint32 code) { dma_next_list(0); } } - - diff --git a/kernel/arch/dreamcast/hardware/video.c b/kernel/arch/dreamcast/hardware/video.c index af1e608a..73551fed 100644 --- a/kernel/arch/dreamcast/hardware/video.c +++ b/kernel/arch/dreamcast/hardware/video.c @@ -2,8 +2,9 @@ video.c - (c)2001 Anders Clerwall (scav) - Parts (c)2000-2001 Megan Potter + Copyright (C) 2001 Anders Clerwall (scav) + Copyright (C) 2000-2001 Megan Potter + Copyright (C) 2023-2024 Donald Haase */ #include <dc/video.h> @@ -12,14 +13,15 @@ #include <string.h> #include <stdio.h> -#define FBPOS(n) (n * 0x200000) +/* The size of the vram. TODO: This needs a better home */ +#define PVR_MEM_SIZE 0x800000 /*-----------------------------------------------------------------------------*/ /* This table is indexed w/ DM_* */ vid_mode_t vid_builtin[DM_MODE_COUNT] = { /* NULL mode.. */ /* DM_INVALID = 0 */ - { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, { 0, 0, 0, 0 } }, + { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, /* 320x240 VGA 60Hz */ /* DM_320x240_VGA */ @@ -30,12 +32,11 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { CT_VGA, 0, 262, 857, - 0xAC, 0x28, - 0x15, 0x104, + 172, 40, + 21, 260, 141, 843, 24, 263, - 0, 1, - { 0, 0, 0, 0 } + 0, 1, 0 }, /* 320x240 NTSC 60Hz */ @@ -47,12 +48,11 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { CT_ANY, 0, 262, 857, - 0xA4, 0x18, - 0x15, 0x104, + 164, 24, + 21, 260, 141, 843, 24, 263, - 0, 1, - { 0, 0, 0, 0 } + 0, 1, 0 }, /* 640x480 VGA 60Hz */ @@ -60,16 +60,15 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { { DM_640x480, 640, 480, - VID_INTERLACE, + 0, CT_VGA, 0, - 0x20C, 0x359, - 0xAC, 0x28, - 0x15, 0x104, - 0x7E, 0x345, - 0x24, 0x204, - 0, 1, - { 0, 0, 0, 0 } + 524, 857, + 172, 40, + 21, 260, + 126, 837, + 36, 516, + 0, 1, 0 }, /* 640x480 NTSC 60Hz IL */ @@ -80,13 +79,12 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { VID_INTERLACE, CT_ANY, 0, - 0x20C, 0x359, - 0xA4, 0x12, - 0x15, 0x104, - 0x7E, 0x345, - 0x24, 0x204, - 0, 1, - { 0, 0, 0, 0 } + 524, 857, + 164, 18, + 21, 260, + 126, 837, + 36, 516, + 0, 1, 0 }, /* 640x480 PAL 50Hz IL */ @@ -97,13 +95,12 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { VID_INTERLACE | VID_PAL, CT_ANY, 0, - 0x270, 0x35F, - 0xAE, 0x2D, - 0x15, 0x104, - 0x8D, 0x34B, - 0x2C, 0x26C, - 0, 1, - { 0, 0, 0, 0 } + 624, 863, + 174, 45, + 21, 260, + 141, 843, + 44, 620, + 0, 1, 0 }, /* 256x256 PAL 50Hz IL (seems to output the same w/o VID_PAL, ie. in NTSC IL mode) */ @@ -116,11 +113,10 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { 0, 624, 863, 226, 37, - 0x15, 0x104, - 0x8D, 0x34B, - 0x2C, 0x26C, - 0, 1, - { 0, 0, 0, 0 } + 21, 260, + 141, 843, + 44, 620, + 0, 1, 0 }, /* 768x480 NTSC 60Hz IL (thanks DCGrendel) */ @@ -133,11 +129,10 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { 0, 524, 857, 96, 18, - 0x15, 0x104, - 0x2e, 0x345, - 0x24, 0x204, - 0, 1, - { 0, 0, 0, 0 } + 21, 260, + 46, 837, + 36, 516, + 0, 1, 0 }, /* 768x576 PAL 50Hz IL (DCG) */ @@ -150,11 +145,10 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { 0, 624, 863, 88, 16, - 0x18, 0x104, - 0x36, 0x34b, - 0x2c, 0x26c, - 0, 1, - { 0, 0, 0, 0 } + 24, 260, + 54, 843, + 44, 620, + 0, 1, 0 }, /* 768x480 PAL 50Hz IL */ @@ -167,11 +161,10 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { 0, 624, 863, 88, 16, - 0x18, 0x104, - 0x36, 0x34b, - 0x2c, 0x26c, - 0, 1, - { 0, 0, 0, 0 } + 24, 260, + 54, 843, + 44, 620, + 0, 1, 0 }, /* 320x240 PAL 50Hz (thanks Marco Martins aka Mekanaizer) */ @@ -187,188 +180,12 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { 21, 260, 141, 843, 44, 620, - 0, 1, - { 0, 0, 0, 0 } - }, - - /* All of the modes below this comment are exactly the same as the ones - above, other than that they support multiple framebuffers (in the current - case, 4). They're only particularly useful if you're doing a drawing by - directly writing to the framebuffer, and are not useful at all if you're - using the PVR to do your drawing. */ - /* 320x240 VGA 60Hz */ - /* DM_320x240_VGA_MB */ - { - DM_320x240 | DM_MULTIBUFFER, - 320, 240, - VID_PIXELDOUBLE | VID_LINEDOUBLE, - CT_VGA, - 0, - 262, 857, - 0xAC, 0x28, - 0x15, 0x104, - 141, 843, - 24, 263, - 0, VID_MAX_FB, - { FBPOS(0), FBPOS(1), FBPOS(2), FBPOS(3) } - }, - - /* 320x240 NTSC 60Hz */ - /* DM_320x240_NTSC_MB */ - { - DM_320x240 | DM_MULTIBUFFER, - 320, 240, - VID_PIXELDOUBLE | VID_LINEDOUBLE, - CT_ANY, - 0, - 262, 857, - 0xA4, 0x18, - 0x15, 0x104, - 141, 843, - 24, 263, - 0, VID_MAX_FB, - { FBPOS(0), FBPOS(1), FBPOS(2), FBPOS(3) } - }, - - /* 640x480 VGA 60Hz */ - /* DM_640x480_VGA_MB */ - { - DM_640x480 | DM_MULTIBUFFER, - 640, 480, - VID_INTERLACE, - CT_VGA, - 0, - 0x20C, 0x359, - 0xAC, 0x28, - 0x15, 0x104, ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |