Skip to content

Commit f418706

Browse files
committed
optimized branches, and formatted unconditional branches
1 parent 3a72e6c commit f418706

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

src/libload/libload.asm

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,8 @@ check_already_loaded:
211211
inc hl
212212
inc de
213213
or a, a ; means we've reached the end of the string
214-
jr z, .match
215-
jr .seach_tbl
216-
.no_match:
217-
pop de
218-
ld hl, (end_arc_lib_locs)
219-
or a, a
220-
sbc hl, de ; have we reached the end of the table?
214+
jr nz, .seach_tbl
221215

222-
ld hl, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr)
223-
add hl, de
224-
ex de, hl ; end of the extraction table?
225-
pop hl
226-
jr z, .not_loaded
227-
jr .loop
228216
.match: ; mark as previously loaded (don't resolve absolutes again)
229217
set loaded, (iy + LIB_FLAGS)
230218
pop hl
@@ -244,6 +232,19 @@ check_already_loaded:
244232
inc hl ; bypass version byte
245233
ld (jump_tbl_ptr), hl
246234
rjump resolve_entry_points ; need to resolve the entry points & enqueue dependencies
235+
236+
.no_match:
237+
pop de
238+
ld hl, (end_arc_lib_locs)
239+
or a, a
240+
sbc hl, de ; have we reached the end of the table?
241+
242+
ld hl, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr)
243+
add hl, de
244+
ex de, hl ; end of the extraction table?
245+
pop hl
246+
jr nz, .loop
247+
247248
.not_loaded:
248249
ld hl, (lib_name_ptr)
249250
move_string_to_end
@@ -252,18 +253,19 @@ findlib:
252253
call ti.ChkFindSym
253254
jr nc, .foundlib ; throw an error if the library doesn't exist
254255
bit optional,(iy + LIB_FLAGS)
255-
jr z, .missing ; if optional, zeroize marker and move on
256-
pop hl ; get version byte pointer
257-
jr optional_lib_clear
256+
; if optional, zeroize marker and move on
257+
jr nz, optional_lib_clear_pop_hl
258258
.missing:
259259
rjump error_missing ; jump to the lib missing handler
260+
260261
.foundlib:
261262
call ti.ChkInRam
262263
jr nz, .archived ; if the library is found in ram, archive the library and search again
263264
call ti.PushOP1
264265
call ti.Arc_Unarc
265266
call ti.PopOP1
266267
jr findlib
268+
267269
.archived:
268270
ex de, hl
269271
ld de, 9
@@ -291,6 +293,7 @@ assert LIB_MAGIC_1 = LIB_MAGIC_1_ALT+1
291293
jr z, lib_exists
292294
bit optional,(iy + LIB_FLAGS)
293295
jr z, invalid_error
296+
optional_lib_clear_pop_hl:
294297
pop hl ; get version byte pointer
295298
optional_lib_clear:
296299
push hl
@@ -310,10 +313,13 @@ optional_lib_clear:
310313
inc hl
311314
inc hl ; move to next jump
312315
jr .loop
316+
313317
.done:
314318
rjump check_for_lib_marker
319+
315320
invalid_error:
316321
rjump error_invalid ; throw an error if the library doesn't match the magic numbers
322+
317323
lib_exists:
318324
inc hl ; hl->version byte in library
319325
push hl ; save location of version byte
@@ -336,10 +342,10 @@ lib_exists:
336342
cp a, (hl) ; check if library version in program is greater than library version on-calc
337343
jr nc, good_version
338344
bit optional,(iy + LIB_FLAGS)
339-
jr z, .version_error
340-
jr optional_lib_clear
345+
jr nz, optional_lib_clear
341346
.version_error:
342347
rjump error_version ; c flag set if on-calc lib version is less than the one used in the program
348+
343349
good_version:
344350
push hl
345351
push de
@@ -393,8 +399,8 @@ need_to_load_lib:
393399
ld (end_arc_lib_locs), hl
394400

395401
bit keep_in_arc, (iy + LIB_FLAGS)
396-
jr z, .not_in_arc
397-
jr resolve_entry_points
402+
jr nz, resolve_entry_points
403+
398404
.not_in_arc:
399405
ld hl, (loaded_size)
400406
push hl
@@ -453,6 +459,7 @@ enqueue_all_deps: ; we don't need to store anything if we are here
453459
inc hl
454460
inc hl ; jp address
455461
jr .next
462+
456463
.check:
457464
cp a, ti.AppVarObj
458465
jr z, .skip ; keep going
@@ -480,6 +487,7 @@ resolve_entry_points_enqueued:
480487
ld (hl), de ; de=resolved address
481488
add hl, bc ; move to next jump
482489
jr .loop
490+
483491
.done: ; finished resolving entry points
484492
; now relocate absolutes in library
485493
relocate_absolutes:
@@ -514,6 +522,7 @@ relocate_absolutes:
514522
pop hl
515523
inc hl ; move to next relocation vector
516524
jr .loop
525+
517526
.done: ; have we found the start of the program?
518527
bit is_dep, (iy + LIB_FLAGS)
519528
jr nz, load_next_dep ; if loading dependencies, don't check markers
@@ -528,6 +537,7 @@ check_for_lib_marker:
528537
jr nz, check_has_deps
529538
goto_load_lib:
530539
rjump load_lib ; load the next library
540+
531541
check_has_deps: ; the first time we hit this, we have all the dependencies placed onto the queue that the libraries use.
532542
res optional, (iy + LIB_FLAGS)
533543
bit is_dep, (iy + LIB_FLAGS)
@@ -561,9 +571,11 @@ load_next_dep:
561571
error_invalid:
562572
rload str_error_invalid
563573
jr throw_error
574+
564575
error_version:
565576
rload str_error_version
566577
jr throw_error
578+
567579
error_missing:
568580
rload str_error_missing
569581
throw_error: ; draw the error message onscreen
@@ -605,8 +617,7 @@ throw_error: ; draw the error message onscreen
605617
cp a,ti.skEnter
606618
jr z,.exit
607619
cp a,ti.skClear
608-
jr z,.exit
609-
jr .wait_key
620+
jr nz,.wait_key
610621
.exit:
611622
call ti.ClrScrn
612623
call ti.HomeUp

0 commit comments

Comments
 (0)