-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTTY.ASM
244 lines (198 loc) · 5.33 KB
/
TTY.ASM
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
;********************* TTY OUTPUT ROUTINES *******************
;
;THIS MODULE PROVIDES THE ROUTINES TO SUPPORT TTY OUTPUT TO THE SCREEN.
;SUBS.DOC DESCRIBES THE USAGE. IT IS INCLUDED IN THE ASSEMBLY ONLY
;IF THE VARIABLE "TTYFLG" IS DEFINED IN THE PROGRAMMERS COPY OF USERASM.ASM.
;THIS ROUTINE TAKES Y:X AS A POINTER TO A NULL TERMINATED ASCII STRING
;AND USES IT TO WRITE TTY DATA TO THE SCREEN. IT CONVERTS ASCII 0-9
;AND A-Z TO BINARY 0-9 AND $0A - $23. IT ALSO SUPPORTS THE FOLLOWING
;SPECIAL VALUES:
;01 = HOME CURSOR AND SCREEN
;09 = MOVE TO NEXT TAB STOP (8)
;$0C = clear screen and home cursor
;$0D = move to start of line then go to next line (automatic line feed)
;$20 = space character which is mapped to FA
;ASCII RANGE CHARS CAN BE FIXED BY CALLERS BY SHARING THE ROUTINE FIXASCII
;WHICH IS A LEGAL CALL POINT. SEE THAT ROUTINE BELOW.
;THIS ROUTINE MAINTAINS THE VALUES "ROW" AND "COL" AS THE CURRENT SCREEN
;CURSOR POSITION. THE SCREEN IS CONSIDERED TO BE 26 ROWS HIGH AND THE
;SCROLL IS CALCULATED BASED ON THIS. ONLY AFTER USING 01 OR 0C IS THE HOME
;POSITION TRULY AT ROW 0 SO BE CAREFUL.
;NOTE: DON'T CALL THIS ROUTINE IF THERE IS AN ACTIVE BACKGROUND. USE
;KILLBACK FIRST! KILLBACK RESETS THE SCREEN PAGE AND SCROLL VALUES
;USED BY THIS ROUTINE AND THIS ROUTINE WILL NOT CHANGE THOSE. IF YOU
;WANT TO RESET THESE FOR SOME SPECIAL PURPOSE, RESET BIT 01 IN REG2000
;AND SET XSCROLL AND YSCROLL=0. THIS ROUTINE WILL ZERO THESE ONLY
;WHEN $0C IS USED IN YOUR TEXT.
;THIS ROUTINE AUTOMATICALLY USES PAGE 0 BUT YOU MAY USE VIDEO PAGE 1 BY
;SETTING TTYBASE TO $24 FOR PAGE 1 AND $20 FOR PAGE 0. THIS VARIABLE
;WILL BE RESET TO $20 AT BOOT TIME. YOU MUST THEN SET REG2000 BIT
;01 IF YOU WANT TO USE PAGE 1 AND RESET THAT BIT IF YOU WANT TO USE PAGE 0.
;ONCE YOU CHANGE THESE VALUES YOU MUST ALSO RESTORE THEM AS NEEDED.
;TTYBASE IS ONLY SET AT BOOT TIME. REG2000 BIT 01 IS RESET WHEN KILLBACK
;IS CALLED.
;THIS ROUTINE WILL END BY ENABLING NMI INTERRUPTS.
TTY: STY MAIN_PTR+1
STX MAIN_PTR ;POINT TO THE TTY DATA
;DISABLE VIDEO AND NMI.
JSR ALLOW_WRITES
;FETCH CHARACTERS UNTIL WE FIND THE NULL.
TTY10: LDY #0
LDA (MAIN_PTR),Y
INC MAIN_PTR
BNE TTY15
INC MAIN_PTR+1 ;POINT TO NEXT
TTY15: CMP #0 ;END OF DATA?
BNE TTY20
;DONE. MAKE THE SCREEN SCROLL VALUES FOR THE DATA WE OUTPUT
JSR TTY_SCROLL
JSR RESUME_NMI
RTS
;HAVE A CHARACTER. SEE WHAT TO DO
TTY20: CMP #01 ;HOME?
BNE TTY25
JSR HOME
JMP TTY10
TTY25: CMP #$0C ;CLEAR SCREEN?
BNE TTY40
JSR HOME
LDA $2002
LDA TTYBASE
STA $2006
LDA #0
STA $2006 ;ADDRESS 2000
LDX #240
LDA #$FA
TTY30: STA $2007
STA $2007
STA $2007
STA $2007
DEX
BNE TTY30 ;CLEAR THE WHOLE SCREEN
LDX #$40
LDA #0
TTY35: STA $2007
DEX
BNE TTY35 ;THEN CLEAR THE PALETTE TOO.
JMP TTY10
TTY40: CMP #$0D ;NEW LINE?
BNE TTY60
INC ROW
LDA #0
STA COL ;GO TO START OF NEXT LINE IF SO
JSR FIXCUR
JMP TTY10
TTY60: CMP #9 ;TAB?
BNE TTY80
LDA COL
CLC
ADC #8
AND #$F8 ;AND CLEAR TO START OF IT
CMP #32 ;BUT CATCH NEXT LINE
BNE TTY70
INC ROW
LDA #0 ;GO TO START OF NEW LINE IF NEXT LINE
TTY70: STA COL ;IF SO, MOVE 8
JSR FIXCUR
JMP TTY10
TTY80: JSR FIXASCII ;FIX ASCII RANGE VALUES.
;HAVE A CHARACTER TO WRITE OUT TO VIDEO AND THEN INC CURSOR.
TTY150: PHA ;SAVE CHAR VALUE
LDA TOPROW
CLC
ADC ROW ;MAKE ROW NUMBER WE ARE WRITING TO
TTY155: CMP #30 ;BUT NEED TO WRAP AT 29
BCC TTY160
SBC #30
JMP TTY155
TTY160: TAX
LDY #32
JSR MUL ;MAKE POINTER TO THE DATA
LDA COL
CLC
ADC #1 ;AND ADD THE COLUMN OFFSET
JSR ADD_WORD
LDA $2002
TYA
CLC
ADC TTYBASE ;ADJUST FOR PAGE IN USE
STA $2006 ;ADDRESS HIGH OFFSET OF PAGE IN USE
STX $2006 ;ADDRESS LOW OFFSET
PLA
STA $2007 ;WRITE OUT THE CHAR
INC COL
JSR FIXCUR ;MOVE TO NEXT CHAR POSITION
JMP TTY10
;THIS ROUTINE WILL FIND THE CHARACTERS 0-9 AND A-Z AND SPACE IN ASCII
;AND CONVERT TO 0-9 BINARY, 10-35, AND $FA. ANYTHING ELSE IS RETURNED
;UNCHANGED.
FIXASCII:
CMP #$20 ;SPACE?
BNE FXA100
LDA #$FA ;IF SO, CONVERT TO FA
JMP FXA150
FXA100: CMP #$30 ;BELOW ASCII 0?
BCC FXA150
CMP #$3A
BCS FXA110
AND #$F ;IF 0-9, MAKE 0-9
JMP FXA150
FXA110: CMP #65 ;A-Z?
BCC FXA150
CMP #91
BCS FXA150
SEC
SBC #55
JMP FXA150
;HAVE FIXED CHARACTER IN A.
FXA150: RTS
;THIS ROUTINE IS CALLED TO CORRECT THE CURSOR POSITION. IT WILL WRAP
;PAST THE RIGHT WHEN COLUMN 30 IS REACHED AND WILL SCROLL UP WHEN ROW
;26 IS REACHED.
FIXCUR: LDA COL
CMP #30
BCC FXC10
SEC
SBC #30 ;IF PAST ROW 29, BACK UP TO 0 AND INC ROW
STA COL
INC ROW
JMP FIXCUR
FXC10: LDA ROW
CMP #26 ;IF PAST ROW 25, SCROLL UP SCREEN
BCC FXC20
DEC ROW
INC TOPROW ;SET NEW TOP OF SCREEN VALUE
LDA TOPROW
CMP #30
BNE FXC15
LDA #0
STA TOPROW ;IF PAST BOTTOM OF SCREEN, SET TOP AS NEXT
FXC15: JMP FXC10
FXC20: RTS
;THIS ROUTINE IS CALLED AFTER EACH CALL TO TTY IN ORDER TO MAKE THE
;SCREEN SCROLL VALUES USED BY NMI AS NEEDED TO DISPLAY THE FULL 26 ROWS
;THAT TTY SUPPORTS.
TTY_SCROLL:
LDA TOPROW ;GET TEXT ROW 0
ASL A
ASL A
ASL A ;MAKE PIXEL OFFSET OF THIS ROW
;IFDEF( `TOPBAR', JMP TS10, ) ;IF TOP SCORE, NO NEED TO BACK UP.
.ifdef TOPBAR
jmp TS10
.endif
SEC
SBC #16 ;BACK UP 2 ROWS TO MAKE IT DISPLAY FULLY
BCS TS10
SBC #16 ;NEED ANOTHER 2 IF GO TO TOP SINCE WE WRAP TO F0
TS10: STA YSCROLL
RTS
;THIS ROUTINE WILL HOME THE CURSOR AND SCROLL VALUES
HOME: LDA #0
STA TOPROW
STA ROW
STA COL
STA XSCROLL
LDA #-16
STA YSCROLL
RTS