Skip to content

Commit

Permalink
GB: use lightest palette color for grid, sdl2-only
Browse files Browse the repository at this point in the history
requires gambatte patch to write the color to "/tmp/dmg_grid_color" which minarch watches for changes to after the "palette" option changes
  • Loading branch information
Shaun Inman committed Dec 6, 2024
1 parent b456975 commit 5051ace
Show file tree
Hide file tree
Showing 12 changed files with 576 additions and 209 deletions.
22 changes: 19 additions & 3 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@ Changes
BASE

- tg_040: fixed rtc bug in MinUI.pak
- all: GB.pak now uses the first/lightest palette color for the Grid effect (SDL2 only)

EXTRAS

- tg_040: fixed rtc bug in Clock.pak
- all: Super Game Boy borders are now optional

---

gambatte
light grid that matches palette
proof of concept added to tg5040 with patch for gambatte core
added patch
need to rebuild all gambatte cores (manually because building cores is disabled locally)
need to copy effect color changes to other sdl2 platforms
+ magicmini (took longer than expected because of faux-brightness)
+ my282
+ rg28xx (rotation/resolution is same as my282 but the math isn't adding up here?! fffffuuuuuu)
+ rgb30?
people are already asking for more
light grid for gbc (looks awful)
someone will ask for the same for ngp/ngpc
this is really entering shader territory...
started dabbling in OpenGL and shaders
hit a wall

minput
seems to be designed top,left aligned for 640x480

Expand All @@ -23,9 +42,6 @@ it's time to retire some supported devices
rgb30
finish updating README (don't forget BASE readme!)

gambatte
can I write the lightest palette value to /tmp so I can use it for gridlines for GB?

rg_xx
usb controller
look into SDL2 controller API
Expand Down
1 change: 1 addition & 0 deletions workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void GFX_sync(void) {
}

FALLBACK_IMPLEMENTATION int PLAT_supportsOverscan(void) { return 0; }
FALLBACK_IMPLEMENTATION void PLAT_setEffectColor(int next_color) { }

int GFX_truncateText(TTF_Font* font, const char* in_name, char* out_name, int max_width, int padding) {
int text_width;
Expand Down
2 changes: 2 additions & 0 deletions workspace/all/common/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ SDL_Surface* GFX_init(int mode);
#define GFX_setScaleClip PLAT_setVideoScaleClip // (int x, int y, int width, int height)
#define GFX_setNearestNeighbor PLAT_setNearestNeighbor // (int enabled)
#define GFX_setSharpness PLAT_setSharpness // (int sharpness)
#define GFX_setEffectColor PLAT_setEffectColor // (int color)
#define GFX_setEffect PLAT_setEffect // (int effect)
void GFX_setMode(int mode);
int GFX_hdmiChanged(void);
Expand Down Expand Up @@ -302,6 +303,7 @@ SDL_Surface* PLAT_resizeVideo(int w, int h, int pitch);
void PLAT_setVideoScaleClip(int x, int y, int width, int height);
void PLAT_setNearestNeighbor(int enabled);
void PLAT_setSharpness(int sharpness);
void PLAT_setEffectColor(int color);
void PLAT_setEffect(int effect);
void PLAT_vsync(int remaining);
scaler_t PLAT_getScaler(GFX_Renderer* renderer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git forkSrcPrefix/libgambatte/libretro/libretro.cpp forkDstPrefix/libgambatte/libretro/libretro.cpp
index 74b2b1dd0bb3f76b77a616ebac2485ba09565467..caa2d1ef21235ffb09ad22440266495d99d9be4e 100644
--- forkSrcPrefix/libgambatte/libretro/libretro.cpp
+++ forkDstPrefix/libgambatte/libretro/libretro.cpp
@@ -2387,6 +2387,12 @@ static void check_variables(bool startup)
{
rgb32 = gb.gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]);
gb.setDmgPaletteColor(palnum, colornum, rgb32);
+
+ if (palnum==0 && colornum==0) {
+ char cmd[32];
+ sprintf(cmd, "echo %i > /tmp/dmg_grid_color", rgb32);
+ system(cmd);
+ }
}
}
}
40 changes: 39 additions & 1 deletion workspace/all/minarch/minarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,34 @@ static void Config_restore(void) {
renderer.dst_p = 0;
}

///////////////////////////////
static struct Special {
int palette_updated;
} special;
static void Special_updatedDMGPalette(int frames) {
// LOG_info("Special_updatedDMGPalette(%i)\n", frames);
special.palette_updated = frames; // must wait a few frames
}
static void Special_refreshDMGPalette(void) {
special.palette_updated -= 1;
if (special.palette_updated>0) return;

int rgb = getInt("/tmp/dmg_grid_color");
GFX_setEffectColor(rgb);
}
static void Special_init(void) {
if (special.palette_updated>1) special.palette_updated = 1;
// else if (exactMatch((char*)core.tag, "GBC")) {
// putInt("/tmp/dmg_grid_color",0xF79E);
// special.palette_updated = 1;
// }
}
static void Special_render(void) {
if (special.palette_updated) Special_refreshDMGPalette();
}
static void Special_quit(void) {
system("rm /tmp/dmg_grid_color > /dev/null");
}
///////////////////////////////

static int Option_getValueIndex(Option* item, const char* value) {
Expand Down Expand Up @@ -1537,6 +1565,8 @@ static void OptionList_setOptionRawValue(OptionList* list, const char* key, int
list->changed = 1;
// LOG_info("\tRAW SET %s (%s) TO %s (%s)\n", item->name, item->key, item->labels[item->value], item->values[item->value]);
// if (list->on_set) list->on_set(list, key);

if (exactMatch((char*)core.tag, "GB") && containsString(item->key, "palette")) Special_updatedDMGPalette(3); // from options
}
else LOG_info("unknown option %s \n", key);
}
Expand All @@ -1545,8 +1575,10 @@ static void OptionList_setOptionValue(OptionList* list, const char* key, const c
if (item) {
Option_setValue(item, value);
list->changed = 1;
LOG_info("\tSET %s (%s) TO %s (%s)\n", item->name, item->key, item->labels[item->value], item->values[item->value]);
// LOG_info("\tSET %s (%s) TO %s (%s)\n", item->name, item->key, item->labels[item->value], item->values[item->value]);
// if (list->on_set) list->on_set(list, key);

if (exactMatch((char*)core.tag, "GB") && containsString(item->key, "palette")) Special_updatedDMGPalette(2); // from core
}
else LOG_info("unknown option %s \n", key);
}
Expand Down Expand Up @@ -2683,6 +2715,8 @@ static void selectScaler(int src_w, int src_h, int src_p) {
static void video_refresh_callback_main(const void *data, unsigned width, unsigned height, size_t pitch) {
// return;

Special_render();

// static int tmp_frameskip = 0;
// if ((tmp_frameskip++)%2) return;

Expand Down Expand Up @@ -4652,6 +4686,8 @@ int main(int argc , char* argv[]) {
GFX_clearAll();
GFX_flip(screen);

Special_init(); // after config

sec_start = SDL_GetTicks();
while (!quit) {
GFX_startFrame();
Expand Down Expand Up @@ -4721,6 +4757,8 @@ int main(int argc , char* argv[]) {

Config_quit();

Special_quit();

MSG_quit();
PWR_quit();
VIB_quit();
Expand Down
5 changes: 1 addition & 4 deletions workspace/all/minui/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ CC = $(CROSS_COMPILE)gcc
CFLAGS = $(ARCH) -fomit-frame-pointer
CFLAGS += $(INCDIR) -DPLATFORM=\"$(PLATFORM)\" -DUSE_$(SDL) -Ofast -std=gnu99
LDFLAGS = -ldl -lmsettings $(LIBS) -l$(SDL) -l$(SDL)_image -l$(SDL)_ttf -lpthread -lm -lz
# CFLAGS += -Wall -Wno-unused-variable -Wno-unused-function -Wno-format-overflow
# CFLAGS += -fsanitize=address -fno-common
# LDFLAGS += -lasan

PRODUCT= build/$(PLATFORM)/$(TARGET).elf

Expand All @@ -40,4 +37,4 @@ clean:
rm -f $(PRODUCT)

$(PREFIX)/include/msettings.h:
cd /root/workspace/$(PLATFORM)/libmsettings && make
cd /root/workspace/$(PLATFORM)/libmsettings && make
Loading

0 comments on commit 5051ace

Please sign in to comment.