print_char: ; sta a ; Save the typed character for now. pha ; Preserve the character. ; ldb #2 ; Make sure that set_ptr sets the third pointer. lda.d #buffer ; Set the third pointer to the start of the screen buffer. pha.q ; Push the pointer onto the stack. lda sp+9 ; Get the character back. ; jsr set_ptr ; ; ldb #0 ; Set B to zero. ; tba ; Set the Accumulator to zero. ; lda a ; Get back the character. cmp #$1B ; Did the user type an escape character? beq esc ; Yes, so go check the escape code. cmp #'\n' ; No, but did the user type a newline? beq nl ; Yes, so handle the newline. cmp #$C ; No, but did the user type Ctrl+L? beq clr_scr ; Yes, so clear the screen. cmp #19 ; No, but did the user type Ctrl+S? beq en_step ; Yes, so enable clock/instruction stepping. cmp #18 ; No, but did the user type Ctrl+R? beq dis_step ; Yes, so disable clock/instruction stepping. cmp #'\b' ; No, but did the user type a backspace? beq bs ; Yes, so handle the backspace. cmp #$7F ; No, but did they type Delete? beq bs ; Yes, so treat it as a backspace. printc: lda #0 ; No, so start trying to print a character. sta d ; lda (sp+1), y ; Are we at the end of the string? beq @save ; Yes, so just print the character. lda b ; No, but was the flag set? bne @save ; Yes, so don't shift the line. sty.w scr_ptr ; No, so save the cursor index for later. jsr fndend ; Find the end of the line. bra @shift ; Start shifting the line right. @update: lda scr_col ; Save the current column position for later. sta scr_tcol ; @update1: jsr findend ; Find the end of the line. sta e ; Use it for redrawing the line. sta scr_row ; Set the row position to to the end of the line. jsr findst ; Find the start of the line. lda scr_row ; Get the start of the line. @update2: sta f ; Set the starting line, to the start of the line. jsr rdrw_ln ; Redraw the line. lda scr_trow ; Get the real row position back. sta scr_row ; lda scr_tcol ; Get the real column position back. sta scr_col ; jsr update_pos ; Update the cursor's position. dec d ; bra @save1 ; @shift: ldy.w scr_ptr3 ; inc scr_ptr3 ; tyx ; dey ; ldb #1 ; stb d ; jsr shftln ; ldb #1 ; stb d ; ; lda a ; lda sp+9 ; sta (sp+1), y ; store typed character into the input buffer. lda scr_row ; sta scr_trow ; bra @update ; @save: ldb d ; bne @update ; @save1: ; lda a ; lda sp+9 ; sta (sp+1), y ; store typed character into the input buffer. @incr: inc scr_col ; Increment the cursor's x coordinate. iny ; @wrapped: ldb #1 ; stb f ; ldb scr_col ; cpb #maxcol+1 ; bcs @scrolled ; @print: sta scr ; Echo typed character. ldb f ; beq @wrap ; bra printc_end ; @scrolled: ldb scr_row ; cpb #maxrow ; bcs @scroll ; @wrapped2: ldb #0 ; stb f ; bra @print ; @scroll: sta scr ; Echo typed character. clc ; lda #1 ; sta wrapped ; jsr scrl_down ; @wrap: ldb #0 stb scr_col ; ldb scr_row ; cpb #maxrow ; bcs @wrap2 ; @wrap1: inc scr_row ; @wrap2: phx.w ; clc ; lda scr_row ; adc scr_str ; tax ; jsr setbit ; plx.w ; jsr update_pos ; printc_end: pla.q ; Pull the pointer off the stack. pla ; Pull the character off the stack. and #0 ; Reset A. rts ; nl: lda #0 ; Reset A. ldb (sp+1), y ; Is this character not a null terminator? bne @scroll ; Yes, so don't overwrite it. sta (sp+1), y ; No, so overwrite it. @scroll: sta scr_col ; Move the cursor to the start of the next line. lda scr_row ; Get the row position. cmp #maxrow ; Are we at the bottom of the screen? bcc @incr ; No, so move down one line. jsr scrl_down ; Yes, so scroll down one line. bra @end ; We are done. @incr: inc scr_row ; Move the cursor down by one line. jsr update_pos ; Update the cursor's position. @end: lda #'\n' ; Print the newline. sta a ; rts ;