summaryrefslogtreecommitdiff
path: root/programs/sub-suite/print_char.s
blob: e12461cc4aafda88be729770ac2739f261f2d511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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		;