From 0455abe91b6a1d88e580149618fc0350730f221b Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Mon, 8 Dec 2025 14:48:42 -0700 Subject: [PATCH 1/4] optimize show_msgs --- src/libload/libload.asm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libload/libload.asm b/src/libload/libload.asm index 29caa9e34..5108faa97 100644 --- a/src/libload/libload.asm +++ b/src/libload/libload.asm @@ -94,15 +94,14 @@ disable_relocations ld (flag_save), a ld (ix_save), ix ; save IX since older ICE programs don't - ld de, show_msgs ; disable or enable error printing - ld a, 1 - ld (de), a ld hl, $AA55AA xor a, a sbc hl, bc - jr nz, .show_msgs - ld (de), a -.show_msgs: + jr z, .no_show_msgs +; .show_msgs: + inc a +.no_show_msgs: + ld (show_msgs), a ; disable or enable error printing pop hl ld de,helpers.source @@ -567,7 +566,7 @@ throw_error: ; draw the error message onscreen ld a, (show_msgs) or a, a jr z, .return - .show_msgs: +.show_msgs: ld a, ti.lcdBpp16 ld (ti.mpLcdCtrl), a push hl From 6693925b739ca89f08c0b500d3a089a75a6f3e72 Mon Sep 17 00:00:00 2001 From: unknown <71151164+ZERICO2005@users.noreply.github.com> Date: Sun, 21 Sep 2025 16:00:22 -0600 Subject: [PATCH 2/4] optimized call/load relative --- src/libload/libload.asm | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/libload/libload.asm b/src/libload/libload.asm index 5108faa97..66311dc9c 100644 --- a/src/libload/libload.asm +++ b/src/libload/libload.asm @@ -144,9 +144,7 @@ end macro relocate helpers, buf + 900 call_relative: pop ix - lea ix, ix + 3 - push ix - lea ix, ix - 3 + pea ix + 3 push de ld de, (ix) add ix, de @@ -160,14 +158,14 @@ jump_relative: pop de jp (ix) ld_relative: - pop ix - ld de, (ix) - push ix - add ix, de - lea hl, ix - pop ix - lea ix, ix + 3 - jp (ix) + pop hl + ld de, (hl) + inc hl + inc hl + inc hl + push hl + add hl, de ; add hl, relative - 3 + ret end relocate macro rcall? name @@ -182,7 +180,7 @@ end macro macro rload? name call ld_relative - dl name - $ + dl name - $ - 3 end macro start: From 9a40280ac6a8c8e8fd8711778754e37de819b1bd Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Wed, 31 Dec 2025 16:15:12 -0700 Subject: [PATCH 3/4] inlined rcall to enqueue_all_deps --- src/libload/libload.asm | 72 ++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/libload/libload.asm b/src/libload/libload.asm index 66311dc9c..9be8f4ab1 100644 --- a/src/libload/libload.asm +++ b/src/libload/libload.asm @@ -142,6 +142,7 @@ macro relocate? name, address* end macro relocate helpers, buf + 900 +if 0 call_relative: pop ix pea ix + 3 @@ -150,6 +151,7 @@ call_relative: add ix, de pop de jp (ix) +end if jump_relative: pop ix push de @@ -420,7 +422,42 @@ need_to_load_lib: resolve_entry_points: ld hl, (ramlocation) - rcall enqueue_all_deps ; get all the dependency pointers that reside in the ram lib + ; get all the dependency pointers that reside in the ram lib +enqueue_all_deps: ; we don't need to store anything if we are here + bit keep_in_arc, (iy + LIB_FLAGS) + jr nz, .finish ; really, this is just a precautionary check -- should work fine without +.loop: + res optional, (iy + LIB_FLAGS) + ld a, (hl) + cp a, REQ_LIB_MARKER ; is there a dependency? + jr nz, .check + ex de, hl + ld hl, (end_dep_queue) + ld (hl), de ; save pointer to start of this dependency -- one at a time + inc hl + inc hl + inc hl ; move to next pointer + ld (end_dep_queue), hl ; save next pointer + ex de, hl +.skip: + move_string_to_end + inc hl ; move to start of dependency jump table +.next: + ld a, (hl) + cp a, JP_OPCODE + jr nz, .loop + inc hl + inc hl + inc hl + inc hl ; jp address + jr .next +.check: + cp a, ti.AppVarObj + jr z, .skip ; keep going +.finish: + +resolve_entry_points_enqueued: + ld hl, (jump_tbl_ptr) ; hl->start of function jump table .loop: ld a, (hl) @@ -518,39 +555,6 @@ load_next_dep: ld a, 1 jp (hl) ; passed all the checks; let's start execution! :) -enqueue_all_deps: ; we don't need to store anything if we are here - bit keep_in_arc, (iy + LIB_FLAGS) - ret nz ; really, this is just a precautionary check -- should work fine without -.loop: - res optional, (iy + LIB_FLAGS) - ld a, (hl) - cp a, REQ_LIB_MARKER ; is there a dependency? - jr nz, .check - ex de, hl - ld hl, (end_dep_queue) - ld (hl), de ; save pointer to start of this dependency -- one at a time - inc hl - inc hl - inc hl ; move to next pointer - ld (end_dep_queue), hl ; save next pointer - ex de, hl -.skip: - move_string_to_end - inc hl ; move to start of dependency jump table -.next: - ld a, (hl) - cp a, JP_OPCODE - jr nz, .loop - inc hl - inc hl - inc hl - inc hl ; jp address - jr .next -.check: - cp a, ti.AppVarObj - jr z, .skip ; keep going - ret - error_invalid: rload str_error_invalid jr throw_error From be7b1264361a36fb36b7377b4b16ff9a3c48bd7c Mon Sep 17 00:00:00 2001 From: zerico <71151164+ZERICO2005@users.noreply.github.com> Date: Wed, 31 Dec 2025 16:27:17 -0700 Subject: [PATCH 4/4] optimized and formatted unconditional branches --- src/libload/libload.asm | 68 +++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/libload/libload.asm b/src/libload/libload.asm index 9be8f4ab1..c6cdffccb 100644 --- a/src/libload/libload.asm +++ b/src/libload/libload.asm @@ -210,21 +210,8 @@ check_already_loaded: inc hl inc de or a, a ; means we've reached the end of the string - jr z, .match - jr .seach_tbl -.no_match: - pop de - ld hl, (end_arc_lib_locs) - call ti.CpHLDE ; have we reached the end of the table? - push af - ex de, hl - ld de, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr) - add hl, de - ex de, hl ; end of the extraction table? - pop af - pop hl - jr z, .not_loaded - jr .loop + jr nz, .seach_tbl + .match: ; mark as previously loaded (don't resolve absolutes again) set loaded, (iy + LIB_FLAGS) pop hl @@ -244,6 +231,20 @@ check_already_loaded: inc hl ; bypass version byte ld (jump_tbl_ptr), hl rjump resolve_entry_points ; need to resolve the entry points & enqueue dependencies + +.no_match: + pop de + ld hl, (end_arc_lib_locs) + call ti.CpHLDE ; have we reached the end of the table? + push af + ex de, hl + ld de, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr) + add hl, de + ex de, hl ; end of the extraction table? + pop af + pop hl + jr nz, .loop + .not_loaded: ld hl, (lib_name_ptr) move_string_to_end @@ -251,12 +252,12 @@ check_already_loaded: findlib: call ti.ChkFindSym jr nc, .foundlib ; throw an error if the library doesn't exist - bit optional,(iy + LIB_FLAGS) - jr z, .missing ; if optional, zeroize marker and move on - pop hl ; get version byte pointer - jr optional_lib_clear + bit optional, (iy + LIB_FLAGS) + ; if optional, zeroize marker and move on + jr nz, optional_lib_clear_pop_hl .missing: rjump error_missing ; jump to the lib missing handler + .foundlib: call ti.ChkInRam jr nz, .archived ; if the library is found in ram, archive the library and search again @@ -264,6 +265,7 @@ findlib: call ti.Arc_Unarc call ti.PopOP1 jr findlib + .archived: ex de, hl ld de, 9 @@ -291,6 +293,7 @@ assert LIB_MAGIC_1 = LIB_MAGIC_1_ALT+1 jr z, lib_exists bit optional,(iy + LIB_FLAGS) jr z, invalid_error +optional_lib_clear_pop_hl: pop hl ; get version byte pointer optional_lib_clear: push hl @@ -310,10 +313,13 @@ optional_lib_clear: inc hl inc hl ; move to next jump jr .loop + .done: rjump check_for_lib_marker + invalid_error: rjump error_invalid ; throw an error if the library doesn't match the magic numbers + lib_exists: inc hl ; hl->version byte in library push hl ; save location of version byte @@ -335,11 +341,11 @@ lib_exists: pop hl ; hl->version of library in the program cp a, (hl) ; check if library version in program is greater than library version on-calc jr nc, good_version - bit optional,(iy + LIB_FLAGS) - jr z, .version_error - jr optional_lib_clear + bit optional, (iy + LIB_FLAGS) + jr nz, optional_lib_clear .version_error: rjump error_version ; c flag set if on-calc lib version is less than the one used in the program + good_version: push hl push de @@ -392,8 +398,7 @@ need_to_load_lib: ld (end_arc_lib_locs), hl bit keep_in_arc, (iy + LIB_FLAGS) - jr z, .not_in_arc - jr resolve_entry_points + jr nz, resolve_entry_points .not_in_arc: ld hl, (loaded_size) push hl @@ -451,6 +456,7 @@ enqueue_all_deps: ; we don't need to store anything if we are here inc hl inc hl ; jp address jr .next + .check: cp a, ti.AppVarObj jr z, .skip ; keep going @@ -481,6 +487,7 @@ resolve_entry_points_enqueued: inc hl inc hl ; move to next jump jr .loop + .done: ; finished resolving entry points ; now relocate absolutes in library relocate_absolutes: @@ -513,6 +520,7 @@ relocate_absolutes: inc hl inc hl ; move to next relocation vector jr .loop + .done: ; have we found the start of the program? bit is_dep, (iy + LIB_FLAGS) jr nz, load_next_dep ; if loading dependencies, don't check markers @@ -527,6 +535,7 @@ check_for_lib_marker: jr nz, check_has_deps goto_load_lib: rjump load_lib ; load the next library + check_has_deps: ; the first time we hit this, we have all the dependencies placed onto the queue that the libraries use. res optional, (iy + LIB_FLAGS) bit is_dep, (iy + LIB_FLAGS) @@ -558,9 +567,11 @@ load_next_dep: error_invalid: rload str_error_invalid jr throw_error + error_version: rload str_error_version jr throw_error + error_missing: rload str_error_missing throw_error: ; draw the error message onscreen @@ -599,11 +610,10 @@ throw_error: ; draw the error message onscreen call ti.PutS .wait_key: call ti.GetCSC - cp a,ti.skEnter - jr z,.exit - cp a,ti.skClear - jr z,.exit - jr .wait_key + cp a, ti.skEnter + jr z, .exit + cp a, ti.skClear + jr nz, .wait_key .exit: call ti.ClrScrn call ti.HomeUp