tuxanci2-engine
Game engine for tuxanci2
Log | Files | Refs | README | LICENSE
commit 0b8c85bc16ef7d446c735d7f52ccd44056aaedd4
parent ef9331fb7207d479bdb4e56eea56e621ab348ebf
Author: Connor Thomson <connor@gnufault.org>
Date: Sun, 18 Oct 2026 18:50:20 -0700
Add n64 target
Diffstat:
2 files changed, 111 insertions(+), 0 deletions(-)
diff --git a/platforms/n64/Makefile b/platforms/n64/Makefile
@@ -0,0 +1,64 @@
+MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
+ROOT_DIR := $(abspath $(MAKEFILE_DIR)/../..)
+
+N64_GCC ?= $(N64_INST)/bin/mips64-elf-gcc
+N64_AR ?= $(N64_INST)/bin/mips64-elf-ar
+N64_BUILD ?= build/n64
+N64_BUILD_DIR := $(ROOT_DIR)/$(N64_BUILD)
+N64_LIBRARY := $(N64_BUILD_DIR)/tuxanci2.a
+N64_SOURCE := $(MAKEFILE_DIR)n64.c
+TARGET := tuxanci2.z64
+
+N64_INST ?= /opt/libdragon
+N64_MK := $(N64_INST)/include/n64.mk
+export N64_INST
+
+ifeq ($(wildcard $(N64_MK)),)
+$(error libdragon n64.mk not found under N64_INST='$(N64_INST)')
+endif
+
+BUILD_DIR := ../../$(N64_BUILD)
+SOURCE_DIR := $(MAKEFILE_DIR)
+ROMNAME := tuxanci2
+include $(N64_MK)
+N64_CFLAGS += -I$(ROOT_DIR)/include -I$(N64_BUILD_DIR)
+
+ROOT_INPUTS := $(shell find $(ROOT_DIR)/src -type f -name '*.c') \
+ $(wildcard $(ROOT_DIR)/include/*.h) \
+ $(ROOT_DIR)/include/ta_config.h.in \
+ $(shell find $(ROOT_DIR)/files -type f) \
+ $(ROOT_DIR)/Makefile
+
+ENGINE_CFLAGS := $(N64_CFLAGS) -DTA_32BIT -DTA_DISABLE_BILINEAR_FILTERING \
+ -I$(ROOT_DIR)/include -I$(N64_BUILD_DIR) -std=c99 \
+ -ffreestanding -nostdlib -nostdinc -fno-builtin \
+ -fno-stack-protector -Wall -Wextra -Werror -pedantic -pedantic-errors
+
+.DEFAULT_GOAL := all
+.PHONY: all clean
+
+all: $(TARGET)
+
+$(N64_LIBRARY): $(ROOT_INPUTS)
+ $(MAKE) -C "$(ROOT_DIR)" CC="$(N64_GCC)" AR="$(N64_AR)" BITS=32 MARCH=vr4300 \
+ BUILD_DIR="$(N64_BUILD)" TA_DISABLE_BILINEAR_FILTERING=true \
+ CFLAGS="$(ENGINE_CFLAGS)" all
+
+$(BUILD_DIR)/n64.o: $(N64_SOURCE) $(N64_BUILD_DIR)/ta_config.h $(wildcard $(ROOT_DIR)/include/*.h)
+
+$(N64_BUILD_DIR)/ta_config.h:
+ $(MAKE) -C "$(ROOT_DIR)" BUILD_DIR="$(N64_BUILD)" BITS=32 MARCH=vr4300 \
+ "$(N64_BUILD)/ta_config.h"
+
+$(BUILD_DIR)/$(ROMNAME).elf: $(BUILD_DIR)/n64.o $(N64_LIBRARY)
+
+$(TARGET): N64_ROM_TITLE = "Tuxanci 2"
+
+clean:
+ $(RM) "$(TARGET)"
+ $(MAKE) -C "$(ROOT_DIR)" BUILD_DIR="$(N64_BUILD)" clean
+ $(RM) -r "$(MAKEFILE_DIR)build"
+
+ifneq ($(wildcard $(BUILD_DIR)),)
+-include $(shell find $(BUILD_DIR) -name '*.d')
+endif
diff --git a/platforms/n64/n64.c b/platforms/n64/n64.c
@@ -0,0 +1,47 @@
+#include "ta_api.h"
+#include <display.h>
+#include <surface.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#define SCREEN_WIDTH 320
+#define SCREEN_HEIGHT 240
+#define WINDOW_BPP 32
+
+int main(void) {
+ display_init(RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, FILTERS_RESAMPLE);
+
+ ta_fb.width = SCREEN_WIDTH;
+ ta_fb.height = SCREEN_HEIGHT;
+ ta_fb.bpp = WINDOW_BPP;
+
+ ta_main_init();
+
+ while (1) {
+ surface_t *display = display_get();
+ ta_main_update();
+
+ const ta_uint32 *source = (const ta_uint32 *)ta_fb.buffers[0];
+ ta_uint32 *destination = (ta_uint32 *)display->buffer;
+
+ for (ta_uint32 i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) {
+ destination[i] = (source[i] << 8) | 0xff;
+ }
+
+ display_show(display);
+ }
+
+ return 0;
+}
+
+void *ta_malloc(ta_size size) {
+ return malloc(size);
+}
+
+void ta_free(void *ptr) {
+ free(ptr);
+}
+
+void ta_exit(int status) {
+ exit(status);
+}