-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathtapwrt.src
377 lines (297 loc) · 7.53 KB
/
tapwrt.src
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
373
374
375
376
377
.page
.subttl 'tape write'
; *** tape write routines ***
;
; primitives first...
; <w>ait for <t>imer to <t>oggle <t>wice
wttt
sec
bcs wtts
; <w>ait for <t>imer to <t>oggle
wtt
clc
wtts
sty t1pipe+2 ; save x,y
stx t1pipe+3
ldy t1pipe ; pre-load for spipe
ldx t1pipe+1
lda #$10
w1 ; wait for timeout
bit tedirq
beq w1
sty timr2l ; reload timer with latch
stx timr2h
sta tedirq ; clear flag
lda port ; toggle write line
eor #$02
sta port
php ; preserve carry (pass indicator)
jsr balout ; do stopkey check
plp ; restore carry
ldy t1pipe+2 ; restore x,y
ldx t1pipe+3
bcs wtt ; if c=1 then do twice
rts
tshort=212-4 ; 240us / 8 cycles(4us) to setup
tlong= 424-4 ; 480us / " "
tbyte= 850-4 ; 960us / " "
; setup >byte< dipole time: 306 cycles
setupb
lda #<tbyte
sta t1pipe
lda #>tbyte
sta t1pipe+1
rts
; setup >short< dipole time: 163 cycles
setups
lda #<tshort
sta t1pipe
lda #>tshort
sta t1pipe+1
rts
; setup >long< dipole time: 234 cycles
setupl
lda #<tlong
sta t1pipe
lda #>tlong
sta t1pipe+1
rts
; write a 0 on tape; ie: s,l
write0
jsr setups
jsr wttt
jsr setupl
jmp wttt ; does rts
; write a 1 on tape; ie: l,s
write1
jsr setupl
jsr wttt
jsr setups
jmp wttt ; does rts
; write a word marker on tape; ie: b,l
writew
jsr setupb
jsr wttt
jsr setupl
jmp wttt ; does rts
; write the byte in (tpbyte) to the tape with leading word marker,
; and ending odd parity.
wrbyte
sta tpbyte ; save byte to be written
lda #1
sta parity
jsr writew
ldx #8 ; #of bits
twloop
ror tpbyte ; lsb first
bcs aone
inc parity ; count the zeros
jsr write0
jmp wjoin
aone
jsr write1
wjoin
dex ; done yet?
bne twloop ; nope
ror parity ; yep, get parity
bcs aoneb
jsr write0
jmp wjoin2
aoneb
jsr write1
wjoin2
rts
; write elemental block to tape as defined by:
; (wrbase{+1})::=@beg of data to be written
; (wrlen{+1})::= 2's compl of numeric length of data
; pass::= {=0 for pass1}, {=$80 for pass2}
welemb
tsx ; save stack mark
stx srecov ; ...for stopkey
lda port ; assert external line low
ora #$02
sta port
jsr setups ; get ready for short*
ldy #1
sty timr2h ; prime t2 to use as one-shot
lda #$10 ; clear any flag
sta tedirq
; lots & lots of shorts...
bit pass ; what pass are we doing
bpl l1loop
; y=1... shorter shorts for second pass
ldy #$40 ; hi loop index...for first pass
ldx #$fe ; low loop index...for both passes
; write leader 1
l1loop
jsr wttt
dex
bne l1loop
dey
bne l1loop
; now write countdown loop
ldy #9
cdloop
tya
ora pass ; pass modifies b(7) of data
jsr wrbyte
dey
bne cdloop
; init checksum
lda type
sta chksum
; now write block type
beq wdloop ; if=0 then no type in block
jsr wrbyte
; write data block
wdloop
ldy #0
lda #wrbase ; fetch byte ( may be under rom )
sta sinner
jsr kludes
pha ;save
eor chksum
sta chksum
pla
jsr wrbyte
inc wrbase
bne okeefe
inc wrbase+1
okeefe
inc wrlen ; one more byte
bne wdloop
inc wrlen+1
bne wdloop
; data written, now do checksum
lda chksum
jsr wrbyte
; do block end marker; ie: l
jsr setupl
jsr wttt
; do end leader; ie: l*450
jsr setups
ldy #1 ; loop hi
ldx #$c2 ; loop lo
l2loop
jsr wttt
dex
bne l2loop
dey
bne l2loop ; done with elemental block
rts
; write a >fixed length data< block
; assumed data is in the pre-allocated tape buffer of 192 bytes.
; *** type must be specified externally !!! ***
wfblok
jsr tstrec
jsr faster ; 1.7mhz/get timer1/no irq's
jsr moton ; get em goin
bcs wdabor ; stop key pressed
lda #$80
sta pass
web
lda tapebs ; tapebs->wrbase
sta wrbase
lda tapebs+1
sta wrbase+1
; setup length & type
lda #$41 ; 2's compl of #191
sta wrlen
lda #$ff
sta wrlen+1
jsr welemb
bcs wdabor ; stop key pressed
lda pass
bpl wdone ; if second pass
lda #0
sta pass
bpl web ; else, do second pass
; done with both elemental blocks
wdone ; good exit
clc
wdabor ; bad exit
jsr motoff ; stop em
jmp slower ; whatever clk/give up timer1/ok irq's & RTS
; write a tape header
; ...write starting, ending address, and filename to tape.
; *** type must be specified externally !!! ***
tphead
jsr bufini
jsr blkbuf
ldy #0
lda stal
sta (tapebs),y
iny
lda stah
sta (tapebs),y
iny
lda eal
sta (tapebs),y
iny
lda eah
sta (tapebs),y
iny ; y=4 ; y@ beg of filename
sty tt2 ; pointer to tape buffer (dest)
ldy #0
sty tt1 ; pointer to filename (source)
tfname
ldy tt1
cpy fnlen
beq fnisin ; all done !
lda #fnadr ; get filename from under rom
sta sinner
jsr kludes
ldy tt2
sta (tapebs),y
inc tt1
inc tt2
jmp tfname
fnisin ; header data area is complete, now write it to tape...
jmp wfblok ; does rts ; c=0=>ok, else error
; write a >variable length data< block (ie: program type).
; block to be written is defined by: (stah/stal,eah/eal)
; *** type must be specified externallly !!! ***
wvblok
jsr tstrec
jsr faster ; 1.7mhz/get timer1/no irq's
jsr moton
bcs wpabor ; stop key pressed
lda #$80
sta pass
wepb
lda stal ; starting address -> wrbase
sta wrbase
lda stah
sta wrbase+1
; compute: ((( end-start ) <xor> $ffff)+1) -> wrlen
; by: ((end-start)-1)) <xor> $ffff) -> wrlen
;
clc
lda eal
sbc stal
eor #$ff
sta wrlen
lda eah
sbc stah
eor #$ff
sta wrlen+1
jsr welemb ; write a elem block
bcs wpabor ; ooops!
lda pass
bpl wpdone ; done with both blocks
lda #0
sta pass
bpl wepb ; write second block
; done with both elem var blocks
wpdone ; good exit
clc
wpabor ; bad exit
jsr motoff
jmp slower ; whatever clk/give up timer1/ok irq's & RTS
; write end-of-tape block
wreot
jsr blkbuf
lda #eot
sta type
jmp wfblok ;& RTS
;end