more line search code optimizations

This commit is contained in:
FeralChild64 committed 2020-07-19 12:13:58 +02:00
1 parent b48d576698
commit fc3a40a254
2 files changed
+25 -26

No files matched your search

+17 -24
View File
@@ -25,8 +25,8 @@ find_line_from_current:
// Check if line is not empty // Check if line is not empty
jsr peek_line_pointer_null_check jsr find_line_null_ptr_check // we can't use 'peek_line_pointer_null_check', it maps out/in the BASIC ROM
bcc find_line_fail beq_16 remap_BASIC_sec_rts // search failed if there is no program
// Fetch the high byte of line number and compare // Fetch the high byte of line number and compare
@@ -35,36 +35,25 @@ find_line_from_current:
cmp LINNUM+1 cmp LINNUM+1
beq !+ 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 bne find_line_next
!: !:
// Fetch the low byte of line number and compare // Fetch the low byte of line number and compare
dey dey
lda (OLDTXT),y lda (OLDTXT),y
cmp LINNUM+0 cmp LINNUM+0
beq find_line_success beq_16 remap_BASIC_clc_rts
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 bne find_line_next
find_line_success:
// Restore default memory mapping and quit
lda #$27
sta CPU_R6510
clc
rts
find_line_next: find_line_next:
// Advance to the next line // Advance to the next line
jsr peek_line_pointer_null_check jsr find_line_null_ptr_check // we can't use 'peek_line_pointer_null_check', it maps out/in the BASIC ROM
bcc find_line_fail // branch in no more lines exist beq_16 remap_BASIC_sec_rts // search failed if no more line exists
ldy #$00 ldy #$00
lda (OLDTXT),y lda (OLDTXT),y
@@ -79,15 +68,19 @@ find_line_next:
jmp_8 find_line_from_current 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 ldy #$01 // for non-NULL pointer, high byte is almost certainly not NULL
sta CPU_R6510 lda (OLDTXT),y
bne !+
dey
sec lda (OLDTXT),y
bne !+
!:
rts rts
#endif #endif
@@ -21,14 +21,18 @@ peek_line_pointer_null_check:
ldy #$01 // for non-NULL pointer, high byte is almost certainly not NULL ldy #$01 // for non-NULL pointer, high byte is almost certainly not NULL
lda (OLDTXT),y lda (OLDTXT),y
bne !+ bne !+ // branch if pointer not NULL
dey dey
lda (OLDTXT),y lda (OLDTXT),y
bne !+ bne !+ // branch if pointer not NULL
// Pointer is NULL // Pointer is NULL
// FALLTROUGH
remap_BASIC_clc_rts:
lda #$27 lda #$27
sta CPU_R6510 sta CPU_R6510
@@ -37,6 +41,8 @@ peek_line_pointer_null_check:
!: !:
// Pointer not NULL // Pointer not NULL
remap_BASIC_sec_rts:
lda #$27 lda #$27
sta CPU_R6510 sta CPU_R6510