From 3b0792dfabe0492c97cb876c59f2346113282ca2 Mon Sep 17 00:00:00 2001 From: Nabile Rahmani Date: Sat, 1 Dec 2018 04:04:00 +0100 Subject: [PATCH] Fixed RGBA16 output being pixel swapped. Cartridge (big-endian): 1234 RAM (little-endian): 4321 Source 16-bit image: 12-34 (2 pixels) Emulated image should be 21-43 (big => little), but the word swap made it 43-21 (pixel swapped) Output: 4321 => 2143 --- DotN64.Desktop/DotN64.Desktop.csproj | 2 ++ DotN64.Desktop/SDL/Window.cs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/DotN64.Desktop/DotN64.Desktop.csproj b/DotN64.Desktop/DotN64.Desktop.csproj index 0d08e4f..866d956 100644 --- a/DotN64.Desktop/DotN64.Desktop.csproj +++ b/DotN64.Desktop/DotN64.Desktop.csproj @@ -28,6 +28,7 @@ + true true @@ -36,6 +37,7 @@ 4 true false + true diff --git a/DotN64.Desktop/SDL/Window.cs b/DotN64.Desktop/SDL/Window.cs index 1e7ae1c..9c07163 100644 --- a/DotN64.Desktop/SDL/Window.cs +++ b/DotN64.Desktop/SDL/Window.cs @@ -119,7 +119,7 @@ namespace DotN64.Desktop.SDL } } - public void Draw(VideoFrame frame, RealityCoprocessor.VideoInterface vi, RDRAM ram) + public unsafe void Draw(VideoFrame frame, RealityCoprocessor.VideoInterface vi, RDRAM ram) { PollEvents(); @@ -163,7 +163,19 @@ namespace DotN64.Desktop.SDL var line = (ushort)((vi.CurrentVerticalLine - vi.VerticalVideo.ActiveVideoStart) / (float)(vi.VerticalVideo.ActiveVideoEnd - vi.VerticalVideo.ActiveVideoStart) * frame.Height); var offset = pitch * line; - Marshal.Copy(ram.Memory, (int)vi.DRAMAddress + offset, pixels + offset, pitch); + if (frame.Size != ControlRegister.PixelSize.RGBA5553) + Marshal.Copy(ram.Memory, (int)vi.DRAMAddress + offset, pixels + offset, pitch); + else + { + fixed (byte* rdram = &ram.Memory[(int)vi.DRAMAddress]) + { + for (int end = offset + pitch; offset < end; offset += 4) + { + ((ushort*)(pixels + offset))[0] = ((ushort*)(rdram + offset))[1]; + ((ushort*)(pixels + offset))[1] = ((ushort*)(rdram + offset))[0]; + } + } + } } SDL_UnlockTexture(texture);