~nytpu/gba-keystroke-programming-demo

1acfa1e615ce46e33f7e56aeff09ebe4033c03ce — nytpu 3 months ago aa39dbf
fix resource building
4 files changed, 55 insertions(+), 13 deletions(-)

M Makefile
M configure
M include/game.h
M src/main.c
M Makefile => Makefile +26 -7
@@ 27,30 27,39 @@ DEBUG = 1

SOURCE_DIR = src
HEADER_DIR = include
RESOURCE_DIR = res
BUILD_DIR = build
DEPS_DIR = deps

SOURCE_FILES := $(call rwildcard,$(SOURCE_DIR),*.c) $(call rwildcard,$(SOURCE_DIR),*.s)
OBJECT_FILES := $(subst $(SOURCE_DIR),$(BUILD_DIR),$(patsubst %.c,%.o,$(patsubst %.s,%.o,$(SOURCE_FILES))))
RESOURCE_FILES := $(call rwildcard,$(RESOURCE_DIR),*.png) $(call rwildcard,$(RESOURCE_DIR),*.ase)
OBJECT_FILES := $(sort $(subst $(SOURCE_DIR),$(BUILD_DIR),$(patsubst %.c,%.o,$(patsubst %.s,%.o,$(SOURCE_FILES)))))
RESOURCE_OBJECT_FILES := $(sort $(subst $(RESOURCE_DIR),$(BUILD_DIR),$(patsubst %.png,%.o,$(patsubst %.ase,%.o,$(RESOURCE_FILES)))))
DEPENDENCY_FILES = $(SUBST $(BUILD_DIR),$(DEPS_DIR),$(OBJECT_FILES:.o=.d))

PLATFORM_FLAGS = -march=armv4t -mcpu=arm7tdmi -mthumb -mthumb-interwork

DEVKITARM_PATH = $(DEVKITPRO_PATH)/devkitARM
DEVKITPRO_TOOLS_PATH = $(DEVKITPRO)/tools/bin
DEVKITPRO_TONC_PATH = $(DEVKITPRO)/libtonc

TOOLCHAIN_PREFIX = $(DEVKITARM_PATH)/bin/arm-none-eabi-

CC = $(TOOLCHAIN_PREFIX)gcc
CFLAGS = -g -Wall -Wextra -Wfatal-errors -O3 -Werror=return-type \
	-I$(HEADER_DIR) -I$(DEVKITPRO_PATH)/libtonc/include $(PLATFORM_FLAGS)
	-I$(HEADER_DIR) -I$(BUILD_DIR) -I$(DEVKITPRO_TONC_PATH)/include $(PLATFORM_FLAGS)
AS = $(TOOLCHAIN_PREFIX)as
ASFLAGS = -g $(PLATFORM_FLAGS)
LDFLAGS = -g -specs=gba.specs -L$(DEVKITPRO_PATH)/libtonc/lib $(PLATFORM_FLAGS)
LDFLAGS = -g -specs=gba.specs -L$(DEVKITPRO_TONC_PATH)/lib $(PLATFORM_FLAGS)
LDLIBS = -ltonc
OBJCOPY = $(TOOLCHAIN_PREFIX)objcopy
OBJCOPY_FLAGS =
GBAFIX = gbafix
GBAFIX = $(DEVKITPRO_TOOLS_PATH)/gbafix
GBAFIX_FLAGS =
GRIT = $(DEVKITPRO_TOOLS_PATH)/grit
GRIT_FLAGS = -Zl -fts -fh -ff
ASEPRITE = aseprite
ASEPRITE_FLAGS = -b
MKDIR = mkdir -p
RMDIR = rm -rf # must work with non-empty directories
RMFILE = rm -f


@@ 61,16 70,25 @@ $(BUILD_DIR)/$(GAME_NAME).gba: $(BUILD_DIR)/$(GAME_NAME).elf | $(BUILD_DIR)
	$(OBJCOPY) -O binary $(OBJCOPY_FLAGS) $< $@
	$(GBAFIX) -t$(GAME_TITLE) -c$(GAME_CODE) -m$(MAKER_CODE) -r$(VERSION) -d$(DEBUG) $(GBAFIX_FLAGS) $@

$(BUILD_DIR)/$(GAME_NAME).elf $(BUILD_DIR)/$(GAME_NAME).map: $(OBJECT_FILES) | $(BUILD_DIR)
	$(CC) $(LDFLAGS) -o $(BUILD_DIR)/$(GAME_NAME).elf -Xlinker -Map=$(BUILD_DIR)/$(GAME_NAME).map $(OBJECT_FILES) $(LDLIBS)
$(BUILD_DIR)/$(GAME_NAME).elf $(BUILD_DIR)/$(GAME_NAME).map: $(OBJECT_FILES) $(RESOURCE_OBJECT_FILES) | $(BUILD_DIR)
	$(CC) $(LDFLAGS) -o $(BUILD_DIR)/$(GAME_NAME).elf -Xlinker -Map=$(BUILD_DIR)/$(GAME_NAME).map $(OBJECT_FILES) $(RESOURCE_OBJECT_FILES) $(LDLIBS)

$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | $(BUILD_DIR) $(DEPS_DIR)
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | $(BUILD_DIR) $(DEPS_DIR) $(RESOURCE_OBJECT_FILES)
	$(CC) $(CFLAGS) -o $@ -c $<
	$(CC) $(CFLAGS) -MM -o $(subst $(BUILD_DIR),$(DEPS_DIR),$(@:.o=.d)) -c $<

$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.s | $(BUILD_DIR) $(DEPS_DIR)
	$(AS) $(ASFLAGS) --MD $(subst $(BUILD_DIR),$(DEPS_DIR),$(@:.o=.d)) -o $@ $<

$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.s | $(BUILD_DIR)
	$(AS) $(ASFLAGS) -o $@ $<

$(BUILD_DIR)/%.s: $(RESOURCE_DIR)/%.png
	$(GRIT) $< -o $@ $(GRIT_FLAGS)

$(RESOURCE_DIR)/%.png: $(RESOURCE_DIR)/%.ase
	$(ASEPRITE) $(ASEPRITE_FLAGS) $< --save-as $@

$(BUILD_DIR):
	$(MKDIR) $(BUILD_DIR)



@@ 87,3 105,4 @@ clean-all: clean
	$(RMFILE) config.mk

.PHONY: clean clean-all
.PRECIOUS: $(RESOURCE_DIR)/%.png $(BUILD_DIR)/%.s

M configure => configure +6 -0
@@ 39,6 39,8 @@ check_and_emit_var() {

printf 'DEVKITPRO_PATH = %s\n' "${DEVKITPRO}"
check_and_emit_var 'DEVKITARM_PATH' "${DEVKITARM:-}"
check_and_emit_var 'DEVKITPRO_TOOLS_PATH' "${DEVKITPRO_TOOLS_PATH:-}"
check_and_emit_var 'DEVKITPRO_TONC_PATH' "${DEVKITPRO_TONC_PATH:-}"
check_and_emit_var 'TOOLCHAIN_PREFIX' "${TOOLCHAIN_PREFIX:-}"
check_and_emit_var 'CC' "${CC:-}"
check_and_emit_var 'CFLAGS' "${CFLAGS:-}"


@@ 50,6 52,10 @@ check_and_emit_var 'OBJCOPY' "${OBJCOPY:-}"
check_and_emit_var 'OBJCOPY_FLAGS' "${OBJCOPY_FLAGS:-}"
check_and_emit_var 'GBAFIX' "${GBAFIX:-}"
check_and_emit_var 'GBAFIX_FLAGS' "${GBAFIX_FLAGS:-}"
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 'MKDIR' "${MKDIR:-}"
check_and_emit_var 'RMDIR' "${RMDIR:-}"
check_and_emit_var 'RMFILE' "${RMFILE:-}"

M include/game.h => include/game.h +0 -4
@@ 4,7 4,3 @@
 */

#pragma once
#ifndef GAME_H
#define GAME_H

#endif // GAME_H

M src/main.c => src/main.c +23 -2
@@ 4,12 4,33 @@
 */

#include "game.h"
#include <tonc.h>
#include <stddef.h>
#include <tonc.h>

typedef void  colt45;

colt45****** shootin_iron; // got my shootin' iron loaded

bool vBlankTriggered = false;

void
vBlankHandler(void)
{
	key_poll();
}

void
init(void)
{
	irq_init(NULL);
	irq_add(II_VBLANK, vBlankHandler);
}

int
main(void)
{
	while (1) {}
	while (1) {
		VBlankIntrWait();
	}
	return 0;
}