From 2809b83ee4d0fde8ebb406d4cdd39d142840254c Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 13 Apr 2021 17:34:33 +0200 Subject: Initial commit of gba template compilation with custom Makefile --- .gitignore | 1 + Makefile | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 33 ++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..46564cc --- /dev/null +++ b/Makefile @@ -0,0 +1,72 @@ +.POSIX: +.SUFFIXES: + +# Path to the development kit (devkitARM) and the GBA library. +DEVKITPRO := /opt/devkitpro +DEVKITARM := /opt/devkitpro/devkitARM +PATH := $(DEVKITARM)/bin:$(PATH) +LIBGBA_DIR := $(DEVKITPRO)/libgba +LIBGBA_SRC := /opt/devkitpro/libgba/include/ +LIBGBA := $(LIBGBA_DIR)/lib/libgba.a +LIBGBA += $(LIBGBA_DIR)/lib/libfat.a +LIBGBA += $(LIBGBA_DIR)/lib/libmm.a + +# Source code location and files to watch for changes. +SRC_DIR := src +SRC_MAIN := $(SRC_DIR)/main.c +WATCH_SRC := $(wildcard $(SRC_DIR)/*.c) +WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) + +# Output library names and executables. +BIN_NAME := template +BUILD_DIR := build +ELF := $(BUILD_DIR)/$(BIN_NAME).elf +BIN := $(BUILD_DIR)/$(BIN_NAME).gba + +# Compiler and linker configuration. +CC := arm-none-eabi-gcc +OBJCOPY := arm-none-eabi-objcopy +ARCH := -mthumb -mthumb-interwork +SPECS := -specs=gba.specs +CFLAGS := -g -Wall -Wextra -pedantic +CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH) +CFLAGS += -I$(LIBGBA_SRC) +LDFLAGS := $(ARCH) $(SPECS) +LDLIBS := $(LIBGBA) +RELEASE_CFLAGS := -DNDEBUG -O2 +DEBUG_CFLAGS := -DDEBUG -O2 + +.PHONY: clean run + +# Setup debug/release builds. +# make clean && make DEBUG=0 +# make clean && make DEBUG=1 +DEBUG ?= 0 +ifeq ($(DEBUG), 1) + CFLAGS += $(DEBUG_CFLAGS) +else + CFLAGS += $(RELEASE_CFLAGS) +endif + +main: $(BUILD_DIR) $(BIN) + +# Strip and fix header to create final .gba file. +$(BIN): $(ELF) + $(OBJCOPY) -v -O binary $(ELF) $(BIN) + gbafix $(BIN) + +# Link files. +$(ELF): $(SRC_MAIN) $(WATCH_SRC) + $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(LDLIBS) + +# Create build directory if needed. +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +# Test the output .gba in an emulator. +run: main + mgba-qt $(BIN) + +# Remove build directory. +clean: + rm -r $(BUILD_DIR) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..64f6234 --- /dev/null +++ b/src/main.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include +#include + +//--------------------------------------------------------------------------------- +// Program entry point +//--------------------------------------------------------------------------------- +int main(void) { +//--------------------------------------------------------------------------------- + + + // the vblank interrupt must be enabled for VBlankIntrWait() to work + // since the default dispatcher handles the bios flags no vblank handler + // is required + irqInit(); + irqEnable(IRQ_VBLANK); + + consoleDemoInit(); + + // ansi escape sequence to set print co-ordinates + // /x1b[line;columnH + iprintf("\x1b[10;10HHello World!\n"); + + while (1) { + VBlankIntrWait(); + } +} + + -- cgit v1.2.1