diff options
author | Bad Diode <bd@badd10de.dev> | 2021-04-13 17:34:33 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-04-13 17:34:33 +0200 |
commit | 2809b83ee4d0fde8ebb406d4cdd39d142840254c (patch) | |
tree | 10d24f2b7ec1cbc6ef25a0c6b2760892602e0b69 | |
download | gba-experiments-2809b83ee4d0fde8ebb406d4cdd39d142840254c.tar.gz gba-experiments-2809b83ee4d0fde8ebb406d4cdd39d142840254c.zip |
Initial commit of gba template compilation with custom Makefile
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 72 | ||||
-rw-r--r-- | src/main.c | 33 |
3 files changed, 106 insertions, 0 deletions
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 @@ | |||
1 | .POSIX: | ||
2 | .SUFFIXES: | ||
3 | |||
4 | # Path to the development kit (devkitARM) and the GBA library. | ||
5 | DEVKITPRO := /opt/devkitpro | ||
6 | DEVKITARM := /opt/devkitpro/devkitARM | ||
7 | PATH := $(DEVKITARM)/bin:$(PATH) | ||
8 | LIBGBA_DIR := $(DEVKITPRO)/libgba | ||
9 | LIBGBA_SRC := /opt/devkitpro/libgba/include/ | ||
10 | LIBGBA := $(LIBGBA_DIR)/lib/libgba.a | ||
11 | LIBGBA += $(LIBGBA_DIR)/lib/libfat.a | ||
12 | LIBGBA += $(LIBGBA_DIR)/lib/libmm.a | ||
13 | |||
14 | # Source code location and files to watch for changes. | ||
15 | SRC_DIR := src | ||
16 | SRC_MAIN := $(SRC_DIR)/main.c | ||
17 | WATCH_SRC := $(wildcard $(SRC_DIR)/*.c) | ||
18 | WATCH_SRC += $(wildcard $(SRC_DIR)/*.h) | ||
19 | |||
20 | # Output library names and executables. | ||
21 | BIN_NAME := template | ||
22 | BUILD_DIR := build | ||
23 | ELF := $(BUILD_DIR)/$(BIN_NAME).elf | ||
24 | BIN := $(BUILD_DIR)/$(BIN_NAME).gba | ||
25 | |||
26 | # Compiler and linker configuration. | ||
27 | CC := arm-none-eabi-gcc | ||
28 | OBJCOPY := arm-none-eabi-objcopy | ||
29 | ARCH := -mthumb -mthumb-interwork | ||
30 | SPECS := -specs=gba.specs | ||
31 | CFLAGS := -g -Wall -Wextra -pedantic | ||
32 | CFLAGS += -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH) | ||
33 | CFLAGS += -I$(LIBGBA_SRC) | ||
34 | LDFLAGS := $(ARCH) $(SPECS) | ||
35 | LDLIBS := $(LIBGBA) | ||
36 | RELEASE_CFLAGS := -DNDEBUG -O2 | ||
37 | DEBUG_CFLAGS := -DDEBUG -O2 | ||
38 | |||
39 | .PHONY: clean run | ||
40 | |||
41 | # Setup debug/release builds. | ||
42 | # make clean && make <target> DEBUG=0 | ||
43 | # make clean && make <target> DEBUG=1 | ||
44 | DEBUG ?= 0 | ||
45 | ifeq ($(DEBUG), 1) | ||
46 | CFLAGS += $(DEBUG_CFLAGS) | ||
47 | else | ||
48 | CFLAGS += $(RELEASE_CFLAGS) | ||
49 | endif | ||
50 | |||
51 | main: $(BUILD_DIR) $(BIN) | ||
52 | |||
53 | # Strip and fix header to create final .gba file. | ||
54 | $(BIN): $(ELF) | ||
55 | $(OBJCOPY) -v -O binary $(ELF) $(BIN) | ||
56 | gbafix $(BIN) | ||
57 | |||
58 | # Link files. | ||
59 | $(ELF): $(SRC_MAIN) $(WATCH_SRC) | ||
60 | $(CC) $(CFLAGS) $(LDFLAGS) -o $(ELF) $(SRC_MAIN) $(LDLIBS) | ||
61 | |||
62 | # Create build directory if needed. | ||
63 | $(BUILD_DIR): | ||
64 | mkdir -p $(BUILD_DIR) | ||
65 | |||
66 | # Test the output .gba in an emulator. | ||
67 | run: main | ||
68 | mgba-qt $(BIN) | ||
69 | |||
70 | # Remove build directory. | ||
71 | clean: | ||
72 | 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 @@ | |||
1 | #include <gba_console.h> | ||
2 | #include <gba_video.h> | ||
3 | #include <gba_interrupt.h> | ||
4 | #include <gba_systemcalls.h> | ||
5 | #include <gba_input.h> | ||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | |||
9 | //--------------------------------------------------------------------------------- | ||
10 | // Program entry point | ||
11 | //--------------------------------------------------------------------------------- | ||
12 | int main(void) { | ||
13 | //--------------------------------------------------------------------------------- | ||
14 | |||
15 | |||
16 | // the vblank interrupt must be enabled for VBlankIntrWait() to work | ||
17 | // since the default dispatcher handles the bios flags no vblank handler | ||
18 | // is required | ||
19 | irqInit(); | ||
20 | irqEnable(IRQ_VBLANK); | ||
21 | |||
22 | consoleDemoInit(); | ||
23 | |||
24 | // ansi escape sequence to set print co-ordinates | ||
25 | // /x1b[line;columnH | ||
26 | iprintf("\x1b[10;10HHello World!\n"); | ||
27 | |||
28 | while (1) { | ||
29 | VBlankIntrWait(); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | |||