diff --git a/c64/basic/,aliases.s b/c64/basic/,aliases.s index fa8a34fc..b0b572b1 100644 --- a/c64/basic/,aliases.s +++ b/c64/basic/,aliases.s @@ -127,6 +127,7 @@ .alias missed_nmi_flag $2A7 .alias tiny_nmi_handler $2A8 .alias shift_mem_up tiny_nmi_handler+shift_mem_up_routine-tiny_nmi_handler_routine + .alias shift_mem_down tiny_nmi_handler+shift_mem_down_routine-tiny_nmi_handler_routine .alias peek_under_roms tiny_nmi_handler+peek_under_roms_routine-tiny_nmi_handler_routine .alias poke_under_roms tiny_nmi_handler+poke_under_roms_routine-tiny_nmi_handler_routine .alias memmap_allram tiny_nmi_handler+memmap_allram_routine-tiny_nmi_handler_routine diff --git a/c64/basic/basic_delete_line.s b/c64/basic/basic_delete_line.s index e15e44fd..48ce3516 100644 --- a/c64/basic/basic_delete_line.s +++ b/c64/basic/basic_delete_line.s @@ -5,5 +5,56 @@ ;; banked out. Oh, yes, and we have to update all the links in ;; the following basic lines. basic_delete_line: + + jsr printf + .byte "DELETING LINE AT $" + .byte $f1,basic_current_line_ptr + .byte $f0,basic_current_line_ptr + .byte $0d,0 + + ;; Get address of next line + ldx #255 bytes. + ;; Either way, things are bad, so abort. + ldx #35 + jmp do_basic_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 basic_end_of_text_ptr+0 + sec + sbc tokenise_work3 + sta basic_end_of_text_ptr+0 + lda basic_end_of_text_ptr+1 + sbc #0 + sta basic_end_of_text_ptr+1 + + clc rts diff --git a/c64/basic/basic_insert_line.s b/c64/basic/basic_insert_line.s index 20350239..3eee0e44 100644 --- a/c64/basic/basic_insert_line.s +++ b/c64/basic/basic_insert_line.s @@ -14,11 +14,17 @@ basic_insert_line: ;; But first, remember where the pointer will be, so that we can ;; put the line in there after. + + jsr printf + .byte "INSERTING LINE AT $" + .byte $f1,basic_current_line_ptr + .byte $f0,basic_current_line_ptr + .byte $0d,0 + lda basic_current_line_ptr+0 - sta $0438 pha lda basic_current_line_ptr+1 - sta $0439 + pha ;; Get number of bytes in tokenised line after line number @@ -75,6 +81,6 @@ line_store_loop: bne line_store_loop dec tokenise_work2 - sec + clc rts diff --git a/c64/basic/basic_shift_mem_down.s b/c64/basic/basic_shift_mem_down.s new file mode 100644 index 00000000..d8ff0d27 --- /dev/null +++ b/c64/basic/basic_shift_mem_down.s @@ -0,0 +1,135 @@ +basic_shift_mem_down_and_relink: + ;; Shift memory down to basic_current_line_pointer + ;; from X bytes further along. + + ;; Destination is basic_current_line_ptr + lda basic_current_line_ptr+0 + sta memmove_dst+0 + lda basic_current_line_ptr+1 + sta memmove_dst+1 + + ;; Source is that plus X + txa + pha ; also keep for later + clc + adc basic_current_line_ptr+0 + sta memmove_src+0 + lda basic_current_line_ptr+1 + adc #0 + sta memmove_src+1 + + ;; Size is distance from source to end of BASIC text. + lda basic_end_of_text_ptr+0 + sec + sbc memmove_src+0 + sta memmove_size+0 + lda basic_end_of_text_ptr+1 + sbc memmove_src+1 + sta memmove_size+1 + + jsr printf + .byte "TOP OF BASIC = $" + .byte $f1,basic_end_of_text_ptr + .byte $f0,basic_end_of_text_ptr + .byte $0d + .byte "SHIFTING UP $" + .byte $f1,memmove_size + .byte $f0,memmove_size + .byte " BYTES FROM $" + .byte $f1,memmove_src + .byte $f0,memmove_src + .byte " TO $" + .byte $f1,memmove_dst + .byte $f0,memmove_dst + .byte $0d,0 + + ;; The copy routine that copies under the ROMs is as simple + ;; as possible to be as small as possible, so we have + ;; to adjust the pointers and counts so that the simple + ;; increment and decrement bounds checks work. + + ;; Specifically we want Y pre-set so that the end of the + ;; copy ends when Y = $00. + ;; So if copying 1 byte, we want Y=$FF + ;; This means we have to then reduce the source and + ;; target pointers by the same amount + + lda memmove_size + eor #$ff + sta tokenise_work3 + + lda memmove_src+0 + sec + sbc tokenise_work3 + sta memmove_src+0 + lda memmove_src+1 + sbc #0 + sta memmove_src+1 + + lda memmove_dst+0 + sec + sbc tokenise_work3 + sta memmove_dst+0 + lda memmove_dst+1 + sbc #0 + sta memmove_dst+1 + + ;; Get Y value ready for the copy + ldy memmove_size+0 + + jsr printf + .byte "REVISED BOUNDS $" + .byte $f1,memmove_size + .byte $f0,memmove_size + .byte " BYTES FROM $" + .byte $f1,memmove_src + .byte $f0,memmove_src + .byte " TO $" + .byte $f1,memmove_dst + .byte $f0,memmove_dst + .byte $0d,0 + + jsr shift_mem_down + + ;; Get length of deletion back + pla + sta tokenise_work3 + +relink_down_next_line: + inc $d020 + jmp relink_down_next_line + + ;; Subtract tokenise_work3 from the pointer + ldy #0 + ldx # memmove_src + ;; This means we have to copy from the back end down. + ;; This routine assumes the pointers are already pointed + ;; to the end of the areas, and that Y is correctly initialised + ;; to allow the copy to begin. + jsr memmap_allram +smd1: + lda (memmove_src),y + sta (memmove_dst),y + iny + bne smd1 + inc memmove_src+1 + inc memmove_dst+1 + dec memmove_size+1 + bne smd1 + jmp memmap_normal + peek_under_roms_routine: stx peek_under_roms+7 ;Offset of arg of lda ($00),y diff --git a/src/compress_text.c b/src/compress_text.c index 29a3bf6b..2beae876 100644 --- a/src/compress_text.c +++ b/src/compress_text.c @@ -164,6 +164,7 @@ char *error_list[]={ "SAVING", "ERROR", // #33 // Simply the word error that is attached to the other parts of messages https://fjkraan.home.xs4all.nl/comp/apple2faq/app2asoftfaq.html "BYTES FREE.\r\r", // #34 // https://github.com/stefanhaustein/expressionparser + "MEMORY CORRUPT", // #35 NULL}; // Token $FF is end of message, so we can have only 255 unique words