makefile stuff to generate bins from graphics automatically.

This commit is contained in:
Moon Man 2025-01-25 09:48:56 -05:00
parent 6958cec5ac
commit 51ae799d93
4 changed files with 49 additions and 11 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@
*.sav
*.bak
.DS_Store
build/
build/
generated/

View File

@ -26,7 +26,8 @@ SOURCES := source
INCLUDES := include
DATA := data
SOUND := sound
GRAPHICS := graphics
GENERATED := generated
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
@ -68,7 +69,8 @@ export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \
$(CURDIR)/$(GENERATED)
export DEPSDIR := $(CURDIR)/$(BUILD)
@ -83,6 +85,15 @@ ifneq ($(strip $(SOUND)),)
BINFILES += soundbank.bin
endif
ifneq ($(strip $(GRAPHICS)),)
export GRAPHICSFILES := $(foreach dir,$(notdir $(wildcard $(GRAPHICS)/*.png)),$(CURDIR)/$(GRAPHICS)/$(dir))
endif
# Add generated bin files if they exist
ifneq ($(wildcard $(GENERATED)/*.bin),)
BINFILES += $(notdir $(wildcard $(GENERATED)/*.bin))
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
@ -111,11 +122,11 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean
.PHONY: $(BUILD) clean process-images process-binaries
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
$(BUILD): process-images process-binaries
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
@cp $(SOURCES)/*.h $(BUILD)/ 2>/dev/null || true
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
@ -125,6 +136,32 @@ clean:
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
process-images: $(GRAPHICSFILES)
@[ -d $(GENERATED) ] || mkdir -p $(GENERATED)
@echo "Processing ALL images"
@for img in $^; do \
depth=$$(magick identify -format "%[depth]" $$img); \
base=$$(basename $$img .png); \
if [ "$$depth" = "8" ]; then \
$(MAKE) $${base}_8.bin; \
else \
echo "Processing image $$base with depth $$depth"; \
$(MAKE) $${base}_16.bin; \
fi \
done
# Rule for 8-bit images
%_8.bin %_8.h: %.png
@echo "Processing 8-bit image $<"
@magick $< -channel-fx "red=>blue,blue=>red" $(GENERATED)/$*_8.temp.png
@grit $(GENERATED)/$*_8.temp.png -gb -gB8 -p -ftb -o $(GENERATED)/$*_8
@rm $(GENERATED)/$*_8.temp.png
# Rule for 16-bit images
%_16.bin %_16.h: %.png
@echo "Processing 16-bit image $<"
@grit $< -gb -gB16 -ftb -o $(GENERATED)/$*_16
#---------------------------------------------------------------------------------
else
@ -148,6 +185,7 @@ $(OFILES_SOURCES) : $(HFILES)
#---------------------------------------------------------------------------------
soundbank.bin soundbank.h : $(MODFILES) $(SFXFILES)
#---------------------------------------------------------------------------------
@echo "Generating soundbank..."
@mmutil $^ -osoundbank.bin -hsoundbank.h
#---------------------------------------------------------------------------------

BIN
graphics/splash.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -9,9 +9,8 @@
#include <maxmod.h>
#include <mm_types.h>
// #include "intro_bin.h"
#include "intro-8bit_img_bin.h"
#include "intro-8bit_pal_bin.h"
#include "splash_8_img_bin.h"
#include "splash_8_pal_bin.h"
// Define any soundbank includes here
#include "soundbank.h"
@ -72,9 +71,9 @@ void loadIntroScreen(void) {
// Load the palette
// Palette size needs to be in 16-bit units (divide by 2)
DMA3COPY(intro_8bit_pal_bin, BG_PALETTE, intro_8bit_pal_bin_size >> 1);
DMA3COPY(splash_8_pal_bin, BG_PALETTE, splash_8_pal_bin_size >> 1);
// Copy image data to first frame buffer
// Image size needs to be in 16-bit units (divide by 2)
DMA3COPY(intro_8bit_img_bin, (void*)VRAM, intro_8bit_img_bin_size >> 1);
DMA3COPY(splash_8_img_bin, (void*)VRAM, splash_8_img_bin_size >> 1);
}