Skip to content

Commit c866c34

Browse files
committed
optimized branches, and formatted unconditional branches
1 parent ede3843 commit c866c34

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

src/fontlibc/fontlibc.asm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,4 +2100,3 @@ currentFontRoot := _CurrentFontRoot - DataBaseAddr
21002100
DataBaseAddr:
21012101
; Embed the current font's properties as library variables
21022102
_CurrentFontProperties strucFont
2103-

src/libload/libload.asm

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +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-
push af
223-
ld hl, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr)
224-
add hl, de
225-
ex de, hl ; end of the extraction table?
226-
pop af
227-
pop hl
228-
jr z, .not_loaded
229-
jr .loop
230216
.match: ; mark as previously loaded (don't resolve absolutes again)
231217
set loaded, (iy + LIB_FLAGS)
232218
pop hl
@@ -246,6 +232,21 @@ check_already_loaded:
246232
inc hl ; bypass version byte
247233
ld (jump_tbl_ptr), hl
248234
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+
push af
243+
ld hl, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr)
244+
add hl, de
245+
ex de, hl ; end of the extraction table?
246+
pop af
247+
pop hl
248+
jr nz, .loop
249+
249250
.not_loaded:
250251
ld hl, (lib_name_ptr)
251252
move_string_to_end
@@ -254,18 +255,19 @@ findlib:
254255
call ti.ChkFindSym
255256
jr nc, .foundlib ; throw an error if the library doesn't exist
256257
bit optional,(iy + LIB_FLAGS)
257-
jr z, .missing ; if optional, zeroize marker and move on
258-
pop hl ; get version byte pointer
259-
jr optional_lib_clear
258+
; if optional, zeroize marker and move on
259+
jr nz, optional_lib_clear_pop_hl
260260
.missing:
261261
rjump error_missing ; jump to the lib missing handler
262+
262263
.foundlib:
263264
call ti.ChkInRam
264265
jr nz, .archived ; if the library is found in ram, archive the library and search again
265266
call ti.PushOP1
266267
call ti.Arc_Unarc
267268
call ti.PopOP1
268269
jr findlib
270+
269271
.archived:
270272
ex de, hl
271273
ld de, 9
@@ -293,6 +295,7 @@ assert LIB_MAGIC_1 = LIB_MAGIC_1_ALT+1
293295
jr z, lib_exists
294296
bit optional,(iy + LIB_FLAGS)
295297
jr z, invalid_error
298+
optional_lib_clear_pop_hl:
296299
pop hl ; get version byte pointer
297300
optional_lib_clear:
298301
push hl
@@ -312,10 +315,13 @@ optional_lib_clear:
312315
inc hl
313316
inc hl ; move to next jump
314317
jr .loop
318+
315319
.done:
316320
rjump check_for_lib_marker
321+
317322
invalid_error:
318323
rjump error_invalid ; throw an error if the library doesn't match the magic numbers
324+
319325
lib_exists:
320326
inc hl ; hl->version byte in library
321327
push hl ; save location of version byte
@@ -338,10 +344,10 @@ lib_exists:
338344
cp a, (hl) ; check if library version in program is greater than library version on-calc
339345
jr nc, good_version
340346
bit optional,(iy + LIB_FLAGS)
341-
jr z, .version_error
342-
jr optional_lib_clear
347+
jr nz, optional_lib_clear
343348
.version_error:
344349
rjump error_version ; c flag set if on-calc lib version is less than the one used in the program
350+
345351
good_version:
346352
push hl
347353
push de
@@ -395,8 +401,8 @@ need_to_load_lib:
395401
ld (end_arc_lib_locs), hl
396402

397403
bit keep_in_arc, (iy + LIB_FLAGS)
398-
jr z, .not_in_arc
399-
jr resolve_entry_points
404+
jr nz, resolve_entry_points
405+
400406
.not_in_arc:
401407
ld hl, (loaded_size)
402408
push hl
@@ -455,6 +461,7 @@ enqueue_all_deps: ; we don't need to store anything if we are here
455461
inc hl
456462
inc hl ; jp address
457463
jr .next
464+
458465
.check:
459466
cp a, ti.AppVarObj
460467
jr z, .skip ; keep going
@@ -482,6 +489,7 @@ resolve_entry_points_enqueued:
482489
ld (hl), de ; de=resolved address
483490
add hl, bc ; move to next jump
484491
jr .loop
492+
485493
.done: ; finished resolving entry points
486494
; now relocate absolutes in library
487495
relocate_absolutes:
@@ -516,6 +524,7 @@ relocate_absolutes:
516524
pop hl
517525
inc hl ; move to next relocation vector
518526
jr .loop
527+
519528
.done: ; have we found the start of the program?
520529
bit is_dep, (iy + LIB_FLAGS)
521530
jr nz, load_next_dep ; if loading dependencies, don't check markers
@@ -530,6 +539,7 @@ check_for_lib_marker:
530539
jr nz, check_has_deps
531540
goto_load_lib:
532541
rjump load_lib ; load the next library
542+
533543
check_has_deps: ; the first time we hit this, we have all the dependencies placed onto the queue that the libraries use.
534544
res optional, (iy + LIB_FLAGS)
535545
bit is_dep, (iy + LIB_FLAGS)
@@ -563,9 +573,11 @@ load_next_dep:
563573
error_invalid:
564574
rload str_error_invalid
565575
jr throw_error
576+
566577
error_version:
567578
rload str_error_version
568579
jr throw_error
580+
569581
error_missing:
570582
rload str_error_missing
571583
throw_error: ; draw the error message onscreen
@@ -607,8 +619,7 @@ throw_error: ; draw the error message onscreen
607619
cp a,ti.skEnter
608620
jr z,.exit
609621
cp a,ti.skClear
610-
jr z,.exit
611-
jr .wait_key
622+
jr nz,.wait_key
612623
.exit:
613624
call ti.ClrScrn
614625
call ti.HomeUp

0 commit comments

Comments
 (0)