diff --git a/System/FFI/TrueType.HC b/System/FFI/TrueType.HC new file mode 100644 index 0000000..2477263 --- /dev/null +++ b/System/FFI/TrueType.HC @@ -0,0 +1,31 @@ +U64 stbtt_heap = MAlloc(1048576 * 32); +U64 stbtt_pos = 0; + +U64 @stbtt_malloc(I64 size) +{ + //"stbtt_malloc(%d)\n", size; + U64 ptr = stbtt_heap + stbtt_pos; + stbtt_pos += size; + return ptr; +} + +U0 @stbtt_free(U8* ptr) +{ + //"stbtt_free(0x%08x)\n", ptr; +} + +U0 _Z15truetype_malloci() +{ + PUSH_SYSV_REGS + GET_SYSV_ARGS + @stbtt_malloc(p0); + POP_SYSV_REGS +} + +U0 _Z13truetype_freePv() +{ + PUSH_SYSV_REGS + GET_SYSV_ARGS + @stbtt_free(p0); + POP_SYSV_REGS +} diff --git a/System/Libraries/Graphics2D.HC b/System/Libraries/Graphics2D.HC index 10ed6c8..7aff17f 100644 --- a/System/Libraries/Graphics2D.HC +++ b/System/Libraries/Graphics2D.HC @@ -1206,7 +1206,7 @@ I64 @get_truetype_baseline(U8* font_name, I64 size) dc->width -= 16; dc->height -= size / 4; res = Y2Pos(dc); - DCDel(dc); + Free(dc); return res; } @@ -1232,7 +1232,7 @@ U0 Text2D(Context2D* ctx, U8* font_name, I64 x, I64 y, I64 size, U32 color, U8* } BlendRect2D(text_ctx, ctx); DelContext2D(text_ctx); - DCDel(dc); + Free(dc); } Context2D* FastBoxBlur2D(Context2D* img, I64 radius) diff --git a/System/MakeSystem.HC b/System/MakeSystem.HC index 9eb9b38..4b60b44 100644 --- a/System/MakeSystem.HC +++ b/System/MakeSystem.HC @@ -23,6 +23,7 @@ WinToTop(adam_task); #include "FFI/LibC"; #include "FFI/New"; #include "FFI/ELF64"; +#include "FFI/TrueType"; // stb_image library #include "Utilities/Image"; diff --git a/System/Utilities/TrueType.HC b/System/Utilities/TrueType.HC index 2dc75da..9d9ab7f 100644 --- a/System/Utilities/TrueType.HC +++ b/System/Utilities/TrueType.HC @@ -44,6 +44,7 @@ U8* @stbtt_RenderText(stbtt_fontinfo* info, I32 b_w, I32 b_h, I32 l_h, I32* word U64 reg R8 r8 = word; U64 reg R9 r9 = advance; no_warn rdi, rsi, rdx, rcx, r8, r9; + stbtt_pos = 0; asm { MOV RAX, STBTT_RENDERTEXT CALL RAX diff --git a/scripts/build-all b/scripts/build-all index 66d6f26..9390e55 100755 --- a/scripts/build-all +++ b/scripts/build-all @@ -107,7 +107,7 @@ def build_image(): def build_truetype(): print("build-all: build-truetype") build_specific_options = '-Wl,--section-start=.text=0x1104000 -Wl,--section-start=.plt=0x1102020 -no-pie' - res = os.system('cd ' + project_path + '&& cd src/truetype && gcc -o ../../build/bin/truetype ' + build_specific_options + ' -O0 -mno-mmx -mno-red-zone truetype.c ../openlibm/libopenlibm.a') + res = os.system('cd ' + project_path + '&& cd src/truetype && gcc -o ../../build/bin/truetype ' + build_specific_options + ' -O0 -mno-mmx -mno-red-zone truetype.c ../../build/lib/libtemple.so ../openlibm/libopenlibm.a') if res: raise ValueError("build-all: step 'build-image' failed, error code " + str(res)) @@ -257,8 +257,8 @@ def build_all(): refresh_build_path() build_image() build_openlibm() - build_truetype() build_libtemple() + build_truetype() build_tlse() transpile_net_to_sepples() build_net() diff --git a/src/libtemple/libtemple.cpp b/src/libtemple/libtemple.cpp index 82ce415..2311264 100644 --- a/src/libtemple/libtemple.cpp +++ b/src/libtemple/libtemple.cpp @@ -74,4 +74,8 @@ long time_jiffies() { return 0; } long time_now() { return 0; } -void time_sleep(long duration) { } \ No newline at end of file +void time_sleep(long duration) { } + +void* truetype_malloc(int size) { return 0; } + +void truetype_free(void* ptr) { } \ No newline at end of file diff --git a/src/truetype/stb_truetype.h b/src/truetype/stb_truetype.h index be4b778..a241520 100644 --- a/src/truetype/stb_truetype.h +++ b/src/truetype/stb_truetype.h @@ -468,8 +468,8 @@ int main(int arg, char **argv) // #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h #ifndef STBTT_malloc #include - #define STBTT_malloc(x,u) ((void)(u),malloc(x)) - #define STBTT_free(x,u) ((void)(u),free(x)) + #define STBTT_malloc(x,u) ((void)(u),_Z15truetype_malloci(x)) + #define STBTT_free(x,u) ((void)(u),_Z13truetype_freePv(x)) #endif #ifndef STBTT_assert diff --git a/src/truetype/truetype.c b/src/truetype/truetype.c index dc58bc8..5d4b2b5 100644 --- a/src/truetype/truetype.c +++ b/src/truetype/truetype.c @@ -1,3 +1,6 @@ +void* _Z15truetype_malloci(int size); +void _Z13truetype_freePv(void* ptr); + #define STB_TRUETYPE_IMPLEMENTATION #include "stb_truetype.h" @@ -5,7 +8,8 @@ unsigned char* stbtt_RenderText(stbtt_fontinfo* info, int b_w, int b_h, int l_h, { // https://github.com/justinmeiners/stb-truetype-example /* create a bitmap for the phrase */ - unsigned char* bitmap = calloc(b_w * b_h, sizeof(unsigned char)); + unsigned char* bitmap = STBTT_malloc(b_w * b_h, sizeof(unsigned char)); + memset(bitmap, 0, b_w * b_h); /* calculate font scaling */ float scale = stbtt_ScaleForPixelHeight(info, l_h);