-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart.asm
More file actions
373 lines (340 loc) · 10.5 KB
/
Copy pathuart.asm
File metadata and controls
373 lines (340 loc) · 10.5 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
;
; ECS Extended BASIC interpreter for Intellivision
;
; UART routines.
;
; by Oscar Toledo G.
; https://nanochess.org/
;
; Creation date: Oct/08/2025.
; Revision date: Oct/10/2025. Added UART delays _after_ _every_ UART access.
;
;
; These routines are coded with information from intvnut, Lathe26 and decle.
;
; Original sparse ECS hardware information:
; http://spatula-city.org/~im14u2c/intv/tech/ecs.html
;
; UART registers and bits:
; https://forums.atariage.com/topic/289278-inty-ecs-gps/
;
; Tape routines:
; https://forums.atariage.com/topic/310486-ecs-text-editor-written-in-intybasic-with-tape-support/
;
; Aquarius printer with ECS:
; https://forums.atariage.com/topic/323929-aquarius-printer-technical-info-and-reverse-engineering/
;
CAS_HEADER_BYTE: equ $aa
CAS_HEADER_COUNT: equ 8
CAS_TIMEOUT: equ 20*60
;
; Init routines for cassette.
;
cassette_init: PROC
PSHR R5
MVII #$03,R0 ; Reset UART.
MVO R0,$00E0
CALL uart_delay
MVII #10,R1
@@1: CALL wait_frame
DECR R1
BNE @@1
PULR PC
ENDP
;
; Reset UART to play from cassette.
; Order is important for jzintv emulator.
;
cassette_play: PROC
PSHR R5
MVII #$1D,R0 ; Start cassette motor. 300 baud, mode RX, TAPE port.
MVO R0,$00E2
CALL uart_delay
MVII #$1D,R0 ; 8 bit, odd parity, 1 stop bit.
MVO R0,$00E0
CALL uart_delay
PULR PC
ENDP
;
; Reset UART to record to cassette.
; Order is important for jzintv emulator.
;
cassette_record: PROC
PSHR R5
MVII #$39,R0 ; Start cassette motor. 300 baud, mode TX, TAPE port.
MVO R0,$00E2
CALL uart_delay
MVII #$1D,R0 ; 8 bit, odd parity, 1 stop bit.
MVO R0,$00E0
CALL uart_delay
MVII #90,R1
@@0: CALL wait_frame
DECR R1
BNE @@0
PULR PC
ENDP
;
; Stop the cassette motor.
;
cassette_stop: PROC
PSHR R5
MVII #60,R1
@@0: CALL wait_frame
DECR R1
BNE @@0
CLRR R0 ; Stop cassette motor.
MVO R0,$00E2 ;
CALL uart_delay
MVII #60,R1
@@1: CALL wait_frame
DECR R1
BNE @@1
CALL printer_reset
PULR PC
ENDP
;
; Save a file.
;
; Input:
; _filename contains the filename (four bytes).
;
cassette_save: PROC
PSHR R5
CALL cassette_record
;
; Writes the eight header bytes spaced by six video frames.
;
MVII #8,R2
@@1: MVII #CAS_HEADER_BYTE,R0
CALL cassette_write
CALL wait_frame
CALL wait_frame
CALL wait_frame
CALL wait_frame
CALL wait_frame
CALL wait_frame
DECR R2
BNE @@1
;
; Record a marker.
;
MVII #$00,R0
CALL cassette_write
;
; Record the filename.
;
MVII #_filename,R4
MVII #4,R2
@@2: MVI@ R4,R0
CALL cassette_write
DECR R2
BNE @@2
;
; Record a end-of-header marker.
;
CLRR R0
CALL cassette_write
PULR PC
ENDP
;
; Load a file.
;
; Input:
; _filename contains the filename (four bytes).
;
; Output:
; 0 = File found.
; 1 = Couldn't find leader.
; 2 = The header contains other file.
;
cassette_load: PROC
PSHR R5
MVI _frame,R0
ADDI #CAS_TIMEOUT,R0 ; 20 seconds for timeout
MVO R0,_timeout
CALL cassette_play
CALL cassette_find_leader
TSTR R0
BNE @@1
CLRR R2
@@2: CALL cassette_read_timeout
CMPI #1,R0
BEQ @@1
MVII #_filename,R4
ADDR R2,R4
CMP@ R4,R0
BNE @@3
INCR R2
CMPI #4,R2
BNE @@2
CALL cassette_read_timeout
B @@1
@@3: MVII #2,R0
@@1:
PULR PC
ENDP
;
; Find the leader
;
cassette_find_leader: PROC
PSHR R5
; Restart search for header byte.
@@1: MVII #CAS_HEADER_COUNT,R4
@@2: CALL cassette_read_timeout
CMPI #1,R0
BEQ @@0
CMPI #CAS_HEADER_BYTE,R0
BNE @@1
DECR R4
BNE @@2
@@3: CALL cassette_read_timeout
CMPI #1,R0
BEQ @@0
CMPI #CAS_HEADER_BYTE,R0
BEQ @@3
TSTR R0 ; Leader ends with a zero byte.
BNE @@1 ; Isn't zero? Restart search.
@@0: PULR PC
ENDP
;
; Read a word from the cassette.
; Used for line numbers and token lengths.
;
cassette_read_word: PROC
PSHR R5
CALL cassette_read
MOVR R0,R1
CALL cassette_read
SWAP R0
ADDR R1,R0
PULR PC
ENDP
;
; Read a byte from the cassette.
;
cassette_read: PROC
PSHR R5
@@0:
MVI $00E0,R0
CALL uart_delay
ANDI #1,R0
BEQ @@0
MVI $00E1,R0
CALL uart_delay
PULR PC
ENDP
;
; Read a byte from the cassette with timeout.
;
cassette_read_timeout: PROC
PSHR R5
@@0:
MVI _timeout,R1
SUB _frame,R1
BNC @@1
MVI $00E0,R0
CALL uart_delay
ANDI #1,R0
BEQ @@0
MVI $00E1,R0
CALL uart_delay
PULR PC
@@1: MVII #1,R0
PULR PC
ENDP
;
; Record a word into the cassette.
;
cassette_write_word: PROC
PSHR R5
CALL cassette_write
SWAP R0
CALL cassette_write
SWAP R0
PULR PC
ENDP
;
; Record a byte into the cassette.
;
cassette_write: PROC
PSHR R5
@@0:
MVI $00E0,R1
CALL uart_delay
ANDI #2,R1
BEQ @@0
MVO R0,$00E1
CALL uart_delay
PULR PC
ENDP
;
; Wait for a video frame to happen.
;
wait_frame: PROC
@@0: MVI _int,R0
TSTR R0
BEQ @@0
CLRR R0
MVO R0,_int
MOVR R5,PC
ENDP
;
; Reset UART to target printer.
; Order is important for jzintv emulator.
;
printer_reset: PROC
PSHR R5
; Only to make sure jzintv actually prints (saving to file)
; jzintv has a bug, so it never prints to file (detected Oct/08/2025)
; MVII #$03,R0 ; Reset jzintv
; MVO R0,$00E0
; CALL uart_delay
MVII #$23,R0 ; 1200 baud, mode TX/CTS, AUX port.
MVO R0,$00E2
CALL uart_delay
MVII #$11,R0 ; 8 bits, 2 stop bits, no parity.
MVO R0,$00E0
CALL uart_delay
PULR PC
ENDP
;
; Send data to the printer.
;
printer_output: PROC
CMPI #$FFFF,R0
BNE @@4
MVI _printer_col,R0
MOVR R5,PC
@@4:
PSHR R5
@@0:
MVI $00E0,R1 ; Read UART status.
CALL uart_delay
ANDI #2,R1 ; TX ready?
BEQ @@0 ; No, jump.
MVO R0,$00E1 ; Write data to UART
CALL uart_delay
CMPI #$0A,R0
BEQ @@2
MVI _printer_col,R1 ; Count columns (for LPOS)
INCR R1
CMPI #40,R1 ; After column 40 goes automatically to column zero.
BEQ @@3
CMPI #$0D,R0
BNE @@1
@@3: CLRR R1
@@1: MVO R1,_printer_col
@@2:
PULR PC
ENDP
;
; UART delay.
; Required or the chip blocks itself.
;
uart_delay: PROC
PSHR R5
MVII #10,R5
@@0: DECR R5
BNE @@0
PULR PC
ENDP