tuxanci2-engine
Game engine for tuxanci2
Log | Files | Refs | README | LICENSE
commit 68a400de6768d12d6b8145c8813873fa8243d77c
parent 9477413cf3ce2271c6d5f75f0360d35cbf32290c
Author: Connor Thomson <connor@gnufault.org>
Date:   Sat, 31 Oct 2026 16:41:11 -0700

Move images out of the engine

Diffstat:
Minclude/ta_abi.h | 3---
Dinclude/ta_files.h | 11-----------
Minclude/ta_vm.h | 3++-
Msrc/ta_syscall.c | 48++++++++++++++++++++++++++----------------------
Msrc/ta_vm.c | 14++++++++++++--
5 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/include/ta_abi.h b/include/ta_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/ta_files.h b/include/ta_files.h @@ -1,11 +0,0 @@ -#ifndef TA_FILES_H -#define TA_FILES_H - -extern unsigned char ta_file_dejavu_sans[]; -extern unsigned int ta_file_dejavu_sans_len; -extern unsigned char ta_file_bg[]; -extern unsigned int ta_file_bg_len; -extern unsigned char ta_file_loading_logo[]; -extern unsigned int ta_file_loading_logo_len; - -#endif diff --git a/include/ta_vm.h b/include/ta_vm.h @@ -43,10 +43,11 @@ ta_vm_status ta_vm_run(ta_vm *vm, ta_uint32 max_steps); ta_bool ta_vm_read8(const ta_vm *vm, ta_uint32 addr, ta_uint8 *out); ta_bool ta_vm_read32(const ta_vm *vm, ta_uint32 addr, ta_uint32 *out); ta_bool ta_vm_write32(ta_vm *vm, ta_uint32 addr, ta_uint32 value); +void *ta_vm_translate_pointer(const ta_vm *vm, ta_uint32 addr, ta_uint32 size); const char *ta_vm_cstr(const ta_vm *vm, ta_uint32 addr); #ifndef TA_VM_RAM_SIZE -#define TA_VM_RAM_SIZE (64u * 1024u) +#define TA_VM_RAM_SIZE (256u * 1024u) #endif #ifndef TA_VM_STEPS_PER_CALL diff --git a/src/ta_syscall.c b/src/ta_syscall.c @@ -3,36 +3,27 @@ #include "ta_api.h" #include "ta_display.h" #include "ta_fb.h" -#include "ta_files.h" #include "ta_image.h" #include "ta_keyboard.h" #include "ta_scene.h" #include "ta_screen.h" #include "ta_text.h" -static ta_text **texts; -static ta_uint32 text_count; +static ta_bool image_data(const ta_vm *vm, ta_uint32 address, const ta_uint8 **data, ta_uint32 *length) { + *data = (const ta_uint8 *)ta_vm_translate_pointer(vm, address, 1); -static ta_bool asset_get(ta_uint32 id, const ta_uint8 **data, ta_uint32 *length) { - switch (id) { - case TA_ASSET_BG: { - *data = ta_file_bg; - *length = ta_file_bg_len; + if (*data == TA_NULL) { + return ta_false; + } - return ta_true; - } - case TA_ASSET_LOADING_LOGO: { - *data = ta_file_loading_logo; - *length = ta_file_loading_logo_len; + *length = vm->mem_size - address; - return ta_true; - } - default: { - return ta_false; - } - } + return ta_true; } +static ta_text **texts; +static ta_uint32 text_count; + static ta_text *text_get(ta_uint32 handle) { if (handle == 0 || handle > text_count) { return TA_NULL; @@ -166,7 +157,11 @@ ta_vm_status ta_syscall(ta_vm *vm) { const ta_uint8 *data; ta_uint32 length; - result = asset_get(args[0], &data, &length) && ta_image_init(data, length) ? 1 : 0; + if (!image_data(vm, args[0], &data, &length)) { + return TA_VM_FAULT_MEMORY; + } + + result = ta_image_init(data, length) ? 1 : 0; break; } @@ -174,7 +169,11 @@ ta_vm_status ta_syscall(ta_vm *vm) { const ta_uint8 *data; ta_uint32 length; - result = asset_get(args[0], &data, &length) && ta_scene_image(data, length, args[1], args[2], args[3], args[4], (ta_uint16)args[5]) ? 1 : 0; + if (!image_data(vm, args[0], &data, &length)) { + return TA_VM_FAULT_MEMORY; + } + + result = ta_scene_image(data, length, args[1], args[2], args[3], args[4], (ta_uint16)args[5]) ? 1 : 0; break; } @@ -184,7 +183,11 @@ ta_vm_status ta_syscall(ta_vm *vm) { ta_uint32 width; ta_uint32 height; - if (!asset_get(args[0], &data, &length) || !ta_image_get_size(data, length, &width, &height)) { + if (!image_data(vm, args[0], &data, &length)) { + return TA_VM_FAULT_MEMORY; + } + + if (!ta_image_get_size(data, length, &width, &height)) { break; } @@ -257,6 +260,7 @@ ta_vm_status ta_syscall(ta_vm *vm) { void ta_syscall_reset(void) { ta_scene_invalidate(); + ta_image_release(); for (ta_uint32 i = 0; i < text_count; i++) { if (texts[i] != TA_NULL) { diff --git a/src/ta_vm.c b/src/ta_vm.c @@ -165,14 +165,24 @@ static ta_bool store_value(ta_vm *vm, ta_uint32 addr, ta_uint32 size, ta_uint32 return ta_true; } +void *ta_vm_translate_pointer(const ta_vm *vm, ta_uint32 addr, ta_uint32 size) { + if (size == 0 || !in_bounds(vm, addr, size)) { + return TA_NULL; + } + + return vm->mem + addr; +} + const char *ta_vm_cstr(const ta_vm *vm, ta_uint32 addr) { - if (addr >= vm->mem_size) { + const char *string = (const char *)ta_vm_translate_pointer(vm, addr, 1); + + if (!string) { return TA_NULL; } for (ta_uint32 offset = addr; offset < vm->mem_size; offset++) { if (vm->mem[offset] == 0) { - return (const char *)(vm->mem + addr); + return string; } }