From 6bad8fa605f5011cadab428156c18b4067922185 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Tue, 24 Mar 2020 18:46:44 -0400 Subject: Added support in SuBEditor for true backspace, and inserting characters without replacing the old ones. --- programs/subeditor.s | 191 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 160 insertions(+), 31 deletions(-) (limited to 'programs/subeditor.s') diff --git a/programs/subeditor.s b/programs/subeditor.s index 5769936..1001f83 100644 --- a/programs/subeditor.s +++ b/programs/subeditor.s @@ -46,6 +46,8 @@ scr_tcol: .byte $0 scr_ptr: .word $0 +scr_ptr2: + .word $0 ; Registers. a: .byte $0 @@ -151,6 +153,8 @@ start: tay jsl clr_cbuf ply #2 + ;lda #1 + ;sta $C010 lda.w #string jsl print_str lda.w zero @@ -204,6 +208,8 @@ print_str: sta.q ptr ldb #0 tba + inb + stb b pntstr_st: phy #2 txy @@ -215,6 +221,8 @@ pntstr_st: jmp pntstr_st pntstr_end: ply #2 + ldb #0 + stb b rtl @@ -278,6 +286,7 @@ getchar: lda $C002 ; Get typed character. ldb #0 stb e + stb b pha #1 phy #2 cmp #10 @@ -363,8 +372,72 @@ print_char: beq bs ; Did the user type a backspace? sta a printc: + lda (ptr5), y ; Are we at the end of the string? + beq printc_save ; Yes, so just print the character. + lda b ; No, but was the flag set? + bne printc_save ; Yes, so don't shift the line. + sty.w scr_ptr ; No, so save the cursor index for later. +prntc_fndnd: + lda (ptr5), y ; Are we at the end of the string? + beq prntc_movln ; Yes, so make room for the next character. + iny ; No, so increment the cursor index. + jmp prntc_fndnd ; Keep looping. +printc_updt: + jmp prntc_updt2 +prntc_updt1: + pla #1 + clc + adc scr_row + sta scr_row + jsl update_pos +prntc_updt2: + lda scr_row + pha #1 + lda scr_col + pha #1 + jsl rdrw_row + pla #1 + sta scr_col + pla #1 + sta scr_row + jsl update_pos +prntc_updt3: + ldb scr_row + lda scr_trow + sec + sab + pha #1 + tab + sec + sab + clc + sta scr_row +prntc_updt4: + jsl getbit + bcs prntc_updt1 + pla #1 + lda scr_trow + sta scr_row + jsl update_pos + dec d + jmp printc_sav1 +prntc_movln: + tyx + dey + ldb #1 + stb d + jsl shftln + ldb #1 + stb d + lda scr_row + sta scr_trow +printc_save: + ldb d + bne printc_updt +printc_sav1: lda a sta (ptr5), y ; Store typed character into the input buffer. +printc_inc: inc scr_col ; Increment the cursor's x coordinate. iny printc_2: @@ -414,7 +487,10 @@ printc_end: nl: lda #0 + ldb (ptr5), y + bne nl1 sta (ptr5), y ; Store said terminator into the input buffer. +nl1: sta scr_col lda scr_row cmp #23 @@ -468,11 +544,16 @@ stp_end: jmp printc_end back: - lda #$7F ; Print a backspace to the screen. - sta $C001 ; dey ; Decrement the buffer's offset. lda #0 ; Place a null terminator sta (ptr5), y ; into the buffer. + tyx ; Copy the current cursor index to X. + iny ; Increment cursor index. + ldb #0 + stb d + jsl shftln ; Move/Shift line back by one character. + lda #$7F ; Print a backspace to the screen. + sta $C001 ; dec scr_col ; Move the cursor back by one column, jsl update_pos ; and update it's position. jmp printc_end ; We are done. @@ -510,6 +591,49 @@ backwrp2: jsl update_pos ; Update the cursor's position. jmp back ; Delete the previous character. +shftln: + ldb d ; Is the flag set? + beq shftln_lp1 ; Yes, so shift, and increment. + jmp shftln_lp0 ; No, so shift, and decrement. +shftln_neg: + ldy.w zero ; Set the source poition to 0. + lda #0 ; Clear the character + sta (ptr5), y ; that is in the source. + jmp shftln_end ; We are done. +shftln_lp0: + sty.w scr_ptr2 ; Save the source position for later. + ldy.w scr_ptr ; Get the previous cursor index. + cpy.w scr_ptr2 ; Is the source position, at, or below the cursor index? + beq shftln_lp01 ; Yes, so keep looping. + bcs shftln_end ; No, so we're done. +shftln_lp01: + ldy.w scr_ptr2 ; Get the source position. + lda (ptr5), y ; Get the character from the source position. + phy #2 ; Save the source position for later. + txy ; Set our position to the destination. + sta (ptr5), y ; Place the character from the source position, to the destination position. + ply #2 ; Set our position back to the source. + lda #0 ; Clear the character + sta (ptr5), y ; that is in the source. + dey ; Decrement the source position. + bng shftln_neg ; The source underflowed, so set it back to zero, + dex ; Decrement the destination position. + jmp shftln_lp0 ; Keep looping. +shftln_lp1: + lda (ptr5), y ; Is the character at the source position, a null terminator? + beq shftln_end ; Yes, so we're done. + phy #2 ; No, so save the source position for later. + txy ; Set our position to the destination. + sta (ptr5), y ; Place the character from the source position, to the destination position. + inx ; Increment the destination position. + ply #2 ; Set our position back to the source. + lda #0 ; Clear the character + sta (ptr5), y ; that is in the source. + iny ; Increment the source position. + jmp shftln_lp1 ; Keep looping. +shftln_end: + rtl ; We are done. + esc: lda $C000 ; Get the next character. lda $C002 ; @@ -611,8 +735,8 @@ isright_wrp: dec scr_row ; No, so move the cursor back up a row. jmp isright_dne ; We are done. isright_scr: - lda scr_str ; Are we at the top of the screen buffer? - beq isright_end ; Yes, so we're done. +; lda scr_str ; Are we at the top of the screen buffer? +; beq isright_end ; Yes, so we're done. lda #1 ; No, so scroll down. sta wrapped ; Set the wrapped flag. jsl scrl_down ; Scroll down. @@ -622,6 +746,7 @@ wrap_inc: sta scr_col ; lda scr_row ; Get the current row number. cmp #23 ; Are we at the bottom of the screen? + beq isright_nd2 ; No, so we're done. bcs isright_scr ; Yes, so check if we are scrolling down. jmp isright_nd2 ; We are done. isright_end: @@ -741,8 +866,13 @@ update_pos: clc lda scr_row adc scr_str + tay clc - mul #80 + lsl #6 + tab + tya + lsl #4 + aab clc adc scr_col tay @@ -781,7 +911,6 @@ getcol: rtl ; End of getrow. scrl_down: - inc scr_str inc scr_end lda #$1B ; Print an escape character @@ -851,14 +980,16 @@ rdrow_inc: inc scr_col lda (ptr5), y beq rdrow_skip - iny rdrow_inc1: + iny +rdrow_inc2: lda scr_col cmp #80 bcs rdrow_end jmp rdrow_st rdrow_skip: - jsl update_pos + lda #$20 + sta $C001 ; to the screen. jmp rdrow_inc1 rdrow_end: lda #0 @@ -867,26 +998,32 @@ rdrow_end: rdrow_done: rtl - ;rdrw_scr: -; lda #$C -; sta $C001 -; lda scr_col -; sta scr_tcol ; lda scr_row -; sta scr_trow +; sta e ; lda #0 -; sta scr_col ; sta scr_row -; phy #2 +; lda scr_col +; sta f +; jsl update_pos +;rdscr_st: +; jsl rdrw_row +; lda scr_row +; cmp #23 +; beq rdscr_inc +; bcs rdscr_done +;rdscr_inc: +; inc scr_row +; jmp rdscr_st +;rdscr_done: +; lda e +; sta scr_row +; lda f +; sta scr_col ; jsl update_pos -; ply #2 -; ldx scr_ptr -; phy #2 -; txy -; lda (ptr), y -; sta $C001 -; ply #2 +; lda #0 +; sta e +; sta f ; rtl result: @@ -945,14 +1082,6 @@ cmd_clr: .org $FFC0 .qword reset -.org $FF50 -.qword spin -.qword spin -.qword spin -.qword spin -.qword spin -.qword spin -.qword spin r ;.org $8000 ;v -- cgit v1.2.3-13-gbd6f