-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.s
175 lines (133 loc) · 2.58 KB
/
terminal.s
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
.reset_display
lda #$0 ;set memory access row to 0
sta $300
lda #0
sta $301 ;cursor x to 0
sta $302 ;cursor y to 0
lda #$02
sta $303 ;cursor mode to blink
jsr .clear_line
lda #' '
sta $308 ;set blit x start to 0
lda #$00
sta $309 ;set blit y start to 0
sta $30a ;set blit x offset to 0
sta $30b ;set blit y offset to 0
lda #80 ;set blit width to 80
sta $30c
lda #50 ;set blit height to 50
sta $30d
lda #$1 ;fill
sta $307
.clear_screen_wait
wai
lda $307
bne .clear_screen_wait
.getch
lda #$1
mmu #$0
.getch_loop
lda $304 ;load keybuffer start to accu
sta .getch_counter ;store keybuffer in zeropage
lda $305 ;load keybuffer position in accu
cmp .getch_counter ;compare keybuffer start and position for key detection
;note: if keypress is detected 305 will increment
;buffer start and position(incremented) will be unequal and bne will branch
bne + ;if accu does not equal value in $5d0 branch (+ means go to next + on branch)
jmp .getch_loop ;if no keypress was detected loop
+ lda .getch_counter
sta $305 ;set keybuffer start to keybuffer position - this may skip some key strokes
lda $306 ;load newly typed character from start of keybuffer
rts
.scroll_screen
lda #0
sta $308
lda #1
sta $309
lda #0
sta $30a
sta $30b
lda #80
sta $30c
lda #49
sta $30d
lda #3
sta $307
.scroll_line_loop
wai
lda $307
cmp #$00
bne .scroll_line_loop
.clear_line
phx
lda .printch_row_length
tax
lda #' '
.clear_line_loop
dex
sta $310, x
cpx #0
bne .clear_line_loop
plx
rts
rts
.printbs
txa
cmp #$00
beq .printbs_exit
lda #$20 ;fill current char with space
sta $310,x
dex ;decrement x to go one character back
.printbs_exit
rts
.printcr
ldx #$00 ;reset x (go back to start of line)
lda .printcr_row
cmp .printcr_column_height
bne .printcr_space_left
jsr .scroll_screen
jsr .clear_line
lda .printcr_row
jmp .printcr_no_space_left
.printcr_space_left
inc
sta .printcr_row
.printcr_no_space_left
sta $300
sta $302
lda #$00
sta .print_col
sta $301
rts
.printch
phx
sta .printch_char
lda .print_col
cmp .printch_row_length
bne .printch_print ; if char does not fit on line, do a line break
jsr .printcr
.printch_print
lda .print_col
tax
inc .print_col
inc
sta $301
lda .printch_char
sta $310,x
plx
rts
.print
cmp .cr_char
beq .print_cr
cmp .bs_char
beq .print_bs
.print_print
jsr .printch
jmp .print_exit
.print_cr
jsr .printcr
jmp .print_exit
.print_bs
jsr .printbs
.print_exit
rts