From fc3a40a254c415db9ef5a47330e6dfbd41a93e6c Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 19 Jul 2020 12:13:58 +0200 Subject: [PATCH] more line search code optimizations --- src/basic/engine_editor/find_line_46K_50K.s | 43 ++++++++----------- .../peek_line_pointer_null_check_46K_50K.s | 10 ++++- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/basic/engine_editor/find_line_46K_50K.s b/src/basic/engine_editor/find_line_46K_50K.s index cbcce444..235129d3 100644 --- a/src/basic/engine_editor/find_line_46K_50K.s +++ b/src/basic/engine_editor/find_line_46K_50K.s @@ -25,8 +25,8 @@ find_line_from_current: // Check if line is not empty - jsr peek_line_pointer_null_check - bcc find_line_fail + jsr find_line_null_ptr_check // we can't use 'peek_line_pointer_null_check', it maps out/in the BASIC ROM + beq_16 remap_BASIC_sec_rts // search failed if there is no program // Fetch the high byte of line number and compare @@ -35,36 +35,25 @@ find_line_from_current: cmp LINNUM+1 beq !+ - bcs find_line_fail // branch if line number too high + bcs_16 remap_BASIC_sec_rts // search failed if line number too high bne find_line_next !: - // Fetch the low byte of line number and compare dey lda (OLDTXT),y cmp LINNUM+0 - beq find_line_success - bcs find_line_fail // branch if line number too high + beq_16 remap_BASIC_clc_rts + bcs_16 remap_BASIC_sec_rts // search failed if line number too high bne find_line_next -find_line_success: - - // Restore default memory mapping and quit - - lda #$27 - sta CPU_R6510 - - clc - rts - find_line_next: // Advance to the next line - jsr peek_line_pointer_null_check - bcc find_line_fail // branch in no more lines exist + jsr find_line_null_ptr_check // we can't use 'peek_line_pointer_null_check', it maps out/in the BASIC ROM + beq_16 remap_BASIC_sec_rts // search failed if no more line exists ldy #$00 lda (OLDTXT),y @@ -79,15 +68,19 @@ find_line_next: jmp_8 find_line_from_current -find_line_fail: +find_line_null_ptr_check: - // Restore default memory mapping and quit + // Check the pointer - lda #$27 - sta CPU_R6510 - - - sec + ldy #$01 // for non-NULL pointer, high byte is almost certainly not NULL + lda (OLDTXT),y + bne !+ + + dey + lda (OLDTXT),y + bne !+ +!: rts + #endif diff --git a/src/basic/peek_line_pointer_null_check_46K_50K.s b/src/basic/peek_line_pointer_null_check_46K_50K.s index c837cfe9..da4856be 100644 --- a/src/basic/peek_line_pointer_null_check_46K_50K.s +++ b/src/basic/peek_line_pointer_null_check_46K_50K.s @@ -21,14 +21,18 @@ peek_line_pointer_null_check: ldy #$01 // for non-NULL pointer, high byte is almost certainly not NULL lda (OLDTXT),y - bne !+ + bne !+ // branch if pointer not NULL dey lda (OLDTXT),y - bne !+ + bne !+ // branch if pointer not NULL // Pointer is NULL + // FALLTROUGH + +remap_BASIC_clc_rts: + lda #$27 sta CPU_R6510 @@ -37,6 +41,8 @@ peek_line_pointer_null_check: !: // Pointer not NULL +remap_BASIC_sec_rts: + lda #$27 sta CPU_R6510