diff --git a/decompiler/config/jak2/all-types.gc b/decompiler/config/jak2/all-types.gc index 2ba8166f74a..0a3b3eb59bd 100644 --- a/decompiler/config/jak2/all-types.gc +++ b/decompiler/config/jak2/all-types.gc @@ -25205,7 +25205,7 @@ ) (define-extern gen-font-12 (function string none)) -(define-extern draw-string-asm (function string dma-buffer font-context uint)) +(define-extern draw-string-asm (function string dma-buffer font-context draw-string-result)) (define-extern draw-string (function string dma-buffer font-context draw-string-result)) (define-extern get-string-length (function string font-context draw-string-result)) (define-extern draw-string-xy (function string dma-buffer int int font-color font-flags draw-string-result)) diff --git a/decompiler/config/jak2/ntsc_v1/hacks.jsonc b/decompiler/config/jak2/ntsc_v1/hacks.jsonc index ed769c99713..cd609bbfcda 100644 --- a/decompiler/config/jak2/ntsc_v1/hacks.jsonc +++ b/decompiler/config/jak2/ntsc_v1/hacks.jsonc @@ -625,7 +625,7 @@ "moving-sphere-triangle-intersect", "calc-animation-from-spr", "draw-string-asm", - "draw-string", + //"draw-string", "get-string-length", "adgif-shader<-texture-with-update!", "init-boundary-regs", diff --git a/decompiler/config/jak2/ntsc_v1/var_names.jsonc b/decompiler/config/jak2/ntsc_v1/var_names.jsonc index b9e0e722a3b..cc0e381a59c 100644 --- a/decompiler/config/jak2/ntsc_v1/var_names.jsonc +++ b/decompiler/config/jak2/ntsc_v1/var_names.jsonc @@ -4503,5 +4503,10 @@ "vars": { "s5-0": ["set-flags", "cshape-reaction-flags"] } + }, + "draw-string": { + "vars": { + "v0-2": ["result", "draw-string-result"] + } } } diff --git a/game/mips2c/jak2_functions/font.cpp b/game/mips2c/jak2_functions/font.cpp index 7442dc6a13f..2ff87559438 100644 --- a/game/mips2c/jak2_functions/font.cpp +++ b/game/mips2c/jak2_functions/font.cpp @@ -1,213 +1,4 @@ -//--------------------------MIPS2C--------------------- -// clang-format off -#include "game/mips2c/mips2c_private.h" -#include "game/kernel/jak2/kscheme.h" -using ::jak2::intern_from_c; -namespace Mips2C::jak2 { -namespace draw_string { -struct Cache { - void* font_work; // *font-work* - void* dma_buffer_free; // dma-buffer-free - void* draw_string_asm; // draw-string-asm - void* string; // string -} cache; - -u64 execute(void* ctxt) { - auto* c = (ExecutionContext*)ctxt; - bool bc = false; - u32 call_addr = 0; - c->daddiu(sp, sp, -80); // daddiu sp, sp, -80 - c->sd(ra, 0, sp); // sd ra, 0(sp) - c->sd(fp, 8, sp); // sd fp, 8(sp) - c->mov64(fp, t9); // or fp, t9, r0 - c->sq(s3, 16, sp); // sq s3, 16(sp) - c->sq(s4, 32, sp); // sq s4, 32(sp) - c->sq(s5, 48, sp); // sq s5, 48(sp) - c->sq(gp, 64, sp); // sq gp, 64(sp) - c->mov64(gp, a0); // or gp, a0, r0 - c->mov64(s5, a1); // or s5, a1, r0 - c->mov64(s4, a2); // or s4, a2, r0 - c->lui(v1, 17152); // lui v1, 17152 - c->mtc1(f0, v1); // mtc1 f0, v1 - c->lwc1(f1, 76, s4); // lwc1 f1, 76(s4) - c->muls(f0, f0, f1); // mul.s f0, f0, f1 - c->cvtws(f0, f0); // cvt.w.s f0, f0 - c->mfc1(v1, f0); // mfc1 v1, f0 - c->lq(a0, 12, s4); // lq a0, 12(s4) - c->addiu(a0, r0, 0); // addiu a0, r0, 0 - //beq r0, r0, L27 // beq r0, r0, L27 - // nop // sll r0, r0, 0 - goto block_5; // branch always - - - block_1: - c->addiu(a1, r0, 0); // addiu a1, r0, 0 - //beq r0, r0, L26 // beq r0, r0, L26 - // nop // sll r0, r0, 0 - goto block_3; // branch always - - - block_2: - c->dsll(a2, a1, 2); // dsll a2, a1, 2 - c->dsll(a3, a0, 4); // dsll a3, a0, 4 - c->daddu(a2, a2, a3); // daddu a2, a2, a3 - c->load_symbol2(a3, cache.font_work); // lw a3, *font-work*(s7) - c->daddu(a2, a2, a3); // daddu a2, a2, a3 - c->lwu(a2, 2160, a2); // lwu a2, 2160(a2) - // Unknown instr: ld a3, L164(fp) - c->gprs[a3].du64[0] = 0xffffffff'00ffffff; - c->and_(a2, a2, a3); // and a2, a2, a3 - c->dsll32(a3, v1, 24); // dsll32 a3, v1, 24 - c->dsrl32(a3, a3, 0); // dsrl32 a3, a3, 0 - c->or_(a2, a2, a3); // or a2, a2, a3 - c->dsll(a3, a1, 2); // dsll a3, a1, 2 - c->dsll(t0, a0, 4); // dsll t0, a0, 4 - c->daddu(a3, a3, t0); // daddu a3, a3, t0 - c->load_symbol2(t0, cache.font_work); // lw t0, *font-work*(s7) - c->daddu(a3, a3, t0); // daddu a3, a3, t0 - c->sw(a2, 2160, a3); // sw a2, 2160(a3) - c->daddiu(a1, a1, 1); // daddiu a1, a1, 1 - - block_3: - c->slti(a2, a1, 4); // slti a2, a1, 4 - bc = c->sgpr64(a2) != 0; // bne a2, r0, L25 - // nop // sll r0, r0, 0 - if (bc) {goto block_2;} // branch non-likely - - c->mov64(a1, s7); // or a1, s7, r0 - c->mov64(a1, s7); // or a1, s7, r0 - c->daddiu(a0, a0, 1); // daddiu a0, a0, 1 - - block_5: - c->slti(a1, a0, 40); // slti a1, a0, 40 - bc = c->sgpr64(a1) != 0; // bne a1, r0, L24 - // nop // sll r0, r0, 0 - if (bc) {goto block_1;} // branch non-likely - - c->mov64(a0, s7); // or a0, s7, r0 - c->mov64(a0, s7); // or a0, s7, r0 - c->load_symbol2(a0, cache.font_work); // lw a0, *font-work*(s7) - c->sw(v1, 2156, a0); // sw v1, 2156(a0) - c->load_symbol2(t9, cache.dma_buffer_free); // lw t9, dma-buffer-free(s7) - c->mov64(a0, s5); // or a0, s5, r0 - call_addr = c->gprs[t9].du32[0]; // function call: - c->sll(v0, ra, 0); // sll v0, ra, 0 - c->jalr(call_addr); // jalr ra, t9 - c->mov64(s3, v0); // or s3, v0, r0 - c->mov64(a0, gp); // or a0, gp, r0 - c->load_symbol2(v1, cache.string); // lw v1, string(s7) - c->lwu(t9, 32, v1); // lwu t9, 32(v1) - call_addr = c->gprs[t9].du32[0]; // function call: - c->sll(v0, ra, 0); // sll v0, ra, 0 - c->jalr(call_addr); // jalr ra, t9 - c->mov64(v1, v0); // or v1, v0, r0 - c->dsll(v1, v1, 5); // dsll v1, v1, 5 - c->sltu(v1, s3, v1); // sltu v1, s3, v1 - bc = c->sgpr64(v1) == 0; // beq v1, r0, L28 - // nop // sll r0, r0, 0 - if (bc) {goto block_8;} // branch non-likely - - c->lq(v0, 12, s4); // lq v0, 12(s4) - c->mov128_gpr_gpr(v1, v0); // por v1, v0, r0 - //beq r0, r0, L29 // beq r0, r0, L29 - // nop // sll r0, r0, 0 - goto block_9; // branch always - - - block_8: - c->load_symbol2(t9, cache.draw_string_asm); // lw t9, draw-string-asm(s7) - c->mov64(a0, gp); // or a0, gp, r0 - c->mov64(a1, s5); // or a1, s5, r0 - c->mov64(a2, s4); // or a2, s4, r0 - call_addr = c->gprs[t9].du32[0]; // function call: - c->sll(v0, ra, 0); // sll v0, ra, 0 - c->jalr(call_addr); // jalr ra, t9 - c->mov128_gpr_gpr(v1, v0); // por v1, v0, r0 - - block_9: - c->addiu(v1, r0, 0); // addiu v1, r0, 0 - //beq r0, r0, L33 // beq r0, r0, L33 - // nop // sll r0, r0, 0 - goto block_14; // branch always - - - block_10: - c->addiu(a0, r0, 0); // addiu a0, r0, 0 - //beq r0, r0, L32 // beq r0, r0, L32 - // nop // sll r0, r0, 0 - goto block_12; // branch always - - - block_11: - c->dsll(a1, a0, 2); // dsll a1, a0, 2 - c->dsll(a2, v1, 4); // dsll a2, v1, 4 - c->daddu(a1, a1, a2); // daddu a1, a1, a2 - c->load_symbol2(a2, cache.font_work); // lw a2, *font-work*(s7) - c->daddu(a1, a1, a2); // daddu a1, a1, a2 - c->lwu(a1, 2160, a1); // lwu a1, 2160(a1) - // Unknown instr: ld a2, L164(fp) - c->gprs[a2].du64[0] = 0xffffffff'00ffffff; - c->and_(a1, a1, a2); // and a1, a1, a2 - c->ori(a2, r0, 32768); // ori a2, r0, 32768 - c->dsll(a2, a2, 16); // dsll a2, a2, 16 - c->or_(a1, a1, a2); // or a1, a1, a2 - c->dsll(a2, a0, 2); // dsll a2, a0, 2 - c->dsll(a3, v1, 4); // dsll a3, v1, 4 - c->daddu(a2, a2, a3); // daddu a2, a2, a3 - c->load_symbol2(a3, cache.font_work); // lw a3, *font-work*(s7) - c->daddu(a2, a2, a3); // daddu a2, a2, a3 - c->sw(a1, 2160, a2); // sw a1, 2160(a2) - c->daddiu(a0, a0, 1); // daddiu a0, a0, 1 - - block_12: - c->slti(a1, a0, 4); // slti a1, a0, 4 - bc = c->sgpr64(a1) != 0; // bne a1, r0, L31 - // nop // sll r0, r0, 0 - if (bc) {goto block_11;} // branch non-likely - - c->mov64(a0, s7); // or a0, s7, r0 - c->mov64(a0, s7); // or a0, s7, r0 - c->daddiu(v1, v1, 1); // daddiu v1, v1, 1 - - block_14: - c->slti(a0, v1, 40); // slti a0, v1, 40 - bc = c->sgpr64(a0) != 0; // bne a0, r0, L30 - // nop // sll r0, r0, 0 - if (bc) {goto block_10;} // branch non-likely - - c->mov64(v1, s7); // or v1, s7, r0 - c->mov64(v1, s7); // or v1, s7, r0 - c->addiu(v1, r0, 128); // addiu v1, r0, 128 - c->load_symbol2(a0, cache.font_work); // lw a0, *font-work*(s7) - c->sw(v1, 2156, a0); // sw v1, 2156(a0) - c->ld(ra, 0, sp); // ld ra, 0(sp) - c->ld(fp, 8, sp); // ld fp, 8(sp) - c->lq(gp, 64, sp); // lq gp, 64(sp) - c->lq(s5, 48, sp); // lq s5, 48(sp) - c->lq(s4, 32, sp); // lq s4, 32(sp) - c->lq(s3, 16, sp); // lq s3, 16(sp) - //jr ra // jr ra - c->daddiu(sp, sp, 80); // daddiu sp, sp, 80 - goto end_of_function; // return - - // nop // sll r0, r0, 0 - // nop // sll r0, r0, 0 - end_of_function: - return c->gprs[v0].du64[0]; -} - -void link() { - cache.font_work = intern_from_c("*font-work*").c(); - cache.dma_buffer_free = intern_from_c("dma-buffer-free").c(); - cache.draw_string_asm = intern_from_c("draw-string-asm").c(); - cache.string = intern_from_c("string").c(); - gLinkedFunctionTable.reg("draw-string", execute, 512); -} - -} // namespace draw_string -} // namespace Mips2C - //--------------------------MIPS2C--------------------- // clang-format off #include "game/mips2c/mips2c_private.h" diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index 5a29a0c0a67..41606403635 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -123,7 +123,6 @@ namespace moving_sphere_triangle_intersect { extern void link(); } namespace calc_animation_from_spr { extern void link(); } namespace cspace_parented_transformq_joint { extern void link(); } namespace draw_string_asm { extern void link(); } -namespace draw_string { extern void link(); } namespace get_string_length { extern void link(); } namespace adgif_shader_texture_with_update { extern void link(); } namespace debug_line_clip { extern void link(); } @@ -333,8 +332,7 @@ PerGameVersion>> gMips2C {{"collide-func", {jak2::collide_do_primitives::link, jak2::moving_sphere_triangle_intersect::link}}, {"joint", {jak2::calc_animation_from_spr::link, jak2::cspace_parented_transformq_joint::link}}, - {"font", - {jak2::draw_string::link, jak2::get_string_length::link, jak2::draw_string_asm::link}}, + {"font", {jak2::get_string_length::link, jak2::draw_string_asm::link}}, {"texture", {jak2::adgif_shader_texture_with_update::link}}, {"debug", {jak2::debug_line_clip::link, jak2::init_boundary_regs::link, diff --git a/goal_src/jak2/engine/gfx/font.gc b/goal_src/jak2/engine/gfx/font.gc index d8fa0d00e0d..15627710e42 100644 --- a/goal_src/jak2/engine/gfx/font.gc +++ b/goal_src/jak2/engine/gfx/font.gc @@ -5,8 +5,7 @@ ;; name in dgo: font ;; dgos: ENGINE, GAME -(def-mips2c draw-string-asm (function string dma-buffer font-context uint)) -(def-mips2c draw-string (function string dma-buffer font-context draw-string-result)) +(def-mips2c draw-string-asm (function string dma-buffer font-context draw-string-result)) (def-mips2c get-string-length (function string font-context draw-string-result)) ;; DECOMP BEGINS @@ -146,7 +145,29 @@ ;; ERROR: function was not converted to expressions. Cannot decompile. -;; ERROR: function was not converted to expressions. Cannot decompile. +(defun draw-string ((arg0 string) (arg1 dma-buffer) (arg2 font-context)) + (local-vars (result draw-string-result)) + (let ((v1-1 (the int (* 128.0 (-> arg2 alpha))))) + (-> arg2 origin quad) + (dotimes (a0-2 40) + (dotimes (a1-1 4) + (set! (-> *font-work* color-table a0-2 color a1-1 a) v1-1) + ) + ) + (set! (-> *font-work* color-shadow w) v1-1) + ) + (if (< (the-as uint (dma-buffer-free arg1)) (the-as uint (* (length arg0) 32))) + (set! result (the-as draw-string-result (-> arg2 origin quad))) + (set! result (draw-string-asm arg0 arg1 arg2)) + ) + (dotimes (v1-7 40) + (dotimes (a0-9 4) + (set! (-> *font-work* color-table v1-7 color a0-9 a) #x80) + ) + ) + (set! (-> *font-work* color-shadow w) 128) + result + ) ;; ERROR: function was not converted to expressions. Cannot decompile.