Skip to content

Commit acbc64e

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
optimized and formatted unconditional branches
1 parent b9751fd commit acbc64e

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

src/libload/libload.asm

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,8 @@ check_already_loaded:
210210
inc hl
211211
inc de
212212
or a, a ; means we've reached the end of the string
213-
jr z, .match
214-
jr .seach_tbl
215-
.no_match:
216-
pop de
217-
ld hl, (end_arc_lib_locs)
218-
call ti.CpHLDE ; have we reached the end of the table?
219-
push af
220-
ex de, hl
221-
ld de, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr)
222-
add hl, de
223-
ex de, hl ; end of the extraction table?
224-
pop af
225-
pop hl
226-
jr z, .not_loaded
227-
jr .loop
213+
jr nz, .seach_tbl
214+
228215
.match: ; mark as previously loaded (don't resolve absolutes again)
229216
set loaded, (iy + LIB_FLAGS)
230217
pop hl
@@ -244,26 +231,41 @@ check_already_loaded:
244231
inc hl ; bypass version byte
245232
ld (jump_tbl_ptr), hl
246233
rjump resolve_entry_points ; need to resolve the entry points & enqueue dependencies
234+
235+
.no_match:
236+
pop de
237+
ld hl, (end_arc_lib_locs)
238+
call ti.CpHLDE ; have we reached the end of the table?
239+
push af
240+
ex de, hl
241+
ld de, 15 ; size of search entry (9=name, 3=ram ptr, 3=arc vec ptr)
242+
add hl, de
243+
ex de, hl ; end of the extraction table?
244+
pop af
245+
pop hl
246+
jr nz, .loop
247+
247248
.not_loaded:
248249
ld hl, (lib_name_ptr)
249250
move_string_to_end
250251
push hl ; save the location in the program we are on
251252
findlib:
252253
call ti.ChkFindSym
253254
jr nc, .foundlib ; throw an error if the library doesn't exist
254-
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
255+
bit optional, (iy + LIB_FLAGS)
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
@@ -335,11 +341,11 @@ lib_exists:
335341
pop hl ; hl->version of library in the program
336342
cp a, (hl) ; check if library version in program is greater than library version on-calc
337343
jr nc, good_version
338-
bit optional,(iy + LIB_FLAGS)
339-
jr z, .version_error
340-
jr optional_lib_clear
344+
bit optional, (iy + LIB_FLAGS)
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
@@ -392,8 +398,7 @@ need_to_load_lib:
392398
ld (end_arc_lib_locs), hl
393399

394400
bit keep_in_arc, (iy + LIB_FLAGS)
395-
jr z, .not_in_arc
396-
jr resolve_entry_points
401+
jr nz, resolve_entry_points
397402
.not_in_arc:
398403
ld hl, (loaded_size)
399404
push hl
@@ -451,6 +456,7 @@ enqueue_all_deps: ; we don't need to store anything if we are here
451456
inc hl
452457
inc hl ; jp address
453458
jr .next
459+
454460
.check:
455461
cp a, ti.AppVarObj
456462
jr z, .skip ; keep going
@@ -481,6 +487,7 @@ resolve_entry_points_enqueued:
481487
inc hl
482488
inc hl ; move to next jump
483489
jr .loop
490+
484491
.done: ; finished resolving entry points
485492
; now relocate absolutes in library
486493
relocate_absolutes:
@@ -513,6 +520,7 @@ relocate_absolutes:
513520
inc hl
514521
inc hl ; move to next relocation vector
515522
jr .loop
523+
516524
.done: ; have we found the start of the program?
517525
bit is_dep, (iy + LIB_FLAGS)
518526
jr nz, load_next_dep ; if loading dependencies, don't check markers
@@ -527,6 +535,7 @@ check_for_lib_marker:
527535
jr nz, check_has_deps
528536
goto_load_lib:
529537
rjump load_lib ; load the next library
538+
530539
check_has_deps: ; the first time we hit this, we have all the dependencies placed onto the queue that the libraries use.
531540
res optional, (iy + LIB_FLAGS)
532541
bit is_dep, (iy + LIB_FLAGS)
@@ -558,9 +567,11 @@ load_next_dep:
558567
error_invalid:
559568
rload str_error_invalid
560569
jr throw_error
570+
561571
error_version:
562572
rload str_error_version
563573
jr throw_error
574+
564575
error_missing:
565576
rload str_error_missing
566577
throw_error: ; draw the error message onscreen
@@ -599,11 +610,10 @@ throw_error: ; draw the error message onscreen
599610
call ti.PutS
600611
.wait_key:
601612
call ti.GetCSC
602-
cp a,ti.skEnter
603-
jr z,.exit
604-
cp a,ti.skClear
605-
jr z,.exit
606-
jr .wait_key
613+
cp a, ti.skEnter
614+
jr z, .exit
615+
cp a, ti.skClear
616+
jr nz, .wait_key
607617
.exit:
608618
call ti.ClrScrn
609619
call ti.HomeUp

0 commit comments

Comments
 (0)