From d7f39ca8314d2605a388e54b1222cd433fa449ce Mon Sep 17 00:00:00 2001 From: goyuken Date: Sun, 17 Aug 2014 20:05:56 +0000 Subject: [PATCH] vba next: coreside work for alternate palettes --- .../Consoles/Nintendo/GBA/LibVBANext.cs | 3 ++- .../Consoles/Nintendo/GBA/VBANext.cs | 19 +++++++++++++++++- .../Consoles/Nintendo/Gameboy/GBColors.cs | 11 +++++++--- output/dll/libvbanext.dll | Bin 443392 -> 443392 bytes vbanext/instance.cpp | 15 ++++++++------ 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibVBANext.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibVBANext.cs index e0acf4f219..c793fb95d4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibVBANext.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/LibVBANext.cs @@ -101,9 +101,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA /// 240x160 packed argb32 /// buffer to recieve stereo audio /// number of samples created + /// /// true if lagged [DllImport(dllname, CallingConvention = cc)] - public static extern bool FrameAdvance(IntPtr g, Buttons input, int[] videobuffer, short[] audiobuffer, out int numsamp); + public static extern bool FrameAdvance(IntPtr g, Buttons input, int[] videobuffer, short[] audiobuffer, out int numsamp, int[] videopalette); [DllImport(dllname, CallingConvention = cc)] public static extern int BinStateSize(IntPtr g); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs index 80eee33b91..3bf2b3e786 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs @@ -74,6 +74,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA savebuff = new byte[LibVBANext.BinStateSize(Core)]; savebuff2 = new byte[savebuff.Length + 13]; InitMemoryDomains(); + + // todo: hook me up as a setting + SetupColors(); } catch { @@ -89,7 +92,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA if (Controller["Power"]) LibVBANext.Reset(Core); - IsLagFrame = LibVBANext.FrameAdvance(Core, GetButtons(), videobuff, soundbuff, out numsamp); + IsLagFrame = LibVBANext.FrameAdvance(Core, GetButtons(), videobuff, soundbuff, out numsamp, videopalette); if (IsLagFrame) LagCount++; @@ -430,6 +433,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA #region VideoProvider int[] videobuff = new int[240 * 160]; + int[] videopalette = new int[65536]; public IVideoProvider VideoProvider { get { return this; } } public int[] GetVideoBuffer() { return videobuff; } @@ -439,6 +443,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA public int BufferHeight { get { return 160; } } public int BackgroundColor { get { return unchecked((int)0xff000000); } } + void SetupColors() + { + int[] tmp = BizHawk.Emulation.Cores.Nintendo.Gameboy.GBColors.GetLut(Gameboy.GBColors.ColorType.vivid); + // reorder + for (int i = 0; i < 32768; i++) + { + int j = i & 0x3e0 | (i & 0x1f) << 10 | i >> 10 & 0x1f; + videopalette[i] = tmp[j]; + } + // duplicate + Array.Copy(videopalette, 0, videopalette, 32768, 32768); + } + #endregion #region SoundProvider diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs index 953ca3c3d0..28bd968dd1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs @@ -126,6 +126,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy }; public static int[] GetLut(ColorType c) + { + int[] ret = new int[32768]; + GetLut(c, ret); + return ret; + } + + public static void GetLut(ColorType c, int[] dest, int offset = 0) { Func f = null; switch (c) @@ -137,13 +144,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy case ColorType.vbabgbold: f = OldVBAColor; break; case ColorType.gba: f = GBAColor; break; } - int[] ret = new int[32768]; int i = 0; for (int b = 0; b < 32; b++) for (int g = 0; g < 32; g++) for (int r = 0; r < 32; r++) - ret[i++] = f(new Triple(r, g, b)).ToARGB32(); - return ret; + dest[offset + i++] = f(new Triple(r, g, b)).ToARGB32(); } } } diff --git a/output/dll/libvbanext.dll b/output/dll/libvbanext.dll index 12ebecefc7e57a7685bbbceb4ab05d96fa8e163f..0247e74803374fd488ad7d018d83064ac4677d46 100644 GIT binary patch delta 3343 zcmah~3shBA8a{V(&*2IvS5xDqKtl$CcwYNF?>SdR&B(_ELQ%w5jtM>@Lv+mHA;v%# z3B1ZNOClzltbB!fD9H#EG_3G3<`5z{sFySarF?`k`(m=z)T}jUt?%x=zy0t1pY#3S z-Zv}HKP%6_=&suh_pah!M}XZS4nIRA&?HB+A$mXrgJF#%fdv!?`#UNP0@&;7Id`2VEvdgU34{&g4k;Tmzci9hW?pgXQiH zo7bPfv+j=7UZV~Ejxw)Ou%2*?8#v!J80crf9ES(`fy;Qs_XEdygM(Ow?}%g*h`w8~ z@#(h!Nc_bS7-|KJes(MfjRkc-J9#4wuju4`0ct#?(XJ6xDsgb8 z$#HXnuTa^9V`$+owZ^pJOEDvcZ7OL#2(T0^*16;Hl*u)fWxzJ&R+YJf6wKz_(Bv2w z2v%Is*D1Tw+S15mPjI*PkD%p3;Ma4SL^;5a2CtQ@x zS=&z)lHWX9xbL_&Bp#0kamV%Kcsw`(kW2J}-MGmJB9?0<`|%)yhoi?ccB%+{73#oI@vC7^fg#?U+Fu5Ia? zS>$4R`k2&thlC`sk{%0U$2M z`D7o1A*N4j6odD#I#Shx_L=3p9j|{^kFRr+*Tg>7tY4tT{Zzj|G5u7(Kx(YMu>oI= z4{1hTk&mSf_SOr_S%8U!t-9wayv|^#(@vkpzX8F~+Iwg4QQ+Ql+KDsx(*G47bryfw zl=+#LON62$=qqN~d%g8l5ABsFUAAO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P3o0=8{tyeupi zHVE5={lZD%vT$GU5=V%XI7Lhsm%>v}2~R<-Xt^Zbg>mqeLM26tmlnW4lu92+Ur6=R zRq3wOEt%yJ@>n@Wo*`$+7WtA4lp(NM$V!|tPsvei$|uTU<)RX!rosSNRGYdRW`B@I zYLlV)i?uacxwca~u7&A>J`HAkj=o;s=1TMs_(uggUS)yVJ&;^RwvrJPO$n3=4V^>f zQDxLts){;Eouiter32`}Fqa8fRwmL3(AW$*m;MXAiQY{grccn{!@}ah_%VUZWM(Q8 z&m=Rmm_^Jg#();rGCr)ru48N2W9(`6JGPO%%-&!fY&-jq{f#wo7B9}13*bg_6F7lW zxfpIbmjd(rRc<*~z`e3kZW!7t;B`3inFf0(c5aluO% zE0D0z{3tkuAdwV#al81T__0_m9u>b8Z-^#okQ5}1g2^sQ^QFbo3Td@eAg!0me5K9O YyD;;2N&8{$XTXB9M7F0_;ycFu6Tew8*8l(j diff --git a/vbanext/instance.cpp b/vbanext/instance.cpp index 1775b9e293..7dcb98ed3b 100644 --- a/vbanext/instance.cpp +++ b/vbanext/instance.cpp @@ -12935,6 +12935,7 @@ void Gigazoid_Init() } u32 *systemVideoFrameDest; +u32 *systemVideoFramePalette; s16 *systemAudioFrameDest; int *systemAudioFrameSamp; bool lagged; @@ -12948,18 +12949,19 @@ void systemDrawScreen (void) for (int i = 0; i < 240 * 160; i++) { u32 input = pix[i]; + /* u32 output = 0xff000000 | input << 9 & 0xf80000 | input << 6 & 0xf800 | input << 3 & 0xf8; + */ + u32 output = systemVideoFramePalette[input]; systemVideoFrameDest[i] = output; } systemVideoFrameDest = nullptr; + systemVideoFramePalette = nullptr; } -// TODO: fix up RTC so this is used -//uint32_t systemGetClock (void) { return 0; } - // called at regular intervals on sound clock void systemOnWriteDataToSoundBuffer(int16_t * finalWave, int length) { @@ -13313,10 +13315,11 @@ templatebool SyncBatteryRam(NewState *ns) CPUReset(); } - bool FrameAdvance(int input, u32 *videobuffer, s16 *audiobuffer, int *numsamp) + bool FrameAdvance(int input, u32 *videobuffer, s16 *audiobuffer, int *numsamp, u32 *videopalette) { joy = input; systemVideoFrameDest = videobuffer; + systemVideoFramePalette = videopalette; systemAudioFrameDest = audiobuffer; systemAudioFrameSamp = numsamp; lagged = true; @@ -13397,9 +13400,9 @@ EXPORT void Reset(Gigazoid *g) g->Reset(); } -EXPORT int FrameAdvance(Gigazoid *g, int input, u32 *videobuffer, s16 *audiobuffer, int *numsamp) +EXPORT int FrameAdvance(Gigazoid *g, int input, u32 *videobuffer, s16 *audiobuffer, int *numsamp, u32 *videopalette) { - return g->FrameAdvance(input, videobuffer, audiobuffer, numsamp); + return g->FrameAdvance(input, videobuffer, audiobuffer, numsamp, videopalette); } EXPORT int SaveRamSize(Gigazoid *g)