forked from mist64/msbasic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtty.s
executable file
·282 lines (220 loc) · 3.8 KB
/
tty.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
; memory map
; 0x0000 - 0x7FFF RAM (32KB)
; 0x8000 - 0x8FFF Devices (4KB) 16 devices, 256 bytes each, D1 = 0x8000-0x80FF, D2= 0x8100-0x81FF ...
; 0x9000 - 0xFFFF ROM (28KB)
; VGA display stuff
A_RXD = $8100
A_TXD = $8100
A_STS = $8101
A_RES = $8101
A_CMD = $8102
A_CTL = $8103
COORD = $80
SHADOW = $90
COLVAL = $80
ROWVAL = $81
SHADOWCOL = $90
SHADOWROW = $91
.org $2000
init:
sei
ldx #$FF
txs
lda #$00
sta COLVAL
sta SHADOWCOL
lda #$C0
sta ROWVAL
and #$7F
sta SHADOWROW
; initialize the ACIA
sta A_RES ; soft reset (value not important)
lda #$0B ; set specific modes and functions
; no parity, no echo, no Tx interrupt, no Rx interrupt, enable Tx/Rx
sta A_CMD ; store to the command register
;lda #$00 ; 1 stop bits, 8 bit word length, external clock, 16x baud rate
lda #$1F ; 1 stop bits, 8 bit word length, internal clock, 19.2k baud rate
sta A_CTL ; program the ctl register
loop:
jsr rx_char_sync
jsr output_char
jsr tx_char_sync
jmp loop ; repeat
new_line:
pha
lda #$00
sta COLVAL ; column goes to 0
inc ROWVAL
lda ROWVAL
cmp #$E3 ; if row 23
bne @exit
jsr scroll ; clear screen
@exit:
pla
rts
inc_col:
pha
inc COLVAL
lda COLVAL
cmp #$61
bne @exit
jsr new_line
@exit:
pla
rts
backspace:
pha
lda COLVAL
cmp #$00
beq @exit
lda #$00
jsr write_char
dec COLVAL
@exit:
pla
rts
output_char:
phx
ldx COLVAL
stx $E300
ldx ROWVAL
stx $E302
plx
cmp #$03
beq wozmon
cmp #$0D
beq @crlf
cmp #$0A
beq @exit
cmp #$1B
beq @clear
cmp #$7F
beq @backspace
cmp #$08
beq @backspace
bra @char_out
@crlf:
jsr new_line
bra @exit
@clear:
lda #$00
sta COLVAL
lda #$C0
sta ROWVAL
jsr cls
bra @exit
@backspace:
jsr backspace
bra @exit
@char_out:
jsr inc_col
jsr write_char
@exit:
rts
wozmon:
jmp $FF00
write_char:
phy
ldy #$00
sta (COORD),y
pha
lda ROWVAL
and #$7F
sta SHADOWROW
lda COLVAL
sta SHADOWCOL
pla
sta (SHADOW),y
ply
rts
tx_char_sync:
pha
@wait:
lda A_STS ; get status byte
and #$10 ; mask transmit buffer status flag
beq @wait ; loop if tx buffer full
pla ; restore A
sta A_TXD ; save byte to ACIA data port
rts
rx_char_sync:
lda A_STS ; get status byte
and #$08 ; max rx buffer status flag
beq rx_char_sync ; loop if rx buffer is empty
lda A_RXD ; get byte from ACIA
rts
cls:
pha
phx
phy
ldy #$00
ldx #$00
stx COLVAL
stx SHADOWCOL
lda #$BF
sta ROWVAL
and #$7F
sta SHADOWROW
lda #$00
@loopy:
ldy #$00
inc ROWVAL
inc SHADOWROW
@loopx:
sta (COORD),y
sta (SHADOW),y
iny
cpy #$FF
bne @loopx
ldy #$00
ldx ROWVAL
cpx #$E6
bne @loopy
ldx #$00
stx COLVAL
stx SHADOWCOL
ldx #$C0
stx ROWVAL
and #$7F
stx SHADOWROW
ply
plx
pla
rts
scroll:
pha
phy
lda #$00
sta COLVAL
sta SHADOWCOL
lda #$C0
sta ROWVAL
and #$7F
sta SHADOWROW
@looprow:
ldy #$00
inc ROWVAL
inc SHADOWROW
@loopcol:
lda (SHADOW),y
dec ROWVAL
dec SHADOWROW
sta (COORD),y
sta (SHADOW),y
inc ROWVAL
inc SHADOWROW
iny
cpy #$64
bne @loopcol
lda ROWVAL
cmp #$E3
bne @looprow
lda #$00
sta COLVAL
sta SHADOWCOL
lda #$E2
sta ROWVAL
and #$7F
sta SHADOWROW
ply
pla
rts