tuxanci2-sdk
SDK for tuxanci2
Log | Files | Refs | README | LICENSE
commit 45a832547e86f85404779fce0f4f8600f584646c
parent 4411e5219f8e20721fe0412841a2d75df75d4f2a
Author: Connor Thomson <connor@gnufault.org>
Date:   Tue, 10 Nov 2026 20:23:12 -0800

Add the new file support

Diffstat:
Minclude/tuxanci2/abi.h | 4++++
Ainclude/tuxanci2/file.h | 16++++++++++++++++
Minclude/tuxanci2/ft2.h | 4++--
Minclude/tuxanci2/image.h | 12++++++------
Minclude/tuxanci2/text.h | 5+++++
Mlinker.ld | 7-------
Msdk.mk | 38++++++++++++++++++++------------------
Asrc/file.c | 46++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 99 insertions(+), 33 deletions(-)

diff --git a/include/tuxanci2/abi.h b/include/tuxanci2/abi.h @@ -26,5 +26,9 @@ #define TA_SYS_FT2_PLAY 22 #define TA_SYS_FT2_STOP 23 #define TA_SYS_FT2_IS_PLAYING 24 +#define TA_SYS_FILE_SIZE 25 +#define TA_SYS_FILE_READ 26 +#define TA_SYS_FILE_EXEC 27 +#define TA_SYS_TEXT_CHANGE_COLOR 28 #endif // TA_ABI_H diff --git a/include/tuxanci2/file.h b/include/tuxanci2/file.h @@ -0,0 +1,16 @@ +#ifndef TA_FILE_H +#define TA_FILE_H + +#include <stdint.h> + +typedef struct __attribute__((packed)) { + uint8_t file; + uint32_t size; + char data[]; +} ta_file; + +ta_file *ta_file_open(uint8_t file); +void ta_file_close(ta_file *file); +void ta_file_exec(ta_file *file); + +#endif // TA_FILE_H diff --git a/include/tuxanci2/ft2.h b/include/tuxanci2/ft2.h @@ -7,8 +7,8 @@ #include <stdbool.h> #include <stddef.h> -static inline bool ta_ft2_load(const void *data, uint32_t length) { - return ta_syscall(TA_SYS_FT2_LOAD, (uint32_t)(size_t)data, length, 0, 0, 0, 0) != 0; +static inline bool ta_ft2_load(uint8_t file) { + return ta_syscall(TA_SYS_FT2_LOAD, file, 0, 0, 0, 0, 0) != 0; } static inline bool ta_ft2_play(void) { 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(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_init(uint8_t file) { + return ta_syscall(TA_SYS_IMAGE_INIT, file, 0, 0, 0, 0, 0) != 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_draw(uint8_t file, ta_fixed x, ta_fixed y, ta_fixed width, ta_fixed height, uint32_t frame) { + return ta_syscall(TA_SYS_IMAGE_DRAW, file, x, y, width, height, frame) != 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; +static inline bool ta_image_get_size(uint8_t file, uint32_t *width, uint32_t *height) { + return ta_syscall(TA_SYS_IMAGE_GET_SIZE, file, (uint32_t)(size_t)width, (uint32_t)(size_t)height, 0, 0, 0) != 0; } #endif // TA_IMAGE_H diff --git a/include/tuxanci2/text.h b/include/tuxanci2/text.h @@ -4,6 +4,7 @@ #include <tuxanci2/syscall.h> #include <tuxanci2/abi.h> #include <stdint.h> +#include <stdbool.h> #include <stddef.h> typedef uint32_t ta_text; @@ -24,6 +25,10 @@ static inline void ta_text_draw(ta_text text, uint32_t x, uint32_t y) { ta_syscall(TA_SYS_TEXT_DRAW, text, x, y, 0, 0, 0); } +static inline bool ta_text_change_color(ta_text text, uint32_t color) { + return ta_syscall(TA_SYS_TEXT_CHANGE_COLOR, text, color, 0, 0, 0, 0) != 0; +} + static inline void ta_text_destroy(ta_text text) { ta_syscall(TA_SYS_TEXT_DESTROY, text, 0, 0, 0, 0, 0); } diff --git a/linker.ld b/linker.ld @@ -8,13 +8,6 @@ __heap_end = __ram_size - __stack_size; SECTIONS { . = 0; - .magic_number : { - BYTE(0x54) /* T */ - BYTE(0x41) /* A */ - BYTE(0x42) /* B */ - BYTE(0x43) /* C */ - } - .text : { KEEP(*(.text.start)) *(.text .text.*) diff --git a/sdk.mk b/sdk.mk @@ -1,12 +1,14 @@ CROSS ?= riscv32-unknown-elf- +SDK_DIR := $(dir $(lastword $(MAKEFILE_LIST))) + CC := $(CROSS)gcc OBJCOPY := $(CROSS)objcopy BUILD ?= build -XXD ?= xxd +TABCONV_DIR ?= $(SDK_DIR)../tabconv +TABCONV ?= $(BUILD)/tabconv FILES ?= files -SDK_DIR := $(dir $(lastword $(MAKEFILE_LIST))) OPT := 2 MARCH := rv32im @@ -32,18 +34,22 @@ 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 -$(BUILD)/$(TARGET).tab: $(BUILD)/$(TARGET).elf +$(BUILD)/$(TARGET).tab: $(BUILD)/$(TARGET).bin $(ASSETS) $(TABCONV) + $(TABCONV) $< $(ASSETS) $@ + +$(BUILD)/$(TARGET).bin: $(BUILD)/$(TARGET).elf $(OBJCOPY) -O binary $< $@ +$(TABCONV): $(TABCONV_DIR)/tabconv.c + mkdir -p $(@D) + $(MAKE) -C $(TABCONV_DIR) OUT=$(abspath $@) + $(BUILD)/$(TARGET).elf: $(OBJS) $(CC) $(LDFLAGS) $^ -o $@ @@ -63,22 +69,18 @@ $(BUILD)/game/%.o: %.S mkdir -p $(@D) $(CC) $(ASFLAGS) -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))';) \ + id=2; \ + for a in $(ASSETS); do \ + name=$$(basename "$$a"); \ + name=$${name%.*}; \ + name=$$(printf '%s' "$$name" | tr 'a-z' 'A-Z' | sed 's/[^A-Z0-9_]/_/g'); \ + printf '#define TA_FILE_%s %d\n' "$$name" "$$id"; \ + id=$$((id + 1)); \ + done; \ printf '\n#endif // TA_FILES_H\n'; \ } > $@.tmp if cmp -s $@.tmp $@; then rm -f $@.tmp; else mv $@.tmp $@; fi diff --git a/src/file.c b/src/file.c @@ -0,0 +1,46 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stddef.h> +#include <tuxanci2/file.h> +#include <tuxanci2/abi.h> +#include <tuxanci2/syscall.h> + +#define TA_FILE_MISSING 0xFFFFFFFFu +#define TA_FILE_LIMIT 0x7FFFFF00u + +ta_file *ta_file_open(uint8_t file) { + uint32_t size = ta_syscall(TA_SYS_FILE_SIZE, file, 0, 0, 0, 0, 0); + + if (size == TA_FILE_MISSING || size > TA_FILE_LIMIT) { + return NULL; + } + + ta_file *opened = (ta_file *)malloc(sizeof(ta_file) + size); + + if (opened == NULL) { + return NULL; + } + + opened->file = file; + opened->size = size; + + if (ta_syscall(TA_SYS_FILE_READ, file, (uint32_t)(size_t)opened->data, 0, 0, 0, 0) == 0) { + free(opened); + + return NULL; + } + + return opened; +} + +void ta_file_close(ta_file *file) { + free(file); +} + +void ta_file_exec(ta_file *file) { + if (file == NULL) { + return; + } + + ta_syscall(TA_SYS_FILE_EXEC, file->file, 0, 0, 0, 0, 0); +}