@@ -60,6 +60,23 @@ reset_data_2:
6060 mva #.sizeof(Line) + 2 , data_line_pos ; Skip 1 for DATA, 1 for next statement offset
6161 rts
6262
63+ ; Advances next_line_ptr to the next line.
64+ ; next_line_ptr = current next line (updated)
65+ ; X SAFE, BC SAFE, DE SAFE
66+
67+ advance_next_line_ptr:
68+ ldy #Line::next_line_offset
69+ lda (next_line_ptr),y ; Get next line offset into A
70+ clc
71+ adc next_line_ptr ; Add line length to low byte of next_line_ptr
72+ sta next_line_ptr ; Save back
73+ bcc set_next_line_pos ; Don't need to change the high byte
74+ inc next_line_ptr+1 ; Increment the high byte
75+
76+ set_next_line_pos:
77+ mvy #.sizeof(Line), next_line_pos
78+ rts
79+
6380; Sets next_line_ptr to program_ptr. Does not change the run state.
6481; Returns next_line_ptr in AX.
6582; BC SAFE, DE SAFE
@@ -68,8 +85,7 @@ reset_next_line_ptr:
6885 ldax program_ptr
6986reset_next_line_ptr_2:
7087 stax next_line_ptr
71- mvy #.sizeof(Line), next_line_pos
72- rts
88+ bne set_next_line_pos ; Unconditional: stax doesn't affect flags, ldax sets Z from high byte
7389
7490; Builds a null line at the location passed in AX. The null line has line number -1 and a length of zero.
7591; The zero length prevents advance_next_line_ptr from advancing past the line.
@@ -131,22 +147,6 @@ compare_next_line_to_target:
131147@done:
132148 rts
133149
134- ; Advances next_line_ptr to the next line.
135- ; next_line_ptr = current next line (updated)
136- ; X SAFE, BC SAFE, DE SAFE
137-
138- advance_next_line_ptr:
139- ldy #Line::next_line_offset
140- lda (next_line_ptr),y ; Get next line offset into A
141- clc
142- adc next_line_ptr ; Add line length to low byte of next_line_ptr
143- sta next_line_ptr ; Save back
144- bcc @skip ; Don't need to change the high byte
145- inc next_line_ptr+1 ; Increment the high byte
146- @skip:
147- mvy #.sizeof(Line), next_line_pos
148- rts
149-
150150; Updates the program based on the information in line_buffer.
151151; If the line number in line_buffer is in the program, remove it.
152152; If line_buffer contains a new line, then insert it into the program.
0 commit comments