tuxanci2-sdk
SDK for tuxanci2
Log | Files | Refs | README | LICENSE
commit f761d9c3a666787f8e96acbfdaa017e14de16c32
parent e0f526d7da8ed41d576e9da9ecab5d548e181bea
Author: Connor Thomson <connor@gnufault.org>
Date: Sat, 31 Oct 2026 16:45:54 -0700
Fix ram size and make it so the new image thing works
Diffstat:
5 files changed, 50 insertions(+), 22 deletions(-)
diff --git a/include/tuxanci2/abi.h b/include/tuxanci2/abi.h
@@ -19,7 +19,4 @@
#define TA_SYS_SCREEN_REGISTER 19
#define TA_SYS_SCREEN_SWITCH 20
-#define TA_ASSET_BG 0
-#define TA_ASSET_LOADING_LOGO 1
-
#endif // TA_ABI_H
diff --git a/include/tuxanci2/image.h b/include/tuxanci2/image.h
@@ -8,16 +8,16 @@
#include <stdbool.h>
#include <stddef.h>
-static inline bool ta_image_init(uint32_t asset) {
- return ta_syscall(TA_SYS_IMAGE_INIT, asset, 0, 0, 0, 0, 0) != 0;
+static inline bool ta_image_init(const void *image) {
+ return ta_syscall(TA_SYS_IMAGE_INIT, (uint32_t)(size_t)image, 0, 0, 0, 0, 0) != 0;
}
-static inline bool ta_image_draw(uint32_t asset, ta_fixed x, ta_fixed y, ta_fixed width, ta_fixed height, uint32_t frame) {
- return ta_syscall(TA_SYS_IMAGE_DRAW, asset, x, y, width, height, frame) != 0;
+static inline bool ta_image_draw(const void *image, ta_fixed x, ta_fixed y, ta_fixed width, ta_fixed height, uint32_t frame) {
+ return ta_syscall(TA_SYS_IMAGE_DRAW, (uint32_t)(size_t)image, x, y, width, height, frame) != 0;
}
-static inline bool ta_image_get_size(uint32_t asset, uint32_t *width, uint32_t *height) {
- return ta_syscall(TA_SYS_IMAGE_GET_SIZE, asset, (uint32_t)(size_t)width, (uint32_t)(size_t)height, 0, 0, 0) != 0;
+static inline bool ta_image_get_size(const void *image, uint32_t *width, uint32_t *height) {
+ return ta_syscall(TA_SYS_IMAGE_GET_SIZE, (uint32_t)(size_t)image, (uint32_t)(size_t)width, (uint32_t)(size_t)height, 0, 0, 0) != 0;
}
#endif // TA_IMAGE_H
diff --git a/linker.ld b/linker.ld
@@ -1,7 +1,7 @@
OUTPUT_ARCH(riscv)
ENTRY(_start)
-PROVIDE(__ram_size = 0x10000);
+PROVIDE(__ram_size = 0x40000);
PROVIDE(__stack_size = 0x2000);
__heap_end = __ram_size - __stack_size;
diff --git a/sdk.mk b/sdk.mk
@@ -3,7 +3,9 @@ CROSS ?= riscv32-unknown-elf-
CC := $(CROSS)gcc
OBJCOPY := $(CROSS)objcopy
-BUILD := build
+BUILD ?= build
+XXD ?= xxd
+FILES ?= files
SDK_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
OPT := 2
@@ -12,12 +14,13 @@ MABI := ilp32
LINKER_SCRIPT := linker.ld
-CFLAGS := -O$(OPT) -march=$(MARCH) -mabi=$(MABI) -ffreestanding -nostdinc -fno-builtin -fno-pic -fno-stack-protector -fno-tree-loop-distribute-patterns -Wall -Wextra -I$(SDK_DIR)include -I$(SDK_DIR)../include
+CFLAGS := -O$(OPT) -march=$(MARCH) -mabi=$(MABI) -ffreestanding -nostdinc -fno-builtin -fno-pic -fno-stack-protector -fno-tree-loop-distribute-patterns -Wall -Wextra -I$(SDK_DIR)include -I$(SDK_DIR)../include -I$(BUILD)/include $(addprefix -I,$(INCLUDES))
ASFLAGS := -march=$(MARCH) -mabi=$(MABI) -I$(SDK_DIR)include -I$(SDK_DIR)../include
LDFLAGS := -march=$(MARCH) -mabi=$(MABI) -nostdlib -static -T $(SDK_DIR)$(LINKER_SCRIPT) -Wl,--gc-sections
SDK_SRCS := $(shell find $(SDK_DIR)src -type f \( -name '*.c' -o -name '*.S' \))
-GAME_SRCS := $(shell find src -type f \( -name '*.c' -o -name '*.S' \))
+SRCS ?= src
+GAME_SRCS := $(sort $(foreach s,$(SRCS),$(if $(wildcard $(s)/.),$(shell find $(patsubst %/,%,$(s)) -type f \( -name '*.c' -o -name '*.S' \)),$(s))))
SDK_OBJS := $(patsubst $(SDK_DIR)%, $(BUILD)/sdk/%, $(SDK_SRCS))
GAME_OBJS := $(patsubst %, $(BUILD)/game/%, $(GAME_SRCS))
@@ -28,6 +31,12 @@ GAME_OBJS := $(GAME_OBJS:.c=.o)
GAME_OBJS := $(GAME_OBJS:.S=.o)
OBJS += $(GAME_OBJS)
+ASSETS := $(sort $(shell find $(FILES) -type f -not -name 'LICENSE' 2>/dev/null))
+asset_sym = $(shell printf '%s' 'ta_file_$(notdir $(basename $(1)))' | sed 's/[^a-zA-Z0-9_]/_/g')
+FILES_HEADER := $(BUILD)/include/ta_files.h
+ASSET_SRCS := $(foreach a,$(ASSETS),$(BUILD)/assets/$(notdir $(basename $(a))).c)
+OBJS += $(ASSET_SRCS:.c=.o)
+
DEPS := $(OBJS:.o=.d)
all: $(BUILD)/$(TARGET).tab
@@ -39,19 +48,41 @@ $(BUILD)/$(TARGET).elf: $(OBJS)
$(CC) $(LDFLAGS) $^ -o $@
$(BUILD)/sdk/%.o: $(SDK_DIR)%.c
- @mkdir -p $(@D)
+ mkdir -p $(@D)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(BUILD)/sdk/%.o: $(SDK_DIR)%.S
- @mkdir -p $(@D)
+ mkdir -p $(@D)
$(CC) $(ASFLAGS) -MMD -MP -c $< -o $@
-$(BUILD)/game/%.o: %.c
- @mkdir -p $(@D)
+$(BUILD)/game/%.o: %.c $(FILES_HEADER)
+ mkdir -p $(@D)
+ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@
+
+define ASSET_RULE
+$(BUILD)/assets/$(notdir $(basename $(1))).c: $(1)
+ mkdir -p $$(@D)
+ $$(XXD) -i -n $(call asset_sym,$(1)) $$< $$@
+endef
+$(foreach a,$(ASSETS),$(eval $(call ASSET_RULE,$(a))))
+
+$(BUILD)/assets/%.o: $(BUILD)/assets/%.c
+ mkdir -p $(@D)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
+$(FILES_HEADER): FORCE
+ mkdir -p $(@D)
+ { \
+ printf '#ifndef TA_FILES_H\n#define TA_FILES_H\n\n'; \
+ $(foreach a,$(ASSETS),printf 'extern unsigned char %s[];\nextern unsigned int %s_len;\n' '$(call asset_sym,$(a))' '$(call asset_sym,$(a))';) \
+ printf '\n#endif // TA_FILES_H\n'; \
+ } > $@.tmp
+ if cmp -s $@.tmp $@; then rm -f $@.tmp; else mv $@.tmp $@; fi
+
+FORCE:
+
$(BUILD)/game/%.o: %.S
- @mkdir -p $(@D)
+ mkdir -p $(@D)
$(CC) $(ASFLAGS) -MMD -MP -c $< -o $@
clean:
@@ -59,4 +90,4 @@ clean:
-include $(DEPS)
-.PHONY: all clean
+.PHONY: all clean FORCE
diff --git a/src/crt0.c b/src/crt0.c
@@ -5,11 +5,11 @@
extern int main(void);
-static inline void ready(void (*stub)(uint32_t)) {
+static inline void ta_ready(void (*stub)(uint32_t)) {
ta_syscall(TA_SYS_READY, (uint32_t)(size_t)stub, 0, 0, 0, 0, 0);
}
-static inline void return(uint32_t value) {
+static inline void ta_return(uint32_t value) {
ta_syscall(TA_SYS_RETURN, value, 0, 0, 0, 0, 0);
while (1) {}
@@ -17,5 +17,5 @@ static inline void return(uint32_t value) {
__attribute__((section(".text.start"))) void _start(void) {
main();
- ready(return);
+ ta_ready(ta_return);
}