From 4e91e1e52d21d99ca6e2465e89676b6daf242310 Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Wed, 4 Mar 2026 13:58:19 -0700 Subject: [PATCH 1/5] format unconditional jumps in crt0.S --- src/crt/crt0.S | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/crt/crt0.S b/src/crt/crt0.S index 3a7112997..1bf8533a6 100644 --- a/src/crt/crt0.S +++ b/src/crt/crt0.S @@ -96,6 +96,7 @@ __start: ldir ld a, ti.kClear jp ti.JForceCmd + .local ___app_start ___app_start: #else @@ -132,6 +133,7 @@ __start: #if HAS_LIBLOAD call ti.PushRealO1 ; save running program name jr .L.tryfind + .L.inram: call ti.Arc_Unarc .L.tryfind: @@ -150,6 +152,7 @@ __start: pop hl ; start of loader (required to be in hl) ld de, ___libload_libs ; start of relocation data jp (hl) ; jump to the loader -- it should take care of everything else + .L.notfound: call ti.PopRealO1 ; restore running program name call ti.ClrScrn @@ -217,6 +220,7 @@ ___libload_libs_ret: inc hl ld b, (hl) jr .L.parse_ans_next + .L.parse_ans_loop: inc hl dec bc @@ -295,6 +299,7 @@ ___libload_libs_ret: #if HAS_INIT_ARRAY ld hl, __init_array_start jr .L.init_array_start + .L.init_array_loop: push hl ld hl, (hl) @@ -331,6 +336,7 @@ ___exithl: _exit: #if HAS_ATEXIT jr .L.exit_function_start + .L.exit_function_loop: ld hl, (ix + 1 + 0 * 3) ld (__atexit_functions), hl @@ -357,6 +363,7 @@ _exit: #if HAS_FINI_ARRAY ld hl, __fini_array_end jr .L.fini_array_start + .L.fini_array_loop: dec hl dec hl @@ -381,6 +388,7 @@ _exit: #endif #if HAS_ABORT jr .L.skip._abort + .global _abort .type _abort, @function _abort: From ed8f3bc43586c372355113f9c3bcca6a0df9a0d7 Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:00:13 -0700 Subject: [PATCH 2/5] optimized skip._abort --- src/crt/crt0.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crt/crt0.S b/src/crt/crt0.S index 1bf8533a6..b77530de7 100644 --- a/src/crt/crt0.S +++ b/src/crt/crt0.S @@ -387,7 +387,8 @@ _exit: pop hl #endif #if HAS_ABORT - jr .L.skip._abort + ; jr .L.skip._abort + db $FD ; ld iy, * .global _abort .type _abort, @function From 76e13f3a36e2d9efae69327cfc3a5868081e2ce1 Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:01:22 -0700 Subject: [PATCH 3/5] remove unneeded or a, a --- src/crt/crt0.S | 1 - 1 file changed, 1 deletion(-) diff --git a/src/crt/crt0.S b/src/crt/crt0.S index b77530de7..ce7abb6bd 100644 --- a/src/crt/crt0.S +++ b/src/crt/crt0.S @@ -71,7 +71,6 @@ __start: ld sp, (ti.onSP) ; reset stacks call ti.ResetStacks ld bc, ___data_len - or a, a sbc hl, hl adc hl, bc jr z, .L.skip_data_copy From 540ec027522b20862e4e28ff9e1cfae19ee9da7e Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:30:54 -0700 Subject: [PATCH 4/5] optimized clock zeroize --- src/crt/crt0.S | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/crt/crt0.S b/src/crt/crt0.S index ce7abb6bd..e6feb75e5 100644 --- a/src/crt/crt0.S +++ b/src/crt/crt0.S @@ -286,11 +286,16 @@ ___libload_libs_ret: res ti.bTmr1Enable, (hl) set ti.bTmr1Crystal, (hl) res ti.bTmr1Overflow, (hl) - ld l, (ti.mpTmr1Counter + 1) & 0xFF - ld de, 0 ; Set the counter to zero - ld (hl), de - dec hl - ld (hl), e + + ; Set the counter to zero + .errif (ti.mpTmr1Counter & 0xFFFF) != 0 + ld l, h ; ld hl, ti.mpTmr1Counter + ld b, 4 +.L.zeroize_counter: + ld (hl), h + inc hl + djnz .L.zeroize_counter + ld l, ti.mpTmrCtrl & 0xFF set ti.bTmr1Enable, (hl) ; Enable the timer #endif From 581c3df072f3c6b6e0cc4144737c3d23cac20919 Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Wed, 4 Mar 2026 15:23:58 -0700 Subject: [PATCH 5/5] use the pointer as the loop counter --- src/crt/crt0.S | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/crt/crt0.S b/src/crt/crt0.S index e6feb75e5..9589412d0 100644 --- a/src/crt/crt0.S +++ b/src/crt/crt0.S @@ -289,12 +289,11 @@ ___libload_libs_ret: ; Set the counter to zero .errif (ti.mpTmr1Counter & 0xFFFF) != 0 - ld l, h ; ld hl, ti.mpTmr1Counter - ld b, 4 + ld l, (ti.mpTmr1Counter + 4) & 0xFF .L.zeroize_counter: + dec l ld (hl), h - inc hl - djnz .L.zeroize_counter + jr nz, .L.zeroize_counter ld l, ti.mpTmrCtrl & 0xFF set ti.bTmr1Enable, (hl) ; Enable the timer