From 75dcf71386063d3c3eac8c3df517d2fe41e81c3e Mon Sep 17 00:00:00 2001 From: andymcca Date: Sun, 25 Aug 2024 21:34:59 +0100 Subject: [PATCH 1/4] Implement Green Swap mode --- video.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/video.cc b/video.cc index a233fcb0..aa4384b3 100644 --- a/video.cc +++ b/video.cc @@ -2286,6 +2286,7 @@ void update_scanline(void) { u32 pitch = get_screen_pitch(); u16 dispcnt = read_ioreg(REG_DISPCNT); + u16 grnswp = read_ioreg(REG_GRNSWP); u32 vcount = read_ioreg(REG_VCOUNT); u16 *screen_offset = get_screen_pixels() + (vcount * pitch); u32 video_mode = dispcnt & 0x07; @@ -2309,6 +2310,21 @@ void update_scanline(void) else render_scanline_window(screen_offset); + // Check for Undocumented Green Swap screen mode + if (grnswp) { + // Apply Green Swap to scanline in place for speed + for (u8 x = 0; x < pitch; x += 4) { + screen_offset[x] = screen_offset[x] & (M_COLOR_RED | M_COLOR_BLUE); + screen_offset[x] |= screen_offset[x + 1] & M_COLOR_GREEN; + screen_offset[x + 1] = screen_offset[x + 1] & (M_COLOR_RED | M_COLOR_BLUE); + screen_offset[x + 1] |= screen_offset[x] & M_COLOR_GREEN; + screen_offset[x + 2] = screen_offset[x + 2] & (M_COLOR_RED | M_COLOR_BLUE); + screen_offset[x + 2] |= screen_offset[x + 3] & M_COLOR_GREEN; + screen_offset[x + 3] = screen_offset[x + 3] & (M_COLOR_RED | M_COLOR_BLUE); + screen_offset[x + 3] |= screen_offset[x + 2] & M_COLOR_GREEN; + } + } + // Mode 0 does not use any affine params at all. if (video_mode) { // Account for vertical mosaic effect, by correcting affine references. From a399366e5c281305becff1e677ecea5b9d37bcb0 Mon Sep 17 00:00:00 2001 From: andymcca Date: Mon, 26 Aug 2024 00:03:43 +0100 Subject: [PATCH 2/4] Update video.cc Add GRNSWP colors --- video.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/video.cc b/video.cc index aa4384b3..3fa63963 100644 --- a/video.cc +++ b/video.cc @@ -90,6 +90,11 @@ typedef struct #define RENDER_COL32 2 #define RENDER_ALPHA 3 +// GRNSWP colors +#define M_COLOR_RED 0x000000FF +#define M_COLOR_GREEN 0x0000FF00 +#define M_COLOR_BLUE 0x00FF0000 +#define M_COLOR_ALPHA 0xFF000000 // Byte lengths of complete tiles and tile rows in 4bpp and 8bpp. From c01a75ebee6af7d5ec0dce876bc4ee17581a71be Mon Sep 17 00:00:00 2001 From: andymcca Date: Mon, 26 Aug 2024 10:30:18 +0100 Subject: [PATCH 3/4] Change GRNSWP colors to RGB565 This should be correct I think....but it still doesn't display correctly :-/ --- video.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/video.cc b/video.cc index 3fa63963..a6cc98bc 100644 --- a/video.cc +++ b/video.cc @@ -91,10 +91,10 @@ typedef struct #define RENDER_ALPHA 3 // GRNSWP colors -#define M_COLOR_RED 0x000000FF -#define M_COLOR_GREEN 0x0000FF00 -#define M_COLOR_BLUE 0x00FF0000 -#define M_COLOR_ALPHA 0xFF000000 +#define M_COLOR_RED 0x001F +#define M_COLOR_GREEN 0x07E0 +#define M_COLOR_BLUE 0xF800 +#define M_COLOR_ALPHA 0x0000 // Byte lengths of complete tiles and tile rows in 4bpp and 8bpp. From 0f62c822f32a3888def48e9aa9101381c3fd819a Mon Sep 17 00:00:00 2001 From: andymcca Date: Mon, 26 Aug 2024 13:53:23 +0100 Subject: [PATCH 4/4] Correct GRNSWP color values and fix routine with swap buffer Color values used for isolating green channels fixed (found that these should be RGB565). Fixed main routine to perform Green Swap - needed a swap buffer to prevent overwriting green channel on previous pixel before we get a chance to swap it! --- video.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/video.cc b/video.cc index a6cc98bc..f84c736b 100644 --- a/video.cc +++ b/video.cc @@ -91,9 +91,9 @@ typedef struct #define RENDER_ALPHA 3 // GRNSWP colors -#define M_COLOR_RED 0x001F +#define M_COLOR_RED 0xF800 #define M_COLOR_GREEN 0x07E0 -#define M_COLOR_BLUE 0xF800 +#define M_COLOR_BLUE 0x001F #define M_COLOR_ALPHA 0x0000 // Byte lengths of complete tiles and tile rows in 4bpp and 8bpp. @@ -2317,16 +2317,19 @@ void update_scanline(void) // Check for Undocumented Green Swap screen mode if (grnswp) { + u16 swapbuffer = 0; // Apply Green Swap to scanline in place for speed for (u8 x = 0; x < pitch; x += 4) { + swapbuffer = screen_offset[x]; screen_offset[x] = screen_offset[x] & (M_COLOR_RED | M_COLOR_BLUE); screen_offset[x] |= screen_offset[x + 1] & M_COLOR_GREEN; screen_offset[x + 1] = screen_offset[x + 1] & (M_COLOR_RED | M_COLOR_BLUE); - screen_offset[x + 1] |= screen_offset[x] & M_COLOR_GREEN; + screen_offset[x + 1] |= swapbuffer & M_COLOR_GREEN; + swapbuffer = screen_offset[x + 2]; screen_offset[x + 2] = screen_offset[x + 2] & (M_COLOR_RED | M_COLOR_BLUE); screen_offset[x + 2] |= screen_offset[x + 3] & M_COLOR_GREEN; screen_offset[x + 3] = screen_offset[x + 3] & (M_COLOR_RED | M_COLOR_BLUE); - screen_offset[x + 3] |= screen_offset[x + 2] & M_COLOR_GREEN; + screen_offset[x + 3] |= swapbuffer & M_COLOR_GREEN; } }