M Makefile => Makefile +3 -0
@@ 60,6 60,8 @@ GRIT = $(DEVKITPRO_TOOLS_PATH)/grit
GRIT_FLAGS = -Zl -fts -fh -ff
ASEPRITE = aseprite
ASEPRITE_FLAGS = -b
+OPTIPNG = optipng
+OPTIPNG_FLAGS = --strip all -o7
MKDIR = mkdir -p
RMDIR = rm -rf # must work with non-empty directories
RMFILE = rm -f
@@ 88,6 90,7 @@ $(BUILD_DIR)/%.s: $(RESOURCE_DIR)/%.png
$(RESOURCE_DIR)/%.png: $(RESOURCE_DIR)/%.ase
$(ASEPRITE) $(ASEPRITE_FLAGS) $< --save-as $@
+ -$(OPTIPNG) $(OPTIPNG_FLAGS) $@
$(BUILD_DIR):
$(MKDIR) $(BUILD_DIR)
M configure => configure +2 -0
@@ 56,6 56,8 @@ check_and_emit_var 'GRIT' "${GRIT:-}"
check_and_emit_var 'GRIT_FLAGS' "${GRIT_FLAGS:-}"
check_and_emit_var 'ASEPRITE' "${ASEPRITE:-}"
check_and_emit_var 'ASEPRITE_FLAGS' "${ASEPRITE_FLAGS:-}"
+check_and_emit_var 'OPTIPNG' "${OPTIPNG:-}"
+check_and_emit_var 'OPTIPNG_FLAGS' "${OPTIPNG_FLAGS:-}"
check_and_emit_var 'MKDIR' "${MKDIR:-}"
check_and_emit_var 'RMDIR' "${RMDIR:-}"
check_and_emit_var 'RMFILE' "${RMFILE:-}"
M res/tiles.grit => res/tiles.grit +1 -1
@@ 1,1 1,1 @@
--g -m! -p -gB4
+-g -m! -p
M res/tiles.png => res/tiles.png +0 -0
M src/main.c => src/main.c +29 -8
@@ 18,11 18,11 @@ enum LineValue {
END,
};
-enum LineValue lines[20] = { [0] = START };
+IWRAM_DATA enum LineValue lines[20] = { [0] = START };
const size_t linesLen = sizeof(lines) / sizeof(lines[0]);
-size_t lineSelected = 0;
+IWRAM_DATA size_t lineSelected = 0;
-void
+static inline void
redrawLines(void)
{
size_t line = 0;
@@ 54,7 54,7 @@ redrawLines(void)
for (line++; line < linesLen; line++) toncset16(&se_mem[30][line*32 + 1], 0, 6);
}
-void
+static void
delLine(void)
{
if (lineSelected == 0 || lineSelected >= linesLen-1 || lines[lineSelected] == END) return;
@@ 63,7 63,7 @@ delLine(void)
if (lines[lineSelected] == END) lineSelected--;
}
-void
+static void
insertLine(enum LineValue val)
{
if (lineSelected >= linesLen-1 || lines[lineSelected] == END) return;
@@ 74,14 74,36 @@ insertLine(enum LineValue val)
if (lineSelected == linesLen-1) lineSelected--;
}
-int
+static void
+uncompressToVRAM(const void *src, void *dst, u8 inputBitDepth, u8 desiredBitDepth)
+{
+ // Save ourselves a lot of effort by uncompressing directly to VRAM if necessary
+ if (inputBitDepth == desiredBitDepth) {
+ LZ77UnCompVram(src, dst);
+ return;
+ }
+
+ // Read size from LZ77 header
+ const u16 size = ((*((u32 *)src)) >> 8) & 0x7FFFFF;
+ u8 place[size];
+ LZ77UnCompWram(src, &place);
+ BUP info = {
+ .src_len = size,
+ .src_bpp = inputBitDepth,
+ .dst_bpp = desiredBitDepth,
+ .dst_ofs = 0
+ };
+ BitUnPack(&place, dst, &info);
+}
+
+__attribute__((noreturn)) int
main(void)
{
irq_init(NULL);
irq_add(II_VBLANK, NULL);
VBlankIntrWait();
- LZ77UnCompVram(tilesTiles, &tile_mem[0][0]);
+ uncompressToVRAM(tilesTiles, &tile_mem[0][0], 1, 4);
LZ77UnCompVram(tilesPal, pal_bg_mem);
se_fill(&se_mem[31][0], SE_BUILD(0, 0, 0, 0));
@@ 114,5 136,4 @@ main(void)
else if (key_hit(KEY_RIGHT)) insertLine(RIGHT_ARROW);
redrawLines();
}
- return 0;
}