Subversion Repositories MB01 Project

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 - 1
  Tue Jul 17 11:00:19 2018                                                                                               Page    1
2
 
3
 
4
 
5
 
6
 
7
 
8
 
9
          2500 A.D. 65816 Macro Assembler #26960 - Version 5.02g
10
          -----------------------------------------------------
11
 
12
                       Input  Filename : src\F9\fscbm.asm
13
                       Output Filename : obj\F9\fscbm.obj
14
                       Listing Has Been Relocated
15
 
16
 
17
 2601                        	.LIST		on
18
 2602
19
 2603  F8FFB1                		.INCLUDE inc\dirp00.inc
20
 2604                        	;----------------------------------------------------------
21
 2605                        	; DIRP00.ASM
22
 2606                        	; PROGETTO: B1601
23
 2607                        	;
24
 2608                        	; Variabili in Direct Page $00
25
 2609                        	;----------------------------------------------------------
26
 2610
27
 2611                        	; sezione COMMON -- questo permette di includere il file in piu' file
28
 2612
29
 2613                        	.LIST on
30
 2614
31
 2615                        	DIRP00:	.SECTION page0, ref_only, common	;Direct-Page 00
32
 2616
33
 2617  000000                		.ABSOLUTE		;; inizia sempre da $00
34
 2618  000000                		.ORG		0x00
35
 2619  000000
36
 2620  000000  0000          	JiffyClk	.DW			; contatore 10ms 32 bit
37
 2621  000002  0000          			.DW
38
 2622  000004                	SysTmr		.DS	SYSTMRCNT	; system timer 0 (10ms)
39
 2623  000008                	SysTMF		.DS	SYSTMRCNT	; flag timer (80 -> start)
40
 2624  00000C  00            	Bnk0Flag	.DB			; <7>: flag test RAM banco 0 ok
41
 2625                        						; <6>: flag warm reset
42
 2626  00000D  00            	RTCFlag		.DB
43
 2627
44
 2628  00000E                	diskstat	.DS	2	; flag device on ata bus #0 & #1
45
 2629                        					; <7>: device ready
46
 2630                        					; <6>: compact flash device (C.F.)
47
 2631                        					; <5>: device identification ok
48
 2632                        					; <4>: MBR loaded
49
 2633                        					; <3>: valid signature in MBR
50
 2634                        					; <2>: first partition found&active
51
 2635                        					; <1>:
52
 2636                        					; <0>: valid partition flag
53
 2637
54
 2638                        					; <7>: device ready
55
 2639                        					; <6>: USB device
56
 2640                        					; <5>: compact flash device (C.F.)
57
 2641                        					; <4>: device identification ok
58
 2642                        					; <3>: MBR loaded
59
 2643                        					; <2>: first partition found&active
60
 2644                        					; <1>: always 1
61
 2645                        					; <0>: valid partition flag
62
 2646  000010
63
  Tue Jul 17 11:00:19 2018                                                                                               Page    2
64
 
65
 
66
 
67
 
68
 2647
69
 2648          00000E        	atadev		.EQU	diskstat
70
 2649
71
 2650  000010                	usbdev		.DS	2	; flag flash disk on usb bus #0
72
 2651                        					; <7>: device plugged and ready
73
 2652                        					; <6>: always 1
74
 2653                        					; <5>: device identification ok
75
 2654                        					; <4>: MBR loaded
76
 2655                        					; <3>: valid signature in MBR
77
 2656                        					; <2>: first partition found&active
78
 2657                        					; <1>:
79
 2658                        					; <0>: valid partition flag
80
 2659
81
 2660  000012                	diskmax		.DS	16	; disk max. sector's
82
 2661          000012        	atasec		.EQU	diskmax
83
 2662          00001A        	usbsec		.EQU	diskmax+8
84
 2663
85
 2664
86
 2665  000022                	atambr		.DS	8	; data for first partition found in mbr
87
 2666                        					; first 3 bytes for start sector of partition
88
 2667                        					; last byte for partition type
89
 2668  00002A                	usbmbr		.DS	8
90
 2669
91
 2670  000032                	ataprt		.DS	8	; total sec's of first partition
92
 2671  00003A                	usbprt		.DS	8	; total sec's of first partition
93
 2672
94
 2673
95
 2674  000042  00            	usb0ch		.DB	; usb0 (ch375/ch376) flag
96
 2675                        				; <7>: module on
97
 2676                        				; <6>: ch376 flag
98
 2677                        				; <5:0>: chip version
99
 2678
100
 2679  000043  00            	usb0st		.DB	; usb0 status
101
 2680                        				; <7>: usb0 host mode ok
102
 2681                        				; <6>: flash disk attached flag
103
 2682                        				; <5>: usb device attached
104
 2683
105
 2684  000044  00            	fdcdrv		.DB		; phisycal drive status (drive #0)
106
 2685                        					; <7>: disk format established in bit 0&1
107
 2686                        					; <6>: double step seek done
108
 2687                        					; <5>: trust format bit's (set after ok r/w)
109
 2688                        					; <4>: write protect bit (if disk in drive)
110
 2689                        					; <3>: don't care
111
 2690                        					; <2>: don't care
112
 2691                        					; <1>: HD disk if set else DD disk
113
 2692                        					; <0>: CBM format if set else IBM format
114
 2693
115
 2694  000045  00            	vdrive		.DB		; virtual drive status (ram disk, drive #1)
116
 2695                        					; <7>: disk format established in bit 0&1
117
 2696                        					; <6>: change disk simulation (after format)
118
 2697                        					; <5>: don't care
119
 2698                        					; <4>: write protect bit (under sw control)
120
 2699                        					; <3>: don't care
121
 2700                        					; <2>: don't care
122
 2701                        					; <1>: HD disk if set else DD disk
123
 2702                        					; <0>: CBM format if set else IBM format
124
 2703
125
  Tue Jul 17 11:00:19 2018                                                                                               Page    3
126
 
127
 
128
 
129
 
130
 2704  000046  00            	fdcctl		.DB		; fdc controller status
131
 2705                        					; <7>: drive is attached
132
 2706                        					; <6>: drive need recalibration (restore)
133
 2707                        					; <5>: FDC controller ok
134
 2708                        					; <4>: motor on
135
 2709                        					; <3>: dma is active
136
 2710                        					; <2>: dma chip ok (post routine)
137
 2711                        					; <1>: clock rate (1=HD,0=DD)
138
 2712                        					; <0>: disk ready
139
 2713
140
 2714  000047  00            	fdctrk		.DB		; fd: current seek track
141
 2715  000048  00            	fdcerr		.DB		; fd: last error code
142
 2716  000049  00            	ataerr		.DB		; ata: last error code
143
 2717  00004A  00            	ataxer		.DB		; ata: last extended error code
144
 2718
145
 2719  00004B  00            	CtrlBrk		.DB		; flag CTRL+BREAK (NMI)
146
 2720
147
 2721  00004C  0000          	MemTop		.DW		; top memoria RAM
148
 2722  00004E  00            			.DB		; banco top mem
149
 2723
150
 2724  00004F  00            	DflTxtIn	.DB		; device di default text input
151
 2725  000050  00            	DflTxtOut	.DB		; device di default text output
152
 2726
153
 2727  000051                	COPPtr		LP		; long pointer for COP decoding
154
 2728  000054  00            	COPIdx		.DB		; COP signature/index
155
 2729
156
 2730  000055  00            	BiosEnt		.DB		; flag accesso a bios setup
157
 2731
158
 2732                        	; variabili utilizzate da ACIA
159
 2733  000056                	spwrk		.DS	$30
160
 2734
161
 2735                        	; bios mem
162
 2736  000086  0000          	nsize		.DW	; dimensione blocco da allocare
163
 2737                        	;bsize		.DW	; dimensione vera blocco free
164
 2738  000088  0000          	splitsz		.DW	; dimensione blocco splittato
165
 2739  00008A  0000          	bfree		.DW	; puntatore blocco free
166
 2740  00008C  0000          	hdrptr		.DW	; puntatore header heap
167
 2741
168
 2742  00008E  0000          	pbrklv		.DW	; current break level of current process
169
 2743  000090  0000          	pbrkmin		.DW	; minimum breal level of current process
170
 2744  000092  0000          	pbrkmax		.DW	; maximum breal level of current process
171
 2745  000094
172
 2746                        	; bios temp. work area
173
 2747  000094                	bwrktmp		.DS	$28
174
 2748
175
 2749  0000BC  00            	coptmp		.DB	; temp. used while cop
176
 2750
177
 2751  0000BD  00            	tstser		.DB	; check ser/usb test board post
178
 2752                        				; <7>: VIA2 ok
179
 2753                        				; <6>: PICRAM ok
180
 2754                        				; <1>: UART 16C550 ok
181
 2755                        				; <0>: R65C51 ok
182
 2756
183
 2757
184
 2758                        	;crc16		.DW
185
 2759
186
 2760  0000BD                		.RELATIVE
187
  Tue Jul 17 11:00:19 2018                                                                                               Page    4
188
 
189
 
190
 
191
 
192
 2761
193
 2762                        		.ENDS
194
 2763
195
 2764          [01]          	.IFDEF		_ACIA_INC_
196
 2765                        		.INCLUDE INC\SP.INC
197
 2766          [00]          	.ENDIF
198
 2767
199
 2771                        	.LIST on
200
 2772
201
 2773  F8FFB1                		.INCLUDE inc\dpcbmfs.inc
202
 2774                        	;; cbm-fs
203
 2775
204
 2776          001000        	VIECMAX		.EQU	$1000
205
 2777
206
 2778          000005        	mxfils		.EQU	5	; max # filenames in cmd string
207
 2779          000060        	cmdlen		.EQU	96	; length of command buffer (+ terminator #0)
208
 2780          000061        	fntlen		.EQU	97	; length of canonical file name table
209
 2781          00001B        	nbsiz		.EQU	27	; nambuf text size
210
 2782          000018        	dirlen		.EQU	24	; directory length used
211
 2783          000008        	maxfd		.EQU	8	; max # file descriptors
212
 2784          00000A        	intfd		.EQU	maxfd+2	; internal # file descriptors
213
 2785          00000F        	mxchnls		.EQU	15	; max # data channels
214
 2786          000008        	irdfd		.EQU	maxfd	; internal fd for read file
215
 2787          000009        	iwrfd		.EQU	maxfd+1	; internal fd for write file
216
 2788
217
 2789          000010        	bindx		.EQU	16	; bam offset index
218
 2790          000006        	bamsiz		.EQU	6	; # bytes/track in bam
219
 2791          000028        	numsec		.EQU	40	; number of logical sectors (blocks)
220
 2792          00000A        	phisec		.EQU	10	; number of phisycal sectors / track
221
 2793          000028        	dirtrk		.EQU	40	; system logical track
222
 2794          000003        	dirst		.EQU	3	; starting directory sector
223
 2795          000051        	maxtrk		.EQU	81	; max. logical track + 1
224
 2796          000001        	startrk		.EQU	1	; logical starting track
225
 2797
226
 2798                        	; max. available blocks's #
227
 2799          000C58        	maxblks		.EQU	(numsec*(maxtrk-1)-numsec)
228
 2800
229
 2801          000044        	dskvern		.EQU	$44	; disk version number
230
 2802          000033        	dosvern		.EQU	$33	; dos version number
231
 2803          00008D        	subvern		.EQU	$8D	; disk sub-version number header ofs. 29 & 30
232
 2804          0000C0        	iobyte		.EQU	$C0	; default bam i/o byte
233
 2805
234
 2806          000004        	MAXDOSDRV	.EQU	4	; dos drives are 0..3
235
 2807
236
 2808                        	;deltyp		.EQU	0	; deleted type
237
 2809          000001        	seqtyp		.EQU	1	; sequential type
238
 2810          000002        	prgtyp		.EQU	2	; program type
239
 2811          000003        	usrtyp		.EQU	3	; user type
240
 2812          000004        	reltyp		.EQU	4	; relative type
241
 2813          000005        	partyp		.EQU	5	; partition type
242
 2814          000006        	exetyp		.EQU	6	; new executable type
243
 2815          000007        	typmsk		.EQU	7	; mask for type bits
244
 2816
245
 2817                        	; internal use: open function's
246
 2818          000000        	rdmode		.EQU	0	; open read mode
247
 2819          000001        	wtmode		.EQU	1	; open write mode
248
 2820          000002        	apmode		.EQU	2	; open append mode
249
  Tue Jul 17 11:00:19 2018                                                                                               Page    5
250
 
251
 
252
 
253
 
254
 2821          000003        	mdmode		.EQU	3	; open modify mode
255
 2822          000003        	lddir		.EQU	3	; load directory
256
 2823          000004        	seqdir		.EQU	4	; open dir as seq. file
257
 2824          000005        	damode		.EQU	5	; open direct access type
258
 2825
259
 2826                        	; error codes
260
 2827          000014        	rdtrk		.EQU	20	; track read error
261
 2828          000015        	badfmt		.EQU	21	; bad disk format (or unformatted disk)
262
 2829          000016        	wrtrk		.EQU	22	; track write error
263
 2830          000018        	rdsec		.EQU	24	; read error
264
 2831          000019        	wrsec		.EQU	25	; write error
265
 2832          00001A        	wpon		.EQU	26	; write protect on
266
 2833          00001D        	badid		.EQU	29	; disk id mismatch
267
 2834          00001E        	badsyn		.EQU	30	; general syntax
268
 2835          00001F        	badcmd		.EQU	31	; invalid command
269
 2836          000020        	longln		.EQU	32	; long line
270
 2837          000021        	badfn		.EQU	33	; invalid filname
271
 2838          000022        	nofile		.EQU	34	; no file given
272
 2839          000023        	baddrv		.EQU	35	; illegal drive number
273
 2840          000024        	badchn		.EQU	36	; illegal channel number
274
 2841          000025        	nullln		.EQU	37	; empty command string
275
 2842          000027        	notsam		.EQU	39	; cannot rename across drives
276
 2843          000028        	flock		.EQU	40	; locked file
277
 2844          000029        	fsplt		.EQU	41	; write file not closed
278
 2845          00002A        	bnotm		.EQU	42	; unmatch blocks count
279
 2846          00002B        	invlnk		.EQU	43	; invalid file link
280
 2847          00002C        	badlst		.EQU	44	; wrong index in last block
281
 2848          00003C        	filopn		.EQU	60	; file open
282
 2849          00003D        	filnop		.EQU	61	; file not open
283
 2850          00003E        	flntfd		.EQU	62	; file not found
284
 2851          00003F        	flexst		.EQU	63	; file exists
285
 2852          000040        	mistyp		.EQU	64	; file type mismatch
286
 2853          000042        	badts		.EQU	66	; illegal track or sector
287
 2854          000043        	systs		.EQU	67	; illegal system t or s
288
 2855          000044        	wrfil		.EQU	68	; write only file
289
 2856          000045        	rdfil		.EQU	69	; read only file
290
 2857          000046        	nochnl		.EQU	70	; no channel available
291
 2858          000047        	direrr		.EQU	71	; directory error
292
 2859          000048        	dskful		.EQU	72	; disk full
293
 2860          000049        	cbmv2		.EQU	73	; cbm emulator version
294
 2861          00004A        	nodriv		.EQU	74	; drive not ready
295
 2862          00004B        	opnchn		.EQU	75	; channel is open
296
 2863          00004C        	nolinx		.EQU	76	; no logical index available
297
 2864          00004D        	fmter		.EQU	77	; format error
298
 2865          00004E        	ibmfmt		.EQU	78	; ibm-formatted disk
299
 2866          00004F        	syterr		.EQU	79	; system track read error
300
 2867          000050        	dirlnk		.EQU	80	; corrupted directory link
301
 2868          000051        	bamcnt		.EQU	81	; corrupted bam
302
 2869          000052        	badcat		.EQU	82	; recursive concat
303
 2870          000053        	badtlk		.EQU	83	; invalid talk command
304
 2871          000054        	badlsn		.EQU	84	; invalid listen command
305
 2872
306
 2873                        	; sezione COMMON -- questo permette di includere il file in piu' file
307
 2874
308
 2875                        	DPCBMFS: .SECTION page0, ref_only, common
309
 2876  000000                		.ABSOLUTE		;; inizia sempre da $00
310
 2877  000000                		.ORG	0x00
311
  Tue Jul 17 11:00:19 2018                                                                                               Page    6
312
 
313
 
314
 
315
 
316
 2878
317
 2879          000000        	zpstart		.EQU	$
318
 2880
319
 2881  000000                	delsec		.DS	2	; sector of 1st avail entry
320
 2882  000002                	delind		.DS	2	; index of 1st avail entry
321
 2883  000004                	dirsec		.DS	2	; directory sector of last not empty entry
322
 2884  000006                	index		.DS	2	; index of last not empty entry
323
 2885  000008  00            	track		.DB		; current track
324
 2886  000009  00            	sector		.DB		; current sector
325
 2887  00000A                	dirp		LP		; long pointer to directory entry
326
 2888  00000D  00            	nxtsec		.DB		; next sector in dir link
327
 2889  00000E  00            	type		.DB		; active file type
328
 2890  00000F  00            	mode		.DB		; active file mode
329
 2891  000010  00            	typflg		.DB		; match by type flag
330
 2892  000011  00            	patflg		.DB		; pattern presence flag
331
 2893  000012  00            	f1cnt		.DB		; file stream 1 count
332
 2894  000013  00            	f2cnt		.DB		; file stream total count
333
 2895  000014  00            	f1ptr		.DB		; file stream 1 pointer
334
 2896  000015  00            	f2ptr		.DB		; file stream 2 pointer
335
 2897  000016  00            	entfnd		.DB		; dir-entry found flag ($FF = not found)
336
 2898  000017  00            	found		.DB		; flag found in file stream
337
 2899  000018  00            	tgflg		.DB		; drive toggle flag
338
 2900                        					; <7>: search both drives
339
 2901                        					; <6>: drvnum was toggled
340
 2902
341
 2903  000019  00            	drvnum		.DB		; current drive
342
 2904
343
 2905  00001A                	filtbl		.DS	mxfils	; filename pointer
344
 2906  00001F  00            	tmpxxx		.DB		; extra byte for filtbl/tmp byte
345
 2907  000020                	filtrk		.DS	mxfils	; 1st link/track
346
 2908  000025                	filsec		.DS	mxfils	;    /sector
347
 2909  00002A                	entsec		.DS	mxfils	; sector of directory entry
348
 2910  00002F                	entind		.DS	mxfils	; index of directory entry
349
 2911  000034                	fildrv		.DS	mxfils	; default flag, drive #
350
 2912  000039                	pattyp		.DS	mxfils	; pattern,replace,closed-flags,type
351
 2913
352
 2914          00003E        	dpsave		.EQU	$ - zpstart
353
 2915
354
 2916                        	;----------------------
355
 2917
356
 2918  00003E                	tlp		LP		; tmp long pointer
357
 2919  000041  00            	cmdsiz		.DB		; cmd string size
358
 2920  000042  00            	char		.DB		; tmp store char
359
 2921  000043  00            	image		.DB		; file stream image
360
 2922
361
 2923          000041        	qfmt		.EQU	cmdsiz	; quick format flag
362
 2924          000042        	idch1		.EQU	char	; ID format char 1
363
 2925          000043        	idch2		.EQU	image	; ID format char 2
364
 2926          000042        	opntm		.EQU	char	; <7>: open type in parameter
365
 2927                        					; <6>: open mode in parameter
366
 2928
367
 2929                        	; virtual iec -----------------------------------------
368
 2930  000044  00            	sa		.DB		; persistent second addr. virtual iec
369
 2931  000045  00            	viecbuf		.DB		; virtual iec buffered data
370
 2932  000046  0000          	viecsiz		.DW
371
 2933  000048  0000          	viecndx		.DW
372
 2934  00004A                	vieclp		LP
373
  Tue Jul 17 11:00:19 2018                                                                                               Page    7
374
 
375
 
376
 
377
 
378
 2935  00004D  00            	viecfg		.DB		; virtual iec flag
379
 2936                        					; <7>: active talk/listen
380
 2937                        					; <6>: talk (listen if 0)
381
 2938
382
 2939  00004E  00            	vcmdix		.DB		; index to command string
383
 2940  00004F  00            	vbufnum		.DB		; viec buffer #
384
 2941  000050  00            	vcmdsiz		.DB		; size of virtuasl iec buffer (channel 15)
385
 2942  000051  00            	veof		.DB		; eof flag
386
 2943
387
 2944                        	;-----------------------------------------------------
388
 2945  000052  00            	chnl		.DB		; channel param
389
 2946  000053  00            	cmdnum		.DB		; command #
390
 2947  000054  00            	bchn		.DB		; block-op channel
391
 2948  000055  00            	subcmd		.DB		; blk subcommand # or open type cmd
392
 2949
393
 2950  000056  00            	lsterr		.DB		; last error
394
 2951
395
 2952  000057  00            	lindx		.DB		; logical index (internal file descriptor)
396
 2953  000058  00            	linuse		.DB		; lindx use flags (1=free, 0=busy)
397
 2954  000059                	lintab		.DS	mxchnls	; lindx table ($FF = free)
398
 2955                        					; <7>: write type fd
399
 2956                        					; <6>: direct access type fd
400
 2957                        					; <5>: directory load type fd
401
 2958                        					; <3>: drive
402
 2959                        					; <2:0> = logical index
403
 2960
404
 2961  000068                	drvfg		.DS	2	; drive flag
405
 2962                        					; <7>: cbm formatted disk
406
 2963                        					; <6>: valid format in bit 1,0
407
 2964                        					; <5>: flag verify in bam iobyte
408
 2965                        					; <4>: flag write protect on
409
 2966                        					; <3>: flag new version
410
 2967                        					;
411
 2968                        					; <1:0>	00 DD ibm format
412
 2969                        					;	01 DD cbm format
413
 2970                        					;	10 HD ibm format
414
 2971                        					;	11 HD cbm format (not used)
415
 2972
416
 2973  00006A  0000          	ndbf		.DW		; # of disk blocks free drive 0
417
 2974  00006C  0000          			.DW		; # of disk blocks free drive 1
418
 2975
419
 2976  00006E                	sysbuf		.DS	2	; DMA buffer # of system track cache
420
 2977  000070                	trkbuf		.DS	2	; DMA buffer # of data track cache
421
 2978  000072                	wrtbuf		.DS	2	; DMA buffer # of write buffer cache
422
 2979  000074                	dirofs		.DS	2	; directory cache buffer high pointer (dma)
423
 2980  000076                	dirbnk		.DS	2	; directory cache buffer bank (dma)
424
 2981  000078                	trkofs		.DS	2	; track cache buffer high pointer (dma)
425
 2982  00007A                	trkbnk		.DS	2	; track cache buffer bank (dma)
426
 2983  00007C                	wrtofs		.DS	2	; write cache pointer
427
 2984  00007E                	wrtbnk		.DS	2
428
 2985  000080                	tcache		.DS	2	; current track in cache (0 invalidate cache)
429
 2986  000082                	wcache		.DS	2	; current track in write cache (0 inv. cache)
430
 2987
431
 2988  000084                	wbam		.DS	2	; dirty bam flag
432
 2989
433
 2990  000086  0000          	bsize		.DW		; size of buffer while read/write op
434
 2991  000088  0000          	btrf		.DW		; count of transf. bytes
435
  Tue Jul 17 11:00:19 2018                                                                                               Page    8
436
 
437
 
438
 
439
 
440
 2992          000086        	ntot		.EQU	bsize	; free block's counter while check file system
441
 2993          000088        	bcnt		.EQU	btrf	; block's count while chech file system
442
 2994
443
 2995  00008A                	bufp		LP		; long pointer to read data buffer (cache)
444
 2996  00008D                	bmpnt		LP		; bam long pointer
445
 2997  000090                	wbuf		LP		; long pointer to write data buffer
446
 2998
447
 2999  000093  00            	tmp0		.DB		; temp. byte
448
 3000  000094  0000          	wtmp		.DW		; tmp word
449
 3001
450
 3002  000096                	fdst		.DS	maxfd	; fd status
451
 3003                        					; <7>: ready
452
 3004                        					; <6>: eof flag
453
 3005                        					; <0>: drive
454
 3006  00009E                	dsec		.DS	maxfd	; sector of dir entry
455
 3007  0000A6                	dind		.DS	maxfd	; index of dir entry
456
 3008  0000AE                	ftrk		.DS	maxfd	; current file track (hi dir ptr for dir list)
457
 3009  0000B6                	fsec		.DS	maxfd	; current file sector (rdlst for dir list)
458
 3010  0000BE                	fdptr		.DS	maxfd	; file buffer pointer
459
 3011  0000C6                	fdblk		.DS	maxfd	; current file block # count
460
 3012  0000CE                			.DS	maxfd	; dir. ptr for dir list
461
 3013  0000D6                	fdlst		.DS	maxfd	; local buffer last byte ptr
462
 3014  0000DE                	fdix		.DS	maxfd	; local buffer pointer
463
 3015
464
 3016
465
 3017  0000E6  00            	wrop		.DB		; flag write-op
466
 3018  0000E7  00            	data		.DB		; buffered byte
467
 3019  0000E8  00            	rddrv		.DB		; drive # to read (buffered operation)
468
 3020  0000E9  00            	rdidx		.DB		; pointer to read buffer (buffered operation)
469
 3021  0000EA  00            	rdlst		.DB		; pointer to last byte (buffered operation)
470
 3022  0000EB  00            	rdeof		.DB		; eof condition (buffered operation)
471
 3023  0000EC  00            	wrdrv		.DB		; drive # to write (buffered operation)
472
 3024  0000ED  00            	wridx		.DB		; pointer to write buffer (buffered operation)
473
 3025  0000EE  00            	wsec		.DB		; last dirty sector in write cache
474
 3026  0000EF  00            	wfirst		.DB		; first dirty sector in write cache
475
 3027  0000F0  0000          	wcnt		.DW		; block's # of write file (buffered operation)
476
 3028
477
 3029  0000F2  00            	pdrv		.DB		; used by disk access routines: drive #
478
 3030  0000F3  00            	pside		.DB		; side #
479
 3031  0000F4  00            	psec		.DB		; start sector #
480
 3032  0000F5  00            	pcnt		.DB		; sector(s) count #
481
 3033  0000F6  00            	pbuf		.DB		; dma buffer #
482
 3034
483
 3035  0000F7  00            	dblfd		.DB		; double index lindx
484
 3036  0000F8  00            	trap		.DB		; flag error trap
485
 3037  0000F9  00            	cmdtrap		.DB		; no error if command string is empty
486
 3038
487
 3039  0000F9                		.RELATIVE
488
 3040                        		.ENDS
489
 3041
490
 3042                        	; CBM FS work area
491
 3043                        	CBMFSW:	.SECTION common, ref_only
492
 3044  000000                		.ABSOLUTE
493
 3045  00E100                		.ORG	CBMFSW_START
494
 3046
495
 3047  00E100                	cmdbuf		.DS	cmdlen	; command buffer
496
 3048  00E160  00            			.DB		; for terminator '0'
497
  Tue Jul 17 11:00:19 2018                                                                                               Page    9
498
 
499
 
500
 
501
 
502
 3049  00E161                	fntab		.DS	fntlen	; room for one dos filename (80) + one cbm...
503
 3050                        					; filename (17) or for 5 cbm file names (85)
504
 3051  00E1C2
505
 3052  00E1C2                	nambuf		.DS	nbsiz	; directory buffer
506
 3053  00E1DD                	nambuf2		.DS	19	; buffer for store quoted file name
507
 3054
508
 3055  00E1F0  0000 0000     	dskser		.LWORD		; serial in new version
509
 3056  00E1F4  0000 0000     			.LWORD
510
 3057
511
 3058  00E1F8  0000          	tos		.DW		; saved stack pointer
512
 3059  00E1FA  00            	etrk		.DB		; save track & sector for fmterr function
513
 3060  00E1FB  00            	esec		.DB
514
 3061  00E1FC                	dskid1		.DS	2	; disk id 1
515
 3062  00E1FE                	dskid2		.DS	2	; disk id 2
516
 3063
517
 3064  00E200                		.RELATIVE
518
 3065                        		.ENDS
519
 3066
520
 3067                        	CBMVIEC: .SECTION common, ref_only
521
 3068  000000                		.ABSOLUTE
522
 3069  00E200                		.ORG	CBMVIEC_START
523
 3070
524
 3071  00E200                	vixtab		.DS	16
525
 3072  00E210                	vsiztab		.DS	16
526
 3073  00E220                	vftab		.DS	16
527
 3074  00E230  00            	vopnsa		.DB		; SA for open command
528
 3075  00E231  00            			.DB
529
 3076  00E232                	vieccmd		.DS	cmdlen
530
 3077  00E292  00            			.DB
531
 3078
532
 3079
533
 3080  00E292                		.RELATIVE
534
 3081                        		.ENDS
535
 3082
536
 3083
537
 3084                        		.CODEF9
538
 3085                        		.LONGA off
539
 3086                        		.LONGI off
540
 3087
541
 3088                        		.EXTERN gctime16
542
 3089
543
 3090                        	;---------------------------------------------------------------------------
544
 3091                        	; System interface
545
 3092                        	;---------------------------------------------------------------------------
546
 3093
547
 3094                        	; virtual iec interface
548
 3095
549
 3096                        	; open procedure
550
 3097                        	;	call vlsnopn (A=sa)
551
 3098                        	;	call vsndcmd (A=byte)
552
 3099                        	;	call vunlsnopn
553
 3100                        	; vlsnopn - listen for open
554
 3101                        	; first call when send command or open file
555
 3102                        	; A=sa
556
 3103  F92A6F                	vlsnopn:
557
 3104                        		.GLOBAL vlsnopn
558
 3105
559
  Tue Jul 17 11:00:19 2018                                                                                               Page   10
560
 
561
 
562
 
563
 
564
 3106  F92A6F  0B            		phd
565
 3107  F92A70  F4 00 7E      		pea	#CBMFSP0
566
 3108  F92A73  2B            		pld			; set dp to emulator
567
 3109  F92A74  8B            		phb			; save current dbr
568
 3110  F92A75  A2 00         		ldx	#0
569
 3111  F92A77  DA            		phx
570
 3112  F92A78  AB            		plb			; set dbr=0
571
 3113  F92A79  29 0F         		and	#$0F
572
 3114  F92A7B  8D 30 E2      		sta	!vopnsa		; save SA
573
 3115  F92A7E  64 4E         		stz	vcmdix		; clear command string index
574
 3116  F92A80  AB            		plb
575
 3117  F92A81  2B            		pld
576
 3118  F92A82  6B            		rtl
577
 3119  F92A83
578
 3120                        	; vsndcmd: send cmd byte (A)
579
 3121  F92A83                	vsndcmd:
580
 3122                        		.GLOBAL vsndcmd
581
 3123
582
 3124  F92A83  DA            		phx
583
 3125  F92A84  0B            		phd
584
 3126  F92A85  F4 00 7E      		pea	#CBMFSP0
585
 3127  F92A88  2B            		pld			; set dp to emulator
586
 3128  F92A89  8B            		phb			; save current dbr
587
 3129  F92A8A  A2 00         		ldx	#0
588
 3130  F92A8C  DA            		phx
589
 3131  F92A8D  AB            		plb			; set dbr=0
590
 3132  F92A8E  A6 4E         		ldx	vcmdix
591
 3133  F92A90  E0 60         		cpx	#cmdlen
592
 3134  F92A92  B0 06         		bcs	?end		; string too long, no store
593
 3135  F92A94  9D 32 E2      		sta	!vieccmd,x	; store
594
 3136  F92A97  E8            		inx
595
 3137  F92A98  86 4E         		stx	vcmdix		; update string index
596
 3138  F92A9A  AB            	?end:	plb
597
 3139  F92A9B  2B            		pld
598
 3140  F92A9C  FA            		plx
599
 3141  F92A9D  6B            		rtl
600
 3142
601
 3143                        	; vunlsnopn - ulisten after open command
602
 3144                        	; CF=1 if error
603
 3145  F92A9E                	vunlsnopn:
604
 3146                        		.GLOBAL vunlsnopn
605
 3147
606
 3148  F92A9E  0B            		phd
607
 3149  F92A9F  F4 00 7E      		pea	#CBMFSP0
608
 3150  F92AA2  2B            		pld			; set dp to emulator
609
 3151  F92AA3  8B            		phb			; save current dbr
610
 3152  F92AA4  A2 00         		ldx	#0
611
 3153  F92AA6  DA            		phx
612
 3154  F92AA7  AB            		plb			; set dbr=0
613
 3155  F92AA8  AD 30 E2      		lda	!vopnsa		; open SA
614
 3156  F92AAB  20 B1 2A      		jsr	vopen		; exec open cmd
615
 3157  F92AAE  AB            		plb
616
 3158  F92AAF  2B            		pld
617
 3159  F92AB0  6B            		rtl
618
 3160  F92AB1
619
 3161                        	; vopen: local for open
620
 3162                        	; A=sa, X=0
621
  Tue Jul 17 11:00:19 2018                                                                                               Page   11
622
 
623
 
624
 
625
 
626
 3163  F92AB1                	vopen:
627
 3164  F92AB1  85 52         		sta	chnl		; channel for exec command
628
 3165  F92AB3  C9 0F         		cmp	#$0F
629
 3166  F92AB5  D0 01         		bne	?trp
630
 3167  F92AB7  CA            		dex			; accept null string in cmd channel
631
 3168  F92AB8  86 F9         	?trp:	stx	cmdtrap
632
 3169  F92ABA  A9 32         		lda	#<vieccmd	; set pointer of command string
633
 3170  F92ABC  85 3E         		sta	tlp
634
 3171  F92ABE  A9 E2         		lda	#>vieccmd
635
 3172  F92AC0  85 3F         		sta	tlp+1
636
 3173  F92AC2  64 40         		stz	tlp+2		; cmd. string in bank 0
637
 3174  F92AC4  A6 4E         		ldx	vcmdix
638
 3175  F92AC6  9E 32 E2      		stz	!vieccmd,x	; terminate command string
639
 3176  F92AC9  20 8D 2F      		jsr	parsex		; parse & execute command string
640
 3177  F92ACC  64 4E         		stz	vcmdix		; clear command buffer index
641
 3178  F92ACE  B0 1B         		bcs	?end		; error
642
 3179  F92AD0  A6 52         		ldx	chnl
643
 3180  F92AD2  E0 0F         		cpx	#$0F
644
 3181  F92AD4  D0 02         		bne	?dat		; data channel
645
 3182  F92AD6  18            		clc
646
 3183  F92AD7  60            		rts
647
 3184  F92AD8  B5 57         	?dat:	lda	lindx,x
648
 3185  F92ADA  29 07         		and	#$07
649
 3186  F92ADC  0A            		asl	a
650
 3187  F92ADD  AA            		tax			; double index #
651
 3188  F92ADE                		ACC16CLC		; CF=0, no error
652
 3189  F92ADE  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
653
 3190                        		.LONGA	on
654
 3191                        		.MNLIST
655
 3192  F92AE0  9E 00 E2      		stz	!vixtab,x
656
 3193  F92AE3  9E 10 E2      		stz	!vsiztab,x
657
 3194  F92AE6  9E 20 E2      		stz	!vftab,x	; pre-read flag & eof
658
 3195  F92AE9                		ACC08
659
 3196  F92AE9  E2 20         		sep	#PMFLAG
660
 3197                        		.LONGA	off
661
 3198                        		.MNLIST
662
 3199  F92AEB  60            	?end:	rts
663
 3200
664
 3201                        	; call after open (X = sa)
665
 3202  F92AEC                	vopnlst:
666
 3203                        		.GLOBAL vopnlst
667
 3204  F92AEC  DA            		phx
668
 3205  F92AED  0B            		phd
669
 3206  F92AEE  F4 00 7E      		pea	#CBMFSP0
670
 3207  F92AF1  2B            		pld			; set dp to emulator
671
 3208  F92AF2  8B            		phb			; save current dbr
672
 3209  F92AF3  A9 00         		lda	#0
673
 3210  F92AF5  48            		pha
674
 3211  F92AF6  AB            		plb			; set dbr=0
675
 3212  F92AF7  B5 57         	?dat:	lda	lindx,x
676
 3213  F92AF9  29 07         		and	#$07
677
 3214  F92AFB  0A            		asl	a
678
 3215  F92AFC  AA            		tax			; double index #
679
 3216  F92AFD                		ACC16CLC		; CF=0, no error
680
 3217  F92AFD  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
681
 3218                        		.LONGA	on
682
 3219                        		.MNLIST
683
  Tue Jul 17 11:00:19 2018                                                                                               Page   12
684
 
685
 
686
 
687
 
688
 3220  F92AFF  9E 00 E2      		stz	!vixtab,x
689
 3221  F92B02  9E 10 E2      		stz	!vsiztab,x
690
 3222  F92B05  9E 20 E2      		stz	!vftab,x	; pre-read flag & eof
691
 3223  F92B08                		ACC08
692
 3224  F92B08  E2 20         		sep	#PMFLAG
693
 3225                        		.LONGA	off
694
 3226                        		.MNLIST
695
 3227  F92B0A  AB            		plb
696
 3228  F92B0B  2B            		pld
697
 3229  F92B0C  FA            		plx
698
 3230  F92B0D  6B            		rtl
699
 3231
700
 3232                        	; A,X,Y=long pointer to command string
701
 3233                        	; B=sa
702
 3234  F92B0E                	viec8open:
703
 3235  F92B0E  0B            		phd			; save current dp
704
 3236  F92B0F  F4 00 7E      		pea	#CBMFSP0
705
 3237  F92B12  2B            		pld			; set dp to emulator
706
 3238  F92B13  85 3E         		sta	tlp		; set command string ptr
707
 3239  F92B15  86 3F         		stx	tlp+1
708
 3240  F92B17  84 40         		sty	tlp+2
709
 3241  F92B19  EB            		xba			; channel #
710
 3242  F92B1A  29 0F         		and	#$0F
711
 3243  F92B1C  85 52         		sta	chnl
712
 3244  F92B1E  8B            		phb			; save current dbr
713
 3245  F92B1F  A2 00         		ldx	#0
714
 3246  F92B21  DA            		phx
715
 3247  F92B22  AB            		plb			; set dbr=0
716
 3248  F92B23  C9 0F         		cmp	#$0F
717
 3249  F92B25  D0 01         		bne	?trp
718
 3250  F92B27  CA            		dex			; accept null string in cmd channel
719
 3251  F92B28  86 F9         	?trp:	stx	cmdtrap
720
 3252  F92B2A  20 8D 2F      		jsr	parsex		; parse & execute command string
721
 3253  F92B2D  B0 1E         		bcs	?end		; error
722
 3254  F92B2F  A6 52         		ldx	chnl
723
 3255  F92B31  E0 0F         		cpx	#$0F
724
 3256  F92B33  D0 05         		bne	?dat		; data channel
725
 3257  F92B35  64 4E         		stz	vcmdix		; clear command buffer index
726
 3258  F92B37  18            		clc
727
 3259  F92B38  F0 13         		beq	?end
728
 3260  F92B3A  B5 57         	?dat:	lda	lindx,x
729
 3261  F92B3C  29 07         		and	#$07
730
 3262  F92B3E  0A            		asl	a
731
 3263  F92B3F  AA            		tax			; double index #
732
 3264  F92B40                		ACC16CLC
733
 3265  F92B40  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
734
 3266                        		.LONGA	on
735
 3267                        		.MNLIST
736
 3268  F92B42  9E 00 E2      		stz	!vixtab,x
737
 3269  F92B45  9E 10 E2      		stz	!vsiztab,x
738
 3270  F92B48  9E 20 E2      		stz	!vftab,x	; pre-read flag & eof
739
 3271  F92B4B                		ACC08
740
 3272  F92B4B  E2 20         		sep	#PMFLAG
741
 3273                        		.LONGA	off
742
 3274                        		.MNLIST
743
 3275  F92B4D  AB            	?end:	plb			; restore dbr
744
 3276  F92B4E  2B            		pld			; restore dp
745
  Tue Jul 17 11:00:19 2018                                                                                               Page   13
746
 
747
 
748
 
749
 
750
 3277  F92B4F  6B            		rtl			; return CF=1 if error
751
 3278
752
 3279                        	; listen command
753
 3280                        	; A=sa
754
 3281  F92B50                	viec8lsn:
755
 3282                        		.GLOBAL viec8lsn
756
 3283
757
 3284  F92B50  DA            		phx			; save X, Y
758
 3285  F92B51  5A            		phy
759
 3286  F92B52  0B            		phd			; save current dp
760
 3287  F92B53  F4 00 7E      		pea	#CBMFSP0
761
 3288  F92B56  2B            		pld			; set dp to cbmfs emulator
762
 3289  F92B57  8B            		phb			; save dbr
763
 3290  F92B58  A2 00         		ldx	#0
764
 3291  F92B5A  DA            		phx
765
 3292  F92B5B  AB            		plb			; set dbr = 0
766
 3293  F92B5C  85 52         		sta	chnl		; save sa
767
 3294  F92B5E  29 0F         		and	#$0F
768
 3295  F92B60  AA            		tax			; X=sa
769
 3296  F92B61
770
 3297  F92B61  9C 30 E2      		stz	!vopnsa
771
 3298
772
 3299  F92B64  24 4D         		bit	viecfg		; already active?
773
 3300  F92B66  10 12         		bpl	?tst		; no
774
 3301  F92B68  E4 44         		cpx	sa
775
 3302  F92B6A  D0 07         		bne	?bad
776
 3303  F92B6C
777
 3304  F92B6C  A0 FF         		ldy	#$FF
778
 3305  F92B6E  8C 30 E2      		sty	.ABS.vopnsa
779
 3306  F92B71  80 15         		bra	?dat
780
 3307
781
 3308  F92B73  A9 54         	?bad:	lda	#badlsn		; invalid listen command
782
 3309  F92B75  20 35 2E      		jsr	viecerr		; set error
783
 3310  F92B78  80 2F         		bra	?end		; exit with CF=1
784
 3311  F92B7A  20 10 2E      	?tst:	jsr	vtstwr		; test if write channel
785
 3312  F92B7D  B0 2A         		bcs	?end		; error
786
 3313  F92B7F  E0 0F         		cpx	#$0F
787
 3314  F92B81  D0 05         		bne	?dat		; data channel
788
 3315  F92B83  64 4E         		stz	vcmdix		; clear index
789
 3316  F92B85  18            		clc
790
 3317  F92B86  80 21         		bra	?end		; exit
791
 3318  F92B88  A6 4F         	?dat:	ldx	vbufnum
792
 3319  F92B8A
793
 3320  F92B8A  18            		clc
794
 3321  F92B8B  2C 30 E2      		bit	!vopnsa
795
 3322  F92B8E  30 19         		bmi	?end
796
 3323
797
 3324  F92B90                		ACC16CLC
798
 3325  F92B90  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
799
 3326                        		.LONGA	on
800
 3327                        		.MNLIST
801
 3328  F92B92  BF CA 2E F9   		lda	>viecdma,x
802
 3329  F92B96  85 4A         		sta	vieclp
803
 3330  F92B98  A0 03         		ldy	#DMABNK+1	; bank $80..$BF
804
 3331  F92B9A  84 4C         		sty	vieclp+2
805
 3332  F92B9C  BF 00 E2 00   		lda	vixtab,x	; get current index
806
 3333  F92BA0  85 48         		sta	viecndx
807
  Tue Jul 17 11:00:19 2018                                                                                               Page   14
808
 
809
 
810
 
811
 
812
 3334  F92BA2  A9 00 10      		lda	#VIECMAX	; max. size of buffer
813
 3335  F92BA5  85 46         		sta	viecsiz
814
 3336  F92BA7                		ACC08
815
 3337  F92BA7  E2 20         		sep	#PMFLAG
816
 3338                        		.LONGA	off
817
 3339                        		.MNLIST
818
 3340  F92BA9  A5 52         	?end:	lda	chnl
819
 3341  F92BAB  AB            		plb
820
 3342  F92BAC  2B            		pld
821
 3343  F92BAD  7A            		ply
822
 3344  F92BAE  FA            		plx
823
 3345  F92BAF  6B            		rtl
824
 3346
825
 3347                        	; talk command
826
 3348                        	; A=sa
827
 3349  F92BB0                	viec8tlk:
828
 3350                        		.GLOBAL viec8tlk
829
 3351
830
 3352  F92BB0  DA            		phx			; save X, Y
831
 3353  F92BB1  5A            		phy
832
 3354  F92BB2  0B            		phd			; save current dp
833
 3355  F92BB3  F4 00 7E      		pea	#CBMFSP0
834
 3356  F92BB6  2B            		pld			; set dp to cbmfs emulator
835
 3357  F92BB7  8B            		phb			; save dbr
836
 3358  F92BB8  A2 00         		ldx	#0
837
 3359  F92BBA  DA            		phx
838
 3360  F92BBB  AB            		plb			; set dbr = 0
839
 3361  F92BBC  85 52         		sta	chnl		; save sa
840
 3362  F92BBE  29 0F         		and	#$0F
841
 3363  F92BC0  AA            		tax			; X=sa
842
 3364  F92BC1
843
 3365  F92BC1  9C 30 E2      		stz	!vopnsa
844
 3366
845
 3367  F92BC4  24 4D         		bit	viecfg		; already active?
846
 3368  F92BC6  10 12         		bpl	?tst		; no
847
 3369  F92BC8  E4 44         		cpx	sa
848
 3370  F92BCA  D0 07         		bne	?bad
849
 3371  F92BCC  A0 FF         		ldy	#$FF
850
 3372  F92BCE  8C 30 E2      		sty	.ABS.vopnsa
851
 3373  F92BD1  80 2B         		bra	?dat
852
 3374
853
 3375  F92BD3  A9 53         	?bad:	lda	#badtlk		; invalid talk command
854
 3376  F92BD5  20 35 2E      		jsr	viecerr		; set error
855
 3377  F92BD8  80 6D         		bra	?end		; exit with CF=1
856
 3378  F92BDA  20 F5 2D      	?tst:	jsr	vtstrd		; test if read channel
857
 3379  F92BDD  B0 68         		bcs	?end		; error
858
 3380  F92BDF  E0 0F         		cpx	#$0F
859
 3381  F92BE1  D0 1B         		bne	?dat		; data channel
860
 3382  F92BE3  20 44 57      		jsr	fnderr		; find last error
861
 3383  F92BE6  A0 FF         		ldy	#$FF		; store error string
862
 3384  F92BE8  C8            	?lp:	iny
863
 3385  F92BE9  B7 3E         		lda	[tlp],y
864
 3386  F92BEB  99 32 E2      		sta	vieccmd,y
865
 3387  F92BEE  D0 F8         		bne	?lp
866
 3388  F92BF0  A9 0D         		lda	#$0D
867
 3389  F92BF2  99 32 E2      		sta	vieccmd,y
868
 3390  F92BF5  C8            		iny
869
  Tue Jul 17 11:00:19 2018                                                                                               Page   15
870
 
871
 
872
 
873
 
874
 3391  F92BF6  84 50         		sty	vcmdsiz		; buffer size
875
 3392  F92BF8  64 4E         		stz	vcmdix		; clear index
876
 3393  F92BFA  C2 41         		rep	#PCFLAG+PVFLAG	; CF=VF=0: no error, no eof
877
 3394  F92BFC  80 49         		bra	?end		; exit
878
 3395  F92BFE  A6 4F         	?dat:	ldx	vbufnum
879
 3396  F92C00  BD 21 E2      		lda	!vftab+1,x
880
 3397  F92C03  85 51         		sta	veof		; eof flag
881
 3398  F92C05
882
 3399  F92C05  2C 30 E2      		bit	!vopnsa
883
 3400  F92C08  30 19         		bmi	?dat2
884
 3401
885
 3402  F92C0A                		ACC16CLC		; CF=0
886
 3403  F92C0A  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
887
 3404                        		.LONGA	on
888
 3405                        		.MNLIST
889
 3406  F92C0C  BF CA 2E F9   		lda	>viecdma,x
890
 3407  F92C10  85 4A         		sta	vieclp		; set buffer pointer
891
 3408  F92C12  A0 03         		ldy	#DMABNK+1
892
 3409  F92C14  84 4C         		sty	vieclp+2
893
 3410  F92C16  BF 00 E2 00   		lda	vixtab,x
894
 3411  F92C1A  85 48         		sta	viecndx		; current index
895
 3412  F92C1C  BD 10 E2      		lda	!vsiztab,x
896
 3413  F92C1F  85 46         		sta	viecsiz		; current buffer size
897
 3414  F92C21                		ACC08
898
 3415  F92C21  E2 20         		sep	#PMFLAG
899
 3416                        		.LONGA	off
900
 3417                        		.MNLIST
901
 3418  F92C23  24 51         	?dat2:	bit	veof		; eof?
902
 3419  F92C25  30 1E         		bmi	?eof		; yes: exit with CF=0, VF=1
903
 3420  F92C27  3C 20 E2      		bit	!vftab,x	; pre-read flag
904
 3421  F92C2A  30 0A         		bmi	?ok		; already pre-readed
905
 3422  F92C2C  20 4E 2C      		jsr	vbufrd		; pre-read into buffer
906
 3423  F92C2F  A9 80         		lda	#$80
907
 3424  F92C31  9D 20 E2      		sta	!vftab,x	; set pre-read flag
908
 3425  F92C34  B0 11         		bcs	?end		; read error
909
 3426  F92C36                	?ok:	ACC16CV			; CF=0, VF=0
910
 3427  F92C36  C2 61         		rep	#(PMFLAG.OR.PCFLAG.OR.PVFLAG)
911
 3428                        		.LONGA	on
912
 3429                        		.MNLIST
913
 3430  F92C38  A5 46         		lda	viecsiz		; buffer is empty?
914
 3431  F92C3A                		ACC08
915
 3432  F92C3A  E2 20         		sep	#PMFLAG
916
 3433                        		.LONGA	off
917
 3434                        		.MNLIST
918
 3435  F92C3C  D0 09         		bne	?end		; no
919
 3436  F92C3E  A9 C0         		lda	#$C0
920
 3437  F92C40  85 51         		sta	veof		; set eof flag
921
 3438  F92C42  9D 21 E2      		sta	!vftab+1,x
922
 3439  F92C45  E2 40         	?eof:	sep	#PVFLAG		; VF=1: eof
923
 3440  F92C47  A5 52         	?end:	lda	chnl
924
 3441  F92C49  AB            		plb
925
 3442  F92C4A  2B            		pld
926
 3443  F92C4B  7A            		ply
927
 3444  F92C4C  FA            		plx
928
 3445  F92C4D  6B            		rtl
929
 3446
930
 3447                        	; CF=1 if read error
931
  Tue Jul 17 11:00:19 2018                                                                                               Page   16
932
 
933
 
934
 
935
 
936
 3448  F92C4E                	vbufrd:
937
 3449  F92C4E                		ACC16
938
 3450  F92C4E  C2 20         		rep	#PMFLAG
939
 3451                        		.LONGA	on
940
 3452                        		.MNLIST
941
 3453  F92C50  A5 4A         		lda	vieclp		; set read buffer
942
 3454  F92C52  A4 4C         		ldy	vieclp+2
943
 3455  F92C54  85 90         		sta	wbuf
944
 3456  F92C56  84 92         		sty	wbuf+2
945
 3457  F92C58  A9 00 10      		lda	#VIECMAX	; buffer max. size
946
 3458  F92C5B  85 86         		sta	bsize
947
 3459  F92C5D  64 88         		stz	btrf		; clear transferred count
948
 3460  F92C5F  64 46         		stz	viecsiz		; empty buffer
949
 3461  F92C61  64 48         		stz	viecndx
950
 3462  F92C63                		ACC08
951
 3463  F92C63  E2 20         		sep	#PMFLAG
952
 3464                        		.LONGA	off
953
 3465                        		.MNLIST
954
 3466  F92C65  A0 00         		ldy	#0		; pre-read into buffer
955
 3467  F92C67  A6 44         		ldx	sa
956
 3468  F92C69  86 52         		stx	chnl
957
 3469  F92C6B  20 4F 43      		jsr	fd_rw
958
 3470  F92C6E  A6 4F         		ldx	vbufnum
959
 3471  F92C70                		ACC16
960
 3472  F92C70  C2 20         		rep	#PMFLAG
961
 3473                        		.LONGA	on
962
 3474                        		.MNLIST
963
 3475  F92C72  A9 00 00      		lda	#0
964
 3476  F92C75  B0 02         		bcs	?st		; error
965
 3477  F92C77  A5 88         		lda	btrf		; count of transf. bytes
966
 3478  F92C79  85 46         	?st:	sta	viecsiz
967
 3479  F92C7B  9D 10 E2      		sta	!vsiztab,x
968
 3480  F92C7E                		ACC08
969
 3481  F92C7E  E2 20         		sep	#PMFLAG
970
 3482                        		.LONGA	off
971
 3483                        		.MNLIST
972
 3484  F92C80  60            		rts
973
 3485
974
 3486                        	; A=data
975
 3487  F92C81                	viec8put:
976
 3488                        		.GLOBAL viec8put
977
 3489
978
 3490  F92C81  DA            		phx			; save X, Y
979
 3491  F92C82  5A            		phy
980
 3492  F92C83  0B            		phd			; save current dp
981
 3493  F92C84  F4 00 7E      		pea	#CBMFSP0
982
 3494  F92C87  2B            		pld			; set dp to cbmfs emulator
983
 3495  F92C88  8B            		phb			; save dbr
984
 3496  F92C89  A2 00         		ldx	#0
985
 3497  F92C8B  DA            		phx
986
 3498  F92C8C  AB            		plb			; set dbr = 0
987
 3499  F92C8D  85 45         		sta	viecbuf		; save data to put
988
 3500  F92C8F  24 4D         		bit	viecfg		; current sa is active?
989
 3501  F92C91  10 02         		bpl	?ern		; no
990
 3502  F92C93  50 0F         		bvc	?ok		; ready to listen
991
 3503  F92C95  A9 46         	?ern:	lda	#nochnl		; no channel available
992
 3504  F92C97  80 04         		bra	?er
993
  Tue Jul 17 11:00:19 2018                                                                                               Page   17
994
 
995
 
996
 
997
 
998
 3505  F92C99  A6 44         	?erl:	ldx	sa		; channel # error
999
 3506  F92C9B  A9 20         		lda	#longln		; command too long
1000
 3507  F92C9D  20 35 2E      	?er:	jsr	viecerr
1001
 3508  F92CA0  A5 45         		lda	viecbuf
1002
 3509  F92CA2  80 4E         		bra	?end		; return CF=1
1003
 3510  F92CA4  A6 44         	?ok:	ldx	sa		; trust on sa channel
1004
 3511  F92CA6  E0 0F         		cpx	#$0F
1005
 3512  F92CA8  D0 0E         		bne	?dat		; put to data channel
1006
 3513  F92CAA  A6 4E         		ldx	vcmdix		; current buffer index
1007
 3514  F92CAC  E0 60         		cpx	#cmdlen
1008
 3515  F92CAE  B0 E9         		bcs	?erl		; command line too long
1009
 3516  F92CB0  9D 32 E2      		sta	!vieccmd,x	; store
1010
 3517  F92CB3  E8            		inx
1011
 3518  F92CB4  86 4E         		stx	vcmdix		; update index
1012
 3519                        		;cmp	#$0D		; terminate command string?
1013
 3520                        		;bne	?clc		; no, wait terminator
1014
 3521                        		;stz	!vieccmd-1,x	; terminate string with null
1015
 3522                        		;lda	#$0F
1016
 3523                        		;xba			; B=channel 15
1017
 3524                        		;lda	#<vieccmd	; set pointer to command string
1018
 3525                        		;ldx	#>vieccmd
1019
 3526                        		;ldy	#0		; command string in bank 0
1020
 3527                        		;stz	vcmdix		; clear buffer index
1021
 3528                        		;jsr	viec8cmd	; exexcute command in channel 15
1022
 3529                        		;lda	#$0D
1023
 3530  F92CB6  80 3A         		bra	?end		; CF set if error
1024
 3531  F92CB8  A2 00         	?dat:	ldx	#0
1025
 3532  F92CBA                		INDEX16
1026
 3533  F92CBA  C2 10         		rep	#PXFLAG
1027
 3534                        		.LONGI	on
1028
 3535                        		.MNLIST
1029
 3536  F92CBC  A4 48         		ldy	viecndx		; index into buffer
1030
 3537  F92CBE  C4 46         		cpy	viecsiz
1031
 3538  F92CC0  B0 07         		bcs	?wr		; flush buffer
1032
 3539  F92CC2  97 4A         		sta	[vieclp],y	; store
1033
 3540  F92CC4  C8            		iny
1034
 3541  F92CC5  84 48         		sty	viecndx		; update index
1035
 3542  F92CC7  80 27         		bra	?xy8		; exit with CF=0
1036
 3543  F92CC9  A4 4A         	?wr:	ldy	vieclp		; flush buffer on disk
1037
 3544  F92CCB  84 90         		sty	wbuf		; set buffer pointer
1038
 3545  F92CCD  A5 4C         		lda	vieclp+2
1039
 3546  F92CCF  85 92         		sta	wbuf+2
1040
 3547  F92CD1  A4 46         		ldy	viecsiz
1041
 3548  F92CD3  84 86         		sty	bsize		; buffer size
1042
 3549  F92CD5  86 88         		stx	btrf		; clear transferred count
1043
 3550  F92CD7  86 48         		stx	viecndx		; clear index
1044
 3551                        		;stx	viecsiz		; clear size
1045
 3552  F92CD9                		CPU08
1046
 3553  F92CD9  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1047
 3554                        		.LONGA	off
1048
 3555                        		.LONGI	off
1049
 3556                        		.MNLIST
1050
 3557  F92CDB  A6 44         		ldx	sa		; set channel #
1051
 3558  F92CDD  86 52         		stx	chnl
1052
 3559  F92CDF  A0 01         		ldy	#1		; write op
1053
 3560  F92CE1  20 4F 43      		jsr	fd_rw
1054
 3561  F92CE4  A5 45         		lda	viecbuf		; data to store
1055
  Tue Jul 17 11:00:19 2018                                                                                               Page   18
1056
 
1057
 
1058
 
1059
 
1060
 3562  F92CE6  B0 0A         		bcs	?end		; error
1061
 3563  F92CE8  A0 01         		ldy	#1
1062
 3564  F92CEA                		INDEX16
1063
 3565  F92CEA  C2 10         		rep	#PXFLAG
1064
 3566                        		.LONGI	on
1065
 3567                        		.MNLIST
1066
 3568  F92CEC  87 4A         		sta	[vieclp]	; store
1067
 3569  F92CEE  84 48         		sty	viecndx		; next index = 1
1068
 3570  F92CF0                	?xy8:	INDEX08
1069
 3571  F92CF0  E2 10         		sep	#PXFLAG
1070
 3572                        		.LONGI	off
1071
 3573                        		.MNLIST
1072
 3574  F92CF2  AB            	?end:	plb
1073
 3575  F92CF3  2B            		pld
1074
 3576  F92CF4  7A            		ply
1075
 3577  F92CF5  FA            		plx
1076
 3578  F92CF6  6B            		rtl
1077
 3579
1078
 3580  F92CF7                	viec8get:
1079
 3581                        		.GLOBAL	viec8get
1080
 3582
1081
 3583  F92CF7  DA            		phx			; save X, Y
1082
 3584  F92CF8  5A            		phy
1083
 3585  F92CF9  0B            		phd			; save current dp
1084
 3586  F92CFA  F4 00 7E      		pea	#CBMFSP0
1085
 3587  F92CFD  2B            		pld			; set dp to cbmfs emulator
1086
 3588  F92CFE  8B            		phb			; save dbr
1087
 3589  F92CFF  A2 00         		ldx	#0
1088
 3590  F92D01  DA            		phx
1089
 3591  F92D02  AB            		plb			; set dbr = 0
1090
 3592  F92D03  24 4D         		bit	viecfg		; current sa is active?
1091
 3593  F92D05  10 02         		bpl	?ern		; no
1092
 3594  F92D07  70 09         		bvs	?ok		; ready to talk
1093
 3595  F92D09  A9 46         	?ern:	lda	#nochnl		; no channel available
1094
 3596  F92D0B  20 35 2E      		jsr	viecerr
1095
 3597  F92D0E  A9 0D         		lda	#$0D
1096
 3598  F92D10  80 5C         		bra	?end		; return CF=1
1097
 3599  F92D12  A6 44         	?ok:	ldx	sa		; talk channel
1098
 3600  F92D14  E0 0F         		cpx	#$0F
1099
 3601  F92D16  D0 1E         		bne	?dat		; data channel
1100
 3602  F92D18  A9 0D         		lda	#$0D
1101
 3603  F92D1A  A4 50         		ldy	vcmdsiz		; if buffer is empty...
1102
 3604  F92D1C  F0 4A         		beq	?eof		; ... return CR & VF=1 (eof)
1103
 3605  F92D1E  A6 4E         		ldx	vcmdix		; index into buffer
1104
 3606  F92D20  E4 50         		cpx	vcmdsiz		; if buffer is terminated...
1105
 3607  F92D22  90 03         		bcc	?get
1106
 3608  F92D24  18            		clc			; ... return CR & VF=1 (eof)
1107
 3609  F92D25  80 41         		bra	?eof
1108
 3610  F92D27  BD 32 E2      	?get:	lda	!vieccmd,x	; get data
1109
 3611  F92D2A  E8            		inx
1110
 3612  F92D2B  86 4E         		stx	vcmdix
1111
 3613  F92D2D  E4 50         		cpx	vcmdsiz		; if not last data...
1112
 3614  F92D2F  B8            		clv
1113
 3615  F92D30  90 3C         		bcc	?end		; ...exit with VF=0
1114
 3616  F92D32  64 56         		stz	lsterr		; clear last error
1115
 3617  F92D34  80 32         		bra	?eof		; return VF=1 (eof)
1116
 3618  F92D36  A2 00         	?dat:	ldx	#0
1117
  Tue Jul 17 11:00:19 2018                                                                                               Page   19
1118
 
1119
 
1120
 
1121
 
1122
 3619  F92D38                		INDEX16CLC		; CF=0
1123
 3620  F92D38  C2 11         		rep	#(PXFLAG.OR.PCFLAG)
1124
 3621                        		.LONGI	on
1125
 3622                        		.MNLIST
1126
 3623  F92D3A  A9 0D         		lda	#$0D		; return CR if eof
1127
 3624  F92D3C  24 51         		bit	veof		; eof flag ?
1128
 3625  F92D3E  30 2E         		bmi	?end		; exit with CF=0, VF=1
1129
 3626  F92D40  A4 46         		ldy	viecsiz		; if buffer is empty...
1130
 3627  F92D42  F0 24         		beq	?eof		; ... return CR & VF=1 (eof)
1131
 3628  F92D44  A4 48         		ldy	viecndx		; index into buffer
1132
 3629  F92D46  B7 4A         		lda	[vieclp],y	; get data
1133
 3630  F92D48  C8            		iny
1134
 3631  F92D49  84 48         		sty	viecndx		; update index
1135
 3632  F92D4B  C4 46         		cpy	viecsiz
1136
 3633  F92D4D  B8            		clv
1137
 3634  F92D4E  90 1E         		bcc	?end		; no eof
1138
 3635  F92D50  C0 00 10      		cpy	#VIECMAX	; partial buffer?
1139
 3636  F92D53  85 45         		sta	viecbuf		; save data
1140
 3637  F92D55  90 1E         		bcc	?eof2		; yes, eof
1141
 3638  F92D57                		INDEX08
1142
 3639  F92D57  E2 10         		sep	#PXFLAG
1143
 3640                        		.LONGI	off
1144
 3641                        		.MNLIST
1145
 3642  F92D59  20 4E 2C      		jsr	vbufrd		; pre-read buffer
1146
 3643  F92D5C  A5 45         		lda	viecbuf		; data
1147
 3644  F92D5E  B0 0E         		bcs	?end		; error
1148
 3645  F92D60                		INDEX16CV
1149
 3646  F92D60  C2 51         		rep	#(PXFLAG.OR.PCFLAG.OR.PVFLAG)
1150
 3647                        		.LONGI	on
1151
 3648                        		.MNLIST
1152
 3649  F92D62  A4 88         		ldy	btrf		; count of transf. bytes
1153
 3650  F92D64  84 46         		sty	viecsiz
1154
 3651                        		;bne	?end		; is not last char
1155
 3652  F92D66  80 06         		bra	?end
1156
 3653  F92D68                	?eof:	CPU08VF			; eof so set VF = 1
1157
 3654  F92D68  E2 70         		sep	#(PMFLAG.OR.PXFLAG.OR.PVFLAG)
1158
 3655                        		.LONGA	off
1159
 3656                        		.LONGI	off
1160
 3657                        		.MNLIST
1161
 3658  F92D6A  A2 C0         		ldx	#$C0
1162
 3659  F92D6C  86 51         		stx	veof		; set eof flag
1163
 3660  F92D6E                	?end:	CPU08
1164
 3661  F92D6E  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1165
 3662                        		.LONGA	off
1166
 3663                        		.LONGI	off
1167
 3664                        		.MNLIST
1168
 3665  F92D70  AB            		plb
1169
 3666  F92D71  2B            		pld
1170
 3667  F92D72  7A            		ply
1171
 3668  F92D73  FA            		plx
1172
 3669  F92D74  6B            		rtl
1173
 3670  F92D75                	?eof2:	CPU08
1174
 3671  F92D75  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1175
 3672                        		.LONGA	off
1176
 3673                        		.LONGI	off
1177
 3674                        		.MNLIST
1178
 3675  F92D77  B8            		clv
1179
  Tue Jul 17 11:00:19 2018                                                                                               Page   20
1180
 
1181
 
1182
 
1183
 
1184
 3676  F92D78  A9 C0         		lda	#$C0
1185
 3677  F92D7A  85 51         		sta	veof
1186
 3678  F92D7C  A5 45         		lda	viecbuf
1187
 3679  F92D7E  80 EE         		bra	?end
1188
 3680
1189
 3681                        	; unlisten
1190
 3682  F92D80                	v8unlsn:
1191
 3683                        		.GLOBAL v8unlsn
1192
 3684
1193
 3685  F92D80  DA            		phx
1194
 3686  F92D81  0B            		phd			; save current dp
1195
 3687  F92D82  F4 00 7E      		pea	#CBMFSP0
1196
 3688  F92D85  2B            		pld			; set dp to cbmfs emulator
1197
 3689  F92D86  8B            		phb			; save dbr
1198
 3690  F92D87  A9 00         		lda	#0
1199
 3691  F92D89  48            		pha
1200
 3692  F92D8A  AB            		plb			; set dbr = 0
1201
 3693  F92D8B  24 4D         		bit	viecfg		; current sa is active?
1202
 3694  F92D8D  10 10         		bpl	?end		; no
1203
 3695  F92D8F  70 0E         		bvs	?end		; channel is talking
1204
 3696  F92D91  A5 44         		lda	sa
1205
 3697  F92D93  C9 0F         		cmp	#$0F
1206
 3698  F92D95  D0 05         		bne	?clr
1207
 3699  F92D97  20 B1 2A      		jsr	vopen
1208
 3700  F92D9A  80 04         		bra	?end2
1209
 3701  F92D9C  20 C3 2D      	?clr:	jsr	v8clr
1210
 3702  F92D9F  18            	?end:	clc
1211
 3703  F92DA0  AB            	?end2:	plb
1212
 3704  F92DA1  2B            		pld
1213
 3705  F92DA2  FA            		plx
1214
 3706  F92DA3  6B            		rtl
1215
 3707  F92DA4
1216
 3708                        	; untalk
1217
 3709  F92DA4                	v8untlk:
1218
 3710                        		.GLOBAL v8untlk
1219
 3711
1220
 3712  F92DA4  DA            		phx
1221
 3713  F92DA5  0B            		phd			; save current dp
1222
 3714  F92DA6  F4 00 7E      		pea	#CBMFSP0
1223
 3715  F92DA9  2B            		pld			; set dp to cbmfs emulator
1224
 3716  F92DAA  8B            		phb			; save dbr
1225
 3717  F92DAB  A9 00         		lda	#0
1226
 3718  F92DAD  48            		pha
1227
 3719  F92DAE  AB            		plb			; set dbr = 0
1228
 3720  F92DAF  24 4D         		bit	viecfg		; current sa is active?
1229
 3721  F92DB1  10 0B         		bpl	?end		; no
1230
 3722  F92DB3  50 09         		bvc	?end		; channel is listening
1231
 3723  F92DB5  A6 44         		ldx	sa
1232
 3724  F92DB7  E0 0F         		cpx	#$0F
1233
 3725  F92DB9  F0 03         		beq	?end
1234
 3726  F92DBB  20 C3 2D      		jsr	v8clr
1235
 3727  F92DBE  AB            	?end:	plb
1236
 3728  F92DBF  2B            		pld
1237
 3729  F92DC0  FA            		plx
1238
 3730  F92DC1  18            		clc
1239
 3731  F92DC2  6B            		rtl
1240
 3732  F92DC3
1241
  Tue Jul 17 11:00:19 2018                                                                                               Page   21
1242
 
1243
 
1244
 
1245
 
1246
 3733                        	; clear channel
1247
 3734  F92DC3                	v8clr:
1248
 3735  F92DC3  A6 4F         		ldx	vbufnum
1249
 3736  F92DC5  A5 51         		lda	veof
1250
 3737  F92DC7  9F 21 E2 00   		sta	vftab+1,x
1251
 3738  F92DCB                		ACC16
1252
 3739  F92DCB  C2 20         		rep	#PMFLAG
1253
 3740                        		.LONGA	on
1254
 3741                        		.MNLIST
1255
 3742  F92DCD  A5 48         		lda	viecndx
1256
 3743  F92DCF  9F 00 E2 00   		sta	vixtab,x
1257
 3744  F92DD3  A5 46         		lda	viecsiz
1258
 3745  F92DD5  9F 10 E2 00   		sta	vsiztab,x
1259
 3746  F92DD9                		ACC08
1260
 3747  F92DD9  E2 20         		sep	#PMFLAG
1261
 3748                        		.LONGA	off
1262
 3749                        		.MNLIST
1263
 3750  F92DDB  64 4D         		stz	viecfg
1264
 3751  F92DDD  60            		rts
1265
 3752
1266
 3753                        	; A,X,Y=long pointer to command string
1267
 3754                        	; B=sa
1268
 3755  F92DDE                	viec8cmd:
1269
 3756  F92DDE  85 3E         		sta	tlp		; set pointer to command string
1270
 3757  F92DE0  86 3F         		stx	tlp+1
1271
 3758  F92DE2  84 40         		sty	tlp+2
1272
 3759  F92DE4  A2 00         		ldx	#0
1273
 3760  F92DE6  EB            		xba
1274
 3761  F92DE7  29 0F         		and	#$0F
1275
 3762  F92DE9  85 52         		sta	chnl
1276
 3763  F92DEB  C9 0F         		cmp	#$0F
1277
 3764  F92DED  D0 01         		bne	?trp
1278
 3765  F92DEF  CA            		dex			; accept null string in cmd channel
1279
 3766  F92DF0  86 F9         	?trp:	stx	cmdtrap
1280
 3767  F92DF2  4C 8D 2F      		jmp	parsex		; parse & execute command string
1281
 3768
1282
 3769                        	; test channel for read
1283
 3770                        	; x = channel #
1284
 3771  F92DF5                	vtstrd:
1285
 3772  F92DF5  E0 0F         		cpx	#$0F
1286
 3773  F92DF7  F0 0F         		beq	?ok		; is command channel
1287
 3774  F92DF9  B5 59         		lda	lintab,x	; test if given channel is open
1288
 3775  F92DFB  A8            		tay
1289
 3776  F92DFC  C9 FF         		cmp	#$FF
1290
 3777  F92DFE  F0 2F         		beq	verrnochn	; channel not open
1291
 3778  F92E00  98            		tya
1292
 3779  F92E01  30 30         		bmi	verrbadchn	; channel not open for read
1293
 3780  F92E03  29 07         		and	#$07
1294
 3781  F92E05  0A            		asl	a
1295
 3782  F92E06  85 4F         		sta	vbufnum		; buffer number #
1296
 3783  F92E08  86 44         	?ok:	stx	sa		; save channel #
1297
 3784  F92E0A  A9 C0         		lda	#$C0		; set active talk sa
1298
 3785  F92E0C  85 4D         		sta	viecfg
1299
 3786  F92E0E  18            		clc			; no error
1300
 3787  F92E0F  60            		rts
1301
 3788
1302
 3789                        	; test channel for write
1303
  Tue Jul 17 11:00:19 2018                                                                                               Page   22
1304
 
1305
 
1306
 
1307
 
1308
 3790                        	; x = channel #
1309
 3791  F92E10                	vtstwr:
1310
 3792  F92E10  E0 0F         		cpx	#$0F
1311
 3793  F92E12  F0 13         		beq	?set		; is command channel
1312
 3794  F92E14  B5 59         		lda	lintab,x	; test if given channel is open
1313
 3795  F92E16  A8            		tay
1314
 3796  F92E17  C9 FF         		cmp	#$FF
1315
 3797  F92E19  F0 14         		beq	verrnochn	; channel not open
1316
 3798  F92E1B  98            		tya
1317
 3799  F92E1C  30 04         		bmi	?ok		; ok is a write channel
1318
 3800  F92E1E  0A            		asl	a		; test bit 6 - direct access
1319
 3801  F92E1F  10 12         		bpl	verrbadchn	; channel not open for write
1320
 3802  F92E21  98            		tya
1321
 3803  F92E22  29 07         	?ok:	and	#$07
1322
 3804  F92E24  0A            		asl	a
1323
 3805  F92E25  85 4F         		sta	vbufnum		; buffer number #
1324
 3806  F92E27  86 44         	?set:	stx	sa		; save channel #
1325
 3807  F92E29  A9 80         		lda	#$80		; set active listen sa
1326
 3808  F92E2B  85 4D         		sta	viecfg
1327
 3809  F92E2D  18            		clc			; no error
1328
 3810  F92E2E  60            		rts
1329
 3811
1330
 3812  F92E2F                	verrnochn:
1331
 3813  F92E2F  A9 3D         		lda	#filnop
1332
 3814  F92E31  80 02         		bra	viecerr
1333
 3815  F92E33                	verrbadchn:
1334
 3816  F92E33  A9 24         		lda	#badchn
1335
 3817  F92E35                	viecerr:
1336
 3818  F92E35  8E FA E1      		stx	etrk
1337
 3819  F92E38  9C FB E1      		stz	esec
1338
 3820  F92E3B  85 56         		sta	lsterr
1339
 3821  F92E3D  38            		sec
1340
 3822  F92E3E  60            		rts
1341
 3823
1342
 3824  F92E3F                	verrlsn:
1343
 3825  F92E3F  A9 54         		lda	#badlsn
1344
 3826  F92E41  80 F2         		bra	viecerr
1345
 3827
1346
 3828                        	; test channel for close
1347
 3829                        	; A=sa
1348
 3830  F92E43                	vtstcls:
1349
 3831  F92E43  64 51         		stz	veof		; clear flush buffer flag
1350
 3832  F92E45  29 0F         		and	#$0F
1351
 3833  F92E47  AA            		tax
1352
 3834  F92E48  E0 0F         		cpx	#$0F
1353
 3835  F92E4A  F0 3E         		beq	?end
1354
 3836  F92E4C  24 4D         		bit	viecfg
1355
 3837  F92E4E  30 EF         		bmi	verrlsn
1356
 3838  F92E50  B5 59         		lda	lintab,x
1357
 3839  F92E52  C9 FF         		cmp	#$FF
1358
 3840  F92E54  F0 D9         		beq	verrnochn
1359
 3841  F92E56  A8            		tay
1360
 3842  F92E57  29 07         		and	#$07
1361
 3843  F92E59  0A            		asl	a
1362
 3844  F92E5A  85 4F         		sta	vbufnum
1363
 3845  F92E5C  98            		tya
1364
 3846  F92E5D  30 03         		bmi	?set
1365
  Tue Jul 17 11:00:19 2018                                                                                               Page   23
1366
 
1367
 
1368
 
1369
 
1370
 3847  F92E5F  0A            		asl	a
1371
 3848  F92E60  10 02         		bpl	?ok
1372
 3849  F92E62  85 51         	?set:	sta	veof		; set flush buffer flag
1373
 3850  F92E64  86 44         	?ok:	stx	sa
1374
 3851  F92E66  24 51         		bit	veof
1375
 3852  F92E68  10 20         		bpl	?end
1376
 3853  F92E6A  A6 4F         		ldx	vbufnum
1377
 3854  F92E6C                		ACC16CLC		; CF=0
1378
 3855  F92E6C  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
1379
 3856                        		.LONGA	on
1380
 3857                        		.MNLIST
1381
 3858  F92E6E  BF CA 2E F9   		lda	>viecdma,x
1382
 3859  F92E72  85 90         		sta	wbuf		; set buffer pointer
1383
 3860  F92E74  A0 03         		ldy	#DMABNK+1
1384
 3861  F92E76  84 92         		sty	wbuf+2
1385
 3862  F92E78  BD 00 E2      		lda	!vixtab,x
1386
 3863  F92E7B  85 86         		sta	bsize		; current index
1387
 3864  F92E7D  64 88         		stz	btrf		; clear transferred count
1388
 3865  F92E7F  9E 00 E2      		stz	!vixtab,x
1389
 3866  F92E82                		ACC08
1390
 3867  F92E82  E2 20         		sep	#PMFLAG
1391
 3868                        		.LONGA	off
1392
 3869                        		.MNLIST
1393
 3870  F92E84  D0 02         		bne	?sa		; ok, will flush buffer
1394
 3871  F92E86  64 51         		stz	veof		; nothing to flush
1395
 3872  F92E88  A6 44         	?sa:	ldx	sa
1396
 3873  F92E8A  18            	?end:	clc
1397
 3874  F92E8B  60            		rts
1398
 3875
1399
 3876                        	; close
1400
 3877  F92E8C                	A=sa
1401
 3878  F92E8C                	v8close:
1402
 3879                        		.GLOBAL v8close
1403
 3880
1404
 3881  F92E8C  0B            		phd			; save current dp
1405
 3882  F92E8D  F4 00 7E      		pea	#CBMFSP0
1406
 3883  F92E90  2B            		pld			; set dp to cbmfs emulator
1407
 3884  F92E91  8B            		phb			; save dbr
1408
 3885  F92E92  A2 00         		ldx	#0
1409
 3886  F92E94  DA            		phx
1410
 3887  F92E95  AB            		plb			; set dbr = 0
1411
 3888  F92E96  20 43 2E      		jsr	vtstcls
1412
 3889  F92E99  B0 2C         		bcs	?end		; error
1413
 3890  F92E9B  E0 0F         		cpx	#$0F
1414
 3891  F92E9D  18            		clc
1415
 3892  F92E9E  F0 27         		beq	?end
1416
 3893  F92EA0  86 52         		stx	chnl
1417
 3894  F92EA2  24 51         		bit	veof		; need ro flush buffer?
1418
 3895  F92EA4  10 0D         		bpl	?cls		; no, close file
1419
 3896  F92EA6  A6 44         		ldx	sa		; set channel #
1420
 3897  F92EA8  86 52         		stx	chnl
1421
 3898  F92EAA  A0 01         		ldy	#1		; write op
1422
 3899  F92EAC  20 4F 43      		jsr	fd_rw
1423
 3900  F92EAF  A6 44         		ldx	sa		; set channel #
1424
 3901  F92EB1  86 52         		stx	chnl		; ignore error
1425
 3902  F92EB3  20 AF 44      	?cls:	jsr	fdcls		; close file(s)
1426
 3903  F92EB6  64 4D         		stz	viecfg
1427
  Tue Jul 17 11:00:19 2018                                                                                               Page   24
1428
 
1429
 
1430
 
1431
 
1432
 3904  F92EB8  A6 4F         		ldx	vbufnum
1433
 3905  F92EBA                		ACC16
1434
 3906  F92EBA  C2 20         		rep	#PMFLAG
1435
 3907                        		.LONGA	on
1436
 3908                        		.MNLIST
1437
 3909  F92EBC  9E 00 E2      		stz	vixtab,x
1438
 3910  F92EBF  9E 10 E2      		stz	vsiztab,x
1439
 3911  F92EC2  9E 20 E2      		stz	vftab,x
1440
 3912  F92EC5                		ACC08
1441
 3913  F92EC5  E2 20         		sep	#PMFLAG
1442
 3914                        		.LONGA	off
1443
 3915                        		.MNLIST
1444
 3916  F92EC7  AB            	?end:	plb
1445
 3917  F92EC8  2B            		pld
1446
 3918  F92EC9  6B            		rtl
1447
 3919
1448
 3920  F92ECA                	viecdma:
1449
 3921  F92ECA  0000 0010 0020 		.DW	$0000, $1000, $2000, $3000
1450
               0030
1451
 3922  F92ED2  0040 0050 0060 		.DW	$4000, $5000, $6000, $7000
1452
               0070
1453
 3923  F92EDA
1454
 3924                        	;---------------------------------------------------------------------------
1455
 3925                        	; COP_cbmfs_cmd - send command to CBM file system emulator
1456
 3926                        	;
1457
 3927                        	; prototype: COP_cbmfs_cmd(sCmd, bChnl)
1458
 3928                        	;
1459
 3929                        	; Params (4 bytes):
1460
 3930                        	;	sCmd	= command string long pointer
1461
 3931                        	;	bChnl 	= channel number $00..$0F
1462
 3932                        	;			$00 		input only
1463
 3933                        	;			$01 		output only
1464
 3934                        	;			$02..$0E	data channel
1465
 3935                        	;			$0F		command channel
1466
 3936                        	;
1467
 3937                        	; Out:
1468
 3938                        	;	CF = 0 if operation completed successfully
1469
 3939                        	;		A,X,Y preserved
1470
 3940                        	;	CF = 1 if error
1471
 3941                        	;		A, X preserved
1472
 3942                        	;		Y = error code (cbm style)
1473
 3943                        	;	Status register always preserved except carry
1474
 3944
1475
 3945                        	; params offset
1476
 3946          000013        	bChnl	.SET	STKPRMS
1477
 3947          000014        	sCmd	.SET	STKPRMS + 1
1478
 3948
1479
 3949  F92EDA                	COP_cbmfs_cmd:
1480
 3950                        		.GLOBAL	COP_cbmfs_cmd
1481
 3951
1482
 3952  F92EDA                		ACC16
1483
 3953  F92EDA  C2 20         		rep	#PMFLAG
1484
 3954                        		.LONGA	on
1485
 3955                        		.MNLIST
1486
 3956  F92EDC  A9 00 7E      		lda	#CBMFSP0	; set DP -- not need to be saved
1487
 3957  F92EDF  5B            		tcd
1488
 3958  F92EE0  A3 14         		lda	sCmd,s		; get command string long pointer
1489
  Tue Jul 17 11:00:19 2018                                                                                               Page   25
1490
 
1491
 
1492
 
1493
 
1494
 3959  F92EE2  85 3E         		sta	tlp
1495
 3960  F92EE4                		ACC08
1496
 3961  F92EE4  E2 20         		sep	#PMFLAG
1497
 3962                        		.LONGA	off
1498
 3963                        		.MNLIST
1499
 3964  F92EE6  A3 16         		lda	sCmd+2,s
1500
 3965  F92EE8  85 40         		sta	tlp+2
1501
 3966  F92EEA  A3 13         		lda	bChnl,s
1502
 3967  F92EEC  29 0F         		and	#$0F		; mask
1503
 3968  F92EEE  85 52         		sta	chnl
1504
 3969  F92EF0  64 F9         		stz	cmdtrap
1505
 3970  F92EF2  20 8D 2F      		jsr	parsex		; parse & execute command string
1506
 3971  F92EF5  6B            		rtl			; return CF=1 if error
1507
 3972
1508
 3973                        	; internal file system command
1509
 3974                        	; A,X,Y=long pointer to command string
1510
 3975  F92EF6                	cbmfs_cmd:
1511
 3976                        		.PUBLIC cbmfs_cmd
1512
 3977
1513
 3978  F92EF6  0B            		phd			; save current dp
1514
 3979  F92EF7  F4 00 7E      		pea	#CBMFSP0
1515
 3980  F92EFA  2B            		pld			; set dp to emulator
1516
 3981  F92EFB  85 3E         		sta	tlp		; set command string ptr
1517
 3982  F92EFD  86 3F         		stx	tlp+1
1518
 3983  F92EFF  84 40         		sty	tlp+2
1519
 3984  F92F01  A9 0F         		lda	#$0F		; command to channel 15
1520
 3985  F92F03  85 52         		sta	chnl
1521
 3986  F92F05  8B            		phb			; save current dbr
1522
 3987  F92F06  A9 00         		lda	#0
1523
 3988  F92F08  48            		pha
1524
 3989  F92F09  AB            		plb			; set dbr=0
1525
 3990  F92F0A  64 F9         		stz	cmdtrap
1526
 3991  F92F0C  20 8D 2F      		jsr	parsex		; parse & execute command string
1527
 3992  F92F0F  AB            		plb			; restore dbr
1528
 3993  F92F10  2B            		pld			; restore dp
1529
 3994  F92F11  60            		rts			; return CF=1 if error (A=error code)
1530
 3995
1531
 3996                        	; internal file system command
1532
 3997                        	; return error string pointer (C=pointer, X=bank)
1533
 3998  F92F12                	cbmfs_err:
1534
 3999                        		.PUBLIC cbmfs_err
1535
 4000
1536
 4001  F92F12  0B            		phd			; save current dp
1537
 4002  F92F13  F4 00 7E      		pea	#CBMFSP0
1538
 4003  F92F16  2B            		pld			; set dp to emulator
1539
 4004  F92F17  20 44 57      		jsr	fnderr
1540
 4005  F92F1A  A0 00         		ldy	#0
1541
 4006  F92F1C  B7 3E         	?02:	lda	[tlp],y
1542
 4007  F92F1E  F0 10         		beq	?06
1543
 4008  F92F20  C9 61         		cmp	#'a'
1544
 4009  F92F22  90 06         		bcc	?04
1545
 4010  F92F24  C9 7B         		cmp	#'z'+1
1546
 4011  F92F26  B0 02         		bcs	?04
1547
 4012  F92F28  29 DF         		and	#$DF
1548
 4013  F92F2A  99 00 E1      	?04:	sta	cmdbuf,y
1549
 4014  F92F2D  C8            		iny
1550
 4015  F92F2E  80 EC         		bra	?02
1551
  Tue Jul 17 11:00:19 2018                                                                                               Page   26
1552
 
1553
 
1554
 
1555
 
1556
 4016  F92F30  99 00 E1      	?06:	sta	cmdbuf,y
1557
 4017  F92F33  A9 E1         		lda	#>cmdbuf
1558
 4018  F92F35  EB            		xba
1559
 4019  F92F36  A9 00         		lda	#<cmdbuf
1560
 4020  F92F38  A2 00         		ldx	#0
1561
 4021  F92F3A  AB            		plb			; restore dbr
1562
 4022  F92F3B  2B            		pld			; restore dp
1563
 4023  F92F3C  60            		rts
1564
 4024  F92F3D
1565
 4025                        	;---------------------------------------------------------------------------
1566
 4026                        	; COP_cbmfs_rw - read/write on channel (in an open file)
1567
 4027                        	;
1568
 4028                        	; prototype: COP_cbmfs_rw(lpBuf, wSize, bChnl)
1569
 4029                        	;
1570
 4030                        	; Params (6 bytes):
1571
 4031                        	;	lpBuf	= long pointer to buffer
1572
 4032                        	;	wSize 	= size (16 bit) of buffer if read or bytes count to write
1573
 4033                        	;	bChnl	= channel number ($00..$0F)
1574
 4034                        	;
1575
 4035                        	; Out:
1576
 4036                        	;	CF = 0 if operation completed successfully
1577
 4037                        	;		C  = number of bytes transferred
1578
 4038                        	;		X  = unchanged
1579
 4039                        	;		Y  = unchanged
1580
 4040                        	;	CF = 1 if error
1581
 4041                        	;		C  = number of bytes transferred
1582
 4042                        	;		X  = unchanged
1583
 4043                        	;		Y  = error code (cbm-like)
1584
 4044                        	;	Status register always preserved except carry
1585
 4045                        	;
1586
 4046                        	; Note:
1587
 4047                        	;	Write to channel 15 ($0F) is no-op and return C = 0 and carry = 0
1588
 4048                        	;	Use COP_cbmfs_cmd function to send command on channel 15
1589
 4049                        	;	Read on channel 15 ($0F) return last error message
1590
 4050                        	;	and need at least 96 bytes buffer large
1591
 4051
1592
 4052                        	; params offset
1593
 4053          000013        	bChnl	.SET	STKPRMS
1594
 4054          000014        	wSize	.SET	STKPRMS + 1
1595
 4055          000016        	lpBuf	.SET	STKPRMS + 3
1596
 4056
1597
 4057  F92F3D                	COP_cbmfs_rw:
1598
 4058                        		.GLOBAL	COP_cbmfs_rw
1599
 4059
1600
 4060  F92F3D                		ACC16			; retrieve function number
1601
 4061  F92F3D  C2 20         		rep	#PMFLAG
1602
 4062                        		.LONGA	on
1603
 4063                        		.MNLIST
1604
 4064  F92F3F  A3 10         		lda	STKPCL,s	; pointer to byte after signature
1605
 4065  F92F41  85 51         		sta	COPPtr
1606
 4066  F92F43  1A            		inc	a		; update return address
1607
 4067  F92F44  83 10         		sta	STKPCL,s
1608
 4068  F92F46                		ACC08			; A,M -> 8 bit
1609
 4069  F92F46  E2 20         		sep	#PMFLAG
1610
 4070                        		.LONGA	off
1611
 4071                        		.MNLIST
1612
 4072  F92F48  A3 12         		lda	STKPBR,s	; bank where was executed cop instruction
1613
  Tue Jul 17 11:00:19 2018                                                                                               Page   27
1614
 
1615
 
1616
 
1617
 
1618
 4073  F92F4A  85 53         		sta	COPPtr+2
1619
 4074  F92F4C  A7 51         		lda	[COPPtr]	; byte after signature (0->read, 1->write)
1620
 4075  F92F4E  A8            		tay			; Y = read(0)/write(1)
1621
 4076  F92F4F                		ACC16
1622
 4077  F92F4F  C2 20         		rep	#PMFLAG
1623
 4078                        		.LONGA	on
1624
 4079                        		.MNLIST
1625
 4080  F92F51  A9 00 7E      		lda	#CBMFSP0	; set DP -- not need to be saved
1626
 4081  F92F54  5B            		tcd
1627
 4082  F92F55  A3 14         		lda	wSize,s		; get buffer size
1628
 4083  F92F57  85 86         		sta	bsize
1629
 4084  F92F59  64 88         		stz	btrf		; clear transferred count
1630
 4085  F92F5B  A3 16         		lda	lpBuf,s		; dest. buffer poinnter
1631
 4086  F92F5D  85 90         		sta	wbuf
1632
 4087  F92F5F                		ACC08			; A,M -> 8 bit
1633
 4088  F92F5F  E2 20         		sep	#PMFLAG
1634
 4089                        		.LONGA	off
1635
 4090                        		.MNLIST
1636
 4091  F92F61  A3 18         		lda	lpBuf+2,s
1637
 4092  F92F63  85 92         		sta	wbuf+2
1638
 4093  F92F65  A3 13         		lda	bChnl,s		; get channel
1639
 4094  F92F67  29 0F         		and	#$0F		; mask
1640
 4095  F92F69  AA            		tax
1641
 4096  F92F6A  86 52         		stx	chnl
1642
 4097  F92F6C  20 4F 43      		jsr	fd_rw		; return carry = 1 if error
1643
 4098  F92F6F  AA            		tax			; save error code if any
1644
 4099  F92F70                		ACC16
1645
 4100  F92F70  C2 20         		rep	#PMFLAG
1646
 4101                        		.LONGA	on
1647
 4102                        		.MNLIST
1648
 4103  F92F72  A5 88         		lda	btrf		; return count of transf. bytes to caller
1649
 4104  F92F74  83 0D         		sta	STKCR,s
1650
 4105  F92F76                		ACC08
1651
 4106  F92F76  E2 20         		sep	#PMFLAG
1652
 4107                        		.LONGA	off
1653
 4108                        		.MNLIST
1654
 4109  F92F78  8A            		txa
1655
 4110  F92F79  6B            		rtl
1656
 4111
1657
 4112                        	;---------------------------------------------------------------------------
1658
 4113                        	; COP_cbmfs_close
1659
 4114                        	;
1660
 4115                        	; prototype: COP_cbmfs_close
1661
 4116                        	;
1662
 4117                        	; Params: none in stack
1663
 4118                        	;	A = channel to close ($00..$0F)
1664
 4119                        	;	closing chnl $0F close all open files
1665
 4120                        	;
1666
 4121                        	; Out:
1667
 4122                        	;	CF = 0 if operation completed successfully
1668
 4123                        	;		C  = unchanged
1669
 4124                        	;		X  = unchanged
1670
 4125                        	;		Y  = unchanged
1671
 4126                        	;	CF = 1 if error
1672
 4127                        	;		C  = unchanged
1673
 4128                        	;		X  = unchanged
1674
 4129                        	;		Y  = error code (cbm-like)
1675
  Tue Jul 17 11:00:19 2018                                                                                               Page   28
1676
 
1677
 
1678
 
1679
 
1680
 4130                        	;	Status register always preserved except carry
1681
 4131                        	;
1682
 4132  F92F7A                	COP_cbmfs_close:
1683
 4133                        		.GLOBAL COP_cbmfs_close
1684
 4134
1685
 4135  F92F7A                		ACC16
1686
 4136  F92F7A  C2 20         		rep	#PMFLAG
1687
 4137                        		.LONGA	on
1688
 4138                        		.MNLIST
1689
 4139  F92F7C  A9 00 7E      		lda	#CBMFSP0	; set DP -- not need to be saved
1690
 4140  F92F7F  5B            		tcd
1691
 4141  F92F80                		ACC08
1692
 4142  F92F80  E2 20         		sep	#PMFLAG
1693
 4143                        		.LONGA	off
1694
 4144                        		.MNLIST
1695
 4145  F92F82  A3 0D         		lda	STKCR,s		; get channel
1696
 4146  F92F84  29 0F         		and	#$0F
1697
 4147  F92F86  AA            		tax
1698
 4148  F92F87  86 52         		stx	chnl
1699
 4149  F92F89  20 AF 44      		jsr	fdcls
1700
 4150  F92F8C  6B            		rtl
1701
 4151
1702
 4152                        	;---------------------------------------------------------------------------
1703
 4153                        	; parse command string & execute command
1704
 4154                        	;---------------------------------------------------------------------------
1705
 4155
1706
 4156                        	; parse & execute command string
1707
 4157  F92F8D                	parsex:
1708
 4158  F92F8D                		ACC16
1709
 4159  F92F8D  C2 20         		rep	#PMFLAG
1710
 4160                        		.LONGA	on
1711
 4161                        		.MNLIST
1712
 4162  F92F8F  3B            		tsc			; save current stack pointer
1713
 4163  F92F90  8D F8 E1      		sta	!tos
1714
 4164  F92F93                		ACC08
1715
 4165  F92F93  E2 20         		sep	#PMFLAG
1716
 4166                        		.LONGA	off
1717
 4167                        		.MNLIST
1718
 4168  F92F95  64 56         		stz	lsterr
1719
 4169  F92F97  20 D1 42      		jsr	cmdset		; trim & up case input string
1720
 4170  F92F9A  A4 41         		ldy	cmdsiz
1721
 4171  F92F9C  F0 40         		beq	?10		; empty command string
1722
 4172  F92F9E  A5 52         		lda	chnl
1723
 4173  F92FA0  C9 0F         		cmp	#$0F
1724
 4174  F92FA2  D0 3F         		bne	?30		; open command
1725
 4175  F92FA4  A2 10         		ldx	#ncmds-1	; check first letter...
1726
 4176  F92FA6  AD 00 E1      		lda	!cmdbuf		; ...with cmd table
1727
 4177  F92FA9  DF 58 5A F9   	?02:	cmp	>cmdtbl,x
1728
 4178  F92FAD  F0 06         		beq	?04
1729
 4179  F92FAF  CA            		dex
1730
 4180  F92FB0  10 F7         		bpl	?02
1731
 4181  F92FB2  4C FD 40      		jmp	e_badcmd
1732
 4182  F92FB5  86 53         	?04:	stx	cmdnum
1733
 4183  F92FB7  A4 41         		ldy	cmdsiz		; if just one char is an arror !
1734
 4184  F92FB9  88            		dey
1735
 4185  F92FBA  F0 24         		beq	?20		; syntax error
1736
 4186  F92FBC  E0 0F         		cpx	#ndcmd		; no check drive for block-op
1737
  Tue Jul 17 11:00:19 2018                                                                                               Page   29
1738
 
1739
 
1740
 
1741
 
1742
 4187  F92FBE  B0 0F         		bcs	?06
1743
 4188  F92FC0  AD 01 E1      		lda	!cmdbuf+1
1744
 4189  F92FC3  A0 00         		ldy	#0		; check cbm drive (0 or 1)
1745
 4190  F92FC5  E0 09         		cpx	#pcmd-1		; if M command, first drive will be dos drive
1746
 4191  F92FC7  D0 01         		bne	?05
1747
 4192  F92FC9  88            		dey			; check dos drive
1748
 4193  F92FCA  20 98 3D      	?05:	jsr	chkdrv
1749
 4194  F92FCD  85 19         		sta	drvnum		; save first drive in command string
1750
 4195  F92FCF  E0 0A         	?06:	cpx	#pcmd		; limit of not parsed cmd
1751
 4196  F92FD1  B0 05         		bcs	?08
1752
 4197  F92FD3  20 0E 41      		jsr	tagcmd		; full parse command
1753
 4198  F92FD6  A6 53         		ldx	cmdnum
1754
 4199  F92FD8  8A            	?08:	txa
1755
 4200  F92FD9  0A            		asl	a
1756
 4201  F92FDA  AA            		tax
1757
 4202  F92FDB  FC C4 5A      		jsr	(cjump,x)
1758
 4203  F92FDE  18            	?10:	clc			; return no error
1759
 4204  F92FDF  60            		rts
1760
 4205
1761
 4206  F92FE0  4C 05 41      	?20:	jmp	e_badsyn
1762
 4207
1763
 4208                        	;---------------------------------------------------------------------------
1764
 4209                        	; open function's
1765
 4210                        	;---------------------------------------------------------------------------
1766
 4211
1767
 4212                        	; parse open command on channel 0..14
1768
 4213                        	; covered cases:
1769
 4214                        	;	"*"
1770
 4215                        	;	"dr:*"
1771
 4216                        	;	"#"
1772
 4217                        	;	"$"
1773
 4218                        	;	"$dr"
1774
 4219                        	;	"$dr:pattern=type"
1775
 4220                        	;	"filename,type,mode" (drive #0)
1776
 4221                        	;	"[@]dr:filename,type,mode"
1777
 4222                        	; in:	A = channel #
1778
 4223  F92FE3  AA            	?30:	tax			; check free chnl
1779
 4224  F92FE4  B4 59         		ldy	lintab,x
1780
 4225  F92FE6  C0 FF         		cpy	#$FF
1781
 4226  F92FE8  F0 05         		beq	?31		; ok, chnl is free
1782
 4227  F92FEA  A9 4B         		lda	#opnchn
1783
 4228  F92FEC  4C ED 56      		jmp	chnerr
1784
 4229  F92FEF  AE 00 E1      	?31:	ldx	cmdbuf		; first char of cmd string
1785
 4230  F92FF2  64 19         		stz	drvnum		; set drive 0 as default
1786
 4231  F92FF4  64 55         		stz	subcmd		; default open file
1787
 4232  F92FF6  A8            		tay			; channel
1788
 4233  F92FF7  D0 30         		bne	?36		; not "load" channel (0)
1789
 4234  F92FF9  E0 2A         		cpx	#'*'		; load first program on drive 0?
1790
 4235  F92FFB  D0 2C         		bne	?36
1791
 4236  F92FFD  A9 2A         	?32:	lda	#'*'		; file = "*"
1792
 4237  F92FFF  8F 00 E1 00   		sta	cmdbuf
1793
 4238  F93003  9C 01 E1      		stz	cmdbuf+1
1794
 4239  F93006  A9 01         		lda	#1
1795
 4240  F93008  85 41         		sta	cmdsiz
1796
 4241  F9300A  A2 00         		ldx	#<cmdbuf
1797
 4242  F9300C  86 1A         		stx	filtbl		; file ptr
1798
 4243  F9300E  A9 80         		lda	#$80
1799
  Tue Jul 17 11:00:19 2018                                                                                               Page   30
1800
 
1801
 
1802
 
1803
 
1804
 4244  F93010  85 39         		sta	pattyp
1805
 4245  F93012  A9 00         		lda	#0
1806
 4246  F93014  A5 19         		lda	drvnum
1807
 4247  F93016  85 34         		sta	fildrv
1808
 4248  F93018  A9 02         		lda	#prgtyp
1809
 4249  F9301A  85 10         		sta	typflg		; filter prog. type in search
1810
 4250  F9301C  64 0F         		stz	mode		; read mode
1811
 4251  F9301E  A9 01         		lda	#1
1812
 4252  F93020  85 12         		sta	f1cnt
1813
 4253  F93022  85 13         		sta	f2cnt
1814
 4254  F93024  64 55         		stz	subcmd		; open file read mode
1815
 4255  F93026  4C C4 30      		jmp	?78
1816
 4256  F93029  E0 24         	?36:	cpx	#'$'		; open directory ?
1817
 4257  F9302B  D0 1D         		bne	?48
1818
 4258  F9302D  98            		tya
1819
 4259  F9302E  D0 0A         		bne	?40		; open directory as seq. file
1820
 4260  F93030  20 AB 41      		jsr	prsldd		; parse string for load directory cmd
1821
 4261  F93033  A9 03         		lda	#lddir		; load dir
1822
 4262  F93035  85 55         		sta	subcmd
1823
 4263  F93037  4C C4 30      		jmp	?78
1824
 4264  F9303A  88            	?40:	dey			; error if channel = 1
1825
 4265  F9303B  F0 0A         		beq	?44
1826
 4266  F9303D  20 31 42      		jsr	simprs		; simple parser for set drive
1827
 4267  F93040  A9 04         		lda	#seqdir
1828
 4268  F93042  85 55         		sta	subcmd		; open directory as seq. file
1829
 4269  F93044  4C C7 30      		jmp	?80		; no pattern here
1830
 4270  F93047  4C 8E 3D      	?44:	jmp	e_badchn
1831
 4271  F9304A  E0 23         	?48:	cpx	#'#'		; open direct access?
1832
 4272  F9304C  D0 12         		bne	?60
1833
 4273  F9304E  A6 41         		ldx	cmdsiz
1834
 4274  F93050  CA            		dex			; #xxx is unsupported
1835
 4275  F93051  F0 03         		beq	?52		; ok
1836
 4276  F93053  4C 05 41      	?50:	jmp	e_badsyn
1837
 4277  F93056  C0 02         	?52:	cpy	#2
1838
 4278  F93058  90 ED         		bcc	?44		; can't use ch 0 & 1
1839
 4279  F9305A  A9 05         		lda	#damode		; open direct access type
1840
 4280  F9305C  85 55         		sta	subcmd
1841
 4281  F9305E  80 67         		bra	?80		; no pattern for direct access type
1842
 4282  F93060  20 66 41      	?60:	jsr	prsopn		; parse "@dr:filename,type,mode"
1843
 4283  F93063  A2 00         		ldx	#0
1844
 4284  F93065  86 0F         		stx	mode		; default read mode
1845
 4285  F93067  86 42         		stx	<opntm		; flag type & mode in parameters
1846
 4286  F93069  E8            		inx
1847
 4287  F9306A  86 0E         		stx	type		; defaul type: seq
1848
 4288  F9306C  E4 12         		cpx	f1cnt		; f1cnt now hold # params
1849
 4289  F9306E  B0 0B         		bcs	?64		; no parameter's
1850
 4290  F93070  20 D0 30      		jsr	?100		; at least one param: check for type & mode
1851
 4291  F93073  E8            		inx
1852
 4292  F93074  E4 12         		cpx	f1cnt
1853
 4293  F93076  B0 03         		bcs	?64		; only one parameter
1854
 4294  F93078  20 D0 30      		jsr	?100		; set type & mode
1855
 4295  F9307B  A4 0E         	?64:	ldy	type
1856
 4296  F9307D  C0 04         		cpy	#reltyp
1857
 4297  F9307F  F0 D2         		beq	?50		; error (unsupported type)
1858
 4298  F93081  C0 05         		cpy	#partyp
1859
 4299  F93083  F0 CE         		beq	?50		; error (unsupported type)
1860
 4300  F93085  A6 52         		ldx	chnl
1861
  Tue Jul 17 11:00:19 2018                                                                                               Page   31
1862
 
1863
 
1864
 
1865
 
1866
 4301  F93087  E0 02         		cpx	#2
1867
 4302  F93089  B0 0C         		bcs	?66		; not load / save
1868
 4303  F9308B  86 0F         		stx	mode		; force read on chn 0 and write on chn 1
1869
 4304  F9308D  24 42         		bit	opntm
1870
 4305  F9308F  30 0C         		bmi	?68		; type from parameter
1871
 4306  F93091  A9 02         		lda	#prgtyp		; set default type for load/save
1872
 4307  F93093  85 0E         		sta	type
1873
 4308  F93095  80 06         		bra	?68
1874
 4309  F93097  24 42         	?66:	bit	opntm
1875
 4310  F93099  30 04         		bmi	?70		; type from param
1876
 4311  F9309B  A9 01         		lda	#seqtyp		; default type: seq
1877
 4312  F9309D  85 0E         	?68:	sta	type
1878
 4313  F9309F  A6 0F         	?70:	ldx	mode
1879
 4314  F930A1  E0 01         		cpx	#wtmode
1880
 4315  F930A3  D0 17         		bne	?76
1881
 4316  F930A5  24 39         		bit	pattyp		; no wildcards for write
1882
 4317  F930A7  10 05         		bpl	?74
1883
 4318  F930A9  A9 21         	?72:	lda	#badfn
1884
 4319  F930AB  4C 07 41      		jmp	cmderr
1885
 4320  F930AE  AF 00 E1 00   	?74:	lda	cmdbuf		; check replace write mode
1886
 4321  F930B2  C9 40         		cmp	#'@'
1887
 4322  F930B4  D0 06         		bne	?76
1888
 4323  F930B6  A9 80         		lda	#$80		; set flag replace mode
1889
 4324  F930B8  85 E6         		sta	wrop
1890
 4325  F930BA  A6 0F         		ldx	mode
1891
 4326  F930BC  86 55         	?76	stx	subcmd		; open file sub-command (read, write, append)
1892
 4327  F930BE  E4 03         		cpx	mdmode		; is like read mode
1893
 4328  F930C0  D0 02         		bne	?78
1894
 4329  F930C2  64 55         		stz	subcmd
1895
 4330  F930C4  20 AC 3F      	?78:	jsr	buildfn		; build table of canonical names
1896
 4331  F930C7  A5 55         	?80:	lda	subcmd
1897
 4332  F930C9  0A            		asl	a
1898
 4333  F930CA  AA            		tax
1899
 4334  F930CB  FC F0 5A      		jsr	(opncmd,x)	; execute open func.
1900
 4335  F930CE  18            		clc			; return no error
1901
 4336  F930CF  60            		rts
1902
 4337
1903
 4338                        	; check type & mode
1904
 4339  F930D0  B4 1A         	?100:	ldy	filtbl,x	; get ptr
1905
 4340  F930D2  B9 00 E1      		lda	cmdbuf,y	; get char
1906
 4341  F930D5  DA            		phx
1907
 4342  F930D6  A2 04         		ldx	#nmodes
1908
 4343  F930D8  CA            	?102:	dex
1909
 4344  F930D9  30 0C         		bmi	?104		; no valid mode
1910
 4345  F930DB  DF 7A 5A F9   		cmp	>modlst,x
1911
 4346  F930DF  D0 F7         		bne	?102
1912
 4347  F930E1  86 0F         		stx	mode		; mode found
1913
 4348  F930E3  A9 40         		lda	#$40
1914
 4349  F930E5  04 42         		tsb	<opntm		; set flag mode
1915
 4350  F930E7  A2 06         	?104:	ldx	#ntypes
1916
 4351  F930E9  CA            	?106:	dex
1917
 4352  F930EA  30 0C         		bmi	?108		; no valid type
1918
 4353  F930EC  DF 7E 5A F9   		cmp	>tplst,x
1919
 4354  F930F0  D0 F7         		bne	?106
1920
 4355  F930F2  86 0E         		stx	type		; type found
1921
 4356  F930F4  A9 80         		lda	#$80
1922
 4357  F930F6  04 42         		tsb	<opntm		; set flag type
1923
  Tue Jul 17 11:00:19 2018                                                                                               Page   32
1924
 
1925
 
1926
 
1927
 
1928
 4358  F930F8  FA            	?108:	plx
1929
 4359  F930F9  60            		rts
1930
 4360
1931
 4361                        	;---------------------------------------------------------------------------
1932
 4362                        	; open file for reading subcommand
1933
 4363                        	;---------------------------------------------------------------------------
1934
 4364  F930FA                	opnrd:
1935
 4365  F930FA  20 03 31      		jsr	opread		; open an read fd
1936
 4366  F930FD  20 AB 57      		jsr	tread		; pre-read in read cache
1937
 4367  F93100  64 F8         		stz	trap		; no trap error
1938
 4368  F93102  60            		rts
1939
 4369
1940
 4370                        	; open a read fd
1941
 4371                        	; common routine for open read & open append
1942
 4372  F93103                	opread:
1943
 4373  F93103  20 97 4B      		jsr	optsch		; init drive and set up search opt.
1944
 4374  F93106  20 70 4A      		jsr	ffst		; look for file entry
1945
 4375  F93109  A5 20         		lda	filtrk
1946
 4376  F9310B  D0 05         		bne	?02		; ok, file found
1947
 4377  F9310D  A9 3E         		lda	#flntfd
1948
 4378  F9310F  4C 07 41      		jmp	cmderr		; file not found
1949
 4379  F93112  A5 39         	?02:	lda	pattyp
1950
 4380  F93114  29 07         		and	#typmsk		; type from file
1951
 4381  F93116  A6 0E         		ldx	type		; del. type is invalid !!
1952
 4382  F93118  D0 04         		bne	?04		; type from parameter
1953
 4383  F9311A  85 0E         		sta	type		; type from file
1954
 4384  F9311C  80 09         		bra	?06
1955
 4385  F9311E  C5 0E         	?04:	cmp	type		; match type from file?
1956
 4386  F93120  F0 05         		beq	?06		; yes
1957
 4387  F93122  A9 40         		lda	#mistyp		; type mismatch
1958
 4388  F93124  4C 07 41      		jmp	cmderr
1959
 4389  F93127  A5 0F         	?06:	lda	mode
1960
 4390  F93129  AA            		tax
1961
 4391  F9312A  C9 03         		cmp	#mdmode
1962
 4392  F9312C  F0 0B         		beq	?08		; open always, even splat file
1963
 4393  F9312E  A9 20         		lda	#$20		; this is a splat file?
1964
 4394  F93130  24 39         		bit	pattyp
1965
 4395  F93132  F0 05         		beq	?08		; no -- open
1966
 4396  F93134  A9 29         		lda	#fsplt
1967
 4397  F93136  4C 07 41      		jmp	cmderr		; write file not closed
1968
 4398  F93139  E0 02         	?08:	cpx	#apmode
1969
 4399  F9313B  D0 0B         		bne	?10
1970
 4400  F9313D  A9 40         		lda	#$40
1971
 4401  F9313F  24 39         		bit	pattyp		; locked file?
1972
 4402  F93141  F0 05         		beq	?10		; no
1973
 4403  F93143  A9 28         		lda	#flock
1974
 4404  F93145  4C 07 41      		jmp	cmderr		; locked file
1975
 4405  F93148  20 28 47      	?10:	jsr	opnrfd		; open read fd
1976
 4406  F9314B  A9 80         		lda	#$80
1977
 4407  F9314D  85 F8         		sta	trap		; trap disk error while open
1978
 4408  F9314F  60            		rts
1979
 4409
1980
 4410                        	;---------------------------------------------------------------------------
1981
 4411                        	; open file for writing subcommand
1982
 4412                        	;---------------------------------------------------------------------------
1983
 4413  F93150                	opnwr:
1984
 4414  F93150  20 97 4B      		jsr	optsch		; init drive and set up search opt.
1985
  Tue Jul 17 11:00:19 2018                                                                                               Page   33
1986
 
1987
 
1988
 
1989
 
1990
 4415  F93153  20 70 4A      		jsr	ffst		; look for file entry
1991
 4416  F93156  A5 20         		lda	filtrk
1992
 4417  F93158  F0 27         		beq	?08		; ok, file not found: can create it
1993
 4418  F9315A  24 E6         		bit	wrop		; replace file?
1994
 4419  F9315C  30 05         		bmi	?02		; yes
1995
 4420  F9315E  A9 3F         		lda	#flexst
1996
 4421  F93160  4C 07 41      		jmp	cmderr		; file exists
1997
 4422  F93163  A5 39         	?02:	lda	pattyp		; splat file?
1998
 4423  F93165  89 20         		bit	#$20
1999
 4424  F93167  F0 05         		beq	?04		; no
2000
 4425  F93169  A9 29         		lda	#fsplt
2001
 4426  F9316B  4C 07 41      		jmp	cmderr		; write file not closed
2002
 4427  F9316E  29 07         	?04:	and	#typmsk		; type from file
2003
 4428  F93170  A6 0E         		ldx	type		; del. type is invalid !!
2004
 4429  F93172  D0 04         		bne	?06		; type from parameter
2005
 4430  F93174  85 0E         		sta	type		; type from file
2006
 4431  F93176  80 0B         		bra	?10
2007
 4432  F93178  C5 0E         	?06:	cmp	type		; match type from file?
2008
 4433  F9317A  F0 07         		beq	?10		; yes
2009
 4434  F9317C  A9 40         		lda	#mistyp		; type mismatch
2010
 4435  F9317E  4C 07 41      		jmp	cmderr
2011
 4436  F93181  64 E6         	?08:	stz	wrop		; create file
2012
 4437  F93183  20 52 47      	?10:	jsr	opnwfd		; open file for write
2013
 4438  F93186  A6 19         		ldx	drvnum
2014
 4439  F93188  74 68         		stz	drvfg,x
2015
 4440  F9318A  60            		rts
2016
 4441
2017
 4442                        	;---------------------------------------------------------------------------
2018
 4443                        	; open file for append subcommand
2019
 4444                        	;---------------------------------------------------------------------------
2020
 4445  F9318B                	opnap:
2021
 4446  F9318B  20 03 31      		jsr	opread		; first of all open an read fd
2022
 4447  F9318E  64 E6         		stz	wrop		; use as temp. eof flag
2023
 4448  F93190  A5 2A         		lda	entsec		; set dir to entry
2024
 4449  F93192  85 09         		sta	sector
2025
 4450  F93194  A0 28         		ldy	#dirtrk
2026
 4451  F93196  84 08         		sty	track
2027
 4452  F93198  A7 0A         		lda	[dirp]		; clear flag closed file
2028
 4453  F9319A  29 4F         		and	#$4F
2029
 4454  F9319C  87 0A         		sta	[dirp]
2030
 4455  F9319E  20 57 36      		jsr	wrdsec		; update dir on disk
2031
 4456  F931A1  A5 20         		lda	filtrk
2032
 4457  F931A3  85 08         		sta	track		; set up first block
2033
 4458  F931A5  A5 25         		lda	filsec
2034
 4459  F931A7  85 09         		sta	sector
2035
 4460  F931A9                		ACC16
2036
 4461  F931A9  C2 20         		rep	#PMFLAG
2037
 4462                        		.LONGA	on
2038
 4463                        		.MNLIST
2039
 4464  F931AB  64 F0         		stz	wcnt		; clear block's counter
2040
 4465  F931AD  A6 F7         		ldx	dblfd
2041
 4466  F931AF  B5 C6         		lda	fdblk,x
2042
 4467  F931B1  85 94         		sta	wtmp		; set limit for read block's #
2043
 4468  F931B3                		ACC08
2044
 4469  F931B3  E2 20         		sep	#PMFLAG
2045
 4470                        		.LONGA	off
2046
 4471                        		.MNLIST
2047
  Tue Jul 17 11:00:19 2018                                                                                               Page   34
2048
 
2049
 
2050
 
2051
 
2052
 4472  F931B5  20 C1 57      	?02:	jsr	wread		; read whole track in write cache
2053
 4473  F931B8  20 5A 56      		jsr	setwb		; set cache ptr to right sector
2054
 4474  F931BB                	?04:	ACC16
2055
 4475  F931BB  C2 20         		rep	#PMFLAG
2056
 4476                        		.LONGA	on
2057
 4477                        		.MNLIST
2058
 4478  F931BD  A5 F0         		lda	wcnt		; update block's counter
2059
 4479  F931BF  1A            		inc	a
2060
 4480  F931C0  85 F0         		sta	wcnt
2061
 4481  F931C2  C5 94         		cmp	wtmp		; sanity check
2062
 4482  F931C4                		ACC08
2063
 4483  F931C4  E2 20         		sep	#PMFLAG
2064
 4484                        		.LONGA	off
2065
 4485                        		.MNLIST
2066
 4486  F931C6  90 0B         		bcc	?08		; for now is ok
2067
 4487  F931C8  F0 05         		beq	?06		; reached block's count #
2068
 4488  F931CA  A9 2A         	?05:	lda	#bnotm
2069
 4489  F931CC  4C FB 56      		jmp	doserr		; unmatch blocks count
2070
 4490  F931CF  A9 80         	?06:	lda	#$80
2071
 4491  F931D1  85 E6         		sta	wrop		; signal count match
2072
 4492  F931D3  A0 01         	?08:	ldy	#1
2073
 4493  F931D5  B7 90         		lda	[wbuf],y	; next sector
2074
 4494  F931D7  A8            		tay
2075
 4495  F931D8  A7 90         		lda	[wbuf]		; next track
2076
 4496  F931DA  F0 1A         		beq	?10		; end of file?
2077
 4497  F931DC  84 09         		sty	sector		; next sector
2078
 4498  F931DE  C9 51         		cmp	#maxtrk
2079
 4499  F931E0  B0 45         		bcs	?15		; invalid track in link
2080
 4500  F931E2  C0 28         		cpy	#numsec
2081
 4501  F931E4  B0 41         		bcs	?15		; invalid sector in link
2082
 4502  F931E6  C5 08         		cmp	track		; same track?
2083
 4503  F931E8  85 08         		sta	track
2084
 4504  F931EA  D0 C9         		bne	?02		; will read a new track
2085
 4505  F931EC  18            		clc
2086
 4506  F931ED  98            		tya
2087
 4507  F931EE  A6 19         		ldx	drvnum
2088
 4508  F931F0  75 7C         		adc	wrtofs,x	; sector in the same track
2089
 4509  F931F2  85 91         		sta	wbuf+1
2090
 4510  F931F4  80 C5         		bra	?04		; next data block
2091
 4511  F931F6  24 E6         	?10:	bit	wrop		; here block's count should match
2092
 4512  F931F8  10 D0         		bpl	?05		; unmatch
2093
 4513  F931FA  C0 02         		cpy	#2		; last block wrong index?
2094
 4514  F931FC  90 30         		bcc	?20		; yes
2095
 4515  F931FE  C8            		iny			; bump pointer
2096
 4516  F931FF  A6 57         		ldx	lindx
2097
 4517  F93201  94 BE         		sty	fdptr,x		; start index for append
2098
 4518  F93203  A5 09         		lda	sector
2099
 4519  F93205  95 B6         		sta	fsec,x		; current file sector
2100
 4520  F93207  A5 08         		lda	track
2101
 4521  F93209  95 AE         		sta	ftrk,x		; current file track
2102
 4522  F9320B                		ACC16
2103
 4523  F9320B  C2 20         		rep	#PMFLAG
2104
 4524                        		.LONGA	on
2105
 4525                        		.MNLIST
2106
 4526  F9320D  A5 F0         		lda	wcnt		; append !!
2107
 4527  F9320F  3A            		dec	a		; one less...when close file...
2108
 4528  F93210  A6 F7         		ldx	dblfd		; one more block will be added
2109
  Tue Jul 17 11:00:19 2018                                                                                               Page   35
2110
 
2111
 
2112
 
2113
 
2114
 4529  F93212  95 C6         		sta	fdblk,x		; store current block's count
2115
 4530  F93214                		ACC08
2116
 4531  F93214  E2 20         		sep	#PMFLAG
2117
 4532                        		.LONGA	off
2118
 4533                        		.MNLIST
2119
 4534  F93216  A9 80         		lda	#$80		; now set fd for write
2120
 4535  F93218  05 57         		ora	lindx
2121
 4536  F9321A  A6 52         		ldx	chnl
2122
 4537  F9321C  95 59         		sta	lintab,x
2123
 4538  F9321E  A6 57         		ldx	lindx
2124
 4539  F93220  64 F8         		stz	trap		; no trap error
2125
 4540  F93222  A6 19         		ldx	drvnum
2126
 4541  F93224  74 68         		stz	drvfg,x
2127
 4542  F93226  60            		rts
2128
 4543
2129
 4544  F93227  85 08         	?15:	sta	track		; invalid link
2130
 4545  F93229  A9 2B         		lda	#invlnk
2131
 4546  F9322B  4C FB 56      		jmp	doserr		; invalid file link
2132
 4547
2133
 4548  F9322E  84 09         	?20:	sty	sector		; wrong index in last block
2134
 4549  F93230  A9 2C         		lda	#badlst
2135
 4550  F93232  4C FB 56      		jmp	doserr
2136
 4551
2137
 4552                        	;---------------------------------------------------------------------------
2138
 4553                        	; load directory subcommand
2139
 4554                        	;---------------------------------------------------------------------------
2140
 4555                        	; start directory loading function
2141
 4556  F93235                	loaddir:
2142
 4557  F93235  20 97 4B      		jsr	optsch		; init drive
2143
 4558  F93238  20 BB 47      		jsr	getrfd		; get a free fd
2144
 4559  F9323B  A6 52         		ldx	chnl
2145
 4560  F9323D  B5 59         		lda	lintab,x
2146
 4561  F9323F  09 20         		ora	#$20		; flag dir. listing
2147
 4562  F93241  95 59         		sta	lintab,x
2148
 4563  F93243  20 2D 4A      		jsr	blknb		; clear name buffer
2149
 4564  F93246  20 3D 56      		jsr	sethdp		; set dir header pointer
2150
 4565  F93249  20 15 49      		jsr	setfdp		; set buffer pointer
2151
 4566  F9324C  A9 04         		lda	#4		; set ptr to start of disk name
2152
 4567  F9324E  85 0A         		sta	dirp
2153
 4568  F93250  A0 16         		ldy	#22		; offset 26 - copy all till start of name
2154
 4569  F93252  B7 0A         	?02:	lda	[dirp],y
2155
 4570  F93254  C9 A0         		cmp	#$A0
2156
 4571  F93256  D0 02         		bne	?04
2157
 4572  F93258  A9 20         		lda	#' '
2158
 4573  F9325A  99 C4 E1      	?04:	sta	nambuf+2,y
2159
 4574  F9325D  88            		dey
2160
 4575  F9325E  10 F2         		bpl	?02
2161
 4576  F93260  A9 14         		lda	#SCN_RVSON
2162
 4577  F93262  8D C2 E1      		sta	!nambuf
2163
 4578  F93265  A9 22         		lda	#'"'		; send name in quotes
2164
 4579  F93267  8D C3 E1      		sta	!nambuf+1
2165
 4580  F9326A  8D D4 E1      		sta	!nambuf+18
2166
 4581  F9326D  A9 20         		lda	#$20
2167
 4582  F9326F  8D D5 E1      		sta	!nambuf+19
2168
 4583  F93272  A0 00         		ldy	#0		; start to fill buffer
2169
 4584  F93274  A9 01         		lda	#1		; put sal in buffer
2170
 4585  F93276  AA            		tax
2171
  Tue Jul 17 11:00:19 2018                                                                                               Page   36
2172
 
2173
 
2174
 
2175
 
2176
 4586  F93277  97 8A         		sta	[bufp],y
2177
 4587  F93279  C8            		iny
2178
 4588  F9327A  A9 04         		lda	#4		; put sah in buffer
2179
 4589  F9327C  97 8A         		sta	[bufp],y
2180
 4590  F9327E  C8            		iny
2181
 4591  F9327F  8A            		txa			; insert fhoney links (0101)
2182
 4592  F93280  97 8A         		sta	[bufp],y
2183
 4593  F93282  C8            		iny
2184
 4594  F93283  97 8A         		sta	[bufp],y
2185
 4595  F93285  C8            		iny
2186
 4596  F93286  A5 19         		lda	drvnum		; put in drive #
2187
 4597  F93288  97 8A         		sta	[bufp],y
2188
 4598  F9328A  C8            		iny
2189
 4599  F9328B  A9 00         		lda	#0
2190
 4600  F9328D  97 8A         		sta	[bufp],y
2191
 4601  F9328F  C8            		iny
2192
 4602  F93290  20 1F 4A      		jsr	movbuf		; get disk name (27 bytes)
2193
 4603  F93293  88            		dey			; adjust (-2 bytes)...
2194
 4604  F93294  88            		dey			; ...to have 32 bytes with terminator
2195
 4605  F93295  A9 00         		lda	#0		; terminator: end of this line
2196
 4606  F93297  97 8A         		sta	[bufp],y
2197
 4607  F93299  C8            		iny			; here will be 32
2198
 4608  F9329A  5A            		phy
2199
 4609  F9329B  20 70 4A      		jsr	ffst		; start find dir entry
2200
 4610  F9329E  7A            		ply
2201
 4611  F9329F  64 EA         		stz	rdlst
2202
 4612  F932A1  64 EB         		stz	rdeof
2203
 4613  F932A3  64 E9         		stz	rdidx
2204
 4614  F932A5  20 28 49      		jsr	dlist		; fill buffer with first block
2205
 4615  F932A8  4C 06 47      		jmp	savzp		; save zp var's after starting dir search
2206
 4616
2207
 4617                        	;---------------------------------------------------------------------------
2208
 4618                        	; open directory as seq. file subcommand
2209
 4619                        	;---------------------------------------------------------------------------
2210
 4620  F932AB                	opndir:
2211
 4621  F932AB  20 97 4B      		jsr	optsch		; init drive
2212
 4622  F932AE  20 BB 47      		jsr	getrfd		; get free fd
2213
 4623  F932B1  A6 57         		ldx	lindx		; X=fd
2214
 4624  F932B3  A9 28         		lda	#dirtrk		; open directory
2215
 4625  F932B5  95 AE         		sta	ftrk,x
2216
 4626  F932B7  74 B6         		stz	fsec,x
2217
 4627  F932B9  A9 02         		lda	#2
2218
 4628  F932BB  95 BE         		sta	fdptr,x		; start of buffer
2219
 4629  F932BD  60            		rts
2220
 4630
2221
 4631                        	;---------------------------------------------------------------------------
2222
 4632                        	; open direct access subcommand
2223
 4633                        	;---------------------------------------------------------------------------
2224
 4634  F932BE                	opnblk:
2225
 4635  F932BE  20 BB 47      		jsr	getrfd		; get free fd
2226
 4636  F932C1  A6 52         		ldx	chnl
2227
 4637  F932C3  B5 59         		lda	lintab,x
2228
 4638  F932C5  09 40         		ora	#$40		; direct access flag
2229
 4639  F932C7  95 59         		sta	lintab,x
2230
 4640  F932C9  60            		rts
2231
 4641
2232
 4642                        	;---------------------------------------------------------------------------
2233
  Tue Jul 17 11:00:19 2018                                                                                               Page   37
2234
 
2235
 
2236
 
2237
 
2238
 4643                        	; scratch command
2239
 4644                        	;---------------------------------------------------------------------------
2240
 4645  F932CA                	scratch:
2241
 4646  F932CA  20 B1 42      		jsr	fs1set		; set type filter if any
2242
 4647  F932CD  20 8D 41      		jsr	alldrs		; set all drives/file ptr's
2243
 4648  F932D0  20 AC 3F      		jsr	buildfn		; build canonical file names
2244
 4649  F932D3  20 97 4B      		jsr	optsch		; init all drive's
2245
 4650  F932D6  64 42         		stz	char		; use as counter
2246
 4651  F932D8  20 70 4A      		jsr	ffst		; start search
2247
 4652  F932DB  30 4A         		bmi	?30		; no match files
2248
 4653  F932DD  64 43         	?15:	stz	image		; flag
2249
 4654  F932DF  20 37 48      		jsr	tstfd		; is an open file?
2250
 4655  F932E2  90 1E         		bcc	?20		; yes - don't scratch
2251
 4656  F932E4  A6 19         		ldx	drvnum
2252
 4657  F932E6  A9 10         		lda	#$10
2253
 4658  F932E8  34 68         		bit	drvfg,x
2254
 4659  F932EA  D0 16         		bne	?20		; disk write protect on - skip
2255
 4660  F932EC  A7 0A         		lda	[dirp]		; type & flags
2256
 4661  F932EE  10 12         		bpl	?20		; not properly closed - skip splat file
2257
 4662  F932F0  89 40         		bit	#$40
2258
 4663  F932F2  D0 0E         		bne	?20		; skip locked file
2259
 4664  F932F4  29 07         		and	#typmsk		; mask type
2260
 4665  F932F6  C9 04         		cmp	#reltyp
2261
 4666  F932F8  F0 08         		beq	?20		; skip rel files
2262
 4667  F932FA  C9 05         		cmp	#partyp
2263
 4668  F932FC  F0 04         		beq	?20		; skip part type
2264
 4669  F932FE  A9 80         		lda	#$80		; candidate to be deleted
2265
 4670  F93300  85 43         		sta	image
2266
 4671  F93302  20 5F 33      	?20:	jsr	shownam		; show file name
2267
 4672  F93305  24 43         		bit	image
2268
 4673  F93307  10 16         		bpl	?25
2269
 4674  F93309  A9 00         		lda	#0
2270
 4675  F9330B  87 0A         		sta	[dirp]		; delete entry
2271
 4676  F9330D  20 57 36      		jsr	wrdsec		; update dir on disk
2272
 4677  F93310  A6 16         		ldx	entfnd
2273
 4678  F93312  B5 20         		lda	filtrk,x	; get first t&s of file
2274
 4679  F93314  85 08         		sta	track
2275
 4680  F93316  B5 25         		lda	filsec,x
2276
 4681  F93318  85 09         		sta	sector
2277
 4682  F9331A  20 38 33      		jsr	delfil		; delete file by links
2278
 4683  F9331D  E6 42         		inc	char		; update counter of scratched files
2279
 4684  F9331F  20 2C 3B      	?25:	jsr	donemsg
2280
 4685  F93322  20 66 4A      		jsr	ffre		; search next matching file
2281
 4686  F93325  10 B6         		bpl	?15		; more files
2282
 4687  F93327  A6 42         	?30:	ldx	char
2283
 4688  F93329  8E FA E1      		stx	etrk		; report scratched file's #
2284
 4689  F9332C  9C FB E1      		stz	esec
2285
 4690  F9332F  A9 01         		lda	#1
2286
 4691  F93331  85 56         		sta	lsterr		; not a true error
2287
 4692  F93333  64 68         		stz	drvfg		; invalidate all drive's
2288
 4693  F93335  64 69         		stz	drvfg+1
2289
 4694  F93337  60            		rts
2290
 4695
2291
 4696                        	; delete file by link
2292
 4697                        	; track & sector first t&s of the file
2293
 4698  F93338                	delfil:
2294
 4699  F93338  20 AB 57      		jsr	tread		; read whole track in cache
2295
  Tue Jul 17 11:00:19 2018                                                                                               Page   38
2296
 
2297
 
2298
 
2299
 
2300
 4700  F9333B  20 4A 56      		jsr	setcp		; set cache ptr to right sector
2301
 4701  F9333E  20 CD 4D      	?02:	jsr	frets		; free current t&s in bam
2302
 4702  F93341  A0 01         		ldy	#1
2303
 4703  F93343  B7 8A         		lda	[bufp],y	; next sector
2304
 4704  F93345  A8            		tay
2305
 4705  F93346  A7 8A         		lda	[bufp]		; next track
2306
 4706  F93348  F0 12         		beq	?10		; end of file
2307
 4707  F9334A  84 09         		sty	sector		; next sector
2308
 4708  F9334C  C5 08         		cmp	track		; same track?
2309
 4709  F9334E  85 08         		sta	track
2310
 4710  F93350  D0 E6         		bne	delfil		; will read a new track
2311
 4711  F93352  18            		clc
2312
 4712  F93353  98            		tya
2313
 4713  F93354  A6 19         		ldx	drvnum
2314
 4714  F93356  75 78         		adc	trkofs,x	; sector in the same track
2315
 4715  F93358  85 8B         		sta	bufp+1
2316
 4716  F9335A  80 E2         		bra	?02		; follow link
2317
 4717  F9335C  4C 10 4E      	?10:	jmp	mapout		; update & write out bam
2318
 4718
2319
 4719  F9335F                	shownam:
2320
 4720  F9335F  20 B0 33      		jsr	movnam
2321
 4721  F93362  D4 94         		pei	(wtmp)
2322
 4722  F93364  A9 00         		lda	#^nambuf
2323
 4723  F93366  48            		pha
2324
 4724  F93367  F4 C2 E1      		pea	#!nambuf
2325
 4725  F9336A  A5 19         		lda	drvnum
2326
 4726  F9336C  48            		pha
2327
 4727  F9336D  4B            		phk
2328
 4728  F9336E  F4 77 33      		pea	#!?100
2329
 4729  F93371  A9 0A         		lda	#10
2330
 4730  F93373  48            		pha
2331
 4731  F93374                		BPRINTF
2332
 4732  F93374  02 11         		cop	$11
2333
 4733                        		.MNLIST
2334
 4734  F93376  60            		rts
2335
 4735
2336
 4736  F93377  0D 64 65 6C 65 	?100:	.DB	$0D, 'delete #%bu:%s (%04hu blocks):...', $00
2337
               74 65 20 23 25
2338
               62 75 3A 25 73
2339
               20 28 25 30 34
2340
               68 75 20 62 6C
2341
               6F 63 6B 73 29
2342
               3A 2E 2E 2E 00
2343
 4737
2344
 4738                        	; move directory entry to namebuf
2345
 4739                        	; in:	X=index in file stream
2346
 4740  F9339A                	movnamx:
2347
 4741  F9339A  B5 34         		lda	fildrv,x	; set directory entry
2348
 4742  F9339C  29 01         		and	#1
2349
 4743  F9339E  85 19         		sta	drvnum
2350
 4744  F933A0  DA            		phx
2351
 4745  F933A1  20 3D 56      		jsr	sethdp
2352
 4746  F933A4  FA            		plx
2353
 4747  F933A5  B5 2A         		lda	entsec,x
2354
 4748  F933A7  18            		clc
2355
 4749  F933A8  65 0B         		adc	dirp+1
2356
 4750  F933AA  85 0B         		sta	dirp+1		; set dir. pointer to file entry
2357
  Tue Jul 17 11:00:19 2018                                                                                               Page   39
2358
 
2359
 
2360
 
2361
 
2362
 4751  F933AC  B5 2F         		lda	entind,x
2363
 4752  F933AE  85 0A         		sta	dirp
2364
 4753
2365
 4754                        	; move directory entry to namebuf
2366
 4755  F933B0                	movnam:
2367
 4756  F933B0  20 2D 4A      		jsr	blknb		; blank nambuf
2368
 4757  F933B3  A0 1D         		ldy	#29		;  & adjust spacing
2369
 4758  F933B5  B7 0A         		lda	[dirp],y	; hi blocks #
2370
 4759  F933B7  85 95         		sta	wtmp+1
2371
 4760  F933B9  88            		dey
2372
 4761  F933BA  B7 0A         		lda	[dirp],y	; low blocks #
2373
 4762  F933BC  85 94         		sta	wtmp
2374
 4763  F933BE  A2 00         		ldx	#0		; file name start
2375
 4764  F933C0  A9 22         		lda	#'"'
2376
 4765  F933C2  8D C2 E1      		sta	!nambuf
2377
 4766  F933C5  A0 03         		ldy	#3
2378
 4767  F933C7  B7 0A         	?04:	lda	[dirp],y
2379
 4768  F933C9  29 7F         		and	#$7F
2380
 4769  F933CB  9D C3 E1      		sta	!nambuf+1,x
2381
 4770  F933CE  E8            		inx
2382
 4771  F933CF  C8            		iny
2383
 4772  F933D0  E0 10         		cpx	#16
2384
 4773  F933D2  90 F3         		bcc	?04
2385
 4774  F933D4  A9 22         		lda	#'"'
2386
 4775  F933D6  9D C3 E1      		sta	!nambuf+1,x
2387
 4776  F933D9  E8            		inx
2388
 4777  F933DA  E8            		inx
2389
 4778  F933DB  A7 0A         		lda	[dirp]		; set type chars
2390
 4779  F933DD  30 07         		bmi	?06
2391
 4780  F933DF  A8            		tay
2392
 4781  F933E0  A9 2A         		lda	#'*'		; file not closed: splat file
2393
 4782  F933E2  9D C3 E1      		sta	!nambuf+1,x
2394
 4783  F933E5  98            		tya
2395
 4784  F933E6  E8            	?06:	inx
2396
 4785  F933E7  9B            		txy			; Y = nambuf index
2397
 4786  F933E8  48            		pha
2398
 4787  F933E9  29 07         		and	#typmsk
2399
 4788  F933EB  AA            		tax			; X = file type
2400
 4789  F933EC  BF 84 5A F9   		lda	>typlst,x
2401
 4790  F933F0  99 C3 E1      		sta	nambuf+1,y
2402
 4791  F933F3  C8            		iny
2403
 4792  F933F4  BF 8A 5A F9   		lda	>tp1lst,x
2404
 4793  F933F8  99 C3 E1      		sta	nambuf+1,y
2405
 4794  F933FB  C8            		iny
2406
 4795  F933FC  BF 90 5A F9   		lda	>tp2lst,x
2407
 4796  F93400  99 C3 E1      		sta	nambuf+1,y
2408
 4797  F93403  C8            		iny
2409
 4798  F93404  BB            		tyx
2410
 4799  F93405  68            		pla
2411
 4800  F93406  0A            		asl	a
2412
 4801  F93407  10 05         		bpl	?08		; file not locked
2413
 4802  F93409  A9 3C         		lda	#'<'
2414
 4803  F9340B  9D C3 E1      		sta	!nambuf+1,x	; file locked
2415
 4804  F9340E  E8            	?08:	inx
2416
 4805  F9340F  9E C3 E1      		stz	nambuf+1,x
2417
 4806  F93412  60            		rts
2418
 4807
2419
  Tue Jul 17 11:00:19 2018                                                                                               Page   40
2420
 
2421
 
2422
 
2423
 
2424
 4808                        	;---------------------------------------------------------------------------
2425
 4809                        	; new disk command (format)
2426
 4810                        	;---------------------------------------------------------------------------
2427
 4811
2428
 4812                        	; quick format command
2429
 4813  F93413                	quickf:
2430
 4814  F93413  20 83 41      		jsr	onedrv		; set just one drive/file ptr
2431
 4815  F93416  20 AC 3F      		jsr	buildfn		; build canonical file names
2432
 4816  F93419  A9 C0         		lda	#$C0
2433
 4817  F9341B  80 08         		bra	newdsk2
2434
 4818  F9341D
2435
 4819                        	; standard cbm format command
2436
 4820  F9341D                	newdsk:
2437
 4821  F9341D  20 83 41      		jsr	onedrv		; set just one drive/file ptr
2438
 4822  F93420  20 AC 3F      		jsr	buildfn		; build canonical file names
2439
 4823  F93423  A9 80         		lda	#$80
2440
 4824  F93425                	newdsk2:
2441
 4825  F93425  85 41         		sta	<qfmt		; assume no ID disk given => quick format
2442
 4826  F93427  A5 12         		lda	f1cnt		; saved total count
2443
 4827  F93429  C9 01         		cmp	#1
2444
 4828  F9342B  F0 29         		beq	?06		; just disk name: quick format
2445
 4829  F9342D  C9 02         		cmp	#2
2446
 4830  F9342F  F0 03         		beq	?04		; given disk ID in filtab
2447
 4831  F93431  4C 05 41      	?02:	jmp	e_badsyn	; error if more data
2448
 4832  F93434  A6 1B         	?04:	ldx	filtbl+1	; pointer to ID string
2449
 4833  F93436  20 55 40      		jsr	fndlmt		; find string limit
2450
 4834  F93439  98            		tya			; string size
2451
 4835  F9343A  F0 F5         		beq	?02		; empty string
2452
 4836  F9343C  C9 03         		cmp	#3
2453
 4837  F9343E  B0 F1         		bcs	?02		; more than 2 char's
2454
 4838  F93440  A6 1B         		ldx	filtbl+1
2455
 4839  F93442  BD 00 E1      		lda	!cmdbuf,x
2456
 4840  F93445  20 9F 35      		jsr	?50		; check ID char: just alphanumeric
2457
 4841  F93448  85 42         		sta	<idch1
2458
 4842  F9344A  BD 01 E1      		lda	!cmdbuf+1,x
2459
 4843  F9344D  20 9F 35      		jsr	?50
2460
 4844  F93450  85 43         		sta	<idch2
2461
 4845  F93452  A9 80         		lda	#$80
2462
 4846  F93454  14 41         		trb	<qfmt		; clear bit 7: given ID in cmd string
2463
 4847  F93456  A5 34         	?06:	lda	fildrv
2464
 4848  F93458  29 01         		and	#1
2465
 4849  F9345A  85 19         		sta	drvnum
2466
 4850  F9345C  AA            		tax
2467
 4851  F9345D  74 68         		stz	drvfg,x		; invalid drive
2468
 4852  F9345F  20 B4 56      		jsr	dsktst		; check if disk is ready
2469
 4853  F93462  A9 10         		lda	#$10
2470
 4854  F93464  34 68         		bit	drvfg,x		; disk write protect on?
2471
 4855  F93466  F0 05         		beq	?07		; no
2472
 4856  F93468  A9 1A         		lda	#wpon
2473
 4857  F9346A  4C 07 41      		jmp	cmderr
2474
 4858  F9346D                	?07:	FDCGETFMT		; query disk format
2475
 4859  F9346D  02 30         		cop	$30
2476
 4860  F9346F  04            		.DB	$04
2477
 4861                        		.MNLIST
2478
 4862  F93470  B0 17         		bcs	?08		; unformatted or not recognized format
2479
 4863  F93472  98            		tya			; format in bit 1,0
2480
 4864  F93473  C9 01         		cmp	#1
2481
  Tue Jul 17 11:00:19 2018                                                                                               Page   41
2482
 
2483
 
2484
 
2485
 
2486
 4865  F93475  D0 12         		bne	?08		; not the right format
2487
 4866  F93477  20 8F 57      		jsr	sysrd		; try to read system track
2488
 4867  F9347A  B0 0D         		bcs	?08		; error reading system track
2489
 4868  F9347C  20 3E 55      		jsr	hdrtst		; test right dir. format
2490
 4869  F9347F  90 11         		bcc	?10		; ok, can be used quick format
2491
 4870  F93481  24 41         		bit	<qfmt
2492
 4871  F93483  30 08         		bmi	?09		; no ID given
2493
 4872  F93485  50 2B         		bvc	?20		; cbm standard: go to full format
2494
 4873  F93487  80 0F         		bra	?12		; quick format with given ID
2495
 4874  F93489  24 41         	?08:	bit	<qfmt		; here quick format not possible
2496
 4875  F9348B  10 25         		bpl	?20		; go to full format
2497
 4876  F9348D  A9 4D         	?09:	lda	#fmter		; not given disk ID
2498
 4877  F9348F  4C 07 41      		jmp	cmderr
2499
 4878  F93492  24 41         	?10:	bit	<qfmt
2500
 4879  F93494  30 2E         		bmi	?30		; no ID given so quick format
2501
 4880  F93496  50 0C         		bvc	?15		; standard cbm format: compare given ID
2502
 4881  F93498  A5 42         	?12:	lda	<idch1		; quick format with given ID
2503
 4882  F9349A  9D FC E1      		sta	!dskid1,x
2504
 4883  F9349D  A5 43         		lda	<idch2
2505
 4884  F9349F  9D FE E1      		sta	!dskid2,x
2506
 4885  F934A2  80 20         		bra	?30		; quick format
2507
 4886  F934A4  A5 42         	?15:	lda	<idch1		; now check given ID with disk ID
2508
 4887  F934A6  DD FC E1      		cmp	!dskid1,x
2509
 4888  F934A9  D0 07         		bne	?20		; unmatch: full format
2510
 4889  F934AB  A5 43         		lda	<idch2
2511
 4890  F934AD  DD FE E1      		cmp	!dskid2,x
2512
 4891  F934B0  F0 12         		beq	?30		; match: quick format
2513
 4892  F934B2  A5 42         	?20:	lda	<idch1		; full format: start low level format
2514
 4893  F934B4  9D FC E1      		sta	!dskid1,x	; store given disk ID
2515
 4894  F934B7  A5 43         		lda	<idch2
2516
 4895  F934B9  9D FE E1      		sta	!dskid2,x
2517
 4896  F934BC                		SCN_CR
2518
 4897  F934BC                		SCNPRCHAR
2519
 4898                        		.MLIST
2520
 4899  F934BC  02 07         		cop	$07
2521
 4900                        		.MNLIST
2522
 4901  F934BE  0D            		.DB	$0D
2523
 4902                        		.MNLIST
2524
 4903  F934BF  20 E1 58      		jsr	llfmt
2525
 4904                        		;SCN_CR
2526
 4905  F934C2  80 0C         		bra	?31		; make empty file system
2527
 4906  F934C4  A5 19         	?30:	lda	drvnum		; quick format
2528
 4907  F934C6  48            		pha
2529
 4908  F934C7  4B            		phk
2530
 4909  F934C8  F4 2E 35      		pea	#!?40
2531
 4910  F934CB  A9 05         		lda	#5
2532
 4911  F934CD  48            		pha
2533
 4912  F934CE                		BPRINTF
2534
 4913  F934CE  02 11         		cop	$11
2535
 4914                        		.MNLIST
2536
 4915  F934D0  20 3D 56      	?31:	jsr	sethdp		; make empty file system
2537
 4916  F934D3  20 B3 35      		jsr	?60		; clear cache
2538
 4917  F934D6  20 9C 4E      		jsr	newmap		; create a new bam
2539
 4918  F934D9  20 4C 4F      		jsr	newhdr		; create a new header
2540
 4919  F934DC  64 8D         		stz	bmpnt		; ptr to new bam
2541
 4920  F934DE  E6 0B         		inc	dirp+1		; set up bam
2542
 4921  F934E0                		INDEX16
2543
  Tue Jul 17 11:00:19 2018                                                                                               Page   42
2544
 
2545
 
2546
 
2547
 
2548
 4922  F934E0  C2 10         		rep	#PXFLAG
2549
 4923                        		.LONGI	on
2550
 4924                        		.MNLIST
2551
 4925  F934E2  A0 FF 01      		ldy	#$01FF		; transfer the new bam
2552
 4926  F934E5  B7 8D         	?32:	lda	[bmpnt],y
2553
 4927  F934E7  97 0A         		sta	[dirp],y
2554
 4928  F934E9  88            		dey
2555
 4929  F934EA  10 F9         		bpl	?32
2556
 4930  F934EC                		INDEX08
2557
 4931  F934EC  E2 10         		sep	#PXFLAG
2558
 4932                        		.LONGI	off
2559
 4933                        		.MNLIST
2560
 4934  F934EE  E6 0B         		inc	dirp+1		; set up first dir block
2561
 4935  F934F0  E6 0B         		inc	dirp+1
2562
 4936  F934F2  A9 00         		lda	#0
2563
 4937  F934F4  87 0A         		sta	[dirp]		; null link
2564
 4938  F934F6  A0 01         		ldy	#1
2565
 4939  F934F8  3A            		dec	a
2566
 4940  F934F9  97 0A         		sta	[dirp],y
2567
 4941  F934FB  A4 1A         		ldy	filtbl
2568
 4942  F934FD  B9 00 E1      	?34:	lda	cmdbuf,y
2569
 4943  F93500  F0 0A         		beq	?36
2570
 4944  F93502  30 03         		bmi	?35
2571
 4945  F93504  C8            		iny
2572
 4946  F93505  80 F6         		bra	?34
2573
 4947  F93507  A9 00         	?35:	lda	#0
2574
 4948  F93509  99 00 E1      		sta	cmdbuf,y
2575
 4949  F9350C  20 D7 57      	?36:	jsr	syswr		; write out system track
2576
 4950  F9350F  74 68         		stz	drvfg,x		; invalidate drive
2577
 4951  F93511  D4 94         		pei	(wtmp)
2578
 4952  F93513  BD FE E1      		lda	!dskid2,x
2579
 4953  F93516  48            		pha
2580
 4954  F93517  BD FC E1      		lda	!dskid1,x
2581
 4955  F9351A  48            		pha
2582
 4956  F9351B  A9 00         		lda	#^cmdbuf
2583
 4957  F9351D  48            		pha
2584
 4958  F9351E  A9 E1         		lda	#>cmdbuf
2585
 4959  F93520  48            		pha
2586
 4960  F93521  A5 1A         		lda	filtbl
2587
 4961  F93523  48            		pha
2588
 4962  F93524  4B            		phk
2589
 4963  F93525  F4 6A 35      		pea	#!?42
2590
 4964  F93528  A9 0B         		lda	#11
2591
 4965  F9352A  48            		pha
2592
 4966  F9352B                		BPRINTF
2593
 4967  F9352B  02 11         		cop	$11
2594
 4968                        		.MNLIST
2595
 4969  F9352D  60            		rts
2596
 4970
2597
 4971  F9352E  0D 51 75 69 63 	?40:	.DB	$0D, 'Quick format diskette on drive #%bu - cbm 1581 format type', 0
2598
               6B 20 66 6F 72
2599
               6D 61 74 20 64
2600
               69 73 6B 65 74
2601
               74 65 20 6F 6E
2602
               20 64 72 69 76
2603
               65 20 23 25 62
2604
               75 20 2D 20 63
2605
  Tue Jul 17 11:00:19 2018                                                                                               Page   43
2606
 
2607
 
2608
 
2609
 
2610
               62 6D 20 31 35
2611
               38 31 20 66 6F
2612
               72 6D 61 74 20
2613
               74 79 70 65 00
2614
 4972  F9356A  0D 44 69 73 6B 	?42:	.DB	$0D, 'Disk name: "%s", ID: "%c%c", total free blocks: %hu', 0
2615
               20 6E 61 6D 65
2616
               3A 20 22 25 73
2617
               22 2C 20 49 44
2618
               3A 20 22 25 63
2619
               25 63 22 2C 20
2620
               74 6F 74 61 6C
2621
               20 66 72 65 65
2622
               20 62 6C 6F 63
2623
               6B 73 3A 20 25
2624
               68 75 00
2625
 4973
2626
 4974  F9359F  C9 30         	?50:	cmp	#'0'		; check ID
2627
 4975  F935A1  90 0D         		bcc	?56
2628
 4976  F935A3  C9 3A         		cmp	#'9'+1
2629
 4977  F935A5  90 08         		bcc	?54
2630
 4978  F935A7  C9 41         		cmp	#'A'
2631
 4979  F935A9  90 05         		bcc	?56
2632
 4980  F935AB  C9 5B         		cmp	#'Z'+1
2633
 4981  F935AD  B0 01         		bcs	?56
2634
 4982  F935AF  60            	?54:	rts
2635
 4983  F935B0  4C 05 41      	?56:	jmp	e_badsyn	; ID error
2636
 4984
2637
 4985  F935B3                	?60:	CPU16			; clear system cache
2638
 4986  F935B3  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
2639
 4987                        		.LONGA	on
2640
 4988                        		.LONGI	on
2641
 4989                        		.MNLIST
2642
 4990  F935B5  A0 FE 13      		ldy	#$1400-2	; $1400 words
2643
 4991  F935B8  A9 00 00      		lda	#0
2644
 4992  F935BB  97 0A         	?62:	sta	[dirp],y
2645
 4993  F935BD  88            		dey
2646
 4994  F935BE  88            		dey
2647
 4995  F935BF  10 FA         		bpl	?62
2648
 4996  F935C1                		CPU08
2649
 4997  F935C1  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
2650
 4998                        		.LONGA	off
2651
 4999                        		.LONGI	off
2652
 5000                        		.MNLIST
2653
 5001  F935C3  60            		rts
2654
 5002
2655
 5003                        	;---------------------------------------------------------------------------
2656
 5004                        	; rename command
2657
 5005                        	;---------------------------------------------------------------------------
2658
 5006  F935C4                	rename:
2659
 5007  F935C4  20 8D 41      		jsr	alldrs		; set all drives/file ptr's
2660
 5008  F935C7  20 AC 3F      		jsr	buildfn		; build canonical file names
2661
 5009  F935CA  A5 35         		lda	fildrv+1
2662
 5010  F935CC  29 01         		and	#1
2663
 5011  F935CE  85 35         		sta	fildrv+1
2664
 5012  F935D0  45 34         		eor	fildrv		; compare drive's #
2665
 5013  F935D2  F0 05         		beq	?01		; ok, same drive
2666
 5014  F935D4  A9 27         		lda	#notsam
2667
  Tue Jul 17 11:00:19 2018                                                                                               Page   44
2668
 
2669
 
2670
 
2671
 
2672
 5015  F935D6  4C 07 41      		jmp	cmderr		; cannot rename across drives
2673
 5016  F935D9  20 38 4A      	?01:	jsr	lookup		; lookup for both file's
2674
 5017  F935DC  20 20 36      		jsr	chkfs1		; check fs1 and fs2
2675
 5018  F935DF  A2 01         		ldx	#1		; check file name 2 not open
2676
 5019  F935E1  20 28 48      		jsr	tstopn		; cannot rename an open file
2677
 5020  F935E4  A5 2B         		lda	entsec+1	; set sector of dir entry for file 2
2678
 5021  F935E6  85 09         		sta	sector
2679
 5022  F935E8  20 C3 4C      		jsr	setdptr		; set ptr to dir cache
2680
 5023  F935EB  A5 30         		lda	entind+1	; set pointer to entry
2681
 5024  F935ED  85 0A         		sta	dirp
2682
 5025  F935EF  A7 0A         		lda	[dirp]		; get type and flags
2683
 5026  F935F1  89 40         		bit	#$40
2684
 5027  F935F3  D0 0F         		bne	?04		; locked file
2685
 5028  F935F5  A6 1A         		ldx	filtbl		; pointer to file 1 name
2686
 5029  F935F7  A0 03         		ldy	#3		; pointer to file name on dir entry
2687
 5030  F935F9  BD 00 E1      	?02:	lda	!cmdbuf,x	; move new file name
2688
 5031  F935FC  F0 59         		beq	wrdsec		; end -- write out sector
2689
 5032  F935FE  97 0A         		sta	[dirp],y
2690
 5033  F93600  E8            		inx
2691
 5034  F93601  C8            		iny
2692
 5035  F93602  80 F5         		bra	?02
2693
 5036
2694
 5037  F93604  A9 28         	?04:	lda	#flock
2695
 5038  F93606  4C 07 41      		jmp	cmderr
2696
 5039  F93609
2697
 5040                        	; check file 2 stream for existence (all should exist)
2698
 5041  F93609                	chkfs2:
2699
 5042  F93609  A5 3A         		lda	pattyp+1	; 1st file bears type
2700
 5043  F9360B  29 07         		and	#typmsk
2701
 5044  F9360D  85 0E         		sta	type
2702
 5045  F9360F  A6 13         		ldx	f2cnt
2703
 5046  F93611  CA            	?10:	dex
2704
 5047  F93612  E4 12         		cpx	f1cnt
2705
 5048  F93614  90 09         		bcc	?20		; skip file in fs1 stream
2706
 5049  F93616  B5 20         		lda	filtrk,x
2707
 5050  F93618  D0 F7         		bne	?10		; ok, exist - check next
2708
 5051  F9361A  A9 3E         		lda	#flntfd		; input file not found
2709
 5052  F9361C  4C 07 41      		jmp	cmderr
2710
 5053  F9361F  60            	?20:	rts
2711
 5054
2712
 5055                        	; check file 1 stream for non-existence (all should not exist)
2713
 5056  F93620                	chkfs1:
2714
 5057  F93620  20 09 36      		jsr	chkfs2		; check fs 2 stream for existence
2715
 5058  F93623  B5 20         	?25:	lda	filtrk,x	; check fs1 stream
2716
 5059  F93625  F0 05         		beq	?30
2717
 5060  F93627  A9 3F         		lda	#flexst		; file exist
2718
 5061  F93629  4C 07 41      		jmp	cmderr
2719
 5062  F9362C  CA            	?30:	dex			; check next file
2720
 5063  F9362D  10 F4         		bpl	?25
2721
 5064  F9362F  60            		rts
2722
 5065
2723
 5066                        	;---------------------------------------------------------------------------
2724
 5067                        	; exist command - check file existance
2725
 5068                        	;---------------------------------------------------------------------------
2726
 5069  F93630                	exist:
2727
 5070  F93630  20 83 41      		jsr	onedrv		; set just one drive/file ptr
2728
 5071  F93633  20 AC 3F      		jsr	buildfn		; build canonical file names
2729
  Tue Jul 17 11:00:19 2018                                                                                               Page   45
2730
 
2731
 
2732
 
2733
 
2734
 5072  F93636  20 38 4A      		jsr	lookup		; lookup for file
2735
 5073  F93639  A5 20         		lda	filtrk
2736
 5074  F9363B  D0 2F         		bne	gtx		; ok
2737
 5075  F9363D  A9 3E         		lda	#flntfd
2738
 5076  F9363F  4C 07 41      		jmp	cmderr
2739
 5077
2740
 5078                        	;---------------------------------------------------------------------------
2741
 5079                        	; lock command - set lock bit in file type (set read only file)
2742
 5080                        	;---------------------------------------------------------------------------
2743
 5081  F93642                	lock:
2744
 5082  F93642  20 5C 36      		jsr	gettyp		; set dir entry ptr & get file type
2745
 5083  F93645  89 40         		bit	#$40		; test lock bit
2746
 5084  F93647  D0 23         		bne	gtx		; already locked, done
2747
 5085  F93649  A8            		tay			; save type
2748
 5086  F9364A  20 6D 36      		jsr	wptst		; check if write protect
2749
 5087  F9364D  A2 00         		ldx	#0		; check file not open
2750
 5088  F9364F  20 28 48      		jsr	tstopn		; cannot do in an open file
2751
 5089  F93652  98            		tya			; restore type
2752
 5090  F93653  09 40         		ora	#$40		; set lock bit
2753
 5091  F93655  87 0A         		sta	[dirp]
2754
 5092  F93657
2755
 5093                        		; write out sector
2756
 5094
2757
 5095                        	; write given directory sector on disk
2758
 5096  F93657                	wrdsec:
2759
 5097  F93657  A9 01         		lda	#1		; write out just 1 sec
2760
 5098  F93659  4C 11 58      		jmp	wrsys
2761
 5099
2762
 5100                        	; find file, set dir pointer, get file type & flag
2763
 5101  F9365C                	gettyp:
2764
 5102  F9365C  20 30 36      		jsr	exist		; file exist in dir entry?
2765
 5103  F9365F  A5 2A         		lda	entsec		; set sector of dir entry
2766
 5104  F93661  85 09         		sta	sector
2767
 5105  F93663  20 C3 4C      		jsr	setdptr		; set ptr to dir cache
2768
 5106  F93666  A5 2F         		lda	entind		; set pointer to entry
2769
 5107  F93668  85 0A         		sta	dirp
2770
 5108  F9366A  A7 0A         		lda	[dirp]		; get type and flags
2771
 5109  F9366C  60            	gtx:	rts
2772
 5110
2773
 5111                        	; abort if disk is write protect
2774
 5112  F9366D                	wptst:
2775
 5113  F9366D  A6 19         		ldx	drvnum
2776
 5114  F9366F  A9 10         		lda	#$10
2777
 5115  F93671  34 68         		bit	drvfg,x
2778
 5116  F93673  F0 F7         		beq	gtx		; ok, no write protect
2779
 5117  F93675  A9 1A         		lda	#wpon		; write protect on
2780
 5118  F93677  4C F5 56      		jmp	drverr
2781
 5119
2782
 5120                        	;---------------------------------------------------------------------------
2783
 5121                        	; unlock command - clear lock bit in file type
2784
 5122                        	;---------------------------------------------------------------------------
2785
 5123  F9367A                	unlock:
2786
 5124  F9367A  20 5C 36      		jsr	gettyp		; set dir entry ptr & get file type
2787
 5125  F9367D  89 40         		bit	#$40		; test lock bit
2788
 5126  F9367F  F0 EB         		beq	gtx		; already unlocked, done
2789
 5127  F93681  A8            		tay			; save type
2790
 5128  F93682  20 6D 36      		jsr	wptst		; check if write protect
2791
  Tue Jul 17 11:00:19 2018                                                                                               Page   46
2792
 
2793
 
2794
 
2795
 
2796
 5129  F93685  A2 00         		ldx	#0		; check file not open
2797
 5130  F93687  20 28 48      		jsr	tstopn		; cannot do in an open file
2798
 5131  F9368A  98            		tya			; restore type
2799
 5132  F9368B  29 BF         		and	#$BF		; reset lock bit
2800
 5133  F9368D  87 0A         		sta	[dirp]
2801
 5134  F9368F  80 C6         		bra	wrdsec		; write out sector
2802
 5135
2803
 5136                        	;---------------------------------------------------------------------------
2804
 5137                        	; transfer command (copy file from ibm-dos disk)
2805
 5138                        	;---------------------------------------------------------------------------
2806
 5139  F93691                	transf:
2807
 5140  F93691  A9 40         		lda	#$40
2808
 5141  F93693  85 35         		sta	fildrv+1	; source drive is dos drive !
2809
 5142  F93695  20 8D 41      		jsr	alldrs
2810
 5143  F93698  A5 35         		lda	fildrv+1	; dos drive will be in command string
2811
 5144  F9369A  30 06         		bmi	?02		; no drive in cmd string
2812
 5145  F9369C  29 07         		and	#7
2813
 5146  F9369E  C5 34         		cmp	fildrv		; will be not the same
2814
 5147  F936A0  D0 03         		bne	?04		; ok
2815
 5148  F936A2  4C 89 3D      	?02:	jmp	e_baddrv
2816
 5149  F936A5  20 AC 3F      	?04:	jsr	buildfn		; build canonical file names
2817
 5150  F936A8  A9 40         		lda	#$40
2818
 5151  F936AA  14 35         		trb	fildrv+1
2819
 5152  F936AC  60            		rts
2820
 5153
2821
 5154                        	;---------------------------------------------------------------------------
2822
 5155                        	; move command (copy file to ibm-dos disk)
2823
 5156                        	;---------------------------------------------------------------------------
2824
 5157  F936AD                	move:
2825
 5158  F936AD  A9 40         		lda	#$40
2826
 5159  F936AF  85 34         		sta	fildrv		; dest drive is dos drive !
2827
 5160  F936B1  20 8D 41      		jsr	alldrs
2828
 5161  F936B4  A5 35         		lda	fildrv+1	; cbm drive will be in command string
2829
 5162  F936B6  30 08         		bmi	?02		; no drive in cmd string
2830
 5163  F936B8  A5 34         		lda	fildrv
2831
 5164  F936BA  29 07         		and	#7
2832
 5165  F936BC  C5 35         		cmp	fildrv+1	; will not be the same
2833
 5166  F936BE  D0 03         		bne	?04		; ok
2834
 5167  F936C0  4C 89 3D      	?02:	jmp	e_baddrv
2835
 5168  F936C3  20 AC 3F      	?04:	jsr	buildfn		; build canonical file names
2836
 5169  F936C6  A9 40         		lda	#$40
2837
 5170  F936C8  14 34         		trb	fildrv
2838
 5171  F936CA  60            		rts
2839
 5172
2840
 5173                        	;---------------------------------------------------------------------------
2841
 5174                        	; append command
2842
 5175                        	;---------------------------------------------------------------------------
2843
 5176  F936CB                	append:
2844
 5177  F936CB  20 8D 41      		jsr	alldrs		; set all drives/file ptr's
2845
 5178  F936CE  20 AC 3F      		jsr	buildfn		; build canonical file names
2846
 5179  F936D1  A9 40         		lda	 #$40
2847
 5180  F936D3  85 55         		sta	subcmd		; flag concat
2848
 5181  F936D5  20 38 4A      		jsr	lookup		; look up all files
2849
 5182  F936D8  A6 34         		ldx	fildrv		; test if dest drive is wp on
2850
 5183  F936DA  A9 10         		lda	#$10
2851
 5184  F936DC  34 68         		bit	drvfg,x
2852
 5185  F936DE  F0 05         		beq	?04
2853
  Tue Jul 17 11:00:19 2018                                                                                               Page   47
2854
 
2855
 
2856
 
2857
 
2858
 5186  F936E0  A9 1A         		lda	#wpon
2859
 5187  F936E2  4C 07 41      		jmp	cmderr
2860
 5188  F936E5  A5 20         	?04:	lda	filtrk
2861
 5189  F936E7  D0 05         		bne	?06		; ok, dest file exist
2862
 5190  F936E9  A9 3E         		lda	#flntfd
2863
 5191  F936EB  4C 07 41      		jmp	cmderr
2864
 5192  F936EE  A2 00         	?06:	ldx	#0		; dest file will not be open
2865
 5193  F936F0  20 28 48      		jsr	tstopn
2866
 5194  F936F3  A2 01         		ldx	#1
2867
 5195  F936F5  20 FE 37      		jsr	tstdup		; check recursive concat
2868
 5196  F936F8  20 09 36      		jsr	chkfs2		; check if fs2 exist
2869
 5197  F936FB  20 ED 37      		jsr	tstfs2		; check not open
2870
 5198  F936FE  A6 13         		ldx	f2cnt		; fs1 & fs2 seq type only
2871
 5199  F93700  CA            	?08:	dex			; index
2872
 5200  F93701  30 18         		bmi	?14
2873
 5201  F93703  B5 39         		lda	pattyp,x
2874
 5202  F93705  89 20         		bit	#$20
2875
 5203  F93707  D0 0D         		bne	?12		; error: splat file
2876
 5204  F93709  29 07         		and	#typmsk
2877
 5205  F9370B  C9 01         		cmp	#seqtyp
2878
 5206  F9370D  D0 02         		bne	?10		; error: mismatch type
2879
 5207  F9370F  80 EF         		bra	?08
2880
 5208  F93711  A9 40         	?10:	lda	#mistyp		; file type mismatch
2881
 5209  F93713  4C 07 41      		jmp	cmderr
2882
 5210  F93716  A9 29         	?12:	lda	#fsplt		; error: write file not closed
2883
 5211  F93718  4C 07 41      		jmp	cmderr
2884
 5212  F9371B  A5 39         	?14:	lda	pattyp		; dest file is locked?
2885
 5213  F9371D  89 40         		bit	#$40
2886
 5214  F9371F  F0 05         		beq	?16		; no
2887
 5215  F93721  A9 28         		lda	#flock		; error: locked file
2888
 5216  F93723  4C 07 41      		jmp	cmderr
2889
 5217  F93726  29 07         	?16:	and	#typmsk
2890
 5218  F93728  85 0E         		sta	type
2891
 5219  F9372A  20 1D 38      		jsr	movdst		; set up dest file name
2892
 5220  F9372D  20 EE 39      		jsr	skend		; seek end: prepare for append
2893
 5221  F93730  A2 01         		ldx	#1
2894
 5222  F93732  20 3A 39      		jsr	cat		; concat fs2 to fs1
2895
 5223  F93735  A6 34         		ldx	fildrv		; invalidate dest drive...
2896
 5224  F93737  74 68         		stz	drvfg,x		; ...so force init next time
2897
 5225  F93739  60            		rts
2898
 5226
2899
 5227                        	;---------------------------------------------------------------------------
2900
 5228                        	; copy command
2901
 5229                        	;
2902
 5230                        	;	Cddr=sdr		; copy all files from sdr to ddr (not same dr)
2903
 5231                        	;	Cddr:[*]=sdr:[*]	; copy all files from sdr to ddr (not same dr)
2904
 5232                        	;	Cddr:[*]=sdr:fname	; copy sdr:fname to ddr:fname (not same drive)
2905
 5233                        	;	Cddr:dest=[sdr:]fname	; copy sdr:fname to ddr:dest
2906
 5234                        	;	Cddr:dest=[sdr1:]fname1,[sdr2:]fname2,[sdr3:]fname3,[sdr4:]fname4
2907
 5235                        	;---------------------------------------------------------------------------
2908
 5236  F9373A                	copy:
2909
 5237  F9373A  20 6E 40      		jsr	prscpy		; parse cmd string
2910
 5238  F9373D  20 AC 3F      		jsr	buildfn		; build canonical file names
2911
 5239  F93740  24 39         		bit	pattyp		; dest file is '*' ?
2912
 5240  F93742  10 03         		bpl	?02
2913
 5241  F93744  4C 3D 38      		jmp	cpall		; yes - copy disk-to-disk
2914
 5242  F93747  64 55         	?02:	stz	subcmd		; flag copy+cat
2915
  Tue Jul 17 11:00:19 2018                                                                                               Page   48
2916
 
2917
 
2918
 
2919
 
2920
 5243  F93749  20 38 4A      		jsr	lookup		; look up all files
2921
 5244  F9374C  A6 34         		ldx	fildrv		; test if dest drive is wp on
2922
 5245  F9374E  A9 10         		lda	#$10
2923
 5246  F93750  34 68         		bit	drvfg,x
2924
 5247  F93752  F0 05         		beq	?04
2925
 5248  F93754  A9 1A         		lda	#wpon
2926
 5249  F93756  4C 07 41      		jmp	cmderr
2927
 5250  F93759  A5 13         	?04:	lda	f2cnt
2928
 5251  F9375B  C9 03         		cmp	#3		; just copy f2 to f1?
2929
 5252  F9375D  90 4B         		bcc	?20		; yes
2930
 5253  F9375F  A5 35         		lda	fildrv+1	; now test if first file of fs2 stream...
2931
 5254  F93761  29 01         		and	#1
2932
 5255  F93763  C5 34         		cmp	fildrv		; ...is the same of the file on fs1 stream
2933
 5256  F93765  D0 43         		bne	?20		; must create dest file
2934
 5257  F93767  A5 2F         		lda	entind
2935
 5258  F93769  C5 30         		cmp	entind+1
2936
 5259  F9376B  D0 3D         		bne	?20		; must create dest file
2937
 5260  F9376D  A5 2A         		lda	entsec
2938
 5261  F9376F  C5 2B         		cmp	entsec+1
2939
 5262  F93771  D0 37         		bne	?20		; must create dest file
2940
 5263
2941
 5264                        		; file1=file2 so append file3,file4... to file1
2942
 5265                        		; all files in fs2 stream will exist and will not be open
2943
 5266  F93773  A2 02         		ldx	#2
2944
 5267  F93775  20 FE 37      		jsr	tstdup		; check recursive concat
2945
 5268  F93778  20 09 36      		jsr	chkfs2		; check if fs2 exist
2946
 5269  F9377B  20 ED 37      		jsr	tstfs2		; check not open
2947
 5270  F9377E  A5 0E         		lda	type		; this is file1=file2 type
2948
 5271  F93780  C9 01         		cmp	#seqtyp		; just seq. tipe can be concat.
2949
 5272  F93782  F0 05         		beq	?06
2950
 5273  F93784  A9 40         	?05:	lda	#mistyp		; file type mismatch
2951
 5274  F93786  4C 07 41      		jmp	cmderr
2952
 5275  F93789  20 1D 38      	?06:	jsr	movdst		; set up dest file name
2953
 5276  F9378C  A5 39         		lda	pattyp		; dest file is locked?
2954
 5277  F9378E  89 40         		bit	#$40
2955
 5278  F93790  F0 05         		beq	?08		; no
2956
 5279  F93792  A9 28         		lda	#flock		; error: locked file
2957
 5280  F93794  4C 07 41      		jmp	cmderr
2958
 5281  F93797  89 20         	?08:	bit	#$20		; splat file?
2959
 5282  F93799  F0 05         		beq	?10		; no
2960
 5283  F9379B  A9 29         	?09:	lda	#fsplt		; error: write file not closed
2961
 5284  F9379D  4C 07 41      		jmp	cmderr
2962
 5285  F937A0  20 D3 37      	?10:	jsr	?70		; check all files f3..fn (seq type, no splat)
2963
 5286  F937A3  20 EE 39      		jsr	skend		; seek end: prepare for append
2964
 5287  F937A6  A2 02         		ldx	#2
2965
 5288  F937A8  80 21         		bra	?24
2966
 5289
2967
 5290                        	?20:	; file1 should be created, then copy file2 to file1 and concat...
2968
 5291                        		; ...file3,file4... to file1 (if type is seq)
2969
 5292  F937AA  20 20 36      		jsr	chkfs1		; fs1 should not exist, fs2 all should exist
2970
 5293  F937AD  20 ED 37      		jsr	tstfs2		; check fs2 not open
2971
 5294  F937B0  20 1D 38      		jsr	movdst		; set up dest file name
2972
 5295  F937B3  A5 3A         		lda	pattyp+1
2973
 5296  F937B5  89 20         		bit	#$20		; file1 will not be splat
2974
 5297  F937B7  D0 E2         		bne	?09		; error: source file is splat file
2975
 5298  F937B9  29 07         		and	#typmsk
2976
 5299  F937BB  C9 04         		cmp	#reltyp
2977
  Tue Jul 17 11:00:19 2018                                                                                               Page   49
2978
 
2979
 
2980
 
2981
 
2982
 5300  F937BD  F0 C5         		beq	?05		; skip rel files
2983
 5301  F937BF  C9 05         		cmp	#partyp
2984
 5302  F937C1  F0 C1         		beq	?05		; skip part type
2985
 5303  F937C3  20 D3 37      		jsr	?70		; check all files f3..fn (seq type, no splat)
2986
 5304  F937C6  20 93 39      		jsr	setwrf		; ok, create dest file
2987
 5305  F937C9  A2 01         		ldx	#1
2988
 5306  F937CB  20 3A 39      	?24:	jsr	cat		; copy/concat
2989
 5307  F937CE  A6 34         		ldx	fildrv		; invalidate dest drive...
2990
 5308  F937D0  74 68         		stz	drvfg,x		; ...so force init next time
2991
 5309  F937D2  60            		rts
2992
 5310
2993
 5311                        	?70:	; check f3..fn: must be just seq. type and no splat
2994
 5312  F937D3  A6 13         		ldx	f2cnt
2995
 5313  F937D5  E0 03         		cpx	#3
2996
 5314  F937D7  90 13         		bcc	?74		; skip this test if just 2 files
2997
 5315  F937D9  CA            	?72:	dex			; index
2998
 5316  F937DA  E0 02         		cpx	#2
2999
 5317  F937DC  90 0E         		bcc	?74
3000
 5318  F937DE  B5 39         		lda	pattyp,x
3001
 5319  F937E0  89 20         		bit	#$20
3002
 5320  F937E2  D0 B7         		bne	?09		; error: splat file
3003
 5321  F937E4  29 07         		and	#typmsk
3004
 5322  F937E6  C9 01         		cmp	#seqtyp
3005
 5323  F937E8  D0 9A         		bne	?05		; error: mismatch type
3006
 5324  F937EA  80 ED         		bra	?72
3007
 5325  F937EC  60            	?74:	rts
3008
 5326
3009
 5327                        	; check file 2 stream for open (all should not be open) (80)
3010
 5328  F937ED                	tstfs2:
3011
 5329  F937ED  A6 13         		ldx	f2cnt
3012
 5330  F937EF  CA            	?82:	dex
3013
 5331  F937F0  E4 12         		cpx	f1cnt
3014
 5332  F937F2  90 09         		bcc	?84		; skip file in fs1 stream
3015
 5333  F937F4  86 16         		stx	entfnd
3016
 5334  F937F6  20 28 48      		jsr	tstopn
3017
 5335  F937F9  A6 16         		ldx	entfnd
3018
 5336  F937FB  80 F2         		bra	?82
3019
 5337  F937FD  60            	?84:	rts
3020
 5338
3021
 5339                        	; in fs2 stream will not be th dest file
3022
 5340                        	; in:	X=index of start test
3023
 5341  F937FE                	tstdup:
3024
 5342  F937FE  B5 34         		lda	fildrv,x
3025
 5343  F93800  29 01         		and	#1
3026
 5344  F93802  C5 34         		cmp	fildrv
3027
 5345  F93804  D0 0C         		bne	?06
3028
 5346  F93806  B5 20         		lda	filtrk,x
3029
 5347  F93808  C5 20         		cmp	filtrk
3030
 5348  F9380A  D0 06         		bne	?06
3031
 5349  F9380C  B5 25         		lda	filsec,x
3032
 5350  F9380E  C5 25         		cmp	filsec
3033
 5351  F93810  F0 06         		beq	?10		; match
3034
 5352  F93812  E8            	?06:	inx
3035
 5353  F93813  E4 13         		cpx	f2cnt
3036
 5354  F93815  90 E7         		bcc	tstdup
3037
 5355  F93817  60            		rts
3038
 5356  F93818  A9 52         	?10:	lda	#badcat		; recursive concat
3039
  Tue Jul 17 11:00:19 2018                                                                                               Page   50
3040
 
3041
 
3042
 
3043
 
3044
 5357  F9381A  4C 07 41      		jmp	cmderr
3045
 5358
3046
 5359                        	; move first file name to namebuf2 (90)
3047
 5360  F9381D                	movdst:
3048
 5361  F9381D  A2 00         		ldx	#0		; file name start
3049
 5362  F9381F  A9 22         		lda	#'"'
3050
 5363  F93821  8D DD E1      		sta	!nambuf2
3051
 5364  F93824  A4 1A         		ldy	filtbl
3052
 5365  F93826  B9 00 E1      	?94:	lda	!cmdbuf,y
3053
 5366  F93829  29 7F         		and	#$7F
3054
 5367  F9382B  9D DE E1      		sta	!nambuf2+1,x
3055
 5368  F9382E  E8            		inx
3056
 5369  F9382F  C8            		iny
3057
 5370  F93830  E0 10         		cpx	#16
3058
 5371  F93832  90 F2         		bcc	?94
3059
 5372  F93834  A9 22         		lda	#'"'
3060
 5373  F93836  9D DE E1      		sta	!nambuf2+1,x
3061
 5374  F93839  9E DF E1      		stz	!nambuf2+2,x
3062
 5375  F9383C  60            		rts
3063
 5376
3064
 5377                        	; copy disk-to-disk (with pattern, no concat)
3065
 5378  F9383D                	cpall:
3066
 5379  F9383D  A9 80         		lda	#$80
3067
 5380  F9383F  85 55         		sta	subcmd		; flag disk-to-disk copy
3068
 5381  F93841  A5 34         		lda	fildrv
3069
 5382  F93843  29 01         		and	#1
3070
 5383  F93845  85 34         		sta	fildrv
3071
 5384  F93847  85 36         		sta	fildrv+2	; save dest drive
3072
 5385  F93849  A5 35         		lda	fildrv+1
3073
 5386  F9384B  29 01         		and	#1
3074
 5387  F9384D  85 35         		sta	fildrv+1
3075
 5388  F9384F  A5 1A         		lda	filtbl
3076
 5389  F93851  85 1C         		sta	filtbl+2	; save file name 1 ptr
3077
 5390  F93853  20 97 4B      		jsr	optsch		; init all drive's
3078
 5391  F93856  64 18         		stz	tgflg		; search just one drive
3079
 5392  F93858  A5 35         		lda	fildrv+1
3080
 5393  F9385A  85 19         		sta	drvnum		; search just in src. drive
3081
 5394  F9385C  85 34         		sta	fildrv
3082
 5395  F9385E  A5 1B         		lda	filtbl+1
3083
 5396  F93860  85 1A         		sta	filtbl
3084
 5397  F93862  A9 01         		lda	#1
3085
 5398  F93864  85 12         		sta	f1cnt
3086
 5399  F93866  85 13         		sta	f2cnt		; fake: just one file in stream!
3087
 5400  F93868  20 70 4A      		jsr	ffst		; start search on src drive
3088
 5401  F9386B  30 3B         		bmi	?20		; no files
3089
 5402  F9386D  64 43         	?02:	stz	image		; flag
3090
 5403  F9386F  64 16         		stz	entfnd		; file is in fs1 stream!
3091
 5404  F93871  20 37 48      		jsr	tstfd		; is an open file?
3092
 5405  F93874  90 1C         		bcc	?04		; yes - don't copy
3093
 5406  F93876  A6 36         		ldx	fildrv+2
3094
 5407  F93878  A9 10         		lda	#$10
3095
 5408  F9387A  34 68         		bit	drvfg,x
3096
 5409  F9387C  D0 14         		bne	?04		; dest disk write protect on - skip
3097
 5410  F9387E  A7 0A         		lda	[dirp]		; type & flags
3098
 5411  F93880  85 3C         		sta	pattyp+3
3099
 5412  F93882  10 0E         		bpl	?04		; not properly closed - skip splat file
3100
 5413  F93884  29 07         		and	#typmsk		; mask type
3101
  Tue Jul 17 11:00:19 2018                                                                                               Page   51
3102
 
3103
 
3104
 
3105
 
3106
 5414  F93886  C9 04         		cmp	#reltyp
3107
 5415  F93888  F0 08         		beq	?04		; skip rel files
3108
 5416  F9388A  C9 05         		cmp	#partyp
3109
 5417  F9388C  F0 04         		beq	?04		; skip part type
3110
 5418  F9388E  A9 80         		lda	#$80		; candidate to be copied
3111
 5419  F93890  85 43         		sta	image
3112
 5420  F93892  20 C6 38      	?04:	jsr	?50		; lookup dest drive for file
3113
 5421  F93895  A2 01         		ldx	#1		; set up one read file
3114
 5422  F93897  86 15         		stx	f2ptr
3115
 5423  F93899  20 A9 38      		jsr	?30		; create & copy
3116
 5424  F9389C  20 21 39      	?10:	jsr	?80		; set back search data for src drive
3117
 5425  F9389F  20 66 4A      		jsr	ffre		; search next matching file
3118
 5426  F938A2  10 C9         		bpl	?02		; more files
3119
 5427  F938A4  A6 36         		ldx	fildrv+2	; invalidate dest drive...
3120
 5428  F938A6  74 68         		stz	drvfg,x		; ...so force init next time
3121
 5429  F938A8  60            	?20:	rts
3122
 5430
3123
 5431                        		; create dest file and copy one file
3124
 5432  F938A9  20 56 3A      	?30:	jsr	cpymsg		; show message
3125
 5433  F938AC  24 43         		bit	image		; skip?
3126
 5434  F938AE  10 13         		bpl	?34		; yes
3127
 5435  F938B0  20 93 39      		jsr	setwrf		; setup write file (create)
3128
 5436  F938B3  20 C2 39      		jsr	setrdf		; setup read file
3129
 5437  F938B6  20 B8 45      	?32:	jsr	bufget		; loop copy (buffered)
3130
 5438  F938B9  20 08 46      		jsr	bufput
3131
 5439  F938BC  A5 EB         		lda	rdeof
3132
 5440  F938BE  F0 F6         		beq	?32		; no eof
3133
 5441  F938C0  20 5D 39      		jsr	clswrf		; close dest file
3134
 5442  F938C3  4C 2C 3B      	?34:	jmp	donemsg
3135
 5443
3136
 5444  F938C6  20 B0 33      	?50:	jsr	movnam		; fill name buffer with src file
3137
 5445  F938C9  24 43         		bit	image
3138
 5446  F938CB  10 53         		bpl	?54		; skip this file
3139
 5447  F938CD  A5 20         		lda	filtrk		; save search data for file name 2
3140
 5448  F938CF  85 21         		sta	filtrk+1
3141
 5449  F938D1  A5 25         		lda	filsec
3142
 5450  F938D3  85 26         		sta	filsec+1
3143
 5451  F938D5  A5 2A         		lda	entsec
3144
 5452  F938D7  85 2B         		sta	entsec+1
3145
 5453  F938D9  A5 2F         		lda	entind
3146
 5454  F938DB  85 30         		sta	entind+1
3147
 5455  F938DD  A5 39         		lda	pattyp
3148
 5456  F938DF  85 3A         		sta	pattyp+1
3149
 5457  F938E1  64 20         		stz	filtrk		; set search data for file name 1
3150
 5458  F938E3  64 25         		stz	filsec
3151
 5459  F938E5  64 2A         		stz	entsec
3152
 5460  F938E7  64 2F         		stz	entind
3153
 5461  F938E9  64 39         		stz	pattyp
3154
 5462  F938EB  A5 36         		lda	fildrv+2	; restore dest drive
3155
 5463  F938ED  85 34         		sta	fildrv
3156
 5464  F938EF  85 19         		sta	drvnum
3157
 5465  F938F1  A6 1C         		ldx	filtbl+2	; restore file name 1 ptr
3158
 5466  F938F3  86 1A         		stx	filtbl
3159
 5467  F938F5  A0 03         		ldy	#3		; move the entry name to file name 1
3160
 5468  F938F7  B7 0A         	?52:	lda	[dirp],y
3161
 5469  F938F9  9D 00 E1      		sta	!cmdbuf,x
3162
 5470  F938FC  E8            		inx
3163
  Tue Jul 17 11:00:19 2018                                                                                               Page   52
3164
 
3165
 
3166
 
3167
 
3168
 5471  F938FD  C8            		iny
3169
 5472  F938FE  C0 13         		cpy	#19
3170
 5473  F93900  90 F5         		bcc	?52
3171
 5474  F93902  A9 01         		lda	#1		; now lookup file name on dest drv
3172
 5475  F93904  85 12         		sta	f1cnt
3173
 5476  F93906  85 13         		sta	f2cnt		; fake: just one file in stream!
3174
 5477  F93908  20 3B 4A      		jsr	lookup2
3175
 5478  F9390B  A9 01         		lda	#1		; restore real situation
3176
 5479  F9390D  85 12         		sta	f1cnt
3177
 5480  F9390F  1A            		inc	a
3178
 5481  F93910  85 13         		sta	f2cnt
3179
 5482  F93912  A5 3C         		lda	pattyp+3
3180
 5483  F93914  29 07         		and	#typmsk
3181
 5484  F93916  85 0E         		sta	type		; file type for copied file
3182
 5485  F93918  A5 20         		lda	filtrk		; check if dest file already exist
3183
 5486  F9391A  F0 04         		beq	?54		; ok
3184
 5487  F9391C  64 43         		stz	image		; can't copy this file
3185
 5488  F9391E  64 0E         		stz	type
3186
 5489  F93920  60            	?54:	rts
3187
 5490
3188
 5491  F93921  64 20         	?80:	stz	filtrk		; set search data for file name 2
3189
 5492  F93923  64 25         		stz	filsec
3190
 5493  F93925  64 2A         		stz	entsec
3191
 5494  F93927  64 2F         		stz	entind
3192
 5495  F93929  A5 35         		lda	fildrv+1
3193
 5496  F9392B  85 19         		sta	drvnum		; search in src. drive
3194
 5497  F9392D  85 34         		sta	fildrv
3195
 5498  F9392F  A5 1B         		lda	filtbl+1
3196
 5499  F93931  85 1A         		sta	filtbl
3197
 5500  F93933  A9 01         		lda	#1
3198
 5501  F93935  85 12         		sta	f1cnt
3199
 5502  F93937  85 13         		sta	f2cnt		; fake: just one file in stream!
3200
 5503  F93939  60            		rts
3201
 5504
3202
 5505                        	; copy/concat
3203
 5506                        	; in:	X=index of first file to concat
3204
 5507  F9393A                	cat:
3205
 5508  F9393A  A9 80         		lda	#$80
3206
 5509  F9393C  85 43         		sta	image		; assume all good
3207
 5510  F9393E  86 15         	?102:	stx	f2ptr		; start file
3208
 5511  F93940  20 9A 33      		jsr	movnamx		; set up file name in nambuf
3209
 5512  F93943  20 56 3A      		jsr	cpymsg		; show message
3210
 5513  F93946  20 C2 39      		jsr	setrdf		; setup read file
3211
 5514  F93949  20 B8 45      	?104:	jsr	bufget		; loop copy
3212
 5515  F9394C  20 08 46      		jsr	bufput
3213
 5516  F9394F  A5 EB         		lda	rdeof
3214
 5517  F93951  F0 F6         		beq	?104		; no eof
3215
 5518  F93953  20 2C 3B      		jsr	donemsg
3216
 5519  F93956  A6 15         		ldx	f2ptr		; concat more file, if any
3217
 5520  F93958  E8            		inx
3218
 5521  F93959  E4 13         		cpx	f2cnt
3219
 5522  F9395B  90 E1         		bcc	?102		; append
3220
 5523                        		;jmp	clswrf
3221
 5524
3222
 5525                        	; close write file when finish to copy
3223
 5526  F9395D                	clswrf:
3224
 5527  F9395D  A5 2A         		lda	entsec		; set dir. ptr to dest file
3225
  Tue Jul 17 11:00:19 2018                                                                                               Page   53
3226
 
3227
 
3228
 
3229
 
3230
 5528  F9395F  85 09         		sta	sector
3231
 5529  F93961  A0 28         		ldy	#dirtrk
3232
 5530  F93963  84 08         		sty	track
3233
 5531  F93965  A6 EC         		ldx	wrdrv
3234
 5532  F93967  86 19         		stx	drvnum
3235
 5533  F93969  20 3D 56      		jsr	sethdp
3236
 5534  F9396C  18            		clc
3237
 5535  F9396D  65 09         		adc	sector
3238
 5536  F9396F  85 0B         		sta	dirp+1		; set dir. pointer to file entry
3239
 5537  F93971  A5 2F         		lda	entind
3240
 5538  F93973  85 0A         		sta	dirp
3241
 5539  F93975  A7 0A         		lda	[dirp]		; set flag closed file
3242
 5540  F93977  09 80         		ora	#$80
3243
 5541  F93979  87 0A         		sta	[dirp]
3244
 5542  F9397B  A0 1C         		ldy	#28		; store block's #
3245
 5543  F9397D                		ACC16
3246
 5544  F9397D  C2 20         		rep	#PMFLAG
3247
 5545                        		.LONGA	on
3248
 5546                        		.MNLIST
3249
 5547  F9397F  A5 F0         		lda	wcnt
3250
 5548  F93981  1A            		inc	a		; take in account last block
3251
 5549  F93982  97 0A         		sta	[dirp],y
3252
 5550  F93984                		ACC08
3253
 5551  F93984  E2 20         		sep	#PMFLAG
3254
 5552                        		.LONGA	off
3255
 5553                        		.MNLIST
3256
 5554  F93986  20 10 4E      		jsr	mapout		; check&update bam on disk
3257
 5555  F93989  A5 09         		lda	sector
3258
 5556  F9398B  C9 04         		cmp	#4		; dir sec already updated with bam?
3259
 5557  F9398D  90 03         		bcc	?02		; yes
3260
 5558  F9398F  20 57 36      		jsr	wrdsec		; update directory
3261
 5559  F93992  60            	?02:	rts
3262
 5560
3263
 5561                        	; setup write file
3264
 5562  F93993                	setwrf:
3265
 5563  F93993  A5 34         		lda	fildrv		; drive #
3266
 5564  F93995  29 01         		and	#1
3267
 5565  F93997  85 EC         		sta	wrdrv
3268
 5566  F93999  85 19         		sta	drvnum
3269
 5567  F9399B  64 09         		stz	sector
3270
 5568  F9399D  A9 28         		lda	#dirtrk
3271
 5569  F9399F  85 08         		sta	track
3272
 5570  F939A1  20 3D 56      		jsr	sethdp
3273
 5571  F939A4  20 D2 4B      		jsr	addfil		; create file in directory
3274
 5572  F939A7  A4 20         		ldy	filtrk		; take first t&s
3275
 5573  F939A9  84 08         		sty	track
3276
 5574  F939AB  A5 25         		lda	filsec
3277
 5575  F939AD  85 09         		sta	sector
3278
 5576  F939AF  85 EE         		sta	wsec		; current write sector
3279
 5577  F939B1  85 EF         		sta	wfirst		; this is first sector
3280
 5578  F939B3  20 C1 57      		jsr	wread		; pre-read whole track
3281
 5579  F939B6  20 5A 56      		jsr	setwb		; set wbuf pointer
3282
 5580  F939B9  A9 02         		lda	#2
3283
 5581  F939BB  85 ED         		sta	wridx		; start index
3284
 5582  F939BD  64 F0         		stz	wcnt		; clear block's count
3285
 5583  F939BF  64 F1         		stz	wcnt+1
3286
 5584  F939C1  60            		rts
3287
  Tue Jul 17 11:00:19 2018                                                                                               Page   54
3288
 
3289
 
3290
 
3291
 
3292
 5585
3293
 5586                        	; setup read file
3294
 5587  F939C2                	setrdf:
3295
 5588  F939C2  A6 15         		ldx	f2ptr		; index=1..n-1
3296
 5589  F939C4  B5 34         		lda	fildrv,x
3297
 5590  F939C6  29 01         		and	#1
3298
 5591  F939C8  85 19         		sta	drvnum
3299
 5592  F939CA  85 E8         		sta	rddrv
3300
 5593  F939CC  B4 20         		ldy	filtrk,x	; first t&s of file
3301
 5594  F939CE  84 08         		sty	track
3302
 5595  F939D0  B5 25         		lda	filsec,x
3303
 5596  F939D2  85 09         		sta	sector
3304
 5597  F939D4  20 AB 57      		jsr	tread		; read whole track
3305
 5598  F939D7  20 4A 56      		jsr	setcp		; set bufp pointer
3306
 5599  F939DA  64 EA         		stz	rdlst		; assume full block
3307
 5600  F939DC  A0 01         		ldy	#1
3308
 5601  F939DE  B7 8A         		lda	[bufp],y
3309
 5602  F939E0  A8            		tay
3310
 5603  F939E1  A7 8A         		lda	[bufp]
3311
 5604  F939E3  D0 02         		bne	?04
3312
 5605  F939E5  84 EA         		sty	rdlst		; last byte pointer
3313
 5606  F939E7  64 EB         	?04:	stz	rdeof
3314
 5607  F939E9  A9 02         		lda	#2
3315
 5608  F939EB  85 E9         		sta	rdidx
3316
 5609  F939ED  60            		rts
3317
 5610
3318
 5611                        	; seek end: open file and put pointer to last byte of file
3319
 5612                        	; use write cache for append
3320
 5613  F939EE                	skend:
3321
 5614  F939EE  A5 34         		lda	fildrv
3322
 5615  F939F0  29 01         		and	#1
3323
 5616  F939F2  85 EC         		sta	wrdrv		; set up write drv
3324
 5617  F939F4  85 19         		sta	drvnum
3325
 5618  F939F6  A5 2A         		lda	entsec		; set dir ptr to entry
3326
 5619  F939F8  85 09         		sta	sector
3327
 5620  F939FA  A0 28         		ldy	#dirtrk
3328
 5621  F939FC  84 08         		sty	track
3329
 5622  F939FE  20 3D 56      		jsr	sethdp
3330
 5623  F93A01  18            		clc
3331
 5624  F93A02  65 09         		adc	sector
3332
 5625  F93A04  85 0B         		sta	dirp+1		; set dir. pointer to file entry
3333
 5626  F93A06  A5 2F         		lda	entind
3334
 5627  F93A08  85 0A         		sta	dirp
3335
 5628  F93A0A  A7 0A         		lda	[dirp]		; clear flag closed file
3336
 5629  F93A0C  29 7F         		and	#$7F
3337
 5630  F93A0E  87 0A         		sta	[dirp]
3338
 5631  F93A10  20 57 36      		jsr	wrdsec		; update dir on disk
3339
 5632  F93A13  A5 20         		lda	filtrk
3340
 5633  F93A15  85 08         		sta	track
3341
 5634  F93A17  A5 25         		lda	filsec
3342
 5635  F93A19  85 09         		sta	sector
3343
 5636  F93A1B  64 F0         		stz	wcnt
3344
 5637  F93A1D  64 F1         		stz	wcnt+1
3345
 5638  F93A1F  20 C1 57      	?02:	jsr	wread		; read whole track in write cache
3346
 5639  F93A22  20 5A 56      		jsr	setwb		; set cache ptr to right sector
3347
 5640  F93A25  E6 F0         	?04:	inc	wcnt
3348
 5641  F93A27  D0 02         		bne	?06
3349
  Tue Jul 17 11:00:19 2018                                                                                               Page   55
3350
 
3351
 
3352
 
3353
 
3354
 5642  F93A29  E6 F1         		inc	wcnt+1
3355
 5643  F93A2B  A0 01         	?06:	ldy	#1
3356
 5644  F93A2D  B7 90         		lda	[wbuf],y	; next sector
3357
 5645  F93A2F  A8            		tay
3358
 5646  F93A30  A7 90         		lda	[wbuf]		; next track
3359
 5647  F93A32  F0 12         		beq	?10		; end of file
3360
 5648  F93A34  84 09         		sty	sector		; next sector
3361
 5649  F93A36  C5 08         		cmp	track		; same track?
3362
 5650  F93A38  85 08         		sta	track
3363
 5651  F93A3A  D0 E3         		bne	?02		; will read a new track
3364
 5652  F93A3C  18            		clc
3365
 5653  F93A3D  98            		tya
3366
 5654  F93A3E  A6 19         		ldx	drvnum
3367
 5655  F93A40  75 7C         		adc	wrtofs,x	; sector in the same track
3368
 5656  F93A42  85 91         		sta	wbuf+1
3369
 5657  F93A44  80 DF         		bra	?04		; follow link
3370
 5658  F93A46  C8            	?10:	iny			; bump pointer
3371
 5659  F93A47  84 ED         		sty	wridx		; start index for append
3372
 5660  F93A49  A5 09         		lda	sector
3373
 5661  F93A4B  85 EE         		sta	wsec		; current write sector
3374
 5662  F93A4D  85 EF         		sta	wfirst		; this is first sector
3375
 5663  F93A4F                		ACC16
3376
 5664  F93A4F  C2 20         		rep	#PMFLAG
3377
 5665                        		.LONGA	on
3378
 5666                        		.MNLIST
3379
 5667  F93A51  C6 F0         		dec	wcnt		; append !!
3380
 5668  F93A53                		ACC08
3381
 5669  F93A53  E2 20         		sep	#PMFLAG
3382
 5670                        		.LONGA	off
3383
 5671                        		.MNLIST
3384
 5672  F93A55  60            		rts
3385
 5673
3386
 5674                        	; show message while copy/concat
3387
 5675  F93A56                	cpymsg:
3388
 5676  F93A56  24 55         		bit	subcmd
3389
 5677  F93A58  10 1C         		bpl	?02		; copy/concat
3390
 5678  F93A5A
3391
 5679                        		; show msg while disk-to-disk copy
3392
 5680  F93A5A  A5 34         		lda	fildrv		; dest drive
3393
 5681  F93A5C  29 01         		and	#1
3394
 5682  F93A5E  48            		pha
3395
 5683  F93A5F  D4 94         		pei	(wtmp)		; block's count #
3396
 5684  F93A61  A9 00         		lda	#^nambuf
3397
 5685  F93A63  48            		pha
3398
 5686  F93A64  F4 C2 E1      		pea	#!nambuf
3399
 5687  F93A67  A5 35         		lda	fildrv+1	; source drive
3400
 5688  F93A69  29 01         		and	#1
3401
 5689  F93A6B  48            		pha
3402
 5690  F93A6C  4B            		phk
3403
 5691  F93A6D  F4 A7 3A      		pea	#!?20
3404
 5692  F93A70  A9 0B         		lda	#11		; params #
3405
 5693  F93A72  48            		pha
3406
 5694  F93A73                		BPRINTF
3407
 5695  F93A73  02 11         		cop	$11
3408
 5696                        		.MNLIST
3409
 5697  F93A75  60            		rts
3410
 5698
3411
  Tue Jul 17 11:00:19 2018                                                                                               Page   56
3412
 
3413
 
3414
 
3415
 
3416
 5699                        		; show msg while copy/concat
3417
 5700  F93A76  A9 00         	?02:	lda	#^nambuf	; dest file name
3418
 5701  F93A78  48            		pha
3419
 5702  F93A79  F4 DD E1      		pea	#!nambuf2
3420
 5703  F93A7C  A5 34         		lda	fildrv		; dest drive
3421
 5704  F93A7E  29 01         		and	#1
3422
 5705  F93A80  48            		pha
3423
 5706  F93A81  D4 94         		pei	(wtmp)		; block's count #
3424
 5707  F93A83  A9 00         		lda	#^nambuf
3425
 5708  F93A85  48            		pha
3426
 5709  F93A86  F4 C2 E1      		pea	#!nambuf
3427
 5710  F93A89  A5 35         		lda	fildrv+1	; source drive
3428
 5711  F93A8B  29 01         		and	#1
3429
 5712  F93A8D  48            		pha
3430
 5713  F93A8E  4B            		phk			; string bank
3431
 5714  F93A8F  24 55         		bit	subcmd
3432
 5715  F93A91  70 0B         		bvs	?04		; always append
3433
 5716  F93A93  A6 15         		ldx	f2ptr
3434
 5717  F93A95  E0 02         		cpx	#2
3435
 5718  F93A97  B0 05         		bcs	?04		; append
3436
 5719  F93A99  F4 D6 3A      		pea	#!?30		; copy
3437
 5720  F93A9C  80 03         		bra	?06
3438
 5721  F93A9E  F4 01 3B      	?04:	pea	#!?40
3439
 5722  F93AA1  A9 0E         	?06:	lda	#14		; params #
3440
 5723  F93AA3  48            		pha
3441
 5724  F93AA4                		BPRINTF
3442
 5725  F93AA4  02 11         		cop	$11
3443
 5726                        		.MNLIST
3444
 5727  F93AA6  60            		rts
3445
 5728
3446
 5729  F93AA7  0D 63 6F 70 79 	?20:	.DB	$0D, 'copy #%bu:%s (%04hu blocks) to drive #%bu:...', $00
3447
               20 23 25 62 75
3448
               3A 25 73 20 28
3449
               25 30 34 68 75
3450
               20 62 6C 6F 63
3451
               6B 73 29 20 74
3452
               6F 20 64 72 69
3453
               76 65 20 23 25
3454
               62 75 3A 2E 2E
3455
               2E 00
3456
 5730  F93AD6  0D 63 6F 70 79 	?30:	.DB	$0D, 'copy #%bu:%s (%04hu blocks) to #%bu:%s...', $00
3457
               20 23 25 62 75
3458
               3A 25 73 20 28
3459
               25 30 34 68 75
3460
               20 62 6C 6F 63
3461
               6B 73 29 20 74
3462
               6F 20 23 25 62
3463
               75 3A 25 73 2E
3464
               2E 2E 00
3465
 5731  F93B01  0D 63 61 74 20 	?40:	.DB	$0D, 'cat  #%bu:%s (%04hu blocks) to #%bu:%s...', $00
3466
               20 23 25 62 75
3467
               3A 25 73 20 28
3468
               25 30 34 68 75
3469
               20 62 6C 6F 63
3470
               6B 73 29 20 74
3471
               6F 20 23 25 62
3472
               75 3A 25 73 2E
3473
  Tue Jul 17 11:00:19 2018                                                                                               Page   57
3474
 
3475
 
3476
 
3477
 
3478
               2E 2E 00
3479
 5732
3480
 5733  F93B2C                	donemsg:
3481
 5734  F93B2C  A9 3B         		lda	#>?10
3482
 5735  F93B2E  EB            		xba
3483
 5736  F93B2F  A9 3F         		lda	#<?10
3484
 5737  F93B31  24 43         		bit	image
3485
 5738  F93B33  10 05         		bpl	?02		; skip
3486
 5739  F93B35  A9 3B         		lda	#>?20
3487
 5740  F93B37  EB            		xba
3488
 5741  F93B38  A9 45         		lda	#<?20
3489
 5742  F93B3A  A2 F9         	?02:	ldx	#^?10
3490
 5743  F93B3C                		SCNSTROUT
3491
 5744  F93B3C  02 03         		cop	$03
3492
 5745                        		.MNLIST
3493
 5746  F93B3E  60            		rts
3494
 5747
3495
 5748  F93B3F  73 6B 69 70 2E 	?10:	.DB	'skip.', 0
3496
               00
3497
 5749  F93B45  64 6F 6E 65 2E 	?20:	.DB	'done.', 0
3498
               00
3499
 5750
3500
 5751                        	;---------------------------------------------------------------------------
3501
 5752                        	; validate/file check command's
3502
 5753                        	;---------------------------------------------------------------------------
3503
 5754                        	; check file system but without change it
3504
 5755  F93B4B                	fcheck:
3505
 5756  F93B4B  20 05 3C      		jsr	initd
3506
 5757  F93B4E  A0 00         		ldy	#$00
3507
 5758  F93B50  80 13         		bra	vdate1
3508
 5759
3509
 5760                        	; check file system and change it
3510
 5761  F93B52                	vdate:
3511
 5762  F93B52  20 05 3C      		jsr	initd
3512
 5763  F93B55  A6 19         		ldx	drvnum
3513
 5764  F93B57  A0 80         		ldy	#$80		; update file system
3514
 5765  F93B59  B5 68         		lda	drvfg,x
3515
 5766  F93B5B  89 08         		bit	#$08		; test if new version
3516
 5767  F93B5D  F0 04         		beq	?10		; only check without correct in old version
3517
 5768  F93B5F  89 10         		bit	#$10		; write protect on?
3518
 5769  F93B61  F0 02         		beq	vdate1		; no -- proceed
3519
 5770  F93B63  A0 00         	?10:	ldy	#$00		; check only -- no update
3520
 5771
3521
 5772  F93B65                	vdate1:
3522
 5773  F93B65  84 E6         		sty	wrop
3523
 5774  F93B67  A5 19         		lda	drvnum
3524
 5775  F93B69  48            		pha
3525
 5776  F93B6A  4B            		phk
3526
 5777  F93B6B  24 E6         		bit	wrop
3527
 5778  F93B6D  30 05         		bmi	?02
3528
 5779  F93B6F  F4 A4 3B      		pea	#!?60
3529
 5780  F93B72  80 03         		bra	?03
3530
 5781  F93B74  F4 D8 3B      	?02:	pea	#!?70
3531
 5782  F93B77  A9 05         	?03:	lda	#5
3532
 5783  F93B79  48            		pha
3533
 5784  F93B7A                		BPRINTF
3534
 5785  F93B7A  02 11         		cop	$11
3535
  Tue Jul 17 11:00:19 2018                                                                                               Page   58
3536
 
3537
 
3538
 
3539
 
3540
 5786                        		.MNLIST
3541
 5787  F93B7C  20 9C 4E      		jsr	newmap		; set new aux bam
3542
 5788  F93B7F  64 02         		stz	delind
3543
 5789  F93B81                		ACC16
3544
 5790  F93B81  C2 20         		rep	#PMFLAG
3545
 5791                        		.LONGA	on
3546
 5792                        		.MNLIST
3547
 5793  F93B83  A9 58 0C      		lda	#maxblks	; max. available block's
3548
 5794  F93B86  85 86         		sta	ntot		; updated in aux bam
3549
 5795  F93B88  85 88         		sta	bcnt		; updated in file check
3550
 5796  F93B8A                		ACC08
3551
 5797  F93B8A  E2 20         		sep	#PMFLAG
3552
 5798                        		.LONGA	off
3553
 5799                        		.MNLIST
3554
 5800  F93B8C  20 2D 4B      		jsr	srchst		; search first file
3555
 5801  F93B8F  F0 0B         		beq	?10		; end search
3556
 5802
3557
 5803  F93B91  20 08 50      	?04:	jsr	chkfil		; found one - check
3558
 5804  F93B94  20 65 4B      		jsr	srre		; next entry
3559
 5805  F93B97  D0 F8         		bne	?04
3560
 5806  F93B99  20 A7 52      		jsr	chkdir
3561
 5807  F93B9C  20 19 53      	?10:	jsr	updbam
3562
 5808  F93B9F  A6 19         		ldx	drvnum
3563
 5809  F93BA1  74 68         		stz	drvfg,x
3564
 5810  F93BA3  60            		rts
3565
 5811
3566
 5812  F93BA4  0D 63 68 65 63 	?60:	.DB	$0D, 'check file system on drive #%bu (without changes).', 0
3567
               6B 20 66 69 6C
3568
               65 20 73 79 73
3569
               74 65 6D 20 6F
3570
               6E 20 64 72 69
3571
               76 65 20 23 25
3572
               62 75 20 28 77
3573
               69 74 68 6F 75
3574
               74 20 63 68 61
3575
               6E 67 65 73 29
3576
               2E 00
3577
 5813  F93BD8  0D 76 61 6C 69 	?70:	.DB	$0D, 'validate file system with bam on drive %bu.', 0
3578
               64 61 74 65 20
3579
               66 69 6C 65 20
3580
               73 79 73 74 65
3581
               6D 20 77 69 74
3582
               68 20 62 61 6D
3583
               20 6F 6E 20 64
3584
               72 69 76 65 20
3585
               25 62 75 2E 00
3586
 5814
3587
 5815                        	;---------------------------------------------------------------------------
3588
 5816                        	; initialize command
3589
 5817                        	;---------------------------------------------------------------------------
3590
 5818  F93C05                	initd:
3591
 5819  F93C05  A5 41         		lda	cmdsiz
3592
 5820  F93C07  C9 03         		cmp	#3
3593
 5821  F93C09  90 03         		bcc	?02
3594
 5822  F93C0B  4C 05 41      		jmp	e_badsyn
3595
 5823  F93C0E  20 31 42      	?02:	jsr	simprs
3596
 5824  F93C11  A6 19         		ldx	drvnum		; force init
3597
  Tue Jul 17 11:00:19 2018                                                                                               Page   59
3598
 
3599
 
3600
 
3601
 
3602
 5825  F93C13  74 68         		stz	drvfg,x
3603
 5826  F93C15  4C 6A 56      		jmp	drvint
3604
 5827
3605
 5828                        	;---------------------------------------------------------------------------
3606
 5829                        	; duplicate command
3607
 5830                        	;---------------------------------------------------------------------------
3608
 5831  F93C18                	dupd:
3609
 5832  F93C18  20 D7 40      		jsr	prsdtd		; check src & dst drive
3610
 5833  F93C1B  A5 35         		lda	fildrv+1
3611
 5834  F93C1D  29 01         		and	#1
3612
 5835  F93C1F  85 19         		sta	drvnum
3613
 5836  F93C21  85 35         		sta	fildrv+1
3614
 5837  F93C23  49 01         		eor	#$01
3615
 5838  F93C25  85 42         		sta	char
3616
 5839  F93C27  20 6A 56      		jsr	drvint		; init source drive
3617
 5840  F93C2A  20 8A 4B      		jsr	togdrv		; toggle drive
3618
 5841  F93C2D  20 B4 56      		jsr	dsktst		; check if dest drive is ready
3619
 5842  F93C30  A6 19         		ldx	drvnum
3620
 5843  F93C32  A9 10         		lda	#$10		; test if write protect
3621
 5844  F93C34  34 68         		bit	drvfg,x
3622
 5845  F93C36  F0 05         		beq	?04
3623
 5846  F93C38  A9 1A         		lda	#wpon
3624
 5847  F93C3A  4C F5 56      		jmp	drverr
3625
 5848  F93C3D                	?04:	SCN_CR
3626
 5849  F93C3D                		SCNPRCHAR
3627
 5850                        		.MLIST
3628
 5851  F93C3D  02 07         		cop	$07
3629
 5852                        		.MNLIST
3630
 5853  F93C3F  0D            		.DB	$0D
3631
 5854                        		.MNLIST
3632
 5855  F93C40  20 E1 58      		jsr	llfmt		; format dest. drive
3633
 5856  F93C43                		SCN_CR
3634
 5857  F93C43                		SCNPRCHAR
3635
 5858                        		.MLIST
3636
 5859  F93C43  02 07         		cop	$07
3637
 5860                        		.MNLIST
3638
 5861  F93C45  0D            		.DB	$0D
3639
 5862                        		.MNLIST
3640
 5863  F93C46  A9 01         		lda	#1
3641
 5864  F93C48  85 08         		sta	track		; track counter
3642
 5865  F93C4A  64 09         		stz	sector
3643
 5866  F93C4C                		SCNGETPOS
3644
 5867  F93C4C  02 18         		cop	$18
3645
 5868  F93C4E  02            		.DB	$02
3646
 5869                        		.MNLIST
3647
 5870  F93C4F  86 94         		stx	wtmp
3648
 5871  F93C51  84 95         		sty	wtmp+1
3649
 5872  F93C53  A6 94         	?10:	ldx	wtmp
3650
 5873  F93C55  A4 95         		ldy	wtmp+1
3651
 5874  F93C57                		SCNSETPOS
3652
 5875  F93C57  02 18         		cop	$18
3653
 5876  F93C59  03            		.DB	$03
3654
 5877                        		.MNLIST
3655
 5878  F93C5A  A5 19         		lda	drvnum
3656
 5879  F93C5C  48            		pha			; dest drive
3657
 5880  F93C5D  A5 35         		lda	fildrv+1
3658
 5881  F93C5F  48            		pha			; src drive
3659
  Tue Jul 17 11:00:19 2018                                                                                               Page   60
3660
 
3661
 
3662
 
3663
 
3664
 5882  F93C60  A5 08         		lda	track
3665
 5883  F93C62  48            		pha
3666
 5884  F93C63  4B            		phk			; bank of format str
3667
 5885  F93C64  F4 90 3C      		pea	#!?100		; address of format str
3668
 5886  F93C67  A9 07         		lda	#7		; # params
3669
 5887  F93C69  48            		pha
3670
 5888  F93C6A                		BPRINTF
3671
 5889  F93C6A  02 11         		cop	$11
3672
 5890                        		.MNLIST
3673
 5891  F93C6C  A6 42         		ldx	char		; 0 if drive 1, 1 if drive 0
3674
 5892  F93C6E  B5 70         		lda	trkbuf,x	; A=dma buffer #
3675
 5893  F93C70  A6 35         		ldx	fildrv+1	; X=src drive
3676
 5894  F93C72  20 63 58      		jsr	readtk		; read whole track
3677
 5895  F93C75  A6 42         		ldx	char		; 0 if drive 1, 1 if drive 0
3678
 5896  F93C77  B5 70         		lda	trkbuf,x	; A=dma buffer #
3679
 5897  F93C79  A6 19         		ldx	drvnum		; X=dest drive
3680
 5898  F93C7B  20 DF 57      		jsr	writetk		; write whole track
3681
 5899  F93C7E  E6 08         		inc	track
3682
 5900  F93C80  A5 08         		lda	track
3683
 5901  F93C82  C9 51         		cmp	#maxtrk
3684
 5902  F93C84  90 CD         		bcc	?10
3685
 5903  F93C86                		SCN_CR
3686
 5904  F93C86                		SCNPRCHAR
3687
 5905                        		.MLIST
3688
 5906  F93C86  02 07         		cop	$07
3689
 5907                        		.MNLIST
3690
 5908  F93C88  0D            		.DB	$0D
3691
 5909                        		.MNLIST
3692
 5910  F93C89  A6 19         		ldx	drvnum
3693
 5911  F93C8B  74 68         		stz	drvfg,x		; invalid drive
3694
 5912  F93C8D  4C 6A 56      		jmp	drvint		; init dest drive
3695
 5913
3696
 5914  F93C90  63 6F 70 79 20 	?100:	.DB	'copy track #%02bu from drive #%bu to drive #%bu', $00
3697
               74 72 61 63 6B
3698
               20 23 25 30 32
3699
               62 75 20 66 72
3700
               6F 6D 20 64 72
3701
               69 76 65 20 23
3702
               25 62 75 20 74
3703
               6F 20 64 72 69
3704
               76 65 20 23 25
3705
               62 75 00
3706
 5915
3707
 5916                        	;---------------------------------------------------------------------------
3708
 5917                        	; block-op commands
3709
 5918                        	;---------------------------------------------------------------------------
3710
 5919
3711
 5920                        	; U1 & U2 commands
3712
 5921                        	; U1 is the same of B-R and U2 is the same of B-W
3713
 5922                        	; U1: ch dr trk blk
3714
 5923                        	; U1: ch,dr,trk,blk
3715
 5924                        	; U2: ch dr trk blk
3716
 5925                        	; U2: ch,dr,trk,blk
3717
 5926  F93CC0                	blku:
3718
 5927  F93CC0  AD 01 E1      		lda	!cmdbuf+1
3719
 5928  F93CC3  3A            		dec	a
3720
 5929  F93CC4  C9 30         		cmp	#'0'
3721
  Tue Jul 17 11:00:19 2018                                                                                               Page   61
3722
 
3723
 
3724
 
3725
 
3726
 5930  F93CC6  F0 04         		beq	?02
3727
 5931  F93CC8  C9 31         		cmp	#'1'
3728
 5932  F93CCA  D0 07         		bne	e_badcmd2
3729
 5933  F93CCC  29 01         	?02:	and	#$01
3730
 5934  F93CCE  AA            		tax			; X=0 => R, X=1 => W
3731
 5935  F93CCF  A0 02         		ldy	#$02		; index next char
3732
 5936  F93CD1  80 21         		bra	blkprs
3733
 5937
3734
 5938  F93CD3                	e_badcmd2:
3735
 5939  F93CD3  4C FD 40      		jmp	e_badcmd
3736
 5940
3737
 5941  F93CD6                	e_badsyn2:
3738
 5942  F93CD6  4C 05 41      		jmp	e_badsyn
3739
 5943
3740
 5944                        	; block-op commands
3741
 5945                        	; B-R: ch dr trk blk
3742
 5946                        	; B-R: ch,dr,trk,blk
3743
 5947                        	; B-W: ch dr trk blk
3744
 5948                        	; B-W: ch,dr,trk,blk
3745
 5949                        	; B-A: dr trk blk
3746
 5950                        	; B-A: dr,trk,blk
3747
 5951                        	; B-F: dr trk blk
3748
 5952                        	; B-F: dr,trk,blk
3749
 5953                        	; B-P: ch pos
3750
 5954                        	; B-P: ch,pos
3751
 5955  F93CD9                	blkb:
3752
 5956  F93CD9  AD 01 E1      		lda	!cmdbuf+1
3753
 5957  F93CDC  C9 2D         		cmp	#'-'		; subcommands seperator
3754
 5958  F93CDE  D0 F6         		bne	e_badsyn2
3755
 5959  F93CE0  A2 04         		ldx	#ncmds2-1
3756
 5960  F93CE2  AD 02 E1      		lda	!cmdbuf+2
3757
 5961  F93CE5  F0 EF         		beq	e_badsyn2	; syntax error if no more char's
3758
 5962  F93CE7  DF 69 5A F9   	?02:	cmp	>cmdstb,x	; match subcommand
3759
 5963  F93CEB  F0 05         		beq	?04
3760
 5964  F93CED  CA            		dex
3761
 5965  F93CEE  10 F7         		bpl	?02
3762
 5966  F93CF0  30 E1         		bmi	e_badcmd2	; error
3763
 5967  F93CF2  A0 03         	?04:	ldy	#3		; index next char
3764
 5968
3765
 5969                        	; common routine for block-op
3766
 5970                        	; X=0 => R, X=1 => W, X=2 => A, X=3 => F, X=4 => P
3767
 5971  F93CF4                	blkprs:
3768
 5972  F93CF4  86 55         		stx	subcmd		; subcommand
3769
 5973  F93CF6  B9 00 E1      		lda	cmdbuf,y	; must be seperator
3770
 5974  F93CF9  C9 3A         		cmp	#':'
3771
 5975  F93CFB  D0 D9         		bne	e_badsyn2
3772
 5976  F93CFD  C8            	?02:	iny
3773
 5977  F93CFE  B9 00 E1      		lda	cmdbuf,y
3774
 5978  F93D01  F0 D3         		beq	e_badsyn2	; end of string is an error here
3775
 5979  F93D03  C9 20         		cmp	#' '		; skip blanks after semicolon
3776
 5980  F93D05  F0 F6         		beq	?02
3777
 5981  F93D07  A2 FF         		ldx	#$FF		; table index
3778
 5982  F93D09  E8            	?04:	inx
3779
 5983  F93D0A  E0 04         		cpx	#mxfils-1
3780
 5984  F93D0C  B0 C8         		bcs	e_badsyn2	; full param's table
3781
 5985  F93D0E  20 B5 3D      		jsr	asc2bin		; convert ascii to byte and put in table
3782
 5986  F93D11  88            		dey
3783
  Tue Jul 17 11:00:19 2018                                                                                               Page   62
3784
 
3785
 
3786
 
3787
 
3788
 5987  F93D12  C8            	?06:	iny
3789
 5988  F93D13  B9 00 E1      		lda	cmdbuf,y	; loop for param's parsing
3790
 5989  F93D16  F0 0A         		beq	?08		; end parsing
3791
 5990  F93D18  C9 20         		cmp	#' '		; skip blank seperator
3792
 5991  F93D1A  F0 F6         		beq	?06
3793
 5992  F93D1C  C9 2C         		cmp	#','		; skip comma seperator
3794
 5993  F93D1E  F0 F2         		beq	?06
3795
 5994  F93D20  D0 E7         		bne	?04		; parse next digit
3796
 5995  F93D22  E8            	?08:	inx
3797
 5996  F93D23  86 12         		stx	f1cnt		; param's counter
3798
 5997  F93D25  A9 04         		lda	#4		; 4 param's for R, W (0 & 1)
3799
 5998  F93D27  A4 55         		ldy	subcmd
3800
 5999  F93D29  F0 0B         		beq	?10
3801
 6000  F93D2B  88            		dey
3802
 6001  F93D2C  F0 08         		beq	?10
3803
 6002  F93D2E  3A            		dec	a		; 3 param's for A, F (2 & 3)
3804
 6003  F93D2F  88            		dey
3805
 6004  F93D30  F0 04         		beq	?10
3806
 6005  F93D32  88            		dey
3807
 6006  F93D33  F0 01         		beq	?10
3808
 6007  F93D35  3A            		dec	a		; 2 param's for P (4)
3809
 6008  F93D36  85 1F         	?10:	sta	tmpxxx
3810
 6009  F93D38  E4 1F         		cpx	tmpxxx
3811
 6010  F93D3A  D0 9A         		bne	e_badsyn2	; wrong param's count
3812
 6011  F93D3C  A4 55         		ldy	subcmd
3813
 6012  F93D3E  C0 04         		cpy	#4
3814
 6013  F93D40  B0 0F         		bcs	?14		; skip drive check for P subcmd
3815
 6014  F93D42  A2 01         		ldx	#1		; for R,W second param is drive number
3816
 6015  F93D44  C0 02         		cpy	#2
3817
 6016  F93D46  90 01         		bcc	?12
3818
 6017  F93D48  CA            		dex			; for A,F first param is drive number
3819
 6018  F93D49  B5 25         	?12:	lda	filsec,x	; check drive number
3820
 6019  F93D4B  C9 02         		cmp	#2
3821
 6020  F93D4D  B0 3A         		bcs	e_baddrv
3822
 6021  F93D4F  85 19         		sta	drvnum
3823
 6022  F93D51  C0 02         	?14:	cpy	#2		; check channel # for R(0),W(1),P(4)
3824
 6023  F93D53  90 04         		bcc	?16
3825
 6024  F93D55  C0 04         		cpy	#4
3826
 6025  F93D57  D0 0C         		bne	?18
3827
 6026  F93D59  A5 25         	?16:	lda	filsec		; channel # is first param
3828
 6027  F93D5B  C9 02         		cmp	#2		; valid channel: 2..14
3829
 6028  F93D5D  90 2F         		bcc	e_badchn
3830
 6029  F93D5F  C9 0F         		cmp	#15
3831
 6030  F93D61  B0 2B         		bcs	e_badchn
3832
 6031  F93D63  85 52         		sta	chnl
3833
 6032  F93D65  C0 04         	?18:	cpy	#4
3834
 6033  F93D67  F0 1A         		beq	?22		; skip trk & sec check for P subcmd
3835
 6034  F93D69  A2 01         		ldx	#1		; trk for A, F
3836
 6035  F93D6B  C0 02         		cpy	#2
3837
 6036  F93D6D  B0 01         		bcs	?20
3838
 6037  F93D6F  E8            		inx			; trk for R, W
3839
 6038  F93D70  B5 25         	?20:	lda	filsec,x
3840
 6039  F93D72  85 08         		sta	track
3841
 6040  F93D74  F0 1D         		beq	e_badts
3842
 6041  F93D76  C9 51         		cmp	#maxtrk
3843
 6042  F93D78  B0 19         		bcs	e_badts
3844
 6043  F93D7A  E8            		inx			; check sector #
3845
  Tue Jul 17 11:00:19 2018                                                                                               Page   63
3846
 
3847
 
3848
 
3849
 
3850
 6044  F93D7B  B5 25         		lda	filsec,x
3851
 6045  F93D7D  85 09         		sta	sector
3852
 6046  F93D7F  C9 28         		cmp	#numsec
3853
 6047  F93D81  B0 10         		bcs	e_badts
3854
 6048  F93D83  98            	?22:	tya
3855
 6049  F93D84  0A            		asl	a
3856
 6050  F93D85  AA            		tax
3857
 6051  F93D86  7C E6 5A      		jmp	(scjmp,x)
3858
 6052
3859
 6053  F93D89                	e_baddrv:
3860
 6054  F93D89  A9 23         		lda	#baddrv
3861
 6055  F93D8B  4C F5 56      		jmp	drverr
3862
 6056
3863
 6057  F93D8E                	e_badchn:
3864
 6058  F93D8E  A9 24         		lda	#badchn
3865
 6059  F93D90  4C ED 56      		jmp	chnerr
3866
 6060
3867
 6061  F93D93                	e_badts:
3868
 6062  F93D93  A9 42         		lda	#badts
3869
 6063  F93D95  4C FB 56      		jmp	doserr
3870
 6064
3871
 6065                        	; check drive number in A
3872
 6066                        	; in:	A = digit drive number ('0', '1', ...)
3873
 6067                        	;	Y = 0 if check cbm drive (just 0,1)
3874
 6068                        	;	Y = $FF if check dos drive (0..7)
3875
 6069                        	; out:	A = drive number (0, 1, ...)
3876
 6070  F93D98                	chkdrv:
3877
 6071  F93D98  C9 30         		cmp	#'0'		; drive 0 and 1 always valid
3878
 6072  F93D9A  F0 16         		beq	?02
3879
 6073  F93D9C  C9 31         		cmp	#'1'
3880
 6074  F93D9E  F0 12         		beq	?02
3881
 6075  F93DA0  C8            		iny			; not zero if check cbm drive
3882
 6076  F93DA1  D0 E6         		bne	e_baddrv	; invalid cbm drive
3883
 6077  F93DA3  C9 38         		cmp	#'8'
3884
 6078  F93DA5  B0 E2         		bcs	e_baddrv	; valid dos drive: 0..7
3885
 6079  F93DA7  C9 30         		cmp	#'0'
3886
 6080  F93DA9  90 DE         		bcc	e_baddrv
3887
 6081  F93DAB  E9 30         		sbc	#'0'
3888
 6082  F93DAD  C9 04         		cmp	#MAXDOSDRV
3889
 6083  F93DAF  B0 D8         		bcs	e_baddrv
3890
 6084  F93DB1  60            		rts
3891
 6085  F93DB2  29 01         	?02:	and	#$01
3892
 6086  F93DB4  60            		rts
3893
 6087
3894
 6088                        	; convert ascii string to byte
3895
 6089                        	; in:	A = first digit
3896
 6090                        	;	X = table index
3897
 6091                        	;	Y = cmdbuf index
3898
 6092                        	; out:	X = table index
3899
 6093                        	;	Y = index of first not-digit
3900
 6094  F93DB5                	asc2bin:
3901
 6095  F93DB5  64 1F         		stz	tmpxxx		; partial value
3902
 6096  F93DB7  C9 30         		cmp	#'0'		; first char must be a digit
3903
 6097  F93DB9  90 2F         		bcc	?08
3904
 6098  F93DBB  C9 3A         		cmp	#'9'+1
3905
 6099  F93DBD  B0 2B         		bcs	?08
3906
 6100  F93DBF  E9 2F         	?02:	sbc	#'0'-1		; convert digit (here always CF = 0)
3907
  Tue Jul 17 11:00:19 2018                                                                                               Page   64
3908
 
3909
 
3910
 
3911
 
3912
 6101  F93DC1  EB            		xba			; B = digit
3913
 6102  F93DC2  18            		clc
3914
 6103  F93DC3  A5 1F         		lda	tmpxxx		; partial null?
3915
 6104  F93DC5  F0 0B         		beq	?04		; yes, skip mult * 10
3916
 6105  F93DC7  C9 1A         		cmp	#26		; this value make overflow
3917
 6106  F93DC9  B0 1F         		bcs	?08
3918
 6107  F93DCB  0A            		asl	a		; safety multiply * 10
3919
 6108  F93DCC  0A            		asl	a
3920
 6109  F93DCD  65 1F         		adc	tmpxxx
3921
 6110  F93DCF  0A            		asl	a		; always carry = 0 here
3922
 6111  F93DD0  85 1F         		sta	tmpxxx
3923
 6112  F93DD2  EB            	?04:	xba
3924
 6113  F93DD3  65 1F         		adc	tmpxxx
3925
 6114  F93DD5  B0 13         		bcs	?08		; overflow
3926
 6115  F93DD7  85 1F         		sta	tmpxxx
3927
 6116  F93DD9  C8            		iny			; next char
3928
 6117  F93DDA  B9 00 E1      		lda	cmdbuf,y
3929
 6118  F93DDD  C9 30         		cmp	#'0'		; continue conversion if next char is a digit
3930
 6119  F93DDF  90 04         		bcc	?06
3931
 6120  F93DE1  C9 3A         		cmp	#'9'+1
3932
 6121  F93DE3  90 DA         		bcc	?02
3933
 6122  F93DE5  A5 1F         	?06:	lda	tmpxxx		; store value in table
3934
 6123  F93DE7  95 25         		sta	filsec,x
3935
 6124  F93DE9  60            		rts
3936
 6125
3937
 6126  F93DEA  4C 05 41      	?08:	jmp	e_badsyn
3938
 6127
3939
 6128                        	; block read
3940
 6129  F93DED                	blkrd:
3941
 6130  F93DED  20 69 3F      		jsr	tstda		; check direct access fd type
3942
 6131  F93DF0  20 79 3F      		jsr	dskbuf		; set tlp ptr to buffer return X=drive...
3943
 6132  F93DF3
3944
 6133                        		; param's in reverse order
3945
 6134  F93DF3  A5 09         		lda	sector
3946
 6135  F93DF5  48            		pha
3947
 6136  F93DF6  A5 08         		lda	track
3948
 6137  F93DF8  48            		pha
3949
 6138  F93DF9  A5 19         		lda	drvnum
3950
 6139  F93DFB  48            		pha
3951
 6140  F93DFC  A5 52         		lda	chnl
3952
 6141  F93DFE  48            		pha
3953
 6142  F93DFF  A9 F9         		lda	#^?01
3954
 6143  F93E01  48            		pha
3955
 6144  F93E02  F4 34 3E      		pea	#!?01
3956
 6145  F93E05  A9 08         		lda	#8		; num params
3957
 6146  F93E07  48            		pha
3958
 6147  F93E08                		BPRINTF
3959
 6148  F93E08  02 11         		cop	$11
3960
 6149                        		.MNLIST
3961
 6150
3962
 6151
3963
 6152  F93E0A  20 B7 58      		jsr	readsec
3964
 6153  F93E0D  A5 09         		lda	sector
3965
 6154  F93E0F  4A            		lsr	a
3966
 6155  F93E10  90 02         		bcc	?02
3967
 6156  F93E12  E6 3F         		inc	tlp+1		; odd sector
3968
 6157  F93E14  A0 00         	?02:	ldy	#0
3969
  Tue Jul 17 11:00:19 2018                                                                                               Page   65
3970
 
3971
 
3972
 
3973
 
3974
 6158  F93E16  B7 3E         	?04:	lda	[tlp],y
3975
 6159  F93E18  97 8A         		sta	[bufp],y
3976
 6160  F93E1A  C8            		iny
3977
 6161  F93E1B  D0 F9         		bne	?04
3978
 6162                        		;rts
3979
 6163  F93E1D  A5 F6         		lda	pbuf
3980
 6164  F93E1F  48            		pha
3981
 6165  F93E20  A5 40         		lda	tlp+2
3982
 6166  F93E22  48            		pha
3983
 6167  F93E23  D4 3E         		pei	(tlp)
3984
 6168  F93E25  A5 8C         		lda	bufp+2
3985
 6169  F93E27  48            		pha
3986
 6170  F93E28  D4 8A         		pei	(bufp)
3987
 6171  F93E2A  4B            		phk
3988
 6172  F93E2B  F4 65 3E      		pea	#!?10
3989
 6173  F93E2E  A9 0B         		lda	#11
3990
 6174  F93E30  48            		pha
3991
 6175  F93E31                		BPRINTF
3992
 6176  F93E31  02 11         		cop	$11
3993
 6177                        		.MNLIST
3994
 6178  F93E33  60            		rts
3995
 6179  F93E34                	?01:
3996
 6180  F93E34  0D 42 2D 52 3A 		.DB	$0D, 'B-R: chnl=%bd, drive=%bd, track=%bd, sector=%bd', 0
3997
               20 63 68 6E 6C
3998
               3D 25 62 64 2C
3999
               20 64 72 69 76
4000
               65 3D 25 62 64
4001
               2C 20 74 72 61
4002
               63 6B 3D 25 62
4003
               64 2C 20 73 65
4004
               63 74 6F 72 3D
4005
               25 62 64 00
4006
 6181  F93E65  0D 62 75 66 70 	?10:	.DB	$0D, 'bufp: %P, tlp: %P, DMA: %bX', 0
4007
               3A 20 25 50 2C
4008
               20 74 6C 70 3A
4009
               20 25 50 2C 20
4010
               44 4D 41 3A 20
4011
               25 62 58 00
4012
 6182
4013
 6183                        	; block write
4014
 6184  F93E82                	blkwr:
4015
 6185                        		; param's in reverse order
4016
 6186  F93E82  A5 09         		lda	sector
4017
 6187  F93E84  48            		pha
4018
 6188  F93E85  A5 08         		lda	track
4019
 6189  F93E87  48            		pha
4020
 6190  F93E88  A5 19         		lda	drvnum
4021
 6191  F93E8A  48            		pha
4022
 6192  F93E8B  A5 54         		lda	bchn
4023
 6193  F93E8D  48            		pha
4024
 6194  F93E8E  A9 F9         		lda	#^?01
4025
 6195  F93E90  48            		pha
4026
 6196  F93E91  F4 9A 3E      		pea	#!?01
4027
 6197  F93E94  A9 08         		lda	#8		; num params
4028
 6198  F93E96  48            		pha
4029
 6199  F93E97                		BPRINTF
4030
 6200  F93E97  02 11         		cop	$11
4031
  Tue Jul 17 11:00:19 2018                                                                                               Page   66
4032
 
4033
 
4034
 
4035
 
4036
 6201                        		.MNLIST
4037
 6202  F93E99  60            		rts
4038
 6203  F93E9A                	?01:
4039
 6204  F93E9A  42 2D 57 3A 20 		.DB	'B-W: chnl=%bd, drive=%bd, track=%bd, sector=%bd', 0
4040
               63 68 6E 6C 3D
4041
               25 62 64 2C 20
4042
               64 72 69 76 65
4043
               3D 25 62 64 2C
4044
               20 74 72 61 63
4045
               6B 3D 25 62 64
4046
               2C 20 73 65 63
4047
               74 6F 72 3D 25
4048
               62 64 00
4049
 6205
4050
 6206                        	; block allocate sector
4051
 6207  F93ECA                	blkalc:
4052
 6208                        		; param's in reverse order
4053
 6209  F93ECA  A5 09         		lda	sector
4054
 6210  F93ECC  48            		pha
4055
 6211  F93ECD  A5 08         		lda	track
4056
 6212  F93ECF  48            		pha
4057
 6213  F93ED0  A5 19         		lda	drvnum
4058
 6214  F93ED2  48            		pha
4059
 6215  F93ED3  A9 F9         		lda	#^?01
4060
 6216  F93ED5  48            		pha
4061
 6217  F93ED6  F4 DF 3E      		pea	#!?01
4062
 6218  F93ED9  A9 07         		lda	#7		; num params
4063
 6219  F93EDB  48            		pha
4064
 6220  F93EDC                		BPRINTF
4065
 6221  F93EDC  02 11         		cop	$11
4066
 6222                        		.MNLIST
4067
 6223  F93EDE  60            		rts
4068
 6224  F93EDF                	?01:
4069
 6225  F93EDF  42 2D 41 3A 20 		.DB	'B-A: drive=%bd, track=%bd, sector=%bd', 0
4070
               64 72 69 76 65
4071
               3D 25 62 64 2C
4072
               20 74 72 61 63
4073
               6B 3D 25 62 64
4074
               2C 20 73 65 63
4075
               74 6F 72 3D 25
4076
               62 64 00
4077
 6226
4078
 6227                        	; block free sector
4079
 6228  F93F05                	blkfree:
4080
 6229                        		; param's in reverse order
4081
 6230  F93F05  A5 09         		lda	sector
4082
 6231  F93F07  48            		pha
4083
 6232  F93F08  A5 08         		lda	track
4084
 6233  F93F0A  48            		pha
4085
 6234  F93F0B  A5 19         		lda	drvnum
4086
 6235  F93F0D  48            		pha
4087
 6236  F93F0E  A9 F9         		lda	#^?01
4088
 6237  F93F10  48            		pha
4089
 6238  F93F11  F4 1A 3F      		pea	#!?01
4090
 6239  F93F14  A9 07         		lda	#7		; num params
4091
 6240  F93F16  48            		pha
4092
 6241  F93F17                		BPRINTF
4093
  Tue Jul 17 11:00:19 2018                                                                                               Page   67
4094
 
4095
 
4096
 
4097
 
4098
 6242  F93F17  02 11         		cop	$11
4099
 6243                        		.MNLIST
4100
 6244  F93F19  60            		rts
4101
 6245  F93F1A                	?01:
4102
 6246  F93F1A  42 2D 46 3A 20 		.DB	'B-F: drive=%bd, track=%bd, sector=%bd', 0
4103
               64 72 69 76 65
4104
               3D 25 62 64 2C
4105
               20 74 72 61 63
4106
               6B 3D 25 62 64
4107
               2C 20 73 65 63
4108
               74 6F 72 3D 25
4109
               62 64 00
4110
 6247
4111
 6248                        	; block set buffer position
4112
 6249                        	; pos is in filsec+1
4113
 6250  F93F40                	blkpos:
4114
 6251
4115
 6252                        		; param's in reverse order
4116
 6253  F93F40  A5 26         		lda	filsec+1
4117
 6254  F93F42  48            		pha
4118
 6255  F93F43  A5 54         		lda	bchn
4119
 6256  F93F45  48            		pha
4120
 6257  F93F46  A9 F9         		lda	#^?01
4121
 6258  F93F48  48            		pha
4122
 6259  F93F49  F4 52 3F      		pea	#!?01
4123
 6260  F93F4C  A9 06         		lda	#6; num params
4124
 6261  F93F4E  48            		pha
4125
 6262  F93F4F                		BPRINTF
4126
 6263  F93F4F  02 11         		cop	$11
4127
 6264                        		.MNLIST
4128
 6265  F93F51  60            		rts
4129
 6266  F93F52                	?01:
4130
 6267  F93F52  42 2D 50 3A 20 		.DB	'B-P: chnl=%bd, pos=%bu', 0
4131
               63 68 6E 6C 3D
4132
               25 62 64 2C 20
4133
               70 6F 73 3D 25
4134
               62 75 00
4135
 6268
4136
 6269                        	; check that chnl is open and direct type access
4137
 6270  F93F69                	tstda:
4138
 6271  F93F69  20 F2 48      		jsr	isopn		; check chn is open
4139
 6272  F93F6C  20 CA 48      		jsr	fnddafd		; check is direct access type
4140
 6273  F93F6F  B0 03         		bcs	?10
4141
 6274  F93F71  4C 15 49      		jmp	setfdp		; set buffer for this fd & return X=lindx
4142
 6275  F93F74  A9 40         	?10:	lda	#mistyp
4143
 6276  F93F76  4C ED 56      		jmp	chnerr		; file type mismatch
4144
 6277
4145
 6278                        	; set buffer pointer for block-read / block-write
4146
 6279                        	; buffer is after dir. cache of the selected drive
4147
 6280                        	; set tmpxxx to dma buffer #
4148
 6281                        	; set Y=wtmp to phisycal sector
4149
 6282                        	; set pside to side
4150
 6283  F93F79                	dskbuf:
4151
 6284  F93F79  20 6A 56      		jsr	drvint		; init drive
4152
 6285  F93F7C  A6 19         		ldx	drvnum		; set buffer ptr
4153
 6286  F93F7E  86 F2         		stx	pdrv
4154
 6287  F93F80  B5 6E         		lda	sysbuf,x	; dma # of dir. cache
4155
  Tue Jul 17 11:00:19 2018                                                                                               Page   68
4156
 
4157
 
4158
 
4159
 
4160
 6288  F93F82  18            		clc
4161
 6289  F93F83  69 14         		adc	#phisec*2
4162
 6290  F93F85  1A            		inc	a
4163
 6291  F93F86  65 57         		adc	lindx
4164
 6292  F93F88  85 F6         		sta	pbuf
4165
 6293  F93F8A  A0 02         		ldy	#DMABNK		; bank for buffer #00..#7F
4166
 6294  F93F8C  0A            		asl	a		; get high pointer
4167
 6295  F93F8D  90 01         		bcc	?02
4168
 6296  F93F8F  C8            		iny			; next bank
4169
 6297  F93F90  64 3E         	?02:	stz	tlp
4170
 6298  F93F92  85 3F         		sta	tlp+1
4171
 6299  F93F94  84 40         		sty	tlp+2
4172
 6300  F93F96  A5 09         		lda	sector		; 0..39
4173
 6301  F93F98  4A            		lsr	a		; 0..19
4174
 6302  F93F99  A0 00         		ldy	#0		; side 0
4175
 6303  F93F9B  C9 0A         		cmp	#phisec		; 0..9 -> side 0, 10..19 -> side 1
4176
 6304  F93F9D  90 03         		bcc	?04
4177
 6305  F93F9F  E9 0A         		sbc	#phisec
4178
 6306  F93FA1  C8            		iny			; side 1
4179
 6307  F93FA2  1A            	?04:	inc	a		; A = phisycal sec
4180
 6308  F93FA3  85 F4         		sta	psec
4181
 6309  F93FA5  84 F3         		sty	pside
4182
 6310  F93FA7  A9 01         		lda	#1
4183
 6311  F93FA9  85 F5         		sta	pcnt
4184
 6312  F93FAB  60            		rts
4185
 6313
4186
 6314                        	;---------------------------------------------------------------------------
4187
 6315                        	; names string utilities
4188
 6316                        	;---------------------------------------------------------------------------
4189
 6317
4190
 6318                        	; build canonical file name's table
4191
 6319                        	; check for empty or too long file name
4192
 6320                        	; check for not allowed char's in file name
4193
 6321                        	; convert '*' in right number of '?'
4194
 6322                        	; pad file name with $A0
4195
 6323  F93FAC                	buildfn:
4196
 6324  F93FAC  A2 00         		ldx	#0
4197
 6325  F93FAE  A9 61         		lda	#<fntab		; set ptr to first file name
4198
 6326  F93FB0  85 3E         		sta	tlp
4199
 6327  F93FB2  A9 E1         		lda	#>fntab
4200
 6328  F93FB4  85 3F         		sta	tlp+1
4201
 6329  F93FB6  86 14         	?02:	stx	f1ptr		; table index
4202
 6330  F93FB8  B5 34         		lda	fildrv,x
4203
 6331  F93FBA  85 1F         		sta	tmpxxx		; ibm/dos drive flag (bit 6)
4204
 6332  F93FBC  B5 1A         		lda	filtbl,x
4205
 6333  F93FBE  AA            		tax			; pointer to string
4206
 6334  F93FBF  20 55 40      		jsr	fndlmt		; find string limit
4207
 6335  F93FC2  98            		tya			; string size
4208
 6336  F93FC3  D0 03         		bne	?03
4209
 6337  F93FC5  4C 01 41      		jmp	e_nofile	; empty: no file given error
4210
 6338  F93FC8  24 1F         	?03:	bit	tmpxxx
4211
 6339  F93FCA  70 48         		bvs	?18		; canonical ibm/dos file name
4212
 6340  F93FCC  C9 11         		cmp	#17
4213
 6341  F93FCE  B0 27         		bcs	?08		; too long: badfn error
4214
 6342  F93FD0  BD 00 E1      		lda	!cmdbuf,x	; check if string start with blank
4215
 6343  F93FD3  C9 20         		cmp	#' '
4216
 6344  F93FD5  F0 20         		beq	?08		; first char is blank: badfn error
4217
  Tue Jul 17 11:00:19 2018                                                                                               Page   69
4218
 
4219
 
4220
 
4221
 
4222
 6345  F93FD7  A0 00         		ldy	#0		; store canonical file name
4223
 6346  F93FD9  BD 00 E1      	?04:	lda	!cmdbuf,x
4224
 6347  F93FDC  F0 22         		beq	?12		; end of string
4225
 6348  F93FDE  86 42         		stx	char
4226
 6349  F93FE0  A2 05         		ldx	#nbadch-1	; check forbidden char's in file name
4227
 6350  F93FE2  DF 96 5A F9   	?06:	cmp	>badchr,x
4228
 6351  F93FE6  F0 0F         		beq	?08		; bad char: badfn error
4229
 6352  F93FE8  CA            		dex
4230
 6353  F93FE9  10 F7         		bpl	?06
4231
 6354  F93FEB  A6 42         		ldx	char
4232
 6355  F93FED  C9 2A         		cmp	#'*'		; special char
4233
 6356  F93FEF  F0 0B         		beq	?10		; handle star char
4234
 6357  F93FF1  91 3E         		sta	(tlp),y		; store char
4235
 6358  F93FF3  E8            		inx
4236
 6359  F93FF4  C8            		iny
4237
 6360  F93FF5  80 E2         		bra	?04		; loop
4238
 6361  F93FF7  A9 21         	?08:	lda	#badfn		; badfn error
4239
 6362  F93FF9  4C 07 41      		jmp	cmderr
4240
 6363  F93FFC  A9 3F         	?10:	lda	#'?'		; fill residual name with '?'
4241
 6364  F93FFE  80 02         		bra	?14
4242
 6365  F94000  A9 A0         	?12:	lda	#$A0		; pad name with $A0
4243
 6366  F94002  88            	?14:	dey
4244
 6367  F94003  C8            	?16:	iny
4245
 6368  F94004  C0 10         		cpy	#16
4246
 6369  F94006  B0 04         		bcs	?17
4247
 6370  F94008  91 3E         		sta	(tlp),y
4248
 6371  F9400A  80 F7         		bra	?16
4249
 6372  F9400C  A9 00         	?17:	lda	#0		; string terminator
4250
 6373  F9400E  91 3E         		sta	(tlp),y
4251
 6374  F94010  C8            		iny			; offset to add for next string
4252
 6375  F94011  18            		clc
4253
 6376  F94012  80 05         		bra	?20
4254
 6377  F94014  20 2A 40      	?18:	jsr	dosfn		; handle dos file name
4255
 6378  F94017  B0 DE         		bcs	?08		; bad dos file name
4256
 6379  F94019  A5 3E         	?20:	lda	tlp		; set new file name pointer
4257
 6380  F9401B  A6 14         		ldx	f1ptr
4258
 6381  F9401D  95 1A         		sta	filtbl,x
4259
 6382  F9401F  98            		tya
4260
 6383  F94020  65 3E         		adc	tlp		; here always CF = 0
4261
 6384  F94022  85 3E         		sta	tlp		; always stay in the same page !
4262
 6385  F94024  E8            		inx			; next file name
4263
 6386  F94025  E4 13         		cpx	f2cnt
4264
 6387  F94027  90 8D         		bcc	?02
4265
 6388  F94029  60            		rts
4266
 6389
4267
 6390                        	; get canonical name of dos file name
4268
 6391  F9402A                	dosfn:
4269
 6392  F9402A  CA            		dex			; store 'X:' at beginning
4270
 6393  F9402B  CA            		dex
4271
 6394  F9402C  A5 1F         		lda	tmpxxx
4272
 6395  F9402E  29 07         		and	#7
4273
 6396  F94030  18            		clc
4274
 6397  F94031  69 41         		adc	#'A'		; convert in drive letter
4275
 6398  F94033  9D 00 E1      		sta	!cmdbuf,x
4276
 6399  F94036  A9 3A         		lda	#':'
4277
 6400  F94038  9D 01 E1      		sta	!cmdbuf+1,x	; check name type A:/xxx...
4278
 6401  F9403B  A9 00         		lda	#0		; bank of src string
4279
  Tue Jul 17 11:00:19 2018                                                                                               Page   70
4280
 
4281
 
4282
 
4283
 
4284
 6402  F9403D  48            		pha
4285
 6403  F9403E  A9 E1         		lda	#>cmdbuf
4286
 6404  F94040  48            		pha			; pointer of source string
4287
 6405  F94041  A9 00         		lda	#<cmdbuf
4288
 6406  F94043  86 42         		stx	char
4289
 6407  F94045  65 42         		adc	char		; add offset
4290
 6408  F94047  48            		pha
4291
 6409  F94048  A9 00         		lda	#0		; bank of dest string
4292
 6410  F9404A  48            		pha
4293
 6411  F9404B  D4 3E         		pei	(tlp)		; dest string pointer
4294
 6412  F9404D  A9 80         		lda	#$80
4295
 6413  F9404F  48            		pha			; fileflag (file)
4296
 6414  F94050                		TRUENAM			; get canonical name (sys call)
4297
 6415  F94050  02 FE         		cop	$FE
4298
 6416                        		.MNLIST
4299
 6417  F94052  A0 50         		ldy	#80		; offset to add for next string
4300
 6418  F94054  60            		rts
4301
 6419
4302
 6420                        	; find string limit in cmdbuf pointed to by X
4303
 6421                        	; in:	X = string pointer
4304
 6422                        	; out:	X = string pointer
4305
 6423                        	;	Y = string size
4306
 6424  F94055                	fndlmt:
4307
 6425  F94055  DA            		phx			; save ptr
4308
 6426  F94056  A0 00         		ldy	#0		; string size
4309
 6427  F94058  BD 00 E1      	?02:	lda	!cmdbuf,x
4310
 6428  F9405B  F0 0F         		beq	?06		; end of string
4311
 6429  F9405D  C9 2C         		cmp	#','
4312
 6430  F9405F  F0 08         		beq	?04		; 'comma' limited
4313
 6431  F94061  C9 3D         		cmp	#'='
4314
 6432  F94063  F0 04         		beq	?04		; 'equal' limited
4315
 6433  F94065  C8            		iny
4316
 6434  F94066  E8            		inx
4317
 6435  F94067  80 EF         		bra	?02		; loop next char
4318
 6436  F94069  9E 00 E1      	?04:	stz	!cmdbuf,x	; string limit
4319
 6437  F9406C  FA            	?06:	plx			; restore ptr
4320
 6438  F9406D  60            		rts
4321
 6439
4322
 6440                        	;---------------------------------------------------------------------------
4323
 6441                        	; parse command string utilities
4324
 6442                        	;---------------------------------------------------------------------------
4325
 6443
4326
 6444                        	; special case: parse command string for copy command
4327
 6445  F9406E                	prscpy:
4328
 6446  F9406E  20 6A 42      		jsr	prscln		; find ":"
4329
 6447  F94071  D0 21         		bne	?20		; ok, found ":"
4330
 6448  F94073  20 D7 40      		jsr	prsdtd		; look for "Cddrv=sdrv"
4331
 6449  F94076  A2 5E         	?10:	ldx	#cmdlen-2
4332
 6450  F94078  A9 2A         		lda	#'*'		; put "*" at buffer end
4333
 6451  F9407A  9D 00 E1      		sta	!cmdbuf,x
4334
 6452  F9407D  9E 01 E1      		stz	!cmdbuf+1,x
4335
 6453  F94080  86 1B         		stx	filtbl+1	; file2 ptr -> "*"
4336
 6454  F94082  86 1A         		stx	filtbl		; file1 ptr -> "*"
4337
 6455  F94084  A9 80         		lda	#$80
4338
 6456  F94086  85 3A         		sta	pattyp+1	; file2 pattern flag
4339
 6457  F94088  A2 01         	?14:	ldx	#1		; set up cnt's
4340
 6458  F9408A  86 12         		stx	f1cnt
4341
  Tue Jul 17 11:00:19 2018                                                                                               Page   71
4342
 
4343
 
4344
 
4345
 
4346
 6459  F9408C  E8            		inx
4347
 6460  F9408D  86 13         		stx	f2cnt
4348
 6461  F9408F  A9 80         		lda	#$80		; file1 pattern flag
4349
 6462  F94091  85 39         		sta	pattyp
4350
 6463  F94093  60            		rts
4351
 6464  F94094  20 13 41      	?20:	jsr	tagcmd2		; continue normal parsing
4352
 6465  F94097  20 8D 41      		jsr	alldrs		; put drv's in filtbl
4353
 6466  F9409A  A5 43         		lda	image		; get parse image
4354
 6467  F9409C  29 55         		and	#%01010101	; mask off copy (fs1 & fs2 just one file)
4355
 6468  F9409E  D0 2E         		bne	?30		; concat
4356
 6469  F940A0
4357
 6470                        		; now parse string "ddrv:file1=sdrv:file2"
4358
 6471  F940A0  A6 1A         		ldx	filtbl		; check file1
4359
 6472  F940A2  BD 00 E1      		lda	!cmdbuf,x
4360
 6473  F940A5  C9 2A         		cmp	#'*'		; file1="*"?
4361
 6474  F940A7  F0 04         		beq	?22
4362
 6475  F940A9  C9 3D         		cmp	#'='		; file1 = NULL?
4363
 6476  F940AB  D0 21         		bne	?30		; no, check normal copy
4364
 6477
4365
 6478                        	?22:	; now string is the form "ddrv:*=sdrv:file2" or "ddrv:=sdrv:file2"
4366
 6479                        		; so operation is type DTD with unspecified file1
4367
 6480  F940AD  A5 35         		lda	fildrv+1	; check drv not equal
4368
 6481  F940AF  29 07         		and	#$07
4369
 6482  F940B1  C5 34         		cmp	fildrv
4370
 6483  F940B3  F0 50         		beq	e_badsyn	; cannot be equal
4371
 6484  F940B5  A6 1B         		ldx	filtbl+1	; check file2
4372
 6485  F940B7  BD 00 E1      		lda	!cmdbuf,x
4373
 6486  F940BA  F0 BA         		beq	?10		; file2 = NULL -> file2 = "*"
4374
 6487  F940BC  C9 2A         		cmp	#'*'
4375
 6488  F940BE  F0 B6         		beq	?10		; file2 = "*"
4376
 6489  F940C0  A2 5E         		ldx	#cmdlen-2
4377
 6490  F940C2  A9 2A         		lda	#'*'		; put "*" at buffer end
4378
 6491  F940C4  9D 00 E1      		sta	!cmdbuf,x
4379
 6492  F940C7  9E 01 E1      		stz	!cmdbuf+1,x
4380
 6493  F940CA  86 1A         		stx	filtbl		; file1 ptr -> "*"
4381
 6494  F940CC  80 BA         		bra	?14		; retain file2, file1 pattern flag
4382
 6495
4383
 6496                        	?30:	; check for normal copy: no pattern, fs1=1 file, fs2=n files
4384
 6497  F940CE  A5 43         		lda	image		; chk for normal
4385
 6498  F940D0  29 D9         		and	#%11011001
4386
 6499  F940D2  D0 31         		bne	e_badsyn
4387
 6500  F940D4  64 39         		stz	pattyp		; clear file1 pattern flag
4388
 6501  F940D6  60            		rts
4389
 6502
4390
 6503                        	; special case: parse string for disk-to-disk operation (DTD)
4391
 6504                        	; i.e.: "Cddrv=sdrv", "Dddrv=sdrv"
4392
 6505  F940D7                	prsdtd:
4393
 6506  F940D7  A9 3D         		lda	#'='		; find "="
4394
 6507  F940D9  20 6F 42      		jsr	parse
4395
 6508  F940DC  F0 27         		beq	e_badsyn	; error
4396
 6509  F940DE  B9 00 E1      		lda	cmdbuf,y	; test src drive
4397
 6510  F940E1  20 5D 42      		jsr	tst0v1
4398
 6511  F940E4  30 13         		bmi	e_baddrv2	; error
4399
 6512  F940E6  85 35         		sta	fildrv+1	; src drive
4400
 6513  F940E8  88            		dey
4401
 6514  F940E9  88            		dey			; back to dest drive
4402
 6515  F940EA  B9 00 E1      		lda	cmdbuf,y
4403
  Tue Jul 17 11:00:19 2018                                                                                               Page   72
4404
 
4405
 
4406
 
4407
 
4408
 6516  F940ED  20 5D 42      		jsr	tst0v1		; test dest drive
4409
 6517  F940F0  30 07         		bmi	e_baddrv2
4410
 6518  F940F2  C5 35         		cmp	fildrv+1	; cannot be equal
4411
 6519  F940F4  F0 0F         		beq	e_badsyn
4412
 6520  F940F6  85 34         		sta	fildrv		; dest drive
4413
 6521  F940F8  60            		rts
4414
 6522
4415
 6523  F940F9                	e_baddrv2:
4416
 6524  F940F9  A9 23         		lda	#baddrv
4417
 6525  F940FB  80 0A         		bra	cmderr
4418
 6526  F940FD                	e_badcmd:
4419
 6527  F940FD  A9 1F         		lda	#badcmd
4420
 6528  F940FF  80 06         		bra	cmderr
4421
 6529  F94101                	e_nofile:
4422
 6530  F94101  A9 22         		lda	#nofile		; no files
4423
 6531  F94103  80 02         		bra	cmderr
4424
 6532  F94105                	e_badsyn:
4425
 6533  F94105  A9 1E         		lda	#badsyn		; err: bad syntax
4426
 6534  F94107                	cmderr:
4427
 6535  F94107  64 08         		stz	track		; cmd level err proc
4428
 6536  F94109  64 09         		stz	sector
4429
 6537  F9410B  4C FB 56      		jmp	doserr
4430
 6538
4431
 6539                        	; tag cmd string,setup cmd.. struc, image & file pntrs
4432
 6540                        	; parse command line for R,S,N,A,T,M,L,K,E
4433
 6541                        	;
4434
 6542                        	; image bits
4435
 6543                        	;            pgdrpgdr
4436
 6544                        	;            fs1 fs2
4437
 6545                        	;   bit reps:  pattern
4438
 6546                        	;              greater than one file
4439
 6547                        	;              drive:filename
4440
 6548                        	;              not drive:filename (inverted d bit)
4441
 6549                        	;
4442
 6550                        	;   fs1 only	XX100001
4443
 6551                        	;   fs1 & fs2	XX10XX10
4444
 6552                        	;   fs1		XX10XX00 (fs2 optional)
4445
 6553
4446
 6554
4447
 6555  F9410E                	tagcmd:
4448
 6556  F9410E  20 6A 42      		jsr	prscln
4449
 6557  F94111  F0 EE         		beq	e_nofile	; missing ':' -- error
4450
 6558
4451
 6559  F94113                	tagcmd2:
4452
 6560  F94113  88            		dey
4453
 6561  F94114  88            		dey
4454
 6562  F94115  84 1A         		sty	filtbl		; ":"-1 starts fs1
4455
 6563  F94117  8A            		txa
4456
 6564  F94118  D0 E7         		bne	e_nofile	; err: "," before ":"
4457
 6565
4458
 6566  F9411A                	prseq:
4459
 6567  F9411A  A9 3D         		lda	#'='		; search: "="
4460
 6568  F9411C  20 6F 42      		jsr	parse
4461
 6569  F9411F  8A            		txa			; ?file count= 1-1?
4462
 6570  F94120  F0 02         		beq	?40
4463
 6571  F94122  A9 40         		lda	#%01000000	; g1-bit - fs1 count > 1
4464
 6572  F94124  09 21         	?40:	ora	#%00100001	; d1,r2-bits - def. drive fs1, fs2 file req.
4465
  Tue Jul 17 11:00:19 2018                                                                                               Page   73
4466
 
4467
 
4468
 
4469
 
4470
 6573  F94126  85 43         		sta	image		; fs structure
4471
 6574  F94128  E8            		inx
4472
 6575  F94129  86 12         		stx	f1cnt		; fs1 file count
4473
 6576  F9412B  86 13         		stx	f2cnt		; init for no fs2
4474
 6577  F9412D  A5 11         		lda	patflg
4475
 6578  F9412F  F0 06         		beq	?50
4476
 6579  F94131  A9 80         		lda	#%10000000	; p1-bit
4477
 6580  F94133  04 43         		tsb	image
4478
 6581  F94135  64 11         		stz	patflg		; clear pattern flag
4479
 6582  F94137  98            	?50:	tya			; ptr to fs2
4480
 6583  F94138  F0 21         		beq	?75		; no '=' -> no fs2
4481
 6584  F9413A  95 1A         		sta	filtbl,x
4482
 6585  F9413C  A5 12         		lda	f1cnt		; fs2 is here now,...
4483
 6586  F9413E  85 15         		sta	f2ptr		; ...now set f2 ptr
4484
 6587  F94140  A9 8D         		lda	#$8d		; dummy: find cr-shifted (till end of line)
4485
 6588  F94142  20 6F 42      		jsr	parse		; parse rest of cmd string
4486
 6589  F94145  E8            		inx			; advance filtbl ptr to end
4487
 6590  F94146  86 13         		stx	f2cnt		; save it
4488
 6591  F94148  CA            		dex			; restore for test
4489
 6592  F94149  A5 11         		lda	patflg		; save last pattern
4490
 6593  F9414B  F0 02         		beq	?60		; ?any patterns?
4491
 6594  F9414D  A9 08         		lda	#%00001000	; yes, p2-bit
4492
 6595  F9414F  E4 12         	?60:	cpx	f1cnt		; ?f2cnt=f1cnt+1?
4493
 6596  F94151  F0 02         		beq	?70
4494
 6597  F94153  09 04         		ora	#%00000100	; g2-bit
4495
 6598  F94155  09 03         	?70:	ora	#%00000011	; d2-bit,r2-bit
4496
 6599  F94157  45 43         		eor	image		; eor clears r2-bit
4497
 6600  F94159  85 43         		sta	image
4498
 6601  F9415B  A5 43         	?75:	lda	image
4499
 6602  F9415D  A6 53         		ldx	cmdnum
4500
 6603  F9415F  3F 6E 5A F9   		and	>struct,x	; match cmd template
4501
 6604  F94163  D0 A0         		bne	e_badsyn
4502
 6605  F94165  60            		rts
4503
 6606
4504
 6607                        	; parse command string for "open"
4505
 6608  F94166                	prsopn:
4506
 6609  F94166  A9 80         		lda	#$80
4507
 6610  F94168  85 93         		sta	tmp0		; accept default drive
4508
 6611  F9416A  20 6A 42      		jsr	prscln		; look for ":"
4509
 6612  F9416D  D0 03         		bne	?02		; found
4510
 6613  F9416F  BB            		tyx			; not found: y=0
4511
 6614  F94170  F0 07         		beq	?06		; bra
4512
 6615  F94172  8A            	?02:	txa
4513
 6616  F94173  D0 90         		bne	e_badsyn	; comma before ":"
4514
 6617  F94175  88            		dey			; back up to ":"
4515
 6618  F94176  F0 01         		beq	?06		; 1st char is ":"
4516
 6619  F94178  88            	        dey
4517
 6620  F94179  84 1A         	?06:	sty	filtbl		; save filename ptr
4518
 6621  F9417B  A9 8D         		lda	#$8d		; parse cmd string
4519
 6622  F9417D  20 6F 42      		jsr	parse
4520
 6623  F94180  E8            		inx
4521
 6624  F94181  86 13         		stx	f2cnt
4522
 6625
4523
 6626                        	; set 1st drive and table pointers
4524
 6627  F94183                	onedrv:
4525
 6628  F94183  A5 13         		lda	f2cnt		; save f2cnt
4526
 6629  F94185  85 12         		sta	f1cnt
4527
  Tue Jul 17 11:00:19 2018                                                                                               Page   74
4528
 
4529
 
4530
 
4531
 
4532
 6630  F94187  A9 01         		lda	#1		; set pointer to first file
4533
 6631  F94189  85 13         		sta	f2cnt
4534
 6632  F9418B  85 15         		sta	f2ptr
4535
 6633  F9418D
4536
 6634                        	;set up all drives from f2cnt (all files in stream)
4537
 6635  F9418D                	alldrs:
4538
 6636  F9418D  A4 19         		ldy	drvnum		; default drive is last parsed drive
4539
 6637  F9418F  A2 00         		ldx	#0		; ...into file entry table...
4540
 6638  F94191  86 14         	?10	stx	f1ptr		; ...on sector ptr byte
4541
 6639  F94193  B5 34         		lda	fildrv,x	; set bit 6 if dos drive
4542
 6640  F94195  85 42         		sta	char
4543
 6641  F94197  B5 1A         		lda	filtbl,x
4544
 6642  F94199  20 EF 41      		jsr	setdrv
4545
 6643  F9419C  A6 14         		ldx	f1ptr
4546
 6644  F9419E  95 1A         		sta	filtbl,x	; incr ptr past ":"
4547
 6645                        					; bits rep drives
4548
 6646  F941A0  98            		tya
4549
 6647  F941A1  05 42         		ora	char		; restore bit 6
4550
 6648  F941A3  95 34         		sta	fildrv,x	; bit7: default drive
4551
 6649  F941A5  E8            		inx			; bit0: drive #
4552
 6650  F941A6  E4 13         		cpx	f2cnt
4553
 6651  F941A8  90 E7         		bcc	?10
4554
 6652  F941AA  60            		rts
4555
 6653
4556
 6654                        	; parse string for load directory command
4557
 6655                        	; cover these situations:
4558
 6656                        	; "$"
4559
 6657                        	; "$x"
4560
 6658                        	; "$x:pattern=type"
4561
 6659  F941AB                	prsldd:
4562
 6660  F941AB  A9 0B         		lda	#ldcmd		; this is used as index for check image
4563
 6661  F941AD  85 53         		sta	cmdnum
4564
 6662  F941AF  A9 80         		lda	#$80		; load only drive zero
4565
 6663  F941B1  A6 41         		ldx	cmdsiz
4566
 6664  F941B3  CA            		dex
4567
 6665  F941B4  F0 0B         		beq	?02		; "$" case
4568
 6666  F941B6  CA            		dex			; load by name
4569
 6667  F941B7  D0 20         		bne	?03
4570
 6668  F941B9  AD 01 E1      		lda	!cmdbuf+1	; "$x" case
4571
 6669  F941BC  20 5D 42      		jsr	tst0v1
4572
 6670  F941BF  30 18         		bmi	?03		; x is not a drive number
4573
 6671  F941C1  85 34         	?02:	sta	fildrv		; specified drive or default drive
4574
 6672  F941C3  86 1A         		stx	filtbl		; file ptr -- here X = 0
4575
 6673  F941C5  E8            		inx
4576
 6674  F941C6  86 12         		stx	f1cnt		; just file 1 stream
4577
 6675  F941C8  86 13         		stx	f2cnt
4578
 6676  F941CA  A9 80         		lda	#$80
4579
 6677  F941CC  85 39         		sta	pattyp
4580
 6678  F941CE  A9 2A         		lda	#'*'		; in fact open "$x:*"
4581
 6679  F941D0  8D 00 E1      		sta	!cmdbuf
4582
 6680  F941D3  9C 01 E1      		stz	!cmdbuf+1
4583
 6681  F941D6  86 41         		stx	cmdsiz
4584
 6682  F941D8  60            		rts
4585
 6683  F941D9  20 6A 42      	?03:	jsr	prscln		; "$x:pattern=type" case
4586
 6684  F941DC  D0 05         		bne	?05		; found ":"
4587
 6685  F941DE  20 1E 43      		jsr	cmdrst		; search by name on both drives
4588
 6686  F941E1  A0 03         		ldy	#3
4589
  Tue Jul 17 11:00:19 2018                                                                                               Page   75
4590
 
4591
 
4592
 
4593
 
4594
 6687  F941E3  88            	?05:	dey
4595
 6688  F941E4  88            		dey
4596
 6689  F941E5  84 1A         		sty	filtbl
4597
 6690  F941E7  20 1A 41      		jsr	prseq		; parse & set tables
4598
 6691  F941EA  20 B1 42      		jsr	fs1set
4599
 6692  F941ED  80 9E         		bra	alldrs
4600
 6693
4601
 6694                        	;---------------------------------------
4602
 6695                        	;  set drive number
4603
 6696                        	;  determines drive # from text or
4604
 6697                        	;  uses default (-d)
4605
 6698                        	;  a: in,out: index, cmdbuf
4606
 6699                        	;  y: in: default drive
4607
 6700                        	;     out: drive number, - if default
4608
 6701                        	;  char<6> set if check dos drive
4609
 6702                        	;---------------------------------------
4610
 6703  F941EF                	setdrv:
4611
 6704  F941EF  AA            		tax			; x= cmdbuf index
4612
 6705  F941F0  A9 3A         		lda	#':'
4613
 6706  F941F2  DD 01 E1      		cmp	!cmdbuf+1,x	; for xxx:file
4614
 6707  F941F5  F0 0D         		beq	?40		;       ^
4615
 6708  F941F7  DD 00 E1      		cmp	!cmdbuf,x	; for xxx:file
4616
 6709  F941FA  D0 2E         		bne	?50		;        ^
4617
 6710  F941FC  E8            		inx			; found ":", so...
4618
 6711  F941FD  80 2B         		bra	?50
4619
 6712  F941FF  29 01         	?22:	and	#1		; convert to numeric
4620
 6713  F94201  A8            	?24:	tay			; set new default drive
4621
 6714  F94202  8A            		txa			; a=index & xxxxfile
4622
 6715  F94203  60            		rts			;               ^
4623
 6716  F94204  BD 00 E1      	?40:	lda	!cmdbuf,x
4624
 6717  F94207  E8            		inx			;  xxx:file
4625
 6718  F94208  E8            		inx			;    --^
4626
 6719  F94209  C9 30         		cmp	#'0'		; for xx0:file
4627
 6720  F9420B  F0 F2         		beq	?22		;         ^
4628
 6721  F9420D  C9 31         		cmp	#'1'		; for xx1:file
4629
 6722  F9420F  F0 EE         		beq	?22		;         ^
4630
 6723  F94211  24 42         		bit	char		; test bit 6
4631
 6724  F94213  50 11         		bvc	?48		; check default cbm drive
4632
 6725  F94215  C9 38         		cmp	#'8'
4633
 6726  F94217  B0 0A         		bcs	?45		; valid dos drive: 0..7
4634
 6727  F94219  C9 30         		cmp	#'0'
4635
 6728  F9421B  90 06         		bcc	?45
4636
 6729  F9421D  E9 30         		sbc	#'0'
4637
 6730  F9421F  C9 04         		cmp	#MAXDOSDRV
4638
 6731  F94221  90 DE         		bcc	?24		; dos drive ok
4639
 6732  F94223  4C 89 3D      	?45:	jmp	e_baddrv
4640
 6733  F94226  24 93         	?48:	bit	tmp0		; for default baddrv error!
4641
 6734  F94228  10 F9         		bpl	?45
4642
 6735  F9422A  98            	?50:	tya			; for xxx,file or xx=file
4643
 6736  F9422B  09 80         		ora	#$80		;         ^          ^
4644
 6737  F9422D  29 87         		and	#$87		; drive= -default
4645
 6738  F9422F  80 D0         		bra	?24
4646
 6739  F94231
4647
 6740                        	; simple parser - set just the drive number
4648
 6741                        	; called by open directory command
4649
 6742  F94231                	simprs:
4650
 6743  F94231  64 1A         		stz	filtbl
4651
  Tue Jul 17 11:00:19 2018                                                                                               Page   76
4652
 
4653
 
4654
 
4655
 
4656
 6744  F94233  20 6A 42      		jsr	prscln		; search colon
4657
 6745  F94236  F0 04         		beq	?02		; ":" not found, Y = next char
4658
 6746  F94238  88            		dey
4659
 6747  F94239  88            		dey
4660
 6748  F9423A  84 1A         		sty	filtbl		; ptr to char before ":"
4661
 6749  F9423C  64 43         	?02:	stz	image
4662
 6750  F9423E  A4 1A         		ldy	filtbl
4663
 6751  F94240  B9 00 E1      	?04:	lda	cmdbuf,y
4664
 6752  F94243  20 5D 42      		jsr	tst0v1
4665
 6753  F94246  10 10         		bpl	?20		; ok, found drive #
4666
 6754  F94248  C8            		iny
4667
 6755  F94249  C4 41         		cpy	cmdsiz
4668
 6756  F9424B  B0 05         		bcs	?10		; end of string
4669
 6757  F9424D  A4 41         		ldy	cmdsiz
4670
 6758  F9424F  88            		dey
4671
 6759  F94250  D0 EE         		bne	?04
4672
 6760  F94252  C6 43         	?10:	dec	image		; invalidate cmd template
4673
 6761  F94254  A5 19         		lda	drvnum		; use default drive
4674
 6762  F94256  09 80         		ora	#$80
4675
 6763  F94258  29 81         	?20:	and	#$81
4676
 6764  F9425A  85 34         		sta	fildrv
4677
 6765  F9425C  60            		rts
4678
 6766
4679
 6767                        	;test char in accum for "0" or "1"
4680
 6768  F9425D  C9 30         	tst0v1:	cmp	#'0'
4681
 6769  F9425F  F0 06         		beq	?02
4682
 6770  F94261  C9 31         		cmp	#'1'
4683
 6771  F94263  F0 02         		beq	?02
4684
 6772  F94265  09 80         		ora	#$80		; use default drive
4685
 6773  F94267  29 81         	?02:	and	#$81		; mask dr #
4686
 6774  F94269  60            		rts
4687
 6775
4688
 6776                        	; find pos'n of ":"
4689
 6777  F9426A                	prscln:
4690
 6778  F9426A  A0 00         		ldy	#0		; buffer ptr
4691
 6779  F9426C  BB            		tyx			; comma counter
4692
 6780  F9426D  A9 3A         		lda	#':'
4693
 6781
4694
 6782                        	;parse string
4695
 6783                        	;  looks for special chars,
4696
 6784                        	;  returning when var'bl char
4697
 6785                        	;  is found
4698
 6786                        	;   a: var'bl char
4699
 6787                        	;   x: in,out: index, filtbl+1
4700
 6788                        	;   y: in: index, cmdbuf
4701
 6789                        	;     out: new ptr, =0 if none
4702
 6790                        	;         (z=1) if y=0
4703
 6791  F9426F                	parse:
4704
 6792  F9426F  85 42         		sta	char		; save var'bl char
4705
 6793  F94271  B9 00 E1      	?10:	lda	cmdbuf,y	; match char
4706
 6794  F94274  F0 29         		beq	?30		; end of string
4707
 6795  F94276  C8            		iny
4708
 6796  F94277  C5 42         		cmp	char
4709
 6797  F94279  F0 26         		beq	?35		; found char
4710
 6798  F9427B  C9 2A         		cmp	#'*'		; match pattern chars
4711
 6799  F9427D  F0 04         		beq	?20
4712
 6800  F9427F  C9 3F         		cmp	#'?'
4713
  Tue Jul 17 11:00:19 2018                                                                                               Page   77
4714
 
4715
 
4716
 
4717
 
4718
 6801  F94281  D0 02         		bne	?25
4719
 6802  F94283  E6 11         	?20:	inc	patflg		; set pattern flag
4720
 6803  F94285  C9 2C         	?25:	cmp	#','		; match file separator
4721
 6804  F94287  D0 E8         		bne	?10		; loop
4722
 6805  F94289  94 1B         		sty	filtbl+1,x	; put ptrs in table
4723
 6806  F9428B  A5 11         		lda	patflg		; save pattern for file
4724
 6807  F9428D  29 7F         		and	#$7f
4725
 6808  F9428F  F0 06         		beq	?28
4726
 6809  F94291  A9 80         		lda	#$80		; retain pattern presence...
4727
 6810  F94293  95 39         		sta	pattyp,x
4728
 6811  F94295  85 11         		sta	patflg		; ...but clear count
4729
 6812  F94297  E8            	?28:	inx
4730
 6813  F94298  E0 05         		cpx	#mxfils
4731
 6814  F9429A  90 D5         		bcc	?10		; no more than mxfils
4732
 6815  F9429C  4C 05 41      		jmp	e_badsyn	; too many files
4733
 6816  F9429F  A0 00         	?30:	ldy	#0		; y=0 (z=1)
4734
 6817  F942A1  A5 41         	?35:	lda	cmdsiz
4735
 6818  F942A3  95 1B         		sta	filtbl+1,x
4736
 6819  F942A5  A5 11         		lda	patflg
4737
 6820  F942A7  29 7F         		and	#$7f
4738
 6821  F942A9  F0 04         		beq	?40
4739
 6822  F942AB  A9 80         		lda	#$80
4740
 6823  F942AD  95 39         		sta	pattyp,x
4741
 6824  F942AF  98            	?40:	tya			; z is set
4742
 6825  F942B0  60            		rts
4743
 6826
4744
 6827                        	; set ptrs to one file stream & chk type
4745
 6828                        	; for command that allow pattern=type
4746
 6829  F942B1                	fs1set:
4747
 6830  F942B1  A2 00         		ldx	#0
4748
 6831  F942B3  A5 12         		lda	f1cnt
4749
 6832  F942B5  C5 13         		cmp	f2cnt
4750
 6833  F942B7  F0 15         		beq	?15		; just one file in stream
4751
 6834  F942B9  C6 13         		dec	f2cnt
4752
 6835  F942BB  A6 13         		ldx	f2cnt
4753
 6836  F942BD  B5 1A         		lda	filtbl,x
4754
 6837  F942BF  AA            		tax
4755
 6838  F942C0  BD 00 E1      		lda	!cmdbuf,x
4756
 6839  F942C3  A2 05         		ldx	#ntypes-1
4757
 6840  F942C5  DF 84 5A F9   	?10:	cmp	>typlst,x
4758
 6841  F942C9  F0 03         		beq	?15
4759
 6842  F942CB  CA            		dex
4760
 6843  F942CC  D0 F7         		bne	?10
4761
 6844  F942CE  86 10         	?15:	stx	typflg
4762
 6845  F942D0  60            		rts
4763
 6846
4764
 6847                        	; copy local cmd string, initialize command tables, ptrs, etc.
4765
 6848                        	; command string, as parameter, is terminated with '0' or CR
4766
 6849  F942D1                	cmdset:
4767
 6850  F942D1  A0 00         		ldy	#0
4768
 6851  F942D3  A7 3E         	?02:	lda	[tlp]		; trim left
4769
 6852  F942D5  F0 2A         		beq	?10		; end of cmd
4770
 6853  F942D7  C9 0D         		cmp	#$0D
4771
 6854  F942D9  F0 18         		beq	?06		; end of cmd
4772
 6855  F942DB  C9 20         		cmp	#' '		; trim blanks
4773
 6856  F942DD  D0 0A         		bne	?03
4774
 6857  F942DF  E6 3E         		inc	tlp
4775
  Tue Jul 17 11:00:19 2018                                                                                               Page   78
4776
 
4777
 
4778
 
4779
 
4780
 6858  F942E1  D0 F0         		bne	?02
4781
 6859  F942E3  E6 3F         		inc	tlp+1
4782
 6860  F942E5  D0 EC         		bne	?02
4783
 6861  F942E7  F0 22         		beq	?11		; long line
4784
 6862  F942E9  88            	?03:	dey
4785
 6863  F942EA  C8            	?04:	iny
4786
 6864  F942EB  B7 3E         		lda	[tlp],y
4787
 6865  F942ED  F0 12         		beq	?10		; end of cmd
4788
 6866  F942EF  C9 0D         		cmp	#$0D
4789
 6867  F942F1  D0 04         		bne	?08
4790
 6868  F942F3  A9 00         	?06:	lda	#0		; end of cmd
4791
 6869  F942F5  80 0A         		bra	?10
4792
 6870  F942F7  C9 61         	?08:	cmp	#'a'		; convert up case
4793
 6871  F942F9  90 06         		bcc	?10
4794
 6872  F942FB  C9 7B         		cmp	#'z'+1
4795
 6873  F942FD  B0 02         		bcs	?10
4796
 6874  F942FF  29 DF         		and	#$DF
4797
 6875  F94301  99 00 E1      	?10:	sta	cmdbuf,y
4798
 6876  F94304  AA            		tax
4799
 6877  F94305  F0 09         		beq	?12
4800
 6878  F94307  C0 60         		cpy	#cmdlen
4801
 6879  F94309  90 DF         		bcc	?04
4802
 6880  F9430B  A9 20         	?11:	lda	#longln		; long line error
4803
 6881  F9430D  4C 07 41      		jmp	cmderr
4804
 6882  F94310  84 41         	?12:	sty	cmdsiz		; not counting final '0'
4805
 6883  F94312  24 F9         		bit	cmdtrap
4806
 6884  F94314  30 08         		bmi	cmdrst		; cmd. empty string is ok
4807
 6885  F94316  BB            		tyx
4808
 6886  F94317  D0 05         		bne	cmdrst
4809
 6887  F94319  A9 25         		lda	#nullln		; empty command string error
4810
 6888  F9431B  4C 07 41      		jmp	cmderr
4811
 6889  F9431E
4812
 6890                        	; clear vars & tbls
4813
 6891  F9431E                	cmdrst:
4814
 6892  F9431E  A0 00         		ldy	#0
4815
 6893  F94320  98            		tya
4816
 6894  F94321  85 0E         		sta	type
4817
 6895  F94323  85 0F         		sta	mode
4818
 6896  F94325  85 10         		sta	typflg
4819
 6897  F94327  85 14         		sta	f1ptr
4820
 6898  F94329  85 15         		sta	f2ptr
4821
 6899  F9432B  85 12         		sta	f1cnt
4822
 6900  F9432D  85 13         		sta	f2cnt
4823
 6901  F9432F  85 11         		sta	patflg
4824
 6902  F94331  85 56         		sta	lsterr
4825
 6903  F94333  85 93         		sta	tmp0
4826
 6904  F94335  85 1F         		sta	tmpxxx
4827
 6905  F94337  85 F8         		sta	trap
4828
 6906  F94339  85 E6         		sta	wrop
4829
 6907  F9433B  A2 05         		ldx	#mxfils
4830
 6908  F9433D  95 19         	?10:	sta	filtbl-1,x
4831
 6909  F9433F  95 29         		sta	entsec-1,x
4832
 6910  F94341  95 2E         		sta	entind-1,x
4833
 6911  F94343  95 33         		sta	fildrv-1,x
4834
 6912  F94345  95 38         		sta	pattyp-1,x
4835
 6913  F94347  95 1F         		sta	filtrk-1,x
4836
 6914  F94349  95 24         		sta	filsec-1,x
4837
  Tue Jul 17 11:00:19 2018                                                                                               Page   79
4838
 
4839
 
4840
 
4841
 
4842
 6915  F9434B  CA            		dex
4843
 6916  F9434C  D0 EF         		bne	?10
4844
 6917  F9434E  60            		rts
4845
 6918
4846
 6919                        	;---------------------------------------------------------------------------
4847
 6920                        	; read/write on fd
4848
 6921                        	;---------------------------------------------------------------------------
4849
 6922
4850
 6923                        	; buffered read/write on file
4851
 6924                        	; in:	X = channel
4852
 6925                        	;	Y = op (read/write)
4853
 6926  F9434F                	fd_rw:
4854
 6927  F9434F                		ACC16
4855
 6928  F9434F  C2 20         		rep	#PMFLAG
4856
 6929                        		.LONGA	on
4857
 6930                        		.MNLIST
4858
 6931  F94351  3B            		tsc			; save current stack pointer
4859
 6932  F94352  8D F8 E1      		sta	!tos
4860
 6933  F94355                		ACC08
4861
 6934  F94355  E2 20         		sep	#PMFLAG
4862
 6935                        		.LONGA	off
4863
 6936                        		.MNLIST
4864
 6937  F94357  E0 0F         		cpx	#$0F
4865
 6938  F94359  D0 26         		bne	?08		; file
4866
 6939  F9435B  98            		tya
4867
 6940  F9435C  F0 02         		beq	?02		; read on channel 15
4868
 6941  F9435E  18            		clc			; write on channel 15 is no-op
4869
 6942  F9435F  60            		rts
4870
 6943  F94360  20 1A 57      	?02:	jsr	fmterr		; format error string (bytes # in btrf)
4871
 6944  F94363  64 56         		stz	lsterr
4872
 6945  F94365  A0 00         		ldy	#0
4873
 6946  F94367                		INDEX16
4874
 6947  F94367  C2 10         		rep	#PXFLAG
4875
 6948                        		.LONGI	on
4876
 6949                        		.MNLIST
4877
 6950  F94369  B9 00 E1      	?04:	lda	cmdbuf,y
4878
 6951  F9436C  97 90         		sta	[wbuf],y
4879
 6952  F9436E  F0 0A         		beq	?06		; end of transfer
4880
 6953  F94370  C8            		iny
4881
 6954  F94371  C4 86         		cpy	bsize
4882
 6955  F94373  90 F4         		bcc	?04
4883
 6956  F94375  88            		dey
4884
 6957  F94376  A9 00         		lda	#0		; trunc string
4885
 6958  F94378  97 90         		sta	[wbuf],y
4886
 6959  F9437A  C8            	?06:	iny
4887
 6960  F9437B  84 88         		sty	btrf
4888
 6961  F9437D                		INDEX08
4889
 6962  F9437D  E2 10         		sep	#PXFLAG
4890
 6963                        		.LONGI	off
4891
 6964                        		.MNLIST
4892
 6965  F9437F  18            		clc
4893
 6966  F94380  60            		rts
4894
 6967  F94381  64 56         	?08:	stz	lsterr
4895
 6968  F94383  64 E6         		stz	wrop
4896
 6969  F94385  98            		tya
4897
 6970  F94386  F0 04         		beq	?10
4898
 6971  F94388  A9 80         		lda	#$80
4899
  Tue Jul 17 11:00:19 2018                                                                                               Page   80
4900
 
4901
 
4902
 
4903
 
4904
 6972  F9438A  85 E6         		sta	wrop
4905
 6973  F9438C  20 76 48      	?10:	jsr	fndfd		; check file (read/write)
4906
 6974  F9438F  20 E2 48      		jsr	fddrv		; get associate drive #
4907
 6975  F94392  B5 59         		lda	lintab,x
4908
 6976  F94394  89 20         		bit	#$20
4909
 6977  F94396  F0 03         		beq	?12
4910
 6978  F94398  4C 70 44      		jmp	fdlist		; buffered load dir
4911
 6979  F9439B  89 40         	?12:	bit	#$40
4912
 6980  F9439D  F0 03         		beq	?14
4913
 6981  F9439F  4C 82 45      		jmp	fdda
4914
 6982  F943A2  24 E6         	?14:	bit	wrop
4915
 6983  F943A4  30 5F         		bmi	fdwrite
4916
 6984                        	;	bmi	?14
4917
 6985                        	;	jmp	fdread
4918
 6986                        	;?14:	jmp	fdwrite
4919
 6987
4920
 6988                        	; read a block of data from file and transfer to destination buffer
4921
 6989                        	; before to call this function these var's should be initialized:
4922
 6990                        	;	lindx	=file descriptor (logical index)
4923
 6991                        	;	bsize	=size of destination buffer
4924
 6992                        	;	wbuf	=long pointer to destination buffer
4925
 6993                        	;
4926
 6994                        	; this function return when:
4927
 6995                        	;	1) destination buffer is full, and/or
4928
 6996                        	;	2) the eof condition is true
4929
 6997                        	;	   in this case the bit 7 of fdst is set
4930
 6998                        	;
4931
 6999                        	; on exit, btrf contain the effective transferred bytes count #
4932
 7000                        	;
4933
 7001  F943A6                	fdread:
4934
 7002  F943A6  64 88         		stz	btrf		; clear count of readden bytes
4935
 7003  F943A8  64 89         		stz	btrf+1
4936
 7004  F943AA  A6 57         		ldx	lindx		; file descriptor
4937
 7005  F943AC  34 96         		bit	fdst,x		; test if eof
4938
 7006  F943AE  30 53         		bmi	?40		; yes, eof
4939
 7007  F943B0  A5 19         		lda	drvnum		; set up read drive #
4940
 7008  F943B2  85 E8         		sta	rddrv
4941
 7009  F943B4  B4 AE         		ldy	ftrk,x
4942
 7010  F943B6  84 08         		sty	track		; set up current file track
4943
 7011  F943B8  B5 B6         		lda	fsec,x
4944
 7012  F943BA  85 09         		sta	sector		; setup current file sector
4945
 7013  F943BC  B4 BE         		ldy	fdptr,x
4946
 7014  F943BE  84 E9         		sty	rdidx		; set file pointer in this blk
4947
 7015  F943C0  20 AB 57      		jsr	tread		; read whole track in read cache
4948
 7016  F943C3  20 4A 56      		jsr	setcp		; set up bufp pointer
4949
 7017  F943C6  64 EA         		stz	rdlst		; assume full block (not last blk)
4950
 7018  F943C8  A0 01         		ldy	#1
4951
 7019  F943CA  B7 8A         		lda	[bufp],y	; read link to next block
4952
 7020  F943CC  A8            		tay			; next sector or last byte ptr
4953
 7021  F943CD  A7 8A         		lda	[bufp]		; next libnk track
4954
 7022  F943CF  D0 02         		bne	?10		; no end of file
4955
 7023  F943D1  84 EA         		sty	rdlst		; last byte pointer (this is last blk)
4956
 7024  F943D3  64 EB         	?10:	stz	rdeof		; clear eof flag
4957
 7025  F943D5  20 B8 45      	?20:	jsr	bufget		; get next byte from disk buffer
4958
 7026  F943D8                		INDEX16
4959
 7027  F943D8  C2 10         		rep	#PXFLAG
4960
 7028                        		.LONGI	on
4961
  Tue Jul 17 11:00:19 2018                                                                                               Page   81
4962
 
4963
 
4964
 
4965
 
4966
 7029                        		.MNLIST
4967
 7030  F943DA  A4 88         		ldy	btrf		; current dest buffer ptr
4968
 7031  F943DC  97 90         		sta	[wbuf],y	; store in dest buffer
4969
 7032  F943DE  C8            		iny
4970
 7033  F943DF  84 88         		sty	btrf		; update ptr
4971
 7034  F943E1  C4 86         		cpy	bsize		; check size of dest buffer
4972
 7035  F943E3                		INDEX08
4973
 7036  F943E3  E2 10         		sep	#PXFLAG
4974
 7037                        		.LONGI	off
4975
 7038                        		.MNLIST
4976
 7039  F943E5  B0 04         		bcs	?30		; dest buffer is full
4977
 7040  F943E7  A5 EB         		lda	rdeof		; eof?
4978
 7041  F943E9  F0 EA         		beq	?20		; no -- get next byte
4979
 7042  F943EB  A6 57         	?30:	ldx	lindx
4980
 7043  F943ED  A4 08         		ldy	track
4981
 7044  F943EF  94 AE         		sty	ftrk,x		; save current fd
4982
 7045  F943F1  A5 09         		lda	sector
4983
 7046  F943F3  95 B6         		sta	fsec,x
4984
 7047  F943F5  A4 E9         		ldy	rdidx
4985
 7048  F943F7  94 BE         		sty	fdptr,x
4986
 7049  F943F9  A5 EB         		lda	rdeof
4987
 7050  F943FB  F0 06         		beq	?40		; no eof
4988
 7051  F943FD  A9 80         		lda	#$80
4989
 7052  F943FF  15 96         		ora	fdst,x
4990
 7053  F94401  95 96         		sta	fdst,x		; eof signal
4991
 7054  F94403  18            	?40:	clc
4992
 7055  F94404  60            		rts
4993
 7056
4994
 7057                        	; write a block of data from source buffer to file
4995
 7058                        	; before to call this function these var's should be initialized:
4996
 7059                        	;	lindx	=file descriptor (logical index)
4997
 7060                        	;	bsize	=number of bytes to write
4998
 7061                        	;	wbuf	=long pointer to destination buffer
4999
 7062                        	;
5000
 7063                        	; on exit, btrf contain the effective transferred bytes count #
5001
 7064                        	;
5002
 7065  F94405                	fdwrite:
5003
 7066  F94405  64 EB         		stz	rdeof
5004
 7067  F94407                		ACC16
5005
 7068  F94407  C2 20         		rep	#PMFLAG
5006
 7069                        		.LONGA	on
5007
 7070                        		.MNLIST
5008
 7071  F94409  64 88         		stz	btrf		; clear count of written bytes
5009
 7072  F9440B  A5 86         		lda	bsize		; nothing to write?
5010
 7073  F9440D                		ACC08
5011
 7074  F9440D  E2 20         		sep	#PMFLAG
5012
 7075                        		.LONGA	off
5013
 7076                        		.MNLIST
5014
 7077  F9440F  F0 5D         		beq	?10		; yes, nothing
5015
 7078  F94411  A6 57         		ldx	lindx		; file descriptor
5016
 7079  F94413  A5 19         		lda	drvnum		; set up write drive #
5017
 7080  F94415  85 EC         		sta	wrdrv
5018
 7081  F94417  B4 AE         		ldy	ftrk,x
5019
 7082  F94419  84 08         		sty	track		; set up current file track
5020
 7083  F9441B  B5 B6         		lda	fsec,x
5021
 7084  F9441D  85 09         		sta	sector		; setup current file sector
5022
 7085  F9441F  85 EE         		sta	wsec		; current sector to write in cache
5023
  Tue Jul 17 11:00:19 2018                                                                                               Page   82
5024
 
5025
 
5026
 
5027
 
5028
 7086  F94421  85 EF         		sta 	wfirst		; first sector to write in cache
5029
 7087  F94423  B4 BE         		ldy	fdptr,x
5030
 7088  F94425  84 ED         		sty	wridx		; set file pointer in this blk
5031
 7089  F94427  A6 F7         		ldx	dblfd
5032
 7090  F94429                		ACC16
5033
 7091  F94429  C2 20         		rep	#PMFLAG
5034
 7092                        		.LONGA	on
5035
 7093                        		.MNLIST
5036
 7094  F9442B  B5 C6         		lda	fdblk,x		; set up block's count
5037
 7095  F9442D  85 F0         		sta	wcnt
5038
 7096  F9442F  A5 90         		lda	wbuf		; wbuf is used by write cache
5039
 7097  F94431  85 8A         		sta	bufp		; bufp is the src. buffer
5040
 7098  F94433                		ACC08
5041
 7099  F94433  E2 20         		sep	#PMFLAG
5042
 7100                        		.LONGA	off
5043
 7101                        		.MNLIST
5044
 7102  F94435  A5 92         		lda	wbuf+2
5045
 7103  F94437  85 8C         		sta	bufp+2
5046
 7104  F94439  20 C1 57      		jsr	wread		; pre-read track in write cache
5047
 7105  F9443C  20 5A 56      		jsr	setwb		; set buffer wbuf to cache
5048
 7106  F9443F                	?02:	INDEX16
5049
 7107  F9443F  C2 10         		rep	#PXFLAG
5050
 7108                        		.LONGI	on
5051
 7109                        		.MNLIST
5052
 7110  F94441  A4 88         		ldy	btrf		; transfer src. buffer to cache
5053
 7111  F94443  B7 8A         		lda	[bufp],y
5054
 7112  F94445  C8            		iny
5055
 7113  F94446  84 88         		sty	btrf		; bump pointer
5056
 7114  F94448  C4 86         		cpy	bsize
5057
 7115  F9444A                		INDEX08
5058
 7116  F9444A  E2 10         		sep	#PXFLAG
5059
 7117                        		.LONGI	off
5060
 7118                        		.MNLIST
5061
 7119  F9444C  08            		php
5062
 7120  F9444D  20 08 46      		jsr	bufput		; put in cache
5063
 7121  F94450  28            		plp
5064
 7122  F94451  90 EC         		bcc	?02		; loop
5065
 7123  F94453  20 7A 46      		jsr	wrtcache	; flush cache on disk
5066
 7124  F94456  A6 57         		ldx	lindx
5067
 7125  F94458  A5 08         		lda	track
5068
 7126  F9445A  95 AE         		sta	ftrk,x
5069
 7127  F9445C  A5 09         		lda	sector
5070
 7128  F9445E  95 B6         		sta	fsec,x
5071
 7129  F94460  A4 ED         		ldy	wridx
5072
 7130  F94462  94 BE         		sty	fdptr,x
5073
 7131  F94464  A6 F7         		ldx	dblfd
5074
 7132  F94466                		ACC16
5075
 7133  F94466  C2 20         		rep	#PMFLAG
5076
 7134                        		.LONGA	on
5077
 7135                        		.MNLIST
5078
 7136  F94468  A5 F0         		lda	wcnt
5079
 7137  F9446A  95 C6         		sta	fdblk,x
5080
 7138  F9446C                		ACC08
5081
 7139  F9446C  E2 20         		sep	#PMFLAG
5082
 7140                        		.LONGA	off
5083
 7141                        		.MNLIST
5084
 7142  F9446E  18            	?10:	clc
5085
  Tue Jul 17 11:00:19 2018                                                                                               Page   83
5086
 
5087
 
5088
 
5089
 
5090
 7143  F9446F  60            		rts
5091
 7144
5092
 7145                        	; read a block of data from dir listing and transfer to destination buffer
5093
 7146                        	; before to call this function these var's should be initialized:
5094
 7147                        	;	lindx	=file descriptor (logical index)
5095
 7148                        	;	bsize	=size of destination buffer
5096
 7149                        	;	wbuf	=long pointer to destination buffer
5097
 7150                        	;
5098
 7151                        	; this function return when:
5099
 7152                        	;	1) destination buffer is full, and/or
5100
 7153                        	;	2) the eof condition is true
5101
 7154                        	;	   in this case the bit 7 of fdst is set
5102
 7155                        	;
5103
 7156                        	; on exit, btrf contain the effective transferred bytes count #
5104
 7157                        	;
5105
 7158  F94470                	fdlist:
5106
 7159  F94470  20 15 49      		jsr	setfdp		; set buffer for this fd & return X=lindx
5107
 7160  F94473  64 88         		stz	btrf		; clear count of readden bytes
5108
 7161  F94475  64 89         		stz	btrf+1
5109
 7162  F94477  34 96         		bit	fdst,x		; test if eof
5110
 7163  F94479  30 32         		bmi	?40		; yes, eof
5111
 7164  F9447B  B4 BE         		ldy	fdptr,x
5112
 7165  F9447D  84 E9         		sty	rdidx		; set file pointer in this blk
5113
 7166  F9447F  64 EB         		stz	rdeof		; clear eof flag
5114
 7167  F94481  20 D7 46      		jsr	exxzp		; get zp var's for dir searching
5115
 7168  F94484  20 B3 46      	?20:	jsr	bufget2		; get next byte from list buffer
5116
 7169  F94487                		INDEX16
5117
 7170  F94487  C2 10         		rep	#PXFLAG
5118
 7171                        		.LONGI	on
5119
 7172                        		.MNLIST
5120
 7173  F94489  A4 88         		ldy	btrf		; current dest buffer ptr
5121
 7174  F9448B  97 90         		sta	[wbuf],y	; store in dest buffer
5122
 7175  F9448D  C8            		iny
5123
 7176  F9448E  84 88         		sty	btrf		; update ptr
5124
 7177  F94490  C4 86         		cpy	bsize		; check size of dest buffer
5125
 7178  F94492                		INDEX08
5126
 7179  F94492  E2 10         		sep	#PXFLAG
5127
 7180                        		.LONGI	off
5128
 7181                        		.MNLIST
5129
 7182  F94494  B0 04         		bcs	?30		; dest buffer is full
5130
 7183  F94496  A5 EB         		lda	rdeof		; eof?
5131
 7184  F94498  F0 EA         		beq	?20		; no -- get next byte
5132
 7185  F9449A  20 D7 46      	?30:	jsr	exxzp		; restore zp var's
5133
 7186  F9449D  A6 57         		ldx	lindx
5134
 7187  F9449F  A4 E9         		ldy	rdidx
5135
 7188  F944A1  94 BE         		sty	fdptr,x
5136
 7189  F944A3  A5 EB         		lda	rdeof
5137
 7190  F944A5  F0 06         		beq	?40		; no eof
5138
 7191  F944A7  A9 80         		lda	#$80
5139
 7192  F944A9  15 96         		ora	fdst,x
5140
 7193  F944AB  95 96         		sta	fdst,x		; eof signal
5141
 7194  F944AD  18            	?40:	clc
5142
 7195  F944AE  60            		rts
5143
 7196
5144
 7197                        	; close file
5145
 7198                        	; in:	X = channel
5146
 7199                        	; if chnl=15 all open files will be closed
5147
  Tue Jul 17 11:00:19 2018                                                                                               Page   84
5148
 
5149
 
5150
 
5151
 
5152
 7200  F944AF                	fdcls:
5153
 7201  F944AF                		ACC16
5154
 7202  F944AF  C2 20         		rep	#PMFLAG
5155
 7203                        		.LONGA	on
5156
 7204                        		.MNLIST
5157
 7205  F944B1  3B            		tsc			; save current stack pointer
5158
 7206  F944B2  8D F8 E1      		sta	!tos
5159
 7207  F944B5                		ACC08
5160
 7208  F944B5  E2 20         		sep	#PMFLAG
5161
 7209                        		.LONGA	off
5162
 7210                        		.MNLIST
5163
 7211  F944B7  8A            		txa
5164
 7212  F944B8  F0 2E         		beq	?28		; read only chnl so just free lindx & chnl
5165
 7213  F944BA  E0 0F         		cpx	#$0F
5166
 7214  F944BC  D0 0E         		bne	?20		; close channel 1..14
5167
 7215  F944BE  A2 0E         		ldx	#mxchnls-1	; closing chnl 15 close all open files
5168
 7216  F944C0  86 52         	?02:	stx	chnl
5169
 7217  F944C2  20 CC 44      		jsr	?20		; close chnl X
5170
 7218  F944C5  A6 52         		ldx	chnl
5171
 7219  F944C7  CA            		dex
5172
 7220  F944C8  10 F6         		bpl	?02
5173
 7221  F944CA  18            	?04:	clc
5174
 7222  F944CB  60            		rts
5175
 7223  F944CC  B5 59         	?20:	lda	lintab,x	; close chnl X
5176
 7224  F944CE  C9 FF         		cmp	#$FF
5177
 7225  F944D0  F0 F8         		beq	?04		; is closed
5178
 7226  F944D2  89 40         		bit	#$40		; direct access?
5179
 7227  F944D4  D0 0F         		bne	?26		; yes, just update bam
5180
 7228  F944D6  29 07         		and	#$07
5181
 7229  F944D8  85 57         		sta	lindx		; associated logical index
5182
 7230  F944DA  20 E2 48      		jsr	fddrv		; get associated drive
5183
 7231  F944DD  20 B2 48      		jsr	fndwfd		; look for write fd
5184
 7232  F944E0  B0 06         		bcs	?28		; read fd: just free lindx
5185
 7233  F944E2  20 ED 44      		jsr	clswfd
5186
 7234  F944E5  20 02 58      	?26:	jsr	bamout
5187
 7235  F944E8  20 F0 47      	?28:	jsr	frefd		; free fd
5188
 7236  F944EB  18            		clc
5189
 7237  F944EC  60            		rts
5190
 7238
5191
 7239                        	; close a write file
5192
 7240                        	;in:	X=lindx
5193
 7241  F944ED                	clswfd:
5194
 7242  F944ED  A5 19         		lda	drvnum		; set up write drive #
5195
 7243  F944EF  85 EC         		sta	wrdrv
5196
 7244  F944F1  B4 AE         		ldy	ftrk,x
5197
 7245  F944F3  84 08         		sty	track		; set up current file track
5198
 7246  F944F5  B5 B6         		lda	fsec,x
5199
 7247  F944F7  85 09         		sta	sector		; setup current file sector
5200
 7248  F944F9  85 EE         		sta	wsec		; current sector to write in cache
5201
 7249  F944FB  85 EF         		sta 	wfirst		; first sector to write in cache
5202
 7250  F944FD  B4 BE         		ldy	fdptr,x
5203
 7251  F944FF  84 ED         		sty	wridx		; set file pointer in this blk
5204
 7252  F94501  A6 F7         		ldx	dblfd
5205
 7253  F94503                		ACC16
5206
 7254  F94503  C2 20         		rep	#PMFLAG
5207
 7255                        		.LONGA	on
5208
 7256                        		.MNLIST
5209
  Tue Jul 17 11:00:19 2018                                                                                               Page   85
5210
 
5211
 
5212
 
5213
 
5214
 7257  F94505  B5 C6         		lda	fdblk,x		; set up block's count
5215
 7258  F94507  1A            		inc	a		; take in count last blk
5216
 7259  F94508  85 F0         		sta	wcnt
5217
 7260  F9450A                		CPU08
5218
 7261  F9450A  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
5219
 7262                        		.LONGA	off
5220
 7263                        		.LONGI	off
5221
 7264                        		.MNLIST
5222
 7265  F9450C  20 C1 57      		jsr	wread		; pre-read track in write cache
5223
 7266  F9450F  20 5A 56      		jsr	setwb		; set buffer bufw to cache
5224
 7267  F94512  A9 00         		lda	#0		; null link in this block
5225
 7268  F94514  87 90         		sta	[wbuf]		; finalize sector
5226
 7269  F94516  A0 01         		ldy	#1
5227
 7270  F94518  A5 ED         		lda	wridx		; last byte ptr (+1)
5228
 7271  F9451A  3A            		dec	a
5229
 7272  F9451B  97 90         		sta	[wbuf],y
5230
 7273  F9451D  20 7A 46      		jsr	wrtcache	; write out cache
5231
 7274  F94520  A6 57         		ldx	lindx
5232
 7275  F94522  B5 9E         		lda	dsec,x		; set dir. ptr to file entry
5233
 7276  F94524  85 09         		sta	sector
5234
 7277  F94526  A0 28         		ldy	#dirtrk
5235
 7278  F94528  84 08         		sty	track
5236
 7279  F9452A  20 3D 56      		jsr	sethdp
5237
 7280  F9452D  18            		clc
5238
 7281  F9452E  65 09         		adc	sector
5239
 7282  F94530  85 0B         		sta	dirp+1		; set dir. pointer to file entry
5240
 7283  F94532  A6 57         		ldx	lindx
5241
 7284  F94534  B5 A6         		lda	dind,x
5242
 7285  F94536  85 0A         		sta	dirp
5243
 7286  F94538  A7 0A         		lda	[dirp]		; set flag closed file
5244
 7287  F9453A  AA            		tax
5245
 7288  F9453B  29 4F         		and	#$4F		; reset replace mode
5246
 7289  F9453D  09 80         		ora	#$80
5247
 7290  F9453F  87 0A         		sta	[dirp]
5248
 7291  F94541  A0 1C         		ldy	#28		; store block's #
5249
 7292  F94543                		ACC16
5250
 7293  F94543  C2 20         		rep	#PMFLAG
5251
 7294                        		.LONGA	on
5252
 7295                        		.MNLIST
5253
 7296  F94545  A5 F0         		lda	wcnt
5254
 7297  F94547  97 0A         		sta	[dirp],y
5255
 7298  F94549                		ACC08
5256
 7299  F94549  E2 20         		sep	#PMFLAG
5257
 7300                        		.LONGA	off
5258
 7301                        		.MNLIST
5259
 7302  F9454B  8A            		txa
5260
 7303  F9454C  89 20         		bit	#$20		; replace flag?
5261
 7304  F9454E  F0 2F         		beq	?10		; no
5262
 7305  F94550  A0 1A         		ldy	#26
5263
 7306  F94552  B7 0A         		lda	[dirp],y	; get new start link
5264
 7307  F94554  AA            		tax			; X=new track
5265
 7308  F94555  C8            		iny
5266
 7309  F94556  B7 0A         		lda	[dirp],y
5267
 7310  F94558  EB            		xba			; B=new sec
5268
 7311  F94559  A0 01         		ldy	#1
5269
 7312  F9455B  B7 0A         		lda	[dirp],y	; old start track
5270
 7313  F9455D  48            		pha
5271
  Tue Jul 17 11:00:19 2018                                                                                               Page   86
5272
 
5273
 
5274
 
5275
 
5276
 7314  F9455E  8A            		txa			; new start track
5277
 7315  F9455F  97 0A         		sta	[dirp],y
5278
 7316  F94561  FA            		plx			; X=old start track
5279
 7317  F94562  C8            		iny
5280
 7318  F94563  B7 0A         		lda	[dirp],y	; old start sec
5281
 7319  F94565  EB            		xba			; A=new start sec, B=old start sec
5282
 7320  F94566  97 0A         		sta	[dirp],y
5283
 7321  F94568  EB            		xba			; A=old start sec
5284
 7322  F94569  A0 1B         		ldy	#27
5285
 7323  F9456B  97 0A         		sta	[dirp],y	; save old start sector
5286
 7324  F9456D  48            		pha
5287
 7325  F9456E  88            		dey
5288
 7326  F9456F  8A            		txa
5289
 7327  F94570  97 0A         		sta	[dirp],y	; save old start track
5290
 7328  F94572  48            		pha
5291
 7329  F94573  20 57 36      		jsr	wrdsec		; update directory
5292
 7330  F94576  68            		pla
5293
 7331  F94577  85 08         		sta	track
5294
 7332  F94579  68            		pla
5295
 7333  F9457A  85 09         		sta	sector
5296
 7334  F9457C  4C 38 33      		jmp	delfil		; delete old file
5297
 7335  F9457F  4C 57 36      	?10:	jmp	wrdsec
5298
 7336
5299
 7337  F94582                	fdda:
5300
 7338  F94582  64 88         		stz	btrf		; clear count of readden bytes
5301
 7339  F94584  64 89         		stz	btrf+1
5302
 7340  F94586  A6 57         		ldx	lindx		; file descriptor
5303
 7341  F94588  24 E6         		bit	wrop
5304
 7342                        		;bmi	???
5305
 7343  F9458A  34 96         		bit	fdst,x		; test if eof
5306
 7344  F9458C  30 28         		bmi	?40		; yes, eof
5307
 7345  F9458E  B4 BE         		ldy	fdptr,x
5308
 7346  F94590  A4 88         	?10:	ldy	btrf		; current dest buffer ptr
5309
 7347  F94592  97 90         		sta	[wbuf],y	; store in dest buffer
5310
 7348  F94594  C8            		iny
5311
 7349  F94595  84 88         		sty	btrf		; update ptr
5312
 7350  F94597  C4 86         		cpy	bsize		; check size of dest buffer
5313
 7351  F94599                		INDEX08
5314
 7352  F94599  E2 10         		sep	#PXFLAG
5315
 7353                        		.LONGI	off
5316
 7354                        		.MNLIST
5317
 7355  F9459B  B0 01         		bcs	?30		; dest buffer is full
5318
 7356  F9459D  98            		tya			; eof?
5319
 7357                        		;bne	?20		; no -- get next byte
5320
 7358  F9459E  A6 57         	?30:	ldx	lindx
5321
 7359  F945A0  A4 08         		ldy	track
5322
 7360  F945A2  94 AE         		sty	ftrk,x		; save current fd
5323
 7361  F945A4  A5 09         		lda	sector
5324
 7362  F945A6  95 B6         		sta	fsec,x
5325
 7363  F945A8  A4 E9         		ldy	rdidx
5326
 7364  F945AA  94 BE         		sty	fdptr,x
5327
 7365  F945AC  A5 EB         		lda	rdeof
5328
 7366  F945AE  F0 06         		beq	?40		; no eof
5329
 7367  F945B0  A9 80         		lda	#$80
5330
 7368  F945B2  15 96         		ora	fdst,x
5331
 7369  F945B4  95 96         		sta	fdst,x		; eof signal
5332
 7370  F945B6  18            	?40:	clc
5333
  Tue Jul 17 11:00:19 2018                                                                                               Page   87
5334
 
5335
 
5336
 
5337
 
5338
 7371  F945B7  60            		rts
5339
 7372
5340
 7373                        	; get next byte from read cache in buffered operation
5341
 7374                        	; read a new whole track in cache if needed
5342
 7375                        	; update pointer and set EOF status in rdeof
5343
 7376                        	; out:	A = byte
5344
 7377                        	;	rdeof not null if EOF
5345
 7378                        	;	rdidx updated
5346
 7379                        	; before to call this function:
5347
 7380                        	;	pre-read whole track in cache
5348
 7381                        	;	set bufp long pointer to cache and sector
5349
 7382                        	;	set rdix=2, rdeof=0, rddrv=drive#
5350
 7383                        	;	rdlst=0 if file have a next block
5351
 7384                        	;	     =last index if this is last block of file
5352
 7385  F945B8                	bufget:
5353
 7386  F945B8  A4 E9         		ldy	rdidx		; current buffer pointer
5354
 7387  F945BA  A5 EA         		lda	rdlst
5355
 7388  F945BC  F0 08         		beq	?02		; full buffer
5356
 7389  F945BE  C4 EA         		cpy	rdlst		; end of buffer?
5357
 7390  F945C0  D0 04         		bne	?02		; no
5358
 7391  F945C2  B7 8A         		lda	[bufp],y	; get byte
5359
 7392  F945C4  80 07         		bra	?04
5360
 7393  F945C6  B7 8A         	?02:	lda	[bufp],y	; get byte
5361
 7394  F945C8  C8            		iny			; bump ptr and set/reset Z
5362
 7395  F945C9  84 E9         		sty	rdidx
5363
 7396  F945CB  D0 06         		bne	?05		; exit (no EOF)
5364
 7397  F945CD  A4 EA         	?04:	ldy	rdlst
5365
 7398  F945CF  F0 03         		beq	?06		; read next file block
5366
 7399  F945D1  84 EB         		sty	rdeof		; EOF
5367
 7400  F945D3  60            	?05:	rts
5368
 7401  F945D4  85 E7         	?06:	sta	data		; save byte
5369
 7402  F945D6  A6 E8         		ldx	rddrv
5370
 7403  F945D8  86 19         		stx	drvnum
5371
 7404  F945DA  A0 01         		ldy	#1		; read link to next block
5372
 7405  F945DC  B7 8A         		lda	[bufp],y
5373
 7406  F945DE  85 09         		sta	sector
5374
 7407  F945E0  A8            		tay
5375
 7408  F945E1  A7 8A         		lda	[bufp]		; read link
5376
 7409  F945E3  C5 08         		cmp	track		; same track?
5377
 7410  F945E5  85 08         		sta	track
5378
 7411  F945E7  F0 05         		beq	?08		; ok, still in cache
5379
 7412  F945E9  20 AB 57      		jsr	tread		; read whole track
5380
 7413  F945EC  A4 09         		ldy	sector
5381
 7414  F945EE  98            	?08:	tya			; set pointer to track/sec cache
5382
 7415  F945EF  18            		clc
5383
 7416  F945F0  75 78         		adc	trkofs,x	; add start of dma buffer
5384
 7417  F945F2  85 8B         		sta	bufp+1
5385
 7418  F945F4  64 EA         		stz	rdlst		; assume full buffer
5386
 7419  F945F6  A0 01         		ldy	#1
5387
 7420  F945F8  B7 8A         		lda	[bufp],y	; next sector
5388
 7421  F945FA  A8            		tay
5389
 7422  F945FB  A7 8A         		lda	[bufp]		; next track
5390
 7423  F945FD  D0 02         		bne	?10		; is not last block
5391
 7424  F945FF  84 EA         		sty	rdlst		; is last block
5392
 7425  F94601  A0 02         	?10:	ldy	#2
5393
 7426  F94603  84 E9         		sty	rdidx		; set start pointer for next get
5394
 7427  F94605  A5 E7         		lda	data		; get byte
5395
  Tue Jul 17 11:00:19 2018                                                                                               Page   88
5396
 
5397
 
5398
 
5399
 
5400
 7428  F94607  60            		rts			; not EOF
5401
 7429
5402
 7430                        	; put byte in write cache in buffered operation
5403
 7431                        	; update buffer pointer, allocate a new t&s if needed
5404
 7432                        	; update t&s link of the file and write out the cache if needed
5405
 7433                        	; in:	A=byte
5406
 7434                        	;	wridx=buffer pointer
5407
 7435                        	;	wrdrv=drive#
5408
 7436                        	;	wfirst=first sector written in this track
5409
 7437                        	;	wsec=current sector written in this track
5410
 7438                        	;	wcnt=current count of file block's
5411
 7439                        	;	rdeof=flag eof when put last byte
5412
 7440                        	;	wbuf=long pointer to cache and sector
5413
 7441                        	; before to call this function will pre-read the track
5414
 7442                        	; of first block of the file (into write cache)
5415
 7443  F94608                	bufput:
5416
 7444  F94608  A4 ED         		ldy	wridx		; need to allocate a new block?
5417
 7445  F9460A  D0 07         		bne	?04		; no, store
5418
 7446  F9460C
5419
 7447                        		; this can happen when append data to current file
5420
 7448                        		; and last byte of last block was $FF
5421
 7449                        		; need to allocate a new block
5422
 7450  F9460C  85 E7         		sta	data		; save byte to store
5423
 7451                        		;lda	wsec		; must save just this sector
5424
 7452                        		;sta	wfirst		; set first=last sector
5425
 7453  F9460E  20 35 46      		jsr	?08		; update cache and alloc new sector...
5426
 7454  F94611  A5 E7         		lda	data		; ...return Y=wrdix
5427
 7455  F94613  97 90         	?04:	sta	[wbuf],y	; store data at
5428
 7456  F94615  A5 EB         		lda	rdeof		; test eof
5429
 7457  F94617  D0 04         		bne	?06		; eof: this is last byte
5430
 7458  F94619  C8            		iny			; bump pointer
5431
 7459  F9461A  84 ED         		sty	wridx
5432
 7460                        		;beq	?08		; need a new block
5433
 7461  F9461C  60            		rts
5434
 7462  F9461D  A9 00         	?06:	lda	#0		; null link in this block
5435
 7463  F9461F  87 90         		sta	[wbuf]		; finalize sector
5436
 7464  F94621  A0 01         		ldy	#1
5437
 7465  F94623  A5 ED         		lda	wridx		; last byte ptr
5438
 7466  F94625  97 90         		sta	[wbuf],y
5439
 7467  F94627  A6 EC         		ldx	wrdrv		; restore drive #
5440
 7468  F94629  86 19         		stx	drvnum
5441
 7469  F9462B  B5 82         		lda	wcache,x	; restore current track
5442
 7470  F9462D  85 08         		sta	track
5443
 7471  F9462F  20 7A 46      		jsr	wrtcache	; write out cache
5444
 7472  F94632  E6 ED         		inc	wridx		; bump pointer (can be null!!)
5445
 7473  F94634  60            		rts
5446
 7474  F94635  A6 EC         	?08:	ldx	wrdrv		; set drive #
5447
 7475  F94637  86 19         		stx	drvnum
5448
 7476  F94639  B5 82         		lda	wcache,x	; restore current t&s
5449
 7477  F9463B  85 08         		sta	track
5450
 7478  F9463D  A5 EE         		lda	wsec
5451
 7479  F9463F  85 09         		sta	sector
5452
 7480  F94641  20 FC 4C      		jsr	nxtts		; alloc a new sector
5453
 7481  F94644  A6 19         		ldx	drvnum
5454
 7482  F94646  A0 01         		ldy	#1
5455
 7483  F94648  A5 09         		lda	sector		; set link to new sector
5456
 7484  F9464A  97 90         		sta	[wbuf],y
5457
  Tue Jul 17 11:00:19 2018                                                                                               Page   89
5458
 
5459
 
5460
 
5461
 
5462
 7485  F9464C  A8            		tay			; Y=sector
5463
 7486  F9464D  A5 08         		lda	track
5464
 7487  F9464F  87 90         		sta	[wbuf]
5465
 7488  F94651  D5 82         		cmp	wcache,x	; same track?
5466
 7489  F94653  F0 12         		beq	?10		; yes
5467
 7490  F94655  48            		pha			; save new track
5468
 7491  F94656  B5 82         		lda	wcache,x	; set old track
5469
 7492  F94658  85 08         		sta	track
5470
 7493  F9465A  20 7A 46      		jsr	wrtcache	; write out cache
5471
 7494  F9465D  68            		pla
5472
 7495  F9465E  85 08         		sta	track		; restore new track
5473
 7496  F94660  20 C1 57      		jsr	wread		; read the new whole track in write cache
5474
 7497  F94663  A4 09         		ldy	sector
5475
 7498  F94665  84 EF         		sty	wfirst		; set first dirty sec
5476
 7499  F94667  84 EE         	?10:	sty	wsec		; update current sector
5477
 7500  F94669  18            		clc
5478
 7501  F9466A  98            		tya
5479
 7502  F9466B  75 7C         		adc	wrtofs,x	; set pointer to sector
5480
 7503  F9466D  85 91         		sta	wbuf+1
5481
 7504  F9466F                		ACC16
5482
 7505  F9466F  C2 20         		rep	#PMFLAG
5483
 7506                        		.LONGA	on
5484
 7507                        		.MNLIST
5485
 7508  F94671  E6 F0         		inc	wcnt		; update block's #
5486
 7509  F94673                		ACC08
5487
 7510  F94673  E2 20         		sep	#PMFLAG
5488
 7511                        		.LONGA	off
5489
 7512                        		.MNLIST
5490
 7513  F94675  A0 02         		ldy	#2		; set start of pointer
5491
 7514  F94677  84 ED         		sty	wridx
5492
 7515  F94679  60            		rts
5493
 7516
5494
 7517  F9467A                	wrtcache:
5495
 7518  F9467A  A6 19         		ldx	drvnum
5496
 7519  F9467C  A5 EF         		lda	wfirst		; first dirty sec
5497
 7520  F9467E  4A            		lsr	a
5498
 7521  F9467F  85 1F         		sta	tmpxxx		; dma buffer offset
5499
 7522  F94681  A8            		tay
5500
 7523  F94682  A5 EE         		lda	wsec		; last dirty sector of this track
5501
 7524  F94684  4A            		lsr	a
5502
 7525  F94685  C9 0A         		cmp	#phisec		; if last is in side 0...
5503
 7526  F94687  90 09         		bcc	?10		; ...write out side 0 only
5504
 7527  F94689  C0 0A         		cpy	#phisec		; if first is in side 1...
5505
 7528  F9468B  B0 05         		bcs	?10		; ...write out side 1 only
5506
 7529  F9468D  B5 72         		lda	wrtbuf,x	; dma buffer #
5507
 7530  F9468F  4C DF 57      		jmp	writetk		; write out whole track
5508
 7531  F94692  64 F3         	?10:	stz	pside		; assume side 0
5509
 7532  F94694  1A            		inc	a		; A = last phis. sec
5510
 7533  F94695  C8            		iny			; Y = first phis. sec
5511
 7534  F94696  90 0B         		bcc	?15		; write out side 0
5512
 7535  F94698  E6 F3         		inc	pside		; side 1
5513
 7536  F9469A  E9 0A         		sbc	#phisec
5514
 7537  F9469C  EB            		xba			; B = last phis. sec
5515
 7538  F9469D  98            		tya
5516
 7539  F9469E  38            		sec
5517
 7540  F9469F  E9 0A         		sbc	#phisec
5518
 7541  F946A1  A8            		tay			; Y = first phis. sec.
5519
  Tue Jul 17 11:00:19 2018                                                                                               Page   90
5520
 
5521
 
5522
 
5523
 
5524
 7542  F946A2  EB            		xba			; A = last phis. sec
5525
 7543  F946A3  84 94         	?15:	sty	wtmp
5526
 7544  F946A5  38            		sec
5527
 7545  F946A6  E5 94         		sbc	wtmp		; last - start + 1...
5528
 7546  F946A8  1A            		inc	a		; ...number's of sec to write out
5529
 7547  F946A9  EB            		xba			; B = sec. count #
5530
 7548  F946AA  B5 72         		lda	wrtbuf,x
5531
 7549  F946AC  18            		clc
5532
 7550  F946AD  65 1F         		adc	tmpxxx		; add sector offset
5533
 7551  F946AF  EB            		xba			; B = dma buffer #, A = sec. count #
5534
 7552  F946B0  4C 86 58      		jmp	writesec
5535
 7553
5536
 7554                        	; get next byte from dir listing cache -- special case for loaddir
5537
 7555                        	; update pointer and set EOF status in rdeof
5538
 7556                        	; out:	A = byte
5539
 7557                        	;	rdeof not null if EOF
5540
 7558                        	;	rdidx updated
5541
 7559                        	; before to call this function:
5542
 7560                        	;	prepare dir listing in cache
5543
 7561                        	;	set bufp long pointer to cache
5544
 7562                        	;	set rdix=0, rdeof=0, rddrv=drive#
5545
 7563                        	;	rdlst=0 if dir.listing have a next block
5546
 7564                        	;	     =last index if this is last block of dir. listing
5547
 7565  F946B3                	bufget2:
5548
 7566  F946B3  A4 E9         		ldy	rdidx		; current buffer pointer
5549
 7567  F946B5  A5 EA         		lda	rdlst
5550
 7568  F946B7  F0 08         		beq	?02		; use full buffer
5551
 7569  F946B9  C4 EA         		cpy	rdlst		; end of buffer?
5552
 7570  F946BB  D0 04         		bne	?02		; no
5553
 7571  F946BD  B7 8A         		lda	[bufp],y	; get byte
5554
 7572  F946BF  80 07         		bra	?04
5555
 7573  F946C1  B7 8A         	?02:	lda	[bufp],y	; get byte
5556
 7574  F946C3  C8            		iny			; bump ptr and set/reset Z
5557
 7575  F946C4  84 E9         		sty	rdidx
5558
 7576  F946C6  D0 06         		bne	?05		; exit (no EOF)
5559
 7577  F946C8  A4 EA         	?04:	ldy	rdlst
5560
 7578  F946CA  F0 03         		beq	?06		; read next dir listing block
5561
 7579  F946CC  84 EB         		sty	rdeof		; EOF
5562
 7580  F946CE  60            	?05:	rts
5563
 7581  F946CF  85 E7         	?06:	sta	data		; save byte
5564
 7582  F946D1  20 28 49      		jsr	dlist		; fill buffer with dir listing
5565
 7583  F946D4  A5 E7         		lda	data		; get byte
5566
 7584  F946D6  60            		rts
5567
 7585
5568
 7586                        	; exchange zero page var's while dir listing
5569
 7587                        	; will be used the next buffer (dir list use just one buffer)
5570
 7588  F946D7                	exxzp:
5571
 7589  F946D7  A2 3D         		ldx	#dpsave-1	; exchange page 0 var's for dir. search
5572
 7590  F946D9  9B            		txy
5573
 7591  F946DA  E6 8B         		inc	bufp+1		; next buffer
5574
 7592  F946DC  B7 8A         	?02:	lda	[bufp],y
5575
 7593  F946DE  EB            		xba
5576
 7594  F946DF  B5 00         		lda	zpstart,x
5577
 7595  F946E1  97 8A         		sta	[bufp],y
5578
 7596  F946E3  EB            		xba
5579
 7597  F946E4  95 00         		sta	zpstart,x
5580
 7598  F946E6  88            		dey
5581
  Tue Jul 17 11:00:19 2018                                                                                               Page   91
5582
 
5583
 
5584
 
5585
 
5586
 7599  F946E7  CA            		dex
5587
 7600  F946E8  10 F2         		bpl	?02
5588
 7601  F946EA  A9 80         		lda	#$80
5589
 7602  F946EC  85 8A         		sta	bufp
5590
 7603  F946EE  A2 60         		ldx	#fntlen-1	; exchange file name table
5591
 7604  F946F0  9B            		txy
5592
 7605  F946F1  B7 8A         	?04:	lda	[bufp],y
5593
 7606  F946F3  EB            		xba
5594
 7607  F946F4  BD 61 E1      		lda	!fntab,x
5595
 7608  F946F7  97 8A         		sta	[bufp],y
5596
 7609  F946F9  EB            		xba
5597
 7610  F946FA  9D 61 E1      		sta	!fntab,x
5598
 7611  F946FD  88            		dey
5599
 7612  F946FE  CA            		dex
5600
 7613  F946FF  10 F0         		bpl	?04
5601
 7614  F94701  64 8A         		stz	bufp		; restore buffer ptr to listing buffer
5602
 7615  F94703  C6 8B         		dec	bufp+1
5603
 7616  F94705  60            		rts
5604
 7617
5605
 7618                        	; save page 0 and file name table in next buffer while dir listing
5606
 7619  F94706                	savzp:
5607
 7620  F94706  A2 3D         		ldx	#dpsave-1	; save page 0 var's for dir. search
5608
 7621  F94708  9B            		txy
5609
 7622  F94709  E6 8B         		inc	bufp+1		; next buffer
5610
 7623  F9470B  B5 00         	?02:	lda	zpstart,x
5611
 7624  F9470D  97 8A         		sta	[bufp],y
5612
 7625  F9470F  88            		dey
5613
 7626  F94710  CA            		dex
5614
 7627  F94711  10 F8         		bpl	?02
5615
 7628  F94713  A9 80         		lda	#$80
5616
 7629  F94715  85 8A         		sta	bufp
5617
 7630  F94717  A2 60         		ldx	#fntlen-1	; exchange file name table
5618
 7631  F94719  9B            		txy
5619
 7632  F9471A  BD 61 E1      	?04:	lda	!fntab,x
5620
 7633  F9471D  97 8A         		sta	[bufp],y
5621
 7634  F9471F  88            		dey
5622
 7635  F94720  CA            		dex
5623
 7636  F94721  10 F7         		bpl	?04
5624
 7637  F94723  64 8A         		stz	bufp		; restore buffer ptr to listing buffer
5625
 7638  F94725  C6 8B         		dec	bufp+1
5626
 7639  F94727  60            		rts
5627
 7640
5628
 7641                        	;---------------------------------------------------------------------------
5629
 7642                        	; logical channels helper's
5630
 7643                        	;---------------------------------------------------------------------------
5631
 7644
5632
 7645                        	; open a read file
5633
 7646  F94728                	opnrfd:
5634
 7647  F94728  20 BB 47      		jsr	getrfd		; get a free file descriptor for read
5635
 7648  F9472B  A6 57         		ldx	lindx		; X=fd
5636
 7649  F9472D  A5 2A         		lda	entsec		; store dir entry in fd table
5637
 7650  F9472F  A4 2F         		ldy	entind
5638
 7651  F94731  95 9E         		sta	dsec,x
5639
 7652  F94733  94 A6         		sty	dind,x
5640
 7653  F94735  A4 20         		ldy	filtrk		; store first t&s of file
5641
 7654  F94737  84 08         		sty	track
5642
 7655  F94739  A5 25         		lda	filsec
5643
  Tue Jul 17 11:00:19 2018                                                                                               Page   92
5644
 
5645
 
5646
 
5647
 
5648
 7656  F9473B  85 09         		sta	sector
5649
 7657  F9473D  94 AE         		sty	ftrk,x
5650
 7658  F9473F  95 B6         		sta	fsec,x
5651
 7659  F94741  A9 02         		lda	#2
5652
 7660  F94743  95 BE         		sta	fdptr,x		; start of buffer
5653
 7661  F94745  A0 1C         		ldy	#28
5654
 7662  F94747                		ACC16
5655
 7663  F94747  C2 20         		rep	#PMFLAG
5656
 7664                        		.LONGA	on
5657
 7665                        		.MNLIST
5658
 7666  F94749  B7 0A         		lda	[dirp],y	; store file block's count
5659
 7667  F9474B  A6 F7         		ldx	dblfd
5660
 7668  F9474D  95 C6         		sta	fdblk,x
5661
 7669  F9474F                		ACC08
5662
 7670  F9474F  E2 20         		sep	#PMFLAG
5663
 7671                        		.LONGA	off
5664
 7672                        		.MNLIST
5665
 7673  F94751  60            		rts
5666
 7674
5667
 7675                        	; open a write file
5668
 7676                        	; if wrop<7>=0 create file
5669
 7677                        	; if wrop<7>=1 replace file
5670
 7678  F94752                	opnwfd:
5671
 7679  F94752  20 B8 47      		jsr	getwfd		; get a free file descriptor for write
5672
 7680  F94755  A9 80         		lda	#$80
5673
 7681  F94757  85 F8         		sta	trap		; trap error for free chnl on error
5674
 7682  F94759  24 E6         		bit	wrop
5675
 7683  F9475B  10 2C         		bpl	?04		; create file on dir
5676
 7684  F9475D  20 63 4D      		jsr	intts		; get a starting t&s for file
5677
 7685  F94760  A7 0A         		lda	[dirp]
5678
 7686  F94762  09 20         		ora	#$20		; set replace flag on dir entry
5679
 7687  F94764  87 0A         		sta	[dirp]
5680
 7688  F94766  A0 1A         		ldy	#26		; set replacing link on dir entry
5681
 7689  F94768  A5 08         		lda	track
5682
 7690  F9476A  97 0A         		sta	[dirp],y
5683
 7691  F9476C  85 20         		sta	filtrk
5684
 7692  F9476E  C8            		iny
5685
 7693  F9476F  A5 09         		lda	sector
5686
 7694  F94771  85 25         		sta	filsec
5687
 7695  F94773  97 0A         		sta	[dirp],y
5688
 7696  F94775  20 02 58      		jsr	bamout		; save bam on disk
5689
 7697  F94778  A5 2A         		lda	entsec
5690
 7698  F9477A  C9 04         		cmp	#4		; dir entry already sve with bam?
5691
 7699  F9477C  90 17         		bcc	?10		; yes
5692
 7700  F9477E  85 09         		sta	sector		; set sector of dir. entry
5693
 7701  F94780  A9 28         		lda	#dirtrk
5694
 7702  F94782  85 08         		sta	track
5695
 7703  F94784  20 57 36      		jsr	wrdsec		; save dir sector on disk
5696
 7704  F94787  80 0C         		bra	?10
5697
 7705  F94789  A9 28         	?04:	lda	#dirtrk
5698
 7706  F9478B  85 08         		sta	track
5699
 7707  F9478D  64 09         		stz	sector
5700
 7708  F9478F  20 3D 56      		jsr	sethdp
5701
 7709  F94792  20 D2 4B      		jsr	addfil		; create file in directory
5702
 7710  F94795  A6 57         	?10:	ldx	lindx
5703
 7711  F94797  A5 2A         		lda	entsec		; store dir entry in fd table
5704
 7712  F94799  A4 2F         		ldy	entind
5705
  Tue Jul 17 11:00:19 2018                                                                                               Page   93
5706
 
5707
 
5708
 
5709
 
5710
 7713  F9479B  95 9E         		sta	dsec,x
5711
 7714  F9479D  94 A6         		sty	dind,x
5712
 7715  F9479F  A4 20         		ldy	filtrk		; store first t&s of file
5713
 7716  F947A1  84 08         		sty	track
5714
 7717  F947A3  A5 25         		lda	filsec
5715
 7718  F947A5  85 09         		sta	sector
5716
 7719  F947A7  94 AE         		sty	ftrk,x
5717
 7720  F947A9  95 B6         		sta	fsec,x
5718
 7721  F947AB  A9 02         		lda	#2
5719
 7722  F947AD  95 BE         		sta	fdptr,x		; start of buffer
5720
 7723  F947AF  A6 F7         		ldx	dblfd
5721
 7724  F947B1  74 C6         		stz	fdblk,x		; clear block's count
5722
 7725  F947B3  74 C7         		stz	fdblk+1,x
5723
 7726  F947B5  64 F8         		stz	trap		; clear trap error
5724
 7727  F947B7  60            		rts
5725
 7728
5726
 7729                        	; allocates a new logical index and associate at given channel
5727
 7730                        	; getwfd allocate a write lindx
5728
 7731                        	; getrfd allocate a read lindx
5729
 7732  F947B8                	getwfd:
5730
 7733  F947B8  38            		sec			; set .c=1 indicate write
5731
 7734  F947B9  B0 01         		bcs	getlx
5732
 7735  F947BB                	getrfd:
5733
 7736  F947BB  18            		clc			; set .c=0 indicate read
5734
 7737  F947BC                	getlx:
5735
 7738  F947BC  08            		php			; save r/w flag (.c)
5736
 7739  F947BD  20 13 48      		jsr	fndlnx		; get next lindx open
5737
 7740  F947C0  85 57         		sta	lindx
5738
 7741  F947C2  AA            		tax
5739
 7742  F947C3  74 96         		stz	fdst,x
5740
 7743  F947C5  74 9E         		stz	dsec,x
5741
 7744  F947C7  74 A6         		stz	dind,x
5742
 7745  F947C9  74 AE         		stz	ftrk,x
5743
 7746  F947CB  74 B6         		stz	fsec,x
5744
 7747  F947CD  74 BE         		stz	fdptr,x
5745
 7748  F947CF  74 D6         		stz	fdlst,x
5746
 7749  F947D1  74 DE         		stz	fdix,x
5747
 7750  F947D3  0A            		asl	a
5748
 7751  F947D4  85 F7         		sta	dblfd
5749
 7752  F947D6  8A            		txa
5750
 7753  F947D7  A6 52         		ldx	chnl
5751
 7754  F947D9  28            		plp
5752
 7755  F947DA  90 02         		bcc	?04		; read
5753
 7756  F947DC  09 80         		ora	#$80		; set write flag
5754
 7757  F947DE  95 59         	?04:	sta	lintab,x
5755
 7758  F947E0  A5 19         		lda	drvnum
5756
 7759  F947E2  0A            		asl	a
5757
 7760  F947E3  0A            		asl	a
5758
 7761  F947E4  0A            		asl	a
5759
 7762  F947E5  15 59         		ora	lintab,x
5760
 7763  F947E7  95 59         		sta	lintab,x	; save lindx in lintab
5761
 7764  F947E9  A6 F7         		ldx	dblfd
5762
 7765  F947EB  74 C6         		stz	fdblk,x
5763
 7766  F947ED  74 C7         		stz	fdblk+1,x
5764
 7767  F947EF  60            		rts
5765
 7768
5766
 7769                        	; free a file descriptor
5767
  Tue Jul 17 11:00:19 2018                                                                                               Page   94
5768
 
5769
 
5770
 
5771
 
5772
 7770  F947F0                	frefd:
5773
 7771  F947F0  A6 52         		ldx	chnl
5774
 7772  F947F2  C9 0F         		cmp	#$0F		; free rd/wrt chnls
5775
 7773  F947F4  F0 1C         		beq	?25		; but don't free ch15
5776
 7774  F947F6  B5 59         		lda	lintab,x
5777
 7775  F947F8  C9 FF         		cmp	#$FF
5778
 7776  F947FA  F0 16         		beq	?25		; already free
5779
 7777  F947FC  29 07         		and	#$07
5780
 7778  F947FE  85 57         		sta	lindx
5781
 7779  F94800  A9 FF         		lda	#$FF
5782
 7780  F94802  95 59         		sta	lintab,x	; mark free in lintab
5783
 7781  F94804  A6 57         		ldx	lindx		; release lindx
5784
 7782  F94806  74 96         		stz	fdst,x
5785
 7783  F94808  A9 01         		lda	#1
5786
 7784  F9480A  CA            	?15:	dex
5787
 7785  F9480B  30 03         		bmi	?10
5788
 7786  F9480D  0A            		asl	a
5789
 7787  F9480E  D0 FA         		bne	?15
5790
 7788  F94810  04 58         	?10:	tsb	linuse		; 1=free 0=used
5791
 7789  F94812  60            	?25:	rts
5792
 7790
5793
 7791                        	; find free lindx to use and mark used in linuse
5794
 7792                        	; return lindx in A
5795
 7793  F94813                	fndlnx:
5796
 7794  F94813  A0 00         		ldy	#0		; bit counter
5797
 7795  F94815  A9 01         		lda	#1		; any bit is a logical index
5798
 7796  F94817  24 58         	?10:	bit	linuse		; 1=free 0=used
5799
 7797  F94819  D0 09         		bne	?30		; free index
5800
 7798  F9481B  C8            		iny
5801
 7799  F9481C  0A            		asl	a		; shift '1' 8 times
5802
 7800  F9481D  D0 F8         		bne	?10
5803
 7801  F9481F  A9 4C         		lda	#nolinx		; no free lindx available
5804
 7802  F94821  4C 07 41      		jmp	cmderr
5805
 7803  F94824  14 58         	?30:	trb	linuse		; mark bit used
5806
 7804  F94826  98            		tya			; return lindx in .a
5807
 7805  F94827  60            		rts
5808
 7806
5809
 7807                        	; check if entry in file table is open and abort if it is
5810
 7808                        	; in:	X = file stream index to check
5811
 7809                        	; A destroyed
5812
 7810  F94828                	tstopn:
5813
 7811  F94828  5A            		phy
5814
 7812  F94829  86 16         		stx	entfnd		; index 0..n-1
5815
 7813  F9482B  20 37 48      		jsr	tstfd
5816
 7814  F9482E  B0 05         		bcs	?02
5817
 7815  F94830  A9 3C         		lda	#filopn
5818
 7816  F94832  4C 07 41      		jmp	cmderr
5819
 7817  F94835  7A            	?02:	ply
5820
 7818  F94836  60            		rts
5821
 7819
5822
 7820                        	; test if entfnd is active file from lindx tbl
5823
 7821                        	; c=1 file not active
5824
 7822                        	; c=0 file active x=entfnd,y=lindx
5825
 7823                        	; use tmp0 & tmpxxx
5826
 7824  F94837                	tstfd:
5827
 7825  F94837  A2 00         		ldx	#0		; start search at top
5828
 7826  F94839  86 93         	?20:	stx	tmp0		; save to look on
5829
  Tue Jul 17 11:00:19 2018                                                                                               Page   95
5830
 
5831
 
5832
 
5833
 
5834
 7827  F9483B  B5 59         		lda	lintab,x	; get lindx
5835
 7828  F9483D  C9 FF         		cmp	#$ff
5836
 7829  F9483F  D0 08         		bne	?40		; allocated so test it
5837
 7830  F94841  A6 93         	?30:	ldx	tmp0		; not active
5838
 7831  F94843  E8            		inx
5839
 7832  F94844  E0 0F         		cpx	#mxchnls	; searched all?
5840
 7833  F94846  90 F1         		bcc	?20		; no
5841
 7834  F94848  60            		rts			; yes, CF = 1
5842
 7835  F94849  86 93         	?40:	stx	tmp0		; save x
5843
 7836  F9484B  AA            		tax
5844
 7837  F9484C  29 07         		and	#$07
5845
 7838  F9484E  A8            		tay			; Y = lindx
5846
 7839  F9484F  8A            		txa
5847
 7840  F94850  29 08         		and	#$08		; get drive #
5848
 7841  F94852  4A            		lsr	a
5849
 7842  F94853  4A            		lsr	a
5850
 7843  F94854  4A            		lsr	a
5851
 7844  F94855  4A            		lsr	a
5852
 7845  F94856  85 1F         		sta	tmpxxx
5853
 7846  F94858  A6 16         		ldx	entfnd		; index entry found
5854
 7847  F9485A  B5 34         		lda	fildrv,x
5855
 7848  F9485C  29 01         		and	#1
5856
 7849  F9485E  C5 1F         		cmp	tmpxxx		; same drive # ?
5857
 7850  F94860  D0 DF         		bne	?30		; no
5858
 7851  F94862  BB            	        tyx
5859
 7852  F94863  B5 9E         	        lda	dsec,x		; yes - same dir. entry ?
5860
 7853  F94865  A6 16         		ldx	entfnd
5861
 7854  F94867  D5 2A         		cmp	entsec,x
5862
 7855  F94869  D0 D6         		bne	?30		; no
5863
 7856  F9486B  BB            		tyx
5864
 7857  F9486C  B5 A6         		lda	dind,x
5865
 7858  F9486E  A6 16         		ldx	entfnd
5866
 7859  F94870  D5 2F         		cmp	entind,x
5867
 7860  F94872  D0 CD         		bne	?30		; no
5868
 7861  F94874  18            		clc			; active file so CF = 0
5869
 7862  F94875  60            		rts
5870
 7863
5871
 7864                        	; return file descriptor of the right type (read or write)
5872
 7865                        	; return X = lindx (fd)
5873
 7866  F94876                	fndfd:
5874
 7867  F94876  20 F2 48      		jsr	isopn		; check if file is open
5875
 7868  F94879  34 59         		bit	lintab,x
5876
 7869  F9487B  50 0A         		bvc	?08
5877
 7870  F9487D  20 CA 48      		jsr	fnddafd		; direct access
5878
 7871  F94880  90 18         		bcc	?20
5879
 7872  F94882  A9 40         		lda	#mistyp
5880
 7873  F94884  4C ED 56      		jmp	chnerr
5881
 7874  F94887  24 E6         	?08:	bit	wrop
5882
 7875  F94889  30 0A         		bmi	?10		; write file
5883
 7876  F9488B  20 A0 48      		jsr	fndrfd		; check read file
5884
 7877  F9488E  90 0A         		bcc	?20
5885
 7878  F94890  A9 44         		lda	#wrfil		; write file only
5886
 7879  F94892  4C ED 56      		jmp	chnerr
5887
 7880  F94895  20 B2 48      	?10:	jsr	fndwfd		; check write file
5888
 7881  F94898  B0 01         		bcs	?30		; read file only
5889
 7882  F9489A  60            	?20:	rts
5890
 7883  F9489B  A9 45         	?30:	lda	#rdfil
5891
  Tue Jul 17 11:00:19 2018                                                                                               Page   96
5892
 
5893
 
5894
 
5895
 
5896
 7884  F9489D  4C ED 56      		jmp	chnerr
5897
 7885
5898
 7886                        	; find lindx of read fd
5899
 7887                        	; CF = 0 if chnl is a read channel, A=X = lindx
5900
 7888                        	; CF = 1 if chnl is not a read channel
5901
 7889  F948A0                	fndrfd:
5902
 7890  F948A0  A6 52         		ldx	chnl
5903
 7891  F948A2  38            		sec
5904
 7892  F948A3  B5 59         		lda	lintab,x
5905
 7893  F948A5  30 0A         		bmi	?02
5906
 7894  F948A7  29 07         		and	#$07
5907
 7895  F948A9  85 57         		sta	lindx
5908
 7896  F948AB  AA            		tax
5909
 7897  F948AC  0A            		asl	a
5910
 7898  F948AD  85 F7         		sta	dblfd
5911
 7899  F948AF  8A            		txa
5912
 7900  F948B0  18            		clc
5913
 7901  F948B1  60            	?02:	rts
5914
 7902
5915
 7903                        	; find lindx of write fd
5916
 7904                        	; CF = 0 if chnl is a write channel, A=X = lindx
5917
 7905                        	; CF = 1 if chnl is not a write channel
5918
 7906  F948B2                	fndwfd:
5919
 7907  F948B2  A6 52         		ldx	chnl
5920
 7908  F948B4  B5 59         		lda	lintab,x
5921
 7909  F948B6  A8            		tay
5922
 7910  F948B7  0A            		asl	a
5923
 7911  F948B8  90 0E         		bcc	?20		; bit 7 = 0, not ok
5924
 7912  F948BA  30 0C         		bmi	?20		; bit 7 & 6 = 1, not ok
5925
 7913  F948BC  98            		tya
5926
 7914  F948BD  29 07         		and	#$07
5927
 7915  F948BF  85 57         		sta	lindx
5928
 7916  F948C1  AA            		tax
5929
 7917  F948C2  0A            		asl	a
5930
 7918  F948C3  85 F7         		sta	dblfd
5931
 7919  F948C5  8A            		txa
5932
 7920  F948C6  18            		clc
5933
 7921  F948C7  60            		rts
5934
 7922  F948C8  38            	?20:	sec
5935
 7923  F948C9  60            		rts
5936
 7924
5937
 7925                        	; find lindx of direct access fd
5938
 7926                        	; CF = 0 if chnl is direct access type, A=X = lindx
5939
 7927                        	; CF = 1 if not
5940
 7928  F948CA                	fnddafd:
5941
 7929  F948CA  A6 52         		ldx	chnl
5942
 7930  F948CC  B5 59         		lda	lintab,x
5943
 7931  F948CE  A8            		tay
5944
 7932  F948CF  0A            		asl	a
5945
 7933  F948D0  B0 0D         		bcs	?10		; bit 7=1, not ok
5946
 7934  F948D2  10 0C         		bpl	?20		; bit 6=0, not ok
5947
 7935  F948D4  98            		tya			; ok, just bit 6=1
5948
 7936  F948D5  29 07         		and	#$07
5949
 7937  F948D7  85 57         		sta	lindx
5950
 7938  F948D9  AA            		tax
5951
 7939  F948DA  0A            		asl	a
5952
 7940  F948DB  85 F7         		sta	dblfd
5953
  Tue Jul 17 11:00:19 2018                                                                                               Page   97
5954
 
5955
 
5956
 
5957
 
5958
 7941  F948DD  8A            		txa
5959
 7942  F948DE  18            		clc
5960
 7943  F948DF  60            	?10:	rts
5961
 7944  F948E0  38            	?20:	sec
5962
 7945  F948E1  60            		rts
5963
 7946
5964
 7947                        	; get drive associated with fd
5965
 7948  F948E2                	fddrv:
5966
 7949  F948E2  A6 52         		ldx	chnl
5967
 7950  F948E4  B5 59         		lda	lintab,x
5968
 7951  F948E6  C9 FF         		cmp	#$FF
5969
 7952  F948E8  F0 07         		beq	?04
5970
 7953  F948EA  29 08         		and	#$08		; drive is in bit 3
5971
 7954  F948EC  4A            		lsr	a
5972
 7955  F948ED  4A            		lsr	a
5973
 7956  F948EE  4A            		lsr	a
5974
 7957  F948EF  85 19         		sta	drvnum
5975
 7958  F948F1  60            	?04:	rts
5976
 7959
5977
 7960                        	; test if given channel is open
5978
 7961  F948F2                	isopn:
5979
 7962  F948F2  A6 52         		ldx	chnl
5980
 7963  F948F4  B5 59         		lda	lintab,x
5981
 7964  F948F6  C9 FF         		cmp	#$FF
5982
 7965  F948F8  F0 01         		beq	?02		; channel not open
5983
 7966  F948FA  60            		rts
5984
 7967  F948FB  A9 3D         	?02:	lda	#filnop
5985
 7968  F948FD  4C ED 56      		jmp	chnerr
5986
 7969
5987
 7970                        	; get first available channel in range 2..14
5988
 7971                        	; return channel in X and chnl
5989
 7972  F94900                	getfre:
5990
 7973  F94900  A2 02         		ldx	#2		; start from chnl 2
5991
 7974  F94902  B5 59         	?02:	lda	lintab,x
5992
 7975  F94904  C9 FF         		cmp	#$FF
5993
 7976  F94906  F0 0A         		beq	?04
5994
 7977  F94908  E8            		inx
5995
 7978  F94909  E0 0F         		cpx	#mxchnls
5996
 7979  F9490B  90 F5         		bcc	?02
5997
 7980  F9490D  A9 46         		lda	#nochnl		; no channels available
5998
 7981  F9490F  4C 07 41      		jmp	cmderr
5999
 7982  F94912  86 52         	?04:	stx	chnl
6000
 7983  F94914  60            		rts
6001
 7984
6002
 7985                        	; set pointer to buffer associated with logical index
6003
 7986                        	; return X = lindx
6004
 7987  F94915                	setfdp:
6005
 7988  F94915  A5 57         		lda	lindx
6006
 7989  F94917  AA            		tax
6007
 7990  F94918  18            		clc
6008
 7991  F94919  69 D4         		adc	#DMALXBUF	; buffer # for index = 0
6009
 7992  F9491B  A0 02         		ldy	#DMABNK		; bank for buffer #00..#7F
6010
 7993  F9491D  0A            		asl	a		; get high pointer
6011
 7994  F9491E  90 01         		bcc	?02
6012
 7995  F94920  C8            		iny			; next bank
6013
 7996  F94921  64 8A         	?02:	stz	bufp		; set buffer pointer
6014
 7997  F94923  85 8B         		sta	bufp+1
6015
  Tue Jul 17 11:00:19 2018                                                                                               Page   98
6016
 
6017
 
6018
 
6019
 
6020
 7998  F94925  84 8C         		sty	bufp+2
6021
 7999  F94927  60            		rts
6022
 8000
6023
 8001                        	;---------------------------------------------------------------------------
6024
 8002                        	; directory listing
6025
 8003                        	;---------------------------------------------------------------------------
6026
 8004
6027
 8005                        	; fill buffer with dir listing
6028
 8006                        	; any list line is 32 bytes long and in cbm basic format
6029
 8007                        	; first 2 bytes is the basic line link
6030
 8008                        	; follow 2 bytes with blocks count of file (like a basic line number)
6031
 8009                        	; follow file name and type
6032
 8010                        	; last byte is null fo terminate basic line
6033
 8011                        	; when listing terminate two null will be appended for terminate basic text
6034
 8012                        	;
6035
 8013                        	; in:	Y=current pointer to dest buffer
6036
 8014                        	; out:	rdlst is ptr to last byte (if not null ending listing)
6037
 8015  F94928                	dlist:
6038
 8016  F94928  A9 01         		lda	#1		; insert fhoney links ($0101)
6039
 8017  F9492A  97 8A         		sta	[bufp],y
6040
 8018  F9492C  C8            		iny
6041
 8019  F9492D  97 8A         		sta	[bufp],y
6042
 8020  F9492F  C8            		iny
6043
 8021  F94930  20 67 49      		jsr	getnam		; get file name and fill name buffer
6044
 8022  F94933  B0 16         		bcs	?10		; CF=1 if last entry
6045
 8023  F94935  A5 94         		lda	wtmp		; put blocks #
6046
 8024  F94937  97 8A         		sta	[bufp],y
6047
 8025  F94939  C8            		iny
6048
 8026  F9493A  A5 95         		lda	wtmp+1
6049
 8027  F9493C  97 8A         		sta	[bufp],y
6050
 8028  F9493E  C8            		iny
6051
 8029  F9493F  20 1F 4A      		jsr	movbuf		; move 27 bytes from name buffer
6052
 8030  F94942  A9 00         		lda	#0		; end of entry
6053
 8031  F94944  97 8A         		sta	[bufp],y
6054
 8032  F94946  C8            		iny
6055
 8033  F94947  D0 DF         		bne	dlist		; next entry
6056
 8034  F94949  80 19         		bra	?20		; buffer is full
6057
 8035  F9494B  A5 94         	?10:	lda	wtmp		; this is end of listing
6058
 8036  F9494D  97 8A         		sta	[bufp],y	; send free blocks #
6059
 8037  F9494F  C8            		iny
6060
 8038  F94950  A5 95         		lda	wtmp+1
6061
 8039  F94952  97 8A         		sta	[bufp],y
6062
 8040  F94954  C8            		iny
6063
 8041  F94955  20 1F 4A      		jsr	movbuf		; move 27 bytes from name buffer
6064
 8042  F94958  88            		dey			; -2 bytes for make room for double null
6065
 8043  F94959  88            		dey
6066
 8044  F9495A  A9 00         		lda	#0		; end of listing (000)
6067
 8045  F9495C  97 8A         		sta	[bufp],y
6068
 8046  F9495E  C8            		iny
6069
 8047  F9495F  97 8A         		sta	[bufp],y
6070
 8048  F94961  C8            		iny
6071
 8049  F94962  97 8A         		sta	[bufp],y
6072
 8050  F94964  84 EA         	?20:	sty	rdlst		; set end pointer (not 0 if end)
6073
 8051  F94966  60            		rts
6074
 8052
6075
 8053                        	; get next file entry from directory
6076
 8054                        	; if listing is complete return with CF=1
6077
  Tue Jul 17 11:00:19 2018                                                                                               Page   99
6078
 
6079
 
6080
 
6081
 
6082
 8055  F94967                	getnam:
6083
 8056  F94967  5A            		phy			; save buffer index
6084
 8057  F94968  A5 16         		lda	entfnd
6085
 8058  F9496A  10 1E         		bpl	?10		; more files
6086
 8059  F9496C  20 2D 4A      		jsr	blknb		; this is end of listing
6087
 8060  F9496F  A2 0B         		ldx	#msglen-1
6088
 8061  F94971  BF 9C 5A F9   	?02:	lda	>fremsg,x
6089
 8062  F94975  9D C2 E1      		sta	!nambuf,x
6090
 8063  F94978  CA            		dex
6091
 8064  F94979  10 F6         		bpl	?02
6092
 8065  F9497B  A5 19         		lda	drvnum
6093
 8066  F9497D  0A            		asl	a
6094
 8067  F9497E  AA            		tax
6095
 8068  F9497F  B5 6A         		lda	ndbf,x		; save free block's count
6096
 8069  F94981  85 94         		sta	wtmp
6097
 8070  F94983  B5 6B         		lda	ndbf+1,x
6098
 8071  F94985  85 95         		sta	wtmp+1
6099
 8072  F94987  7A            		ply
6100
 8073  F94988  38            		sec			; CF=1 end of listing
6101
 8074  F94989  60            		rts
6102
 8075
6103
 8076  F9498A  A2 18         	?10:	ldx	#dirlen		; set number blocks
6104
 8077  F9498C  A0 1D         		ldy	#29		;  & adjust spacing
6105
 8078  F9498E  B7 0A         		lda	[dirp],y	; hi blocks #
6106
 8079  F94990  85 95         		sta	wtmp+1
6107
 8080  F94992  F0 02         		beq	?12
6108
 8081  F94994  A2 16         		ldx	#dirlen-2	; blocks < 256
6109
 8082  F94996  88            	?12:	dey
6110
 8083  F94997  B7 0A         		lda	[dirp],y	; low blocks #
6111
 8084  F94999  85 94         		sta	wtmp
6112
 8085  F9499B  E0 16         		cpx	#dirlen-2
6113
 8086  F9499D  F0 0A         		beq	?14
6114
 8087  F9499F  C9 0A         		cmp	#10
6115
 8088  F949A1  90 06         		bcc	?14		; blocks < 10
6116
 8089  F949A3  CA            		dex
6117
 8090  F949A4  C9 64         		cmp	#100
6118
 8091  F949A6  90 01         		bcc	?14		; blocks < 100
6119
 8092  F949A8  CA            		dex
6120
 8093  F949A9  20 2D 4A      	?14:	jsr	blknb		; clear name buffer
6121
 8094  F949AC  A7 0A         		lda	[dirp]		; set type chars
6122
 8095  F949AE  48            		pha
6123
 8096  F949AF  0A            		asl	a		; (used in bcs for check closed flag)
6124
 8097  F949B0  10 05         		bpl	?15		; file not locked
6125
 8098  F949B2  A9 3C         		lda	#'<'
6126
 8099  F949B4  9D C3 E1      		sta	!nambuf+1,x	; file locked
6127
 8100  F949B7  68            	?15:	pla
6128
 8101  F949B8  29 0F         		and	#$0f
6129
 8102  F949BA  9B            		txy			; Y = nambuf index
6130
 8103  F949BB  AA            		tax			; X = file type
6131
 8104  F949BC  BF 90 5A F9   		lda	>tp2lst,x
6132
 8105  F949C0  99 C2 E1      		sta	nambuf,y
6133
 8106  F949C3  88            		dey
6134
 8107  F949C4  BF 8A 5A F9   		lda	>tp1lst,x
6135
 8108  F949C8  99 C2 E1      		sta	nambuf,y
6136
 8109  F949CB  88            		dey
6137
 8110  F949CC  BF 84 5A F9   		lda	>typlst,x
6138
 8111  F949D0  99 C2 E1      		sta	nambuf,y
6139
  Tue Jul 17 11:00:19 2018                                                                                               Page  100
6140
 
6141
 
6142
 
6143
 
6144
 8112  F949D3  88            		dey
6145
 8113  F949D4  88            		dey
6146
 8114  F949D5  B0 05         		bcs	?20		; (from asl)
6147
 8115  F949D7  A9 2A         		lda	#'*'		; file not closed: splat file
6148
 8116  F949D9  99 C3 E1      		sta	nambuf+1,y
6149
 8117  F949DC  A9 A0         	?20:	lda	#$A0
6150
 8118  F949DE  99 C2 E1      		sta	nambuf,y
6151
 8119  F949E1  BB            		tyx			; X = nambuf index
6152
 8120  F949E2  CA            		dex
6153
 8121  F949E3  A0 12         		ldy	#18		; end of file name
6154
 8122  F949E5  B7 0A         	?22:	lda	[dirp],y	; move file name
6155
 8123  F949E7  9D C2 E1      		sta	!nambuf,x
6156
 8124  F949EA  CA            		dex
6157
 8125  F949EB  88            		dey
6158
 8126  F949EC  C0 03         		cpy	#3
6159
 8127  F949EE  B0 F5         		bcs	?22
6160
 8128  F949F0  A9 22         		lda	#'"'		; send name in quotes
6161
 8129  F949F2  9D C2 E1      		sta	!nambuf,x
6162
 8130  F949F5  E8            	?30:	inx
6163
 8131  F949F6  E0 20         		cpx	#$20		; max 32 bytes
6164
 8132  F949F8  B0 0B         		bcs	?35
6165
 8133  F949FA  BD C2 E1      		lda	!nambuf,x
6166
 8134  F949FD  C9 22         		cmp	#'"'
6167
 8135  F949FF  F0 04         		beq	?35
6168
 8136  F94A01  C9 A0         		cmp	#$A0		; stop at first padding byte
6169
 8137  F94A03  D0 F0         		bne	?30
6170
 8138  F94A05  A9 22         	?35:	lda	#'"'
6171
 8139  F94A07  9D C2 E1      		sta	!nambuf,x
6172
 8140  F94A0A  E8            	?37:	inx
6173
 8141  F94A0B  E0 20         		cpx	#$20
6174
 8142  F94A0D  B0 0A         		bcs	?40
6175
 8143  F94A0F  A9 7F         		lda	#$7F		; clear bit of any char
6176
 8144  F94A11  3D C2 E1      		and	!nambuf,x
6177
 8145  F94A14  9D C2 E1      		sta	!nambuf,x
6178
 8146  F94A17  80 F1         		bra	?37
6179
 8147  F94A19  20 88 4A      	?40:	jsr	fndfil		; put dir ptr to next entry
6180
 8148  F94A1C  7A            		ply
6181
 8149  F94A1D  18            		clc			; CF=0 no ending listing
6182
 8150  F94A1E  60            		rts
6183
 8151
6184
 8152                        	; move file name to listing buf
6185
 8153  F94A1F                	movbuf:
6186
 8154  F94A1F  A2 00         		ldx	#0
6187
 8155  F94A21  BD C2 E1      	?02:	lda	!nambuf,x
6188
 8156  F94A24  97 8A         		sta	[bufp],y
6189
 8157  F94A26  C8            		iny
6190
 8158  F94A27  E8            		inx
6191
 8159  F94A28  E0 1B         		cpx	#nbsiz
6192
 8160  F94A2A  D0 F5         		bne	?02
6193
 8161  F94A2C  60            		rts
6194
 8162
6195
 8163                        	; blank nambuf
6196
 8164  F94A2D                	blknb:
6197
 8165  F94A2D  A0 1B         		ldy	#nbsiz
6198
 8166  F94A2F  A9 20         		lda	#' '
6199
 8167  F94A31  99 C1 E1      	?02:	sta	nambuf-1,y
6200
 8168  F94A34  88            		dey
6201
  Tue Jul 17 11:00:19 2018                                                                                               Page  101
6202
 
6203
 
6204
 
6205
 
6206
 8169  F94A35  D0 FA         		bne	?02
6207
 8170  F94A37  60            		rts
6208
 8171
6209
 8172                        	;---------------------------------------------------------------------------
6210
 8173                        	; directory search helper's
6211
 8174                        	;---------------------------------------------------------------------------
6212
 8175
6213
 8176                        	; lookup all files in stream and fill tbls w/info
6214
 8177  F94A38                	lookup:
6215
 8178  F94A38  20 97 4B      		jsr	optsch		; init drive(s)
6216
 8179  F94A3B                	lookup2:
6217
 8180  F94A3B  A6 19         	?05:	ldx	drvnum
6218
 8181  F94A3D  74 02         		stz	delind,x
6219
 8182  F94A3F  20 2D 4B      		jsr	srchst		; start search
6220
 8183  F94A42  D0 10         		bne	?25		; valid entry
6221
 8184  F94A44  24 18         	?10:	bit	tgflg		; end of dir - search both drives?
6222
 8185  F94A46  10 1D         		bpl	?40		; no, so exit
6223
 8186  F94A48  70 1B         		bvs	?40		; other drive already searched, so exit
6224
 8187  F94A4A  20 8A 4B      		jsr	togdrv		; toggle drvnum
6225
 8188  F94A4D  80 EC         		bra	?05		; lookup on other drive
6226
 8189  F94A4F  20 76 4B      	?20:	jsr	search		; find valid fn
6227
 8190  F94A52  F0 0D         		beq	?30		; end of directory
6228
 8191  F94A54  20 A6 4A      	?25:	jsr	compar		; compare dir w/ table
6229
 8192  F94A57  A5 17         		lda	found		; found flag
6230
 8193  F94A59  D0 0A         		bne	?40		; all fn's found
6231
 8194  F94A5B  A5 16         		lda	entfnd
6232
 8195  F94A5D  30 F0         		bmi	?20		; no match, continue searching dir
6233
 8196  F94A5F  10 F3         		bpl	?25		; last match, compare again tables
6234
 8197  F94A61  A5 17         	?30:	lda	found
6235
 8198  F94A63  F0 DF         		beq	?10		; lookup other drive, if need
6236
 8199  F94A65  60            	?40:	rts
6237
 8200
6238
 8201                        	; find next file name matching
6239
 8202                        	; any file in stream & return
6240
 8203                        	; with entry found stuffed into tables
6241
 8204                        	; return N=1 if lookup exhausted, otherwise N=0
6242
 8205                        	; ffst start a search
6243
 8206                        	; findfil continue a search
6244
 8207                        	; ffre re-entry a search
6245
 8208  F94A66                	ffre:
6246
 8209  F94A66  20 65 4B      		jsr	srre		; find file re-entry
6247
 8210  F94A69  F0 10         		beq	ffend		; end of directory
6248
 8211  F94A6B  D0 20         		bne	ffcp		; found valid entry
6249
 8212
6250
 8213  F94A6D                	ffst0:
6251
 8214  F94A6D  20 8A 4B      		jsr	togdrv		; toggle drvnum and start again search
6252
 8215                        					; lookup it in the other drive
6253
 8216  F94A70                	ffst:
6254
 8217  F94A70  A6 19         		ldx	drvnum		; find file start entry
6255
 8218  F94A72  74 02         		stz	delind,x
6256
 8219  F94A74  20 2D 4B      		jsr	srchst
6257
 8220  F94A77  D0 14         		bne	ffcp		; found valid entry
6258
 8221  F94A79  85 17         		sta	found		; found=0 if end of directory
6259
 8222  F94A7B  A5 17         	ffend:	lda	found		; = $FF if lookup completed
6260
 8223  F94A7D  D0 08         		bne	?04		; exit with N=1
6261
 8224  F94A7F  24 18         		bit	tgflg		; search both drives?
6262
 8225  F94A81  10 02         		bpl	?02		; no, so exit with N=1
6263
  Tue Jul 17 11:00:19 2018                                                                                               Page  102
6264
 
6265
 
6266
 
6267
 
6268
 8226  F94A83  50 E8         		bvc	ffst0		; start searching on the other drive
6269
 8227                        					; if not already searched
6270
 8228  F94A85  A9 FF         	?02:	lda	#$FF		; exit with N=1
6271
 8229  F94A87  60            	?04:	rts
6272
 8230
6273
 8231  F94A88                	fndfil:
6274
 8232  F94A88  20 76 4B      		jsr	search		; find file continuous...
6275
 8233  F94A8B  F0 EE         		beq	ffend		; end of directory
6276
 8234  F94A8D  20 A6 4A      	ffcp:	jsr	compar		; compare file names and fill tables
6277
 8235  F94A90  A6 16         		ldx	entfnd
6278
 8236  F94A92  10 05         		bpl	?30		; file stream tabulated
6279
 8237  F94A94  A5 17         		lda	found
6280
 8238  F94A96  F0 F0         		beq	fndfil		; continue searching
6281
 8239  F94A98  60            		rts			; N=1 - stop search
6282
 8240  F94A99  A5 10         	?30:	lda	typflg
6283
 8241  F94A9B  F0 08         		beq	?40		; no type restriction - exit N=0
6284
 8242  F94A9D  B5 39         		lda	pattyp,x
6285
 8243  F94A9F  29 07         		and	#typmsk
6286
 8244  F94AA1  C5 10         		cmp	typflg
6287
 8245  F94AA3  D0 E3         		bne	fndfil
6288
 8246  F94AA5  60            	?40:	rts			; exit N=0
6289
 8247
6290
 8248                        	;compare all filenames in stream table
6291
 8249                        	;  with each valid entry in the
6292
 8250                        	;  directory and matches are tabulated
6293
 8251                        	;  Z=0,N=1 and found=$FF if table exhausted
6294
 8252                        	;  Z=1,N=0 and found=0 if table not exhausted
6295
 8253                        	;  entfnd = index of matching files stream or $FF in no match
6296
 8254                        	;  at first match this function exit
6297
 8255                        	;  if a search involve both drives, first will be processed table for
6298
 8256                        	;  drvnum and after will be processed table for the other drive
6299
 8257  F94AA6                	compar:
6300
 8258  F94AA6  A2 FF         		ldx	#$FF
6301
 8259  F94AA8  86 16         		stx	entfnd		; set entry not found
6302
 8260  F94AAA  E8            		inx
6303
 8261  F94AAB  86 11         		stx	patflg
6304
 8262  F94AAD  20 12 4B      		jsr	?90		; check unfound entry in file stream
6305
 8263  F94AB0  F0 06         		beq	?10		; unfound, so will be tabulated
6306
 8264  F94AB2  60            	?02:	rts			; all are found
6307
 8265  F94AB3  20 1A 4B      	?05:	jsr	?91		; check next entry in file stream
6308
 8266  F94AB6  D0 FA         		bne	?02		; all are found
6309
 8267  F94AB8  A5 19         	?10:	lda	drvnum		; current drive
6310
 8268  F94ABA  55 34         		eor	fildrv,x
6311
 8269  F94ABC  4A            		lsr	a
6312
 8270  F94ABD  B0 F4         		bcs	?05		; drive doesn't match, check next file
6313
 8271  F94ABF  B5 1A         	?20:	lda	filtbl,x	; good drive match
6314
 8272  F94AC1  AA            		tax			; pointer to pattern
6315
 8273  F94AC2  A0 03         		ldy	#3		; offset of entry name in directory sec
6316
 8274  F94AC4  BD 00 E1      	?30:	lda	!cmdbuf,x	; compare byte
6317
 8275  F94AC7  F0 0C         		beq	?40		; match filename !
6318
 8276  F94AC9  D7 0A         		cmp	[dirp],y
6319
 8277  F94ACB  F0 04         		beq	?32		; match byte
6320
 8278  F94ACD  C9 3F         		cmp	#'?'		; '?' match any byte
6321
 8279  F94ACF  D0 E2         		bne	?05		; no match so check next entry in file stream
6322
 8280  F94AD1  E8            	?32:	inx
6323
 8281  F94AD2  C8            		iny
6324
 8282  F94AD3  80 EF         		bra	?30
6325
  Tue Jul 17 11:00:19 2018                                                                                               Page  103
6326
 
6327
 
6328
 
6329
 
6330
 8283  F94AD5  A6 15         	?40:	ldx	f2ptr		; file name match
6331
 8284  F94AD7  86 16         		stx	entfnd		; save index in file stream
6332
 8285  F94AD9  B5 39         		lda	pattyp,x	; store info in tables
6333
 8286  F94ADB  29 80         		and	#$80
6334
 8287  F94ADD  85 11         		sta	patflg		; pattern flag
6335
 8288  F94ADF  9B            		txy
6336
 8289  F94AE0  A6 19         		ldx	drvnum
6337
 8290  F94AE2  B5 06         		lda	index,x
6338
 8291  F94AE4  BB            		tyx
6339
 8292  F94AE5  95 2F         		sta	entind,x
6340
 8293  F94AE7  A5 09         		lda	sector
6341
 8294  F94AE9  95 2A         		sta	entsec,x
6342
 8295  F94AEB  A7 0A         		lda	[dirp]
6343
 8296  F94AED  48            		pha
6344
 8297  F94AEE  29 40         		and	#$40		; mask on lock bit
6345
 8298  F94AF0  85 93         		sta	tmp0
6346
 8299  F94AF2  68            		pla
6347
 8300  F94AF3  29 DF         		and	#$FF-$20	; mask off bit 5 ($DF)
6348
 8301  F94AF5  30 02         		bmi	?42		; if is closed
6349
 8302  F94AF7  09 20         		ora	#$20		; file not closed: set bit 5
6350
 8303  F94AF9  29 27         	?42:	and	#$27		; mask open bit and type
6351
 8304  F94AFB  05 93         		ora	tmp0		; plus lock bit
6352
 8305  F94AFD  85 93         		sta	tmp0
6353
 8306  F94AFF  A9 80         		lda	#$80
6354
 8307  F94B01  35 39         		and	pattyp,x	; <7>: pattern
6355
 8308  F94B03  05 93         		ora	tmp0		; <6>: lock bit, <5>: closed flag
6356
 8309  F94B05  95 39         		sta	pattyp,x	; <2:0>: file type
6357
 8310  F94B07  A0 01         		ldy	#1		; first track & sector of file
6358
 8311  F94B09  B7 0A         		lda	[dirp],y
6359
 8312  F94B0B  95 20         		sta	filtrk,x
6360
 8313  F94B0D  C8            		iny
6361
 8314  F94B0E  B7 0A         		lda	[dirp],y
6362
 8315  F94B10  95 25         		sta	filsec,x
6363
 8316  F94B12
6364
 8317                        		; restart table check -- in this way exit always with found=0
6365
 8318                        		; if tables not exhausted
6366
 8319
6367
 8320                        	; check table for unfound files
6368
 8321  F94B12  A9 FF         	?90:	lda	#$FF
6369
 8322  F94B14  85 17         		sta	found
6370
 8323  F94B16  A5 13         		lda	f2cnt
6371
 8324  F94B18  85 15         		sta	f2ptr
6372
 8325  F94B1A  C6 15         	?91:	dec	f2ptr
6373
 8326  F94B1C  30 0E         		bmi	?99		; table exhausted
6374
 8327                        					; exit with Z=0,N=1 and found=$FF
6375
 8328  F94B1E  A6 15         		ldx	f2ptr
6376
 8329  F94B20  B5 39         		lda	pattyp,x
6377
 8330  F94B22  30 04         		bmi	?95		; wildcards: still must search
6378
 8331  F94B24  B5 20         		lda	filtrk,x
6379
 8332  F94B26  D0 F2         		bne	?91		; already tabulated so skip
6380
 8333  F94B28  A9 00         	?95:	lda	#0		; exit with Z=1,N=0...
6381
 8334  F94B2A  85 17         		sta	found		; ... and found=0
6382
 8335  F94B2C  60            	?99:	rts
6383
 8336
6384
 8337                        	; search directory
6385
 8338                        	;  returns with valid entry w/ delind=0
6386
 8339                        	;  or returns w/ 1st deleted entry w/ delind=1
6387
  Tue Jul 17 11:00:19 2018                                                                                               Page  104
6388
 
6389
 
6390
 
6391
 
6392
 8340                        	;  srchst will initiate a search
6393
 8341                        	;  search will continue a search
6394
 8342                        	;  srre will re-entry a search
6395
 8343  F94B2D                	srchst:
6396
 8344  F94B2D  A6 19         		ldx	drvnum
6397
 8345  F94B2F  A0 00         		ldy	#0		; init deleted sector
6398
 8346  F94B31  94 00         		sty	delsec,x
6399
 8347  F94B33  88            		dey
6400
 8348  F94B34  84 16         		sty	entfnd		; = $FF => not found
6401
 8349  F94B36  A9 28         		lda	#dirtrk		; start search at beginning
6402
 8350  F94B38  85 08         		sta	track
6403
 8351  F94B3A  A9 03         		lda	#dirst		; /1st dir blk
6404
 8352  F94B3C  85 09         	srnews:	sta	sector		; search from beginning or from a new sector
6405
 8353  F94B3E  20 C3 4C      		jsr	setdptr		; set dir buffer ptr
6406
 8354  F94B41  A7 0A         	srnext:	lda	[dirp]		; search next entry
6407
 8355  F94B43  D0 11         		bne	?02		; not empty entry
6408
 8356  F94B45  B5 00         		lda	delsec,x	; deleted entry found
6409
 8357  F94B47  D0 2D         		bne	search		; deleted entry already found
6410
 8358  F94B49  A5 09         		lda	sector		; store sector of empty entry
6411
 8359  F94B4B  95 00         		sta	delsec,x
6412
 8360  F94B4D  A5 0A         		lda	dirp		; get current index of entry
6413
 8361  F94B4F  B4 02         		ldy	delind,x	; bit1: want deleted entry
6414
 8362  F94B51  95 02         		sta	delind,x	; store index of empty entry
6415
 8363  F94B53  F0 21         		beq	search		; delind=0 => want valid entry
6416
 8364  F94B55  60            		rts			; (Z=0)
6417
 8365  F94B56  A9 01         	?02:	lda	#1
6418
 8366  F94B58  D5 02         		cmp	delind,x	; ?looking for empty entry?
6419
 8367  F94B5A  F0 1A         		beq	search		; yes => continue searching
6420
 8368                        					; no! found not empty entry
6421
 8369  F94B5C  A5 0A         		lda	dirp		; found not empty entry
6422
 8370  F94B5E  95 06         		sta	index,x		; save index
6423
 8371  F94B60  A5 09         		lda	sector
6424
 8372  F94B62  95 04         		sta	dirsec,x	; save sector
6425
 8373  F94B64  60            		rts			; (Z=0)
6426
 8374
6427
 8375                        	; re-entry from a search
6428
 8376  F94B65                	srre:
6429
 8377  F94B65  A6 19         		ldx	drvnum		; get last used accessed search
6430
 8378  F94B67  A9 28         		lda	#dirtrk
6431
 8379  F94B69  85 08         		sta	track
6432
 8380  F94B6B  B5 04         		lda	dirsec,x	; found entry sector
6433
 8381  F94B6D  85 09         		sta	sector
6434
 8382  F94B6F  20 C3 4C      		jsr	setdptr		; set dir buffer ptr
6435
 8383  F94B72  B5 06         		lda	index,x		; found entry index
6436
 8384  F94B74  85 0A         		sta	dirp		; set dir buffer low ptr
6437
 8385  F94B76
6438
 8386                        	; continue a searching
6439
 8387  F94B76                	search:
6440
 8388  F94B76  A6 19         		ldx	drvnum
6441
 8389  F94B78  A9 FF         		lda	#$FF
6442
 8390  F94B7A  85 16         		sta	entfnd
6443
 8391  F94B7C  A9 20         		lda	#32		; incr by 32
6444
 8392  F94B7E  18            		clc
6445
 8393  F94B7F  65 0A         		adc	dirp
6446
 8394  F94B81  85 0A         		sta	dirp		; next entry...
6447
 8395  F94B83  90 BC         		bcc	srnext		; ...in same sector
6448
 8396  F94B85  A5 0D         		lda	nxtsec		; next dir sector
6449
  Tue Jul 17 11:00:19 2018                                                                                               Page  105
6450
 
6451
 
6452
 
6453
 
6454
 8397  F94B87  D0 B3         		bne	srnews		; not last dir sec
6455
 8398  F94B89  60            		rts			; exit with Z = 1
6456
 8399
6457
 8400                        	; toggle drive number in drvnum
6458
 8401  F94B8A                	togdrv:
6459
 8402  F94B8A  A5 19         		lda	drvnum
6460
 8403  F94B8C  49 01         		eor	#1
6461
 8404  F94B8E  29 01         		and	#1
6462
 8405  F94B90  85 19         		sta	drvnum
6463
 8406  F94B92  A9 40         		lda	#$40		; set bit 6 for signaling toggle
6464
 8407  F94B94  04 18         		tsb	tgflg
6465
 8408  F94B96  60            		rts
6466
 8409
6467
 8410                        	; set tgflg for search option on both drives and init drive's
6468
 8411                        	; read system directory and check integrity of header
6469
 8412  F94B97                	optsch:
6470
 8413  F94B97  A9 00         		lda	#0
6471
 8414  F94B99  85 18         		sta	tgflg
6472
 8415  F94B9B  A6 13         		ldx	f2cnt		; scan file stream
6473
 8416  F94B9D  A8            	?02:	tay			; option search
6474
 8417  F94B9E  CA            		dex			; adjust pointer
6475
 8418  F94B9F  30 0E         		bmi	?06		; end scanning
6476
 8419  F94BA1  B5 34         		lda	fildrv,x
6477
 8420  F94BA3  4A            		lsr	a		; CF = drive
6478
 8421  F94BA4  98            		tya
6479
 8422  F94BA5  B0 04         		bcs	?04		; drive #1
6480
 8423  F94BA7  09 01         		ora	#1		; drive #0 (bit 0)
6481
 8424  F94BA9  80 F2         		bra	?02
6482
 8425  F94BAB  09 02         	?04:	ora	#2		; drive #1 (bit 1)
6483
 8426  F94BAD  80 EE         		bra	?02
6484
 8427  F94BAF  C9 03         	?06:	cmp	#3
6485
 8428  F94BB1  D0 04         		bne	?08		; just one drive tabulated in file stream
6486
 8429  F94BB3  A9 80         		lda	#$80		; search both drives flag
6487
 8430  F94BB5  85 18         		sta	tgflg
6488
 8431  F94BB7  A5 34         	?08:	lda	fildrv		; set drvnum for first file on stream
6489
 8432  F94BB9  29 01         		and	#1
6490
 8433  F94BBB  85 19         		sta	drvnum
6491
 8434  F94BBD  20 6A 56      		jsr	drvint		; init drive and system track cache
6492
 8435  F94BC0  24 18         		bit	tgflg
6493
 8436  F94BC2  10 0D         		bpl	?10		; just one drive
6494
 8437  F94BC4  A5 19         		lda	drvnum
6495
 8438  F94BC6  48            		pha			; save
6496
 8439  F94BC7  49 01         		eor	#$01		; toggle drive #
6497
 8440  F94BC9  85 19         		sta	drvnum
6498
 8441  F94BCB  20 6A 56      		jsr	drvint
6499
 8442  F94BCE  68            		pla			; restore drive #
6500
 8443  F94BCF  85 19         		sta	drvnum
6501
 8444  F94BD1  60            	?10:	rts
6502
 8445
6503
 8446                        	;---------------------------------------------------------------------------
6504
 8447                        	; track & sector allocation helper's - bam helper's
6505
 8448                        	;---------------------------------------------------------------------------
6506
 8449
6507
 8450                        	; add a new file to directory in first available empty entry
6508
 8451                        	; add a new sector to directory chain if no empty entry available
6509
 8452  F94BD2                	addfil:
6510
 8453                        	;	;jsr	curblk		; last used accessed search
6511
  Tue Jul 17 11:00:19 2018                                                                                               Page  106
6512
 
6513
 
6514
 
6515
 
6516
 8454  F94BD2  64 41         		stz	cmdsiz		; not null if will be allocated new dir sec
6517
 8455  F94BD4  A5 0E         		lda	type
6518
 8456  F94BD6  48            		pha
6519
 8457  F94BD7  A5 34         		lda	fildrv		; use this drive
6520
 8458  F94BD9  29 01         		and	#1
6521
 8459  F94BDB  AA            		tax			; required drive
6522
 8460  F94BDC  45 19         		eor	drvnum		; compare with last accessed drive
6523
 8461  F94BDE  4A            		lsr	a
6524
 8462  F94BDF  90 0D         		bcc	?08		; same drive, use last accessed search
6525
 8463  F94BE1  86 19         		stx	drvnum		; set current drive
6526
 8464  F94BE3  A9 01         		lda	#1
6527
 8465  F94BE5  95 02         		sta	delind,x	; look for empty entry
6528
 8466  F94BE7  20 2D 4B      		jsr	srchst
6529
 8467  F94BEA  F0 1A         		beq	?15		; all full, alloc new dir sector
6530
 8468  F94BEC  D0 27         		bne	?18		; found one
6531
 8469  F94BEE  B5 00         	?08:	lda	delsec,x	; already called srchst here!!
6532
 8470  F94BF0  F0 0B         		beq	?10		; deleted entry not located
6533
 8471  F94BF2  C5 09         		cmp	sector		; resident sector?
6534
 8472  F94BF4  F0 21         		beq	?20		; yes
6535
 8473  F94BF6  85 09         		sta	sector		; sector of empty entry
6536
 8474  F94BF8  20 C3 4C      		jsr	setdptr
6537
 8475  F94BFB  80 1A         		bra	?20		; use it
6538
 8476  F94BFD  A9 01         	?10:	lda	#1		; find empty entry
6539
 8477  F94BFF  95 02         		sta	delind,x
6540
 8478  F94C01  20 65 4B      		jsr	srre		; restart search
6541
 8479  F94C04  D0 0F         		bne	?18		; found one
6542
 8480  F94C06  20 8D 4C      	?15:	jsr	nxdrbk		; all full, alloc new directory sector
6543
 8481  F94C09  A6 19         		ldx	drvnum
6544
 8482  F94C0B  A5 09         		lda	sector
6545
 8483  F94C0D  95 00         		sta	delsec,x
6546
 8484  F94C0F  A9 02         		lda	#2
6547
 8485  F94C11  95 02         		sta	delind,x
6548
 8486  F94C13  80 06         		bra	?21
6549
 8487  F94C15  A6 19         	?18:	ldx	drvnum
6550
 8488  F94C17  B5 02         	?20:	lda	delind,x
6551
 8489  F94C19  85 0A         		sta	dirp		; low pointer
6552
 8490  F94C1B  68            	?21:	pla
6553
 8491  F94C1C  85 0E         		sta	type		; set type
6554
 8492  F94C1E  85 39         		sta	pattyp
6555
 8493  F94C20  87 0A         		sta	[dirp]
6556
 8494  F94C22  20 63 4D      		jsr	intts		; allocate init t&s for new file
6557
 8495  F94C25  A5 08         		lda	track
6558
 8496  F94C27  85 20         		sta	filtrk		; ...table & entry
6559
 8497  F94C29  A0 01         		ldy	#1
6560
 8498  F94C2B  97 0A         		sta	[dirp],y
6561
 8499  F94C2D  A5 09         		lda	sector
6562
 8500  F94C2F  85 25         		sta	filsec		; set sector link in...
6563
 8501  F94C31  C8            		iny
6564
 8502  F94C32  97 0A         		sta	[dirp],y	; ...table & entry
6565
 8503  F94C34  C8            		iny
6566
 8504  F94C35  A6 1A         		ldx	filtbl
6567
 8505  F94C37  BD 00 E1      	?22:	lda	!cmdbuf,x	; copy file name
6568
 8506  F94C3A  F0 06         		beq	?24
6569
 8507  F94C3C  97 0A         		sta	[dirp],y
6570
 8508  F94C3E  E8            		inx
6571
 8509  F94C3F  C8            		iny
6572
 8510  F94C40  80 F5         		bra	?22
6573
  Tue Jul 17 11:00:19 2018                                                                                               Page  107
6574
 
6575
 
6576
 
6577
 
6578
 8511  F94C42  97 0A         	?24:	sta	[dirp],y	; clear # of blocks &...
6579
 8512  F94C44  C8            		iny			; ...& replace links
6580
 8513  F94C45  C0 1E         		cpy	#30
6581
 8514  F94C47  90 F9         		bcc	?24
6582
 8515  F94C49  A6 19         		ldx	drvnum
6583
 8516  F94C4B  B5 00         		lda	delsec,x
6584
 8517  F94C4D  85 2A         		sta	entsec
6585
 8518  F94C4F  B5 02         		lda	delind,x
6586
 8519  F94C51  85 2F         		sta	entind
6587
 8520  F94C53  74 02         		stz	delind,x
6588
 8521  F94C55  74 00         		stz	delsec,x
6589
 8522  F94C57
6590
 8523                        		; now must save bam, old dir sector, and new dir sec
6591
 8524                        		; bam is in phis. sec 1 & 2
6592
 8525                        		; dir sec 3 is in phis. sec. 2
6593
 8526  F94C57  20 10 4E      		jsr	mapout		; save bam if dirty
6594
 8527  F94C5A  A5 41         		lda	cmdsiz		; prev. dir sec. if any
6595
 8528  F94C5C  A4 2A         		ldy	entsec		; current dir sec
6596
 8529  F94C5E  AA            		tax
6597
 8530  F94C5F  F0 11         		beq	?34
6598
 8531  F94C61  4A            		lsr	a		; to phis. sec.
6599
 8532  F94C62  1A            		inc	a
6600
 8533  F94C63  C9 03         		cmp	#3
6601
 8534  F94C65  90 0B         		bcc	?34		; saved with bam
6602
 8535  F94C67  48            		pha			; save old dir psec
6603
 8536  F94C68  5A            		phy			; save current dir sec
6604
 8537  F94C69  86 09         		stx	sector		; write out old dir sec
6605
 8538  F94C6B  20 57 36      		jsr	wrdsec
6606
 8539  F94C6E  7A            		ply
6607
 8540  F94C6F  84 09         		sty	sector		; restore current dir sec
6608
 8541  F94C71  68            		pla
6609
 8542  F94C72  85 41         	?34:	sta	cmdsiz		; restore old dir psec
6610
 8543  F94C74  98            		tya			; current dir sec
6611
 8544  F94C75  84 09         		sty	sector
6612
 8545  F94C77  4A            		lsr	a
6613
 8546  F94C78  1A            		inc	a		; current dir psec
6614
 8547  F94C79  C9 03         		cmp	#3
6615
 8548  F94C7B  90 07         		bcc	?36
6616
 8549  F94C7D  C5 41         		cmp	cmdsiz		; compare with prev, if any
6617
 8550  F94C7F  F0 03         		beq	?36		; already saved
6618
 8551  F94C81  20 57 36      		jsr	wrdsec		; write out current dir sec
6619
 8552  F94C84  A5 20         	?36:	lda	filtrk
6620
 8553  F94C86  85 08         		sta	track
6621
 8554  F94C88  A5 25         		lda	filsec
6622
 8555  F94C8A  85 09         		sta	sector
6623
 8556                        		;;sta	dind,x
6624
 8557                        		;;sta	dsec,x
6625
 8558  F94C8C  60            		rts
6626
 8559  F94C8D
6627
 8560                        	; allocate next directory block on system track
6628
 8561                        	; and mark as used in bam
6629
 8562                        	; dirp, track & sector filled with current values
6630
 8563  F94C8D                	nxdrbk:
6631
 8564  F94C8D  A5 09         		lda	sector
6632
 8565  F94C8F  85 41         		sta	cmdsiz		; save current directory block
6633
 8566  F94C91  64 0A         		stz	dirp		; pointer to start of current sector
6634
 8567  F94C93  20 00 4D      		jsr	nxtds		; allocate a new dir block
6635
  Tue Jul 17 11:00:19 2018                                                                                               Page  108
6636
 
6637
 
6638
 
6639
 
6640
 8568  F94C96  A4 09         		ldy	sector
6641
 8569  F94C98  C0 03         		cpy	#dirst
6642
 8570  F94C9A  90 57         		bcc	e_dskful0	; must be > dirst
6643
 8571  F94C9C  A5 08         		lda	track		; put link in current block
6644
 8572  F94C9E  87 0A         		sta	[dirp]
6645
 8573  F94CA0  98            		tya			; sector
6646
 8574  F94CA1  A0 01         		ldy	#1
6647
 8575  F94CA3  97 0A         		sta	[dirp],y	; the new allocated sec
6648
 8576  F94CA5  64 0D         		stz	nxtsec		; this is last dir sec
6649
 8577  F94CA7  20 3D 56      		jsr	sethdp		; preset dir pointer to header
6650
 8578  F94CAA  18            		clc
6651
 8579  F94CAB  65 09         		adc	sector		; add sector offset
6652
 8580  F94CAD  85 0B         		sta	dirp+1
6653
 8581  F94CAF  A0 01         		ldy	#1
6654
 8582  F94CB1  A9 FF         		lda	#$FF		; put next link: $00, $FF
6655
 8583  F94CB3  97 0A         		sta	[dirp],y
6656
 8584  F94CB5  1A            		inc	a
6657
 8585  F94CB6  87 0A         		sta	[dirp]
6658
 8586  F94CB8  C8            		iny
6659
 8587  F94CB9  97 0A         	?02:	sta	[dirp],y	; clear block
6660
 8588  F94CBB  C8            		iny
6661
 8589  F94CBC  D0 FB         		bne	?02
6662
 8590  F94CBE  A9 02         		lda	#2		; preset pointer to first entry
6663
 8591  F94CC0  85 0A         		sta	dirp
6664
 8592  F94CC2  60            		rts
6665
 8593
6666
 8594                        	; set directory pointer for drvnum and sector
6667
 8595                        	; also, set nxtsec for directory search
6668
 8596                        	; preset dir pointer to first entry on sector
6669
 8597                        	; return X = drive #
6670
 8598  F94CC3                	setdptr:
6671
 8599  F94CC3  A6 19         		ldx	drvnum
6672
 8600  F94CC5  B5 74         		lda	dirofs,x
6673
 8601  F94CC7  B4 76         		ldy	dirbnk,x
6674
 8602  F94CC9  18            		clc
6675
 8603  F94CCA  65 09         		adc	sector		; add sector offset
6676
 8604  F94CCC  64 0A         		stz	dirp		; set pointer to dir link
6677
 8605  F94CCE  85 0B         		sta	dirp+1
6678
 8606  F94CD0  84 0C         		sty	dirp+2
6679
 8607  F94CD2                		ACC16
6680
 8608  F94CD2  C2 20         		rep	#PMFLAG
6681
 8609                        		.LONGA	on
6682
 8610                        		.MNLIST
6683
 8611  F94CD4  A7 0A         		lda	[dirp]		; A = nxt track, B = nxt sector
6684
 8612  F94CD6  AA            		tax			; X = nxt track
6685
 8613  F94CD7  EB            		xba			; B = nxt track, A = nxt sector
6686
 8614  F94CD8  C9 FF 00      		cmp	#$00FF		; last dir. sector?
6687
 8615  F94CDB                		ACC08
6688
 8616  F94CDB  E2 20         		sep	#PMFLAG
6689
 8617                        		.LONGA	off
6690
 8618                        		.MNLIST
6691
 8619  F94CDD  F0 05         		beq	?04		; yes, this is final sector
6692
 8620  F94CDF  E0 28         		cpx	#dirtrk		; check system track
6693
 8621  F94CE1  D0 0B         		bne	e_dirlnk	; dir error
6694
 8622  F94CE3  3A            		dec	a		; adjust sector
6695
 8623  F94CE4  1A            	?04:	inc	a		; = 0 if link is $FF
6696
 8624  F94CE5  85 0D         		sta	nxtsec		; next sector (0 if no more sec)
6697
  Tue Jul 17 11:00:19 2018                                                                                               Page  109
6698
 
6699
 
6700
 
6701
 
6702
 8625  F94CE7  A6 19         		ldx	drvnum
6703
 8626  F94CE9  A9 02         		lda	#2		; index of first entry
6704
 8627  F94CEB  85 0A         		sta	dirp
6705
 8628  F94CED  60            		rts
6706
 8629
6707
 8630  F94CEE                	e_dirlnk:
6708
 8631  F94CEE  A9 50         		lda	#dirlnk
6709
 8632  F94CF0  4C FB 56      		jmp	doserr
6710
 8633
6711
 8634  F94CF3                	e_dskful0:
6712
 8635  F94CF3  A6 19         		ldx	drvnum		; invalidate drive
6713
 8636  F94CF5  74 68         		stz	drvfg,x
6714
 8637
6715
 8638  F94CF7                	e_dskful:
6716
 8639  F94CF7  A9 48         		lda	#dskful
6717
 8640  F94CF9  4C 07 41      		jmp	cmderr
6718
 8641
6719
 8642                        	; returns next available trk & sec
6720
 8643                        	; given current t & s
6721
 8644                        	;  allocation is from trk 40
6722
 8645                        	;  towards 1 & 80, by full tracks
6723
 8646  F94CFC                	nxtts:
6724
 8647                        		;;jsr	gethdr		; ??? set current t&s for file
6725
 8648  F94CFC  A9 03         		lda	#3
6726
 8649  F94CFE  85 93         		sta	tmp0		; set pass count
6727
 8650
6728
 8651                        	; allocate new directory sector
6729
 8652  F94D00                	nxtds:
6730
 8653  F94D00  20 5D 4E      		jsr	bamtrk
6731
 8654  F94D03  A7 8D         		lda	[bmpnt]		; free blocks count
6732
 8655  F94D05  D0 32         		bne	?06		; available blocks
6733
 8656  F94D07  A5 08         		lda	track
6734
 8657  F94D09  C9 28         		cmp	#dirtrk		; directory full
6735
 8658  F94D0B  F0 EA         		beq	e_dskful
6736
 8659  F94D0D  90 14         		bcc	?02		; track < dirtrack
6737
 8660  F94D0F  E6 08         		inc	track		; track > dirtrack
6738
 8661  F94D11  A5 08         		lda	track
6739
 8662  F94D13  C9 51         		cmp	#maxtrk
6740
 8663  F94D15  D0 E9         		bne	nxtds
6741
 8664  F94D17  A2 27         		ldx	#dirtrk-1	; track := dirtrack - 1
6742
 8665  F94D19  86 08         		stx	track
6743
 8666  F94D1B  64 09         		stz	sector
6744
 8667  F94D1D  C6 93         		dec	tmp0
6745
 8668  F94D1F  D0 DF         		bne	nxtds
6746
 8669  F94D21  F0 D4         		beq	e_dskful
6747
 8670  F94D23  A5 08         	?02:	lda	track
6748
 8671  F94D25  C9 01         		cmp	#startrk
6749
 8672  F94D27  90 04         		bcc	?03
6750
 8673  F94D29  C6 08         		dec	track
6751
 8674  F94D2B  D0 D3         		bne	nxtds
6752
 8675  F94D2D  A2 29         	?03:	ldx	#dirtrk+1	; start again
6753
 8676  F94D2F  86 08         		stx	track		; track := dirtrack + 1
6754
 8677  F94D31  64 09         		stz	sector
6755
 8678  F94D33  C6 93         		dec	tmp0
6756
 8679  F94D35  D0 C9         		bne	nxtds
6757
 8680  F94D37  F0 BE         		beq	e_dskful
6758
 8681  F94D39  E6 09         	?06:	inc	sector		; increment current sec
6759
  Tue Jul 17 11:00:19 2018                                                                                               Page  110
6760
 
6761
 
6762
 
6763
 
6764
 8682  F94D3B  A9 28         		lda	#numsec		; find next sec
6765
 8683  F94D3D  C5 09         		cmp	sector		; is it over?
6766
 8684  F94D3F  B0 0B         		bcs	?10		; no..it's ok
6767
 8685  F94D41  38            		sec
6768
 8686  F94D42  A5 09         		lda	sector
6769
 8687  F94D44  E9 28         		sbc	#numsec
6770
 8688  F94D46  85 09         		sta	sector
6771
 8689  F94D48  F0 02         		beq	?10
6772
 8690  F94D4A  C6 09         		dec	sector		; -1
6773
 8691  F94D4C  20 F8 4D      	?10:	jsr	getsec
6774
 8692  F94D4F  D0 51         		bne	wused		; ok, this block is free
6775
 8693  F94D51  64 09         	?12:	stz	sector		; start again with sector = 0
6776
 8694  F94D53  20 F8 4D      		jsr	getsec
6777
 8695  F94D56  D0 4A         		bne	wused		; ok
6778
 8696
6779
 8697  F94D58                	e_direrr:
6780
 8698  F94D58  A9 47         		lda	#direrr
6781
 8699  F94D5A  4C FB 56      		jmp	doserr
6782
 8700
6783
 8701  F94D5D                	e_direrr0:
6784
 8702  F94D5D  A6 19         		ldx	drvnum
6785
 8703  F94D5F  74 68         		stz	drvfg,x		; invalidate drive
6786
 8704  F94D61  80 F5         		bra	e_direrr
6787
 8705
6788
 8706                        	; find first track & sector for a new file
6789
 8707  F94D63                	intts:
6790
 8708  F94D63  A9 01         		lda	#1		; set a counter
6791
 8709  F94D65  85 93         		sta	tmp0
6792
 8710  F94D67  A9 28         	?s1:	lda	#dirtrk		; track:= dirtrk-tmp0
6793
 8711  F94D69  38            		sec
6794
 8712  F94D6A  E5 93         		sbc	tmp0
6795
 8713  F94D6C  85 08         		sta	track
6796
 8714  F94D6E  08            		php
6797
 8715  F94D6F  C9 01         		cmp	#startrk	; ok?
6798
 8716  F94D71  B0 03         		bcs	?01		; yes - startrk < track
6799
 8717  F94D73  28            		plp			; discard
6800
 8718  F94D74  80 0C         		bra	?s2		; track = 0 so start again toward max track
6801
 8719  F94D76  28            	?01:	plp			; check result of sbc
6802
 8720  F94D77  90 09         		bcc	?s2		; if track <= 0...
6803
 8721  F94D79  F0 07         		beq	?s2		; ...start again toward max track
6804
 8722  F94D7B  20 5D 4E      		jsr	bamtrk		; set the bam pntr
6805
 8723  F94D7E  A7 8D         		lda	[bmpnt]		; any free block?
6806
 8724  F94D80  D0 19         		bne	?10		; found free sector
6807
 8725  F94D82  A9 28         	?s2:	lda	#dirtrk		; trk= dirtrk+tmp0
6808
 8726  F94D84  18            		clc
6809
 8727  F94D85  65 93         		adc	tmp0
6810
 8728  F94D87  85 08         		sta	track
6811
 8729  F94D89  E6 93         		inc	tmp0		; next trk
6812
 8730  F94D8B  C9 51         		cmp	#maxtrk
6813
 8731  F94D8D  90 05         		bcc	?s3		; ok
6814
 8732  F94D8F  A9 43         		lda	#systs		; error, no free sector
6815
 8733  F94D91  4C FB 56      		jmp	doserr
6816
 8734  F94D94  20 5D 4E      	?s3:	jsr	bamtrk		; set ptr
6817
 8735  F94D97  A7 8D         		lda	[bmpnt]
6818
 8736  F94D99  F0 CC         		beq	?s1		; not free... try next track
6819
 8737  F94D9B  64 09         	?10:	stz	sector
6820
 8738  F94D9D  20 F8 4D      		jsr	getsec		; get sector
6821
  Tue Jul 17 11:00:19 2018                                                                                               Page  111
6822
 
6823
 
6824
 
6825
 
6826
 8739  F94DA0  F0 BB         		beq	e_direrr0	; no free sector
6827
 8740                        		;;jmp	wused
6828
 8741
6829
 8742                        	; sector allocation - mark bam for used sector
6830
 8743  F94DA2                	wused:
6831
 8744  F94DA2  20 5D 4E      		jsr  	bamtrk		; get bam index
6832
 8745  F94DA5  20 4A 4E      		jsr	bambit
6833
 8746  F94DA8  F0 22         		beq	?10		; used, no action
6834
 8747  F94DAA  B7 8D         		lda	[bmpnt],y	; get bits
6835
 8748  F94DAC  5F A8 5A F9   		eor	>bmask,x	; toggle: mark sec used
6836
 8749  F94DB0  97 8D         		sta	[bmpnt],y
6837
 8750  F94DB2  A7 8D         		lda	[bmpnt]		; count -1
6838
 8751  F94DB4  3A            		dec	a
6839
 8752  F94DB5  87 8D         		sta	[bmpnt]		; save it
6840
 8753  F94DB7  A6 19         		ldx	drvnum
6841
 8754  F94DB9  A9 80         		lda	#$80
6842
 8755  F94DBB  95 84         		sta	wbam,x		; set it dirty
6843
 8756  F94DBD  A5 08         		lda	track
6844
 8757  F94DBF  C9 28         		cmp	#dirtrk
6845
 8758  F94DC1  F0 09         		beq	?10
6846
 8759  F94DC3  8A            		txa
6847
 8760  F94DC4  0A            		asl	a
6848
 8761  F94DC5  AA            		tax
6849
 8762  F94DC6                		ACC16
6850
 8763  F94DC6  C2 20         		rep	#PMFLAG
6851
 8764                        		.LONGA	on
6852
 8765                        		.MNLIST
6853
 8766  F94DC8  D6 6A         		dec	ndbf,x		; update total free block's
6854
 8767  F94DCA                		ACC08
6855
 8768  F94DCA  E2 20         		sep	#PMFLAG
6856
 8769                        		.LONGA	off
6857
 8770                        		.MNLIST
6858
 8771  F94DCC  60            	?10:	rts
6859
 8772
6860
 8773                        	; free a sector - mark bam for free sector
6861
 8774  F94DCD                	frets:
6862
 8775  F94DCD  20 5D 4E      		jsr	bamtrk		; mrk bam free
6863
 8776  F94DD0  20 4A 4E      		jsr	bambit
6864
 8777  F94DD3  D0 22         		bne	?10		; free already
6865
 8778  F94DD5  B7 8D         		lda	[bmpnt],y	; not free, free it
6866
 8779  F94DD7  1F A8 5A F9   		ora	bmask,x
6867
 8780  F94DDB  97 8D         		sta	[bmpnt],y
6868
 8781  F94DDD  A7 8D         		lda	[bmpnt]
6869
 8782  F94DDF  1A            		inc	a		; add one to # blocks free
6870
 8783  F94DE0  87 8D         		sta	[bmpnt]
6871
 8784  F94DE2  A6 19         		ldx	drvnum
6872
 8785  F94DE4  A9 80         		lda	#$80
6873
 8786  F94DE6  95 84         		sta	wbam,x		; set it dirty
6874
 8787  F94DE8  A5 08         		lda	track
6875
 8788  F94DEA  C9 28         		cmp	#dirtrk
6876
 8789  F94DEC  F0 09         		beq	?10
6877
 8790  F94DEE  8A            		txa
6878
 8791  F94DEF  0A            		asl	a
6879
 8792  F94DF0  AA            		tax
6880
 8793  F94DF1                		ACC16
6881
 8794  F94DF1  C2 20         		rep	#PMFLAG
6882
 8795                        		.LONGA	on
6883
  Tue Jul 17 11:00:19 2018                                                                                               Page  112
6884
 
6885
 
6886
 
6887
 
6888
 8796                        		.MNLIST
6889
 8797  F94DF3  F6 6A         		inc	ndbf,x		; update total free block's
6890
 8798  F94DF5                		ACC08
6891
 8799  F94DF5  E2 20         		sep	#PMFLAG
6892
 8800                        		.LONGA	off
6893
 8801                        		.MNLIST
6894
 8802  F94DF7  60            	?10:	rts
6895
 8803
6896
 8804                        	; find a free block in current track
6897
 8805                        	; return Z = 0 if sector is a free block
6898
 8806                        	; use tmp0
6899
 8807  F94DF8                	getsec:
6900
 8808  F94DF8  20 5D 4E      		jsr	bamtrk		; set bam and block bit ptr
6901
 8809  F94DFB  20 7D 4E      		jsr	avck		; chk bits & count
6902
 8810  F94DFE  A5 09         	?10:	lda	sector
6903
 8811  F94E00  C9 28         		cmp	#numsec
6904
 8812  F94E02  B0 09         		bcs	?20		; not free blocks in this track
6905
 8813  F94E04  20 4A 4E      		jsr	bambit		; get block offset
6906
 8814  F94E07  D0 06         		bne	?30		; ok is free
6907
 8815  F94E09  E6 09         		inc	sector		; try next block numb.
6908
 8816  F94E0B  80 F1         		bra	?10		; loop
6909
 8817  F94E0D  A9 00         	?20:	lda	#0		; nothing free
6910
 8818  F94E0F  60            	?30:	rts			; (z=0): free
6911
 8819
6912
 8820                        	; write out bam of current drive, if dirty
6913
 8821                        	; use wtmp, wtmp+1, tmp0
6914
 8822  F94E10                	mapout:
6915
 8823  F94E10  A6 19         		ldx	drvnum
6916
 8824  F94E12  34 84         		bit	wbam,x		; dirty?
6917
 8825  F94E14  10 33         		bpl	?50		; no, no write
6918
 8826  F94E16  A9 51         		lda	#maxtrk		; verify bam first
6919
 8827  F94E18  85 94         		sta	wtmp		; set trk counter
6920
 8828  F94E1A  B5 74         		lda	dirofs,x	; preset bam ptr
6921
 8829  F94E1C  1A            		inc	a		; bam 1
6922
 8830  F94E1D  B4 76         		ldy	dirbnk,x
6923
 8831  F94E1F  85 8E         		sta	bmpnt+1
6924
 8832  F94E21  1A            		inc	a
6925
 8833  F94E22  85 95         		sta	wtmp+1		; bam 2
6926
 8834  F94E24  84 8F         		sty	bmpnt+2
6927
 8835  F94E26  A9 10         	?10:	lda	#bindx		; bam offset
6928
 8836  F94E28  85 8D         	?20:	sta	bmpnt		; lsb
6929
 8837  F94E2A  20 7D 4E      		jsr	avck		; check this trk
6930
 8838  F94E2D  C6 94         		dec	wtmp		; do next trk
6931
 8839  F94E2F  F0 11         		beq	?30		; verify done
6932
 8840  F94E31  18            		clc			; update bam pointer
6933
 8841  F94E32  A5 8D         		lda	bmpnt
6934
 8842  F94E34  69 06         		adc	#6		; 6 byte per trk
6935
 8843  F94E36  90 F0         		bcc	?20		; same bam
6936
 8844  F94E38  A5 8E         		lda	bmpnt+1
6937
 8845  F94E3A  C5 95         		cmp	wtmp+1
6938
 8846  F94E3C  F0 04         		beq	?30		; end check
6939
 8847  F94E3E  E6 8E         		inc	bmpnt+1		; do next bam
6940
 8848  F94E40  80 E4         		bra	?10
6941
 8849  F94E42  20 02 58      	?30:	jsr	bamout		; wrt the bams
6942
 8850  F94E45  A6 19         	?40:	ldx	drvnum
6943
 8851  F94E47  74 84         		stz	wbam,x		; set it clean now!
6944
 8852  F94E49  60            	?50:	rts
6945
  Tue Jul 17 11:00:19 2018                                                                                               Page  113
6946
 
6947
 
6948
 
6949
 
6950
 8853
6951
 8854                        	; check if a block is free or not
6952
 8855                        	; in:	bmpnt = bam pointer
6953
 8856                        	;	sector = block number (0..39)
6954
 8857                        	; out:	Z = 0 if blocks is free
6955
 8858                        	;	Y,X = bam byte index and bit index
6956
 8859  F94E4A                	bambit:
6957
 8860  F94E4A  A5 09         		lda	sector		; get block bit in bam
6958
 8861  F94E4C  4A            		lsr	a		; sectr/8
6959
 8862  F94E4D  4A            		lsr	a
6960
 8863  F94E4E  4A            		lsr	a
6961
 8864  F94E4F  A8            		tay
6962
 8865  F94E50  C8            		iny			; adjust it
6963
 8866  F94E51  A5 09         		lda	sector		; get remainder
6964
 8867  F94E53  29 07         		and	#$07
6965
 8868  F94E55  AA            		tax			; bit mask index
6966
 8869  F94E56  B7 8D         		lda	[bmpnt],y
6967
 8870  F94E58  3F A8 5A F9   		and	>bmask,x	; = 0 if not free
6968
 8871  F94E5C  60            		rts
6969
 8872
6970
 8873                        	; set bam pointer for track and drvnum
6971
 8874  F94E5D                	bamtrk:
6972
 8875  F94E5D  A6 19         		ldx	drvnum
6973
 8876  F94E5F  B5 76         		lda	dirbnk,x
6974
 8877  F94E61  85 8F         		sta	bmpnt+2		; set bank pointer
6975
 8878  F94E63  B4 74         		ldy	dirofs,x	; high pointer
6976
 8879  F94E65  C8            		iny			; set for bam 1
6977
 8880  F94E66  A5 08         		lda	track
6978
 8881  F94E68  C9 29         		cmp	#41		; which bam ?
6979
 8882  F94E6A  90 03         		bcc	?04		; bam1
6980
 8883  F94E6C  E9 28         		sbc	#40		; range 40 trk per bam
6981
 8884  F94E6E  C8            		iny			; it's bam2
6982
 8885  F94E6F  84 8E         	?04:	sty	bmpnt+1
6983
 8886  F94E71  0A            		asl	a		; trk x6 offset
6984
 8887  F94E72  85 8D         		sta	bmpnt		; save x2
6985
 8888  F94E74  0A            		asl	a		; x4
6986
 8889  F94E75  18            		clc			; total=x6
6987
 8890  F94E76  65 8D         		adc	bmpnt		;
6988
 8891  F94E78  69 0A         		adc	#bindx-6	; bam offset -1 trk blk
6989
 8892  F94E7A  85 8D         		sta	bmpnt
6990
 8893  F94E7C  60            		rts
6991
 8894
6992
 8895                        	; check count of free blocks in track
6993
 8896                        	; use tmp0
6994
 8897  F94E7D                	avck:
6995
 8898  F94E7D  64 93         		stz	tmp0		; blk counter
6996
 8899  F94E7F  A0 05         		ldy	#bamsiz-1	; offset of last byte
6997
 8900  F94E81  A2 08         	?10:	ldx	#8		; bit counter
6998
 8901  F94E83  B7 8D         		lda	[bmpnt],y
6999
 8902  F94E85  0A            	?20:	asl	a		; used ?
7000
 8903  F94E86  90 02         		bcc	?30		; no
7001
 8904  F94E88  E6 93         		inc	tmp0		; count it
7002
 8905  F94E8A  CA            	?30:	dex
7003
 8906  F94E8B  D0 F8         		bne	?20		; do next bit
7004
 8907  F94E8D  88            		dey			; do next byte
7005
 8908  F94E8E  D0 F1         		bne	?10
7006
 8909  F94E90  A7 8D         		lda	[bmpnt]		; stored count of free blocks
7007
  Tue Jul 17 11:00:19 2018                                                                                               Page  114
7008
 
7009
 
7010
 
7011
 
7012
 8910  F94E92  C5 93         		cmp	tmp0
7013
 8911  F94E94  D0 01         		bne	?40		; counts don't match
7014
 8912  F94E96  60            	        rts
7015
 8913  F94E97  A9 51         	?40:	lda	#bamcnt
7016
 8914  F94E99  4C 07 41      		jmp	cmderr
7017
 8915
7018
 8916                        	; build bam for an empty new disk
7019
 8917  F94E9C                	newmap:
7020
 8918  F94E9C  A6 19         		ldx	drvnum		; init buffer for bam1&bam2
7021
 8919  F94E9E  B5 74         		lda	dirofs,x
7022
 8920  F94EA0  B4 76         		ldy	dirbnk,x
7023
 8921  F94EA2  18            		clc
7024
 8922  F94EA3  69 28         		adc	#numsec		; buffer allocated after dir. cache
7025
 8923  F94EA5  1A            		inc	a		; +1
7026
 8924  F94EA6  85 8E         		sta	bmpnt+1		; bmpnt -> bam 1
7027
 8925  F94EA8  84 8F         		sty	bmpnt+2
7028
 8926  F94EAA  1A            		inc	a
7029
 8927  F94EAB  85 3F         		sta	tlp+1		; tlp -> bam 2
7030
 8928  F94EAD  84 40         		sty	tlp+2
7031
 8929  F94EAF  64 8D         		stz	bmpnt
7032
 8930  F94EB1  64 3E         		stz	tlp
7033
 8931  F94EB3  A0 00         		ldy	#0
7034
 8932  F94EB5  98            		tya
7035
 8933  F94EB6  97 8D         	?02:	sta	[bmpnt],y	; clear bam1&bam2
7036
 8934  F94EB8  97 3E         		sta	[tlp],y
7037
 8935  F94EBA  C8            		iny
7038
 8936  F94EBB  D0 F9         		bne	?02
7039
 8937  F94EBD  A9 28         		lda	#dirtrk		; link to bam2
7040
 8938  F94EBF  87 8D         		sta	[bmpnt]		; set trk links
7041
 8939  F94EC1  98            		tya			; Y=0 -- end trk link
7042
 8940  F94EC2  87 3E         		sta	[tlp]		;
7043
 8941  F94EC4  A9 02         		lda	#2		; link to bam2
7044
 8942  F94EC6  C8            		iny			; 1
7045
 8943  F94EC7  97 8D         		sta	[bmpnt],y
7046
 8944  F94EC9  A9 FF         		lda	#$ff		; sector end link
7047
 8945  F94ECB  97 3E         		sta	[tlp],y
7048
 8946  F94ECD  A9 44         		lda	#dskvern	; disk version number
7049
 8947  F94ECF  C8            		iny			; 2
7050
 8948  F94ED0  97 8D         		sta	[bmpnt],y
7051
 8949  F94ED2  97 3E         		sta	[tlp],y
7052
 8950  F94ED4  49 FF         		eor	#$FF		; complement
7053
 8951  F94ED6  C8            	        iny			; 3
7054
 8952  F94ED7  97 8D         		sta	[bmpnt],y
7055
 8953  F94ED9  97 3E         		sta	[tlp],y
7056
 8954  F94EDB  BD FC E1      		lda	!dskid1,x	; ID 1
7057
 8955  F94EDE  C8            		iny			; 4
7058
 8956  F94EDF  97 8D         		sta	[bmpnt],y
7059
 8957  F94EE1  97 3E         		sta	[tlp],y
7060
 8958  F94EE3  BD FE E1      		lda	!dskid2,x	; ID 2
7061
 8959  F94EE6  C8            		iny			; 5
7062
 8960  F94EE7  97 8D         		sta	[bmpnt],y
7063
 8961  F94EE9  97 3E         		sta	[tlp],y
7064
 8962  F94EEB  A9 C0         		lda	#iobyte		; default i/o byte
7065
 8963  F94EED  C8            		iny			; 6
7066
 8964  F94EEE  97 8D         		sta	[bmpnt],y
7067
 8965  F94EF0  97 3E         		sta	[tlp],y
7068
 8966  F94EF2  A0 10         	?04:	ldy	#bindx		; bam offset
7069
  Tue Jul 17 11:00:19 2018                                                                                               Page  115
7070
 
7071
 
7072
 
7073
 
7074
 8967  F94EF4  A9 28         	?06:	lda	#numsec
7075
 8968  F94EF6  97 8D         		sta	[bmpnt],y	; store free block's in this track
7076
 8969  F94EF8  C8            		iny
7077
 8970  F94EF9  A2 05         		ldx	#5		; bytes counter
7078
 8971  F94EFB  A9 FF         		lda	#$FF		; all free
7079
 8972  F94EFD  97 8D         	?08:	sta	[bmpnt],y	; write out bit map
7080
 8973  F94EFF  C8            		iny
7081
 8974  F94F00  CA            		dex
7082
 8975  F94F01  D0 FA         		bne	?08
7083
 8976  F94F03  98            		tya			; done?
7084
 8977  F94F04  D0 EE         		bne	?06		; no
7085
 8978  F94F06  A5 8E         		lda	bmpnt+1
7086
 8979  F94F08  C5 3F         		cmp	tlp+1		; both bams done?
7087
 8980  F94F0A  F0 04         		beq	?10		; yep...
7088
 8981  F94F0C  E6 8E         		inc	bmpnt+1		; do the next bam
7089
 8982  F94F0E  80 E2         		bra	?04		; next bam
7090
 8983  F94F10                	?10:	ACC16
7091
 8984  F94F10  C2 20         		rep	#PMFLAG
7092
 8985                        		.LONGA	on
7093
 8986                        		.MNLIST
7094
 8987  F94F12  A9 58 0C      		lda	#maxblks	; max. available block's
7095
 8988  F94F15  85 94         		sta	wtmp
7096
 8989  F94F17                		ACC08
7097
 8990  F94F17  E2 20         		sep	#PMFLAG
7098
 8991                        		.LONGA	off
7099
 8992                        		.MNLIST
7100
 8993  F94F19  C6 8E         		dec	bmpnt+1		; back to bam 1
7101
 8994  F94F1B  A9 28         		lda	#dirtrk		; alloc sector for system track
7102
 8995  F94F1D  0A            		asl	a		; trk x6 offset
7103
 8996  F94F1E  85 8D         		sta	bmpnt		; save x2
7104
 8997  F94F20  0A            		asl	a		; x4
7105
 8998  F94F21  18            		clc			; total=x6
7106
 8999  F94F22  65 8D         		adc	bmpnt		;
7107
 9000  F94F24  69 0A         		adc	#bindx-6	; bam offset -1 trk blk
7108
 9001  F94F26  85 8D         		sta	bmpnt		; pointer to bitmap for system track
7109
 9002  F94F28  64 09         		stz	sector		; allocate 3 sectors & directory sector
7110
 9003  F94F2A  20 39 4F      		jsr	?20		; sec. 0
7111
 9004  F94F2D  E6 09         		inc	sector
7112
 9005  F94F2F  20 39 4F      		jsr	?20		; sec. 1
7113
 9006  F94F32  E6 09         		inc	sector
7114
 9007  F94F34  20 39 4F      		jsr	?20		; sec. 2
7115
 9008  F94F37  E6 09         		inc	sector		; sec. 3 usually for dir.
7116
 9009  F94F39  20 4A 4E      	?20:	jsr	bambit
7117
 9010  F94F3C  F0 0D         		beq	?30		; used, no action
7118
 9011  F94F3E  B7 8D         		lda	[bmpnt],y	; get bits
7119
 9012  F94F40  5F A8 5A F9   		eor	>bmask,x	; toggle: mark sec used
7120
 9013  F94F44  97 8D         		sta	[bmpnt],y
7121
 9014  F94F46  A7 8D         		lda	[bmpnt]		; count -1
7122
 9015  F94F48  3A            		dec	a
7123
 9016  F94F49  87 8D         		sta	[bmpnt]		; save it
7124
 9017  F94F4B  60            	?30:	rts
7125
 9018
7126
 9019                        	; build a new disk header in system cache
7127
 9020  F94F4C                	newhdr:
7128
 9021  F94F4C  A0 01         		ldy	#1
7129
 9022  F94F4E  A9 28         		lda	#dirtrk		; directory track
7130
 9023  F94F50  87 0A         		sta	[dirp]
7131
  Tue Jul 17 11:00:19 2018                                                                                               Page  116
7132
 
7133
 
7134
 
7135
 
7136
 9024  F94F52  A9 03         		lda	#dirst		; link to first dir. block
7137
 9025  F94F54  97 0A         		sta	[dirp],y
7138
 9026  F94F56  C8            		iny			; 2
7139
 9027  F94F57  A9 44         		lda	#dskvern
7140
 9028  F94F59  97 0A         		sta	[dirp],y	; disk version number
7141
 9029  F94F5B  C8            		iny
7142
 9030  F94F5C  C8            		iny			; 4
7143
 9031  F94F5D  A6 1A         		ldx	filtbl		; ptr to disk name
7144
 9032  F94F5F  BD 00 E1      	?02:	lda	!cmdbuf,x	; store disk name
7145
 9033  F94F62  F0 06         		beq	?04
7146
 9034  F94F64  97 0A         		sta	[dirp],y
7147
 9035  F94F66  C8            		iny
7148
 9036  F94F67  E8            		inx
7149
 9037  F94F68  80 F5         		bra	?02
7150
 9038  F94F6A  A9 A0         	?04:	lda	#$A0
7151
 9039  F94F6C  97 0A         		sta	[dirp],y	; 20
7152
 9040  F94F6E  C8            		iny
7153
 9041  F94F6F  97 0A         		sta	[dirp],y
7154
 9042  F94F71  C8            		iny			; 22
7155
 9043  F94F72  A6 19         		ldx	drvnum
7156
 9044  F94F74  BD FC E1      		lda	!dskid1,x	; store ID 1
7157
 9045  F94F77  97 0A         		sta	[dirp],y
7158
 9046  F94F79  C8            		iny			; 23
7159
 9047  F94F7A  BD FE E1      		lda	!dskid2,x	; store ID 2
7160
 9048  F94F7D  97 0A         		sta	[dirp],y
7161
 9049  F94F7F  C8            		iny			; 24
7162
 9050  F94F80  A9 A0         		lda	#$A0
7163
 9051  F94F82  97 0A         		sta	[dirp],y
7164
 9052  F94F84  C8            		iny			; 25
7165
 9053  F94F85  A9 33         		lda	#dosvern	; store dos version number
7166
 9054  F94F87  97 0A         		sta	[dirp],y
7167
 9055  F94F89  C8            		iny			; 26
7168
 9056  F94F8A  A9 44         		lda	#dskvern
7169
 9057  F94F8C  97 0A         		sta	[dirp],y	; disk version number
7170
 9058  F94F8E  C8            		iny			; 27
7171
 9059  F94F8F  A9 A0         		lda	#$A0
7172
 9060  F94F91  97 0A         		sta	[dirp],y
7173
 9061  F94F93  C8            		iny			; 28
7174
 9062  F94F94  A9 A0         		lda	#$A0
7175
 9063  F94F96  97 0A         		sta	[dirp],y
7176
 9064  F94F98  A0 1E         		ldy	#30
7177
 9065  F94F9A  A9 8D         		lda	#subvern	; store sub-version
7178
 9066  F94F9C  97 0A         		sta	[dirp],y
7179
 9067  F94F9E  C8            		iny			; 31
7180
 9068  F94F9F  49 FF         		eor	#$FF
7181
 9069  F94FA1  97 0A         		sta	[dirp],y
7182
 9070  F94FA3                		CPU16
7183
 9071  F94FA3  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
7184
 9072                        		.LONGA	on
7185
 9073                        		.LONGI	on
7186
 9074                        		.MNLIST
7187
 9075  F94FA5  20 A5 1B      		jsr	gctime16	; compact time&date (ret CPU16)
7188
 9076  F94FA8  A0 20 00      		ldy	#32
7189
 9077  F94FAB  97 0A         		sta	[dirp],y	; store 32 bit serial
7190
 9078  F94FAD  8A            		txa
7191
 9079  F94FAE  C8            		iny
7192
 9080  F94FAF  C8            		iny
7193
  Tue Jul 17 11:00:19 2018                                                                                               Page  117
7194
 
7195
 
7196
 
7197
 
7198
 9081  F94FB0  97 0A         		sta	[dirp],y
7199
 9082  F94FB2  A9 58 0C      		lda	#maxblks
7200
 9083  F94FB5  85 94         		sta	wtmp
7201
 9084  F94FB7                		CPU08
7202
 9085  F94FB7  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
7203
 9086                        		.LONGA	off
7204
 9087                        		.LONGI	off
7205
 9088                        		.MNLIST
7206
 9089  F94FB9  60            		rts
7207
 9090
7208
 9091                        	;---------------------------------------------------------------------------
7209
 9092                        	; file system check routines
7210
 9093                        	;---------------------------------------------------------------------------
7211
 9094
7212
 9095                        	; mark aux bam for used sector
7213
 9096  F94FBA                	mkbam:
7214
 9097  F94FBA  A6 19         		ldx	drvnum		; set pointer to aux bam
7215
 9098  F94FBC  B5 74         		lda	dirofs,x
7216
 9099  F94FBE  B4 76         		ldy	dirbnk,x
7217
 9100  F94FC0  84 8F         		sty	bmpnt+2
7218
 9101  F94FC2  18            		clc
7219
 9102  F94FC3  69 28         		adc	#numsec		; buffer allocated after dir. cache
7220
 9103  F94FC5  1A            		inc	a		; +1
7221
 9104  F94FC6  A8            		tay
7222
 9105  F94FC7  A5 09         		lda	sector
7223
 9106  F94FC9  C9 28         		cmp	#numsec
7224
 9107  F94FCB  B0 3A         		bcs	?04
7225
 9108  F94FCD  A5 08         		lda	track
7226
 9109  F94FCF  F0 36         		beq	?04
7227
 9110  F94FD1  C9 51         		cmp	#maxtrk
7228
 9111  F94FD3  B0 32         		bcs	?04
7229
 9112  F94FD5  C9 29         		cmp	#41		; which bam ?
7230
 9113  F94FD7  90 03         		bcc	?02		; bam1
7231
 9114  F94FD9  E9 28         		sbc	#40		; range 40 trk per bam
7232
 9115  F94FDB  C8            		iny			; it's bam2
7233
 9116  F94FDC  84 8E         	?02:	sty	bmpnt+1
7234
 9117  F94FDE  0A            		asl	a		; trk x6 offset
7235
 9118  F94FDF  85 8D         		sta	bmpnt		; save x2
7236
 9119  F94FE1  0A            		asl	a		; x4
7237
 9120  F94FE2  18            		clc			; total=x6
7238
 9121  F94FE3  65 8D         		adc	bmpnt		;
7239
 9122  F94FE5  69 0A         		adc	#bindx-6	; bam offset -1 trk blk
7240
 9123  F94FE7  85 8D         		sta	bmpnt
7241
 9124  F94FE9  20 4A 4E      		jsr	bambit
7242
 9125  F94FEC  F0 19         		beq	?04		; used, no action
7243
 9126  F94FEE  B7 8D         		lda	[bmpnt],y	; get bits
7244
 9127  F94FF0  5F A8 5A F9   		eor	>bmask,x	; toggle: mark sec used
7245
 9128  F94FF4  97 8D         		sta	[bmpnt],y
7246
 9129  F94FF6  A7 8D         		lda	[bmpnt]		; count -1
7247
 9130  F94FF8  3A            		dec	a
7248
 9131  F94FF9  87 8D         		sta	[bmpnt]		; save it
7249
 9132  F94FFB  A5 08         		lda	track
7250
 9133  F94FFD  C9 28         		cmp	#dirtrk
7251
 9134  F94FFF  F0 06         		beq	?04
7252
 9135  F95001                		ACC16
7253
 9136  F95001  C2 20         		rep	#PMFLAG
7254
 9137                        		.LONGA	on
7255
  Tue Jul 17 11:00:19 2018                                                                                               Page  118
7256
 
7257
 
7258
 
7259
 
7260
 9138                        		.MNLIST
7261
 9139  F95003  C6 86         		dec	ntot		; update total free block's
7262
 9140  F95005                		ACC08
7263
 9141  F95005  E2 20         		sep	#PMFLAG
7264
 9142                        		.LONGA	off
7265
 9143                        		.MNLIST
7266
 9144  F95007  60            	?04:	rts
7267
 9145
7268
 9146                        	; check file consistency and update aux bam
7269
 9147                        	; enter with start t&s of the file
7270
 9148  F95008                	chkfil:
7271
 9149  F95008  A5 09         		lda	sector		; save dir. sector
7272
 9150  F9500A  85 2A         		sta	entsec
7273
 9151  F9500C  A7 0A         		lda	[dirp]
7274
 9152  F9500E  85 0E         		sta	type
7275
 9153  F95010  A0 01         		ldy	#1
7276
 9154  F95012  B7 0A         		lda	[dirp],y
7277
 9155  F95014  85 08         		sta	track		; set up first t&s
7278
 9156  F95016  C8            		iny
7279
 9157  F95017  B7 0A         		lda	[dirp],y
7280
 9158  F95019  85 09         		sta	sector
7281
 9159  F9501B  A9 22         		lda	#'"'
7282
 9160  F9501D  8D DD E1      		sta	!nambuf2
7283
 9161  F95020  A2 00         		ldx	#0
7284
 9162  F95022  C8            		iny
7285
 9163  F95023  B7 0A         	?02:	lda	[dirp],y
7286
 9164  F95025  30 09         		bmi	?04
7287
 9165  F95027  9D DE E1      		sta	!nambuf2+1,x
7288
 9166  F9502A  C8            		iny
7289
 9167  F9502B  E8            		inx
7290
 9168  F9502C  E0 10         		cpx	#16
7291
 9169  F9502E  90 F3         		bcc	?02
7292
 9170  F95030  A9 22         	?04:	lda	#'"'
7293
 9171  F95032  9D DE E1      		sta	!nambuf2+1,x
7294
 9172  F95035  9E DF E1      		stz	!nambuf2+2,x
7295
 9173  F95038  A0 1C         		ldy	#28		; check block's count
7296
 9174  F9503A                		ACC16
7297
 9175  F9503A  C2 20         		rep	#PMFLAG
7298
 9176                        		.LONGA	on
7299
 9177                        		.MNLIST
7300
 9178  F9503C  B7 0A         		lda	[dirp],y
7301
 9179  F9503E  85 94         		sta	wtmp		; stored file block's count
7302
 9180  F95040  64 F0         		stz	wcnt		; clear block's counter
7303
 9181  F95042                		ACC08
7304
 9182  F95042  E2 20         		sep	#PMFLAG
7305
 9183                        		.LONGA	off
7306
 9184                        		.MNLIST
7307
 9185  F95044  A5 0E         		lda	type
7308
 9186  F95046  30 2B         		bmi	?12
7309
 9187  F95048  A9 00         		lda	#^nambuf2
7310
 9188  F9504A  48            		pha
7311
 9189  F9504B  F4 DD E1      		pea	#!nambuf2
7312
 9190  F9504E  4B            		phk			; splat file msg
7313
 9191  F9504F  F4 85 51      		pea	#!?100
7314
 9192  F95052  A9 07         		lda	#7
7315
 9193  F95054  48            		pha
7316
 9194  F95055                		BPRINTF
7317
  Tue Jul 17 11:00:19 2018                                                                                               Page  119
7318
 
7319
 
7320
 
7321
 
7322
 9195  F95055  02 11         		cop	$11
7323
 9196                        		.MNLIST
7324
 9197  F95057  24 E6         		bit	wrop
7325
 9198  F95059  30 03         		bmi	?08		; ok, delete splat file
7326
 9199  F9505B  4C 7B 51      		jmp	?90		; skip & exit
7327
 9200  F9505E  A9 00         	?08:	lda	#0		; delete entry
7328
 9201  F95060  87 0A         		sta	[dirp]
7329
 9202  F95062  A5 2A         		lda	entsec
7330
 9203  F95064  85 09         		sta	sector
7331
 9204  F95066  20 57 36      		jsr	wrdsec		; update dir
7332
 9205  F95069  A2 F9         		ldx	#^?105
7333
 9206  F9506B  A9 51         		lda	#>?105
7334
 9207  F9506D  EB            		xba
7335
 9208  F9506E  A9 9D         		lda	#<?105
7336
 9209  F95070                		SCNSTROUT
7337
 9210  F95070  02 03         		cop	$03
7338
 9211                        		.MNLIST
7339
 9212  F95072  60            	?10:	rts
7340
 9213  F95073  29 07         	?12:	and	#typmsk
7341
 9214  F95075  C9 04         		cmp	#reltyp
7342
 9215  F95077  F0 F9         		beq	?10		; skip
7343
 9216  F95079  C9 05         		cmp	#partyp
7344
 9217  F9507B  F0 F5         		beq	?10		; skip
7345
 9218  F9507D  A5 08         		lda	track
7346
 9219  F9507F  F0 0A         		beq	?13		; invalid track
7347
 9220  F95081  C9 51         		cmp	#maxtrk
7348
 9221  F95083  B0 06         		bcs	?13		; invalid track
7349
 9222  F95085  A5 09         		lda	sector
7350
 9223  F95087  C9 28         		cmp	#numsec
7351
 9224  F95089  90 03         		bcc	?14		; invalid sector?
7352
 9225  F9508B  4C 2B 51      	?13:	jmp	?30
7353
 9226  F9508E  20 AB 57      	?14:	jsr	tread		; read whole track in cache
7354
 9227  F95091  20 4A 56      		jsr	setcp		; set cache ptr to right sector
7355
 9228  F95094                	?16:	ACC16CLC
7356
 9229  F95094  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
7357
 9230                        		.LONGA	on
7358
 9231                        		.MNLIST
7359
 9232  F95096  E6 F0         		inc	wcnt		; update file block's counter
7360
 9233  F95098  C6 88         		dec	bcnt		; update total free block's
7361
 9234  F9509A  A5 94         		lda	wtmp		; stored block's #
7362
 9235  F9509C  69 20 00      		adc	#32		; add a guard
7363
 9236  F9509F  C5 F0         		cmp	wcnt		; compare with computed block's #
7364
 9237  F950A1                		ACC08
7365
 9238  F950A1  E2 20         		sep	#PMFLAG
7366
 9239                        		.LONGA	off
7367
 9240                        		.MNLIST
7368
 9241  F950A3  B0 03         		bcs	?17
7369
 9242  F950A5  4C 65 51      		jmp	?50		; hmmm...never reach end of file?
7370
 9243  F950A8  20 BA 4F      	?17:	jsr	mkbam		; mark aux bam
7371
 9244  F950AB  A0 01         		ldy	#1
7372
 9245  F950AD  B7 8A         		lda	[bufp],y	; next sector
7373
 9246  F950AF  A8            		tay
7374
 9247  F950B0  A7 8A         		lda	[bufp]		; next track
7375
 9248  F950B2  F0 1D         		beq	?18		; end of file?
7376
 9249  F950B4  C9 51         		cmp	#maxtrk
7377
 9250  F950B6  B0 04         		bcs	?17a		; invalid track in link
7378
 9251  F950B8  C0 28         		cpy	#numsec		; invalid sector in link?
7379
  Tue Jul 17 11:00:19 2018                                                                                               Page  120
7380
 
7381
 
7382
 
7383
 
7384
 9252  F950BA  90 03         		bcc	?17b
7385
 9253  F950BC  4C 47 51      	?17a:	jmp	?40
7386
 9254  F950BF  84 09         	?17b:	sty	sector		; next sector
7387
 9255  F950C1  C5 08         		cmp	track		; same track?
7388
 9256  F950C3  85 08         		sta	track
7389
 9257  F950C5  D0 C7         		bne	?14		; will read a new track
7390
 9258  F950C7  18            		clc
7391
 9259  F950C8  98            		tya
7392
 9260  F950C9  A6 19         		ldx	drvnum
7393
 9261  F950CB  75 78         		adc	trkofs,x	; sector in the same track
7394
 9262  F950CD  85 8B         		sta	bufp+1
7395
 9263                        		;jsr	mkbam		; mark aux bam
7396
 9264  F950CF  80 C3         		bra	?16		; follow link
7397
 9265  F950D1  C0 02         	?18:	cpy	#2		; in last block must be >= 2
7398
 9266  F950D3  90 3F         		bcc	?20
7399
 9267  F950D5                		ACC16
7400
 9268  F950D5  C2 20         		rep	#PMFLAG
7401
 9269                        		.LONGA	on
7402
 9270                        		.MNLIST
7403
 9271  F950D7  A5 94         		lda	wtmp		; check block's count
7404
 9272  F950D9  C5 F0         		cmp	wcnt
7405
 9273  F950DB                		ACC08
7406
 9274  F950DB  E2 20         		sep	#PMFLAG
7407
 9275                        		.LONGA	off
7408
 9276                        		.MNLIST
7409
 9277  F950DD  F0 93         		beq	?10		; ok, match -- exit
7410
 9278  F950DF  D4 94         		pei	(wtmp)
7411
 9279  F950E1  D4 F0         		pei	(wcnt)
7412
 9280  F950E3  A9 00         		lda	#^nambuf2
7413
 9281  F950E5  48            		pha
7414
 9282  F950E6  F4 DD E1      		pea	#!nambuf2
7415
 9283  F950E9  4B            		phk			; unmatch msg
7416
 9284  F950EA  F4 AC 51      		pea	#!?115
7417
 9285  F950ED  A9 0B         		lda	#11
7418
 9286  F950EF  48            		pha
7419
 9287  F950F0                		BPRINTF
7420
 9288  F950F0  02 11         		cop	$11
7421
 9289                        		.MNLIST
7422
 9290  F950F2  24 E6         		bit	wrop
7423
 9291  F950F4  30 03         		bmi	?19
7424
 9292  F950F6  4C 7B 51      		jmp	?90		; skip & exit
7425
 9293  F950F9  A0 1C         	?19:	ldy	#28		; correct
7426
 9294  F950FB                		ACC16
7427
 9295  F950FB  C2 20         		rep	#PMFLAG
7428
 9296                        		.LONGA	on
7429
 9297                        		.MNLIST
7430
 9298  F950FD  A5 F0         		lda	wcnt
7431
 9299  F950FF  97 0A         		sta	[dirp],y
7432
 9300  F95101                		ACC08
7433
 9301  F95101  E2 20         		sep	#PMFLAG
7434
 9302                        		.LONGA	off
7435
 9303                        		.MNLIST
7436
 9304  F95103  A5 2A         		lda	entsec
7437
 9305  F95105  85 09         		sta	sector
7438
 9306  F95107  20 57 36      		jsr	wrdsec		; update dir
7439
 9307  F9510A  A2 F9         		ldx	#^?130
7440
 9308  F9510C  A9 52         		lda	#>?130
7441
  Tue Jul 17 11:00:19 2018                                                                                               Page  121
7442
 
7443
 
7444
 
7445
 
7446
 9309  F9510E  EB            		xba
7447
 9310  F9510F  A9 4C         		lda	#<?130
7448
 9311  F95111                		SCNSTROUT
7449
 9312  F95111  02 03         		cop	$03
7450
 9313                        		.MNLIST
7451
 9314  F95113  60            		rts
7452
 9315  F95114  A5 09         	?20:	lda	sector
7453
 9316  F95116  48            		pha
7454
 9317  F95117  A5 08         		lda	track
7455
 9318  F95119  48            		pha
7456
 9319  F9511A  5A            		phy			; last ptr
7457
 9320  F9511B  A9 00         		lda	#^nambuf2
7458
 9321  F9511D  48            		pha
7459
 9322  F9511E  F4 DD E1      		pea	#!nambuf2
7460
 9323  F95121  4B            		phk			; corrupted last link
7461
 9324  F95122  F4 E3 51      		pea	#!?120
7462
 9325  F95125  A9 0A         		lda	#10
7463
 9326  F95127  48            		pha
7464
 9327  F95128                		BPRINTF
7465
 9328  F95128  02 11         		cop	$11
7466
 9329                        		.MNLIST
7467
 9330  F9512A  60            		rts			; no correction possible here
7468
 9331  F9512B  A5 09         	?30:	lda	sector		; invalid start track and/or sector
7469
 9332  F9512D  48            		pha
7470
 9333  F9512E  A5 08         		lda	track
7471
 9334  F95130  48            		pha
7472
 9335  F95131  A9 00         		lda	#^nambuf2
7473
 9336  F95133  48            		pha
7474
 9337  F95134  F4 DD E1      		pea	#!nambuf2
7475
 9338  F95137  4B            		phk
7476
 9339  F95138  F4 1D 52      		pea	#!?125
7477
 9340  F9513B  A9 09         		lda	#9
7478
 9341  F9513D  48            		pha
7479
 9342  F9513E                		BPRINTF
7480
 9343  F9513E  02 11         		cop	$11
7481
 9344                        		.MNLIST
7482
 9345  F95140  24 E6         		bit	wrop
7483
 9346  F95142  10 37         		bpl	?90		; skip
7484
 9347  F95144  4C 5E 50      		jmp	?08		; delete entry
7485
 9348
7486
 9349  F95147  A6 09         	?40:	ldx	sector		; invalid link
7487
 9350  F95149  DA            		phx
7488
 9351  F9514A  A6 08         		ldx	track
7489
 9352  F9514C  DA            		phx
7490
 9353  F9514D  5A            		phy			; possible invalid sec link
7491
 9354  F9514E  48            		pha			; possible invalid trk link
7492
 9355  F9514F  A9 00         		lda	#^nambuf2
7493
 9356  F95151  48            		pha
7494
 9357  F95152  F4 DD E1      		pea	#!nambuf2
7495
 9358  F95155  4B            		phk
7496
 9359  F95156  F4 55 52      		pea	#!?135
7497
 9360  F95159  A9 0B         		lda	#11
7498
 9361  F9515B  48            		pha
7499
 9362  F9515C                		BPRINTF
7500
 9363  F9515C  02 11         		cop	$11
7501
 9364                        		.MNLIST
7502
 9365  F9515E  24 E6         		bit	wrop
7503
  Tue Jul 17 11:00:19 2018                                                                                               Page  122
7504
 
7505
 
7506
 
7507
 
7508
 9366  F95160  10 19         		bpl	?90		; skip
7509
 9367  F95162  4C 5E 50      		jmp	?08		; delete entry
7510
 9368
7511
 9369  F95165  A9 00         	?50:	lda	#^nambuf2	; eof not found...
7512
 9370  F95167  48            		pha
7513
 9371  F95168  F4 DD E1      		pea	#!nambuf2
7514
 9372  F9516B  4B            		phk
7515
 9373  F9516C  F4 8C 52      		pea	#!?140
7516
 9374  F9516F  A9 07         		lda	#7
7517
 9375  F95171  48            		pha
7518
 9376  F95172                		BPRINTF
7519
 9377  F95172  02 11         		cop	$11
7520
 9378                        		.MNLIST
7521
 9379  F95174  24 E6         		bit	wrop
7522
 9380  F95176  10 03         		bpl	?90		; skip
7523
 9381  F95178  4C 5E 50      		jmp	?08		; delete entry
7524
 9382
7525
 9383  F9517B  A2 F9         	?90:	ldx	#^?110		; show 'skip' msg & exit
7526
 9384  F9517D  A9 51         		lda	#>?110
7527
 9385  F9517F  EB            		xba
7528
 9386  F95180  A9 A6         		lda	#<?110
7529
 9387  F95182                		SCNSTROUT
7530
 9388  F95182  02 03         		cop	$03
7531
 9389                        		.MNLIST
7532
 9390  F95184  60            		rts
7533
 9391
7534
 9392  F95185  0D 66 69 6C 65 	?100:	.DB	$0D, 'file %s: not closed...', 0
7535
               20 25 73 3A 20
7536
               6E 6F 74 20 63
7537
               6C 6F 73 65 64
7538
               2E 2E 2E 00
7539
 9393  F9519D  64 65 6C 65 74 	?105:	.DB	'deleted.', 0
7540
               65 64 2E 00
7541
 9394  F951A6  73 6B 69 70 2E 	?110:	.DB	'skip.', 0
7542
               00
7543
 9395  F951AC  0D 66 69 6C 65 	?115:	.DB	$0D, 'file %s: unmatch blocks count (actual %hu vs. %hu)...', 0
7544
               20 25 73 3A 20
7545
               75 6E 6D 61 74
7546
               63 68 20 62 6C
7547
               6F 63 6B 73 20
7548
               63 6F 75 6E 74
7549
               20 28 61 63 74
7550
               75 61 6C 20 25
7551
               68 75 20 76 73
7552
               2E 20 25 68 75
7553
               29 2E 2E 2E 00
7554
 9396  F951E3  0D 66 69 6C 65 	?120:	.DB	$0D, 'file %s: last link (t:0,s:%bu) corrupted at t:%bu,s:%bu.', 0
7555
               20 25 73 3A 20
7556
               6C 61 73 74 20
7557
               6C 69 6E 6B 20
7558
               28 74 3A 30 2C
7559
               73 3A 25 62 75
7560
               29 20 63 6F 72
7561
               72 75 70 74 65
7562
               64 20 61 74 20
7563
               74 3A 25 62 75
7564
               2C 73 3A 25 62
7565
  Tue Jul 17 11:00:19 2018                                                                                               Page  123
7566
 
7567
 
7568
 
7569
 
7570
               75 2E 00
7571
 9397  F9521D  0D 66 69 6C 65 	?125:	.DB	$0D, 'file %s: invalid start block (t:%bu,s:%bu)...', 0
7572
               20 25 73 3A 20
7573
               69 6E 76 61 6C
7574
               69 64 20 73 74
7575
               61 72 74 20 62
7576
               6C 6F 63 6B 20
7577
               28 74 3A 25 62
7578
               75 2C 73 3A 25
7579
               62 75 29 2E 2E
7580
               2E 00
7581
 9398  F9524C  63 6F 72 72 65 	?130:	.DB	'correct.', 0
7582
               63 74 2E 00
7583
 9399  F95255  0D 66 69 6C 65 	?135:	.DB	$0D, 'file %s: invalid link (t:%bu,s:%bu) at t:%bu,s:%bu...', 0
7584
               20 25 73 3A 20
7585
               69 6E 76 61 6C
7586
               69 64 20 6C 69
7587
               6E 6B 20 28 74
7588
               3A 25 62 75 2C
7589
               73 3A 25 62 75
7590
               29 20 61 74 20
7591
               74 3A 25 62 75
7592
               2C 73 3A 25 62
7593
               75 2E 2E 2E 00
7594
 9400  F9528C  0D 66 69 6C 65 	?140:	.DB	$0D, 'file %s: EOF not found...', 0
7595
               20 25 73 3A 20
7596
               45 4F 46 20 6E
7597
               6F 74 20 66 6F
7598
               75 6E 64 2E 2E
7599
               2E 00
7600
 9401
7601
 9402                        	; check directory consistence & update aux bam
7602
 9403  F952A7                	chkdir:
7603
 9404  F952A7  A9 28         		lda	#dirtrk
7604
 9405  F952A9  85 08         		sta	track
7605
 9406  F952AB  64 09         		stz	sector
7606
 9407  F952AD  20 AB 57      		jsr	tread		; read whole track in cache
7607
 9408  F952B0  20 4A 56      		jsr	setcp		; set cache ptr to right sector
7608
 9409  F952B3  20 BA 4F      	?02:	jsr	mkbam		; mark aux bam
7609
 9410  F952B6  A0 01         		ldy	#1
7610
 9411  F952B8  B7 8A         		lda	[bufp],y	; next sector
7611
 9412  F952BA  A8            		tay
7612
 9413  F952BB  A7 8A         		lda	[bufp]		; next track
7613
 9414  F952BD  F0 12         		beq	?04		; end of dir?
7614
 9415  F952BF  84 09         		sty	sector		; next sector
7615
 9416  F952C1  C5 08         		cmp	track		; same track?
7616
 9417  F952C3  85 08         		sta	track
7617
 9418  F952C5  D0 0E         		bne	?10		; error!
7618
 9419  F952C7  18            		clc
7619
 9420  F952C8  98            		tya
7620
 9421  F952C9  A6 19         		ldx	drvnum
7621
 9422  F952CB  75 78         		adc	trkofs,x	; sector in the same track
7622
 9423  F952CD  85 8B         		sta	bufp+1
7623
 9424  F952CF  80 E2         		bra	?02		; follow link
7624
 9425  F952D1  C0 FF         	?04:	cpy	#$FF		; must be $FF
7625
 9426  F952D3  F0 10         		beq	?15
7626
 9427  F952D5  A5 09         	?10:	lda	sector
7627
  Tue Jul 17 11:00:19 2018                                                                                               Page  124
7628
 
7629
 
7630
 
7631
 
7632
 9428  F952D7  48            		pha
7633
 9429  F952D8  5A            		phy			; last ptr
7634
 9430  F952D9  A5 08         		lda	track
7635
 9431  F952DB  48            		pha
7636
 9432  F952DC  4B            		phk			; unmatch msg
7637
 9433  F952DD  F4 E6 52      		pea	#!?20
7638
 9434  F952E0  A9 07         		lda	#7
7639
 9435  F952E2  48            		pha
7640
 9436  F952E3                		BPRINTF
7641
 9437  F952E3  02 11         		cop	$11
7642
 9438                        		.MNLIST
7643
 9439  F952E5  60            	?15:	rts
7644
 9440
7645
 9441  F952E6  0D 64 69 72 65 	?20:	.DB	$0D, 'directory: wrong link (t:%bu,s:%bu) at sector %bu', 0
7646
               63 74 6F 72 79
7647
               3A 20 77 72 6F
7648
               6E 67 20 6C 69
7649
               6E 6B 20 28 74
7650
               3A 25 62 75 2C
7651
               73 3A 25 62 75
7652
               29 20 61 74 20
7653
               73 65 63 74 6F
7654
               72 20 25 62 75
7655
               00
7656
 9442
7657
 9443                        	; report file block's count & update bam if validation
7658
 9444  F95319                	updbam:
7659
 9445  F95319  20 C4 53      		jsr	?30		; for safety check again aux bam free block's
7660
 9446  F9531C                		ACC16
7661
 9447  F9531C  C2 20         		rep	#PMFLAG
7662
 9448                        		.LONGA	on
7663
 9449                        		.MNLIST
7664
 9450  F9531E  A5 86         		lda	ntot
7665
 9451  F95320  C5 94         		cmp	wtmp
7666
 9452  F95322                		ACC08
7667
 9453  F95322  E2 20         		sep	#PMFLAG
7668
 9454                        		.LONGA	off
7669
 9455                        		.MNLIST
7670
 9456  F95324  F0 1B         		beq	?06
7671
 9457  F95326  D4 94         		pei	(wtmp)
7672
 9458  F95328  D4 86         		pei	(ntot)
7673
 9459  F9532A  4B            		phk
7674
 9460  F9532B  F4 8A 54      		pea	#!?65
7675
 9461  F9532E  A9 08         		lda	#8
7676
 9462  F95330  48            		pha
7677
 9463  F95331                		BPRINTF
7678
 9464  F95331  02 11         		cop	$11
7679
 9465                        		.MNLIST
7680
 9466  F95333  24 E6         	?02:	bit	wrop
7681
 9467  F95335  10 09         		bpl	?04
7682
 9468  F95337  A9 54         		lda	#>?70
7683
 9469  F95339  EB            		xba
7684
 9470  F9533A  A9 B6         		lda	#<?70
7685
 9471  F9533C  A2 F9         		ldx	#^?70
7686
 9472  F9533E                		SCNSTROUT
7687
 9473  F9533E  02 03         		cop	$03
7688
 9474                        		.MNLIST
7689
  Tue Jul 17 11:00:19 2018                                                                                               Page  125
7690
 
7691
 
7692
 
7693
 
7694
 9475  F95340  60            	?04:	rts
7695
 9476  F95341  D4 88         	?06:	pei	(bcnt)
7696
 9477  F95343  4B            		phk
7697
 9478  F95344  F4 0F 54      		pea	#!?50
7698
 9479  F95347  A9 06         		lda	#6
7699
 9480  F95349  48            		pha
7700
 9481  F9534A                		BPRINTF
7701
 9482  F9534A  02 11         		cop	$11
7702
 9483                        		.MNLIST
7703
 9484  F9534C  D4 86         		pei	(ntot)
7704
 9485  F9534E  4B            		phk
7705
 9486  F9534F  F4 38 54      		pea	#!?55
7706
 9487  F95352  A9 06         		lda	#6
7707
 9488  F95354  48            		pha
7708
 9489  F95355                		BPRINTF
7709
 9490  F95355  02 11         		cop	$11
7710
 9491                        		.MNLIST
7711
 9492  F95357  A5 19         		lda	drvnum
7712
 9493  F95359  0A            		asl	a
7713
 9494  F9535A  AA            		tax
7714
 9495  F9535B  B5 6A         		lda	ndbf,x
7715
 9496  F9535D  B4 6B         		ldy	ndbf+1,x
7716
 9497  F9535F  5A            		phy
7717
 9498  F95360  48            		pha
7718
 9499  F95361  4B            		phk
7719
 9500  F95362  F4 61 54      		pea	#!?60
7720
 9501  F95365  A9 06         		lda	#6
7721
 9502  F95367  48            		pha
7722
 9503  F95368                		BPRINTF
7723
 9504  F95368  02 11         		cop	$11
7724
 9505                        		.MNLIST
7725
 9506  F9536A                		ACC16
7726
 9507  F9536A  C2 20         		rep	#PMFLAG
7727
 9508                        		.LONGA	on
7728
 9509                        		.MNLIST
7729
 9510  F9536C  A5 88         		lda	bcnt
7730
 9511  F9536E  C5 86         		cmp	ntot
7731
 9512  F95370                		ACC08
7732
 9513  F95370  E2 20         		sep	#PMFLAG
7733
 9514                        		.LONGA	off
7734
 9515                        		.MNLIST
7735
 9516  F95372  F0 0F         		beq	?08
7736
 9517  F95374  D4 86         		pei	(ntot)
7737
 9518  F95376  D4 88         		pei	(bcnt)
7738
 9519  F95378  4B            		phk
7739
 9520  F95379  F4 D6 54      		pea	#!?75
7740
 9521  F9537C  A9 08         		lda	#8
7741
 9522  F9537E  48            		pha
7742
 9523  F9537F                		BPRINTF
7743
 9524  F9537F  02 11         		cop	$11
7744
 9525                        		.MNLIST
7745
 9526  F95381  80 B0         		bra	?02
7746
 9527  F95383
7747
 9528                        		; ok, bam can be updated
7748
 9529  F95383  24 E6         	?08:	bit	wrop
7749
 9530  F95385  10 3C         		bpl	?10		; no bam update
7750
 9531  F95387  20 3D 56      		jsr	sethdp		; update bam on disk
7751
  Tue Jul 17 11:00:19 2018                                                                                               Page  126
7752
 
7753
 
7754
 
7755
 
7756
 9532  F9538A  E6 0B         		inc	dirp+1		; set up bam
7757
 9533  F9538C  A6 19         		ldx	drvnum		; set pointer to aux bam
7758
 9534  F9538E  A9 80         		lda	#$80
7759
 9535  F95390  95 84         		sta	wbam,x		; set bam dirty
7760
 9536  F95392  B5 74         		lda	dirofs,x
7761
 9537  F95394  B4 76         		ldy	dirbnk,x
7762
 9538  F95396  84 8F         		sty	bmpnt+2
7763
 9539  F95398  18            		clc
7764
 9540  F95399  69 28         		adc	#numsec		; buffer allocated after dir. cache
7765
 9541  F9539B  1A            		inc	a		; +1
7766
 9542  F9539C  85 8E         		sta	bmpnt+1
7767
 9543  F9539E  64 8D         		stz	bmpnt		; ptr to new bam
7768
 9544  F953A0                		INDEX16
7769
 9545  F953A0  C2 10         		rep	#PXFLAG
7770
 9546                        		.LONGI	on
7771
 9547                        		.MNLIST
7772
 9548  F953A2  A0 FF 01      		ldy	#$01FF		; transfer the new bam
7773
 9549  F953A5  B7 8D         	?09:	lda	[bmpnt],y
7774
 9550  F953A7  97 0A         		sta	[dirp],y
7775
 9551  F953A9  88            		dey
7776
 9552  F953AA  10 F9         		bpl	?09
7777
 9553  F953AC                		INDEX08
7778
 9554  F953AC  E2 10         		sep	#PXFLAG
7779
 9555                        		.LONGI	off
7780
 9556                        		.MNLIST
7781
 9557  F953AE  A9 55         		lda	#>?85
7782
 9558  F953B0  EB            		xba
7783
 9559  F953B1  A9 27         		lda	#<?85
7784
 9560  F953B3  A2 F9         		ldx	#^?85
7785
 9561  F953B5                		SCNSTROUT
7786
 9562  F953B5  02 03         		cop	$03
7787
 9563                        		.MNLIST
7788
 9564  F953B7  20 10 4E      		jsr	mapout		; write out map
7789
 9565  F953BA  A9 55         		lda	#>?80
7790
 9566  F953BC  EB            		xba
7791
 9567  F953BD  A9 10         		lda	#<?80
7792
 9568  F953BF  A2 F9         		ldx	#^?80
7793
 9569  F953C1                		SCNSTROUT
7794
 9570  F953C1  02 03         		cop	$03
7795
 9571                        		.MNLIST
7796
 9572  F953C3  60            	?10:	rts
7797
 9573                        	?30:	; calc # of blocks free
7798
 9574  F953C4  64 94         		stz	wtmp
7799
 9575  F953C6  64 95         		stz	wtmp+1
7800
 9576  F953C8  A0 01         		ldy	#startrk
7801
 9577  F953CA  88            		dey
7802
 9578  F953CB  C8            	?32:	iny
7803
 9579  F953CC  84 08         		sty	track
7804
 9580  F953CE  C0 28         		cpy	#dirtrk
7805
 9581  F953D0  F0 F9         		beq	?32		; skip dir track
7806
 9582  F953D2  C0 51         		cpy	#maxtrk		; done ?
7807
 9583  F953D4  B0 14         		bcs	?34		; yes
7808
 9584  F953D6  20 EB 53      		jsr	?40		; set up next bam trk
7809
 9585  F953D9  A4 08         		ldy	track		; retrivie track
7810
 9586  F953DB  A9 00         		lda	#0
7811
 9587  F953DD  EB            		xba			; B = 0
7812
 9588  F953DE  A7 8D         		lda	[bmpnt]		; A = get blks free
7813
  Tue Jul 17 11:00:19 2018                                                                                               Page  127
7814
 
7815
 
7816
 
7817
 
7818
 9589  F953E0                		ACC16CLC
7819
 9590  F953E0  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
7820
 9591                        		.LONGA	on
7821
 9592                        		.MNLIST
7822
 9593  F953E2  65 94         		adc	wtmp		; up data count
7823
 9594  F953E4  85 94         		sta	wtmp
7824
 9595  F953E6                		ACC08
7825
 9596  F953E6  E2 20         		sep	#PMFLAG
7826
 9597                        		.LONGA	off
7827
 9598                        		.MNLIST
7828
 9599  F953E8  80 E1         		bra	?32
7829
 9600  F953EA  60            	?34:	rts
7830
 9601
7831
 9602  F953EB  A6 19         	?40:	ldx	drvnum		; set pointer to aux bam
7832
 9603  F953ED  B5 74         		lda	dirofs,x
7833
 9604  F953EF  B4 76         		ldy	dirbnk,x
7834
 9605  F953F1  84 8F         		sty	bmpnt+2
7835
 9606  F953F3  18            		clc
7836
 9607  F953F4  69 28         		adc	#numsec		; buffer allocated after dir. cache
7837
 9608  F953F6  1A            		inc	a		; +1
7838
 9609  F953F7  A8            		tay
7839
 9610  F953F8  A5 08         		lda	track
7840
 9611  F953FA  C9 29         		cmp	#41		; which bam ?
7841
 9612  F953FC  90 03         		bcc	?42		; bam1
7842
 9613  F953FE  E9 28         		sbc	#40		; range 40 trk per bam
7843
 9614  F95400  C8            		iny			; it's bam2
7844
 9615  F95401  84 8E         	?42:	sty	bmpnt+1
7845
 9616  F95403  0A            		asl	a		; trk x6 offset
7846
 9617  F95404  85 8D         		sta	bmpnt		; save x2
7847
 9618  F95406  0A            		asl	a		; x4
7848
 9619  F95407  18            		clc			; total=x6
7849
 9620  F95408  65 8D         		adc	bmpnt		;
7850
 9621  F9540A  69 0A         		adc	#bindx-6	; bam offset -1 trk blk
7851
 9622  F9540C  85 8D         		sta	bmpnt
7852
 9623  F9540E  60            		rts
7853
 9624
7854
 9625  F9540F  0D 74 6F 74 61 	?50:	.DB	$0D, 'total computed free block''s:     % 4hu.', 0
7855
               6C 20 63 6F 6D
7856
               70 75 74 65 64
7857
               20 66 72 65 65
7858
               20 62 6C 6F 63
7859
               6B 27 73 3A 20
7860
               20 20 20 20 25
7861
               20 34 68 75 2E
7862
               00
7863
 9626  F95438  0D 74 6F 74 61 	?55:	.DB	$0D, 'total free block''s from new BAM: % 4hu.', 0
7864
               6C 20 66 72 65
7865
               65 20 62 6C 6F
7866
               63 6B 27 73 20
7867
               66 72 6F 6D 20
7868
               6E 65 77 20 42
7869
               41 4D 3A 20 25
7870
               20 34 68 75 2E
7871
               00
7872
 9627  F95461  0D 74 6F 74 61 	?60:	.DB	$0D, 'total free block''s from old BAM: % 4hu.', 0
7873
               6C 20 66 72 65
7874
               65 20 62 6C 6F
7875
  Tue Jul 17 11:00:19 2018                                                                                               Page  128
7876
 
7877
 
7878
 
7879
 
7880
               63 6B 27 73 20
7881
               66 72 6F 6D 20
7882
               6F 6C 64 20 42
7883
               41 4D 3A 20 25
7884
               20 34 68 75 2E
7885
               00
7886
 9628  F9548A  0D 6E 65 77 20 	?65:	.DB	$0D, 'new BAM free block''s unmatch: %hu vs. %hu.', 0
7887
               42 41 4D 20 66
7888
               72 65 65 20 62
7889
               6C 6F 63 6B 27
7890
               73 20 75 6E 6D
7891
               61 74 63 68 3A
7892
               20 25 68 75 20
7893
               76 73 2E 20 25
7894
               68 75 2E 00
7895
 9629  F954B6  0D 42 41 4D 20 	?70:	.DB	$0D, 'BAM on disk cannot be updated.', 0
7896
               6F 6E 20 64 69
7897
               73 6B 20 63 61
7898
               6E 6E 6F 74 20
7899
               62 65 20 75 70
7900
               64 61 74 65 64
7901
               2E 00
7902
 9630  F954D6  0D 63 6F 6D 70 	?75:	.DB	$0D, 'computed free block''s (%hu) unmatch new BAM count (%hu).', 0
7903
               75 74 65 64 20
7904
               66 72 65 65 20
7905
               62 6C 6F 63 6B
7906
               27 73 20 28 25
7907
               68 75 29 20 75
7908
               6E 6D 61 74 63
7909
               68 20 6E 65 77
7910
               20 42 41 4D 20
7911
               63 6F 75 6E 74
7912
               20 28 25 68 75
7913
               29 2E 00
7914
 9631  F95510  0D 66 69 6C 65 	?80:	.DB	$0D, 'file system is clean.', 0
7915
               20 73 79 73 74
7916
               65 6D 20 69 73
7917
               20 63 6C 65 61
7918
               6E 2E 00
7919
 9632  F95527  0D 75 70 64 61 	?85:	.DB	$0D, 'update BAM on disk...', 0
7920
               74 65 20 42 41
7921
               4D 20 6F 6E 20
7922
               64 69 73 6B 2E
7923
               2E 2E 00
7924
 9633
7925
 9634                        	;---------------------------------------------------------------------------
7926
 9635                        	; drive's initialitation
7927
 9636                        	;---------------------------------------------------------------------------
7928
 9637
7929
 9638                        	; check directory header
7930
 9639                        	; X = drive #
7931
 9640                        	; return CF = 0 if ok, otherwise CF = 1
7932
 9641  F9553E                	hdrtst:
7933
 9642  F9553E  20 3D 56      		jsr	sethdp		; set dir pointer
7934
 9643  F95541  A7 0A         		lda	[dirp]		; track link
7935
 9644  F95543  C9 28         		cmp	#dirtrk
7936
 9645  F95545  D0 6D         		bne	?02		; error
7937
  Tue Jul 17 11:00:19 2018                                                                                               Page  129
7938
 
7939
 
7940
 
7941
 
7942
 9646  F95547  A0 01         		ldy	#1
7943
 9647  F95549  B7 0A         		lda	[dirp],y	; sec link
7944
 9648  F9554B  C9 03         		cmp	#dirst
7945
 9649  F9554D  D0 65         		bne	?02		; error
7946
 9650  F9554F  C8            		iny
7947
 9651  F95550  B7 0A         		lda	[dirp],y	; disk version number
7948
 9652  F95552  C9 44         		cmp	#dskvern
7949
 9653  F95554  D0 5E         		bne	?02		; error
7950
 9654  F95556  A0 1A         		ldy	#26
7951
 9655  F95558  D7 0A         		cmp	[dirp],y	; compare with vernum at offset 26
7952
 9656  F9555A  D0 58         		bne	?02		; error
7953
 9657  F9555C  88            		dey			; offset 25
7954
 9658  F9555D  B7 0A         		lda	[dirp],y	; dos version number
7955
 9659  F9555F  C9 33         		cmp	#dosvern
7956
 9660  F95561  D0 51         		bne	?02		; error
7957
 9661  F95563  A0 16         		ldy	#22
7958
 9662  F95565  B7 0A         		lda	[dirp],y	; disk ID 1
7959
 9663  F95567  9D FC E1      		sta	!dskid1,x
7960
 9664  F9556A  C8            		iny
7961
 9665  F9556B  B7 0A         		lda	[dirp],y	; disk ID 2
7962
 9666  F9556D  9D FE E1      		sta	!dskid2,x
7963
 9667  F95570  A9 F7         		lda	#$F7
7964
 9668  F95572  35 68         		and	drvfg,x		; clear bit 3 (assume no new version)
7965
 9669  F95574  95 68         		sta	drvfg,x
7966
 9670  F95576  A0 1E         		ldy	#30
7967
 9671  F95578  B7 0A         		lda	[dirp],y	; disk sub-version
7968
 9672  F9557A  F0 28         		beq	?01		; standard version
7969
 9673  F9557C  C9 8D         		cmp	#subvern
7970
 9674  F9557E  D0 24         		bne	?01
7971
 9675  F95580  49 FF         		eor	#$FF		; compliment
7972
 9676  F95582  C8            		iny			; offset 31
7973
 9677  F95583  D7 0A         		cmp	[dirp],y	; compare with sub-ver at ofs. 30
7974
 9678  F95585  D0 1D         		bne	?01		; standard version
7975
 9679  F95587  A9 08         		lda	#$08		; set bit 3: new version
7976
 9680  F95589  15 68         		ora	drvfg,x
7977
 9681  F9558B  95 68         		sta	drvfg,x
7978
 9682  F9558D  C8            		iny			; offset 32: serial 32 bit
7979
 9683  F9558E  8A            		txa
7980
 9684  F9558F  0A            		asl	a		; * 4 - index double word
7981
 9685  F95590  0A            		asl	a
7982
 9686  F95591  AA            		tax
7983
 9687  F95592                		ACC16
7984
 9688  F95592  C2 20         		rep	#PMFLAG
7985
 9689                        		.LONGA	on
7986
 9690                        		.MNLIST
7987
 9691  F95594  B7 0A         		lda	[dirp],y	; store serial
7988
 9692  F95596  9D F0 E1      		sta	!dskser,x
7989
 9693  F95599  C8            		iny
7990
 9694  F9559A  C8            		iny
7991
 9695  F9559B  B7 0A         		lda	[dirp],y
7992
 9696  F9559D  9D F2 E1      		sta	!dskser+2,x
7993
 9697  F955A0                		ACC08
7994
 9698  F955A0  E2 20         		sep	#PMFLAG
7995
 9699                        		.LONGA	off
7996
 9700                        		.MNLIST
7997
 9701  F955A2  A6 19         		ldx	drvnum
7998
 9702  F955A4  E6 0B         	?01:	inc	dirp+1		; set ptr to bam1
7999
  Tue Jul 17 11:00:19 2018                                                                                               Page  130
8000
 
8001
 
8002
 
8003
 
8004
 9703  F955A6  A7 0A         		lda	[dirp]		; track link
8005
 9704  F955A8  C9 28         		cmp	#dirtrk
8006
 9705  F955AA  D0 08         		bne	?02		; error
8007
 9706  F955AC  A0 01         		ldy	#1
8008
 9707  F955AE  B7 0A         		lda	[dirp],y	; sec link
8009
 9708  F955B0  C9 02         		cmp	#dirst-1	; will be 1 below of dir start
8010
 9709  F955B2  F0 02         		beq	?04		; ok
8011
 9710  F955B4  38            	?02:	sec			; return disk id mismatch error
8012
 9711  F955B5  60            	?03:	rts
8013
 9712  F955B6  20 1A 56      	?04:	jsr	chkbam		; check bam 1 header
8014
 9713  F955B9  B0 FA         		bcs	?03		; error
8015
 9714  F955BB  B7 0A         		lda	[dirp],y	; bam 1 iobyte
8016
 9715  F955BD  10 06         		bpl	?06
8017
 9716  F955BF  A9 20         		lda	#$20		; set bit 5 drive flag
8018
 9717  F955C1  15 68         		ora	drvfg,x
8019
 9718  F955C3  95 68         		sta	drvfg,x
8020
 9719  F955C5  E6 0B         	?06:	inc	dirp+1		; set ptr to bam2
8021
 9720  F955C7  A7 0A         		lda	[dirp]		; track link
8022
 9721  F955C9  D0 E9         		bne	?02		; error, will be 0
8023
 9722  F955CB  A0 01         		ldy	#1
8024
 9723  F955CD  B7 0A         		lda	[dirp],y	; sec link
8025
 9724  F955CF  C9 FF         		cmp	#$FF
8026
 9725  F955D1  D0 E1         		bne	?02		; error, will be $FF
8027
 9726  F955D3  20 1A 56      		jsr	chkbam		; check bam 2 header
8028
 9727  F955D6  B0 DD         		bcs	?03		; error
8029
 9728  F955D8  B7 0A         		lda	[dirp],y	; bam 1 iobyte
8030
 9729  F955DA  10 06         		bpl	nfcalc
8031
 9730  F955DC  A9 20         		lda	#$20		; set bit 5 drive flag
8032
 9731  F955DE  34 68         		bit	drvfg,x
8033
 9732  F955E0  F0 D2         		beq	?02		; mismatch with bam 1
8034
 9733
8035
 9734                        	; calc # of disk blocks free
8036
 9735  F955E2                	nfcalc:
8037
 9736  F955E2  A5 08         		lda	track
8038
 9737  F955E4  48            		pha
8039
 9738  F955E5  A5 19         		lda	drvnum
8040
 9739  F955E7  0A            		asl	a
8041
 9740  F955E8  AA            		tax			; index
8042
 9741  F955E9  74 6A         		stz	ndbf,x
8043
 9742  F955EB  74 6B         		stz	ndbf+1,x
8044
 9743  F955ED  86 93         		stx	tmp0		; save index
8045
 9744  F955EF  A0 01         		ldy	#startrk
8046
 9745  F955F1  88            		dey
8047
 9746  F955F2  C8            	?02:	iny
8048
 9747  F955F3  84 08         		sty	track
8049
 9748  F955F5  C0 28         		cpy	#dirtrk
8050
 9749  F955F7  F0 F9         		beq	?02		; skip dir track
8051
 9750  F955F9  C0 51         		cpy	#maxtrk		; done ?
8052
 9751  F955FB  B0 16         		bcs	?04		; yes
8053
 9752  F955FD  20 5D 4E      		jsr	bamtrk		; set up next bam trk
8054
 9753  F95600  A4 08         		ldy	track		; retrivie track
8055
 9754  F95602  A9 00         		lda	#0
8056
 9755  F95604  EB            		xba			; B = 0
8057
 9756  F95605  A7 8D         		lda	[bmpnt]		; A = get blks free
8058
 9757  F95607  A6 93         		ldx	tmp0		; retrivie index
8059
 9758  F95609                		ACC16CLC
8060
 9759  F95609  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
8061
  Tue Jul 17 11:00:19 2018                                                                                               Page  131
8062
 
8063
 
8064
 
8065
 
8066
 9760                        		.LONGA	on
8067
 9761                        		.MNLIST
8068
 9762  F9560B  75 6A         		adc	ndbf,x		; up data count
8069
 9763  F9560D  95 6A         		sta	ndbf,x
8070
 9764  F9560F                		ACC08
8071
 9765  F9560F  E2 20         		sep	#PMFLAG
8072
 9766                        		.LONGA	off
8073
 9767                        		.MNLIST
8074
 9768  F95611  80 DF         		bra	?02
8075
 9769  F95613  18            	?04:	clc
8076
 9770  F95614  68            		pla
8077
 9771  F95615  85 08         		sta	track
8078
 9772  F95617  A6 19         		ldx	drvnum
8079
 9773  F95619  60            		rts			; return with carry = 0
8080
 9774
8081
 9775                        	; check bam header
8082
 9776                        	; Y = 1 when called
8083
 9777  F9561A                	chkbam:
8084
 9778  F9561A  C8            		iny
8085
 9779  F9561B  B7 0A         		lda	[dirp],y	; bam disk version number
8086
 9780  F9561D  C9 44         		cmp	#dskvern
8087
 9781  F9561F  D0 07         		bne	?02		; error
8088
 9782  F95621  C8            		iny			; offset 3
8089
 9783  F95622  49 FF         		eor	#$FF		; complement
8090
 9784  F95624  D7 0A         		cmp	[dirp],y	; bam1 compl. disk version number
8091
 9785  F95626  F0 02         		beq	?04
8092
 9786  F95628  38            	?02:	sec			; return disk id mismatch error
8093
 9787  F95629  60            		rts
8094
 9788  F9562A  C8            	?04:	iny			; offset 4
8095
 9789  F9562B  B7 0A         		lda	[dirp],y	; bam disk id 1
8096
 9790  F9562D  DD FC E1      		cmp	!dskid1,x
8097
 9791  F95630  D0 F6         		bne	?02
8098
 9792  F95632  C8            		iny			; offset 5
8099
 9793  F95633  B7 0A         		lda	[dirp],y	; bam disk id 2
8100
 9794  F95635  DD FE E1      		cmp	!dskid2,x
8101
 9795  F95638  D0 EE         		bne	?02
8102
 9796  F9563A  C8            		iny
8103
 9797  F9563B  18            		clc			; ok
8104
 9798  F9563C  60            		rts
8105
 9799  F9563D
8106
 9800                        	; set pointer to directory header
8107
 9801                        	; return with X = drive
8108
 9802  F9563D                	sethdp:
8109
 9803  F9563D  A6 19         		ldx	drvnum
8110
 9804  F9563F  B5 74         		lda	dirofs,x
8111
 9805  F95641  B4 76         		ldy	dirbnk,x
8112
 9806  F95643  64 0A         		stz	dirp		; set pointer to system track cache
8113
 9807  F95645  85 0B         		sta	dirp+1
8114
 9808  F95647  84 0C         		sty	dirp+2
8115
 9809  F95649  60            		rts
8116
 9810
8117
 9811                        	; set pointer to track cache & sector
8118
 9812                        	; return with X = drive
8119
 9813  F9564A                	setcp:
8120
 9814  F9564A  A6 19         		ldx	drvnum
8121
 9815  F9564C  B5 78         		lda	trkofs,x
8122
 9816  F9564E  B4 7A         		ldy	trkbnk,x
8123
  Tue Jul 17 11:00:19 2018                                                                                               Page  132
8124
 
8125
 
8126
 
8127
 
8128
 9817  F95650  64 8A         		stz	bufp		; set pointer to track cache
8129
 9818  F95652  18            		clc
8130
 9819  F95653  65 09         		adc	sector
8131
 9820  F95655  85 8B         		sta	bufp+1
8132
 9821  F95657  84 8C         		sty	bufp+2
8133
 9822  F95659  60            		rts
8134
 9823
8135
 9824                        	; set pointer to write cache & sector
8136
 9825                        	; return with X = drive
8137
 9826  F9565A                	setwb:
8138
 9827  F9565A  A6 19         		ldx	drvnum
8139
 9828  F9565C  B5 7C         		lda	wrtofs,x
8140
 9829  F9565E  B4 7E         		ldy	wrtbnk,x
8141
 9830  F95660  64 90         		stz	wbuf		; set pointer to write cache
8142
 9831  F95662  18            		clc
8143
 9832  F95663  65 09         		adc	sector
8144
 9833  F95665  85 91         		sta	wbuf+1
8145
 9834  F95667  84 92         		sty	wbuf+2
8146
 9835  F95669  60            		rts
8147
 9836
8148
 9837                        	; drive initialitation
8149
 9838                        	; check if drive is ready or if disk was changed
8150
 9839                        	; get low level disk format
8151
 9840                        	; read system track (logical track 40) and put in cache
8152
 9841                        	; fill drvfg flag for the given drive
8153
 9842  F9566A                	drvint:
8154
 9843  F9566A  20 9C 56      		jsr	fmttst		; check low level disk format...
8155
 9844  F9566D  B5 68         		lda	drvfg,x		; ...if drive is ready
8156
 9845  F9566F  30 2A         		bmi	?10		; system track already in cache
8157
 9846  F95671  4A            		lsr	a		; if <0> = 0 => ibm disk
8158
 9847  F95672  90 08         		bcc	?02
8159
 9848  F95674  4A            		lsr	a		; if <1> = 0 => DD cbm disk
8160
 9849  F95675  90 0A         		bcc	?04
8161
 9850  F95677  A9 15         		lda	#badfmt		; unsupported HD cbm format
8162
 9851  F95679  4C F5 56      		jmp	drverr
8163
 9852  F9567C  A9 4E         	?02:	lda	#ibmfmt		; is ibm format
8164
 9853  F9567E  4C F5 56      		jmp	drverr
8165
 9854  F95681  20 8F 57      	?04:	jsr	sysrd		; read system track into cache
8166
 9855  F95684  B0 09         		bcs	?06		; error reading system track
8167
 9856  F95686  20 3E 55      		jsr	hdrtst		; check directory header
8168
 9857  F95689  90 08         		bcc	?08		; ok
8169
 9858  F9568B  A9 1D         		lda	#badid		; mismatch header
8170
 9859  F9568D  80 66         		bra	drverr
8171
 9860  F9568F  A9 4F         	?06:	lda	#syterr
8172
 9861  F95691  80 62         		bra	drverr
8173
 9862  F95693  A6 19         	?08:	ldx	drvnum		; set good flag for drive
8174
 9863  F95695  A9 80         		lda	#$80
8175
 9864  F95697  15 68         		ora	drvfg,x
8176
 9865  F95699  95 68         		sta	drvfg,x
8177
 9866  F9569B  60            	?10:	rts
8178
 9867
8179
 9868                        	; test if disk is low-level formatted
8180
 9869                        	; report format in drvfg
8181
 9870                        	; return with X = drive
8182
 9871  F9569C                	fmttst:
8183
 9872  F9569C  20 B4 56      		jsr	dsktst		; check if disk inside drive
8184
 9873  F9569F  34 68         		bit	drvfg,x		; check if already tested
8185
  Tue Jul 17 11:00:19 2018                                                                                               Page  133
8186
 
8187
 
8188
 
8189
 
8190
 9874  F956A1  70 10         		bvs	?04		; yes, format already recognized
8191
 9875  F956A3                		FDCGETFMT		; query disk format
8192
 9876  F956A3  02 30         		cop	$30
8193
 9877  F956A5  04            		.DB	$04
8194
 9878                        		.MNLIST
8195
 9879  F956A6  90 04         		bcc	?02		; ok, recognized format
8196
 9880  F956A8  A9 15         		lda	#badfmt
8197
 9881  F956AA  80 49         		bra	drverr
8198
 9882  F956AC  98            	?02:	tya			; format in bit 1,0
8199
 9883  F956AD  09 40         		ora	#$40
8200
 9884  F956AF  15 68         		ora	drvfg,x
8201
 9885  F956B1  95 68         		sta	drvfg,x
8202
 9886  F956B3  60            	?04:	rts
8203
 9887
8204
 9888                        	; check if disk is inserted on a drive
8205
 9889                        	; return with X = drive
8206
 9890  F956B4                	dsktst:
8207
 9891  F956B4  A6 19         		ldx	drvnum		; drive 0 or 1
8208
 9892  F956B6                		FDCTST			; check if disk inserted
8209
 9893  F956B6  02 30         		cop	$30
8210
 9894  F956B8  03            		.DB	$03
8211
 9895                        		.MNLIST
8212
 9896  F956B9  B0 06         		bcs	?02		; check if disk was changed
8213
 9897  F956BB  34 68         		bit	drvfg,x		; check if disk was inside drive at boot time
8214
 9898  F956BD  30 2D         		bmi	?08		; no, already init so exit
8215
 9899  F956BF  10 0E         		bpl	?07		; invalidate all cached data
8216
 9900  F956C1  C0 11         	?02:	cpy	#FDC_CHANGE	; check error code
8217
 9901  F956C3  F0 05         		beq	?06		; disk changed
8218
 9902  F956C5  A9 4A         	?04:	lda	#nodriv		; abort: no disk
8219
 9903  F956C7  4C 07 41      		jmp	cmderr
8220
 9904  F956CA                	?06:	FDCTST			; check again
8221
 9905  F956CA  02 30         		cop	$30
8222
 9906  F956CC  03            		.DB	$03
8223
 9907                        		.MNLIST
8224
 9908  F956CD  B0 F6         		bcs	?04		; fatal error
8225
 9909  F956CF  74 68         	?07:	stz	drvfg,x		; invalidate drive flags bcs disk changed
8226
 9910  F956D1  74 84         		stz	wbam,x
8227
 9911  F956D3  74 04         		stz	dirsec,x
8228
 9912  F956D5  74 06         		stz	index,x
8229
 9913  F956D7  74 02         		stz	delind,x
8230
 9914  F956D9  74 00         		stz	delsec,x
8231
 9915  F956DB  74 80         		stz	tcache,x
8232
 9916  F956DD  74 82         		stz	wcache,x
8233
 9917  F956DF                		FDCGETST		; get status drive
8234
 9918  F956DF  02 30         		cop	$30
8235
 9919  F956E1  02            		.DB	$02
8236
 9920                        		.MNLIST
8237
 9921  F956E2  B0 E1         		bcs	?04
8238
 9922  F956E4  98            		tya
8239
 9923  F956E5  0A            		asl	a		; test bit 6
8240
 9924  F956E6  10 04         		bpl	?08
8241
 9925  F956E8  A9 10         		lda	#$10
8242
 9926  F956EA  95 68         		sta	drvfg,x
8243
 9927  F956EC  60            	?08:	rts
8244
 9928
8245
 9929                        	;---------------------------------------------------------------------------
8246
 9930                        	; error procedure's
8247
  Tue Jul 17 11:00:19 2018                                                                                               Page  134
8248
 
8249
 
8250
 
8251
 
8252
 9931                        	;---------------------------------------------------------------------------
8253
 9932
8254
 9933                        	; main error procedure
8255
 9934                        	; in:	A = error code
8256
 9935                        	;	track & sector
8257
 9936                        	;		t & s = 0 for command error
8258
 9937                        	;		t = drvnum for drive error level
8259
 9938                        	;		t = chnl for channel error level
8260
 9939                        	; abort any procedure and return to caller with error code
8261
 9940
8262
 9941  F956ED                	chnerr:
8263
 9942  F956ED  A6 52         		ldx	chnl
8264
 9943  F956EF  86 08         		stx	track
8265
 9944  F956F1  64 09         		stz	sector
8266
 9945  F956F3  80 06         		bra	doserr
8267
 9946
8268
 9947  F956F5                	drverr:
8269
 9948  F956F5  A6 19         		ldx	drvnum		; track = drive #
8270
 9949  F956F7  86 08         		stx	track
8271
 9950  F956F9  64 09         		stz	sector
8272
 9951
8273
 9952  F956FB                	doserr:
8274
 9953  F956FB  85 56         		sta	lsterr		; last error
8275
 9954  F956FD  A6 08         		ldx	track		; save track & sector for later use
8276
 9955  F956FF  8E FA E1      		stx	etrk
8277
 9956  F95702  A6 09         		ldx	sector
8278
 9957  F95704  8E FB E1      		stx	esec
8279
 9958  F95707  24 F8         		bit	trap		; set flag while open functiom
8280
 9959  F95709  10 05         		bpl	?10
8281
 9960  F9570B  20 F0 47      		jsr	frefd		; free fd
8282
 9961  F9570E  64 F8         		stz	trap
8283
 9962  F95710                	?10:	INDEX16
8284
 9963  F95710  C2 10         		rep	#PXFLAG
8285
 9964                        		.LONGI	on
8286
 9965                        		.MNLIST
8287
 9966  F95712  AE F8 E1      		ldx	tos
8288
 9967  F95715  9A            		txs			; recover stack pointer
8289
 9968  F95716                		INDEX08
8290
 9969  F95716  E2 10         		sep	#PXFLAG
8291
 9970                        		.LONGI	off
8292
 9971                        		.MNLIST
8293
 9972  F95718  38            		sec			; error code in accum.
8294
 9973  F95719  60            		rts
8295
 9974
8296
 9975                        	; format error message -- called reading channel 15
8297
 9976  F9571A                	fmterr:
8298
 9977  F9571A  20 44 57      		jsr	fnderr		; find error string
8299
 9978  F9571D  AE FB E1      		ldx	esec		; push params for _bsprintf
8300
 9979  F95720  DA            		phx			; sector (1b)
8301
 9980  F95721  AE FA E1      		ldx	etrk
8302
 9981  F95724  DA            		phx			; track (1b)
8303
 9982  F95725  4B            		phk			; error string bank (1b)
8304
 9983  F95726  D4 3E         		pei	(tlp)		; error string ptr (2b)
8305
 9984  F95728  A5 56         		lda	lsterr
8306
 9985  F9572A  48            		pha			; error code (1b)
8307
 9986  F9572B  F4 60 00      		pea	#cmdlen		; size of dest. string (2b)
8308
 9987  F9572E  A9 00         		lda	#^cmdbuf	; dest string bank (1b)
8309
  Tue Jul 17 11:00:19 2018                                                                                               Page  135
8310
 
8311
 
8312
 
8313
 
8314
 9988  F95730  48            		pha
8315
 9989  F95731  F4 00 E1      		pea	#cmdbuf		; dest string pointer (2b)
8316
 9990  F95734  4B            		phk			; fmt string bank (1b)
8317
 9991  F95735  F4 FC 5A      		pea	#erfmt		; fmt string pointer (2b)
8318
 9992  F95738  A9 0F         		lda	#15
8319
 9993  F9573A  48            		pha			; # params bytes (1b)
8320
 9994  F9573B                		BSPRINTF
8321
 9995  F9573B  02 12         		cop	$12
8322
 9996                        		.MNLIST
8323
 9997  F9573D                		ACC16
8324
 9998  F9573D  C2 20         		rep	#PMFLAG
8325
 9999                        		.LONGA	on
8326
10000                        		.MNLIST
8327
10001  F9573F  85 88         		sta	btrf		; save count of bytes
8328
10002  F95741                		ACC08
8329
10003  F95741  E2 20         		sep	#PMFLAG
8330
10004                        		.LONGA	off
8331
10005                        		.MNLIST
8332
10006  F95743  60            		rts
8333
10007
8334
10008                        	; find basic error string
8335
10009  F95744                	fnderr:
8336
10010  F95744  A5 56         		lda	lsterr
8337
10011  F95746  F0 04         		beq	?00
8338
10012  F95748  C9 49         		cmp	#cbmv2
8339
10013  F9574A  D0 06         		bne	?01
8340
10014  F9574C  9C FA E1      	?00:	stz	etrk
8341
10015  F9574F  9C FB E1      		stz	esec
8342
10016  F95752  A9 11         	?01:	lda	#<ertbl
8343
10017  F95754  85 3E         		sta	tlp
8344
10018  F95756  A9 5B         		lda	#>ertbl
8345
10019  F95758  85 3F         		sta	tlp+1
8346
10020  F9575A  A9 F9         		lda	#^ertbl
8347
10021  F9575C  85 40         		sta	tlp+2
8348
10022  F9575E  A7 3E         	?02:	lda	[tlp]		; check error code
8349
10023  F95760  C5 56         		cmp	lsterr
8350
10024  F95762  F0 24         		beq	?10		; match
8351
10025  F95764  A0 01         		ldy	#1
8352
10026  F95766  B7 3E         	?04:	lda	[tlp],y
8353
10027  F95768  F0 03         		beq	?06		; end of string
8354
10028  F9576A  C8            		iny
8355
10029  F9576B  80 F9         		bra	?04		; find end of string
8356
10030  F9576D  C8            	?06:	iny
8357
10031  F9576E  B7 3E         		lda	[tlp],y
8358
10032  F95770  F0 0C         		beq	?08		; end of table -- string not found
8359
10033  F95772  18            		clc
8360
10034  F95773  98            		tya
8361
10035  F95774  65 3E         		adc	tlp
8362
10036  F95776  85 3E         		sta	tlp
8363
10037  F95778  90 E4         		bcc	?02		; next string
8364
10038  F9577A  E6 3F         		inc	tlp+1
8365
10039  F9577C  80 E0         		bra	?02
8366
10040  F9577E  A9 B1         	?08:	lda	#<uerr		; unknow error
8367
10041  F95780  85 3E         		sta	tlp
8368
10042  F95782  A9 5E         		lda	#>uerr
8369
10043  F95784  85 3F         		sta	tlp+1
8370
10044  F95786  80 06         		bra	?12
8371
  Tue Jul 17 11:00:19 2018                                                                                               Page  136
8372
 
8373
 
8374
 
8375
 
8376
10045  F95788  E6 3E         	?10:	inc	tlp		; found string
8377
10046  F9578A  D0 02         		bne	?12
8378
10047  F9578C  E6 3F         		inc	tlp+1
8379
10048  F9578E  60            	?12:	rts
8380
10049
8381
10050                        	;---------------------------------------------------------------------------
8382
10051                        	; phisycal access to disk
8383
10052                        	;---------------------------------------------------------------------------
8384
10053  F9578F
8385
10054                        	; read system track
8386
10055                        	; return CF=1 if error
8387
10056                        	; X=drive #
8388
10057  F9578F                	sysrd:
8389
10058  F9578F  86 F2         		stx	pdrv
8390
10059  F95791  A9 05         		lda	#5		; try to read system track
8391
10060  F95793  85 93         		sta	tmp0		; set pass count
8392
10061  F95795  DA            	?02:	phx			; drive #
8393
10062  F95796  A9 27         		lda	#dirtrk-1	; physical system track
8394
10063  F95798  48            		pha
8395
10064  F95799  B5 6E         		lda	sysbuf,x	; dma buffer #
8396
10065  F9579B  48            		pha
8397
10066  F9579C  A9 01         		lda	#1		; cbm format
8398
10067  F9579E  48            		pha
8399
10068  F9579F                		FDCTKRD			; read whole track
8400
10069  F9579F  02 35         		cop	$35
8401
10070  F957A1  00            		.DB	$00
8402
10071                        		.MNLIST
8403
10072  F957A2  A6 F2         		ldx	pdrv
8404
10073  F957A4  90 04         		bcc	?04
8405
10074  F957A6  C6 93         		dec	tmp0
8406
10075  F957A8  D0 EB         		bne	?02		; try again
8407
10076  F957AA  60            	?04:	rts
8408
10077
8409
10078                        	; read whole track into drive read cache, if not already in cache
8410
10079  F957AB                	tread:
8411
10080  F957AB  A6 19         		ldx	drvnum
8412
10081  F957AD  B5 80         		lda	tcache,x	; invalid cache?
8413
10082  F957AF  F0 06         		beq	?02		; yes so read track
8414
10083  F957B1  C5 08         		cmp	track		; already in cache?
8415
10084  F957B3  F0 0B         		beq	?04		; yes
8416
10085  F957B5  74 80         		stz	tcache,x	; invalidate cache
8417
10086  F957B7  B5 70         	?02:	lda	trkbuf,x	; dma buffer #
8418
10087  F957B9  20 63 58      		jsr	readtk
8419
10088                        		;ldx	drvnum
8420
10089  F957BC  A5 08         		lda	track
8421
10090  F957BE  95 80         		sta	tcache,x	; validate cache
8422
10091  F957C0  60            	?04:	rts
8423
10092
8424
10093                        	; read whole track into drive write cache, if not already in cache
8425
10094  F957C1                	wread:
8426
10095  F957C1  A6 19         		ldx	drvnum
8427
10096  F957C3  B5 82         		lda	wcache,x	; invalid cache?
8428
10097  F957C5  F0 06         		beq	?02		; yes so read track
8429
10098  F957C7  C5 08         		cmp	track		; already in cache?
8430
10099  F957C9  F0 0B         		beq	?04		; yes
8431
10100  F957CB  74 82         		stz	wcache,x	; invalidate cache
8432
10101  F957CD  B5 72         	?02:	lda	wrtbuf,x	; dma buffer #
8433
  Tue Jul 17 11:00:19 2018                                                                                               Page  137
8434
 
8435
 
8436
 
8437
 
8438
10102  F957CF  20 63 58      		jsr	readtk
8439
10103                        		;ldx	drvnum
8440
10104  F957D2  A5 08         		lda	track
8441
10105  F957D4  95 82         		sta	wcache,x	; validate cache
8442
10106  F957D6  60            	?04:	rts
8443
10107
8444
10108                        	; write out the system track
8445
10109  F957D7                	syswr:
8446
10110  F957D7  A0 28         		ldy	#dirtrk
8447
10111  F957D9  84 08         		sty	track
8448
10112  F957DB  A6 19         		ldx	drvnum
8449
10113  F957DD  B5 6E         		lda	sysbuf,x	; dma buffer #
8450
10114
8451
10115                        	; write out a whole track from dma buffer
8452
10116                        	; in:	A=dma buffer#
8453
10117                        	;	X=drive #
8454
10118                        	;	track=logical track
8455
10119  F957DF                	writetk:
8456
10120  F957DF  85 F6         		sta	pbuf		; dma buffer #
8457
10121  F957E1  86 F2         		stx	pdrv
8458
10122  F957E3  A9 05         		lda	#5		; write out whole track
8459
10123  F957E5  85 93         		sta	tmp0		; set pass count
8460
10124  F957E7  DA            	?02:	phx			; drive #
8461
10125  F957E8  A5 08         		lda	track
8462
10126  F957EA  3A            		dec	a		; phisycal track
8463
10127  F957EB  48            		pha
8464
10128  F957EC  A5 F6         		lda	pbuf
8465
10129  F957EE  48            		pha			; dma buffer #
8466
10130  F957EF  A9 81         		lda	#$81
8467
10131  F957F1  48            		pha			; cbm format
8468
10132  F957F2                		FDCTKWR
8469
10133  F957F2  02 35         		cop	$35
8470
10134  F957F4  02            		.DB	$02
8471
10135                        		.MNLIST
8472
10136  F957F5  A6 F2         		ldx	pdrv
8473
10137  F957F7  90 69         		bcc	lsp		; ok no error
8474
10138  F957F9  C6 93         		dec	tmp0
8475
10139  F957FB  D0 EA         		bne	?02		; try again
8476
10140  F957FD  A9 16         		lda	#wrtrk
8477
10141  F957FF  4C FB 56      		jmp	doserr
8478
10142
8479
10143                        	; update on disk bam of current drive
8480
10144                        	; write out logical sector 1 & 2 (phisycal sec 1 & 2)
8481
10145  F95802                	bamout:
8482
10146  F95802  A9 02         		lda	#2
8483
10147  F95804  85 F5         		sta	pcnt		; number of sector's to write out
8484
10148  F95806  A6 19         		ldx	drvnum		; X = drive #
8485
10149  F95808  B5 6E         		lda	sysbuf,x	; dma buffer #
8486
10150  F9580A  EB            		xba			; B = dma buffer #
8487
10151  F9580B  A9 01         		lda	#1		; A = first phisycal sector to write
8488
10152  F9580D  A0 00         		ldy	#0		; Y = side 0
8489
10153  F9580F  80 05         		bra	wrsys2
8490
10154
8491
10155                        	; write given directory sector on disk
8492
10156                        	; A = number of sec. to write out
8493
10157  F95811                	wrsys:
8494
10158  F95811  85 F5         		sta	pcnt		; number of sector's to write out
8495
  Tue Jul 17 11:00:19 2018                                                                                               Page  138
8496
 
8497
 
8498
 
8499
 
8500
10159  F95813  20 4D 58      		jsr	lsec2p		; convert logical sec to phis. sec & side
8501
10160
8502
10161                        	; X=drive #
8503
10162                        	; Y=side
8504
10163                        	; A=start phisycal sec
8505
10164                        	; B=dma buffer #
8506
10165                        	; tpcnt=count #
8507
10166  F95816                	wrsys2:
8508
10167  F95816  85 F4         		sta	psec		; first phisycal sector
8509
10168  F95818  EB            		xba
8510
10169  F95819  85 F6         		sta	pbuf		; dma buffer #
8511
10170  F9581B  86 F2         		stx	pdrv
8512
10171  F9581D  84 F3         		sty	pside
8513
10172  F9581F  A9 28         		lda	#dirtrk
8514
10173  F95821  85 08         		sta	track
8515
10174  F95823
8516
10175                        		; prepare stack params for call system function:
8517
10176                        		; FDCWRITE(bDrive, bTrk, bHead, bSect, bNum, bBuf, bFlag)
8518
10177  F95823  A9 05         		lda	#5
8519
10178  F95825  85 93         		sta	tmp0		; set pass count
8520
10179  F95827  DA            	?02:	phx			; drive #
8521
10180  F95828  A5 08         		lda	track
8522
10181  F9582A  3A            		dec	a		; phisycal track
8523
10182  F9582B  48            		pha
8524
10183  F9582C  A5 F3         		lda	pside
8525
10184  F9582E  48            		pha			; side (head)
8526
10185  F9582F  A5 F4         		lda	psec
8527
10186  F95831  48            		pha			; phisycal sector
8528
10187  F95832  A5 F5         		lda	pcnt
8529
10188  F95834  48            		pha			; sector's count to write out
8530
10189  F95835  A5 F6         		lda	pbuf
8531
10190  F95837  48            		pha			; dma buffer
8532
10191  F95838  A9 81         		lda	#$81		; A = 1
8533
10192  F9583A  48            		pha			; flag (cbm format, verify)
8534
10193  F9583B                		FDCWRITE
8535
10194  F9583B  02 31         		cop	$31
8536
10195  F9583D  02            		.DB	$02
8537
10196                        		.MNLIST
8538
10197  F9583E  A6 F2         		ldx	pdrv
8539
10198  F95840  90 20         		bcc	lsp
8540
10199  F95842  C6 93         		dec	tmp0
8541
10200  F95844  D0 E1         		bne	?02		; try again
8542
10201  F95846  74 68         		stz	drvfg,x		; ...invalidate drive #
8543
10202  F95848  A9 19         		lda	#wrsec		; write error
8544
10203  F9584A  4C FB 56      		jmp	doserr
8545
10204  F9584D
8546
10205                        	; translate logical sector into phisycal sector & side
8547
10206                        	; in:	sector = logical sector
8548
10207                        	; out:	X = drive #
8549
10208                        	;	A = sector #
8550
10209                        	;	Y = side #
8551
10210                        	;	B = dma buffer #
8552
10211  F9584D                	lsec2p:
8553
10212  F9584D  A6 19         		ldx	drvnum
8554
10213  F9584F  A5 09         		lda	sector		; 0..39
8555
10214  F95851  4A            		lsr	a		; 0..19
8556
10215  F95852  A8            		tay			; save
8557
  Tue Jul 17 11:00:19 2018                                                                                               Page  139
8558
 
8559
 
8560
 
8561
 
8562
10216  F95853  18            		clc			; add base dma buffer
8563
10217  F95854  75 6E         		adc	sysbuf,x
8564
10218  F95856  EB            		xba			; B = dma buffer # that contain phis. sec.
8565
10219  F95857  98            		tya
8566
10220  F95858  A0 00         		ldy	#0		; side 0
8567
10221  F9585A  C9 0A         		cmp	#phisec		; 0..9 -> side 0, 10..19 -> side 1
8568
10222  F9585C  90 03         		bcc	?02
8569
10223  F9585E  E9 0A         		sbc	#phisec
8570
10224  F95860  C8            		iny			; side 1
8571
10225  F95861  1A            	?02:	inc	a		; A = phisycal sec
8572
10226  F95862  60            	lsp:	rts
8573
10227
8574
10228                        	; read a whole track into dma buffer
8575
10229                        	; in:	A=dma buffer#
8576
10230                        	;	X=drive #
8577
10231                        	;	track=logical track
8578
10232  F95863                	readtk:
8579
10233  F95863  85 F6         		sta	pbuf		; dma buffer #
8580
10234  F95865  86 F2         		stx	pdrv
8581
10235  F95867  A9 05         		lda	#5
8582
10236  F95869  85 93         		sta	tmp0		; set pass count
8583
10237  F9586B  DA            	?02:	phx			; drive #
8584
10238  F9586C  A5 08         		lda	track		; physical track
8585
10239  F9586E  3A            		dec	a
8586
10240  F9586F  48            		pha
8587
10241  F95870  A5 F6         		lda	pbuf		; dma buffer #
8588
10242  F95872  48            		pha
8589
10243  F95873  A9 01         		lda	#1		; cbm format
8590
10244  F95875  48            		pha
8591
10245  F95876                		FDCTKRD			; read whole track
8592
10246  F95876  02 35         		cop	$35
8593
10247  F95878  00            		.DB	$00
8594
10248                        		.MNLIST
8595
10249  F95879  A6 F2         		ldx	pdrv
8596
10250  F9587B  90 E5         		bcc	lsp		; ok, no error
8597
10251  F9587D  C6 93         		dec	tmp0
8598
10252  F9587F  D0 EA         		bne	?02		; try again
8599
10253  F95881  A9 14         		lda	#rdtrk		; error reading whole track
8600
10254  F95883  4C FB 56      		jmp	doserr
8601
10255
8602
10256                        	; write out sector(s) from dma buffer
8603
10257                        	; in:	X=drive
8604
10258                        	;	Y=start phisycal sector
8605
10259                        	;	A=sector's count #
8606
10260                        	;	B=dma buffer #
8607
10261                        	;	pside=side
8608
10262                        	; use tmp0
8609
10263  F95886                	writesec:
8610
10264  F95886  85 F5         		sta	pcnt		; count #
8611
10265  F95888  EB            		xba
8612
10266  F95889  85 F6         		sta	pbuf		; dma buffer #
8613
10267  F9588B  84 F4         		sty	psec
8614
10268  F9588D  86 F2         		stx	pdrv
8615
10269  F9588F  A9 05         		lda	#5		; set pass count
8616
10270  F95891  85 93         		sta	tmp0
8617
10271  F95893  DA            	?02:	phx			; drive #
8618
10272  F95894  A5 08         		lda	track
8619
  Tue Jul 17 11:00:19 2018                                                                                               Page  140
8620
 
8621
 
8622
 
8623
 
8624
10273  F95896  3A            		dec	a
8625
10274  F95897  48            		pha			; phisycal track
8626
10275  F95898  A5 F3         		lda	pside
8627
10276  F9589A  48            		pha			; side
8628
10277  F9589B  A5 F4         		lda	psec
8629
10278  F9589D  48            		pha			; start phisycal sector
8630
10279  F9589E  A5 F5         		lda	pcnt
8631
10280  F958A0  48            		pha			; count #: how much sec's
8632
10281  F958A1  A5 F6         		lda	pbuf
8633
10282  F958A3  48            		pha			; dma buffer #
8634
10283  F958A4  A9 81         		lda	#$81
8635
10284  F958A6  48            		pha			; cbm format
8636
10285  F958A7                		FDCWRITE
8637
10286  F958A7  02 31         		cop	$31
8638
10287  F958A9  02            		.DB	$02
8639
10288                        		.MNLIST
8640
10289  F958AA  A6 F2         		ldx	pdrv
8641
10290  F958AC  90 B4         		bcc	lsp		; ok no error
8642
10291  F958AE  C6 93         		dec	tmp0
8643
10292  F958B0  D0 E1         		bne	?02		; try again
8644
10293  F958B2  A9 19         		lda	#wrsec
8645
10294  F958B4  4C FB 56      		jmp	doserr
8646
10295
8647
10296                        	; read sector(s) into dma buffer
8648
10297                        	; use tmp0
8649
10298  F958B7                	readsec:
8650
10299  F958B7  A9 05         		lda	#5		; set pass count
8651
10300  F958B9  85 93         		sta	tmp0
8652
10301  F958BB  A5 F2         	?02:	lda	pdrv		; drive #
8653
10302  F958BD  48            		pha
8654
10303  F958BE  A5 08         		lda	track
8655
10304  F958C0  3A            		dec	a
8656
10305  F958C1  48            		pha			; phisycal track
8657
10306  F958C2  A5 F3         		lda	pside
8658
10307  F958C4  48            		pha			; side
8659
10308  F958C5  A5 F4         		lda	psec
8660
10309  F958C7  48            		pha			; start phisycal sector
8661
10310  F958C8  A5 F5         		lda	pcnt
8662
10311  F958CA  48            		pha			; count #: how much sec's
8663
10312  F958CB  A5 F6         		lda	pbuf
8664
10313  F958CD  48            		pha			; dma buffer #
8665
10314  F958CE  A9 01         		lda	#1
8666
10315  F958D0  48            		pha			; cbm format
8667
10316  F958D1                		FDCREAD
8668
10317  F958D1  02 31         		cop	$31
8669
10318  F958D3  00            		.DB	$00
8670
10319                        		.MNLIST
8671
10320  F958D4  A6 F2         		ldx	pdrv
8672
10321  F958D6  90 8A         		bcc	lsp		; ok no error
8673
10322  F958D8  C6 93         		dec	tmp0
8674
10323  F958DA  D0 DF         		bne	?02		; try again
8675
10324  F958DC  A9 18         		lda	#rdsec
8676
10325  F958DE  4C FB 56      		jmp	doserr
8677
10326
8678
10327                        	;---------------------------------------------------------------------------
8679
10328                        	; low level format
8680
10329                        	;---------------------------------------------------------------------------
8681
  Tue Jul 17 11:00:19 2018                                                                                               Page  141
8682
 
8683
 
8684
 
8685
 
8686
10330
8687
10331  F958E1                	llfmt:
8688
10332  F958E1  20 5F 59      		jsr	?110
8689
10333  F958E4  A5 19         		lda	drvnum
8690
10334  F958E6  48            		pha			; drive #
8691
10335  F958E7  A9 C1         		lda	#$C1
8692
10336  F958E9  48            		pha			; flag (notify, verify, cbm fmt)
8693
10337  F958EA  A9 00         		lda	#0
8694
10338  F958EC  48            		pha			; fill byte
8695
10339  F958ED  4B            		phk			; adress of callback
8696
10340  F958EE  F4 03 59      		pea	#!?08
8697
10341  F958F1                		FDCFORMAT
8698
10342  F958F1  02 33         		cop	$33
8699
10343                        		.MNLIST
8700
10344  F958F3  90 0D         		bcc	?06		; ok
8701
10345  F958F5  C0 0B         		cpy	#FDC_WP
8702
10346  F958F7  D0 04         		bne	?02
8703
10347  F958F9  A9 1A         		lda	#wpon
8704
10348  F958FB  80 02         		bra	?04
8705
10349  F958FD  A9 4D         	?02:	lda	#fmter
8706
10350  F958FF  4C F5 56      	?04:	jmp	drverr
8707
10351  F95902  60            	?06:	rts
8708
10352
8709
10353                        	; callback function while formatting
8710
10354                        	; In	- A = drive
8711
10355                        	;	  X = head
8712
10356                        	;	  Y = track
8713
10357                        	;	  B = sector/track
8714
10358                        	;	  CF = 0 when called first time
8715
10359  F95903                	?08:
8716
10360  F95903  0B            		phd			; save DP
8717
10361  F95904  F4 00 7E      		pea	#CBMFSP0	; set new DP
8718
10362  F95907  2B            		pld
8719
10363  F95908  DA            		phx
8720
10364  F95909  C8            		iny			; show track 1..80
8721
10365  F9590A  5A            		phy
8722
10366  F9590B  B0 07         		bcs	?10
8723
10367  F9590D                		SCNGETPOS		; first time get position on screen
8724
10368  F9590D  02 18         		cop	$18
8725
10369  F9590F  02            		.DB	$02
8726
10370                        		.MNLIST
8727
10371  F95910  86 94         		stx	wtmp
8728
10372  F95912  84 95         		sty	wtmp+1
8729
10373                        		;;SCN_CR
8730
10374                        		;;bra	?20
8731
10375  F95914  A6 94         	?10:	ldx	wtmp
8732
10376  F95916  A4 95         		ldy	wtmp+1
8733
10377  F95918                		SCNSETPOS
8734
10378  F95918  02 18         		cop	$18
8735
10379  F9591A  03            		.DB	$03
8736
10380                        		.MNLIST
8737
10381  F9591B                	?20:
8738
10382                        					; X = head - param format in stack
8739
10383                        					; Y = track - param format in stack
8740
10384  F9591B  48            		pha			; A = drive #
8741
10385  F9591C  4B            		phk			; bank of format str
8742
10386  F9591D  F4 27 59      		pea	#!?100		; address of format str
8743
  Tue Jul 17 11:00:19 2018                                                                                               Page  142
8744
 
8745
 
8746
 
8747
 
8748
10387  F95920  A9 07         		lda	#7		; # params
8749
10388  F95922  48            		pha
8750
10389  F95923                		BPRINTF
8751
10390  F95923  02 11         		cop	$11
8752
10391                        		.MNLIST
8753
10392  F95925  2B            		pld
8754
10393  F95926  6B            		rtl
8755
10394
8756
10395  F95927  66 6F 72 6D 61 	?100:	.DB	'format diskette on drive #%bu (track #%02bu, side #%bu)', $00
8757
               74 20 64 69 73
8758
               6B 65 74 74 65
8759
               20 6F 6E 20 64
8760
               72 69 76 65 20
8761
               23 25 62 75 20
8762
               28 74 72 61 63
8763
               6B 20 23 25 30
8764
               32 62 75 2C 20
8765
               73 69 64 65 20
8766
               23 25 62 75 29
8767
               00
8768
10396
8769
10397                        	?110:	; format msg
8770
10398  F9595F  A5 19         		lda	drvnum
8771
10399  F95961  48            		pha
8772
10400  F95962  4B            		phk
8773
10401  F95963  F4 75 59      		pea	#!?120
8774
10402  F95966  A9 05         		lda	#5
8775
10403  F95968  48            		pha
8776
10404  F95969                		BPRINTF
8777
10405  F95969  02 11         		cop	$11
8778
10406                        		.MNLIST
8779
10407  F9596B  A9 59         		lda	#>?130
8780
10408  F9596D  EB            		xba
8781
10409  F9596E  A9 AB         		lda	#<?130
8782
10410  F95970  A2 F9         		ldx	#^?130
8783
10411  F95972                		SCNSTROUT
8784
10412  F95972  02 03         		cop	$03
8785
10413                        		.MNLIST
8786
10414  F95974  60            		rts
8787
10415
8788
10416  F95975  0D 46 6F 72 6D 	?120:	.DB	$0D, 'Format diskette on drive #%bu - cbm 1581 format type', 0
8789
               61 74 20 64 69
8790
               73 6B 65 74 74
8791
               65 20 6F 6E 20
8792
               64 72 69 76 65
8793
               20 23 25 62 75
8794
               20 2D 20 63 62
8795
               6D 20 31 35 38
8796
               31 20 66 6F 72
8797
               6D 61 74 20 74
8798
               79 70 65 00
8799
10417  F959AB  0D 53 69 64 65 	?130:	.DB	$0D, 'Sides: 2, tracks: 80/side, sectors: 10/track, total: 1600', $0D, 0
8800
               73 3A 20 32 2C
8801
               20 74 72 61 63
8802
               6B 73 3A 20 38
8803
               30 2F 73 69 64
8804
               65 2C 20 73 65
8805
  Tue Jul 17 11:00:19 2018                                                                                               Page  143
8806
 
8807
 
8808
 
8809
 
8810
               63 74 6F 72 73
8811
               3A 20 31 30 2F
8812
               74 72 61 63 6B
8813
               2C 20 74 6F 74
8814
               61 6C 3A 20 31
8815
               36 30 30 0D 00
8816
10418
8817
10419                        	;---------------------------------------------------------------------------
8818
10420                        	; emulator initialitation
8819
10421                        	;---------------------------------------------------------------------------
8820
10422
8821
10423                        	; init emulator -- called at boot time
8822
10424  F959E7                	fscbmint:
8823
10425                        		.GLOBAL fscbmint
8824
10426  F959E7
8825
10427  F959E7  0B            		phd			; save DP
8826
10428  F959E8  F4 00 7E      		pea	#CBMFSP0	; set DP of cbm f.s.
8827
10429  F959EB  2B            		pld
8828
10430  F959EC  A2 00         		ldx	#0
8829
10431  F959EE  74 00         	?02:	stz	<zpstart,x
8830
10432  F959F0  9E 00 E1      		stz	CBMFSW_START,x
8831
10433  F959F3  E8            		inx
8832
10434  F959F4  D0 F8         		bne	?02
8833
10435  F959F6  A9 FF         		lda	#$FF
8834
10436  F959F8  85 58         		sta	linuse		; all free
8835
10437  F959FA  A2 0E         		ldx	#mxchnls-1
8836
10438  F959FC  95 59         	?04:	sta	lintab,x	; all free
8837
10439  F959FE  CA            		dex
8838
10440  F959FF  10 FB         		bpl	?04
8839
10441  F95A01  A9 49         		lda	#cbmv2		; emulator compatibility
8840
10442  F95A03  85 56         		sta	lsterr
8841
10443  F95A05  A9 00         		lda	#DR0SYS
8842
10444  F95A07  85 6E         		sta	sysbuf		; drive 0 system track cache
8843
10445  F95A09  20 51 5A      		jsr	?100
8844
10446  F95A0C  85 74         		sta	dirofs
8845
10447  F95A0E  84 76         		sty	dirbnk
8846
10448  F95A10  A9 24         		lda	#DR1SYS
8847
10449  F95A12  85 6F         		sta	sysbuf+1	; drive 1 system track cache
8848
10450  F95A14  20 51 5A      		jsr	?100
8849
10451  F95A17  85 75         		sta	dirofs+1
8850
10452  F95A19  84 77         		sty	dirbnk+1
8851
10453  F95A1B  A9 48         		lda	#DR0CACHE
8852
10454  F95A1D  85 70         		sta	trkbuf		; drive 0 track cache
8853
10455  F95A1F  20 51 5A      		jsr	?100
8854
10456  F95A22  85 78         		sta	trkofs
8855
10457  F95A24  84 7A         		sty	trkbnk
8856
10458  F95A26  A9 DC         		lda	#DR1CACHE
8857
10459  F95A28  85 71         		sta	trkbuf+1	; drive 1 track cache
8858
10460  F95A2A  20 51 5A      		jsr	?100
8859
10461  F95A2D  85 79         		sta	trkofs+1
8860
10462  F95A2F  84 7B         		sty	trkbnk+1
8861
10463  F95A31  64 80         		stz	tcache		; invalidate track cache
8862
10464  F95A33  64 81         		stz	tcache+1
8863
10465  F95A35  A9 6C         		lda	#DMAFREE0	; drive 0 write cache
8864
10466  F95A37  85 72         		sta	wrtbuf
8865
10467  F95A39  20 51 5A      		jsr	?100
8866
10468  F95A3C  85 7C         		sta	wrtofs
8867
  Tue Jul 17 11:00:19 2018                                                                                               Page  144
8868
 
8869
 
8870
 
8871
 
8872
10469  F95A3E  84 7E         		sty	wrtbnk
8873
10470  F95A40  A9 C0         		lda	#DMAFREE1	; drive 1 write cache
8874
10471  F95A42  85 73         		sta	wrtbuf+1
8875
10472  F95A44  20 51 5A      		jsr	?100
8876
10473  F95A47  85 7D         		sta	wrtofs+1
8877
10474  F95A49  84 7F         		sty	wrtbnk+1
8878
10475  F95A4B  64 82         		stz	wcache		; invalidate write cache
8879
10476  F95A4D  64 83         		stz	wcache+1
8880
10477  F95A4F  2B            		pld
8881
10478  F95A50  60            		rts
8882
10479
8883
10480                        	; calc effective high pointer
8884
10481                        	; in:	A = dma buffer
8885
10482                        	; out:	Y = bank
8886
10483                        	;	A = high pointer
8887
10484  F95A51  A0 02         	?100:	ldy	#DMABNK		; bank for buffer #00..#7F
8888
10485  F95A53  0A            		asl	a		; get high pointer
8889
10486  F95A54  90 01         		bcc	?102
8890
10487  F95A56  C8            		iny			; next bank
8891
10488  F95A57  60            	?102:	rts
8892
10489
8893
10490                        	;---------------------------------------------------------------------------
8894
10491                        	; tables
8895
10492                        	;---------------------------------------------------------------------------
8896
10493
8897
10494                        	; command search table
8898
10495                        	; Rename Scratch New Exist Lock unlocK Append Transfer Move Quick-format
8899
10496  F95A58  52 53 4E 45 4C 	cmdtbl	.DB	'RSNELKATMQ'	; these call tagcmd routine
8900
               4B 41 54 4D 51
8901
10497          00000A        	pcmd	.EQU	$ - cmdtbl	; limit of no parsed cmds
8902
10498          00000B        	ldcmd	.EQU	pcmd + 1	; load dir cmd image
8903
10499                        	; Copy Validate Filecheck Init Duplicate
8904
10500  F95A62  43 56 46 49 44 		.DB	'CVFID'
8905
10501          00000F        	ndcmd	.EQU	$ - cmdtbl	; limit for check drive
8906
10502                        	; Block-op User
8907
10503  F95A67  42 55         		.DB	'BU'
8908
10504          000011        	ncmds	.EQU	$ - cmdtbl
8909
10505
8910
10506                        	; Block-op subcmds: Read, Write, Alloc, Free, Position
8911
10507  F95A69  52 57 41 46 50 	cmdstb	.DB	'RWAFP'
8912
10508          000005        	ncmds2	.EQU	$ - cmdstb
8913
10509
8914
10510                        	; template mask for cmds
8915
10511  F95A6E                	struct:
8916
10512  F95A6E  DD            		.DB	%11011101	; Rename
8917
10513  F95A6F  1C            		.DB	%00011100	; Scratch (=type is optional)
8918
10514  F95A70  9E            		.DB	%10011110	; New
8919
10515  F95A71  DE            		.DB	%11011110	; Exist
8920
10516  F95A72  DE            		.DB	%11011110	; Lock
8921
10517  F95A73  DE            		.DB	%11011110	; unlocK
8922
10518  F95A74  D9            		.DB	%11011001	; Append
8923
10519  F95A75  DD            		.DB	%11011101	; Transfer
8924
10520  F95A76  DD            		.DB	%11011101	; Move
8925
10521  F95A77  9E            		.DB	%10011110	; QuickF (like New)
8926
10522  F95A78
8927
10523  F95A78  51            		.DB	%01010001	; Copy (basic mask)
8928
10524  F95A79  1C            		.DB	%00011100	; load dir template
8929
  Tue Jul 17 11:00:19 2018                                                                                               Page  145
8930
 
8931
 
8932
 
8933
 
8934
10525
8935
10526  F95A7A  52 57 41 4D   	modlst	.DB	'RWAM'		; mode table
8936
10527          000004        	nmodes	.EQU	$ - modlst
8937
10528  F95A7E  44 53 50 55 4C 	tplst	.DB	'DSPULC'	; file type table
8938
               43
8939
10529  F95A84  44 53 50 55 52 	typlst	.DB	'DSPURC'	; del,seq,prog,user,rel,cbm
8940
               43
8941
10530          000006        	ntypes	.EQU	$ - typlst
8942
10531  F95A8A  45 45 52 53 45 	tp1lst	.DB	'EERSEB'
8943
               42
8944
10532  F95A90  4C 51 47 52 4C 	tp2lst	.DB	'LQGRLM'
8945
               4D
8946
10533
8947
10534                        	; cbm file name bad char's
8948
10535  F95A96  3A 2C 3D 24 22 	badchr	.DB	':,=$"@'	; char's not allowed in file name
8949
               40
8950
10536          000006        	nbadch	.EQU	$ - badchr
8951
10537
8952
10538  F95A9C  62 6C 6F 63 6B 	fremsg	.DB	'blocks free.'
8953
               73 20 66 72 65
8954
               65 2E
8955
10539          00000C        	msglen	.EQU	$-fremsg
8956
10540
8957
10541                        	; bit mask
8958
10542  F95AA8  01 02 04 08 10 	bmask	.DB	$01, $02, $04, $08, $10, $20, $40, $80
8959
               20 40 80
8960
10543  F95AB0  0100 0200 0400 	wmask	.DW	$0001, $0002, $0004, $0008, $0010, $0020, $0040, $0080
8961
               0800 1000 2000
8962
               4000 8000
8963
10544  F95AC0  0001 0002     		.DW	$0100, $0200
8964
10545
8965
10546                        	; command functions table
8966
10547  F95AC4                	cjump:
8967
10548  F95AC4  C435 CA32 1D34 		.DW	rename, scratch, newdsk, exist, lock, unlock
8968
               3036 4236 7A36
8969
10549  F95AD0  CB36 9136 AD36 		.DW	append, transf, move, quickf, copy, vdate, fcheck
8970
               1334 3A37 523B
8971
               4B3B
8972
10550  F95ADE  053C 183C D93C 		.DW	initd, dupd, blkb, blku
8973
               C03C
8974
10551
8975
10552                        	; subcommand functions table
8976
10553  F95AE6                	scjmp:
8977
10554  F95AE6  ED3D 823E CA3E 		.DW	blkrd, blkwr, blkalc, blkfree, blkpos
8978
               053F 403F
8979
10555
8980
10556                        	; read, write, append, load dir, open dir, open blk
8981
10557  F95AF0                	opncmd:
8982
10558  F95AF0  FA30 5031 8B31 		.DW	opnrd, opnwr, opnap, loaddir, opndir, opnblk
8983
               3532 AB32 BE32
8984
10559
8985
10560                        	; error msg
8986
10561  F95AFC  25 30 32 62 75 	erfmt:	.DB	'%02bu,%s,%02bu,%02bu', 0
8987
               2C 25 73 2C 25
8988
               30 32 62 75 2C
8989
               25 30 32 62 75
8990
               00
8991
  Tue Jul 17 11:00:19 2018                                                                                               Page  146
8992
 
8993
 
8994
 
8995
 
8996
10562
8997
10563  F95B11                	ertbl:
8998
10564  F95B11  00 4F 6B 00   		.DB	$00,	'Ok', 0						; 00
8999
10565  F95B15  01 46 69 6C 65 		.DB	$01,	'Files scratched', 0				; 01
9000
               73 20 73 63 72
9001
               61 74 63 68 65
9002
               64 00
9003
10566  F95B26  14 54 72 61 63 		.DB	rdtrk,	'Track read error', 0				; 20
9004
               6B 20 72 65 61
9005
               64 20 65 72 72
9006
               6F 72 00
9007
10567  F95B38  15 42 61 64 20 		.DB	badfmt,	'Bad disk format (or unformatted disk)', 0	; 21
9008
               64 69 73 6B 20
9009
               66 6F 72 6D 61
9010
               74 20 28 6F 72
9011
               20 75 6E 66 6F
9012
               72 6D 61 74 74
9013
               65 64 20 64 69
9014
               73 6B 29 00
9015
10568  F95B5F  16 54 72 61 63 		.DB	wrtrk,	'Track write error', 0				; 22
9016
               6B 20 77 72 69
9017
               74 65 20 65 72
9018
               72 6F 72 00
9019
10569  F95B72  18 52 65 61 64 		.DB	rdsec,	'Read error', 0					; 24
9020
               20 65 72 72 6F
9021
               72 00
9022
10570  F95B7E  19 57 72 69 74 		.DB	wrsec,	'Write error', 0				; 25
9023
               65 20 65 72 72
9024
               6F 72 00
9025
10571  F95B8B  1A 57 72 69 74 		.DB	wpon,	'Write protect on', 0				; 26
9026
               65 20 70 72 6F
9027
               74 65 63 74 20
9028
               6F 6E 00
9029
10572  F95B9D  1D 44 69 73 6B 		.DB	badid,	'Disk ID mismatch', 0				; 29
9030
               20 49 44 20 6D
9031
               69 73 6D 61 74
9032
               63 68 00
9033
10573  F95BAF  1E 47 65 6E 65 		.DB	badsyn,	'General syntax error', 0			; 30
9034
               72 61 6C 20 73
9035
               79 6E 74 61 78
9036
               20 65 72 72 6F
9037
               72 00
9038
10574  F95BC5  1F 49 6E 76 61 		.DB	badcmd,	'Invalid command', 0				; 31
9039
               6C 69 64 20 63
9040
               6F 6D 6D 61 6E
9041
               64 00
9042
10575  F95BD6  20 43 6F 6D 6D 		.DB	longln,	'Command line too long', 0			; 32
9043
               61 6E 64 20 6C
9044
               69 6E 65 20 74
9045
               6F 6F 20 6C 6F
9046
               6E 67 00
9047
10576  F95BED  21 49 6E 76 61 		.DB	badfn,	'Invalid file name', 0				; 33
9048
               6C 69 64 20 66
9049
               69 6C 65 20 6E
9050
               61 6D 65 00
9051
10577  F95C00  22 4D 69 73 73 		.DB	nofile,	'Missing file name', 0				; 34
9052
               69 6E 67 20 66
9053
  Tue Jul 17 11:00:19 2018                                                                                               Page  147
9054
 
9055
 
9056
 
9057
 
9058
               69 6C 65 20 6E
9059
               61 6D 65 00
9060
10578  F95C13  23 49 6C 6C 65 		.DB	baddrv,	'Illegal drive number', 0			; 35
9061
               67 61 6C 20 64
9062
               72 69 76 65 20
9063
               6E 75 6D 62 65
9064
               72 00
9065
10579  F95C29  24 49 6C 6C 65 		.DB	badchn,	'Illegal channel number', 0			; 36
9066
               67 61 6C 20 63
9067
               68 61 6E 6E 65
9068
               6C 20 6E 75 6D
9069
               62 65 72 00
9070
10580  F95C41  25 45 6D 70 74 		.DB	nullln, 'Empty command string', 0			; 37
9071
               79 20 63 6F 6D
9072
               6D 61 6E 64 20
9073
               73 74 72 69 6E
9074
               67 00
9075
10581  F95C57  27 43 61 6E 6E 		.DB	notsam,	'Cannot rename across drives', 0		; 39
9076
               6F 74 20 72 65
9077
               6E 61 6D 65 20
9078
               61 63 72 6F 73
9079
               73 20 64 72 69
9080
               76 65 73 00
9081
10582  F95C74  28 4C 6F 63 6B 		.DB	flock,	'Locked file', 0				; 40
9082
               65 64 20 66 69
9083
               6C 65 00
9084
10583  F95C81  29 57 72 69 74 		.DB	fsplt,	'Write file not closed', 0			; 41
9085
               65 20 66 69 6C
9086
               65 20 6E 6F 74
9087
               20 63 6C 6F 73
9088
               65 64 00
9089
10584  F95C98  2A 55 6E 6D 61 		.DB	bnotm,	'Unmatch blocks count', 0			; 42
9090
               74 63 68 20 62
9091
               6C 6F 63 6B 73
9092
               20 63 6F 75 6E
9093
               74 00
9094
10585  F95CAE  2B 49 6E 76 61 		.DB	invlnk,	'Invalid file link', 0				; 43
9095
               6C 69 64 20 66
9096
               69 6C 65 20 6C
9097
               69 6E 6B 00
9098
10586  F95CC1  2C 57 72 6F 6E 		.DB	badlst,	'Wrong index in last block', 0			; 44
9099
               67 20 69 6E 64
9100
               65 78 20 69 6E
9101
               20 6C 61 73 74
9102
               20 62 6C 6F 63
9103
               6B 00
9104
10587  F95CDC  3C 46 69 6C 65 		.DB	filopn,	'File open', 0					; 60
9105
               20 6F 70 65 6E
9106
               00
9107
10588  F95CE7  3D 46 69 6C 65 		.DB	filnop,	'File not open', 0				; 61
9108
               20 6E 6F 74 20
9109
               6F 70 65 6E 00
9110
10589  F95CF6  3E 46 69 6C 65 		.DB	flntfd,	'File not found', 0				; 62
9111
               20 6E 6F 74 20
9112
               66 6F 75 6E 64
9113
               00
9114
10590  F95D06  3F 46 69 6C 65 		.DB	flexst,	'File exists', 0				; 63
9115
  Tue Jul 17 11:00:19 2018                                                                                               Page  148
9116
 
9117
 
9118
 
9119
 
9120
               20 65 78 69 73
9121
               74 73 00
9122
10591  F95D13  40 46 69 6C 65 		.DB	mistyp,	'File type mismatch', 0				; 64
9123
               20 74 79 70 65
9124
               20 6D 69 73 6D
9125
               61 74 63 68 00
9126
10592  F95D27  42 49 6C 6C 65 		.DB	badts,	'Illegal track or sector', 0			; 55
9127
               67 61 6C 20 74
9128
               72 61 63 6B 20
9129
               6F 72 20 73 65
9130
               63 74 6F 72 00
9131
10593  F95D40  43 49 6C 6C 65 		.DB	systs,	'Illegal system track or sector', 0		; 67
9132
               67 61 6C 20 73
9133
               79 73 74 65 6D
9134
               20 74 72 61 63
9135
               6B 20 6F 72 20
9136
               73 65 63 74 6F
9137
               72 00
9138
10594  F95D60  44 57 72 69 74 		.DB	wrfil,	'Write only file', 0				; 68
9139
               65 20 6F 6E 6C
9140
               79 20 66 69 6C
9141
               65 00
9142
10595  F95D71  45 52 65 61 64 		.DB	rdfil,	'Read only file', 0				; 69
9143
               20 6F 6E 6C 79
9144
               20 66 69 6C 65
9145
               00
9146
10596  F95D81  46 4E 6F 20 63 		.DB	nochnl,	'No channel available',0			; 70
9147
               68 61 6E 6E 65
9148
               6C 20 61 76 61
9149
               69 6C 61 62 6C
9150
               65 00
9151
10597  F95D97  47 44 69 72 65 		.DB	direrr,	'Directory error', 0				; 71
9152
               63 74 6F 72 79
9153
               20 65 72 72 6F
9154
               72 00
9155
10598  F95DA8  48 44 69 73 6B 		.DB	dskful,	'Disk full', 0					; 72
9156
               20 66 75 6C 6C
9157
               00
9158
10599  F95DB3  49 43 42 4D 20 		.DB	cbmv2,	'CBM DOS V10 1581 Emulator', 0			; 73
9159
               44 4F 53 20 56
9160
               31 30 20 31 35
9161
               38 31 20 45 6D
9162
               75 6C 61 74 6F
9163
               72 00
9164
10600  F95DCE  4A 44 72 69 76 		.DB	nodriv,	'Drive not ready', 0				; 74
9165
               65 20 6E 6F 74
9166
               20 72 65 61 64
9167
               79 00
9168
10601  F95DDF  4B 43 68 61 6E 		.DB	opnchn,	'Channel is open',0				; 75
9169
               6E 65 6C 20 69
9170
               73 20 6F 70 65
9171
               6E 00
9172
10602  F95DF0  4C 4E 6F 20 6C 		.DB	nolinx,	'No logical index available',0			; 76
9173
               6F 67 69 63 61
9174
               6C 20 69 6E 64
9175
               65 78 20 61 76
9176
               61 69 6C 61 62
9177
  Tue Jul 17 11:00:19 2018                                                                                               Page  149
9178
 
9179
 
9180
 
9181
 
9182
               6C 65 00
9183
10603  F95E0C  4D 46 6F 72 6D 		.DB	fmter,	'Format error', 0				; 77
9184
               61 74 20 65 72
9185
               72 6F 72 00
9186
10604  F95E1A  4E 49 42 4D 20 		.DB	ibmfmt,	'IBM formatted disk', 0				; 78
9187
               66 6F 72 6D 61
9188
               74 74 65 64 20
9189
               64 69 73 6B 00
9190
10605  F95E2E  4F 53 79 73 74 		.DB	syterr,	'System track read error', 0			; 79
9191
               65 6D 20 74 72
9192
               61 63 6B 20 72
9193
               65 61 64 20 65
9194
               72 72 6F 72 00
9195
10606  F95E47  50 43 6F 72 72 		.DB	dirlnk,	'Corrupted directory link', 0			; 80
9196
               75 70 74 65 64
9197
               20 64 69 72 65
9198
               63 74 6F 72 79
9199
               20 6C 69 6E 6B
9200
               00
9201
10607  F95E61  51 43 6F 72 72 		.DB	bamcnt,	'Corrupted bam', 0				; 81
9202
               75 70 74 65 64
9203
               20 62 61 6D 00
9204
10608  F95E70  52 52 65 63 75 		.DB	badcat,	'Recursive concat', 0				; 82
9205
               72 73 69 76 65
9206
               20 63 6F 6E 63
9207
               61 74 00
9208
10609  F95E82  53 49 6E 76 61 		.DB	badtlk, 'Invalid talk command', 0			; 83
9209
               6C 69 64 20 74
9210
               61 6C 6B 20 63
9211
               6F 6D 6D 61 6E
9212
               64 00
9213
10610  F95E98  54 49 6E 76 61 		.DB	badlsn, 'Invalid listen command', 0			; 84
9214
               6C 69 64 20 6C
9215
               69 73 74 65 6E
9216
               20 63 6F 6D 6D
9217
               61 6E 64 00
9218
10611  F95EB0
9219
10612  F95EB0  00            		.DB	0	; end of table
9220
10613
9221
10614  F95EB1                	uerr:
9222
10615  F95EB1  55 6E 6B 6E 6F 		.DB	'Unknow error', 0
9223
               77 20 65 72 72
9224
               6F 72 00
9225
 
9226
 
9227
             Lines Assembled : 10081                  Errors : 0
9228
 
9229
 
9230