small cleanup in BASIC

This commit is contained in:
FeralChild64 committed 2020-06-28 08:32:25 +02:00
1 parent 5db25db3b5
commit 996327b335
3 files changed
+23 -24

No files matched your search

+89
View File
@@ -0,0 +1,89 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Delete the current BASIC line, which is assumed to have already been found with find_line.
// Consists of copying memory down and lline linkage update.
//
delete_line:
// jsr printf
// .text "DELETING LINE AT $"
// .byte $f1,<OLDTXT,>OLDTXT
// .byte $f0,<OLDTXT,>OLDTXT
// .byte $0d,0
// Get address of next line
ldy #0
#if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT
jsr peek_under_roms
#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
jsr peek_under_roms_via_OLDTXT
#else // CONFIG_MEMORY_MODEL_38K
lda (OLDTXT),y
#endif
sta __tokenise_work3
iny
#if CONFIG_MEMORY_MODEL_60K
jsr peek_under_roms
#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
jsr peek_under_roms_via_OLDTXT
#else // CONFIG_MEMORY_MODEL_38K
lda (OLDTXT),y
#endif
sta __tokenise_work4
// Work out length of this line by looking at the pointer
lda __tokenise_work3
sec
sbc OLDTXT+0
sta __tokenise_work3
lda __tokenise_work4
sbc OLDTXT+1
sta __tokenise_work4
// jsr printf
// .text "LINE LENGTH IS $"
// .byte $f0,<__tokenise_work4,>__tokenise_work4
// .byte $f0,<__tokenise_work3,>__tokenise_work3
// .byte $0d,0
lda __tokenise_work4
sbc #0
cmp #$00
beq !+
// Line length is <0 or >255 bytes.
// Either way, things are bad, so abort.
jmp do_MEMORY_CORRUPT_error
!:
// Length can now be safely assumed to be in the low
// byte only, i.e., stored in __tokenise_work3
lda __tokenise_work3
pha
tax
// Shuffle everything down
jsr basic_shift_mem_down_and_relink
// Now decrease top of BASIC mem
pla
sta __tokenise_work3
lda VARTAB+0
sec
sbc __tokenise_work3
sta VARTAB+0
lda VARTAB+1
sbc #0
sta VARTAB+1
clc
rts
+106
View File
@@ -0,0 +1,106 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Insert the tokenised line stored at $0200.
//
// First work out where in the list to put it (find_line with the line number can be used to work
// out the insertion point, as it should abort once it finds a line number too high).
// Then all we have to do is push the rest of the BASIC text up,
// and update the pointers in all following basic lines.
//
insert_line:
// ASSUMES find_line has been called to set the insert point.
// We need to insert space for the link link token, the line number,
// and the zero-terminated line itself. This means 2+2+1 plus length
// of tokenised string after the line number
// But first, remember where the pointer will be, so that we can
// put the line in there after.
// jsr printf
// .text "INSERTING LINE AT $"
// .byte $f1,<OLDTXT,>OLDTXT
// .byte $f0,<OLDTXT,>OLDTXT
// .byte $0d,0
lda OLDTXT+0
pha
lda OLDTXT+1
pha
// Get number of bytes in tokenised line after line number
lda __tokenise_work2
sec
sbc __tokenise_work1
// Add on the four bytes space we need
clc
adc #5
pha
tax
// Make the space
jsr basic_shift_mem_up_and_relink
// Now increase top of BASIC mem
pla
clc
adc VARTAB+0
sta VARTAB+0
lda VARTAB+1
adc #0
sta VARTAB+1
// Get pointer back
pla
sta OLDTXT+1
pla
sta OLDTXT+0
// Write the line number
ldy #2
lda LINNUM+0
#if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT+0
jsr poke_under_roms
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
sta (OLDTXT),y
#endif
iny
lda LINNUM+1
#if CONFIG_MEMORY_MODEL_60K
jsr poke_under_roms
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
sta (OLDTXT),y
#endif
// Now store the line body itself
inc __tokenise_work2
!:
ldx __tokenise_work1
lda $0200,x
inc __tokenise_work1
iny
#if CONFIG_MEMORY_MODEL_60K
ldx #<OLDTXT+0
jsr poke_under_roms
#else // CONFIG_MEMORY_MODEL_38K || CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
sta (OLDTXT),y
#endif
lda __tokenise_work1
cmp __tokenise_work2
bne !-
dec __tokenise_work2
clc
rts
+7 -9
View File
@@ -148,24 +148,22 @@ shell_add_delete_line:
// First, clear all variables, so that we only have to shove BASIC text around
jsr basic_do_clr
.break
// Delete line if present
// Check if line already present
jsr find_line
// XXX
bcs !+
// Delete the line, whether we are deleting or
// replacing the line
jsr basic_delete_line
// Line already present - delete it
.break
jsr delete_line
!:
// Insert new line if non-zero length, i.e., that
// we are not just deleting the line.
lda __tokenise_work1
cmp __tokenise_work2
beq !+
jsr basic_insert_line
jsr insert_line
!:
// No READY message after entering or deleting a line of BASIC
jmp shell_read_next_line