mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-02 16:42:38 +02:00
Switch to embedding cartridge templates and boot ROM as GResources
Also set up gdk-pixbuf in the Makefile, which will be used for image ops
This commit is contained in:
34
Makefile
34
Makefile
@@ -225,6 +225,12 @@ GIO_CFLAGS += -DG_ENABLE_DEBUG
|
|||||||
else
|
else
|
||||||
GIO_CFLAGS += -DG_DISABLE_ASSERT
|
GIO_CFLAGS += -DG_DISABLE_ASSERT
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
GDK_PIXBUF_CFLAGS := $(shell $(PKG_CONFIG) --cflags gdk-pixbuf-2.0)
|
||||||
|
GDK_PIXBUF_LDFLAGS := $(shell $(PKG_CONFIG) --libs gdk-pixbuf-2.0)
|
||||||
|
|
||||||
|
LIBPNG_CFLAGS := $(shell $(PKG_CONFIG) --cflags libpng)
|
||||||
|
LIBPNG_LDFLAGS := $(shell $(PKG_CONFIG) --libs libpng)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq (,$(PKG_CONFIG))
|
ifeq (,$(PKG_CONFIG))
|
||||||
@@ -338,7 +344,7 @@ endif
|
|||||||
|
|
||||||
cocoa: $(BIN)/SameBoy.app
|
cocoa: $(BIN)/SameBoy.app
|
||||||
quicklook: $(BIN)/SameBoy.qlgenerator
|
quicklook: $(BIN)/SameBoy.qlgenerator
|
||||||
xdg-thumbnailer: $(BIN)/XdgThumbnailer/sameboy-thumbnailer $(BIN)/XdgThumbnailer/cgb_boot_fast.bin $(patsubst QuickLook/%.png,$(BIN)/XdgThumbnailer/%.png,$(wildcard QuickLook/*.png))
|
xdg-thumbnailer: $(BIN)/XdgThumbnailer/sameboy-thumbnailer
|
||||||
sdl: $(SDL_TARGET) $(BIN)/SDL/dmg_boot.bin $(BIN)/SDL/mgb_boot.bin $(BIN)/SDL/cgb0_boot.bin $(BIN)/SDL/cgb_boot.bin $(BIN)/SDL/agb_boot.bin $(BIN)/SDL/sgb_boot.bin $(BIN)/SDL/sgb2_boot.bin $(BIN)/SDL/LICENSE $(BIN)/SDL/registers.sym $(BIN)/SDL/background.bmp $(BIN)/SDL/Shaders $(BIN)/SDL/Palettes
|
sdl: $(SDL_TARGET) $(BIN)/SDL/dmg_boot.bin $(BIN)/SDL/mgb_boot.bin $(BIN)/SDL/cgb0_boot.bin $(BIN)/SDL/cgb_boot.bin $(BIN)/SDL/agb_boot.bin $(BIN)/SDL/sgb_boot.bin $(BIN)/SDL/sgb2_boot.bin $(BIN)/SDL/LICENSE $(BIN)/SDL/registers.sym $(BIN)/SDL/background.bmp $(BIN)/SDL/Shaders $(BIN)/SDL/Palettes
|
||||||
bootroms: $(BIN)/BootROMs/agb_boot.bin $(BIN)/BootROMs/cgb_boot.bin $(BIN)/BootROMs/cgb0_boot.bin $(BIN)/BootROMs/dmg_boot.bin $(BIN)/BootROMs/mgb_boot.bin $(BIN)/BootROMs/sgb_boot.bin $(BIN)/BootROMs/sgb2_boot.bin
|
bootroms: $(BIN)/BootROMs/agb_boot.bin $(BIN)/BootROMs/cgb_boot.bin $(BIN)/BootROMs/cgb0_boot.bin $(BIN)/BootROMs/dmg_boot.bin $(BIN)/BootROMs/mgb_boot.bin $(BIN)/BootROMs/sgb_boot.bin $(BIN)/BootROMs/sgb2_boot.bin
|
||||||
tester: $(TESTER_TARGET) $(BIN)/tester/dmg_boot.bin $(BIN)/tester/cgb_boot.bin $(BIN)/tester/agb_boot.bin $(BIN)/tester/sgb_boot.bin $(BIN)/tester/sgb2_boot.bin
|
tester: $(TESTER_TARGET) $(BIN)/tester/dmg_boot.bin $(BIN)/tester/cgb_boot.bin $(BIN)/tester/agb_boot.bin $(BIN)/tester/sgb_boot.bin $(BIN)/tester/sgb2_boot.bin
|
||||||
@@ -377,7 +383,7 @@ IOS_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(IOS_SOURCES))
|
|||||||
QUICKLOOK_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(QUICKLOOK_SOURCES))
|
QUICKLOOK_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(QUICKLOOK_SOURCES))
|
||||||
SDL_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(SDL_SOURCES))
|
SDL_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(SDL_SOURCES))
|
||||||
TESTER_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(TESTER_SOURCES))
|
TESTER_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(TESTER_SOURCES))
|
||||||
XDG_THUMBNAILER_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(XDG_THUMBNAILER_SOURCES)) $(OBJ)/XdgThumbnailer/interface.c.o
|
XDG_THUMBNAILER_OBJECTS := $(patsubst %,$(OBJ)/%.o,$(XDG_THUMBNAILER_SOURCES)) $(OBJ)/XdgThumbnailer/interface.c.o $(OBJ)/XdgThumbnailer/resources.c.o
|
||||||
|
|
||||||
lib: $(PUBLIC_HEADERS)
|
lib: $(PUBLIC_HEADERS)
|
||||||
|
|
||||||
@@ -423,18 +429,26 @@ $(OBJ)/SDL/%.c.o: SDL/%.c
|
|||||||
|
|
||||||
$(OBJ)/XdgThumbnailer/%.c.o: XdgThumbnailer/%.c
|
$(OBJ)/XdgThumbnailer/%.c.o: XdgThumbnailer/%.c
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
$(CC) $(CFLAGS) $(GIO_CFLAGS) -DG_LOG_DOMAIN='"sameboy-thumbnailer"' -c $< -o $@
|
$(CC) $(CFLAGS) $(GIO_CFLAGS) $(GDK_PIXBUF_CFLAGS) $(LIBPNG_CFLAGS) -DG_LOG_DOMAIN='"sameboy-thumbnailer"' -c $< -o $@
|
||||||
# Make sure not to attempt compiling this before generating the interface code.
|
# Make sure not to attempt compiling this before generating the interface code.
|
||||||
$(OBJ)/XdgThumbnailer/main.c.o: $(OBJ)/XdgThumbnailer/interface.h
|
$(OBJ)/XdgThumbnailer/main.c.o: $(OBJ)/XdgThumbnailer/interface.h
|
||||||
|
# Make sure not to attempt compiling this before generating the resource code.
|
||||||
|
$(OBJ)/XdgThumbnailer/emulate.c.o: $(OBJ)/XdgThumbnailer/resources.h
|
||||||
# Silence warnings for this. It is code generated not by us, so we do not want `-Werror` to break
|
# Silence warnings for this. It is code generated not by us, so we do not want `-Werror` to break
|
||||||
# compilation with some version of the generator and/or compiler.
|
# compilation with some version of the generator and/or compiler.
|
||||||
$(OBJ)/XdgThumbnailer/interface.c.o: $(OBJ)/XdgThumbnailer/interface.c
|
$(OBJ)/XdgThumbnailer/%.c.o: $(OBJ)/XdgThumbnailer/%.c
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
$(CC) $(CFLAGS) $(GIO_CFLAGS) -DG_LOG_DOMAIN='"sameboy-thumbnailer"' -w -c $< -o $@
|
$(CC) $(CFLAGS) $(GIO_CFLAGS) $(GDK_PIXBUF_CFLAGS) $(LIBPNG_CFLAGS) -DG_LOG_DOMAIN='"sameboy-thumbnailer"' -w -c $< -o $@
|
||||||
|
|
||||||
$(OBJ)/XdgThumbnailer/interface.c $(OBJ)/XdgThumbnailer/interface.h: XdgThumbnailer/interface.xml
|
$(OBJ)/XdgThumbnailer/interface.c $(OBJ)/XdgThumbnailer/interface.h: XdgThumbnailer/interface.xml
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
gdbus-codegen --c-generate-autocleanup none --c-namespace Thumbnailer --interface-prefix org.freedesktop.thumbnails. --generate-c-code $(OBJ)/XdgThumbnailer/interface $<
|
gdbus-codegen --c-generate-autocleanup none --c-namespace Thumbnailer --interface-prefix org.freedesktop.thumbnails. --generate-c-code $(OBJ)/XdgThumbnailer/interface $<
|
||||||
|
|
||||||
|
$(OBJ)/XdgThumbnailer/resources.c $(OBJ)/XdgThumbnailer/resources.h: %: XdgThumbnailer/resources.gresource.xml $(BIN)/BootROMs/cgb_boot_fast.bin
|
||||||
|
-@$(MKDIR) -p $(dir $@)
|
||||||
|
CC=$(CC) glib-compile-resources --dependency-file $@.mk --generate-phony-targets --generate --target $@ $<
|
||||||
|
-include $(OBJ)/XdgThumbnailer/resources.c.mk $(OBJ)/XdgThumbnailer/resources.h.mk
|
||||||
|
|
||||||
$(OBJ)/OpenDialog/%.c.o: OpenDialog/%.c
|
$(OBJ)/OpenDialog/%.c.o: OpenDialog/%.c
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
$(CC) $(CFLAGS) $(SDL_CFLAGS) $(GL_CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(SDL_CFLAGS) $(GL_CFLAGS) -c $< -o $@
|
||||||
@@ -560,7 +574,7 @@ $(BIN)/SameBoy.qlgenerator/Contents/Resources/cgb_boot_fast.bin: $(BIN)/BootROMs
|
|||||||
|
|
||||||
$(BIN)/XdgThumbnailer/sameboy-thumbnailer: $(CORE_OBJECTS) $(XDG_THUMBNAILER_OBJECTS)
|
$(BIN)/XdgThumbnailer/sameboy-thumbnailer: $(CORE_OBJECTS) $(XDG_THUMBNAILER_OBJECTS)
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
$(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) $(GIO_LDFLAGS)
|
$(CC) $^ -o $@ $(LDFLAGS) $(GIO_LDFLAGS) $(GDK_PIXBUF_LDFLAGS) $(LIBPNG_LDFLAGS)
|
||||||
|
|
||||||
# SDL Port
|
# SDL Port
|
||||||
|
|
||||||
@@ -627,14 +641,6 @@ $(BIN)/SameBoy-iOS.app/%.bin: $(BOOTROMS_DIR)/%.bin
|
|||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
cp -f $< $@
|
cp -f $< $@
|
||||||
|
|
||||||
$(BIN)/XdgThumbnailer/%.png: QuickLook/%.png
|
|
||||||
-@$(MKDIR) -p $(dir $@)
|
|
||||||
cp -f $< $@
|
|
||||||
|
|
||||||
$(BIN)/XdgThumbnailer/%.bin: $(BOOTROMS_DIR)/%.bin
|
|
||||||
-@$(MKDIR) -p $(dir $@)
|
|
||||||
cp -f $< $@
|
|
||||||
|
|
||||||
$(BIN)/SDL/%.bin: $(BOOTROMS_DIR)/%.bin
|
$(BIN)/SDL/%.bin: $(BOOTROMS_DIR)/%.bin
|
||||||
-@$(MKDIR) -p $(dir $@)
|
-@$(MKDIR) -p $(dir $@)
|
||||||
cp -f $< $@
|
cp -f $< $@
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
#include "emulate.h"
|
#include "emulate.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "Core/gb.h"
|
#include "Core/gb.h"
|
||||||
#include "Core/memory.h"
|
|
||||||
#include "glibconfig.h"
|
// Auto-generated via `glib-compile-resources` from `resources.gresource.xml`.
|
||||||
|
#include "build/obj/XdgThumbnailer/resources.h"
|
||||||
|
|
||||||
#define NB_FRAMES_TO_EMULATE (60 * 10)
|
#define NB_FRAMES_TO_EMULATE (60 * 10)
|
||||||
|
|
||||||
@@ -67,7 +69,15 @@ unsigned emulate(enum FileKind kind, unsigned char const *rom, size_t rom_size,
|
|||||||
GB_gameboy_t gb;
|
GB_gameboy_t gb;
|
||||||
GB_init(&gb, GB_MODEL_CGB_E);
|
GB_init(&gb, GB_MODEL_CGB_E);
|
||||||
|
|
||||||
GB_load_boot_rom_from_buffer(&gb, (unsigned char const *)boot_rom, sizeof(boot_rom));
|
GError *error = NULL;
|
||||||
|
GBytes *boot_rom = g_resource_lookup_data(resources_get_resource(), "/thumbnailer/cgb_boot_fast.bin", G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
|
||||||
|
g_assert_no_error(error);
|
||||||
|
size_t boot_rom_size;
|
||||||
|
unsigned char const *boot_rom_data = g_bytes_get_data(boot_rom, &boot_rom_size);
|
||||||
|
g_assert_cmpuint(boot_rom_size, ==, BOOT_ROM_SIZE);
|
||||||
|
GB_load_boot_rom_from_buffer(&gb, boot_rom_data, boot_rom_size);
|
||||||
|
g_bytes_unref(boot_rom);
|
||||||
|
|
||||||
if (kind == KIND_ISX) {
|
if (kind == KIND_ISX) {
|
||||||
g_assert_not_reached(); // TODO: implement GB_load_isx_from_buffer
|
g_assert_not_reached(); // TODO: implement GB_load_isx_from_buffer
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,6 @@ int main(int argc, char const *argv[])
|
|||||||
// unsigned active_worker_threads = 0;
|
// unsigned active_worker_threads = 0;
|
||||||
// Create the task queue *before* starting to accept tasks from D-Bus.
|
// Create the task queue *before* starting to accept tasks from D-Bus.
|
||||||
init_tasks();
|
init_tasks();
|
||||||
load_boot_rom();
|
|
||||||
// Likewise, create the main loop before then, so it can be aborted even before entering it.
|
// Likewise, create the main loop before then, so it can be aborted even before entering it.
|
||||||
main_loop = g_main_loop_new(NULL, FALSE);
|
main_loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
|
@@ -3,9 +3,9 @@
|
|||||||
// As defined in the thumbnailer spec.
|
// As defined in the thumbnailer spec.
|
||||||
enum ErrorCode {
|
enum ErrorCode {
|
||||||
ERROR_UNKNOWN_SCHEME_OR_MIME,
|
ERROR_UNKNOWN_SCHEME_OR_MIME,
|
||||||
ERROR_SPECIALIZED_THUMBNAILER_CONNECTION_FAILED,
|
ERROR_SPECIALIZED_THUMBNAILER_CONNECTION_FAILED, // Not applicable.
|
||||||
ERROR_INVALID_DATA,
|
ERROR_INVALID_DATA, // Any file can be decoded as a GB ROM, apparently!
|
||||||
ERROR_THUMBNAIILING_THUMBNAIL,
|
ERROR_THUMBNAIILING_THUMBNAIL, // We defer checking this to the generic thumbnailer.
|
||||||
ERROR_COULD_NOT_WRITE,
|
ERROR_COULD_NOT_WRITE,
|
||||||
ERROR_UNSUPPORTED_FLAVOR,
|
ERROR_UNSUPPORTED_FLAVOR,
|
||||||
};
|
};
|
||||||
|
9
XdgThumbnailer/resources.gresource.xml
Normal file
9
XdgThumbnailer/resources.gresource.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gresources>
|
||||||
|
<gresource prefix="/thumbnailer">
|
||||||
|
<file alias="CartridgeTemplate.png">QuickLook/CartridgeTemplate.png</file>
|
||||||
|
<file alias="ColorCartridgeTemplate.png">QuickLook/ColorCartridgeTemplate.png</file>
|
||||||
|
<file alias="UniversalCartridgeTemplate.png">QuickLook/UniversalCartridgeTemplate.png</file>
|
||||||
|
<file alias="cgb_boot_fast.bin">build/bin/BootROMs/cgb_boot_fast.bin</file>
|
||||||
|
</gresource>
|
||||||
|
</gresources>
|
@@ -11,6 +11,20 @@
|
|||||||
|
|
||||||
#define THUMBNAILING_ERROR_DOMAIN (g_quark_from_static_string("thumbnailing"))
|
#define THUMBNAILING_ERROR_DOMAIN (g_quark_from_static_string("thumbnailing"))
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
|
enum CartridgeType {
|
||||||
|
CART_DMG_ONLY,
|
||||||
|
CART_DUAL,
|
||||||
|
CART_CGB_ONLY,
|
||||||
|
};
|
||||||
|
|
||||||
|
void load_cartridge_images(void) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
struct TaskData {
|
struct TaskData {
|
||||||
char *contents;
|
char *contents;
|
||||||
size_t length;
|
size_t length;
|
||||||
@@ -25,6 +39,8 @@ static void destroy_task_data(void *data)
|
|||||||
g_slice_free(struct TaskData, task_data);
|
g_slice_free(struct TaskData, task_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
static void generate_thumbnail(GTask *task, void *source_object, void *data,
|
static void generate_thumbnail(GTask *task, void *source_object, void *data,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
@@ -33,8 +49,21 @@ static void generate_thumbnail(GTask *task, void *source_object, void *data,
|
|||||||
uint32_t screen[160 * 144];
|
uint32_t screen[160 * 144];
|
||||||
unsigned cgb_flag = emulate(task_data->kind, (unsigned char const *)task_data->contents,
|
unsigned cgb_flag = emulate(task_data->kind, (unsigned char const *)task_data->contents,
|
||||||
task_data->length, screen);
|
task_data->length, screen);
|
||||||
// TODO: generate the thumbnail from `screen` and `cgb_flag`.
|
|
||||||
(void)cgb_flag;
|
// Generate the thumbnail from `screen` and `cgb_flag`.
|
||||||
|
enum CartridgeType type;
|
||||||
|
switch (cgb_flag) {
|
||||||
|
case 0xC0:
|
||||||
|
type = CART_CGB_ONLY;
|
||||||
|
break;
|
||||||
|
case 0x80:
|
||||||
|
type = CART_DUAL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
type = CART_DMG_ONLY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
(void)type;
|
||||||
|
|
||||||
g_task_return_boolean(task, TRUE);
|
g_task_return_boolean(task, TRUE);
|
||||||
g_object_unref(task);
|
g_object_unref(task);
|
||||||
@@ -69,6 +98,8 @@ static void on_file_ready(GObject *source_object, GAsyncResult *res, void *user_
|
|||||||
g_task_run_in_thread(task, generate_thumbnail);
|
g_task_run_in_thread(task, generate_thumbnail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- */
|
||||||
|
|
||||||
static void on_thumbnailing_end(GObject *source_object, GAsyncResult *res, void *user_data)
|
static void on_thumbnailing_end(GObject *source_object, GAsyncResult *res, void *user_data)
|
||||||
{
|
{
|
||||||
// TODO: start a new thread if some task is pending.
|
// TODO: start a new thread if some task is pending.
|
||||||
|
Reference in New Issue
Block a user