Skip to content

Commit 940dade

Browse files
committed
Added palette table selection for the Sega Genesis
1 parent 3d8f9b1 commit 940dade

10 files changed

+101
-5
lines changed

callback_gui.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "undo.h"
2727
#include "class_global.h"
2828
#include "palette.h"
29+
#include "runlua.h"
30+
#include "luaconfig.h"
2931
static const char* GPLv3="This program is free software: you can redistribute it and/or modify\n"
3032
"it under the terms of the GNU General Public License as published by\n"
3133
"the Free Software Foundation, either version 3 of the License, or\n"
@@ -123,17 +125,21 @@ static void palCopyConvert(unsigned cols){
123125
}
124126
void set_game_system(Fl_Widget*,void* selection){
125127
gameSystemEnum sel=(gameSystemEnum)(intptr_t)selection;
128+
const gameSystemEnum gold=currentProject->gameSystem;
126129
if(unlikely(sel==currentProject->gameSystem)){
127130
fl_alert("You are already in that mode");
128131
return;
129132
}
130133
pushProject();
134+
lua_getglobal(Lconf,"switchSystemBefore");
135+
lua_pushinteger(Lconf,gold);
136+
lua_pushinteger(Lconf,sel);
137+
runLuaFunc(Lconf,2,0);
131138
if(sel==NES){
132139
updateNesTab(0,false);
133140
updateNesTab(0,true);
134141
}
135142
unsigned msprt=window->metaspritesel->value();
136-
gameSystemEnum gold=currentProject->gameSystem;
137143
uint32_t sold=currentProject->subSystem;
138144
unsigned bd=currentProject->getBitdepthSys();
139145
unsigned bdold=bd;
@@ -425,6 +431,10 @@ void set_game_system(Fl_Widget*,void* selection){
425431
}
426432
}
427433
}
434+
lua_getglobal(Lconf,"switchSystemAfter");
435+
lua_pushinteger(Lconf,gold);
436+
lua_pushinteger(Lconf,sel);
437+
runLuaFunc(Lconf,2,0);
428438
window->redraw();
429439
}
430440
void trueColTileToggle(Fl_Widget*,void*){

config.lua

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ dofile "callbacks.lua"
2626
dofile "gui.lua"
2727
dofile "level.lua"
2828
dofile "project.lua"
29+
dofile "system.lua"
2930
--print('Code will execute here after the window is created but before the GUI controls are added')

gui.lua

+16-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,23 @@
1414
along with Retro Graphics Toolkit. If not, see <http://www.gnu.org/licenses/>.
1515
Copyright Sega16 (or whatever you wish to call me) (2012-2015)
1616
--]]
17+
function setPalTabCB(unused)
18+
project.setPalTab(palTabSel:value())
19+
palette.toRgbAll()
20+
rgt.damage()
21+
end
1722
function tabConfig(tab)
18-
if tab==rgt.levelTab then
23+
if tab==rgt.paletteTab then
24+
palTabSel=Fl_Choice.new(336, 464, 128, 24,"Palette table selection")
25+
palTabSel:align(FL.ALIGN_TOP)
26+
palTabSel:callback('setPalTabCB')
27+
palTabSel:add("HardwareMan's measured values")
28+
palTabSel:add('round(255*v\\/7)')
29+
palTabSel:add('Steps of 36')
30+
palTabSel:add('Steps of 32')
31+
palTabSel:labelsize(12)
32+
palTabSel:value(0)
33+
elseif tab==rgt.levelTab then
1934
initLevelEditor()
2035
end
2136
end

palette.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ void sortBy(unsigned type,bool perRow){
6262
}
6363
const uint8_t palTabGameGear[]={0,17,34,51,68,85,102,119,136,153,170,187,204,221,236,255};
6464
const uint8_t palTabMasterSystem[]={0,85,170,255};//From http://segaretro.org/Palette
65-
const uint8_t palTab[]= {0,49,87,119,146,174,206,255,0,27,49,71,87,103,119,130,130,146,157,174,190,206,228,255};//from http://gendev.spritesmind.net/forum/viewtopic.php?t=1389
66-
const uint8_t palTabEmu[]={0,36,72,108,144,180,216,252,0,18,36,54,72, 90,108,126,126,144,162,180,198,216,234,252};
65+
const uint8_t*palTab=palTabGenReal;
66+
const uint8_t*palTabPtr[]={palTabGenReal,palTabGen255div7,palTabGen36,palTabGen32};
67+
const uint8_t palTabGenReal[]= {0,49,87,119,146,174,206,255,0,27,49,71,87,103,119,130,130,146,157,174,190,206,228,255};//from http://gendev.spritesmind.net/forum/viewtopic.php?t=1389
68+
const uint8_t palTabGen255div7[]={0,36,73,109,146,182,219,255,0,18,36,55,73,91 ,109,128,128,146,164,182,200,219,237,255};
69+
const uint8_t palTabGen36[]= {0,36,72,108,144,180,216,252,0,18,36,54,72,90 ,108,126,126,144,162,180,198,216,234,252};
70+
const uint8_t palTabGen32[]= {0,32,64, 96,128,160,192,224,0,16,32,48,64,80 ,96 ,112,112,128,144,160,176,192,208,224};
6771
void set_palette_type_force(unsigned type){
6872
palTypeGen=type;
6973
//now reconvert all the colors

palette.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
#pragma once
1818
extern const uint8_t palTabGameGear[];
1919
extern const uint8_t palTabMasterSystem[];
20-
extern const uint8_t palTab[];
20+
extern const uint8_t*palTabPtr[];
21+
extern const uint8_t*palTab;
22+
extern const uint8_t palTabGenReal[];
23+
extern const uint8_t palTabGen255div7[];
24+
extern const uint8_t palTabGen36[];
25+
extern const uint8_t palTabGen32[];
2126
extern unsigned palTypeGen;
2227
void sortBy(unsigned type,bool perRow);
2328
void set_palette_type(void);

project.h

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "classtilemaps.h"
3030
#include "classlevel.h"
3131
#include "metasprites.h"
32+
#include "palette.h"
3233
#define currentProjectVersionNUM 8
3334
extern uint32_t curProjectID;
3435
enum luaLocEnum{PALETTE_C,TILEMAP_C,CHUNK_C,SPRITE_C,LEVEL_C,GLOBAL_C/*Not allowed for luaControl*/,CUSTOM_TAB_0/*And so on*/};
@@ -79,6 +80,16 @@ struct Project{/*!<Holds all data needed for a project based system for example
7980
int getBitdepthSys(void)const{
8081
return getBitdepthSysraw()+1;
8182
}
83+
int getPalTab(void)const{
84+
palTab=palTabPtr[(subSystem>>3)&7];
85+
return (subSystem>>3)&7;
86+
}
87+
void setPalTab(unsigned val){
88+
val&=7;
89+
subSystem&=~(7<<3);
90+
subSystem|=val<<3;
91+
palTab=palTabPtr[val];
92+
}
8293
unsigned szPerExtPalRow(void);
8394
unsigned extAttrTilesPerByte(void);
8495
bool isFixedPalette(void);

project.lua

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
--]]
1717
function switchProject()
1818
rgt.syncProject()
19+
palTabSel:value(project.getPalTab())--Fixes internal pointer
20+
if project.have(project.palMask)~=false then
21+
palette.toRgbAll()
22+
end
1923
if project.have(project.levelMask)~=false then
2024
layerSel:clear()
2125
for i=1,#level.names do

runlua.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ static int lua_palette_sortByHSL(lua_State*L){
667667
sortBy(luaL_optinteger(L,1,0),luaL_optinteger(L,2,0));
668668
return 0;
669669
}
670+
static int lua_palette_paletteToRgb(lua_State*L){
671+
currentProject->pal->paletteToRgb();
672+
return 0;
673+
}
670674
static const luaL_Reg lua_paletteAPI[]={
671675
{"getRGB",lua_palette_getRGB},
672676
{"setRGB",lua_palette_setRGB},
@@ -676,6 +680,7 @@ static const luaL_Reg lua_paletteAPI[]={
676680
{"maxInRow",lua_palette_maxInRow},
677681
{"getType",lua_palette_getType},
678682
{"sortByHSL",lua_palette_sortByHSL},
683+
{"toRgbAll",lua_palette_paletteToRgb},
679684
{0,0}
680685
};
681686
static unsigned inRangeTile(unsigned tile){
@@ -1194,6 +1199,14 @@ static int lua_project_update(lua_State*L){
11941199
updateProjectTablesLua(L);
11951200
return 0;
11961201
}
1202+
static int lua_project_getPalTab(lua_State*L){
1203+
lua_pushinteger(L,currentProject->getPalTab());
1204+
return 1;
1205+
}
1206+
static int lua_project_setPalTab(lua_State*L){
1207+
currentProject->setPalTab(luaL_optinteger(L,1,0));
1208+
return 0;
1209+
}
11971210
static const luaL_Reg lua_projectAPI[]={/*!This is the project table. The global project contains the following functions*/
11981211
{"have",lua_project_rgt_have},
11991212
{"haveOR",lua_project_rgt_haveOR},
@@ -1202,6 +1215,8 @@ static const luaL_Reg lua_projectAPI[]={/*!This is the project table. The global
12021215
{"update",lua_project_update},
12031216
{"getSettings",lua_project_getSettings},
12041217
{"setSettings",lua_project_setSettings},
1218+
{"getPalTab",lua_project_getPalTab},
1219+
{"setPalTab",lua_project_setPalTab},
12051220
{0,0}
12061221
};
12071222
#define arLen(ar) (sizeof(ar)/sizeof(ar[0]))
@@ -1354,6 +1369,8 @@ void updateProjectTablesLua(lua_State*L){
13541369
mkKeyunsigned(L,"gameSystem",currentProject->gameSystem);
13551370
mkKeyunsigned(L,"segaGenesis",segaGenesis);
13561371
mkKeyunsigned(L,"NES",NES);
1372+
mkKeyunsigned(L,"gameGear",gameGear);
1373+
mkKeyunsigned(L,"masterSystem",masterSystem);
13571374
mkKeyunsigned(L,"count",projects_count);
13581375
mkKeyunsigned(L,"curProjectID",curProjectID);
13591376
lua_setglobal(L, "project");

system.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum TMS9918SubSys{MODE_0,MODE_1,MODE_2,MODE_3};
2626
* These are not compatible when switching systems
2727
* For the Sega Genesis, Master System and Game Gear bits 1-0 contain bit depth 0 means 1 bit
2828
* For the Sega Genesis bit 2 sets if shadow highlight is enabled and bit 3 sets if highlight should be displayed instead of shadow
29+
* For the Sega Genesis bit 5-3 contain which palette table is used.
2930
* For the NES bit 1 contains bit depth 1 if 2 bit 0 if 1 bit
3031
* For the TMS9918 bits 1-0 contain the subsystem
3132
* For palette framebuffer bits 2-0 contain bit depth add 1 to get actual just like the others

system.lua

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--[[
2+
This file is part of Retro Graphics Toolkit
3+
4+
Retro Graphics Toolkit is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or any later version.
7+
8+
Retro Graphics Toolkit is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with Retro Graphics Toolkit. If not, see <http://www.gnu.org/licenses/>.
15+
Copyright Sega16 (or whatever you wish to call me) (2012-2015)
16+
--]]
17+
18+
function switchSystemBefore(old,new)
19+
if new==project.segaGenesis then
20+
palTabSel:show()
21+
else
22+
palTabSel:hide()
23+
end
24+
end
25+
26+
function switchSystemAfter(old,new)
27+
28+
end

0 commit comments

Comments
 (0)