diff --git a/output/luaScripts/ShowPalette.lua b/output/luaScripts/ShowPalette.lua new file mode 100644 index 00000000..1f2805c2 --- /dev/null +++ b/output/luaScripts/ShowPalette.lua @@ -0,0 +1,62 @@ +-- Show Palette +-- Click for other palette boxes +-- P00 - P3F are NES palette values. +-- P40 - P7F are LUA palette values. + +-- True or False +ShowTextLabels=true; + +function DecToHex(numberin) + if (numberin < 16) then + return string.format("0%X",numberin); + else + return string.format("%X",numberin); + end; +end; + +function text(x,y,str,text,back) + if (x > 0 and x < 255 and y > 0 and y < 240) then + gui.text(x,y,str,text,back); + end; +end; + +local ButtonWasPressed; +local CurrentPaletteDisplay=0; + + + +while(true) do + +FCEU.frameadvance(); + +for i = 0, 7 do + gui.box(0 + (30*i),0,29 + (30*i),29,"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8))); + gui.box(0 + (30*i),30,29 + (30*i),59,"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8))); + gui.box(0 + (30*i),60,29 + (30*i),89,"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8))); + gui.box(0 + (30*i),90,29 + (30*i),119,"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8)),"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8))); + if(ShowTextLabels == true) then + text(6 + (30*i),11,"P" .. DecToHex(0+i+(CurrentPaletteDisplay * 8))) + text(6 + (30*i),41,"P" .. DecToHex(16+i+(CurrentPaletteDisplay * 8))) + text(6 + (30*i),71,"P" .. DecToHex(32+i+(CurrentPaletteDisplay * 8))) + text(6 + (30*i),101,"P" .. DecToHex(48+i+(CurrentPaletteDisplay * 8))) + end; +end; + +mousestuff = input.get() + +if (not ButtonWasPressed) then + if (mousestuff.leftclick) then + ButtonWasPressed = 1; + CurrentPaletteDisplay=CurrentPaletteDisplay+1; + if (CurrentPaletteDisplay == 2) then + CurrentPaletteDisplay=8; + end; + if (CurrentPaletteDisplay == 10) then + CurrentPaletteDisplay=0; + end; + end; +end + +ButtonWasPressed = (mousestuff.leftclick); + +end; \ No newline at end of file diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp index 4b2cdec8..45790c87 100644 --- a/src/lua-engine.cpp +++ b/src/lua-engine.cpp @@ -3013,6 +3013,7 @@ s_colorMapping [] = * offset to a RGB32 colour. Several encodings are supported. * The user may construct their own RGB value, given a simple colour name, * or an HTML-style "#09abcd" colour. 16 bit reduction doesn't occur at this time. + * NES palettes added with notation "P00" to "P3F". "P40" to "P7F" denote LUA palettes. */ static inline bool str2colour(uint32 *colour, lua_State *L, const char *str) { if (str[0] == '#') { @@ -3025,6 +3026,29 @@ static inline bool str2colour(uint32 *colour, lua_State *L, const char *str) { *colour = color; return true; } + else if (str[0] == 'P') { + uint8 palette; + uint8 tr, tg, tb; + + if (strlen(str+1) == 2) { + palette = ((hex2int(L, str[1]) * 0x10) + hex2int(L, str[2])); + } else if (strlen(str+1) == 1) { + palette = (hex2int(L, str[1])); + } else { + luaL_error(L, "palettes are defined with P## hex notion"); + return false; + } + + if (palette > 0x7F) { + luaL_error(L, "palettes range from P00 to P7F"); + return false; + } + + FCEUD_GetPalette(palette + 0x80, &tr, &tg, &tb); + // Feeding it RGBA, because it will spit out the right value for me + *colour = LUA_BUILD_PIXEL(tr, tg, tb, 0xFF); + return true; + } else { if(!strnicmp(str, "rand", 4)) { *colour = ((rand()*255/RAND_MAX) << 8) | ((rand()*255/RAND_MAX) << 16) | ((rand()*255/RAND_MAX) << 24) | 0xFF; diff --git a/vc/Help/fceux.hnd b/vc/Help/fceux.hnd index acc3dacf..c55252b9 100644 Binary files a/vc/Help/fceux.hnd and b/vc/Help/fceux.hnd differ