From f517f32902b8c454ea355141444807198f9b678e Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Sat, 10 Oct 2009 14:26:53 +0000 Subject: [PATCH] RGB support. svn-id: r44874 --- backends/platform/dc/dc.h | 9 +- backends/platform/dc/dcmain.cpp | 2 +- backends/platform/dc/display.cpp | 137 +++++++++++++++++++++++++------ 3 files changed, 123 insertions(+), 25 deletions(-) diff --git a/backends/platform/dc/dc.h b/backends/platform/dc/dc.h index 45d9aa99c2f..c3e81aef736 100644 --- a/backends/platform/dc/dc.h +++ b/backends/platform/dc/dc.h @@ -82,6 +82,12 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Filesys void setPalette(const byte *colors, uint start, uint num); void grabPalette(byte *colors, uint start, uint num); + // Determine the pixel format currently in use for screen rendering. + Graphics::PixelFormat getScreenFormat() const; + + // Returns a list of all pixel formats supported by the backend. + Common::List getSupportedFormats(); + // Set the size of the video bitmap. // Typically, 320x200 void initSize(uint w, uint h, const Graphics::PixelFormat *format); @@ -198,7 +204,7 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Filesys int _current_shake_pos, _screen_w, _screen_h; int _overlay_x, _overlay_y; unsigned char *_ms_buf; - unsigned char _ms_keycolor; + uint32 _ms_keycolor; bool _overlay_visible, _overlay_dirty, _screen_dirty; int _screen_buffer, _overlay_buffer, _mouse_buffer; bool _aspect_stretch, _softkbd_on, _enable_cursor_palette; @@ -214,6 +220,7 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Filesys unsigned short palette[256], cursor_palette[256]; Graphics::Surface _framebuffer; + int _screenFormat, _mouseFormat; int temp_sound_buffer[RING_BUFFER_SAMPLES>>SOUND_BUFFER_SHIFT]; diff --git a/backends/platform/dc/dcmain.cpp b/backends/platform/dc/dcmain.cpp index 078c6266a43..8ad4708ebf5 100644 --- a/backends/platform/dc/dcmain.cpp +++ b/backends/platform/dc/dcmain.cpp @@ -44,7 +44,7 @@ OSystem_Dreamcast::OSystem_Dreamcast() : _devpoll(0), screen(NULL), mouse(NULL), overlay(NULL), _softkbd(this), _ms_buf(NULL), _timer(NULL), _mixer(NULL), _savefile(NULL), _current_shake_pos(0), _aspect_stretch(false), _softkbd_on(false), - _softkbd_motion(0), _enable_cursor_palette(false) + _softkbd_motion(0), _enable_cursor_palette(false), _screenFormat(0) { memset(screen_tx, 0, sizeof(screen_tx)); memset(mouse_tx, 0, sizeof(mouse_tx)); diff --git a/backends/platform/dc/display.cpp b/backends/platform/dc/display.cpp index c6be514e363..75bf31f4f64 100644 --- a/backends/platform/dc/display.cpp +++ b/backends/platform/dc/display.cpp @@ -41,6 +41,22 @@ #define TOP_OFFSET (_top_offset+_yscale*_current_shake_pos) +static const struct { + Graphics::PixelFormat pixelFormat; + unsigned int textureFormat; + operator const Graphics::PixelFormat&() const { return pixelFormat; } +} screenFormats[] = { + /* Note: These are ordered by _increasing_ preference, so that + CLUT8 appears at index 0. getSupportedFormats() will return + them in reversed order. */ + { Graphics::PixelFormat::createFormatCLUT8(), TA_TEXTUREMODE_ARGB1555 }, + { Graphics::PixelFormat(2,4,4,4,4,8,4,0,12), TA_TEXTUREMODE_ARGB4444 }, + { Graphics::PixelFormat(2,5,5,5,1,10,5,0,15), TA_TEXTUREMODE_ARGB1555 }, + { Graphics::PixelFormat(2,5,6,5,0,11,5,0,0), TA_TEXTUREMODE_RGB565 }, +}; +#define NUM_FORMATS (sizeof(screenFormats)/sizeof(screenFormats[0])) + + #define QACR0 (*(volatile unsigned int *)(void *)0xff000038) #define QACR1 (*(volatile unsigned int *)(void *)0xff00003c) @@ -178,6 +194,20 @@ void OSystem_Dreamcast::grabPalette(byte *colors, uint start, uint num) } } +Graphics::PixelFormat OSystem_Dreamcast::getScreenFormat() const +{ + return screenFormats[_screenFormat]; +} + +Common::List OSystem_Dreamcast::getSupportedFormats() +{ + Common::List list; + int i; + for (i=0; i 400) { @@ -197,6 +227,13 @@ void OSystem_Dreamcast::initSize(uint w, uint h, const Graphics::PixelFormat *fo { assert(w <= SCREEN_W && h <= SCREEN_H); + int i = 0; + if (format != NULL) + for (i=NUM_FORMATS-1; i>0; --i) + if (*format == screenFormats[i]) + break; + _screenFormat = i; + _overlay_visible = false; _overlay_fade = 0.0; _screen_w = w; @@ -208,7 +245,7 @@ void OSystem_Dreamcast::initSize(uint w, uint h, const Graphics::PixelFormat *fo setScaling(); ta_sync(); if (!screen) - screen = new unsigned char[SCREEN_W*SCREEN_H]; + screen = new unsigned char[SCREEN_W*SCREEN_H*2]; if (!overlay) overlay = new unsigned short[OVL_W*OVL_H]; for (int i=0; i0; --i) + if (*format == screenFormats[i]) + break; + _mouseFormat = i; if (_ms_buf) free(_ms_buf); + if (_mouseFormat != 0) + w <<= 1; + _ms_buf = (byte *)malloc(w * h); memcpy(_ms_buf, buf, w * h); } @@ -298,12 +348,20 @@ void OSystem_Dreamcast::updateScreenTextures(void) // while ((*((volatile unsigned int *)(void*)0xa05f810c) & 0x3ff) != 200); // *((volatile unsigned int *)(void*)0xa05f8040) = 0xff0000; - for ( int y = 0; y<_screen_h; y++ ) - { - texture_memcpy64_pal( dst, src, _screen_w>>5, palette ); - src += SCREEN_W; - dst += SCREEN_W; - } + if (_screenFormat == 0) + for ( int y = 0; y<_screen_h; y++ ) + { + texture_memcpy64_pal( dst, src, _screen_w>>5, palette ); + src += SCREEN_W*2; + dst += SCREEN_W; + } + else + for ( int y = 0; y<_screen_h; y++ ) + { + texture_memcpy64( dst, src, _screen_w>>5 ); + src += SCREEN_W*2; + dst += SCREEN_W; + } _screen_dirty = false; } @@ -341,8 +399,9 @@ void OSystem_Dreamcast::updateScreenPolygons(void) mypoly.mode2 = TA_POLYMODE2_BLEND_SRC|TA_POLYMODE2_FOG_DISABLED|TA_POLYMODE2_TEXTURE_REPLACE| TA_POLYMODE2_U_SIZE_1024|TA_POLYMODE2_V_SIZE_1024; - mypoly.texture = TA_TEXTUREMODE_ARGB1555|TA_TEXTUREMODE_NON_TWIDDLED| - TA_TEXTUREMODE_STRIDE|TA_TEXTUREMODE_ADDRESS(screen_tx[_screen_buffer]); + mypoly.texture = screenFormats[_screenFormat].textureFormat| + TA_TEXTUREMODE_NON_TWIDDLED|TA_TEXTUREMODE_STRIDE| + TA_TEXTUREMODE_ADDRESS(screen_tx[_screen_buffer]); mypoly.red = mypoly.green = mypoly.blue = mypoly.alpha = 0; @@ -471,17 +530,22 @@ void OSystem_Dreamcast::maybeRefreshScreen(void) void OSystem_Dreamcast::drawMouse(int xdraw, int ydraw, int w, int h, unsigned char *buf, bool visible) { + if (!visible || buf == NULL || !w || !h || w>MOUSE_W || h>MOUSE_H) { + commit_dummy_transpoly(); + return; + } + struct polygon_list mypoly; struct packed_colour_vertex_list myvertex; - unsigned short *pal = _enable_cursor_palette? cursor_palette : palette; - _mouse_buffer++; _mouse_buffer &= NUM_BUFFERS-1; unsigned short *dst = (unsigned short *)mouse_tx[_mouse_buffer]; + unsigned int texturemode = screenFormats[_mouseFormat].textureFormat; - if (visible && w && h && w<=MOUSE_W && h<=MOUSE_H) + if (_mouseFormat == 0) { + unsigned short *pal = _enable_cursor_palette? cursor_palette : palette; for (int y=0; y>1)|0x8000; + } + dst += MOUSE_W-x; + } + } else { + unsigned short *bufs = (unsigned short *)buf; + for (int y=0; y