Subversion Repositories MB01 Project

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 - 1
  Tue Jul 17 11:00:20 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\fsint.asm
13
                       Output Filename : obj\F9\fsint.obj
14
                       Listing Has Been Relocated
15
 
16
 
17
 2606                        	.LIST		on
18
 2607
19
 2608  F8FFB1                		.INCLUDE inc\dirp00.inc
20
 2609                        	;----------------------------------------------------------
21
 2610                        	; DIRP00.ASM
22
 2611                        	; PROGETTO: B1601
23
 2612                        	;
24
 2613                        	; Variabili in Direct Page $00
25
 2614                        	;----------------------------------------------------------
26
 2615
27
 2616                        	; sezione COMMON -- questo permette di includere il file in piu' file
28
 2617
29
 2618                        	.LIST on
30
 2619
31
 2620                        	DIRP00:	.SECTION page0, ref_only, common	;Direct-Page 00
32
 2621
33
 2622  000000                		.ABSOLUTE		;; inizia sempre da $00
34
 2623  000000                		.ORG		0x00
35
 2624  000000
36
 2625  000000  0000          	JiffyClk	.DW			; contatore 10ms 32 bit
37
 2626  000002  0000          			.DW
38
 2627  000004                	SysTmr		.DS	SYSTMRCNT	; system timer 0 (10ms)
39
 2628  000008                	SysTMF		.DS	SYSTMRCNT	; flag timer (80 -> start)
40
 2629  00000C  00            	Bnk0Flag	.DB			; <7>: flag test RAM banco 0 ok
41
 2630                        						; <6>: flag warm reset
42
 2631  00000D  00            	RTCFlag		.DB
43
 2632
44
 2633  00000E                	diskstat	.DS	2	; flag device on ata bus #0 & #1
45
 2634                        					; <7>: device ready
46
 2635                        					; <6>: compact flash device (C.F.)
47
 2636                        					; <5>: device identification ok
48
 2637                        					; <4>: MBR loaded
49
 2638                        					; <3>: valid signature in MBR
50
 2639                        					; <2>: first partition found&active
51
 2640                        					; <1>:
52
 2641                        					; <0>: valid partition flag
53
 2642
54
 2643                        					; <7>: device ready
55
 2644                        					; <6>: USB device
56
 2645                        					; <5>: compact flash device (C.F.)
57
 2646                        					; <4>: device identification ok
58
 2647                        					; <3>: MBR loaded
59
 2648                        					; <2>: first partition found&active
60
 2649                        					; <1>: always 1
61
 2650                        					; <0>: valid partition flag
62
 2651  000010
63
  Tue Jul 17 11:00:20 2018                                                                                               Page    2
64
 
65
 
66
 
67
 
68
 2652
69
 2653          00000E        	atadev		.EQU	diskstat
70
 2654
71
 2655  000010                	usbdev		.DS	2	; flag flash disk on usb bus #0
72
 2656                        					; <7>: device plugged and ready
73
 2657                        					; <6>: always 1
74
 2658                        					; <5>: device identification ok
75
 2659                        					; <4>: MBR loaded
76
 2660                        					; <3>: valid signature in MBR
77
 2661                        					; <2>: first partition found&active
78
 2662                        					; <1>:
79
 2663                        					; <0>: valid partition flag
80
 2664
81
 2665  000012                	diskmax		.DS	16	; disk max. sector's
82
 2666          000012        	atasec		.EQU	diskmax
83
 2667          00001A        	usbsec		.EQU	diskmax+8
84
 2668
85
 2669
86
 2670  000022                	atambr		.DS	8	; data for first partition found in mbr
87
 2671                        					; first 3 bytes for start sector of partition
88
 2672                        					; last byte for partition type
89
 2673  00002A                	usbmbr		.DS	8
90
 2674
91
 2675  000032                	ataprt		.DS	8	; total sec's of first partition
92
 2676  00003A                	usbprt		.DS	8	; total sec's of first partition
93
 2677
94
 2678
95
 2679  000042  00            	usb0ch		.DB	; usb0 (ch375/ch376) flag
96
 2680                        				; <7>: module on
97
 2681                        				; <6>: ch376 flag
98
 2682                        				; <5:0>: chip version
99
 2683
100
 2684  000043  00            	usb0st		.DB	; usb0 status
101
 2685                        				; <7>: usb0 host mode ok
102
 2686                        				; <6>: flash disk attached flag
103
 2687                        				; <5>: usb device attached
104
 2688
105
 2689  000044  00            	fdcdrv		.DB		; phisycal drive status (drive #0)
106
 2690                        					; <7>: disk format established in bit 0&1
107
 2691                        					; <6>: double step seek done
108
 2692                        					; <5>: trust format bit's (set after ok r/w)
109
 2693                        					; <4>: write protect bit (if disk in drive)
110
 2694                        					; <3>: don't care
111
 2695                        					; <2>: don't care
112
 2696                        					; <1>: HD disk if set else DD disk
113
 2697                        					; <0>: CBM format if set else IBM format
114
 2698
115
 2699  000045  00            	vdrive		.DB		; virtual drive status (ram disk, drive #1)
116
 2700                        					; <7>: disk format established in bit 0&1
117
 2701                        					; <6>: change disk simulation (after format)
118
 2702                        					; <5>: don't care
119
 2703                        					; <4>: write protect bit (under sw control)
120
 2704                        					; <3>: don't care
121
 2705                        					; <2>: don't care
122
 2706                        					; <1>: HD disk if set else DD disk
123
 2707                        					; <0>: CBM format if set else IBM format
124
 2708
125
  Tue Jul 17 11:00:20 2018                                                                                               Page    3
126
 
127
 
128
 
129
 
130
 2709  000046  00            	fdcctl		.DB		; fdc controller status
131
 2710                        					; <7>: drive is attached
132
 2711                        					; <6>: drive need recalibration (restore)
133
 2712                        					; <5>: FDC controller ok
134
 2713                        					; <4>: motor on
135
 2714                        					; <3>: dma is active
136
 2715                        					; <2>: dma chip ok (post routine)
137
 2716                        					; <1>: clock rate (1=HD,0=DD)
138
 2717                        					; <0>: disk ready
139
 2718
140
 2719  000047  00            	fdctrk		.DB		; fd: current seek track
141
 2720  000048  00            	fdcerr		.DB		; fd: last error code
142
 2721  000049  00            	ataerr		.DB		; ata: last error code
143
 2722  00004A  00            	ataxer		.DB		; ata: last extended error code
144
 2723
145
 2724  00004B  00            	CtrlBrk		.DB		; flag CTRL+BREAK (NMI)
146
 2725
147
 2726  00004C  0000          	MemTop		.DW		; top memoria RAM
148
 2727  00004E  00            			.DB		; banco top mem
149
 2728
150
 2729  00004F  00            	DflTxtIn	.DB		; device di default text input
151
 2730  000050  00            	DflTxtOut	.DB		; device di default text output
152
 2731
153
 2732  000051                	COPPtr		LP		; long pointer for COP decoding
154
 2733  000054  00            	COPIdx		.DB		; COP signature/index
155
 2734
156
 2735  000055  00            	BiosEnt		.DB		; flag accesso a bios setup
157
 2736
158
 2737                        	; variabili utilizzate da ACIA
159
 2738  000056                	spwrk		.DS	$30
160
 2739
161
 2740                        	; bios mem
162
 2741  000086  0000          	nsize		.DW	; dimensione blocco da allocare
163
 2742                        	;bsize		.DW	; dimensione vera blocco free
164
 2743  000088  0000          	splitsz		.DW	; dimensione blocco splittato
165
 2744  00008A  0000          	bfree		.DW	; puntatore blocco free
166
 2745  00008C  0000          	hdrptr		.DW	; puntatore header heap
167
 2746
168
 2747  00008E  0000          	pbrklv		.DW	; current break level of current process
169
 2748  000090  0000          	pbrkmin		.DW	; minimum breal level of current process
170
 2749  000092  0000          	pbrkmax		.DW	; maximum breal level of current process
171
 2750  000094
172
 2751                        	; bios temp. work area
173
 2752  000094                	bwrktmp		.DS	$28
174
 2753
175
 2754  0000BC  00            	coptmp		.DB	; temp. used while cop
176
 2755
177
 2756  0000BD  00            	tstser		.DB	; check ser/usb test board post
178
 2757                        				; <7>: VIA2 ok
179
 2758                        				; <6>: PICRAM ok
180
 2759                        				; <1>: UART 16C550 ok
181
 2760                        				; <0>: R65C51 ok
182
 2761
183
 2762
184
 2763                        	;crc16		.DW
185
 2764
186
 2765  0000BD                		.RELATIVE
187
  Tue Jul 17 11:00:20 2018                                                                                               Page    4
188
 
189
 
190
 
191
 
192
 2766
193
 2767                        		.ENDS
194
 2768
195
 2769          [01]          	.IFDEF		_ACIA_INC_
196
 2770                        		.INCLUDE INC\SP.INC
197
 2771          [00]          	.ENDIF
198
 2772
199
 2786                        	.LIST on
200
 2787
201
 2788          000060        	KBDBUFLEN	.EQU	96		; dimensione buffer di tastiera
202
 2789
203
 2790                        	DIRP01:	.SECTION page0, ref_only, common	;Direct-Page 01
204
 2791
205
 2792  000000                		.ABSOLUTE		;; inizia sempre da $00
206
 2793  000000                		.ORG		0x00
207
 2794
208
 2795  000000
209
 2796  000000                	KbdBuf		.DS	KBDBUFLEN	; buffer della tastiera
210
 2797  000060  00            	KbdITail	.DB			; coda buffer tastiera
211
 2798  000061  00            	KbdIHead	.DB			; testa buffer tastiera
212
 2799  000062  00            	KbdCnt		.DB			; numero bytes nel buffer
213
 2800  000063  00            	KbdShift	.DB
214
 2801  000064  00            	KbdFlag		.DB
215
 2802  000065  00            	KbdToggle	.DB
216
 2803  000066  00            	KbdSt		.DB			; status tastiera dopo reset
217
 2804  000067  00            	PS2Ctl		.DB			; flag controller PS2 keyboard
218
 2805
219
 2806  000068  00            	LCDFlag		.DB
220
 2807  000069  00            	LCDTmp		.DB
221
 2808  00006A  0000          	LCDVal		.DW
222
 2809
223
 2810  00006C  00            	VBBFlag		.DB		; flag video board
224
 2811  00006D  00            	VBBRam		.DB		; flag video RAM
225
 2812
226
 2813  00006E  00            	ScnLinTmp	.DB
227
 2814  00006F  00            	ScnChBase	.DB		; base video ram VDC
228
 2815  000070  00            	ScnAttBase	.DB		; base ram attributi VDC
229
 2816  000071  00            	ScnCursMode	.DB		; VDC cursore default
230
 2817  000072  00            	ScnSaveAttr	.DB
231
 2818  000073  00            	ScnInsert	.DB
232
 2819  000074  00            	ScnAutoIns	.DB		; bit 7 -> autoins - bit 6 -> modo input
233
 2820  000075  00            	ScnScroll	.DB
234
 2821  000076  00            	ScnMaxRow	.DB		; max. righe finestra (-1)
235
 2822  000077  00            	ScnMaxCols	.DB		; max. colonne finestra (-1)
236
 2823
237
 2824  000078                	ScnMapTabs1	.DS	10
238
 2825  000082                	ScnMapTabs2	.DS	4
239
 2826  000086
240
 2827  000086  0000          	ScnPtr		.DW		; puntatore video ram linea corrente
241
 2828  000088  00            			.DB
242
 2829
243
 2830  000089  00            	ScnFiltLen	.DB		; lunghezza set caratteri filtro
244
 2831
245
 2832  00008A  0000          	ScnAtPtr	.DW		; puntatore attributi ram linea corrente
246
 2833  00008C  00            			.DB
247
 2834
248
 2835  00008D  00            	ScnTmpx		.DB		; temporaneo: durante put char
249
  Tue Jul 17 11:00:20 2018                                                                                               Page    5
250
 
251
 
252
 
253
 
254
 2836  00008E
255
 2837  00008E  00            	ScnTop		.DB		; riga superiore finestra
256
 2838  00008F  00            	ScnLeft		.DB		; colonna sinistra finestra
257
 2839  000090  00            	ScnBottom	.DB		; riga inferiore finestra
258
 2840  000091  00            	ScnRight	.DB		; colonna destra finestra
259
 2841  000092  00            	ScnAttr		.DB		; attributo default
260
 2842  000093  00            	ScnAttr2	.DB		; attributo alternativo
261
 2843  000094  00            	ScnRow		.DB		; riga cursore
262
 2844  000095  00            	ScnCol		.DB		; colonna cursore
263
 2845  000096  00            	ScnRowStart	.DB		; riga di start input
264
 2846  000097  00            	ScnInput	.DB		; riga di fine input
265
 2847  000098  00            	ScnColStart	.DB		; colonna di start input
266
 2848  000099  00            	ScnSaveX	.DB
267
 2849  00009A  00            	ScnSaveY	.DB
268
 2850  00009B  00            	ScnTmpL		.DB
269
 2851  00009C  00            	ScnTmpH		.DB
270
 2852  00009D  00            	ScnSaveRow	.DB
271
 2853  00009E  00            	ScnSaveCol	.DB
272
 2854  00009F  00            	ScnCurChr	.DB
273
 2855  0000A0  00            	ScnLstChr	.DB
274
 2856  0000A1  00            	ScnCR		.DB
275
 2857  0000A2  0000          	ScnPrm		.DW		; puntatore long utilizzato da print imm
276
 2858  0000A4  00            			.DB		; banco puntatore ScnPrm
277
 2859  0000A5  00            	ScnMode		.DB		; flag modo schermo
278
 2860
279
 2861  0000A6                	ScnPtr1		LP
280
 2862
281
 2863  0000A9  00            	ScnDefCol	.DB		; default foreground color
282
 2864
283
 2865  0000AA                	ScnPtr2		LP
284
 2866
285
 2867  0000AD  00            	ScnDefBkgCol	.DB		; default background color
286
 2868  0000AE  00            	ScnInpRow	.DB		; modo input line: riga start input
287
 2869  0000AF  00            	ScnInpCol	.DB		; modo input line: colonna start input
288
 2870  0000B0  00            	ScnLstRow	.DB		; modo input line: riga stop input
289
 2871  0000B1  00            	ScnLstCol	.DB		; modo input line: colonna stop input
290
 2872  0000B2  00            	ScnFlag		.DB		; Bit 7: input line - Bit 6: input riga unica
291
 2873  0000B3  00            	ScnMask		.DB		; flag tasti funzione editor di linea
292
 2874  0000B4  00            	ScnFilt		.DB		; filtro tasti editor di linea
293
 2875  0000B5  00            	ScnCntrl	.DB		; flag ASCII/CONTROL
294
 2876                        	;DflTxtIn	.DB		; device di default text input
295
 2877                        	;DflTxtOut	.DB		; device di default text output
296
 2878  0000B6
297
 2879          000047        	SCNCLRLEN	.EQU	($ - ScnLinTmp - 1)
298
 2880
299
 2881                        	;SCNCLRLEN	.EQU	(DflTxtOut - ScnLinTmp)
300
 2882
301
 2883                        	; variabili monitor
302
 2884  0000B6  00            	SMAddrL		.DB	; address low/high
303
 2885  0000B7  00            	SMAddrH		.DB
304
 2886  0000B8  00            	SMAddrK		.DB	; address bank
305
 2887  0000B9  00            	SMFlag32	.DB	; flag parametro 32 bit
306
 2888  0000BA  00            	SMTmpL		.DB	; temp. low/high
307
 2889  0000BB  00            	SMTmpH		.DB
308
 2890  0000BC  00            	SMTmpK		.DB	; temp. bank
309
 2891  0000BD  00            	SMTmpKK		.DB	; high byte param. 32 bit
310
 2892  0000BE  00            	SMSizeL		.DB	; size low/high
311
  Tue Jul 17 11:00:20 2018                                                                                               Page    6
312
 
313
 
314
 
315
 
316
 2893  0000BF  00            	SMSizeH		.DB
317
 2894  0000C0  00            	SMSizeK		.DB	; size bank
318
 2895  0000C1  00            	SMXAddrL	.DB	; address low/high XM
319
 2896  0000C2  00            	SMXAddrH	.DB
320
 2897  0000C3  00            	SMXAddrK	.DB	; address bank XM
321
 2898  0000C4  00            	SMbndx		.DB	; indice input buffer
322
 2899  0000C5  00            	SMnprm		.DB	; numero parametri riga di comando
323
 2900  0000C6  00            	SMdumb		.DB
324
 2901  0000C7  00            	SMkr		.DB
325
 2902  0000C8  0000          	SMpc		.DW
326
 2903  0000CA  00            	SMsr		.DB
327
 2904  0000CB  00            	SMbr		.DB
328
 2905  0000CC  0000          	SMdp		.DW
329
 2906  0000CE  0000          	SMac		.DW
330
 2907  0000D0  0000          	SMxr		.DW
331
 2908  0000D2  0000          	SMyr		.DW
332
 2909  0000D4  0000          	SMsp		.DW
333
 2910
334
 2911  0000D6  00            	SMAuxL		.DB
335
 2912  0000D7  00            	SMAuxH		.DB
336
 2913
337
 2914  0000D8  00            	asmlong		.DB	; flag for CPU in 16 mode
338
 2915                        				; <7> -> A/M in 16 bit mode
339
 2916                        				; <6> -> X/Y in 16 bit mode
340
 2917  0000D9  00            	asmcpu		.DB	; <7> -> 8 bit family
341
 2918                        				; <6> -> 65C02 cmos version
342
 2919
343
 2920  0000DA  00            	SMctx		.DB	; context (if = $00 no quit command)
344
 2921  0000DB                	SMrsm		LP	; long pointer to resume caller context
345
 2922
346
 2923  0000DE  00            	rtcadr		.DB	; rtc internal ram address
347
 2924  0000DF  00            	rtcbnk		.DB	; RTC internal bank ram
348
 2925  0000E0  00            	cmdlin		.DB	;
349
 2926  0000E1  00            	SMesc		.DB
350
 2927
351
 2928  0000E2                	SMXTmp:		.DS	26	; 26 bytes tmp
352
 2929
353
 2930          0000E2        	SMTmp2		.EQU	SMXTmp
354
 2931          0000E4        	SMTmp3		.EQU	SMXTmp+2
355
 2932          0000E6        	SMdwTmp1	.EQU	SMXTmp+4
356
 2933          0000EA        	SMdwTmp2	.EQU	SMXTmp+8
357
 2934          0000EE        	SMFsrc		.EQU	SMXTmp+12	; source bank for flash update
358
 2935          0000EF        	SMFflag		.EQU	SMXTmp+13	; flag file for flash update
359
 2936          0000F0        	SMXPos2		.EQU	SMXTmp+14
360
 2937          0000F1        	SMYPos2		.EQU	SMXTmp+15
361
 2938          0000F2        	SMXPos3		.EQU	SMXTmp+16
362
 2939          0000F3        	SMYPos3		.EQU	SMXTmp+17
363
 2940                        	;SMAuxL		.EQU	SMXTmp+18
364
 2941                        	;SMAuxH		.EQU	SMXTmp+19
365
 2942          0000F6        	SMXPos		.EQU	SMXTmp+20
366
 2943          0000F7        	SMYPos		.EQU	SMXTmp+21
367
 2944          0000F8        	SMdwTmp3	.EQU	SMXTmp+22
368
 2945
369
 2946          0000E2        	atcmd		.EQU	SMXTmp		; save @ command
370
 2947          0000E3        	atnum		.EQU	SMXTmp+1	; @ command index
371
 2948          0000E4        	atflag		.EQU	SMXTmp+2	; @ L,S,V,R,W start address flag
372
 2949          0000E5        	atbnk		.EQU	SMXTmp+3	; @ L,S,V,R,W bank
373
  Tue Jul 17 11:00:20 2018                                                                                               Page    7
374
 
375
 
376
 
377
 
378
 2950          0000E6        	atstr		.EQU	SMXTmp+4	; @ command string start (word)
379
 2951          0000E8        	atstart		.EQU	SMXTmp+6	; @ L,S,V,R,W start address (word)
380
 2952          0000EA        	atend		.EQU	SMXTmp+8	; @ S,W end address (word)
381
 2953          0000EC        	atbuf		.EQU	SMXTmp+10	; @ local buffer pointer (word)
382
 2954          0000EE        	atipb		.EQU	SMXTmp+12	; @ bank of input buffer
383
 2955          0000EF        	atdir		.EQU	SMXTmp+13	; @ load dir flag
384
 2956          0000F0        	atptr		.EQU	SMXTmp+14	; @ load dir pointer (word)
385
 2957          0000F2        	atsiz		.EQU	SMXTmp+16	; @ buffer size (word)
386
 2958          0000F5        	atlp		.EQU	SMXTmp+19	; @ long pointer
387
 2959          0000F8        	atsa		.EQU	SMXTmp+22	; @ sa
388
 2960
389
 2961          0000E2        	btmpx		.EQU	SMXTmp		; asc2bin conversion
390
 2962          0000E3        	brtcsec		.EQU	SMXTmp+1
391
 2963          0000E4        	brtcmin		.EQU	SMXTmp+2
392
 2964          0000E5        	brtchour	.EQU	SMXTmp+3
393
 2965          0000E6        	brtcday		.EQU	SMXTmp+4
394
 2966          0000E7        	brtcmonth	.EQU	SMXTmp+5
395
 2967          0000E8        	brtcyear	.EQU	SMXTmp+6
396
 2968          0000E9        	brtcct		.EQU	SMXTmp+7
397
 2969
398
 2970
399
 2971  0000FC                		.RELATIVE
400
 2972
401
 2973                        		.ENDS
402
 2974
403
 2998                        	.LIST on
404
 2999
405
 3000                        	;---------------------------------------------------------------------------
406
 3001
407
 3002          000020        	HPLMAX		.EQU	32		; Max. subdirectory level
408
 3003
409
 3004          000200        	BCBCNT		.EQU	$200		; BCB's struct's count #
410
 3005          000C00        	BCBXBNK		.EQU	$0C00		; starting BCB x-mem buffer #
411
 3006          000040        	DMACNT		.EQU	64
412
 3007
413
 3008          0000E0        	FAT0X		.EQU	$E0		; x-mem bank for fat table of ata #0
414
 3009          0000F0        	FAT1X		.EQU	$F0		; x-mem bank for fat table of ata #1
415
 3010
416
 3011  F8FFB1                		.INCLUDE INC\LDT.INC
417
 3012                        	; LDT.INC
418
 3013
419
 3014          [01]          	.IFNDEF		__LDT_INC__
420
 3015          000001        	__LDT_INC__	.SET	1
421
 3016
422
 3017                        	.LIST on
423
 3018                        	;---------------------------------------------------------------------------
424
 3019                        	; Logical Drive Table (LDT) -- page 0 offset's
425
 3020                        	;---------------------------------------------------------------------------
426
 3021
427
 3022  F8FFB1                	 STRUCT		LDT
428
 3023                        	_LDT	.SECTION page0,common,ref_only,offset 0	;LDT Struct
429
 3024                        			;.ABSOLUTE
430
 3025                        			;.ORG	0
431
 3026                        		.MNLIST
432
 3027  000000  00            	ldt_fg1		.DB		; logical volume flag's
433
 3028                        					; <7>: device ready (fdc drive or ata device)
434
 3029                        					; <6>: if=1->HD/CF else->FD
435
  Tue Jul 17 11:00:20 2018                                                                                               Page    8
436
 
437
 
438
 
439
 
440
 3030                        					; <1:0>: phisycal device number
441
 3031
442
 3032  000001  00            	ldt_fg2		.DB		; <7>: valid volume (fat volume or cbm disk)
443
 3033                        					; <6>: if=1->FAT else->CBM (FD only)
444
 3034                        					; <5>: disk format checked
445
 3035                        					; <1:0>: disk format (fdc only)
446
 3036
447
 3037  000002  0000          	ldt_root	.DW		; lba of root dir
448
 3038  000004  0000          	ldt_fat1	.DW		; lba of fat1 table
449
 3039  000006  0000          	ldt_fat2	.DW		; lba of fat2 table
450
 3040  000008  0000          	ldt_cls		.DW		; lba of first data cluster
451
 3041  00000A  0000          	ldt_max		.DW		; max usable cluster + 1
452
 3042  00000C  0000          	ldt_rent	.DW		; root dir. max. entries
453
 3043  00000E  0000          	ldt_cent	.DW		; max. entries in dir. cluster
454
 3044  000010  0000          	ldt_eoc		.DW		; end of cluster chain marker
455
 3045  000012  0000          	ldt_free	.DW		; count of free cluster's
456
 3046  000014  0000          	ldt_nxt		.DW		; next free cluster
457
 3047  000016  0000          	ldt_fsiz	.DW		; fat table size
458
 3048
459
 3049  000018  00            	ldt_csiz	.DB		; cluster size (1,2,4,8,16,32,64)
460
 3050  000019  00            	ldt_cshf	.DB		; cluster shift (0,1,2,3,4,5,6)
461
 3051  00001A  00            	ldt_rsiz	.DB		; root dir. size (sector's)
462
 3052  00001B  00            	ldt_mcls	.DB		; mask for clust. module: 00,01,03,07,0F,1F,3F
463
 3053  00001C  0000          	ldt_cdlp	.DW		; current working dir list pointer
464
 3054  00001E  0000          	ldt_cdcls	.DW		; current working dir start cluster
465
 3055  000020  00            	ldt_cdlvl	.DB		; current working dir level count
466
 3056
467
 3057  000021  00            	ldt_ptype	.DB
468
 3058  000022  0000 0000     	ldt_pstart	.LWORD
469
 3059  000026  0000 0000     	ldt_psize	.LWORD
470
 3060
471
 3061          000022        	ldt_fp		.EQU	ldt_pstart	; fat table buffer long pointer
472
 3062          000025        	ldt_fbuf	.EQU	ldt_pstart+3		; fat table: x-mem base bank/dma buffer
473
 3063
474
 3064          000026        	ldt_pbr		.EQU	ldt_psize		; long pointer to PBR cache buffer
475
 3065          000029        	ldt_fmt		.EQU	ldt_psize+3
476
 3066
477
 3067  00002A                	 ESTRUCT	LDT
478
 3068  00002A                	LDTSIZE	.DS	0
479
 3069                        			;.RELATIVE
480
 3070                        			.ENDS
481
 3071                        		.MNLIST
482
 3072
483
 3073          [00]          	.ENDIF
484
 3074
485
 3075  F8FFB1
486
 3076                        	;---------------------------------------------------------------------------
487
 3077                        	; Hierarchical Path List (HPL) -- 16 bit offset's
488
 3078                        	;---------------------------------------------------------------------------
489
 3079
490
 3080  F8FFB1                	 LSTRUCT	HPL
491
 3081                        	_HPL	.SECTION common,ref_only,offset 0	;HPL Struct
492
 3082                        		.MNLIST
493
 3083  000000  0000          	hpl_cls		.DW		; parent cluster
494
 3084  000002  0000          	hpl_ix		.DW		; entry index in parent cluster
495
 3085  000004                	hpl_fcb		.DS	11	; fcb name
496
 3086  00000F  00            	hpl_lst		.DB		; unused
497
  Tue Jul 17 11:00:20 2018                                                                                               Page    9
498
 
499
 
500
 
501
 
502
 3087  000010                	 ESTRUCT	HPL
503
 3088  000010                	HPLSIZE	.DS	0
504
 3089                        			;.RELATIVE
505
 3090                        			.ENDS
506
 3091                        		.MNLIST
507
 3092
508
 3093                        	;---------------------------------------------------------------------------
509
 3094                        	; Buffer Control Block (BCB) -- 16 bit offset's
510
 3095                        	;---------------------------------------------------------------------------
511
 3096
512
 3097  F8FFB1                	 LSTRUCT	BCB
513
 3098                        	_BCB	.SECTION common,ref_only,offset 0	;BCB Struct
514
 3099                        		.MNLIST
515
 3100  000000  0000          	bcb_next	.DW			; next logical linked BCB
516
 3101  000002  00            	bcb_drv		.DB			; logical drive
517
 3102  000003  00            	bcb_sec		.DB			; sector offset
518
 3103  000004  0000          	bcb_cls		.DW			; cluster
519
 3104  000006  0000          	bcb_lba		.DW			; sector lba address
520
 3105  000008  0000          	bcb_lbah	.DW			; lba high
521
 3106          000008        	bcb_head	.EQU	bcb_lbah	; floppy head
522
 3107  00000A  0000          	bcb_buf		.DW			; x-mem buffer number
523
 3108          00000A        	bcb_trk		.EQU	bcb_buf		; floppy track(low) & sector(hi)
524
 3109  00000C  0000          	bcb_ptr		.DW			; buffer pointer
525
 3110  00000E  0000          	bcb_xbnk	.DW			; buffer pointer hi & x-mem bank
526
 3111          00000E        	bcb_dma		.EQU	bcb_xbnk	; buffer pointer hi & dma buffer
527
 3112  000010                	 ESTRUCT	BCB
528
 3113  000010                	BCBSIZE	.DS	0
529
 3114                        			;.RELATIVE
530
 3115                        			.ENDS
531
 3116                        		.MNLIST
532
 3117
533
 3118                        	;---------------------------------------------------------------------------
534
 3119                        	; hash Control Block (BCB) -- 16 bit offset's
535
 3120                        	;---------------------------------------------------------------------------
536
 3121
537
 3122  F8FFB1                	 LSTRUCT	HCB
538
 3123                        	_HCB	.SECTION common,ref_only,offset 0	;HCB Struct
539
 3124                        		.MNLIST
540
 3125  000000  0000          	hcb_next	.DW		; pointer to next HCB
541
 3126  000002  0000          	hcb_cls		.DW		; cluster number
542
 3127  000004  0000          	hcb_seq		.DW		; sequence number + logical drive number
543
 3128  000006  0000          	hcb_cnt		.DW		; number of hashed entries
544
 3129  000008                	hcb_data	.DS	0	; hash buffer data
545
 3130  000008                	 ESTRUCT	HCB
546
 3131  000008                	HCBSIZE	.DS	0
547
 3132                        			;.RELATIVE
548
 3133                        			.ENDS
549
 3134                        		.MNLIST
550
 3135
551
 3136                        	;---------------------------------------------------------------------------
552
 3137                        	; TOS Working Segment
553
 3138                        	;---------------------------------------------------------------------------
554
 3139
555
 3140          000001        	WKB		.EQU	.SEG.TOSSEG	; TOS working bank
556
 3141
557
 3142          010000        	TS		.SET	TOSSEG
558
 3143          01FFFF        	TE		.SET	TOSSEG + $FFFF
559
  Tue Jul 17 11:00:20 2018                                                                                               Page   10
560
 
561
 
562
 
563
 
564
 3144          018C00        	TO0		.SET	$018C00
565
 3145          019E00        	TO1		.SET	TOSWKM
566
 3146
567
 3147                        	.comment @
568
 3148                        	_TOS0:	.SECTION ref_only, common, offset TO0, range TS TE ;FAT Struct's
569
 3149                        	_TOS0_START	.DS	0
570
 3150
571
 3151                        	_pbr0		.DS	512
572
 3152                        	_pbr1		.DS	512
573
 3153                        	_pbr2		.DS	512
574
 3154                        	_pbr3		.DS	512
575
 3155
576
 3156                        	_TOS0_END	.DS	0
577
 3157                        	TOS0SIZ		.EQU	(_TOS0_END - _TOS0_START)
578
 3158                        	.ENDS
579
 3159                        	@
580
 3160
581
 3161                        	_TOS1:	.SECTION ref_only, common, offset TO1, range TS TE ;FAT Struct's
582
 3162  019E00                	_TOS1_START	.DS	0
583
 3163
584
 3164                        	; current working directory HPL
585
 3165  019E00                	cwdl0		.DS	(HPLSIZE*HPLMAX)
586
 3166  01A000                	cwdl1		.DS	(HPLSIZE*HPLMAX)
587
 3167  01A200                	cwdl2		.DS	(HPLSIZE*HPLMAX)
588
 3168  01A400                	cwdl3		.DS	(HPLSIZE*HPLMAX)
589
 3169
590
 3170                        	; current building path HPL
591
 3171  01A600                	cbpl		.DS	(HPLSIZE*HPLMAX)
592
 3172          01A600        	HPL_CLS		.EQU	hpl_cls+cbpl
593
 3173          01A602        	HPL_IX		.EQU	hpl_ix+cbpl
594
 3174          01A604        	HPL_FCB		.EQU	hpl_fcb+cbpl
595
 3175
596
 3176                        	; BCB list's
597
 3177  01A800                	bcbstart	.DS	(BCBCNT*BCBSIZE)
598
 3178  01C800                	bcbend		.DS	0
599
 3179  01C800                	dmastart	.DS	(DMACNT*BCBSIZE)
600
 3180  01CC00                	dmaend		.DS	0
601
 3181  01CC00                	dma0s		.DS	(17*BCBSIZE)
602
 3182  01CD10                	dma1s		.DS	(17*BCBSIZE)
603
 3183
604
 3184  01CE20                	_TOS1_END	.DS	0
605
 3185          003020        	TOS1SIZ		.EQU	(_TOS1_END - _TOS1_START)
606
 3186                        	.ENDS
607
 3187
608
 3188                        	;---------------------------------------------------------------------------
609
 3189                        	; HCB Segment
610
 3190                        	;---------------------------------------------------------------------------
611
 3191
612
 3192          000004        	HCBBNK		.EQU	.SEG.HCBSEG
613
 3193          040000        	HS		.SET	HCBSEG
614
 3194          04FFFF        	HE		.SET	HCBSEG + $FFFF
615
 3195          040000        	HO		.SET	HCBSEG
616
 3196
617
 3197                        	_HCBS:	.SECTION ref_only, common, offset HO, range HS HE	;HCB's List
618
 3198  040000                	hcb_bnk		.DS	8
619
 3199  040008                	hcbstart	.DS	0
620
 3200                        	.ENDS
621
  Tue Jul 17 11:00:20 2018                                                                                               Page   11
622
 
623
 
624
 
625
 
626
 3201
627
 3202                        	;.comment @
628
 3203                        	;---------------------------------------------------------------------------
629
 3204                        	; direct page for LDT var's
630
 3205                        	;---------------------------------------------------------------------------
631
 3206
632
 3207                        	; P0OS
633
 3208                        	DPOS:	.SECTION page0, common, ref_only, offset 0	;OS Main D.P.
634
 3209
635
 3210                        	;sysbuf		.DS	2	; floppy track 0 cache buffer
636
 3211  000000  00            	defhsec		.DB		; default hidden sector's in fdisk
637
 3212  000001  00            			.DB
638
 3213  000002  0000          	cmdstk		.DW		; saved stack on TOS command's
639
 3214  000004                	bpath		.DS	80
640
 3215
641
 3216  000054                	bpath1		.DS	0
642
 3217                        	.ENDS
643
 3218                        	;@
644
 3219
645
 3220                        	; P0LDT
646
 3221                        	DPLDT:	.SECTION page0, common, ref_only, offset 0	;LDT D.P.
647
 3222
648
 3223  000000                	ldt0		.DS	LDTSIZE
649
 3224  00002A                	ldt1		.DS	LDTSIZE
650
 3225  000054                	ldt2		.DS	LDTSIZE
651
 3226  00007E                	ldt3		.DS	LDTSIZE
652
 3227  0000A8                	ldt4		.DS	LDTSIZE
653
 3228
654
 3229  0000D2                	ldtp		.DS	6	; pointer to LDT's in DPLDT page
655
 3230
656
 3231  0000D8                	sysbuf		.DS	4	; floppy track 0 cache buffer
657
 3232
658
 3233                        	.ENDS
659
 3234
660
 3235                        	;---------------------------------------------------------------------------
661
 3236                        	; direct page for FAT var's
662
 3237                        	;---------------------------------------------------------------------------
663
 3238
664
 3239                        	; P0FAT
665
 3240                        	DPFAT:	.SECTION page0, common, ref_only, offset 0	;FAT D.P.
666
 3241
667
 3242  000000  0000          	ostos		.DW		; saved top of stack
668
 3243  000002  00            	ioerr		.DB		; i/o error
669
 3244  000003  00            	ioerr2		.DB		; extended i/o error
670
 3245  000004  0000          	hcbroot		.DW		; HCB struct's list
671
 3246  000006  0000          	hcblst		.DW		; the last one HCB
672
 3247  000008  00            	hsiz		.DB		; how many sector's an HCB can hold
673
 3248  000009  00            	hlog2		.DB		; shift count related to hsiz
674
 3249  00000A  0000          	bcbroot		.DW		; BCB buffer's list
675
 3250  00000C  0000          	bcblst		.DW		; the last one BCB
676
 3251  00000E  0000          	dmaroot		.DW		; dma BCB buffer's list
677
 3252  000010  0000          	dmalst		.DW		; the last one dma BCB
678
 3253  000012  0000          	dmabcb		.DW		; BCB list for floppy root, cluster#2,#3&#4
679
 3254  000014  00            	fspt		.DB		; sector per track (floppy)
680
 3255  000015  00            	pdrive		.DB		; phisycal drive number
681
 3256  000016  00            	bplvl		.DB		; subdir level while build path
682
 3257  000017  00            	defdrv		.DB		; default drive
683
  Tue Jul 17 11:00:20 2018                                                                                               Page   12
684
 
685
 
686
 
687
 
688
 3258
689
 3259                        	; the first block of ldt_ var's is copied from the LDT struct
690
 3260  000018  00            	ldtfg1		.DB		; logical volume flag's
691
 3261                        					; <7>: device ready (fdc drive or ata device)
692
 3262                        					; <6>: if=1->HD/CF else->FD
693
 3263                        					; <0>: phisycal device number
694
 3264
695
 3265  000019  00            	ldtfg2		.DB		; <7>: valid volume (fat volume or cbm disk)
696
 3266                        					; <6>: if=1->FAT else->CBM (FD only)
697
 3267                        					; <5>: disk format checked
698
 3268                        					; <1:0>: disk format (fdc only)
699
 3269
700
 3270  00001A                	ldtfp		LP		; fat table buffer long pointer
701
 3271  00001D  00            	ldtfbuf		.DB		; fat table: x-mem base bank/dma buffer
702
 3272
703
 3273  00001E  0000          	ldtroot		.DW		; lba of root dir
704
 3274  000020  0000          	ldtfat1		.DW		; lba of fat1 table
705
 3275  000022  0000          	ldtfat2		.DW		; lba of fat2 table
706
 3276  000024  0000          	ldtcls		.DW		; lba of first data cluster
707
 3277  000026  0000          	ldtmax		.DW		; max usable cluster + 1
708
 3278  000028  00            	ldtcsiz		.DB		; cluster size (1,2,4,8,16,32,64)
709
 3279  000029  00            	ldtcshf		.DB		; cluster shift (0,1,2,3,4,5,6)
710
 3280  00002A  00            	ldtfsiz		.DB		; fat table size (if 0 -> 256)
711
 3281  00002B  00            	ldtrsiz		.DB		; root dir. size (sector's)
712
 3282  00002C  0000          	ldtrent		.DW		; root dir. max. entries
713
 3283  00002E  0000          	ldtcent		.DW		; max. entries in dir. cluster
714
 3284  000030  0000          	ldteoc		.DW		; end of cluster chain marker
715
 3285  000032  00            	ldtmcls		.DB		; mask for clust. module: 00,01,03,07,0F,1F,3F
716
 3286  000033  00            	ldtfmt		.DB		; floppy disk format (0,1,2, FF if ata device)
717
 3287  000034  0000          	ldtcdlp		.DW		; current working dir list pointer
718
 3288  000036  0000          	ldtcdcls	.DW		; current working dir start cluster
719
 3289  000038  0000          	ldtfree		.DW		; count of free cluster's
720
 3290  00003A  0000          	ldtnxt		.DW		; next free cluster
721
 3291  00003C  00            	ldtcdlvl	.DB		; current working dir level count
722
 3292  00003D                	ldtpbr		LP		; long pointer to PBR cache buffer
723
 3293
724
 3294  000040  0000          	chdcls		.DW		; last accessed chained dir. cluster
725
 3295  000042  0000          	clsofs		.DW		; cluster's offset from start of chain
726
 3296
727
 3297                        	; not change order of the 2 following var's: will be accessed as 16 bit var
728
 3298  000044  00            	entofs		.DB		; entry offset from start of sector
729
 3299  000045  00            	secofs		.DB		; sector's offset from start of cluster
730
 3300
731
 3301  000046  0000          	dircls		.DW		; directory cluster
732
 3302  000048  0000          	dcnt		.DW		; directory entry counter
733
 3303  00004A  0000          	lba		.DW		; lba sector address
734
 3304  00004C  0000          	lbah		.DW		; lba is 24 bit's only
735
 3305  00004E  0000          	xbuf		.DW		; x-mem buffer transfer number
736
 3306
737
 3307          00004C        	fhead		.EQU	lbah	; fd head
738
 3308          00004E        	ftrack		.EQU	xbuf	; fd track
739
 3309          00004F        	fsec		.EQU	xbuf+1	; fd sector
740
 3310
741
 3311  000050  00            	dfcbtyp		.DB		; FCB type to search
742
 3312  000051  00            	dfcbatt		.DB		; attribute of found FCB
743
 3313
744
 3314  000052  00            	curdrv		.DB		; current logical drive
745
  Tue Jul 17 11:00:20 2018                                                                                               Page   13
746
 
747
 
748
 
749
 
750
 3315  000053                	fcbs		.DS	11	; file control block name
751
 3316
752
 3317                        	;dcmask		.DW		; mask to start of cluster
753
 3318                        					; FFF0, FFE0, FFC0, FF80, FF00, FE00
754
 3319
755
 3320  00005E  0000          	fcbp		.DW		; FCB buffer long pointer
756
 3321  000060  0000          			.DW		; low=fcbp+2, high=x-mem bank or dma buffer
757
 3322          000061        	dmabuf		.EQU	fcbp+3	; dma buffer #
758
 3323          000061        	xmbank		.EQU	fcbp+3	; x-mem bank #
759
 3324
760
 3325                        	; temp area
761
 3326  000062  00            	hcbseq		.DB
762
 3327  000063  00            	hcbdrv		.DB
763
 3328  000064  0000          	bcbcls		.DW
764
 3329  000066  00            	bcbdrv		.DB
765
 3330  000067  00            	bcbsec		.DB
766
 3331
767
 3332  000068  0000          	thash		.DW
768
 3333          000068        	hcbrec	.EQU	thash
769
 3334          000068        	wtmp	.EQU	thash
770
 3335
771
 3336  00006A  0000          	hlast		.DW
772
 3337  00006C  0000          	hcbcls		.DW
773
 3338  00006E  0000          	hcbx		.DW
774
 3339  000070  0000          	hcby		.DW
775
 3340          00006A        	tmpp	.EQU	hlast	; temp. long pointer
776
 3341          00006E        	tmpx	.EQU	hcbx
777
 3342          00006F        	wild	.EQU	hcbx+1
778
 3343          000070        	fsiz	.EQU	hcby
779
 3344          000071        	fptr	.EQU	hcby+1
780
 3345          00006E        	ldrv	.EQU	hcbx
781
 3346          00006F        	tmpldt	.EQU	hcbx+1
782
 3347
783
 3348  000072  0000          	fhash		.DW
784
 3349  000074  0000          	fcbofs		.DW
785
 3350  000076  00            	bcbload		.DB
786
 3351  000077  00            	xstart		.DB
787
 3352  000078  00            	xend		.DB
788
 3353  000079  00            	seccnt		.DB
789
 3354  00007A  00            	maxseq		.DB
790
 3355  00007B  00            	dsiz		.DB
791
 3356
792
 3357  00007C  00            	haswld		.DB
793
 3358  00007D  00            	strix		.DB
794
 3359  00007E                	pathp		LP		; long pointer to path string
795
 3360
796
 3361                        	; TEMP
797
 3362  000081  0000          	quot		.DW
798
 3363  000083  0000          	dvsor		.DW
799
 3364  000085  0000          	troot		.DW
800
 3365  000087  0000          	tlst		.DW
801
 3366  000089  0000          	bdmask		.DW
802
 3367  00008B  0000          	bcmask		.DW
803
 3368
804
 3369  00008D  00            	hcbuse		.DB
805
 3370
806
 3371                        	.ENDS
807
  Tue Jul 17 11:00:20 2018                                                                                               Page   14
808
 
809
 
810
 
811
 
812
 3372
813
 3377                        	.LIST on
814
 3378
815
 3379                        	; P0OS
816
 3380                        	; page 0 (LDT var's) local var's
817
 3381                        	_FSTMP:	.SECTION page0, ref_only, offset bpath
818
 3382          000004        	FSTMP_START	.EQU	$
819
 3383
820
 3384  000004  0000 0000     	maxsec		.LWORD		; ata device max sector's
821
 3385  000008  0000 0000     	hidsec		.LWORD		; hidden sectors
822
 3386  00000C  0000 0000     	totsec		.LWORD		; partition size in sector's
823
 3387  000010  0000          	maxcnt		.DW		; max. cluster's count
824
 3388  000012  0000          	first		.DW		; relative first data sector
825
 3389
826
 3390          000012        	totrsv		.EQU	first
827
 3391          000004        	bcbbnk		.EQU	maxsec
828
 3392          000006        	hcbsiz		.EQU	maxsec+2
829
 3393          000010        	hcbrem		.EQU	maxcnt
830
 3394          000004        	tbdrv		.EQU	maxsec
831
 3395          000006        	tbcls		.EQU	maxsec+2
832
 3396          000008        	tblba		.EQU	hidsec
833
 3397          00000A        	tbhead		.EQU	hidsec+2
834
 3398          00000C        	tbtrk		.EQU	totsec
835
 3399          00000E        	tbptr		.EQU	totsec+2
836
 3400          000010        	tbdma		.EQU	maxcnt
837
 3401          000004        	fdopt		.EQU	maxsec
838
 3402          000005        	fdarg		.EQU	maxsec+1
839
 3403          000006        	fdlbl		.EQU	maxsec+2
840
 3404
841
 3405  000014  0000          	clscnt		.DW		; cluster's count #
842
 3406  000016  0000          	rsvsec		.DW		; reserved sector's
843
 3407  000018  0000          	fatsiz		.DW		; FAT16 fat table size
844
 3408  00001A  0000          	rootsiz		.DW		; root directory size
845
 3409  00001C  0000          	rootent		.DW		; root dir. max. entries
846
 3410  00001E  0000          	clsent		.DW		; sub-diectory max. entries
847
 3411  000020  0000          	root		.DW		; root dir start
848
 3412  000022  0000          	fat1		.DW		; fat1 table start
849
 3413  000024  0000          	fat2		.DW		; fat 2 table start
850
 3414  000026  0000          	start		.DW		; first data sector
851
 3415  000028  0000          	maxcls		.DW		; last usable cluster+1
852
 3416  00002A  0000          	xfatb		.DW		; x-mem fat table buffer
853
 3417
854
 3418          00002A        	fdix		.EQU	xfatb	; floppy disk index DD/HD
855
 3419          00002B        	media		.EQU	xfatb+1	; floppy disk media field
856
 3420
857
 3421  00002C  0000          	flba		.DW		; low 16 bit lba
858
 3422  00002E  0000          	freecnt		.DW		; free cluster's count
859
 3423  000030  0000          	freecls		.DW		; first free cluster
860
 3424
861
 3425          00002E        	remsec		.EQU	freecnt
862
 3426
863
 3427  000032                	pbrp		LP		; PBR pointer
864
 3428  000035  00            	clssiz		.DB		; cluster size
865
 3429  000036  00            	clsshf		.DB		; cluster shift
866
 3430  000037  00            	clsmod		.DB
867
 3431  000038  00            	xbnk		.DB		; x-mem bank
868
 3432  000039  00            	lunit		.DB		; unity letter
869
  Tue Jul 17 11:00:20 2018                                                                                               Page   15
870
 
871
 
872
 
873
 
874
 3433  00003A                	tp		LP		; fat cache pointer
875
 3434  00003D  00            	fdfmt		.DB		; floppy format
876
 3435  00003E  00            	pdev		.DB		; phisycal device
877
 3436  00003F  00            	ldev		.DB		; logical device
878
 3437  000040  00            	ldtcur		.DB		; current LDT ptr
879
 3438  000041  00            	lflag		.DB		; flag load fat table
880
 3439  000042  00            	rtcsec		.DB		; seconds
881
 3440  000043  00            	rtcmin		.DB		; minutes
882
 3441
883
 3442          000042        	badcls		.EQU	rtcsec
884
 3443
885
 3444  000044  00            	rtchour		.DB		; hours
886
 3445  000045  00            	rtcday		.DB		; day of month
887
 3446  000046  00            	rtcmonth	.DB		; month
888
 3447  000047  00            	rtcyear		.DB		; year
889
 3448  000048  0000          	ctime		.DW		; compact time
890
 3449  00004A  0000          	cdate		.DW
891
 3450  00004C                	tlp		LP
892
 3451  00004F  00            	fd2ix		.DB
893
 3452
894
 3453          00004F        	nulptr		.EQU	fd2ix	; flag null ptr
895
 3454
896
 3455  000050  00            	rootbnk		.DB
897
 3456
898
 3457          000050        	getfmt		.EQU	rootbnk	; get format from floppy disk
899
 3458
900
 3459  000051  00            	fatbnk		.DB
901
 3460  000052  00            	clsbnk		.DB
902
 3461  000053  00            	sec100		.DB		; tenths of seconds for ctime (ms stamp)
903
 3462
904
 3463          000050        	FSTMP_SIZ	.EQU	($-FSTMP_START)
905
 3464                        		.ENDS
906
 3468                        	.LIST on
907
 3469                        		.GLOBAL ldt4
908
 3470
909
 3471                        	; default hidden sectors
910
 3472          00003F        	HIDSEC		.EQU	$3F
911
 3473                        	; default hashed sector's
912
 3474          000001        	DEFHSIZ		.EQU	1
913
 3475          000000        	DEFHLOG2	.EQU	0
914
 3476
915
 3477                        	; max. clusters count + 1
916
 3478          00FFF5        	MAXF16		.EQU	$FFF5
917
 3479          000FF5        	MAXF12		.EQU	$0FF5
918
 3480                        	; End-of-Chain marker (EOC marker)
919
 3481          00FFF8        	F16EOC		.EQU	$FFF8
920
 3482          000FF8        	F12EOC		.EQU	$0FF8
921
 3483  F8FFB1
922
 3484                        	;---------------------------------------------------------------------------
923
 3485                        	; code segment -- bank $F9
924
 3486                        	;---------------------------------------------------------------------------
925
 3487
926
 3488                        		.CODEF9
927
 3489                        		.PUBLIC fssetup, gctime16, bldldt, lhdfmt, shpart, lfdisk
928
 3490                        		.EXTERN cbmfs_cmd
929
 3491
930
 3492                        		.LONGA	off
931
  Tue Jul 17 11:00:20 2018                                                                                               Page   16
932
 
933
 
934
 
935
 
936
 3493                        		.LONGI	off
937
 3494
938
 3495                        	;---------------------------------------------------------------------------
939
 3496                        	; setup
940
 3497                        	;---------------------------------------------------------------------------
941
 3498
942
 3499  F90305                	lusbldt:
943
 3500                        		.PUBLIC lusbldt
944
 3501
945
 3502  F90305  8B            		phb
946
 3503  F90306  A9 00         		lda	#0
947
 3504  F90308  48            		pha
948
 3505  F90309  AB            		plb
949
 3506  F9030A  0B            		phd
950
 3507  F9030B  F4 00 40      		pea	#P0LDT
951
 3508  F9030E  2B            		pld			; set dp page
952
 3509  F9030F  20 15 03      		jsr	usbldt
953
 3510  F90312  2B            		pld
954
 3511  F90313  AB            		plb
955
 3512  F90314  6B            		rtl
956
 3513  F90315
957
 3514                        	; LDT for usb #0 device (E)
958
 3515  F90315                	usbldt:
959
 3516  F90315  0B            		phd
960
 3517  F90316  F4 00 42      		pea	#P0OS
961
 3518  F90319  2B            		pld
962
 3519  F9031A  A2 29         		ldx	#LDTSIZE-1
963
 3520  F9031C  74 A8         	?zm:	stz	ldt4,x
964
 3521  F9031E  CA            		dex
965
 3522  F9031F  10 FB         		bpl	?zm
966
 3523  F90321  AD 10 00      		lda	!usbdev		; phisycal usb #0 device
967
 3524  F90324  29 C0         		and	#$C0
968
 3525  F90326  09 02         		ora	#$02		; phisycal drive #2
969
 3526  F90328  8D A8 40      		sta	!P0LDT+ldt4+ldt_fg1
970
 3527  F9032B  A9 00         		lda	#<PBR0USB	; set PBR pointer
971
 3528  F9032D  8D CE 40      		sta	!P0LDT+ldt4+ldt_pbr
972
 3529  F90330  A9 96         		lda	#>PBR0USB
973
 3530  F90332  8D CF 40      		sta	!P0LDT+ldt4+ldt_pbr+1
974
 3531  F90335  A9 01         		lda	#^PBR0USB
975
 3532  F90337  8D D0 40      		sta	!P0LDT+ldt4+ldt_pbr+2
976
 3533  F9033A  A9 FF         		lda	#$FF
977
 3534  F9033C  8D D1 40      		sta	!P0LDT+ldt4+ldt_fmt
978
 3535  F9033F                		ACC16
979
 3536  F9033F  C2 20         		rep	#PMFLAG
980
 3537                        		.LONGA	on
981
 3538                        		.MNLIST
982
 3539  F90341  A9 F8 FF      		lda	#F16EOC
983
 3540  F90344  8D B8 40      		sta	!P0LDT+ldt4+ldt_eoc	; FAT16 end of chain marker
984
 3541  F90347                		ACC08
985
 3542  F90347  E2 20         		sep	#PMFLAG
986
 3543                        		.LONGA	off
987
 3544                        		.MNLIST
988
 3545  F90349  2B            		pld
989
 3546  F9034A  A9 45         		lda	#'E'		; usb #0 device: 'E'
990
 3547  F9034C  85 39         		sta	lunit		; logical drive letter
991
 3548  F9034E                		SCNPRINT
992
 3549  F9034E  02 01         		cop	$01
993
  Tue Jul 17 11:00:20 2018                                                                                               Page   17
994
 
995
 
996
 
997
 
998
 3550                        		.MNLIST
999
 3551  F90350  63 68 65 63 6B 		.DB	'check <E>: ', 0
1000
               20 3C 45 3E 3A
1001
               20 00
1002
 3552  F9035C  AD 10 00      		lda	!usbdev
1003
 3553  F9035F  C9 FF         		cmp	#$FF
1004
 3554  F90361  F0 31         		beq	?ok
1005
 3555  F90363
1006
 3556  F90363                		SCNPRINT
1007
 3557  F90363  02 01         		cop	$01
1008
 3558                        		.MNLIST
1009
 3559  F90365  75 6E 70 61 72 		.DB	'unpartitioned disk or invalid partition ID.', 13, 0
1010
               74 69 74 69 6F
1011
               6E 65 64 20 64
1012
               69 73 6B 20 6F
1013
               72 20 69 6E 76
1014
               61 6C 69 64 20
1015
               70 61 72 74 69
1016
               74 69 6F 6E 20
1017
               49 44 2E 0D 00
1018
 3560  F90392  38            		sec
1019
 3561  F90393  60            		rts
1020
 3562
1021
 3563  F90394  20 3C 0B      	?ok:	jsr	usbchk16	; check partition PBR
1022
 3564  F90397  90 29         		bcc	?ok1
1023
 3565  F90399
1024
 3566  F90399                	?inv:	SCNPRINT
1025
 3567  F90399  02 01         		cop	$01
1026
 3568                        		.MNLIST
1027
 3569  F9039B  69 6E 76 61 6C 		.DB	'invalid partition type (not FAT16).', 13, 0
1028
               69 64 20 70 61
1029
               72 74 69 74 69
1030
               6F 6E 20 74 79
1031
               70 65 20 28 6E
1032
               6F 74 20 46 41
1033
               54 31 36 29 2E
1034
               0D 00
1035
 3570  F903C0  38            		sec
1036
 3571  F903C1  60            		rts
1037
 3572  F903C2
1038
 3573  F903C2  20 18 0D      	?ok1:	jsr	fcalc		; fat data calc
1039
 3574  F903C5  B0 D2         		bcs	?inv		; invalid partition
1040
 3575  F903C7
1041
 3576  F903C7                		ACC16			; move LDT
1042
 3577  F903C7  C2 20         		rep	#PMFLAG
1043
 3578                        		.LONGA	on
1044
 3579                        		.MNLIST
1045
 3580  F903C9  A5 20         		lda	root
1046
 3581  F903CB  8D AA 40      		sta	!P0LDT+ldt4+ldt_root
1047
 3582  F903CE  A5 22         		lda	fat1
1048
 3583  F903D0  8D AC 40      		sta	!P0LDT+ldt4+ldt_fat1
1049
 3584  F903D3  A5 24         		lda	fat2
1050
 3585  F903D5  8D AE 40      		sta	!P0LDT+ldt4+ldt_fat2
1051
 3586  F903D8  A5 26         		lda	start
1052
 3587  F903DA  8D B0 40      		sta	!P0LDT+ldt4+ldt_cls
1053
 3588  F903DD  A5 28         		lda	maxcls
1054
 3589  F903DF  8D B2 40      		sta	!P0LDT+ldt4+ldt_max
1055
  Tue Jul 17 11:00:20 2018                                                                                               Page   18
1056
 
1057
 
1058
 
1059
 
1060
 3590  F903E2  A5 1C         		lda	rootent
1061
 3591  F903E4  8D B4 40      		sta	!P0LDT+ldt4+ldt_rent
1062
 3592  F903E7  A5 1E         		lda	clsent
1063
 3593  F903E9  8D B6 40      		sta	!P0LDT+ldt4+ldt_cent
1064
 3594  F903EC  A5 2E         		lda	freecnt
1065
 3595  F903EE  8D BA 40      		sta	!P0LDT+ldt4+ldt_free
1066
 3596  F903F1  A5 30         		lda	freecls
1067
 3597  F903F3  8D BC 40      		sta	!P0LDT+ldt4+ldt_nxt
1068
 3598  F903F6                		ACC08
1069
 3599  F903F6  E2 20         		sep	#PMFLAG
1070
 3600                        		.LONGA	off
1071
 3601                        		.MNLIST
1072
 3602  F903F8  A5 35         		lda	clssiz
1073
 3603  F903FA  8D C0 40      		sta	!P0LDT+ldt4+ldt_csiz
1074
 3604  F903FD  A5 36         		lda	clsshf
1075
 3605  F903FF  8D C1 40      		sta	!P0LDT+ldt4+ldt_cshf
1076
 3606  F90402  A5 18         		lda	fatsiz
1077
 3607  F90404  8D BE 40      		sta	!P0LDT+ldt4+ldt_fsiz
1078
 3608  F90407  A5 1A         		lda	rootsiz
1079
 3609  F90409  8D C2 40      		sta	!P0LDT+ldt4+ldt_rsiz
1080
 3610  F9040C  A5 37         		lda	clsmod
1081
 3611  F9040E  8D C3 40      		sta	!P0LDT+ldt4+ldt_mcls
1082
 3612
1083
 3613  F90411  A9 E0         		lda	#$E0
1084
 3614  F90413  8D A9 40      		sta	!P0LDT+ldt4+ldt_fg2
1085
 3615  F90416  18            		clc
1086
 3616  F90417  60            		rts
1087
 3617
1088
 3618  F90418                	fssetup:
1089
 3619  F90418  0B            		phd
1090
 3620  F90419  F4 00 42      		pea	#P0OS
1091
 3621  F9041C  2B            		pld			; set dp page
1092
 3622  F9041D  A2 3B         		ldx	#RTCSHID	; default hidden sector's (for fdisk)
1093
 3623  F9041F  8E 4C FD      		stx	RTCALE		; from RTC RAM in bank 0 & 1
1094
 3624  F90422  AD 4D FD      		lda	RTCDATA		; read saved value
1095
 3625  F90425  C9 40         		cmp	#$40		; invalid?
1096
 3626  F90427  90 05         		bcc	?01b		; no
1097
 3627  F90429  A9 3F         	?01:	lda	#HIDSEC		; get default value
1098
 3628  F9042B  8D 4D FD      		sta	RTCDATA		; save default value
1099
 3629  F9042E  85 00         	?01b:	sta	defhsec
1100
 3630  F90430  C9 00         		cmp	#0
1101
 3631  F90432  D0 07         		bne	?01c
1102
 3632  F90434  A9 3F         		lda	#HIDSEC		; get default value
1103
 3633  F90436  8D 4D FD      		sta	RTCDATA		; save default value
1104
 3634  F90439  85 00         		sta	defhsec
1105
 3635  F9043B  A2 3C         	?01c:	ldx	#RTCHUSE	; flag use hash block's
1106
 3636  F9043D  8E 4C FD      		stx	RTCALE
1107
 3637  F90440  AD 4D FD      		lda	RTCDATA		; read saved value
1108
 3638  F90443  C9 FF         		cmp	#$FF
1109
 3639  F90445  D0 05         		bne	?02
1110
 3640  F90447  A9 80         		lda	#$80		; default value (use hash)
1111
 3641  F90449  8D 4D FD      		sta	RTCDATA		; save default value
1112
 3642  F9044C  8D 8D 41      	?02:	sta	!P0FAT+hcbuse
1113
 3643  F9044F  A2 3D         		ldx	#RTCHLOG2	; sector's per hcb block
1114
 3644  F90451  8E 4C FD      		stx	RTCALE
1115
 3645  F90454  AD 4D FD      		lda	RTCDATA		; read saved value
1116
 3646  F90457  C9 FF         		cmp	#$FF
1117
  Tue Jul 17 11:00:20 2018                                                                                               Page   19
1118
 
1119
 
1120
 
1121
 
1122
 3647  F90459  F0 04         		beq	?03
1123
 3648  F9045B  C9 07         		cmp	#7		; valid value: 0..6
1124
 3649  F9045D  90 05         		bcc	?04
1125
 3650  F9045F  A9 04         	?03:	lda	#$04		; default value (16 sector's per block)
1126
 3651  F90461  8D 4D FD      		sta	RTCDATA		; save default value
1127
 3652  F90464  8D 09 41      	?04:	sta	!P0FAT+hlog2
1128
 3653  F90467  AA            		tax
1129
 3654  F90468  BF 61 1C F9   		lda	>CLSSIZE,x	; get block size in sector's
1130
 3655  F9046C  8D 08 41      		sta	!P0FAT+hsiz
1131
 3656  F9046F                		ACC16
1132
 3657  F9046F  C2 20         		rep	#PMFLAG
1133
 3658                        		.LONGA	on
1134
 3659                        		.MNLIST
1135
 3660  F90471  A9 10 00      		lda	#16		; get max. entries per block
1136
 3661  F90474  9B            		txy
1137
 3662  F90475  F0 04         		beq	?04b		; no shift
1138
 3663  F90477  0A            	?04a:	asl	a		; mult * 16 to get entries #
1139
 3664  F90478  CA            		dex
1140
 3665  F90479  D0 FC         		bne	?04a
1141
 3666  F9047B  0A            	?04b:	asl	a		; 2 bytes per entry
1142
 3667  F9047C  69 08 00      		adc	#HCBSIZE	; plus HCB header
1143
 3668  F9047F  85 06         		sta	hcbsiz		; effective HCB size
1144
 3669  F90481  38            		sec
1145
 3670  F90482  A9 00 00      		lda	#0
1146
 3671  F90485  E9 08 00      		sbc	#hcbstart
1147
 3672  F90488  85 10         		sta	hcbrem		; free room in bank
1148
 3673  F9048A  A0 00         		ldy	#0
1149
 3674  F9048C                		CPU16
1150
 3675  F9048C  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1151
 3676                        		.LONGA	on
1152
 3677                        		.LONGI	on
1153
 3678                        		.MNLIST
1154
 3679  F9048E  A2 1E 30      		ldx	#TOS1SIZ-2	; clear TOS work area
1155
 3680  F90491  98            		tya
1156
 3681  F90492  9F 00 9E 01   	?05:	sta	>_TOS1_START,x
1157
 3682  F90496  CA            		dex
1158
 3683  F90497  CA            		dex
1159
 3684  F90498  10 F8         		bpl	?05
1160
 3685  F9049A  BB            		tyx
1161
 3686  F9049B  9F 00 00 04   	?10:	sta	>hcb_bnk,x	; clear HCB bank
1162
 3687  F9049F  E8            		inx
1163
 3688  F904A0  E8            		inx
1164
 3689  F904A1  D0 F8         		bne	?10
1165
 3690  F904A3                		CPU08
1166
 3691  F904A3  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1167
 3692                        		.LONGA	off
1168
 3693                        		.LONGI	off
1169
 3694                        		.MNLIST
1170
 3695  F904A5  8B            		phb			; save dbr
1171
 3696  F904A6  A9 01         		lda	#WKB
1172
 3697  F904A8  48            		pha
1173
 3698  F904A9  AB            		plb			; set dbr to fat work area
1174
 3699  F904AA                		CPU16
1175
 3700  F904AA  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1176
 3701                        		.LONGA	on
1177
 3702                        		.LONGI	on
1178
 3703                        		.MNLIST
1179
  Tue Jul 17 11:00:20 2018                                                                                               Page   20
1180
 
1181
 
1182
 
1183
 
1184
 3704  F904AC  A9 00 0C      		lda	#BCBXBNK	; init BCB struct's for at drive's buffer's
1185
 3705  F904AF  85 04         		sta	bcbbnk
1186
 3706  F904B1  A9 00 A8      		lda	#bcbstart
1187
 3707  F904B4  8F 0A 41 00   		sta	>P0FAT+bcbroot
1188
 3708  F904B8  AA            		tax
1189
 3709  F904B9  A5 04         	?15:	lda	bcbbnk
1190
 3710  F904BB  9D 0A 00      		sta	!bcb_buf,x
1191
 3711  F904BE  0A            		asl	a
1192
 3712  F904BF  0A            		asl	a
1193
 3713  F904C0  0A            		asl	a
1194
 3714  F904C1  0A            		asl	a		; x-mem bank
1195
 3715  F904C2  A8            		tay
1196
 3716  F904C3  29 00 FF      		and	#$FF00		; low byte = buffer hi ptr
1197
 3717  F904C6  1A            		inc	a		; bank 1
1198
 3718  F904C7  9D 0E 00      		sta	!bcb_xbnk,x	; store buffer high ptr + x-mem bank
1199
 3719  F904CA  98            		tya
1200
 3720  F904CB  EB            		xba			; C=0000,1000,2000,...,E000,F000
1201
 3721  F904CC  29 00 F0      		and	#$F000
1202
 3722  F904CF  4A            		lsr	a
1203
 3723  F904D0  4A            		lsr	a
1204
 3724  F904D1  4A            		lsr	a		; C=0000,0200,0400,...,1C00,1E00
1205
 3725  F904D2  09 00 20      		ora	#XMSTART	; C=2000,2200,2400,...,3C00,3E00
1206
 3726  F904D5  9D 0C 00      		sta	!bcb_ptr,x
1207
 3727  F904D8  A9 FF FF      		lda	#$FFFF
1208
 3728  F904DB  9D 02 00      		sta	!bcb_drv,x	; drive+sec = $FFFF -> unused
1209
 3729  F904DE  E6 04         		inc	bcbbnk
1210
 3730  F904E0  8A            		txa
1211
 3731  F904E1  18            		clc
1212
 3732  F904E2  69 10 00      		adc	#BCBSIZE
1213
 3733  F904E5  C9 00 C8      		cmp	#bcbend
1214
 3734  F904E8  B0 06         		bcs	?20
1215
 3735  F904EA  9D 00 00      		sta	!bcb_next,x
1216
 3736  F904ED  AA            		tax
1217
 3737  F904EE  80 C9         		bra	?15
1218
 3738  F904F0  9E 00 00      	?20:	stz	!bcb_next,x	; last struct
1219
 3739  F904F3  8A            		txa
1220
 3740  F904F4  8F 0C 41 00   		sta	>P0FAT+bcblst
1221
 3741  F904F8                		CPU08
1222
 3742  F904F8  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1223
 3743                        		.LONGA	off
1224
 3744                        		.LONGI	off
1225
 3745                        		.MNLIST
1226
 3746  F904FA  A9 80         		lda	#BCBDMA		; init BCB's struct's in dma buffer's
1227
 3747  F904FC  85 05         		sta	bcbbnk+1	; dma buffer # in high byte
1228
 3748  F904FE  20 96 06      		jsr	?100		; get dma bank
1229
 3749  F90501  84 04         		sty	bcbbnk
1230
 3750  F90503                		CPU16
1231
 3751  F90503  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1232
 3752                        		.LONGA	on
1233
 3753                        		.LONGI	on
1234
 3754                        		.MNLIST
1235
 3755  F90505  A9 00 C8      		lda	#dmastart
1236
 3756  F90508  8F 0E 41 00   		sta	>P0FAT+dmaroot
1237
 3757  F9050C  AA            		tax
1238
 3758  F9050D  A9 FF FF      	?25:	lda	#$FFFF		; invalidate buffer
1239
 3759  F90510  9D 02 00      		sta	!bcb_drv,x	; drive+sec = $FFFF -> unused
1240
 3760  F90513  A5 04         		lda	bcbbnk
1241
  Tue Jul 17 11:00:20 2018                                                                                               Page   21
1242
 
1243
 
1244
 
1245
 
1246
 3761  F90515  9D 0E 00      		sta	!bcb_dma,x	; store buffer high ptr + dma buffer #
1247
 3762  F90518  A8            		tay
1248
 3763  F90519  29 00 7F      		and	#$7F00		; strip off bit 15
1249
 3764  F9051C  0A            		asl	a
1250
 3765  F9051D  9D 0C 00      		sta	!bcb_ptr,x	; buffer pointer
1251
 3766  F90520  98            		tya
1252
 3767  F90521  EB            		xba
1253
 3768  F90522  1A            		inc	a		; increment bank
1254
 3769  F90523  EB            		xba
1255
 3770  F90524  85 04         		sta	bcbbnk
1256
 3771  F90526  8A            		txa
1257
 3772  F90527  18            		clc
1258
 3773  F90528  69 10 00      		adc	#BCBSIZE
1259
 3774  F9052B  C9 00 CC      		cmp	#dmaend
1260
 3775  F9052E  B0 06         		bcs	?30
1261
 3776  F90530  9D 00 00      		sta	!bcb_next,x	; pointer to next BCB
1262
 3777  F90533  AA            		tax
1263
 3778  F90534  80 D7         		bra	?25
1264
 3779  F90536  9E 00 00      	?30:	stz	!bcb_next,x	; last struct
1265
 3780  F90539  8A            		txa
1266
 3781  F9053A  8F 10 41 00   		sta	>P0FAT+dmalst
1267
 3782  F9053E  A2 00 CC      		ldx	#dma0s
1268
 3783  F90541  A9 FF FF      		lda	#$FFFF		; invalidate buffer
1269
 3784  F90544  9D 02 00      		sta	!bcb_drv,x	; drive+sec = $FFFF -> unused
1270
 3785  F90547  A2 10 CD      		ldx	#dma1s
1271
 3786  F9054A  9D 02 00      		sta	!bcb_drv,x	; drive+sec = $FFFF -> unused
1272
 3787  F9054D                		CPU08
1273
 3788  F9054D  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1274
 3789                        		.LONGA	off
1275
 3790                        		.LONGI	off
1276
 3791                        		.MNLIST
1277
 3792  F9054F  A9 04         		lda	#HCBBNK		; init HCB struct's
1278
 3793  F90551  48            		pha
1279
 3794  F90552  AB            		plb
1280
 3795  F90553                		CPU16
1281
 3796  F90553  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1282
 3797                        		.LONGA	on
1283
 3798                        		.LONGI	on
1284
 3799                        		.MNLIST
1285
 3800  F90555  A9 08 00      		lda	#hcbstart
1286
 3801  F90558  8F 04 41 00   		sta	>P0FAT+hcbroot
1287
 3802  F9055C  AA            		tax
1288
 3803  F9055D  A9 FF FF      	?35:	lda	#$FFFF
1289
 3804  F90560  9D 04 00      		sta	!hcb_seq,x	; unused HCB
1290
 3805  F90563  A5 10         		lda	hcbrem		; free room
1291
 3806  F90565  38            		sec
1292
 3807  F90566  E5 06         		sbc	hcbsiz
1293
 3808  F90568  90 10         		bcc	?40		; no more room
1294
 3809  F9056A  C5 06         		cmp	hcbsiz
1295
 3810  F9056C  90 0C         		bcc	?40		; no more room
1296
 3811  F9056E  85 10         		sta	hcbrem		; save new free room
1297
 3812  F90570  8A            		txa
1298
 3813  F90571  18            		clc
1299
 3814  F90572  65 06         		adc	hcbsiz
1300
 3815  F90574  9D 00 00      		sta	!hcb_next,x
1301
 3816  F90577  AA            		tax			; next HCB
1302
 3817  F90578  80 E3         		bra	?35
1303
  Tue Jul 17 11:00:20 2018                                                                                               Page   22
1304
 
1305
 
1306
 
1307
 
1308
 3818  F9057A  9E 00 00      	?40:	stz	!hcb_next,x	; last HCB
1309
 3819  F9057D  8A            		txa
1310
 3820  F9057E  8F 06 41 00   		sta	>P0FAT+hcblst
1311
 3821  F90582                		CPU08
1312
 3822  F90582  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1313
 3823                        		.LONGA	off
1314
 3824                        		.LONGI	off
1315
 3825                        		.MNLIST
1316
 3826  F90584  AB            		plb			; restore dbr
1317
 3827  F90585  0B            		phd
1318
 3828  F90586  F4 00 40      		pea	#P0LDT		; switch to LDT D.P.
1319
 3829  F90589  2B            		pld
1320
 3830  F9058A  A2 A8         		ldx	#ldt4		; set up LDT ptr's
1321
 3831  F9058C  86 D6         		stx	ldtp+4		; logical drive #4
1322
 3832                        		;ldx	#ldt5		; set up LDT ptr's
1323
 3833                        		;stx	ldtp+5		; logical drive #4
1324
 3834  F9058E  A2 00         		ldx	#ldt0		; set up LDT ptr's
1325
 3835  F90590  86 D2         		stx	ldtp		; logical drive #0
1326
 3836  F90592  AD 46 00      		lda	!fdcctl		; phisycal drive 0 ready flag
1327
 3837  F90595  29 80         		and	#$80
1328
 3838  F90597  95 00         		sta	ldt_fg1,x
1329
 3839  F90599  A2 2A         		ldx	#ldt1
1330
 3840  F9059B  86 D3         		stx	ldtp+1		; logical drive #1
1331
 3841  F9059D  A9 81         		lda	#$81		; virtual drive 1 always ready
1332
 3842  F9059F  95 00         		sta	ldt_fg1,x
1333
 3843  F905A1  A2 54         		ldx	#ldt2
1334
 3844  F905A3  86 D4         		stx	ldtp+2		; logical drive #2
1335
 3845  F905A5  AD 0E 00      		lda	!atadev		; phisycal ata device #0
1336
 3846  F905A8  29 80         		and	#$80
1337
 3847  F905AA  09 40         		ora	#$40		; ata device #0
1338
 3848  F905AC  95 00         		sta	ldt_fg1,x
1339
 3849  F905AE  A2 7E         		ldx	#ldt3
1340
 3850  F905B0  86 D5         		stx	ldtp+3		; logical drive #3
1341
 3851  F905B2  AD 0F 00      		lda	!atadev+1	; phisycal ata device #1
1342
 3852  F905B5  29 80         		and	#$80
1343
 3853  F905B7  09 41         		ora	#$41		; ata device #1
1344
 3854  F905B9  95 00         		sta	ldt_fg1,x
1345
 3855  F905BB  A9 00         		lda	#DR0SYS
1346
 3856  F905BD  85 D8         		sta	sysbuf		; drive 0 system track cache
1347
 3857  F905BF  AA            		tax
1348
 3858  F905C0  E8            		inx
1349
 3859  F905C1  86 25         		stx	ldt0+ldt_fbuf
1350
 3860  F905C3  20 96 06      		jsr	?100
1351
 3861  F905C6  85 27         		sta	ldt0+ldt_pbr+1	; set PBR pointer
1352
 3862  F905C8  84 28         		sty	ldt0+ldt_pbr+2
1353
 3863  F905CA  64 26         		stz	ldt0+ldt_pbr
1354
 3864  F905CC  1A            		inc	a		; drive 0 fat table dma buffer
1355
 3865  F905CD  1A            		inc	a
1356
 3866  F905CE  85 23         		sta	ldt0+ldt_fp+1	; set fat pointer
1357
 3867  F905D0  84 24         		sty	ldt0+ldt_fp+2
1358
 3868  F905D2  64 22         		stz	ldt0+ldt_fp
1359
 3869  F905D4  A9 24         		lda	#DR1SYS
1360
 3870  F905D6  85 DA         		sta	sysbuf+2	; drive 1 system track cache
1361
 3871  F905D8  AA            		tax
1362
 3872  F905D9  E8            		inx
1363
 3873  F905DA  86 4F         		stx	ldt1+ldt_fbuf
1364
 3874  F905DC  20 96 06      		jsr	?100
1365
  Tue Jul 17 11:00:20 2018                                                                                               Page   23
1366
 
1367
 
1368
 
1369
 
1370
 3875  F905DF  85 51         		sta	ldt1+ldt_pbr+1	; set PBR pointer
1371
 3876  F905E1  84 52         		sty	ldt1+ldt_pbr+2
1372
 3877  F905E3  64 50         		stz	ldt1+ldt_pbr
1373
 3878  F905E5  1A            		inc	a		; drive 1 fat table dma buffer
1374
 3879  F905E6  1A            		inc	a
1375
 3880  F905E7  85 4D         		sta	ldt1+ldt_fp+1	; set fat pointer
1376
 3881  F905E9  84 4E         		sty	ldt1+ldt_fp+2
1377
 3882  F905EB  64 4C         		stz	ldt1+ldt_fp
1378
 3883  F905ED  A9 E0         		lda	#FAT0X
1379
 3884  F905EF  85 79         		sta	ldt2+ldt_fbuf	; fat cache buffer drive #2
1380
 3885  F905F1  A9 F0         		lda	#FAT1X
1381
 3886  F905F3  85 A3         		sta	ldt3+ldt_fbuf	; fat cache buffer drive #3
1382
 3887  F905F5  A9 20         		lda	#>XMSTART
1383
 3888  F905F7  A0 01         		ldy	#XMBANK
1384
 3889  F905F9  64 76         		stz	ldt2+ldt_fp	; set fat drive # 2 pointer
1385
 3890  F905FB  85 77         		sta	ldt2+ldt_fp+1
1386
 3891  F905FD  84 78         		sty	ldt2+ldt_fp+2
1387
 3892  F905FF  64 A0         		stz	ldt3+ldt_fp	; set fat drive # 3 pointer
1388
 3893  F90601  85 A1         		sta	ldt3+ldt_fp+1
1389
 3894  F90603  84 A2         		sty	ldt3+ldt_fp+2
1390
 3895  F90605  AF 89 1C F9   		lda	>PBRPTR2
1391
 3896  F90609  85 7C         		sta	ldt2+ldt_pbr+2
1392
 3897  F9060B  AF 8A 1C F9   		lda	>PBRPTR2+1
1393
 3898  F9060F  85 A6         		sta	ldt3+ldt_pbr+2
1394
 3899  F90611  A9 FF         		lda	#$FF
1395
 3900  F90613  85 29         		sta	ldt0+ldt_fmt
1396
 3901  F90615  85 53         		sta	ldt1+ldt_fmt
1397
 3902  F90617  85 7D         		sta	ldt2+ldt_fmt
1398
 3903  F90619  85 A7         		sta	ldt3+ldt_fmt
1399
 3904  F9061B                		ACC16
1400
 3905  F9061B  C2 20         		rep	#PMFLAG
1401
 3906                        		.LONGA	on
1402
 3907                        		.MNLIST
1403
 3908  F9061D  AF 85 1C F9   		lda	>PBRPTR
1404
 3909  F90621  85 7A         		sta	ldt2+ldt_pbr
1405
 3910  F90623  AF 87 1C F9   		lda	>PBRPTR+2
1406
 3911  F90627  85 A4         		sta	ldt3+ldt_pbr
1407
 3912  F90629  A9 F8 0F      		lda	#F12EOC
1408
 3913  F9062C  85 10         		sta	ldt0+ldt_eoc	; FAT12 end of chain marker
1409
 3914  F9062E  85 3A         		sta	ldt1+ldt_eoc
1410
 3915  F90630  A9 F8 FF      		lda	#F16EOC
1411
 3916  F90633  85 64         		sta	ldt2+ldt_eoc	; FAT16 end of chain marker
1412
 3917  F90635  85 8E         		sta	ldt3+ldt_eoc
1413
 3918  F90637  A9 00 9E      		lda	#cwdl0
1414
 3919  F9063A  85 1C         		sta	ldt0+ldt_cdlp	; current directory pointer drive #0
1415
 3920  F9063C  A9 00 A0      		lda	#cwdl1
1416
 3921  F9063F  85 46         		sta	ldt1+ldt_cdlp	; current directory pointer drive #1
1417
 3922  F90641  A9 00 A2      		lda	#cwdl2
1418
 3923  F90644  85 70         		sta	ldt2+ldt_cdlp	; current directory pointer drive #2
1419
 3924  F90646  A9 00 A4      		lda	#cwdl3
1420
 3925  F90649  85 9A         		sta	ldt3+ldt_cdlp	; current directory pointer drive #3
1421
 3926  F9064B  64 1E         		stz	ldt0+ldt_cdcls	; current directory cluster
1422
 3927  F9064D  64 48         		stz	ldt1+ldt_cdcls
1423
 3928  F9064F  64 72         		stz	ldt2+ldt_cdcls
1424
 3929  F90651  64 9C         		stz	ldt3+ldt_cdcls
1425
 3930  F90653  A0 00         		ldy	#0
1426
 3931  F90655  84 20         		sty	ldt0+ldt_cdlvl	; current directory level
1427
  Tue Jul 17 11:00:20 2018                                                                                               Page   24
1428
 
1429
 
1430
 
1431
 
1432
 3932  F90657  84 4A         		sty	ldt1+ldt_cdlvl
1433
 3933  F90659  84 74         		sty	ldt2+ldt_cdlvl
1434
 3934  F9065B  84 9E         		sty	ldt3+ldt_cdlvl
1435
 3935  F9065D  64 12         		stz	ldt0+ldt_free	; clear free cluster's count & next free clu.
1436
 3936  F9065F  64 14         		stz	ldt0+ldt_nxt
1437
 3937  F90661  64 3C         		stz	ldt1+ldt_free
1438
 3938  F90663  64 3E         		stz	ldt1+ldt_nxt
1439
 3939  F90665  64 66         		stz	ldt2+ldt_free
1440
 3940  F90667  64 68         		stz	ldt2+ldt_nxt
1441
 3941  F90669  64 90         		stz	ldt3+ldt_free
1442
 3942  F9066B  64 92         		stz	ldt3+ldt_nxt
1443
 3943  F9066D                		ACC08
1444
 3944  F9066D  E2 20         		sep	#PMFLAG
1445
 3945                        		.LONGA	off
1446
 3946                        		.MNLIST
1447
 3947  F9066F  2B            		pld			; restore DP
1448
 3948  F90670  A2 01         		ldx	#1		; test virtual drive (drive #1)
1449
 3949  F90672  20 D3 08      		jsr	ldtfd
1450
 3950  F90675  90 13         		bcc	?90		; ok
1451
 3951  F90677  A9 82         		lda	#$82		; force HD format
1452
 3952  F90679  8D 45 00      		sta	!vdrive
1453
 3953  F9067C  A9 02         		lda	#2
1454
 3954  F9067E  A0 00         		ldy	#0
1455
 3955  F90680  A2 01         		ldx	#1
1456
 3956  F90682  20 BF 0D      		jsr	newf12		; make fat12 file system (no error!)
1457
 3957  F90685  A2 01         		ldx	#1
1458
 3958  F90687  20 D3 08      		jsr	ldtfd		; test again virtual drive
1459
 3959  F9068A  A2 02         	?90:	ldx	#2		; build LDT for ata device's
1460
 3960  F9068C  20 9D 06      	?95:	jsr	ldt16
1461
 3961  F9068F  E8            		inx
1462
 3962  F90690  E0 04         		cpx	#MAXDRV
1463
 3963  F90692  90 F8         		bcc	?95
1464
 3964  F90694  2B            		pld
1465
 3965  F90695  60            		rts
1466
 3966
1467
 3967  F90696  A0 02         	?100:	ldy	#DMABNK		; bank for buffer #00..#7F
1468
 3968  F90698  0A            		asl	a		; get high pointer
1469
 3969  F90699  90 01         		bcc	?102
1470
 3970  F9069B  C8            		iny			; next bank
1471
 3971  F9069C  60            	?102:	rts
1472
 3972
1473
 3973                        	; X=logical, DBR=0, DPR=P0LDT
1474
 3974  F9069D                	ldt16:
1475
 3975                        		.EXTERN lchkmbr
1476
 3976
1477
 3977  F9069D  86 3F         		stx	ldev		; logical drive
1478
 3978  F9069F  9B            		txy
1479
 3979  F906A0  BE D2 40      		ldx	!P0LDT+ldtp,y
1480
 3980  F906A3  86 40         		stx	ldtcur		; current LDT ptr
1481
 3981  F906A5  3C 00 40      		bit	!P0LDT+ldt_fg1,x
1482
 3982  F906A8  10 5C         		bpl	?15		; not ready
1483
 3983  F906AA  50 5A         		bvc	?15		; floppy disk
1484
 3984  F906AC  BD 00 40      		lda	!P0LDT+ldt_fg1,x
1485
 3985  F906AF  29 03         		and	#3
1486
 3986  F906B1  85 3E         		sta	pdev		; phisycal drive
1487
 3987  F906B3  18            		clc
1488
 3988  F906B4  69 43         		adc	#'C'		; ata device: 'C' or 'D'
1489
  Tue Jul 17 11:00:20 2018                                                                                               Page   25
1490
 
1491
 
1492
 
1493
 
1494
 3989  F906B6  85 39         		sta	lunit		; logical drive letter
1495
 3990  F906B8  20 09 07      		jsr	?20		; check message
1496
 3991  F906BB  20 67 07      		jsr	?30		; load PBR
1497
 3992  F906BE  20 A3 07      		jsr	?40		; check PBR
1498
 3993  F906C1  20 D1 07      		jsr	?50		; fat calc
1499
 3994  F906C4  A6 40         		ldx	ldtcur
1500
 3995  F906C6  BC 25 40      		ldy	!P0LDT+ldt_fbuf,x
1501
 3996  F906C9  84 38         		sty	xbnk
1502
 3997  F906CB                		ACC16
1503
 3998  F906CB  C2 20         		rep	#PMFLAG
1504
 3999                        		.LONGA	on
1505
 4000                        		.MNLIST
1506
 4001  F906CD  98            		tya
1507
 4002  F906CE  0A            		asl	a
1508
 4003  F906CF  0A            		asl	a
1509
 4004  F906D0  0A            		asl	a
1510
 4005  F906D1  0A            		asl	a
1511
 4006  F906D2  85 2A         		sta	xfatb
1512
 4007  F906D4  A5 22         		lda	fat1
1513
 4008  F906D6  85 2C         		sta	flba
1514
 4009  F906D8  BD 22 40      		lda	!P0LDT+ldt_fp,x
1515
 4010  F906DB  85 3A         		sta	tp
1516
 4011  F906DD  BC 24 40      		ldy	!P0LDT+ldt_fp+2,x
1517
 4012  F906E0  84 3C         		sty	tp+2
1518
 4013  F906E2                		ACC08
1519
 4014  F906E2  E2 20         		sep	#PMFLAG
1520
 4015                        		.LONGA	off
1521
 4016                        		.MNLIST
1522
 4017  F906E4  A9 00         		lda	#0		; try to load fat1 table
1523
 4018  F906E6  20 D8 07      		jsr	?60
1524
 4019  F906E9  90 0D         		bcc	?10		; ok
1525
 4020  F906EB                		ACC16
1526
 4021  F906EB  C2 20         		rep	#PMFLAG
1527
 4022                        		.LONGA	on
1528
 4023                        		.MNLIST
1529
 4024  F906ED  A5 24         		lda	fat2
1530
 4025  F906EF  85 2C         		sta	flba
1531
 4026  F906F1                		ACC08
1532
 4027  F906F1  E2 20         		sep	#PMFLAG
1533
 4028                        		.LONGA	off
1534
 4029                        		.MNLIST
1535
 4030  F906F3  A9 80         		lda	#$80		; try to read fat2 table (no return if error)
1536
 4031  F906F5  20 D8 07      		jsr	?60
1537
 4032  F906F8  20 22 08      	?10:	jsr	?80		; count free cluster's
1538
 4033  F906FB  20 6D 0D      		jsr	mvldt		; move data to LDT
1539
 4034  F906FE  A9 E0         		lda	#$E0
1540
 4035  F90700  9D 01 40      		sta	!P0LDT+ldt_fg2,x
1541
 4036  F90703  20 67 08      		jsr	?100		; print summary data
1542
 4037  F90706  A6 3F         	?15:	ldx	ldev
1543
 4038  F90708  60            		rts
1544
 4039
1545
 4040  F90709  A5 39         	?20:	lda	lunit		; print check message
1546
 4041  F9070B  48            		pha
1547
 4042  F9070C  4B            		phk
1548
 4043  F9070D  F4 5A 07      		pea	#!?25
1549
 4044  F90710  A9 05         		lda	#5
1550
 4045  F90712  48            		pha
1551
  Tue Jul 17 11:00:20 2018                                                                                               Page   26
1552
 
1553
 
1554
 
1555
 
1556
 4046  F90713                		BPRINTF
1557
 4047  F90713  02 11         		cop	$11
1558
 4048                        		.MNLIST
1559
 4049  F90715  A6 3E         		ldx	pdev
1560
 4050  F90717  BD 0E 00      		lda	!atadev,x	; check ata device flag
1561
 4051  F9071A  29 BD         		and	#10111101B	; ready&ident&valid MBR partition
1562
 4052  F9071C  C9 BD         		cmp	#10111101B
1563
 4053  F9071E  F0 08         		beq	?36a		; ok
1564
 4054  F90720  A6 3E         		ldx	pdev		; load MBR
1565
 4055  F90722  22 4D 90 F8   		jsl	lchkmbr
1566
 4056  F90726  B0 01         		bcs	?36b
1567
 4057  F90728  60            	?36a:	rts
1568
 4058
1569
 4059  F90729                	?36b:
1570
 4060  F90729                		SCNPRINT
1571
 4061  F90729  02 01         		cop	$01
1572
 4062                        		.MNLIST
1573
 4063  F9072B  75 6E 70 61 72 		.DB	'unpartitioned disk or invalid partition ID.', 13, 0
1574
               74 69 74 69 6F
1575
               6E 65 64 20 64
1576
               69 73 6B 20 6F
1577
               72 20 69 6E 76
1578
               61 6C 69 64 20
1579
               70 61 72 74 69
1580
               74 69 6F 6E 20
1581
               49 44 2E 0D 00
1582
 4064  F90758  80 44         		bra	?32		; no or invalid partition
1583
 4065
1584
 4066  F9075A  63 68 65 63 6B 	?25:	.DB	'check <%c>: ', 0
1585
               20 3C 25 63 3E
1586
               3A 20 00
1587
 4067
1588
 4068  F90767  A6 3E         	?30:	ldx	pdev		; load PBR
1589
 4069  F90769  A9 03         		lda	#3
1590
 4070  F9076B                		ATACTL
1591
 4071  F9076B  02 41         		cop	$41
1592
 4072                        		.MNLIST
1593
 4073  F9076D  90 33         		bcc	?36		; ok
1594
 4074  F9076F                		SCNPRINT
1595
 4075  F9076F  02 01         		cop	$01
1596
 4076                        		.MNLIST
1597
 4077  F90771  75 6E 61 62 6C 		.DB	'unable to load partition boot record (PBR).', 13, 0
1598
               65 20 74 6F 20
1599
               6C 6F 61 64 20
1600
               70 61 72 74 69
1601
               74 69 6F 6E 20
1602
               62 6F 6F 74 20
1603
               72 65 63 6F 72
1604
               64 20 28 50 42
1605
               52 29 2E 0D 00
1606
 4078  F9079E  68            	?32:	pla			; discard return address
1607
 4079  F9079F  68            		pla
1608
 4080  F907A0  A6 3F         	?34:	ldx	ldev
1609
 4081  F907A2  60            	?36:	rts
1610
 4082  F907A3
1611
 4083  F907A3  20 65 0B      	?40:	jsr	chk16		; check PBR
1612
 4084  F907A6  90 FA         		bcc	?36
1613
  Tue Jul 17 11:00:20 2018                                                                                               Page   27
1614
 
1615
 
1616
 
1617
 
1618
 4085  F907A8                	?45:	SCNPRINT
1619
 4086  F907A8  02 01         		cop	$01
1620
 4087                        		.MNLIST
1621
 4088  F907AA  69 6E 76 61 6C 		.DB	'invalid partition type (not FAT16).', 13, 0
1622
               69 64 20 70 61
1623
               72 74 69 74 69
1624
               6F 6E 20 74 79
1625
               70 65 20 28 6E
1626
               6F 74 20 46 41
1627
               54 31 36 29 2E
1628
               0D 00
1629
 4089  F907CF  80 CD         		bra	?32
1630
 4090
1631
 4091  F907D1  20 18 0D      	?50:	jsr	fcalc		; fat calc
1632
 4092  F907D4  90 CC         		bcc	?36
1633
 4093  F907D6  80 D0         		bra	?45
1634
 4094
1635
 4095  F907D8  85 41         	?60:	sta	lflag
1636
 4096
1637
 4097  F907DA  A6 3E         		ldx	pdev
1638
 4098  F907DC  AD CF FD      		lda	!VIA3+VIAPRANH
1639
 4099  F907DF  29 F8         		and	#$F8
1640
 4100  F907E1  1F 20 08 F9   		ora	>?69,x
1641
 4101  F907E5  8D CF FD      		sta	!VIA3+VIAPRANH	; set bank
1642
 4102
1643
 4103  F907E8  A6 3E         		ldx	pdev
1644
 4104  F907EA  DA            		phx			; phisical drive
1645
 4105  F907EB  A9 00         		lda	#0
1646
 4106  F907ED  48            		pha			; lba high
1647
 4107  F907EE  D4 2C         		pei	(flba)		; lba low
1648
 4108  F907F0  A5 18         		lda	fatsiz
1649
 4109  F907F2  48            		pha			; sector's count
1650
 4110  F907F3
1651
 4111                        		;pha			; use x-mem buffer
1652
 4112                        		;pei	(xfatb)		; x-mem buffer
1653
 4113                        		;pha			; flag=0
1654
 4114                        		;ATAREAD
1655
 4115  F907F3
1656
 4116  F907F3  BF 20 08 F9   		lda	>?69,x
1657
 4117  F907F7  48            		pha
1658
 4118  F907F8  A9 00         		lda	#0
1659
 4119  F907FA  48            		pha
1660
 4120  F907FB                		ATADMARD
1661
 4121  F907FB  02 42         		cop	$42
1662
 4122  F907FD  00            		.DB	$00
1663
 4123                        		.MNLIST
1664
 4124  F907FE
1665
 4125  F907FE  90 A2         		bcc	?36		; ok no error
1666
 4126  F90800  24 41         		bit	lflag
1667
 4127  F90802  10 9E         		bpl	?36		; try fat2 table
1668
 4128  F90804                		SCNPRINT
1669
 4129  F90804  02 01         		cop	$01
1670
 4130                        		.MNLIST
1671
 4131  F90806  66 61 74 20 74 		.DB	'fat table load error.', 13, 0
1672
               61 62 6C 65 20
1673
               6C 6F 61 64 20
1674
               65 72 72 6F 72
1675
  Tue Jul 17 11:00:20 2018                                                                                               Page   28
1676
 
1677
 
1678
 
1679
 
1680
               2E 0D 00
1681
 4132                        		;bra	?32
1682
 4133  F9081D  4C 9E 07      		jmp	?32
1683
 4134  F90820  05 06         	?69:	.DB	$05, $06	; FAT table bank
1684
 4135
1685
 4136  F90822  64 3A         	?80:	stz	tp
1686
 4137  F90824  64 3B         		stz	tp+1
1687
 4138  F90826  A9 02         		lda	#$02
1688
 4139  F90828  85 3C         		sta	tp+2
1689
 4140
1690
 4141  F9082A  A6 3E         		ldx	pdev
1691
 4142  F9082C  AD CF FD      		lda	!VIA3+VIAPRANH
1692
 4143  F9082F  29 F8         		and	#$F8
1693
 4144  F90831  1F 20 08 F9   		ora	>?69,x
1694
 4145  F90835  8D CF FD      		sta	!VIA3+VIAPRANH	; set bank
1695
 4146  F90838  A9 08         		lda	#$08		; PB3 VIA3
1696
 4147  F9083A  1C C0 FD      		trb	VIA3+VIAPRB	; enable 1Mb buffer
1697
 4148  F9083D
1698
 4149  F9083D  A2 00         		ldx	#0		; cluster number
1699
 4150  F9083F                		CPU16
1700
 4151  F9083F  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1701
 4152                        		.LONGA	on
1702
 4153                        		.LONGI	on
1703
 4154                        		.MNLIST
1704
 4155  F90841  9B            		txy
1705
 4156  F90842  64 2E         		stz	freecnt
1706
 4157  F90844  64 30         		stz	freecls
1707
 4158  F90846  B7 3A         	?85a:	lda	[tp],y		; scan fat table
1708
 4159  F90848  D0 08         		bne	?90a		; not free
1709
 4160  F9084A  E6 2E         		inc	freecnt		; update free cluster's count
1710
 4161  F9084C  A5 30         		lda	freecls		; already set?
1711
 4162  F9084E  D0 02         		bne	?90a		; yes
1712
 4163  F90850  86 30         		stx	freecls		; set first free cluster
1713
 4164  F90852  E8            	?90a:	inx
1714
 4165  F90853  E4 28         		cpx	maxcls		; end of table?
1715
 4166  F90855  B0 0D         		bcs	?95a		; yes
1716
 4167  F90857  C8            		iny
1717
 4168  F90858  C8            		iny
1718
 4169  F90859  D0 EB         		bne	?85a
1719
 4170  F9085B  A5 3B         		lda	tp+1
1720
 4171  F9085D  69 00 01      		adc	#$0100
1721
 4172  F90860  85 3B         		sta	tp+1
1722
 4173  F90862  80 E2         		bra	?85a
1723
 4174  F90864                	?95a:	CPU08
1724
 4175  F90864  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1725
 4176                        		.LONGA	off
1726
 4177                        		.LONGI	off
1727
 4178                        		.MNLIST
1728
 4179  F90866  60            		rts
1729
 4180
1730
 4181                        	.COMMENT @
1731
 4182
1732
 4183                        		ldx	CRXME		; save X mem setting
1733
 4184                        		phx
1734
 4185                        		sta	!CRXMEON	; enable X mem in window $012000 - $013FFF
1735
 4186                        		lda	xbnk
1736
 4187                        		sta	!PIA0+PIAPRA	; set x-mem bank
1737
  Tue Jul 17 11:00:20 2018                                                                                               Page   29
1738
 
1739
 
1740
 
1741
 
1742
 4188                        		phb			; save DBR
1743
 4189                        		lda	tp+2
1744
 4190                        		pha
1745
 4191                        		plb			; set DBR to fat table cache
1746
 4192                        		ldx	#0		; cluster number
1747
 4193                        		CPU16
1748
 4194                        		txy
1749
 4195                        		stz	freecnt
1750
 4196                        		stz	freecls
1751
 4197                        	?85:	lda	(tp),y		; scan fat table
1752
 4198                        		bne	?90		; not free
1753
 4199                        		inc	freecnt		; update free cluster's count
1754
 4200                        		lda	freecls		; already set?
1755
 4201                        		bne	?90		; yes
1756
 4202                        		stx	freecls		; set first free cluster
1757
 4203                        	?90:	inx
1758
 4204                        		cpx	maxcls		; end of table?
1759
 4205                        		bcs	?95		; yes
1760
 4206                        		iny
1761
 4207                        		iny
1762
 4208                        		cpy	#XMWSIZ		; end of x-mem window?
1763
 4209                        		bcc	?85		; no
1764
 4210                        		ACC08
1765
 4211                        		lda	>PIA0+PIAPRA	; update x-mem bank
1766
 4212                        		inc	a
1767
 4213                        		sta	>PIA0+PIAPRA
1768
 4214                        		ACC16
1769
 4215                        		ldy	#0
1770
 4216                        		bra	?85
1771
 4217                        	?95:	CPU08
1772
 4218                        		plb			; restore DBR
1773
 4219                        		plx			; restore X mem setting
1774
 4220                        		sta	!CRXME,x
1775
 4221                        		rts
1776
 4222                        	@
1777
 4223
1778
 4224  F90867                	?100:	ACC16			; print summary
1779
 4225  F90867  C2 20         		rep	#PMFLAG
1780
 4226                        		.LONGA	on
1781
 4227                        		.MNLIST
1782
 4228  F90869  A5 28         		lda	maxcls
1783
 4229  F9086B  3A            		dec	a
1784
 4230  F9086C  3A            		dec	a
1785
 4231  F9086D  85 28         		sta	maxcls
1786
 4232  F9086F                		ACC08
1787
 4233  F9086F  E2 20         		sep	#PMFLAG
1788
 4234                        		.LONGA	off
1789
 4235                        		.MNLIST
1790
 4236  F90871  A5 35         		lda	clssiz
1791
 4237  F90873  48            		pha
1792
 4238  F90874  D4 2E         		pei	(freecnt)
1793
 4239  F90876  D4 28         		pei	(maxcls)
1794
 4240  F90878  4B            		phk
1795
 4241  F90879  F4 82 08      		pea	#!?110
1796
 4242  F9087C  A9 09         		lda	#9
1797
 4243  F9087E  48            		pha
1798
 4244  F9087F                		BPRINTF
1799
  Tue Jul 17 11:00:20 2018                                                                                               Page   30
1800
 
1801
 
1802
 
1803
 
1804
 4245  F9087F  02 11         		cop	$11
1805
 4246                        		.MNLIST
1806
 4247  F90881  60            		rts
1807
 4248
1808
 4249  F90882  25 2C 68 75 20 	?110:	.DB	'%,hu cluster(s) (free: %,hu, 1 cluster=%bu sector(s)).', 13, 0
1809
               63 6C 75 73 74
1810
               65 72 28 73 29
1811
               20 28 66 72 65
1812
               65 3A 20 25 2C
1813
               68 75 2C 20 31
1814
               20 63 6C 75 73
1815
               74 65 72 3D 25
1816
               62 75 20 73 65
1817
               63 74 6F 72 28
1818
               73 29 29 2E 0D
1819
               00
1820
 4250
1821
 4251                        	; build LDT for floppy disk
1822
 4252                        	; X=logical drive
1823
 4253  F908BA                	bldldt:
1824
 4254  F908BA  A9 00         		lda	#0
1825
 4255  F908BC  8B            		phb
1826
 4256  F908BD  48            		pha
1827
 4257  F908BE  AB            		plb
1828
 4258  F908BF  0B            		phd
1829
 4259  F908C0  F4 00 42      		pea	#P0OS
1830
 4260  F908C3  2B            		pld
1831
 4261  F908C4  20 D3 08      		jsr	ldtfd
1832
 4262  F908C7  2B            		pld
1833
 4263  F908C8  AB            		plb
1834
 4264  F908C9  60            		rts
1835
 4265
1836
 4266  F908CA                	testldt:
1837
 4267  F908CA  A2 00         		ldx	#0
1838
 4268  F908CC  20 BA 08      		jsr	bldldt
1839
 4269  F908CF  00 00         		brk
1840
 4270  F908D1  00 00         		brk
1841
 4271
1842
 4272                        	; build LDT for floppy disk media
1843
 4273                        	; X=logical device, DPR=P0LDT
1844
 4274  F908D3                	ldtfd:
1845
 4275  F908D3  86 3F         		stx	ldev		; logical drive
1846
 4276  F908D5  9B            		txy
1847
 4277  F908D6  BE D2 40      		ldx	!P0LDT+ldtp,y
1848
 4278  F908D9  86 40         		stx	ldtcur		; current LDT ptr
1849
 4279  F908DB  3C 00 40      		bit	!P0LDT+ldt_fg1,x
1850
 4280  F908DE  10 34         		bpl	?15		; not ready
1851
 4281  F908E0  70 32         		bvs	?15		; ata device
1852
 4282  F908E2  9E 01 40      		stz	!P0LDT+ldt_fg2,x	; reset flag 2
1853
 4283  F908E5  BD 00 40      		lda	!P0LDT+ldt_fg1,x
1854
 4284  F908E8  29 03         		and	#3
1855
 4285  F908EA  85 3E         		sta	pdev		; phisycal drive
1856
 4286  F908EC  20 18 09      		jsr	?20		; check media format
1857
 4287  F908EF  20 44 09      		jsr	?30		; load PBR
1858
 4288  F908F2  20 59 09      		jsr	?40		; check PBR
1859
 4289  F908F5  20 60 09      		jsr	?50		; fat calc
1860
 4290  F908F8  20 67 09      		jsr	?60		; count free cluster's
1861
  Tue Jul 17 11:00:20 2018                                                                                               Page   31
1862
 
1863
 
1864
 
1865
 
1866
 4291  F908FB  A5 3D         		lda	fdfmt
1867
 4292  F908FD  C9 01         		cmp	#1		; DD ibm disk?
1868
 4293  F908FF  D0 03         		bne	?10		; no
1869
 4294  F90901  20 AF 09      		jsr	?90		; pre-read cluster #4
1870
 4295  F90904  20 6D 0D      	?10:	jsr	mvldt		; move data to LDT
1871
 4296  F90907  A9 E0         		lda	#$E0		; update flag 2
1872
 4297  F90909  05 3D         		ora	fdfmt
1873
 4298  F9090B  9D 01 40      		sta	!P0LDT+ldt_fg2,x
1874
 4299  F9090E  9E 20 40      		stz	!P0LDT+ldt_cdlvl,x	; set to root directory
1875
 4300  F90911  20 CA 09      		jsr	?100		; setup BCB list for root, cluster #2,#3&#4
1876
 4301  F90914  A6 3F         	?15:	ldx	ldev
1877
 4302  F90916  18            		clc
1878
 4303  F90917  60            		rts
1879
 4304
1880
 4305  F90918  AA            	?20:	tax			; try to get media format
1881
 4306  F90919                		FDCGETFMT
1882
 4307  F90919  02 30         		cop	$30
1883
 4308  F9091B  04            		.DB	$04
1884
 4309                        		.MNLIST
1885
 4310  F9091C  B0 38         		bcs	?34		; unformatted disk?
1886
 4311  F9091E  84 3D         		sty	fdfmt		; save media format
1887
 4312  F90920  C0 01         		cpy	#1		; cbm format?
1888
 4313  F90922  D0 34         		bne	?35		; no, so return
1889
 4314  F90924  A9 49         		lda	#'I'		; send init command to cbm emulator
1890
 4315  F90926  85 04         		sta	bpath
1891
 4316  F90928  A5 3E         		lda	pdev
1892
 4317  F9092A  09 30         		ora	#'0'		; drive
1893
 4318  F9092C  85 05         		sta	bpath+1
1894
 4319  F9092E  64 06         		stz	bpath+2
1895
 4320  F90930  A9 04         		lda	#bpath		; address of command string
1896
 4321  F90932  A2 42         		ldx	#>P0OS
1897
 4322  F90934  A0 00         		ldy	#0
1898
 4323  F90936  20 F6 2E      		jsr	cbmfs_cmd
1899
 4324  F90939  B0 1B         		bcs	?34		; skip return address if error
1900
 4325  F9093B  A9 A1         		lda	#10100001B	; set flag 2
1901
 4326  F9093D  A6 40         		ldx	ldtcur
1902
 4327  F9093F  9D 01 40      		sta	!P0LDT+ldt_fg2,x
1903
 4328  F90942  80 12         		bra	?34		; skip return address & CF=0
1904
 4329
1905
 4330  F90944  A6 3E         	?30:	ldx	pdev		; read system track (track 0)
1906
 4331  F90946  DA            		phx			; phsycal drive
1907
 4332  F90947  A9 00         		lda	#0
1908
 4333  F90949  48            		pha			; track=0
1909
 4334  F9094A  BD D8 40      		lda	!P0LDT+sysbuf,x	; dma buffer #
1910
 4335  F9094D  48            		pha
1911
 4336  F9094E  A5 3D         		lda	fdfmt		; format
1912
 4337  F90950  48            		pha
1913
 4338  F90951                		FDCTKRD			; read whole track
1914
 4339  F90951  02 35         		cop	$35
1915
 4340  F90953  00            		.DB	$00
1916
 4341                        		.MNLIST
1917
 4342  F90954  90 02         		bcc	?35		; ok
1918
 4343  F90956  68            	?34:	pla			; discard return address
1919
 4344  F90957  68            		pla
1920
 4345  F90958  60            	?35:	rts
1921
 4346
1922
 4347  F90959  20 42 0C      	?40:	jsr	chk12		; check floppy disk PBR
1923
  Tue Jul 17 11:00:20 2018                                                                                               Page   32
1924
 
1925
 
1926
 
1927
 
1928
 4348  F9095C  90 FA         		bcc	?35		; ok
1929
 4349  F9095E  80 F6         		bra	?34		; skip return address
1930
 4350
1931
 4351  F90960  20 18 0D      	?50:	jsr	fcalc		; fat calc
1932
 4352  F90963  90 F3         		bcc	?35
1933
 4353  F90965  80 EF         		bra	?34		; skip return address
1934
 4354
1935
 4355  F90967  A6 40         	?60:	ldx	ldtcur		; compute free cluster's
1936
 4356  F90969                		ACC16
1937
 4357  F90969  C2 20         		rep	#PMFLAG
1938
 4358                        		.LONGA	on
1939
 4359                        		.MNLIST
1940
 4360  F9096B  BD 22 40      		lda	!P0LDT+ldt_fp,x
1941
 4361  F9096E  85 3A         		sta	tp
1942
 4362  F90970  BC 24 40      		ldy	!P0LDT+ldt_fp+2,x
1943
 4363  F90973  8B            		phb
1944
 4364  F90974  5A            		phy
1945
 4365  F90975  AB            		plb
1946
 4366  F90976  A2 00         		ldx	#0		; cluster number
1947
 4367  F90978                		CPU16
1948
 4368  F90978  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1949
 4369                        		.LONGA	on
1950
 4370                        		.LONGI	on
1951
 4371                        		.MNLIST
1952
 4372  F9097A  9B            		txy			; Y=fat table index
1953
 4373  F9097B  64 2E         		stz	freecnt
1954
 4374  F9097D  64 30         		stz	freecls
1955
 4375  F9097F  B1 3A         	?65:	lda	(tp),y		; even index cluster
1956
 4376  F90981  29 FF 0F      		and	#$0FFF
1957
 4377  F90984  D0 08         		bne	?70		; not free
1958
 4378  F90986  E6 2E         		inc	freecnt		; update free cluster's count
1959
 4379  F90988  A5 30         		lda	freecls		; already set?
1960
 4380  F9098A  D0 02         		bne	?70		; yes
1961
 4381  F9098C  86 30         		stx	freecls		; set first free cluster
1962
 4382  F9098E  E8            	?70:	inx
1963
 4383  F9098F  E4 28         		cpx	maxcls		; end of table?
1964
 4384  F90991  B0 18         		bcs	?80		; yes
1965
 4385  F90993  C8            		iny			; odd index cluster
1966
 4386  F90994  B1 3A         		lda	(tp),y
1967
 4387  F90996  4A            		lsr	a		; shift x 4
1968
 4388  F90997  4A            		lsr	a
1969
 4389  F90998  4A            		lsr	a
1970
 4390  F90999  4A            		lsr	a
1971
 4391  F9099A  D0 08         		bne	?75
1972
 4392  F9099C  E6 2E         		inc	freecnt		; update free cluster's count
1973
 4393  F9099E  A5 30         		lda	freecls		; already set?
1974
 4394  F909A0  D0 02         		bne	?75		; yes
1975
 4395  F909A2  86 30         		stx	freecls		; set first free cluster
1976
 4396  F909A4  C8            	?75:	iny
1977
 4397  F909A5  C8            		iny			; pointer to next cluster
1978
 4398  F909A6  E8            		inx
1979
 4399  F909A7  E4 28         		cpx	maxcls
1980
 4400  F909A9  90 D4         		bcc	?65
1981
 4401  F909AB                	?80:	CPU08
1982
 4402  F909AB  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1983
 4403                        		.LONGA	off
1984
 4404                        		.LONGI	off
1985
  Tue Jul 17 11:00:20 2018                                                                                               Page   33
1986
 
1987
 
1988
 
1989
 
1990
 4405                        		.MNLIST
1991
 4406  F909AD  AB            		plb
1992
 4407  F909AE  60            		rts
1993
 4408
1994
 4409  F909AF  A6 3E         	?90:	ldx	pdev		; pre-read cluster #4 DD disk
1995
 4410  F909B1  DA            		phx			; phsycal drive
1996
 4411  F909B2  F4 00 01      		pea	#$0100		; track=1, head=0
1997
 4412  F909B5  F4 02 01      		pea	#$0102		; start sec=1, sec num=2
1998
 4413  F909B8  BD D8 40      		lda	!P0LDT+sysbuf,x	; dma buffer #
1999
 4414  F909BB  18            		clc			; using first buffer after...
2000
 4415  F909BC  69 14         		adc	#20		; ...system track 0
2001
 4416  F909BE  48            		pha
2002
 4417  F909BF  A5 3D         		lda	fdfmt		; format
2003
 4418  F909C1  48            		pha
2004
 4419  F909C2                		FDCTKRD			; read whole track
2005
 4420  F909C2  02 35         		cop	$35
2006
 4421  F909C4  00            		.DB	$00
2007
 4422                        		.MNLIST
2008
 4423  F909C5  90 02         		bcc	?95		; ok
2009
 4424  F909C7  68            		pla			; discard return address
2010
 4425  F909C8  68            		pla
2011
 4426  F909C9  60            	?95:	rts
2012
 4427
2013
 4428  F909CA  A5 3F         	?100:	lda	ldev		; setup BCB list for root
2014
 4429  F909CC  85 04         		sta	tbdrv
2015
 4430  F909CE  64 07         		stz	tbcls+1
2016
 4431  F909D0  64 0B         		stz	tbhead+1
2017
 4432  F909D2  64 09         		stz	tblba+1
2018
 4433  F909D4  A6 3E         		ldx	pdev
2019
 4434  F909D6  A9 07         		lda	#$07		; first DD root sec
2020
 4435  F909D8  A4 3D         		ldy	fdfmt
2021
 4436  F909DA  F0 02         		beq	?105
2022
 4437  F909DC  A9 13         		lda	#$13		; first HD root sec
2023
 4438  F909DE  18            	?105:	clc
2024
 4439  F909DF  7D D8 40      		adc	!P0LDT+sysbuf,x
2025
 4440  F909E2  AA            		tax
2026
 4441  F909E3  A0 02         		ldy	#DMABNK		; bank for buffer #00..#7F
2027
 4442  F909E5  0A            		asl	a		; get high pointer
2028
 4443  F909E6  90 01         		bcc	?110
2029
 4444  F909E8  C8            		iny			; next bank
2030
 4445  F909E9  84 10         	?110:	sty	tbdma
2031
 4446  F909EB  64 0E         		stz	tbptr
2032
 4447  F909ED  3A            		dec	a
2033
 4448  F909EE  3A            		dec	a
2034
 4449  F909EF  85 0F         		sta	tbptr+1
2035
 4450  F909F1  CA            		dex
2036
 4451  F909F2  86 11         		stx	tbdma+1		; dma buffer #
2037
 4452  F909F4  A2 00         		ldx	#0
2038
 4453  F909F6  A5 3D         		lda	fdfmt
2039
 4454  F909F8  F0 02         		beq	?115
2040
 4455  F909FA  A2 0E         		ldx	#?501
2041
 4456  F909FC  8B            	?115:	phb
2042
 4457  F909FD  A9 01         		lda	#WKB
2043
 4458  F909FF  48            		pha
2044
 4459  F90A00  AB            		plb
2045
 4460  F90A01                		INDEX16
2046
 4461  F90A01  C2 10         		rep	#PXFLAG
2047
  Tue Jul 17 11:00:20 2018                                                                                               Page   34
2048
 
2049
 
2050
 
2051
 
2052
 4462                        		.LONGI	on
2053
 4463                        		.MNLIST
2054
 4464  F90A03  A0 00 CC      		ldy	#dma0s
2055
 4465  F90A06  A5 3E         		lda	pdev
2056
 4466  F90A08  F0 03         		beq	?120
2057
 4467  F90A0A  A0 10 CD      		ldy	#dma1s
2058
 4468  F90A0D  BF 7C 0A F9   	?120:	lda	>?500,x		; lba
2059
 4469  F90A11  F0 5A         		beq	?125		; end of list
2060
 4470  F90A13  85 08         		sta	tblba
2061
 4471  F90A15  BF 9C 0A F9   		lda	>?510,x		; sec. offset
2062
 4472  F90A19  85 05         		sta	tbdrv+1
2063
 4473  F90A1B  BF 1C 0B F9   		lda	>?550,x		; cluster #
2064
 4474  F90A1F  85 06         		sta	tbcls
2065
 4475  F90A21  BF DC 0A F9   		lda	>?530,x		; head #
2066
 4476  F90A25  85 0A         		sta	tbhead
2067
 4477  F90A27  BF BC 0A F9   		lda	>?520,x		; track #
2068
 4478  F90A2B  85 0C         		sta	tbtrk
2069
 4479  F90A2D  BF FC 0A F9   		lda	>?540,x		; sector #
2070
 4480  F90A31  85 0D         		sta	tbtrk+1
2071
 4481  F90A33  A5 0F         		lda	tbptr+1		; update buffer ptr
2072
 4482  F90A35  1A            		inc	a
2073
 4483  F90A36  1A            		inc	a
2074
 4484  F90A37  85 0F         		sta	tbptr+1
2075
 4485  F90A39  E6 11         		inc	tbdma+1		; update dma buffer #
2076
 4486  F90A3B                		ACC16CLC
2077
 4487  F90A3B  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
2078
 4488                        		.LONGA	on
2079
 4489                        		.MNLIST
2080
 4490  F90A3D  A5 04         		lda	tbdrv
2081
 4491  F90A3F  99 02 00      		sta	bcb_drv,y
2082
 4492  F90A42  A5 06         		lda	tbcls
2083
 4493  F90A44  99 04 00      		sta	bcb_cls,y
2084
 4494  F90A47  A5 08         		lda	tblba
2085
 4495  F90A49  99 06 00      		sta	bcb_lba,y
2086
 4496  F90A4C  A5 0A         		lda	tbhead
2087
 4497  F90A4E  99 08 00      		sta	bcb_head,y
2088
 4498  F90A51  A5 0C         		lda	tbtrk
2089
 4499  F90A53  99 0A 00      		sta	bcb_trk,y
2090
 4500  F90A56  A5 0E         		lda	tbptr
2091
 4501  F90A58  99 0C 00      		sta	bcb_ptr,y
2092
 4502  F90A5B  A5 10         		lda	tbdma
2093
 4503  F90A5D  99 0E 00      		sta	bcb_dma,y
2094
 4504  F90A60  98            		tya
2095
 4505  F90A61  69 10 00      		adc	#BCBSIZE
2096
 4506  F90A64  99 00 00      		sta	bcb_next,y
2097
 4507  F90A67  A8            		tay
2098
 4508  F90A68                		ACC08
2099
 4509  F90A68  E2 20         		sep	#PMFLAG
2100
 4510                        		.LONGA	off
2101
 4511                        		.MNLIST
2102
 4512  F90A6A  E8            		inx
2103
 4513  F90A6B  80 A0         		bra	?120
2104
 4514  F90A6D                	?125:	ACC16
2105
 4515  F90A6D  C2 20         		rep	#PMFLAG
2106
 4516                        		.LONGA	on
2107
 4517                        		.MNLIST
2108
 4518  F90A6F  98            		tya
2109
  Tue Jul 17 11:00:20 2018                                                                                               Page   35
2110
 
2111
 
2112
 
2113
 
2114
 4519  F90A70  38            		sec
2115
 4520  F90A71  E9 10 00      		sbc	#BCBSIZE
2116
 4521  F90A74  AA            		tax
2117
 4522  F90A75  9E 00 00      		stz	!bcb_next,x
2118
 4523  F90A78                		CPU08
2119
 4524  F90A78  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
2120
 4525                        		.LONGA	off
2121
 4526                        		.LONGI	off
2122
 4527                        		.MNLIST
2123
 4528  F90A7A  AB            		plb
2124
 4529  F90A7B  60            		rts
2125
 4530
2126
 4531                        		; DD system track lba
2127
 4532  F90A7C  07 08 09 0A 0B 	?500:	.DB	$07, $08, $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $11, $12
2128
               0C 0D 0E 0F 10
2129
               11 12
2130
 4533  F90A88  13 00         		.DB	$13, $00
2131
 4534          00000E        	?501	.EQU	$-?500
2132
 4535                        		; HD system track lba
2133
 4536  F90A8A  13 14 15 16 17 		.DB	$13, $14, $15, $16, $17, $18, $19, $1A, $1B, $1C, $1D, $1E
2134
               18 19 1A 1B 1C
2135
               1D 1E
2136
 4537  F90A96  1F 20 21 22 23 		.DB	$1F, $20, $21, $22, $23, $00
2137
               00
2138
 4538
2139
 4539                        	?510:	; DD sector offset
2140
 4540  F90A9C  00 01 02 03 04 		.DB	0, 1, 2, 3, 4, 5, 6, 0, 1, 0, 1, 0, 1, 0
2141
               05 06 00 01 00
2142
               01 00 01 00
2143
 4541                        		; HD sector offset
2144
 4542  F90AAA  00 01 02 03 04 		.DB	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0, 0
2145
               05 06 07 08 09
2146
               0A 0B 0C 0D 00
2147
               00 00 00
2148
 4543  F90ABC
2149
 4544                        	?520:	; DD track
2150
 4545  F90ABC  00 00 00 00 00 		.DB	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0
2151
               00 00 00 00 00
2152
               00 01 01 00
2153
 4546                        		; HD track
2154
 4547  F90ACA  00 00 00 00 00 		.DB	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
2155
               00 00 00 00 00
2156
               00 00 00 00 00
2157
               00 00 00
2158
 4548  F90ADC
2159
 4549                        	?530:	; DD head
2160
 4550  F90ADC  00 00 01 01 01 		.DB	0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
2161
               01 01 01 01 01
2162
               01 00 00 00
2163
 4551                        		; HD head
2164
 4552  F90AEA  01 01 01 01 01 		.DB	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
2165
               01 01 01 01 01
2166
               01 01 01 01 01
2167
               01 01 00
2168
 4553  F90AFC
2169
 4554                        	?540:	; DD sector #
2170
 4555  F90AFC  08 09 01 02 03 		.DB	8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 0
2171
  Tue Jul 17 11:00:20 2018                                                                                               Page   36
2172
 
2173
 
2174
 
2175
 
2176
               04 05 06 07 08
2177
               09 01 02 00
2178
 4556                        		; HD sector #
2179
 4557  F90B0A  02 03 04 05 06 		.DB	2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
2180
               07 08 09 0A 0B
2181
               0C 0D 0E 0F
2182
 4558  F90B18  10 11 12 00   		.DB	16, 17, 18, 0
2183
 4559
2184
 4560                        	?550:	; DD cluster #
2185
 4561  F90B1C  00 00 00 00 00 		.DB	0, 0, 0, 0, 0, 0, 0, 2, 2, 3, 3, 4, 4, 0
2186
               00 00 02 02 03
2187
               03 04 04 00
2188
 4562                        		; HD cluster #
2189
 4563  F90B2A  00 00 00 00 00 		.DB	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
2190
               00 00 00 00 00
2191
               00 00 00 00
2192
 4564  F90B38  02 03 04 00   		.DB	2, 3, 4, 0
2193
 4565
2194
 4566                        	; check fat16 volume in pbr record on usb #0 disk
2195
 4567  F90B3C                	usbchk16:
2196
 4568  F90B3C  A9 00         		lda	#<PBR0USB
2197
 4569  F90B3E  85 32         		sta	pbrp
2198
 4570  F90B40  A9 96         		lda	#>PBR0USB
2199
 4571  F90B42  85 33         		sta	pbrp+1
2200
 4572  F90B44  A9 01         		lda	#^PBR0USB
2201
 4573  F90B46  85 34         		sta	pbrp+2
2202
 4574  F90B48                		ACC16
2203
 4575  F90B48  C2 20         		rep	#PMFLAG
2204
 4576                        		.LONGA	on
2205
 4577                        		.MNLIST
2206
 4578  F90B4A  AD 2A 00      		lda	!usbmbr		; partition start
2207
 4579  F90B4D  85 08         		sta	hidsec		; this is also hidden sectors count
2208
 4580  F90B4F  AD 2C 00      		lda	!usbmbr+2
2209
 4581  F90B52  29 FF 00      		and	#$00FF
2210
 4582  F90B55  85 0A         		sta	hidsec+2
2211
 4583  F90B57  AD 3A 00      		lda	!usbprt		; total partition sector's
2212
 4584  F90B5A  85 0C         		sta	totsec
2213
 4585  F90B5C  AD 3C 00      		lda	!usbprt+2
2214
 4586  F90B5F  85 0E         		sta	totsec+2
2215
 4587  F90B61                		ACC08
2216
 4588  F90B61  E2 20         		sep	#PMFLAG
2217
 4589                        		.LONGA	off
2218
 4590                        		.MNLIST
2219
 4591  F90B63  80 2E         		bra	chk16c
2220
 4592  F90B65
2221
 4593                        	; check fat16 volume in pbr record
2222
 4594  F90B65                	chk16:
2223
 4595  F90B65  A9 FF         		lda	#$FF
2224
 4596  F90B67  85 3D         		sta	fdfmt
2225
 4597  F90B69  A5 3E         		lda	pdev		; phisycal drive
2226
 4598  F90B6B  0A            		asl	a
2227
 4599  F90B6C  0A            		asl	a
2228
 4600  F90B6D  AA            		tax
2229
 4601  F90B6E                		ACC16
2230
 4602  F90B6E  C2 20         		rep	#PMFLAG
2231
 4603                        		.LONGA	on
2232
 4604                        		.MNLIST
2233
  Tue Jul 17 11:00:20 2018                                                                                               Page   37
2234
 
2235
 
2236
 
2237
 
2238
 4605  F90B70  BD 22 00      		lda	!atambr,x	; partition start
2239
 4606  F90B73  85 08         		sta	hidsec		; this is also hidden sectors count
2240
 4607  F90B75  BD 24 00      		lda	!atambr+2,x
2241
 4608  F90B78  29 FF 00      		and	#$00FF
2242
 4609  F90B7B  85 0A         		sta	hidsec+2
2243
 4610  F90B7D  BD 32 00      		lda	!ataprt,x	; total partition sector's
2244
 4611  F90B80  85 0C         		sta	totsec
2245
 4612  F90B82  BD 34 00      		lda	!ataprt+2,x
2246
 4613  F90B85  85 0E         		sta	totsec+2
2247
 4614  F90B87  A6 40         		ldx	ldtcur		; LDT ptr
2248
 4615  F90B89  BD 26 40      		lda	!P0LDT+ldt_pbr,x
2249
 4616  F90B8C  85 32         		sta	pbrp
2250
 4617  F90B8E  BC 28 40      		ldy	!P0LDT+ldt_pbr+2,x
2251
 4618  F90B91  84 34         		sty	pbrp+2
2252
 4619
2253
 4620                        	; entry point to check usb #0 disk
2254
 4621  F90B93                	chk16c:
2255
 4622  F90B93                		ACC16
2256
 4623  F90B93  C2 20         		rep	#PMFLAG
2257
 4624                        		.LONGA	on
2258
 4625                        		.MNLIST
2259
 4626  F90B95  A6 33         		ldx	pbrp+1
2260
 4627  F90B97  E8            		inx
2261
 4628  F90B98  86 33         		stx	pbrp+1
2262
 4629  F90B9A  A9 F5 FF      		lda	#MAXF16
2263
 4630  F90B9D  85 10         		sta	maxcnt
2264
 4631  F90B9F  A0 FE         		ldy	#$FE		; pointer to pbr signature
2265
 4632  F90BA1  B7 32         		lda	[pbrp],y
2266
 4633  F90BA3  C9 55 AA      		cmp	#$AA55
2267
 4634  F90BA6  D0 67         		bne	?10		; signature error
2268
 4635  F90BA8  CA            		dex
2269
 4636  F90BA9  86 33         		stx	pbrp+1
2270
 4637  F90BAB  A0 0B         		ldy	#$0B		; pointer to bytes per sector
2271
 4638  F90BAD  B7 32         		lda	[pbrp],y
2272
 4639  F90BAF  C9 00 02      		cmp	#$0200		; must be always 512 bytes per sector
2273
 4640  F90BB2  D0 5B         		bne	?10		; error
2274
 4641  F90BB4  A0 1C         		ldy	#$1C		; pointer to hidden sector's count
2275
 4642  F90BB6  B7 32         		lda	[pbrp],y	; typical value: $3F
2276
 4643  F90BB8  C5 08         		cmp	hidsec		; must match
2277
 4644  F90BBA  D0 53         		bne	?10
2278
 4645  F90BBC  C8            		iny
2279
 4646  F90BBD  C8            		iny
2280
 4647  F90BBE  B7 32         		lda	[pbrp],y
2281
 4648  F90BC0  C5 0A         		cmp	hidsec+2
2282
 4649  F90BC2  D0 4B         		bne	?10
2283
 4650  F90BC4  C9 00 00      		cmp	#0
2284
 4651  F90BC7  D0 46         		bne	?10		; must be 0
2285
 4652  F90BC9  A0 0E         		ldy	#$0E		; pointer to reserved sector's
2286
 4653  F90BCB  B7 32         		lda	[pbrp],y	; typical value: 1 (no mandatory)
2287
 4654  F90BCD  85 16         		sta	rsvsec
2288
 4655  F90BCF  A0 11         		ldy	#$11		; pointer to root dir entry #
2289
 4656  F90BD1  B7 32         		lda	[pbrp],y
2290
 4657  F90BD3  F0 3A         		beq	?10		; fat32?
2291
 4658  F90BD5  C9 00 02      		cmp	#$0200		; typical value: not mandatory...
2292
 4659  F90BD8  D0 35         		bne	?10		; ...but this will be
2293
 4660  F90BDA  85 1C         		sta	rootent
2294
 4661  F90BDC  4A            		lsr	a		; divide by 16...
2295
  Tue Jul 17 11:00:20 2018                                                                                               Page   38
2296
 
2297
 
2298
 
2299
 
2300
 4662  F90BDD  4A            		lsr	a
2301
 4663  F90BDE  4A            		lsr	a
2302
 4664  F90BDF  4A            		lsr	a		;...to get root dir size in sec's
2303
 4665  F90BE0  85 1A         		sta	rootsiz
2304
 4666  F90BE2  A0 13         		ldy	#$13		; pointer to tot. sec16
2305
 4667  F90BE4  B7 32         		lda	[pbrp],y
2306
 4668  F90BE6  F0 0A         		beq	?06		; invalid: is valid field tot. sec32
2307
 4669  F90BE8  C5 0C         		cmp	totsec
2308
 4670  F90BEA  D0 23         		bne	?10		; error
2309
 4671  F90BEC  A5 0E         		lda	totsec+2	; must be 0
2310
 4672  F90BEE  D0 1F         		bne	?10		; errore
2311
 4673  F90BF0  F0 10         		beq	?08		; ok
2312
 4674  F90BF2  A0 20         	?06:	ldy	#$20		; pointer to tot. sec32
2313
 4675  F90BF4  B7 32         		lda	[pbrp],y
2314
 4676  F90BF6  C5 0C         		cmp	totsec
2315
 4677  F90BF8  D0 15         		bne	?10		; error
2316
 4678  F90BFA  C8            		iny
2317
 4679  F90BFB  C8            		iny
2318
 4680  F90BFC  B7 32         		lda	[pbrp],y
2319
 4681  F90BFE  C5 0E         		cmp	totsec+2
2320
 4682  F90C00  D0 0D         		bne	?10		; error
2321
 4683  F90C02  A0 16         	?08:	ldy	#$16		; pointer to fat size (FAT16)
2322
 4684  F90C04  B7 32         		lda	[pbrp],y
2323
 4685  F90C06  85 18         		sta	fatsiz
2324
 4686  F90C08  F0 05         		beq	?10		; hmmm... is fat32... not good
2325
 4687  F90C0A  C9 01 01      		cmp	#257		; fat16 table size limited to 256 sec. max
2326
 4688  F90C0D  80 01         		bra	?12
2327
 4689  F90C0F  38            	?10:	sec
2328
 4690  F90C10                	?12:	CPU08
2329
 4691  F90C10  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
2330
 4692                        		.LONGA	off
2331
 4693                        		.LONGI	off
2332
 4694                        		.MNLIST
2333
 4695  F90C12  B0 20         		bcs	?18		; error
2334
 4696  F90C14  A0 15         		ldy	#$15		; pointer to media byte
2335
 4697  F90C16  B7 32         		lda	[pbrp],y	; must be $F8
2336
 4698  F90C18  C9 F8         		cmp	#$F8
2337
 4699  F90C1A  D0 17         		bne	?16
2338
 4700  F90C1C  A0 10         		ldy	#$10		; pointer to count of fat table's
2339
 4701  F90C1E  B7 32         		lda	[pbrp],y
2340
 4702  F90C20  C9 02         		cmp	#2		; must be 2
2341
 4703  F90C22  D0 0F         		bne	?16
2342
 4704  F90C24  A0 0D         		ldy	#$0D		; pointer to sector(s) per cluster
2343
 4705  F90C26  B7 32         		lda	[pbrp],y
2344
 4706  F90C28  A2 06         		ldx	#CLSCNT-1
2345
 4707  F90C2A  DF 61 1C F9   	?14:	cmp	>CLSSIZE,x
2346
 4708  F90C2E  F0 05         		beq	?20
2347
 4709  F90C30  CA            		dex
2348
 4710  F90C31  10 F7         		bpl	?14
2349
 4711  F90C33  38            	?16:	sec
2350
 4712  F90C34  60            	?18:	rts
2351
 4713  F90C35  85 35         	?20:	sta	clssiz
2352
 4714  F90C37  3A            		dec	a
2353
 4715  F90C38  85 37         		sta	clsmod
2354
 4716  F90C3A  BF 68 1C F9   		lda	>CLSSHIFT,x
2355
 4717  F90C3E  85 36         		sta	clsshf
2356
 4718  F90C40  18            		clc
2357
  Tue Jul 17 11:00:20 2018                                                                                               Page   39
2358
 
2359
 
2360
 
2361
 
2362
 4719  F90C41  60            		rts
2363
 4720
2364
 4721                        	; check floppy disk PBR
2365
 4722  F90C42                	chk12:
2366
 4723                        		;ldx	pdev		; phisycal drive
2367
 4724                        		;lda	!fdcdrv,x	; get format from bios
2368
 4725                        		;and	#00000011B
2369
 4726                        		;sta	fdfmt		; format to check (0 or 2)
2370
 4727  F90C42  A5 3D         		lda	fdfmt
2371
 4728  F90C44  4A            		lsr	a		; index DD/HD
2372
 4729  F90C45  85 2A         		sta	fdix
2373
 4730  F90C47  0A            		asl	a
2374
 4731  F90C48  85 4F         		sta	fd2ix
2375
 4732  F90C4A                		ACC16
2376
 4733  F90C4A  C2 20         		rep	#PMFLAG
2377
 4734                        		.LONGA	on
2378
 4735                        		.MNLIST
2379
 4736  F90C4C  A9 F5 0F      		lda	#MAXF12
2380
 4737  F90C4F  85 10         		sta	maxcnt
2381
 4738  F90C51  A6 40         		ldx	ldtcur		; LDT ptr
2382
 4739  F90C53  BD 26 40      		lda	!P0LDT+ldt_pbr,x
2383
 4740  F90C56  85 32         		sta	pbrp
2384
 4741  F90C58  BC 28 40      		ldy	!P0LDT+ldt_pbr+2,x
2385
 4742  F90C5B  84 34         		sty	pbrp+2
2386
 4743  F90C5D  A6 33         		ldx	pbrp+1
2387
 4744  F90C5F  E8            		inx
2388
 4745  F90C60  86 33         		stx	pbrp+1
2389
 4746  F90C62  A0 FE         		ldy	#$FE		; pointer to pbr signature
2390
 4747  F90C64  B7 32         		lda	[pbrp],y
2391
 4748  F90C66  C9 55 AA      		cmp	#$AA55
2392
 4749  F90C69  D0 79         		bne	?10		; signature error
2393
 4750  F90C6B  CA            		dex
2394
 4751  F90C6C  86 33         		stx	pbrp+1
2395
 4752  F90C6E  A6 4F         		ldx	fd2ix		; X=DD/HD double index
2396
 4753  F90C70  A0 0B         		ldy	#$0B		; pointer to bytes per sector
2397
 4754  F90C72  B7 32         		lda	[pbrp],y
2398
 4755  F90C74  C9 00 02      		cmp	#$0200		; must be always 512 bytes per sector
2399
 4756  F90C77  D0 6B         		bne	?10		; error
2400
 4757  F90C79  A0 0E         		ldy	#$0E		; pointer to reserved sector's
2401
 4758  F90C7B  B7 32         		lda	[pbrp],y	; mandatory value: 1
2402
 4759  F90C7D  85 16         		sta	rsvsec
2403
 4760  F90C7F  3A            		dec	a
2404
 4761  F90C80  D0 62         		bne	?10		; error
2405
 4762  F90C82  A0 11         		ldy	#$11		; pointer to root dir entry #
2406
 4763  F90C84  B7 32         		lda	[pbrp],y
2407
 4764  F90C86  DF 6F 1C F9   		cmp	>FDROOT,x	; mandatory
2408
 4765  F90C8A  D0 58         		bne	?10		; error
2409
 4766  F90C8C  85 1C         		sta	rootent
2410
 4767  F90C8E  4A            		lsr	a		; divide by 16...
2411
 4768  F90C8F  4A            		lsr	a
2412
 4769  F90C90  4A            		lsr	a
2413
 4770  F90C91  4A            		lsr	a		;...to get root dir size in sec's
2414
 4771  F90C92  85 1A         		sta	rootsiz
2415
 4772  F90C94  A0 13         		ldy	#$13		; pointer to tot. sec.
2416
 4773  F90C96  B7 32         		lda	[pbrp],y
2417
 4774  F90C98  DF 73 1C F9   		cmp	>FDSEC,x
2418
 4775  F90C9C  D0 46         		bne	?10		; error
2419
  Tue Jul 17 11:00:20 2018                                                                                               Page   40
2420
 
2421
 
2422
 
2423
 
2424
 4776  F90C9E  85 0C         		sta	totsec
2425
 4777  F90CA0  A0 16         		ldy	#$16		; pointer to fat size (FAT12)
2426
 4778  F90CA2  B7 32         		lda	[pbrp],y
2427
 4779  F90CA4  DF 77 1C F9   		cmp	>FDFAT,x
2428
 4780  F90CA8  D0 3A         		bne	?10		; error
2429
 4781  F90CAA  85 18         		sta	fatsiz
2430
 4782  F90CAC  A0 18         		ldy	#$18		; pointer to sector's per track
2431
 4783  F90CAE  B7 32         		lda	[pbrp],y
2432
 4784  F90CB0  DF 7B 1C F9   		cmp	>FDSPT,x
2433
 4785  F90CB4  D0 2E         		bne	?10		; error
2434
 4786  F90CB6  A0 1A         		ldy	#$1A		; pointer to sides count #
2435
 4787  F90CB8  B7 32         		lda	[pbrp],y
2436
 4788  F90CBA  C9 02 00      		cmp	#2		; must be 2
2437
 4789  F90CBD  D0 25         		bne	?10		; error
2438
 4790  F90CBF  A0 1C         		ldy	#$1C		; pointer to hidden sec
2439
 4791  F90CC1  B7 32         		lda	[pbrp],y
2440
 4792  F90CC3  D0 1F         		bne	?10		; must be 0
2441
 4793  F90CC5  A0 1E         		ldy	#$1E
2442
 4794  F90CC7  B7 32         		lda	[pbrp],y
2443
 4795  F90CC9  D0 19         		bne	?10		; must be 0
2444
 4796  F90CCB  A0 20         		ldy	#$20		; tot sec32
2445
 4797  F90CCD  B7 32         		lda	[pbrp],y
2446
 4798  F90CCF  D0 13         		bne	?10		; must be 0
2447
 4799  F90CD1  85 08         		sta	hidsec
2448
 4800  F90CD3  85 0A         		sta	hidsec+2
2449
 4801  F90CD5  85 0E         		sta	totsec+2
2450
 4802  F90CD7  A0 22         		ldy	#$22
2451
 4803  F90CD9  B7 32         		lda	[pbrp],y
2452
 4804  F90CDB  D0 07         		bne	?10		; must be 0
2453
 4805  F90CDD  A0 24         		ldy	#$24		; rsvd1 & rsvd2
2454
 4806  F90CDF  B7 32         		lda	[pbrp],y
2455
 4807  F90CE1  18            		clc
2456
 4808  F90CE2  F0 01         		beq	?12		; must be 0
2457
 4809  F90CE4  38            	?10:	sec
2458
 4810  F90CE5                	?12:	ACC08
2459
 4811  F90CE5  E2 20         		sep	#PMFLAG
2460
 4812                        		.LONGA	off
2461
 4813                        		.MNLIST
2462
 4814  F90CE7  B0 2A         		bcs	?16		; exit&error
2463
 4815  F90CE9  A6 2A         		ldx	fdix
2464
 4816  F90CEB  A0 0D         		ldy	#$0D		; pointer to sector(s) per cluster
2465
 4817  F90CED  B7 32         		lda	[pbrp],y
2466
 4818  F90CEF  DF 7F 1C F9   		cmp	>FDCLS,x
2467
 4819  F90CF3  D0 1D         		bne	?14		; error
2468
 4820  F90CF5  85 35         		sta	clssiz
2469
 4821  F90CF7  3A            		dec	a
2470
 4822  F90CF8  85 37         		sta	clsmod
2471
 4823  F90CFA  BF 81 1C F9   		lda	>FDSHF,x
2472
 4824  F90CFE  85 36         		sta	clsshf
2473
 4825  F90D00  A0 10         		ldy	#$10		; pointer to count of fat table's
2474
 4826  F90D02  B7 32         		lda	[pbrp],y
2475
 4827  F90D04  C9 02         		cmp	#2		; must be 2
2476
 4828  F90D06  D0 0A         		bne	?14
2477
 4829  F90D08  A0 15         		ldy	#$15		; pointer to media byte
2478
 4830  F90D0A  B7 32         		lda	[pbrp],y
2479
 4831  F90D0C  DF 83 1C F9   		cmp	>FDMEDIA,x
2480
 4832  F90D10  F0 02         		beq	?18
2481
  Tue Jul 17 11:00:20 2018                                                                                               Page   41
2482
 
2483
 
2484
 
2485
 
2486
 4833  F90D12  38            	?14:	sec
2487
 4834  F90D13  60            	?16:	rts
2488
 4835  F90D14  85 2B         	?18:	sta	media
2489
 4836  F90D16  18            		clc
2490
 4837  F90D17  60            		rts
2491
 4838
2492
 4839                        	; compute fat param's
2493
 4840  F90D18                	fcalc:
2494
 4841  F90D18                		ACC16CLC
2495
 4842  F90D18  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
2496
 4843                        		.LONGA	on
2497
 4844                        		.MNLIST
2498
 4845  F90D1A  A5 08         		lda	hidsec
2499
 4846  F90D1C  65 16         		adc	rsvsec
2500
 4847  F90D1E  B0 4A         		bcs	?14		; error
2501
 4848  F90D20  85 22         		sta	fat1		; fat1 table lba
2502
 4849  F90D22  65 18         		adc	fatsiz
2503
 4850  F90D24  85 24         		sta	fat2		; fat2 table lba
2504
 4851  F90D26  B0 42         		bcs	?14		; error
2505
 4852  F90D28  65 18         		adc	fatsiz
2506
 4853  F90D2A  B0 3E         		bcs	?14		; error
2507
 4854  F90D2C  85 20         		sta	root		; root dir. lba
2508
 4855  F90D2E  65 1A         		adc	rootsiz
2509
 4856  F90D30  B0 38         		bcs	?14		; error
2510
 4857  F90D32  85 26         		sta	start		; first data sector lba
2511
 4858  F90D34  38            		sec
2512
 4859  F90D35  E5 08         		sbc	hidsec
2513
 4860  F90D37  85 12         		sta	first		; first relative data sec
2514
 4861  F90D39  38            		sec
2515
 4862  F90D3A  A5 0C         		lda	totsec		; tot. data sec
2516
 4863  F90D3C  E5 12         		sbc	first
2517
 4864  F90D3E  85 14         		sta	clscnt		; cluster count
2518
 4865  F90D40  A5 0E         		lda	totsec+2
2519
 4866  F90D42  E9 00 00      		sbc	#0
2520
 4867  F90D45  A4 36         		ldy	clsshf
2521
 4868  F90D47  F0 06         		beq	?12		; no shift
2522
 4869  F90D49  4A            	?10:	lsr	a
2523
 4870  F90D4A  66 14         		ror	clscnt
2524
 4871  F90D4C  88            		dey
2525
 4872  F90D4D  D0 FA         		bne	?10
2526
 4873  F90D4F  48            	?12:	pha
2527
 4874  F90D50  68            		pla
2528
 4875  F90D51  38            		sec
2529
 4876  F90D52  D0 16         		bne	?14		; error: must be 0
2530
 4877  F90D54  A5 14         		lda	clscnt
2531
 4878  F90D56  C5 10         		cmp	maxcnt
2532
 4879  F90D58  90 03         		bcc	?13
2533
 4880  F90D5A  A9 F4 FF      		lda	#MAXF16-1	; limit max. count
2534
 4881  F90D5D  1A            	?13:	inc	a		; here CF=0
2535
 4882  F90D5E  1A            		inc	a		; max. usable cluster+1=N+2 (2..N+1)
2536
 4883  F90D5F  85 28         		sta	maxcls
2537
 4884  F90D61  A6 35         		ldx	clssiz
2538
 4885  F90D63  8A            		txa			; B=0, A=clssiz
2539
 4886  F90D64  0A            		asl	a		; 16 entries per sec...
2540
 4887  F90D65  0A            		asl	a
2541
 4888  F90D66  0A            		asl	a
2542
 4889  F90D67  0A            		asl	a		; here CF=0
2543
  Tue Jul 17 11:00:20 2018                                                                                               Page   42
2544
 
2545
 
2546
 
2547
 
2548
 4890  F90D68  85 1E         		sta	clsent		; entries in cluster
2549
 4891  F90D6A                	?14:	ACC08
2550
 4892  F90D6A  E2 20         		sep	#PMFLAG
2551
 4893                        		.LONGA	off
2552
 4894                        		.MNLIST
2553
 4895  F90D6C  60            		rts
2554
 4896
2555
 4897                        	; move computed fat var's to LDT
2556
 4898  F90D6D                	mvldt:
2557
 4899  F90D6D  A6 40         		ldx	ldtcur
2558
 4900  F90D6F                		ACC16
2559
 4901  F90D6F  C2 20         		rep	#PMFLAG
2560
 4902                        		.LONGA	on
2561
 4903                        		.MNLIST
2562
 4904  F90D71  A5 20         		lda	root
2563
 4905  F90D73  9D 02 40      		sta	!P0LDT+ldt_root,x
2564
 4906  F90D76  A5 22         		lda	fat1
2565
 4907  F90D78  9D 04 40      		sta	!P0LDT+ldt_fat1,x
2566
 4908  F90D7B  A5 24         		lda	fat2
2567
 4909  F90D7D  9D 06 40      		sta	!P0LDT+ldt_fat2,x
2568
 4910  F90D80  A5 26         		lda	start
2569
 4911  F90D82  9D 08 40      		sta	!P0LDT+ldt_cls,x
2570
 4912  F90D85  A5 28         		lda	maxcls
2571
 4913  F90D87  9D 0A 40      		sta	!P0LDT+ldt_max,x
2572
 4914  F90D8A  A5 1C         		lda	rootent
2573
 4915  F90D8C  9D 0C 40      		sta	!P0LDT+ldt_rent,x
2574
 4916  F90D8F  A5 1E         		lda	clsent
2575
 4917  F90D91  9D 0E 40      		sta	!P0LDT+ldt_cent,x
2576
 4918  F90D94  A5 2E         		lda	freecnt
2577
 4919  F90D96  9D 12 40      		sta	!P0LDT+ldt_free,x
2578
 4920  F90D99  A5 30         		lda	freecls
2579
 4921  F90D9B  9D 14 40      		sta	!P0LDT+ldt_nxt,x
2580
 4922  F90D9E                		ACC08
2581
 4923  F90D9E  E2 20         		sep	#PMFLAG
2582
 4924                        		.LONGA	off
2583
 4925                        		.MNLIST
2584
 4926  F90DA0  A5 35         		lda	clssiz
2585
 4927  F90DA2  9D 18 40      		sta	!P0LDT+ldt_csiz,x
2586
 4928  F90DA5  A5 36         		lda	clsshf
2587
 4929  F90DA7  9D 19 40      		sta	!P0LDT+ldt_cshf,x
2588
 4930  F90DAA  A5 18         		lda	fatsiz
2589
 4931  F90DAC  9D 16 40      		sta	!P0LDT+ldt_fsiz,x
2590
 4932  F90DAF  A5 1A         		lda	rootsiz
2591
 4933  F90DB1  9D 1A 40      		sta	!P0LDT+ldt_rsiz,x
2592
 4934  F90DB4  A5 37         		lda	clsmod
2593
 4935  F90DB6  9D 1B 40      		sta	!P0LDT+ldt_mcls,x
2594
 4936  F90DB9  A5 3D         		lda	fdfmt
2595
 4937  F90DBB  9D 29 40      		sta	!P0LDT+ldt_fmt,x
2596
 4938  F90DBE  60            		rts
2597
 4939
2598
 4940                        	;---------------------------------------------------------------------------
2599
 4941                        	; new fat file system
2600
 4942                        	;---------------------------------------------------------------------------
2601
 4943
2602
 4944                        	; make a new fresh fat12 file system on floppy disk
2603
 4945                        	; in:	A=format (0 or 2)
2604
 4946                        	;	X=logical drive
2605
  Tue Jul 17 11:00:20 2018                                                                                               Page   43
2606
 
2607
 
2608
 
2609
 
2610
 4947                        	;	Y=$FF if label is specified
2611
 4948  F90DBF                	newf12:
2612
 4949  F90DBF  85 3D         		sta	fdfmt
2613
 4950  F90DC1  86 3F         		stx	ldev
2614
 4951  F90DC3  84 41         		sty	lflag
2615
 4952  F90DC5  4A            		lsr	a
2616
 4953  F90DC6  85 2A         		sta	fdix		; DD/HD index
2617
 4954  F90DC8  9B            		txy
2618
 4955  F90DC9  BE D2 40      		ldx	!P0LDT+ldtp,y
2619
 4956  F90DCC  86 40         		stx	ldtcur
2620
 4957  F90DCE  BD 00 40      		lda	!P0LDT+ldt_fg1,x
2621
 4958  F90DD1  29 03         		and	#3
2622
 4959  F90DD3  85 3E         		sta	pdev		; phisycal drive
2623
 4960  F90DD5  24 41         		bit	lflag
2624
 4961  F90DD7  30 0C         		bmi	?10		; label specified
2625
 4962  F90DD9  A2 0A         		ldx	#10		; move standard label
2626
 4963  F90DDB  BF 8B 1C F9   	?05:	lda	>PBRLBL,x
2627
 4964  F90DDF  9D 53 41      		sta	!P0FAT+fcbs,x
2628
 4965  F90DE2  CA            		dex
2629
 4966  F90DE3  10 F6         		bpl	?05
2630
 4967  F90DE5  A6 2A         	?10:	ldx	fdix
2631
 4968  F90DE7  BF 83 1C F9   		lda	>FDMEDIA,x
2632
 4969  F90DEB  85 2B         		sta	media		; media type
2633
 4970  F90DED                		ACC16
2634
 4971  F90DED  C2 20         		rep	#PMFLAG
2635
 4972                        		.LONGA	on
2636
 4973                        		.MNLIST
2637
 4974  F90DEF  A6 40         		ldx	ldtcur
2638
 4975  F90DF1  BD 26 40      		lda	!P0LDT+ldt_pbr,x	; set PBR pointer
2639
 4976  F90DF4  85 32         		sta	pbrp
2640
 4977  F90DF6  BC 28 40      		ldy	!P0LDT+ldt_pbr+2,x
2641
 4978  F90DF9  84 34         		sty	pbrp+2
2642
 4979  F90DFB  BD 22 40      		lda	!P0LDT+ldt_fp,x	; set fat1 table pointer
2643
 4980  F90DFE  85 3A         		sta	tp
2644
 4981  F90E00  BC 24 40      		ldy	!P0LDT+ldt_fp+2,x
2645
 4982  F90E03  84 3C         		sty	tp+2
2646
 4983  F90E05  A9 B1 1C      		lda	#F12HDD		; boot sector header DD
2647
 4984  F90E08  A4 3D         		ldy	fdfmt
2648
 4985  F90E0A  F0 03         		beq	?12
2649
 4986  F90E0C  A9 CD 1C      		lda	#F12HHD		; boot sector header HD
2650
 4987  F90E0F  85 4C         	?12:	sta	tlp
2651
 4988  F90E11  A0 F9         		ldy	#.SEG.F12HDD
2652
 4989  F90E13  84 4E         		sty	tlp+2
2653
 4990  F90E15  A9 00 24      		lda	#$2400		; bytes for DD whole track
2654
 4991  F90E18  A4 3D         		ldy	fdfmt
2655
 4992  F90E1A  F0 03         		beq	?15
2656
 4993  F90E1C  A9 00 48      		lda	#$4800		; bytes for HD whole track
2657
 4994  F90E1F  A2 00         	?15:	ldx	#0
2658
 4995  F90E21                		INDEX16
2659
 4996  F90E21  C2 10         		rep	#PXFLAG
2660
 4997                        		.LONGI	on
2661
 4998                        		.MNLIST
2662
 4999  F90E23  A8            		tay
2663
 5000  F90E24  88            		dey
2664
 5001  F90E25  88            		dey			; index
2665
 5002  F90E26  8A            		txa			; clear C
2666
 5003  F90E27  97 32         	?20:	sta	[pbrp],y	; clear track buffer
2667
  Tue Jul 17 11:00:20 2018                                                                                               Page   44
2668
 
2669
 
2670
 
2671
 
2672
 5004  F90E29  88            		dey
2673
 5005  F90E2A  88            		dey
2674
 5006  F90E2B  10 FA         		bpl	?20
2675
 5007  F90E2D  A0 FE 01      		ldy	#$01FE		; store signature in boot sector
2676
 5008  F90E30  A9 55 AA      		lda	#$AA55
2677
 5009  F90E33  97 32         		sta	[pbrp],y
2678
 5010  F90E35                		CPU08
2679
 5011  F90E35  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
2680
 5012                        		.LONGA	off
2681
 5013                        		.LONGI	off
2682
 5014                        		.MNLIST
2683
 5015  F90E37  A0 1B         		ldy	#F12HSIZ-1	; move boot sector header
2684
 5016  F90E39  B7 4C         	?25:	lda	[tlp],y
2685
 5017  F90E3B  97 32         		sta	[pbrp],y
2686
 5018  F90E3D  88            		dey
2687
 5019  F90E3E  10 F9         		bpl	?25
2688
 5020  F90E40  A0 26         		ldy	#$26		; extended boot signature flag
2689
 5021  F90E42  A9 29         		lda	#$29
2690
 5022  F90E44  97 32         		sta	[pbrp],y
2691
 5023  F90E46  A0 2B         		ldy	#$2B		; volume label pointer
2692
 5024  F90E48  BD 53 41      	?30:	lda	!P0FAT+fcbs,x
2693
 5025  F90E4B  97 32         		sta	[pbrp],y
2694
 5026  F90E4D  E8            		inx
2695
 5027  F90E4E  C8            		iny
2696
 5028  F90E4F  E0 0B         		cpx	#11
2697
 5029  F90E51  90 F5         		bcc	?30
2698
 5030  F90E53  A2 00         		ldx	#0
2699
 5031  F90E55  BF A1 1C F9   	?35:	lda	>F12NAM,x	; store system name
2700
 5032  F90E59  97 32         		sta	[pbrp],y
2701
 5033  F90E5B  E8            		inx
2702
 5034  F90E5C  C8            		iny
2703
 5035  F90E5D  E0 08         		cpx	#8
2704
 5036  F90E5F  90 F4         		bcc	?35
2705
 5037  F90E61  20 C7 1B      		jsr	gettime		; get time stamp
2706
 5038  F90E64  A0 27         		ldy	#$27
2707
 5039  F90E66                		ACC16
2708
 5040  F90E66  C2 20         		rep	#PMFLAG
2709
 5041                        		.LONGA	on
2710
 5042                        		.MNLIST
2711
 5043  F90E68  A5 48         		lda	ctime		; store volume serial number
2712
 5044  F90E6A  97 32         		sta	[pbrp],y
2713
 5045  F90E6C  C8            		iny
2714
 5046  F90E6D  C8            		iny
2715
 5047  F90E6E  A5 4A         		lda	cdate
2716
 5048  F90E70  97 32         		sta	[pbrp],y
2717
 5049  F90E72  A9 00 0E      		lda	#$0E00		; DD root directory offset
2718
 5050  F90E75  A4 3D         		ldy	fdfmt
2719
 5051  F90E77  F0 03         		beq	?40
2720
 5052  F90E79  A9 00 26      		lda	#$2600		; HD root directory offset
2721
 5053  F90E7C  18            	?40:	clc
2722
 5054  F90E7D  65 32         		adc	pbrp
2723
 5055  F90E7F  85 4C         		sta	tlp		; root directory pointer
2724
 5056  F90E81  A4 34         		ldy	pbrp+2
2725
 5057  F90E83  84 4E         		sty	tlp+2
2726
 5058  F90E85  A5 48         		lda	ctime		; store volume label write/creation time
2727
 5059  F90E87  A0 0E         		ldy	#$0E		; index of creation
2728
 5060  F90E89  97 4C         		sta	[tlp],y
2729
  Tue Jul 17 11:00:20 2018                                                                                               Page   45
2730
 
2731
 
2732
 
2733
 
2734
 5061  F90E8B  A0 16         		ldy	#$16		; index of write time
2735
 5062  F90E8D  97 4C         		sta	[tlp],y
2736
 5063  F90E8F  C8            		iny
2737
 5064  F90E90  C8            		iny
2738
 5065  F90E91  A5 4A         		lda	cdate
2739
 5066  F90E93  97 4C         		sta	[tlp],y
2740
 5067  F90E95  A0 10         		ldy	#$10
2741
 5068  F90E97  97 4C         		sta	[tlp],y
2742
 5069  F90E99                		ACC08
2743
 5070  F90E99  E2 20         		sep	#PMFLAG
2744
 5071                        		.LONGA	off
2745
 5072                        		.MNLIST
2746
 5073  F90E9B  A0 0D         		ldy	#13
2747
 5074  F90E9D  A5 53         		lda	sec100
2748
 5075  F90E9F  97 4C         		sta	[tlp],y
2749
 5076  F90EA1  A2 00         		ldx	#0		; store volume label in root directory
2750
 5077  F90EA3  9B            		txy
2751
 5078  F90EA4  BD 53 41      	?45:	lda	!P0FAT+fcbs,x
2752
 5079  F90EA7  97 4C         		sta	[tlp],y
2753
 5080  F90EA9  E8            		inx
2754
 5081  F90EAA  C8            		iny
2755
 5082  F90EAB  E0 0B         		cpx	#11
2756
 5083  F90EAD  90 F5         		bcc	?45
2757
 5084  F90EAF  A9 08         		lda	#DA_VOLUME	; store label attribute
2758
 5085  F90EB1  97 4C         		sta	[tlp],y
2759
 5086  F90EB3                		ACC16CLC
2760
 5087  F90EB3  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
2761
 5088                        		.LONGA	on
2762
 5089                        		.MNLIST
2763
 5090  F90EB5  A9 00 06      		lda	#$0600		; fat 2 offset
2764
 5091  F90EB8  A4 3D         		ldy	fdfmt
2765
 5092  F90EBA  F0 03         		beq	?50
2766
 5093  F90EBC  A9 00 12      		lda	#$1200
2767
 5094  F90EBF  65 3A         	?50:	adc	tp
2768
 5095  F90EC1  85 4C         		sta	tlp		; fat 2 pointer
2769
 5096  F90EC3  A4 3C         		ldy	tp+2
2770
 5097  F90EC5  84 4E         		sty	tlp+2
2771
 5098  F90EC7  A9 FF FF      		lda	#$FFFF		; store fake cluster 0&1
2772
 5099  F90ECA  A0 01         		ldy	#1
2773
 5100  F90ECC  97 3A         		sta	[tp],y
2774
 5101  F90ECE  97 4C         		sta	[tlp],y
2775
 5102  F90ED0                		ACC08
2776
 5103  F90ED0  E2 20         		sep	#PMFLAG
2777
 5104                        		.LONGA	off
2778
 5105                        		.MNLIST
2779
 5106  F90ED2  A5 2B         		lda	media
2780
 5107  F90ED4  87 3A         		sta	[tp]
2781
 5108  F90ED6  87 4C         		sta	[tlp]
2782
 5109  F90ED8  A6 3E         		ldx	pdev		; write whole track on disk
2783
 5110  F90EDA  DA            		phx			; drive #
2784
 5111  F90EDB  A9 00         		lda	#0		; track #0
2785
 5112  F90EDD  48            		pha
2786
 5113  F90EDE  BD D8 40      		lda	!P0LDT+sysbuf,x
2787
 5114  F90EE1  48            		pha			; dma buffer #
2788
 5115  F90EE2  A5 3D         		lda	fdfmt
2789
 5116  F90EE4  09 80         		ora	#$80		; verf flag
2790
 5117  F90EE6  48            		pha			; format
2791
  Tue Jul 17 11:00:20 2018                                                                                               Page   46
2792
 
2793
 
2794
 
2795
 
2796
 5118  F90EE7                		FDCTKWR
2797
 5119  F90EE7  02 35         		cop	$35
2798
 5120  F90EE9  02            		.DB	$02
2799
 5121                        		.MNLIST
2800
 5122  F90EEA  60            	nx:	rts			; return CF=1 if error
2801
 5123
2802
 5124                        	; create partition on fixed disk X and format it
2803
 5125                        	; in:	X=logical drive
2804
 5126                        	;	Y=$FF if label is specified
2805
 5127  F90EEB                	lfdisk:
2806
 5128  F90EEB  20 83 11      		jsr	prenew		; prepare for partitioning
2807
 5129  F90EEE  B0 FA         		bcs	nx
2808
 5130  F90EF0  A5 39         		lda	lunit
2809
 5131  F90EF2  48            		pha
2810
 5132  F90EF3  4B            		phk
2811
 5133  F90EF4  F4 27 0F      		pea	#!?08
2812
 5134  F90EF7  A9 05         		lda	#5
2813
 5135  F90EF9  48            		pha
2814
 5136  F90EFA                		BPRINTF
2815
 5137  F90EFA  02 11         		cop	$11
2816
 5138                        		.MNLIST
2817
 5139  F90EFC  20 AF 19      		jsr	newprt		; prepare for a new partition
2818
 5140  F90EFF  90 4F         		bcc	?10
2819
 5141  F90F01                		SCNPRINT
2820
 5142  F90F01  02 01         		cop	$01
2821
 5143                        		.MNLIST
2822
 5144  F90F03  65 72 72 6F 72 		.DB	'error computing a new partition.', 13, 0
2823
               20 63 6F 6D 70
2824
               75 74 69 6E 67
2825
               20 61 20 6E 65
2826
               77 20 70 61 72
2827
               74 69 74 69 6F
2828
               6E 2E 0D 00
2829
 5145  F90F25  38            		sec
2830
 5146  F90F26  60            	?05:	rts
2831
 5147
2832
 5148  F90F27  0D 70 61 72 74 	?08:	.DB	13, 'partitioning fixed disk on drive <%c>:', 13, 0
2833
               69 74 69 6F 6E
2834
               69 6E 67 20 66
2835
               69 78 65 64 20
2836
               64 69 73 6B 20
2837
               6F 6E 20 64 72
2838
               69 76 65 20 3C
2839
               25 63 3E 3A 0D
2840
               00
2841
 5149
2842
 5150  F90F50  A9 80         	?10:	lda	#$80
2843
 5151  F90F52  85 41         		sta	lflag		; flag creation new pbr/mbr
2844
 5152  F90F54  80 05         		bra	lfmt2
2845
 5153  F90F56
2846
 5154                        	; format main partition on fixed disk X
2847
 5155                        	; in:	X=logical drive
2848
 5156                        	;	Y=$FF if label is specified
2849
 5157  F90F56                	lhdfmt:
2850
 5158  F90F56  20 40 17      		jsr	prefmt		; format pre-task
2851
 5159  F90F59  B0 8F         		bcs	nx
2852
 5160  F90F5B
2853
  Tue Jul 17 11:00:20 2018                                                                                               Page   47
2854
 
2855
 
2856
 
2857
 
2858
 5161  F90F5B                	lfmt2:
2859
 5162  F90F5B  20 B5 17      		jsr	showprt
2860
 5163  F90F5E  20 30 1B      		jsr	askcont
2861
 5164  F90F61  90 01         		bcc	?01
2862
 5165  F90F63  60            		rts
2863
 5166  F90F64                	?01:	SCN_CR
2864
 5167  F90F64                		SCNPRCHAR
2865
 5168                        		.MLIST
2866
 5169  F90F64  02 07         		cop	$07
2867
 5170                        		.MNLIST
2868
 5171  F90F66  0D            		.DB	$0D
2869
 5172                        		.MNLIST
2870
 5173  F90F67  24 41         		bit	lflag
2871
 5174  F90F69  10 2C         		bpl	?02
2872
 5175  F90F6B  20 ED 12      		jsr	newpbr		; create a new pbr/mbr
2873
 5176  F90F6E
2874
 5177                        		; transfer to DMA buffer
2875
 5178  F90F6E  8B            		phb
2876
 5179  F90F6F  A9 08         		lda	#$08		; PB3 VIA3
2877
 5180  F90F71  1C C0 FD      		trb	VIA3+VIAPRB	; enable 1Mb buffer
2878
 5181  F90F74  AD CF FD      		lda	!VIA3+VIAPRANH
2879
 5182  F90F77  29 F8         		and	#$F8
2880
 5183  F90F79  8D CF FD      		sta	!VIA3+VIAPRANH	; set bank $00
2881
 5184  F90F7C                		CPU16
2882
 5185  F90F7C  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
2883
 5186                        		.LONGA	on
2884
 5187                        		.LONGI	on
2885
 5188                        		.MNLIST
2886
 5189  F90F7E  A9 FF 01      		lda	#$01FF
2887
 5190  F90F81  A0 00 42      		ldy	#$4200		; dest -> $024200 (buffer $21)
2888
 5191  F90F84  A6 32         		ldx	pbrp		; source
2889
 5192  F90F86  54 02 01      		mvn	#1, #2
2890
 5193  F90F89  A9 FF 01      		lda	#$01FF
2891
 5194  F90F8C  A0 00 40      		ldy	#$4000		; dest -> $024000 (buffer $20)
2892
 5195  F90F8F  A6 4C         		ldx	tlp		; source
2893
 5196  F90F91  54 02 01      		mvn	#1, #2
2894
 5197  F90F94                		CPU08
2895
 5198  F90F94  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
2896
 5199                        		.LONGA	off
2897
 5200                        		.LONGI	off
2898
 5201                        		.MNLIST
2899
 5202  F90F96  AB            		plb
2900
 5203
2901
 5204  F90F97  A5 51         	?02:	lda	fatbnk
2902
 5205  F90F99  20 1F 14      		jsr	newfat
2903
 5206  F90F9C  A5 50         		lda	rootbnk
2904
 5207  F90F9E  20 71 14      		jsr	newroot
2905
 5208  F90FA1  A5 52         		lda	clsbnk
2906
 5209  F90FA3  20 F8 14      		jsr	newcls
2907
 5210  F90FA6  20 F3 1A      		jsr	askfmt
2908
 5211  F90FA9  90 03         		bcc	?04		; quick format
2909
 5212  F90FAB  20 63 10      		jsr	fmtcls		; write out cluster's
2910
 5213  F90FAE                	?04:	SCN_CR
2911
 5214  F90FAE                		SCNPRCHAR
2912
 5215                        		.MLIST
2913
 5216  F90FAE  02 07         		cop	$07
2914
 5217                        		.MNLIST
2915
  Tue Jul 17 11:00:20 2018                                                                                               Page   48
2916
 
2917
 
2918
 
2919
 
2920
 5218  F90FB0  0D            		.DB	$0D
2921
 5219                        		.MNLIST
2922
 5220  F90FB1  24 41         		bit	lflag
2923
 5221  F90FB3  10 0A         		bpl	?06		; skip MBR&PBR write out
2924
 5222  F90FB5  20 04 16      		jsr	wrmbr		; write out MBR
2925
 5223  F90FB8  B0 63         		bcs	?10		; error
2926
 5224  F90FBA  20 C8 15      		jsr	wrpbr		; write out PBR
2927
 5225  F90FBD  B0 5E         		bcs	?10
2928
 5226  F90FBF  A9 00         	?06:	lda	#0
2929
 5227  F90FC1  EB            		xba			; B=0
2930
 5228  F90FC2  A5 51         		lda	fatbnk
2931
 5229  F90FC4                		ACC16
2932
 5230  F90FC4  C2 20         		rep	#PMFLAG
2933
 5231                        		.LONGA	on
2934
 5232                        		.MNLIST
2935
 5233  F90FC6  0A            		asl	a
2936
 5234  F90FC7  0A            		asl	a
2937
 5235  F90FC8  0A            		asl	a
2938
 5236  F90FC9  0A            		asl	a
2939
 5237  F90FCA  85 2A         		sta	xfatb		; x-mem fat buffer
2940
 5238  F90FCC  A5 22         		lda	fat1
2941
 5239  F90FCE  85 2C         		sta	flba
2942
 5240  F90FD0                		ACC08
2943
 5241  F90FD0  E2 20         		sep	#PMFLAG
2944
 5242                        		.LONGA	off
2945
 5243                        		.MNLIST
2946
 5244  F90FD2  A2 01         		ldx	#1		; write out fat1
2947
 5245  F90FD4  20 7B 16      		jsr	wrfat
2948
 5246  F90FD7  B0 44         		bcs	?10
2949
 5247  F90FD9  A5 24         		lda	fat2
2950
 5248  F90FDB  85 2C         		sta	flba
2951
 5249  F90FDD  A5 25         		lda	fat2+1
2952
 5250  F90FDF  85 2D         		sta	flba+1
2953
 5251  F90FE1  A2 02         		ldx	#2		; write out fat1
2954
 5252  F90FE3  20 7B 16      		jsr	wrfat
2955
 5253  F90FE6  B0 35         		bcs	?10
2956
 5254  F90FE8  A9 00         		lda	#0
2957
 5255  F90FEA  EB            		xba			; B=0
2958
 5256  F90FEB  A5 50         		lda	rootbnk
2959
 5257  F90FED                		ACC16
2960
 5258  F90FED  C2 20         		rep	#PMFLAG
2961
 5259                        		.LONGA	on
2962
 5260                        		.MNLIST
2963
 5261  F90FEF  0A            		asl	a
2964
 5262  F90FF0  0A            		asl	a
2965
 5263  F90FF1  0A            		asl	a
2966
 5264  F90FF2  0A            		asl	a
2967
 5265  F90FF3  85 2A         		sta	xfatb		; x-mem fat buffer
2968
 5266  F90FF5  A5 20         		lda	root
2969
 5267  F90FF7  85 2C         		sta	flba
2970
 5268  F90FF9                		ACC08
2971
 5269  F90FF9  E2 20         		sep	#PMFLAG
2972
 5270                        		.LONGA	off
2973
 5271                        		.MNLIST
2974
 5272  F90FFB  20 7D 15      		jsr	wrroot
2975
 5273  F90FFE  B0 1D         		bcs	?10
2976
 5274  F91000  A6 3E         		ldx	pdev		; update drive flag
2977
  Tue Jul 17 11:00:20 2018                                                                                               Page   49
2978
 
2979
 
2980
 
2981
 
2982
 5275  F91002  B5 0E         		lda	atadev,x
2983
 5276  F91004  29 E0         		and	#$E0
2984
 5277  F91006  09 1D         		ora	#$1D
2985
 5278  F91008  95 0E         		sta	atadev,x
2986
 5279  F9100A  20 6D 0D      		jsr	mvldt
2987
 5280  F9100D  A9 E0         		lda	#$E0
2988
 5281  F9100F  9D 01 40      		sta	!P0LDT+ldt_fg2,x
2989
 5282  F91012  9E 20 40      		stz	!P0LDT+ldt_cdlvl,x
2990
 5283  F91015  9E 1E 40      		stz	!P0LDT+ldt_cdcls,x
2991
 5284  F91018  9E 1F 40      		stz	!P0LDT+ldt_cdcls+1,x
2992
 5285  F9101B  18            		clc
2993
 5286  F9101C  60            	?08:	rts
2994
 5287  F9101D  A6 40         	?10:	ldx	ldtcur		; invalidate logical drive if error
2995
 5288  F9101F  9E 01 40      		stz	!P0LDT+ldt_fg2,x
2996
 5289  F91022  A6 3E         		ldx	pdev		; invalidate drive if error
2997
 5290  F91024  B5 0E         		lda	atadev,x
2998
 5291  F91026  29 E0         		and	#$E0
2999
 5292  F91028  95 0E         		sta	atadev,x
3000
 5293  F9102A  8A            		txa
3001
 5294  F9102B  0A            		asl	a
3002
 5295  F9102C  0A            		asl	a
3003
 5296  F9102D  AA            		tax
3004
 5297  F9102E  A0 00         		ldy	#0
3005
 5298  F91030                		CPU16
3006
 5299  F91030  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
3007
 5300                        		.LONGA	on
3008
 5301                        		.LONGI	on
3009
 5302                        		.MNLIST
3010
 5303  F91032  9E 22 00      		stz	!atambr,x
3011
 5304  F91035  9E 24 00      		stz	!atambr+2,x
3012
 5305  F91038  9E 32 00      		stz	!ataprt,x
3013
 5306  F9103B  9E 34 00      		stz	!ataprt+2,x
3014
 5307  F9103E  98            		tya			; C=0
3015
 5308  F9103F  97 4C         	?15:	sta	[tlp],y		; clear MBR
3016
 5309  F91041  C8            		iny
3017
 5310  F91042  C8            		iny
3018
 5311  F91043  C0 00 02      		cpy	#$200
3019
 5312  F91046  90 F7         		bcc	?15
3020
 5313  F91048                		CPU08
3021
 5314  F91048  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
3022
 5315                        		.LONGA	off
3023
 5316                        		.LONGI	off
3024
 5317                        		.MNLIST
3025
 5318  F9104A  A5 3E         		lda	pdev		; write out an empty invalid MBR
3026
 5319  F9104C  48            		pha			; ata drive
3027
 5320  F9104D  A9 00         		lda	#0
3028
 5321  F9104F  48            		pha
3029
 5322  F91050  F4 00 00      		pea	#0		; lba=0
3030
 5323  F91053  A9 01         		lda	#1
3031
 5324  F91055  48            		pha			; write 1 sector
3032
 5325  F91056  A5 4E         		lda	tlp+2
3033
 5326  F91058  48            		pha			; buffer pointer
3034
 5327  F91059  D4 4C         		pei	(tlp)
3035
 5328  F9105B  A9 00         		lda	#$00		; no verify after write
3036
 5329  F9105D  48            		pha
3037
 5330  F9105E                		ATAWRITE
3038
 5331  F9105E  02 40         		cop	$40
3039
  Tue Jul 17 11:00:20 2018                                                                                               Page   50
3040
 
3041
 
3042
 
3043
 
3044
 5332  F91060  02            		.DB	$02
3045
 5333                        		.MNLIST
3046
 5334  F91061  38            		sec			; return error status
3047
 5335  F91062  60            	?20:	rts
3048
 5336
3049
 5337  F91063                	fmtcls:
3050
 5338  F91063                		SCN_CR
3051
 5339  F91063                		SCNPRCHAR
3052
 5340                        		.MLIST
3053
 5341  F91063  02 07         		cop	$07
3054
 5342                        		.MNLIST
3055
 5343  F91065  0D            		.DB	$0D
3056
 5344                        		.MNLIST
3057
 5345  F91066                		SCNPRINT
3058
 5346  F91066  02 01         		cop	$01
3059
 5347                        		.MNLIST
3060
 5348  F91068  70 72 65 73 73 		.DB	'press <CTRL+BREAK> to stop.', 13, 0
3061
               20 3C 43 54 52
3062
               4C 2B 42 52 45
3063
               41 4B 3E 20 74
3064
               6F 20 73 74 6F
3065
               70 2E 0D 00
3066
 5349  F91085                		SCNGETPOS
3067
 5350  F91085  02 18         		cop	$18
3068
 5351  F91087  02            		.DB	$02
3069
 5352                        		.MNLIST
3070
 5353  F91088  86 4F         		stx	fd2ix
3071
 5354  F9108A  A9 00         		lda	#0
3072
 5355  F9108C  85 13         		sta	first+1		; cluster size 16 bit
3073
 5356  F9108E  85 16         		sta	rsvsec		; lba hi
3074
 5357  F91090  A6 35         		ldx	clssiz
3075
 5358  F91092  86 12         		stx	first
3076
 5359  F91094  A2 01         		ldx	#XMBANK
3077
 5360  F91096  86 3C         		stx	tp+2
3078
 5361  F91098  EB            		xba			; B=0
3079
 5362  F91099  A5 52         		lda	clsbnk
3080
 5363  F9109B                		ACC16
3081
 5364  F9109B  C2 20         		rep	#PMFLAG
3082
 5365                        		.LONGA	on
3083
 5366                        		.MNLIST
3084
 5367  F9109D  0A            		asl	a
3085
 5368  F9109E  0A            		asl	a
3086
 5369  F9109F  0A            		asl	a
3087
 5370  F910A0  0A            		asl	a
3088
 5371  F910A1  85 2A         		sta	xfatb		; x-mem fat buffer
3089
 5372  F910A3  A5 26         		lda	start
3090
 5373  F910A5  85 2C         		sta	flba		; cluster #2 lba
3091
 5374  F910A7  A9 02 00      		lda	#2
3092
 5375  F910AA  85 14         		sta	clscnt		; start with cluster #2
3093
 5376  F910AC  A5 28         		lda	maxcls
3094
 5377  F910AE  3A            		dec	a
3095
 5378  F910AF  85 10         		sta	maxcnt
3096
 5379  F910B1  64 42         		stz	badcls
3097
 5380  F910B3                		ACC08
3098
 5381  F910B3  E2 20         		sep	#PMFLAG
3099
 5382                        		.LONGA	off
3100
 5383                        		.MNLIST
3101
  Tue Jul 17 11:00:20 2018                                                                                               Page   51
3102
 
3103
 
3104
 
3105
 
3106
 5384  F910B5  A6 4F         	?10:	ldx	fd2ix		; set screen position
3107
 5385  F910B7  A0 00         		ldy	#0
3108
 5386  F910B9                		SCNSETPOS
3109
 5387  F910B9  02 18         		cop	$18
3110
 5388  F910BB  03            		.DB	$03
3111
 5389                        		.MNLIST
3112
 5390  F910BC  D4 10         		pei	(maxcnt)
3113
 5391  F910BE  D4 14         		pei	(clscnt)
3114
 5392  F910C0  4B            		phk
3115
 5393  F910C1  F4 49 11      		pea	#!?100
3116
 5394  F910C4  A9 08         		lda	#8
3117
 5395  F910C6  48            		pha
3118
 5396  F910C7                		BPRINTF
3119
 5397  F910C7  02 11         		cop	$11
3120
 5398                        		.MNLIST
3121
 5399  F910C9  A5 3E         		lda	pdev
3122
 5400  F910CB  48            		pha			; ata drive
3123
 5401  F910CC  A5 16         		lda	rsvsec
3124
 5402  F910CE  48            		pha
3125
 5403  F910CF  D4 2C         		pei	(flba)		; fat table lba
3126
 5404  F910D1  A5 12         		lda	first
3127
 5405  F910D3  48            		pha			; write n sector
3128
 5406  F910D4
3129
 5407                        		;lda	#0
3130
 5408                        		;pha			; A=0 -> x-mem buffer
3131
 5409                        		;pei	(xfatb)
3132
 5410                        		;lda	#$80		; verify after write
3133
 5411                        		;pha
3134
 5412                        		;ATAWRITE
3135
 5413  F910D4
3136
 5414  F910D4  F4 40 00      		pea	#$40
3137
 5415  F910D7                		ATADMAWR
3138
 5416  F910D7  02 42         		cop	$42
3139
 5417  F910D9  01            		.DB	$01
3140
 5418                        		.MNLIST
3141
 5419
3142
 5420  F910DA  90 03         		bcc	?20		; write ok
3143
 5421                        		;brk
3144
 5422  F910DC  20 1B 11      		jsr	?40		; mark bad cluster
3145
 5423  F910DF                	?20:	ACC16
3146
 5424  F910DF  C2 20         		rep	#PMFLAG
3147
 5425                        		.LONGA	on
3148
 5426                        		.MNLIST
3149
 5427  F910E1  A5 14         		lda	clscnt
3150
 5428  F910E3  1A            		inc	a
3151
 5429  F910E4  C5 28         		cmp	maxcls
3152
 5430  F910E6  B0 10         		bcs	?30
3153
 5431  F910E8  85 14         		sta	clscnt
3154
 5432  F910EA  A5 2C         		lda	flba
3155
 5433  F910EC  A2 00         		ldx	#0
3156
 5434  F910EE  65 12         		adc	first
3157
 5435  F910F0  85 2C         		sta	flba
3158
 5436  F910F2  90 02         		bcc	?25
3159
 5437  F910F4  E8            		inx
3160
 5438  F910F5  18            		clc
3161
 5439  F910F6  86 16         	?25:	stx	rsvsec
3162
 5440  F910F8                	?30:	ACC08
3163
  Tue Jul 17 11:00:20 2018                                                                                               Page   52
3164
 
3165
 
3166
 
3167
 
3168
 5441  F910F8  E2 20         		sep	#PMFLAG
3169
 5442                        		.LONGA	off
3170
 5443                        		.MNLIST
3171
 5444  F910FA  B0 0A         		bcs	?35
3172
 5445  F910FC  AD 4B 00      		lda	!CtrlBrk
3173
 5446  F910FF  9C 4B 00      		stz	!CtrlBrk
3174
 5447  F91102  C9 80         		cmp	#$80
3175
 5448  F91104  D0 AF         		bne	?10
3176
 5449  F91106                	?35:	SCNPRINT
3177
 5450  F91106  02 01         		cop	$01
3178
 5451                        		.MNLIST
3179
 5452  F91108  64 6F 6E 65 2E 		.DB	'done.', 13, 0
3180
               0D 00
3181
 5453  F9110F  D4 42         		pei	(badcls)
3182
 5454  F91111  4B            		phk
3183
 5455  F91112  F4 69 11      		pea	#!?110
3184
 5456  F91115  A9 06         		lda	#6
3185
 5457  F91117  48            		pha
3186
 5458  F91118                		BPRINTF
3187
 5459  F91118  02 11         		cop	$11
3188
 5460                        		.MNLIST
3189
 5461  F9111A  60            		rts
3190
 5462
3191
 5463  F9111B  AE 0A FC      	?40:	ldx	CRXME		; save X mem setting
3192
 5464  F9111E  DA            		phx
3193
 5465  F9111F  8D 0B FC      		sta	!CRXMEON	; enable X mem in window $012000 - $013FFF
3194
 5466  F91122  A5 15         		lda	clscnt+1	; A=sector (one sec. = 256 cluster #)
3195
 5467  F91124  AA            		tax
3196
 5468  F91125  4A            		lsr	a		; divide by 16 to get x-mem buffer bank
3197
 5469  F91126  4A            		lsr	a
3198
 5470  F91127  4A            		lsr	a
3199
 5471  F91128  4A            		lsr	a
3200
 5472  F91129  18            		clc
3201
 5473  F9112A  65 51         		adc	fatbnk		; add fat table base base bank
3202
 5474  F9112C  8D 28 FD      		sta	!PIA0+PIAPRA	; set bank
3203
 5475  F9112F  8A            		txa
3204
 5476  F91130  EB            		xba
3205
 5477  F91131  A5 14         		lda	clscnt
3206
 5478  F91133                		ACC16
3207
 5479  F91133  C2 20         		rep	#PMFLAG
3208
 5480                        		.LONGA	on
3209
 5481                        		.MNLIST
3210
 5482  F91135  29 FF 0F      		and	#$0FFF		; mask 4096 cluster's
3211
 5483  F91138  0A            		asl	a
3212
 5484  F91139  85 3A         		sta	tp
3213
 5485  F9113B  A9 F7 FF      		lda	#$FFF7
3214
 5486  F9113E  87 3A         		sta	[tp]
3215
 5487  F91140  E6 42         		inc	badcls
3216
 5488  F91142                		ACC08
3217
 5489  F91142  E2 20         		sep	#PMFLAG
3218
 5490                        		.LONGA	off
3219
 5491                        		.MNLIST
3220
 5492  F91144  FA            		plx			; restore X mem setting
3221
 5493  F91145  9D 0A FC      		sta	!CRXME,x
3222
 5494  F91148  60            		rts
3223
 5495
3224
 5496  F91149  63 6C 65 61 72 	?100:	.DB	'clear cluster %05hu of %05hu...', 0
3225
  Tue Jul 17 11:00:20 2018                                                                                               Page   53
3226
 
3227
 
3228
 
3229
 
3230
               20 63 6C 75 73
3231
               74 65 72 20 25
3232
               30 35 68 75 20
3233
               6F 66 20 25 30
3234
               35 68 75 2E 2E
3235
               2E 00
3236
 5497  F91169  64 65 66 65 63 	?110:	.DB	'defective cluster(s): %hu', 0
3237
               74 69 76 65 20
3238
               63 6C 75 73 74
3239
               65 72 28 73 29
3240
               3A 20 25 68 75
3241
               00
3242
 5498
3243
 5499                        	; common pre task routine for format fixed disk
3244
 5500                        	; in:	X=logical drive
3245
 5501                        	;	Y=$FF if label is specified
3246
 5502  F91183                	prenew:
3247
 5503  F91183  86 3F         		stx	ldev
3248
 5504  F91185  84 41         		sty	lflag
3249
 5505  F91187  9B            		txy
3250
 5506  F91188  BE D2 40      		ldx	!P0LDT+ldtp,y
3251
 5507  F9118B  86 40         		stx	ldtcur
3252
 5508  F9118D  3C 00 40      		bit	!P0LDT+ldt_fg1,x
3253
 5509  F91190  10 02         		bpl	?01		; not ready
3254
 5510  F91192  70 10         		bvs	?03		; ok, ata device
3255
 5511  F91194  98            	?01:	tya
3256
 5512  F91195  18            		clc
3257
 5513  F91196  69 41         		adc	#'A'
3258
 5514  F91198  48            		pha
3259
 5515  F91199  4B            		phk
3260
 5516  F9119A  F4 BA 12      		pea	#!?100
3261
 5517  F9119D  A9 05         		lda	#5
3262
 5518  F9119F  48            		pha
3263
 5519  F911A0                		BPRINTF
3264
 5520  F911A0  02 11         		cop	$11
3265
 5521                        		.MNLIST
3266
 5522  F911A2  38            		sec
3267
 5523  F911A3  60            		rts
3268
 5524  F911A4  BD 00 40      	?03:	lda	!P0LDT+ldt_fg1,x
3269
 5525  F911A7  29 03         		and	#3
3270
 5526  F911A9  85 3E         		sta	pdev		; phisycal drive
3271
 5527  F911AB  18            		clc
3272
 5528  F911AC  69 43         		adc	#'C'		; ata device: 'C' or 'D'
3273
 5529  F911AE  85 39         		sta	lunit		; logical drive letter
3274
 5530  F911B0  24 41         		bit	lflag
3275
 5531  F911B2  30 0C         		bmi	?10		; label specified
3276
 5532  F911B4  A2 0A         		ldx	#10		; move standard label
3277
 5533  F911B6  BF 96 1C F9   	?05:	lda	>NOLBL,x
3278
 5534  F911BA  9D 53 41      		sta	!P0FAT+fcbs,x
3279
 5535  F911BD  CA            		dex
3280
 5536  F911BE  10 F6         		bpl	?05
3281
 5537  F911C0  64 41         	?10:	stz	lflag
3282
 5538  F911C2  A5 3E         		lda	pdev
3283
 5539  F911C4  0A            		asl	a
3284
 5540  F911C5  0A            		asl	a
3285
 5541  F911C6  AA            		tax
3286
 5542  F911C7                		ACC16
3287
  Tue Jul 17 11:00:20 2018                                                                                               Page   54
3288
 
3289
 
3290
 
3291
 
3292
 5543  F911C7  C2 20         		rep	#PMFLAG
3293
 5544                        		.LONGA	on
3294
 5545                        		.MNLIST
3295
 5546  F911C9  BD 12 00      		lda	!atasec,x	; max. disk usable sector's
3296
 5547  F911CC  85 04         		sta	maxsec
3297
 5548  F911CE  BD 14 00      		lda	!atasec+2,x
3298
 5549  F911D1  85 06         		sta	maxsec+2
3299
 5550  F911D3  BD 22 00      		lda	!atambr,x
3300
 5551  F911D6  85 08         		sta	hidsec
3301
 5552  F911D8  BD 24 00      		lda	!atambr+2,x
3302
 5553  F911DB  29 FF 00      		and	#$00FF
3303
 5554  F911DE  85 0A         		sta	hidsec+2
3304
 5555  F911E0  BD 32 00      		lda	!ataprt,x
3305
 5556  F911E3  85 0C         		sta	totsec
3306
 5557  F911E5  BD 34 00      		lda	!ataprt+2,x
3307
 5558  F911E8  85 0E         		sta	totsec+2
3308
 5559  F911EA  A6 40         		ldx	ldtcur
3309
 5560  F911EC  BD 26 40      		lda	!P0LDT+ldt_pbr,x	; set PBR pointer
3310
 5561  F911EF  85 32         		sta	pbrp
3311
 5562  F911F1  BC 28 40      		ldy	!P0LDT+ldt_pbr+2,x
3312
 5563  F911F4  84 34         		sty	pbrp+2
3313
 5564  F911F6  BD 22 40      		lda	!P0LDT+ldt_fp,x	; set fat1 table pointer
3314
 5565  F911F9  85 3A         		sta	tp
3315
 5566  F911FB  BC 24 40      		ldy	!P0LDT+ldt_fp+2,x
3316
 5567  F911FE  84 3C         		sty	tp+2
3317
 5568  F91200  A9 00 88      		lda	#MBR0ATA	; set pointer for MBR
3318
 5569  F91203  A4 3E         		ldy	pdev
3319
 5570  F91205  F0 0A         		beq	?15
3320
 5571  F91207  A9 00 8A      		lda	#MBR1ATA
3321
 5572  F9120A  C0 01         		cpy	#1
3322
 5573  F9120C  F0 03         		beq	?15
3323
 5574  F9120E  A9 00 94      		lda	#MBR0USB
3324
 5575  F91211  85 4C         	?15:	sta	tlp
3325
 5576  F91213  A0 01         		ldy	#^MBR0ATA
3326
 5577  F91215  84 4E         		sty	tlp+2
3327
 5578  F91217  BC 25 40      		ldy	!P0LDT+ldt_fbuf,x
3328
 5579  F9121A  84 51         		sty	fatbnk		; x-mem bank for fat cache buffer
3329
 5580  F9121C  BD 02 40      		lda	!P0LDT+ldt_root,x
3330
 5581  F9121F  85 20         		sta	root
3331
 5582  F91221  BD 04 40      		lda	!P0LDT+ldt_fat1,x
3332
 5583  F91224  85 22         		sta	fat1
3333
 5584  F91226  BD 06 40      		lda	!P0LDT+ldt_fat2,x
3334
 5585  F91229  85 24         		sta	fat2
3335
 5586  F9122B  BD 08 40      		lda	!P0LDT+ldt_cls,x
3336
 5587  F9122E  85 26         		sta	start
3337
 5588  F91230  BD 0C 40      		lda	!P0LDT+ldt_rent,x
3338
 5589  F91233  85 1C         		sta	rootent
3339
 5590  F91235  BD 0E 40      		lda	!P0LDT+ldt_cent,x
3340
 5591  F91238  85 1E         		sta	clsent
3341
 5592  F9123A  BD 12 40      		lda	!P0LDT+ldt_free,x
3342
 5593  F9123D  85 2E         		sta	freecnt
3343
 5594  F9123F  BD 14 40      		lda	!P0LDT+ldt_nxt,x
3344
 5595  F91242  85 30         		sta	freecls
3345
 5596  F91244  BC 18 40      		ldy	!P0LDT+ldt_csiz,x
3346
 5597  F91247  84 35         		sty	clssiz
3347
 5598  F91249  BD 0A 40      		lda	!P0LDT+ldt_max,x
3348
 5599  F9124C  85 28         		sta	maxcls
3349
  Tue Jul 17 11:00:20 2018                                                                                               Page   55
3350
 
3351
 
3352
 
3353
 
3354
 5600  F9124E  3A            		dec	a
3355
 5601  F9124F  3A            		dec	a
3356
 5602  F91250  85 14         		sta	clscnt
3357
 5603  F91252  BC 19 40      		ldy	!P0LDT+ldt_cshf,x
3358
 5604  F91255  84 36         		sty	clsshf
3359
 5605  F91257  A0 B4         		ldy	#$B4
3360
 5606  F91259  84 50         		sty	rootbnk		; root dir. x-mem bank
3361
 5607  F9125B  A0 B8         		ldy	#$B8
3362
 5608  F9125D  84 52         		sty	clsbnk		; cluster x-mem bank
3363
 5609  F9125F                		ACC08
3364
 5610  F9125F  E2 20         		sep	#PMFLAG
3365
 5611                        		.LONGA	off
3366
 5612                        		.MNLIST
3367
 5613  F91261  A0 00         		ldy	#0
3368
 5614  F91263  BD 16 40      		lda	!P0LDT+ldt_fsiz,x
3369
 5615  F91266  85 18         		sta	fatsiz
3370
 5616  F91268  D0 01         		bne	?16
3371
 5617  F9126A  C8            		iny
3372
 5618  F9126B  84 19         	?16:	sty	fatsiz+1
3373
 5619  F9126D  BD 1A 40      		lda	!P0LDT+ldt_rsiz,x
3374
 5620  F91270  85 1A         		sta	rootsiz
3375
 5621  F91272  BD 1B 40      		lda	!P0LDT+ldt_mcls,x
3376
 5622  F91275  85 37         		sta	clsmod
3377
 5623  F91277  BD 29 40      		lda	!P0LDT+ldt_fmt,x
3378
 5624  F9127A  85 3D         		sta	fdfmt
3379
 5625  F9127C  BD 01 40      		lda	!P0LDT+ldt_fg2,x
3380
 5626  F9127F  64 41         		stz	lflag		; invalid partition flag
3381
 5627  F91281  29 E0         		and	#$E0		; valid partition?
3382
 5628  F91283  C9 E0         		cmp	#$E0
3383
 5629  F91285  D0 31         		bne	?50		; no
3384
 5630  F91287  85 41         		sta	lflag		; valid partition flag
3385
 5631  F91289                		ACC16
3386
 5632  F91289  C2 20         		rep	#PMFLAG
3387
 5633                        		.LONGA	on
3388
 5634                        		.MNLIST
3389
 5635  F9128B  A5 14         		lda	clscnt
3390
 5636  F9128D  85 2E         		sta	remsec
3391
 5637  F9128F  A9 00 00      		lda	#0
3392
 5638  F91292  A4 36         		ldy	clsshf
3393
 5639  F91294  F0 06         		beq	?25
3394
 5640  F91296  06 2E         	?20:	asl	remsec
3395
 5641  F91298  2A            		rol	a
3396
 5642  F91299  88            		dey
3397
 5643  F9129A  D0 FA         		bne	?20
3398
 5644  F9129C  85 30         	?25:	sta	remsec+2
3399
 5645  F9129E  18            		clc
3400
 5646  F9129F  A5 26         		lda	start
3401
 5647  F912A1  65 2E         		adc	remsec
3402
 5648  F912A3  85 2E         		sta	remsec
3403
 5649  F912A5  90 02         		bcc	?30
3404
 5650  F912A7  E6 30         		inc	remsec+2
3405
 5651  F912A9  38            	?30:	sec
3406
 5652  F912AA  A5 04         		lda	maxsec
3407
 5653  F912AC  E5 2E         		sbc	remsec
3408
 5654  F912AE  85 2E         		sta	remsec
3409
 5655  F912B0  A5 06         		lda	maxsec+2
3410
 5656  F912B2  E5 30         		sbc	remsec+2
3411
  Tue Jul 17 11:00:20 2018                                                                                               Page   56
3412
 
3413
 
3414
 
3415
 
3416
 5657  F912B4  85 30         		sta	remsec+2
3417
 5658  F912B6                		ACC08
3418
 5659  F912B6  E2 20         		sep	#PMFLAG
3419
 5660                        		.LONGA	off
3420
 5661                        		.MNLIST
3421
 5662  F912B8  18            	?50:	clc
3422
 5663  F912B9  60            		rts
3423
 5664
3424
 5665  F912BA  0D 65 72 72 6F 	?100:	.DB	13, 'error: drive <%c> not ready or not a fixed disk.', 13, 0
3425
               72 3A 20 64 72
3426
               69 76 65 20 3C
3427
               25 63 3E 20 6E
3428
               6F 74 20 72 65
3429
               61 64 79 20 6F
3430
               72 20 6E 6F 74
3431
               20 61 20 66 69
3432
               78 65 64 20 64
3433
               69 73 6B 2E 0D
3434
               00
3435
 5666
3436
 5667                        	; set a new MBR/PBR for ata drive
3437
 5668  F912ED                	newpbr:
3438
 5669  F912ED  A0 00         		ldy	#0
3439
 5670  F912EF  A5 3E         		lda	pdev
3440
 5671  F912F1  0A            		asl	a
3441
 5672  F912F2  0A            		asl	a
3442
 5673  F912F3  AA            		tax			; device index
3443
 5674  F912F4                		CPU16
3444
 5675  F912F4  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
3445
 5676                        		.LONGA	on
3446
 5677                        		.LONGI	on
3447
 5678                        		.MNLIST
3448
 5679  F912F6  98            		tya			; C=0
3449
 5680  F912F7  97 32         	?10:	sta	[pbrp],y	; clear PBR...
3450
 5681  F912F9  97 4C         		sta	[tlp],y		; ...and MBR
3451
 5682  F912FB  C8            		iny
3452
 5683  F912FC  C8            		iny
3453
 5684  F912FD  C0 FE 01      		cpy	#$01FE
3454
 5685  F91300  90 F5         		bcc	?10
3455
 5686  F91302  A9 55 AA      		lda	#$AA55		; put signature
3456
 5687  F91305  97 32         		sta	[pbrp],y
3457
 5688  F91307  97 4C         		sta	[tlp],y
3458
 5689  F91309  A0 BE 01      		ldy	#$01BE		; ptr to first partition in MBR
3459
 5690  F9130C                		ACC08
3460
 5691  F9130C  E2 20         		sep	#PMFLAG
3461
 5692                        		.LONGA	off
3462
 5693                        		.MNLIST
3463
 5694  F9130E  A9 80         		lda	#$80
3464
 5695  F91310  97 4C         		sta	[tlp],y		; first active partition
3465
 5696  F91312  C8            		iny			; $01BF
3466
 5697  F91313  A9 01         		lda	#1		; fake CHS
3467
 5698  F91315  97 4C         		sta	[tlp],y
3468
 5699  F91317  C8            		iny			; $01C0
3469
 5700  F91318  97 4C         		sta	[tlp],y
3470
 5701  F9131A  C8            		iny			; $01C1
3471
 5702  F9131B  A9 00         		lda	#0
3472
 5703  F9131D  97 4C         		sta	[tlp],y
3473
  Tue Jul 17 11:00:20 2018                                                                                               Page   57
3474
 
3475
 
3476
 
3477
 
3478
 5704  F9131F  C8            		iny			; $01C2
3479
 5705  F91320  A9 06         		lda	#6		; partition type = FAT16
3480
 5706  F91322  97 4C         		sta	[tlp],y
3481
 5707  F91324  C8            		iny			; $01C3
3482
 5708  F91325  A9 FE         		lda	#$FE		; fake CHS
3483
 5709  F91327  97 4C         		sta	[tlp],y
3484
 5710  F91329  C8            		iny			; $01C4
3485
 5711  F9132A  1A            		inc	a
3486
 5712  F9132B  97 4C         		sta	[tlp],y
3487
 5713  F9132D  C8            		iny			; $01C5
3488
 5714  F9132E  97 4C         		sta	[tlp],y
3489
 5715  F91330  C8            		iny			; $01C6 -> partition start lba
3490
 5716  F91331                		ACC16
3491
 5717  F91331  C2 20         		rep	#PMFLAG
3492
 5718                        		.LONGA	on
3493
 5719                        		.MNLIST
3494
 5720  F91333  A5 08         		lda	hidsec
3495
 5721  F91335  97 4C         		sta	[tlp],y
3496
 5722  F91337  9D 22 00      		sta	!atambr,x
3497
 5723  F9133A  C8            		iny
3498
 5724  F9133B  C8            		iny
3499
 5725  F9133C  A5 0A         		lda	hidsec+2	; this is always null
3500
 5726  F9133E  97 4C         		sta	[tlp],y
3501
 5727  F91340  09 00 06      		ora	#$0600		; partition type
3502
 5728  F91343  9D 24 00      		sta	!atambr+2,x
3503
 5729  F91346  C8            		iny
3504
 5730  F91347  C8            		iny			; $01CA -> partition total sectors
3505
 5731  F91348  A5 0C         		lda	totsec
3506
 5732  F9134A  AA            		tax
3507
 5733  F9134B  97 4C         		sta	[tlp],y
3508
 5734  F9134D  C8            		iny
3509
 5735  F9134E  C8            		iny
3510
 5736  F9134F  A5 0E         		lda	totsec+2
3511
 5737  F91351  97 4C         		sta	[tlp],y
3512
 5738  F91353  F0 09         		beq	?15		; now switch to PBR
3513
 5739  F91355  A0 22 00      		ldy	#$22		; partition total sectors 32 high
3514
 5740  F91358  97 32         		sta	[pbrp],y
3515
 5741  F9135A  88            		dey
3516
 5742  F9135B  88            		dey
3517
 5743  F9135C  80 03         		bra	?20
3518
 5744  F9135E  A0 13 00      	?15:	ldy	#$13		; partition total sectors 16
3519
 5745  F91361  8A            	?20:	txa
3520
 5746  F91362  97 32         		sta	[pbrp],y
3521
 5747  F91364                		INDEX08
3522
 5748  F91364  E2 10         		sep	#PXFLAG
3523
 5749                        		.LONGI	off
3524
 5750                        		.MNLIST
3525
 5751  F91366  A0 1C         		ldy	#$1C		; hidden sectors
3526
 5752  F91368  A5 08         		lda	hidsec
3527
 5753  F9136A  97 32         		sta	[pbrp],y
3528
 5754  F9136C  C8            		iny
3529
 5755  F9136D  C8            		iny
3530
 5756  F9136E  A5 0A         		lda	hidsec+2
3531
 5757  F91370  97 32         		sta	[pbrp],y
3532
 5758  F91372  A0 0B         		ldy	#$0B		; bytes per sector
3533
 5759  F91374  A9 00 02      		lda	#$0200
3534
 5760  F91377  97 32         		sta	[pbrp],y
3535
  Tue Jul 17 11:00:20 2018                                                                                               Page   58
3536
 
3537
 
3538
 
3539
 
3540
 5761  F91379  A0 11         		ldy	#$11		; root directory entries
3541
 5762  F9137B  97 32         		sta	[pbrp],y
3542
 5763  F9137D  85 1C         		sta	rootent
3543
 5764  F9137F  A0 16         		ldy	#$16		; fat table size
3544
 5765  F91381  A5 18         		lda	fatsiz
3545
 5766  F91383  97 32         		sta	[pbrp],y
3546
 5767  F91385  A0 0E         		ldy	#$0E		; reserved sectors count
3547
 5768  F91387  A9 01 00      		lda	#1
3548
 5769  F9138A  97 32         		sta	[pbrp],y
3549
 5770  F9138C  1A            		inc	a		; C=2
3550
 5771  F9138D                		CPU08
3551
 5772  F9138D  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
3552
 5773                        		.LONGA	off
3553
 5774                        		.LONGI	off
3554
 5775                        		.MNLIST
3555
 5776  F9138F  A0 10         		ldy	#$10		; fat's count = 2
3556
 5777  F91391  97 32         		sta	[pbrp],y
3557
 5778  F91393  A0 0D         		ldy	#$0D		; sector(s) per cluster
3558
 5779  F91395  A5 35         		lda	clssiz
3559
 5780  F91397  97 32         		sta	[pbrp],y
3560
 5781  F91399  A0 15         		ldy	#$15		; media type = F8
3561
 5782  F9139B  A9 F8         		lda	#$F8
3562
 5783  F9139D  97 32         		sta	[pbrp],y
3563
 5784  F9139F  A0 26         		ldy	#$26		; extended signature flag
3564
 5785  F913A1  A9 29         		lda	#$29
3565
 5786  F913A3  97 32         		sta	[pbrp],y
3566
 5787  F913A5  A0 0A         		ldy	#3+8-1		; OEM name end
3567
 5788  F913A7  A2 07         		ldx	#7
3568
 5789  F913A9  BF B4 1C F9   	?25:	lda	>OEMNAM,x
3569
 5790  F913AD  97 32         		sta	[pbrp],y
3570
 5791  F913AF  88            		dey
3571
 5792  F913B0  CA            		dex
3572
 5793  F913B1  10 F6         		bpl	?25
3573
 5794  F913B3  E8            		inx			; X=0
3574
 5795  F913B4  A0 2B         		ldy	#$2B		; volume label pointer
3575
 5796  F913B6  BD 53 41      	?30:	lda	!P0FAT+fcbs,x
3576
 5797  F913B9  97 32         		sta	[pbrp],y
3577
 5798  F913BB  E8            		inx
3578
 5799  F913BC  C8            		iny
3579
 5800  F913BD  E0 0B         		cpx	#11
3580
 5801  F913BF  90 F5         		bcc	?30
3581
 5802  F913C1  A2 00         		ldx	#0
3582
 5803  F913C3  BF A9 1C F9   	?35:	lda	>F16NAM,x	; store system name string
3583
 5804  F913C7  97 32         		sta	[pbrp],y
3584
 5805  F913C9  E8            		inx
3585
 5806  F913CA  C8            		iny
3586
 5807  F913CB  E0 08         		cpx	#8
3587
 5808  F913CD  90 F4         		bcc	?35
3588
 5809  F913CF  A5 3E         		lda	pdev
3589
 5810  F913D1  0A            		asl	a
3590
 5811  F913D2  0A            		asl	a
3591
 5812  F913D3  AA            		tax			; device index
3592
 5813  F913D4                		ACC16
3593
 5814  F913D4  C2 20         		rep	#PMFLAG
3594
 5815                        		.LONGA	on
3595
 5816                        		.MNLIST
3596
 5817  F913D6  A5 0C         		lda	totsec
3597
  Tue Jul 17 11:00:20 2018                                                                                               Page   59
3598
 
3599
 
3600
 
3601
 
3602
 5818  F913D8  9D 32 00      		sta	!ataprt,x
3603
 5819  F913DB  A5 0E         		lda	totsec+2
3604
 5820  F913DD  9D 34 00      		sta	!ataprt+2,x
3605
 5821  F913E0                		ACC08
3606
 5822  F913E0  E2 20         		sep	#PMFLAG
3607
 5823                        		.LONGA	off
3608
 5824                        		.MNLIST
3609
 5825  F913E2  20 C7 1B      		jsr	gettime		; get time stamp
3610
 5826  F913E5  A9 EB         		lda	#$EB		; this signature in first 3 bytes...
3611
 5827  F913E7  87 32         		sta	[pbrp]		; ...only for microsoft!
3612
 5828  F913E9  A0 01         		ldy	#1
3613
 5829  F913EB  A9 00         		lda	#0
3614
 5830  F913ED  97 32         		sta	[pbrp],y
3615
 5831  F913EF  C8            		iny
3616
 5832  F913F0  A9 90         		lda	#$90
3617
 5833  F913F2  97 32         		sta	[pbrp],y
3618
 5834  F913F4  A0 27         		ldy	#$27
3619
 5835  F913F6                		ACC16
3620
 5836  F913F6  C2 20         		rep	#PMFLAG
3621
 5837                        		.LONGA	on
3622
 5838                        		.MNLIST
3623
 5839  F913F8  A5 48         		lda	ctime		; store volume serial number
3624
 5840  F913FA  97 32         		sta	[pbrp],y
3625
 5841  F913FC  C8            		iny
3626
 5842  F913FD  C8            		iny
3627
 5843  F913FE  A5 4A         		lda	cdate
3628
 5844  F91400  97 32         		sta	[pbrp],y
3629
 5845  F91402  A6 35         		ldx	clssiz
3630
 5846  F91404  9B            		txy
3631
 5847  F91405  8A            		txa			; B=0, A=clssiz
3632
 5848  F91406  0A            		asl	a		; 16 entries per sec...
3633
 5849  F91407  0A            		asl	a
3634
 5850  F91408  0A            		asl	a
3635
 5851  F91409  0A            		asl	a		; here CF=0
3636
 5852  F9140A  85 1E         		sta	clsent		; entries in cluster
3637
 5853  F9140C  88            		dey
3638
 5854  F9140D  84 37         		sty	clsmod
3639
 5855  F9140F  A5 14         		lda	clscnt
3640
 5856  F91411  85 2E         		sta	freecnt
3641
 5857  F91413  A9 02 00      		lda	#2
3642
 5858  F91416  85 30         		sta	freecls
3643
 5859  F91418                		ACC08
3644
 5860  F91418  E2 20         		sep	#PMFLAG
3645
 5861                        		.LONGA	off
3646
 5862                        		.MNLIST
3647
 5863  F9141A  A9 FF         		lda	#$FF
3648
 5864  F9141C  85 3D         		sta	fdfmt
3649
 5865  F9141E  60            		rts
3650
 5866
3651
 5867                        	; new empty fat table
3652
 5868                        	; in:	A=fat bank buffer
3653
 5869  F9141F                	newfat:
3654
 5870
3655
 5871                        		; clear 128k - buffer $100
3656
 5872  F9141F  AD CF FD      		lda	!VIA3+VIAPRANH
3657
 5873  F91422  29 F8         		and	#$F8
3658
 5874  F91424  09 01         		ora	#$01
3659
  Tue Jul 17 11:00:20 2018                                                                                               Page   60
3660
 
3661
 
3662
 
3663
 
3664
 5875  F91426  8D CF FD      		sta	!VIA3+VIAPRANH	; set bank 1 (buffer $100)
3665
 5876  F91429  A2 00         		ldx	#0
3666
 5877  F9142B  8A            		txa
3667
 5878  F9142C                		INDEX16
3668
 5879  F9142C  C2 10         		rep	#PXFLAG
3669
 5880                        		.LONGI	on
3670
 5881                        		.MNLIST
3671
 5882  F9142E  9F 00 00 02   	?01:	sta	>$020000,x
3672
 5883  F91432  9F 00 00 03   		sta	>$030000,x
3673
 5884  F91436  E8            		inx
3674
 5885  F91437  D0 F5         		bne	?01
3675
 5886  F91439  A9 F8         		lda	#$FFF8		; set fake cluster 0&1
3676
 5887  F9143B  8F 00 00 02   		sta	>$020000
3677
 5888  F9143F  A9 FF         		lda	#$FFFF
3678
 5889  F91441  8F 02 00 02   		sta	>$020002
3679
 5890  F91445                		INDEX08
3680
 5891  F91445  E2 10         		sep	#PXFLAG
3681
 5892                        		.LONGI	off
3682
 5893                        		.MNLIST
3683
 5894
3684
 5895  F91447  AE 0A FC      		ldx	CRXME		; save X mem setting
3685
 5896  F9144A  DA            		phx
3686
 5897  F9144B  8D 0B FC      		sta	!CRXMEON	; enable X mem in window $012000 - $013FFF
3687
 5898  F9144E  8B            		phb			; save DBR
3688
 5899  F9144F  A2 01         		ldx	#XMBANK
3689
 5900  F91451  DA            		phx
3690
 5901  F91452  AB            		plb			; set DBR to fat table cache
3691
 5902  F91453  A0 10         		ldy	#16		; clear 16 8k-blocks
3692
 5903  F91455  20 27 15      		jsr	clrxmem
3693
 5904  F91458                		CPU16
3694
 5905  F91458  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
3695
 5906                        		.LONGA	on
3696
 5907                        		.LONGI	on
3697
 5908                        		.MNLIST
3698
 5909  F9145A  A2 00 20      		ldx	#XMSTART
3699
 5910  F9145D  A9 F8 FF      		lda	#$FFF8		; set fake cluster 0&1
3700
 5911  F91460  9D 00 00      		sta	!0,x
3701
 5912  F91463  A9 FF FF      		lda	#$FFFF
3702
 5913  F91466  9D 02 00      		sta	!2,x
3703
 5914  F91469                		CPU08
3704
 5915  F91469  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
3705
 5916                        		.LONGA	off
3706
 5917                        		.LONGI	off
3707
 5918                        		.MNLIST
3708
 5919  F9146B  AB            		plb			; restore DBR
3709
 5920  F9146C  FA            		plx			; restore X mem setting
3710
 5921  F9146D  9D 0A FC      		sta	!CRXME,x
3711
 5922  F91470  60            		rts
3712
 5923
3713
 5924                        	; new empty root directory
3714
 5925                        	; in:	A=root directory bank buffer
3715
 5926  F91471                	newroot:
3716
 5927
3717
 5928                        		; clear 16k - buffer $00
3718
 5929  F91471  AD CF FD      		lda	!VIA3+VIAPRANH
3719
 5930  F91474  29 F8         		and	#$F8
3720
 5931  F91476  8D CF FD      		sta	!VIA3+VIAPRANH	; set bank 1 (buffer $100)
3721
  Tue Jul 17 11:00:20 2018                                                                                               Page   61
3722
 
3723
 
3724
 
3725
 
3726
 5932  F91479  8B            		phb
3727
 5933  F9147A  A9 02         		lda	#$02
3728
 5934  F9147C  48            		pha
3729
 5935  F9147D  AB            		plb
3730
 5936  F9147E                		INDEX16
3731
 5937  F9147E  C2 10         		rep	#PXFLAG
3732
 5938                        		.LONGI	on
3733
 5939                        		.MNLIST
3734
 5940  F91480  A2 FF 3F      		ldx	#$3FFF
3735
 5941  F91483  9E 00 00      	?01:	stz	!$0,x
3736
 5942  F91486  CA            		dex
3737
 5943  F91487  10 FA         		bpl	?01
3738
 5944  F91489                		INDEX08
3739
 5945  F91489  E2 10         		sep	#PXFLAG
3740
 5946                        		.LONGI	off
3741
 5947                        		.MNLIST
3742
 5948  F9148B  A9 08         		lda	#DA_VOLUME
3743
 5949  F9148D  99 01 00      		sta	!0+1,y
3744
 5950  F91490  BF 53 41 00   	?04:	lda	>P0FAT+fcbs,x
3745
 5951  F91494  99 00 00      		sta	!0,y
3746
 5952  F91497  88            		dey
3747
 5953  F91498  CA            		dex
3748
 5954  F91499  10 F5         		bpl	?04
3749
 5955  F9149B                		ACC16
3750
 5956  F9149B  C2 20         		rep	#PMFLAG
3751
 5957                        		.LONGA	on
3752
 5958                        		.MNLIST
3753
 5959  F9149D  A5 48         		lda	ctime		; set creation time&date...
3754
 5960  F9149F  8D 0E 00      		sta	!0+14
3755
 5961  F914A2  8D 16 00      		sta	!0+22	; ...and write time&date
3756
 5962  F914A5  A5 4A         		lda	cdate
3757
 5963  F914A7  8D 10 00      		sta	!0+16
3758
 5964  F914AA  8D 18 00      		sta	!0+24
3759
 5965  F914AD                		ACC08
3760
 5966  F914AD  E2 20         		sep	#PMFLAG
3761
 5967                        		.LONGA	off
3762
 5968                        		.MNLIST
3763
 5969  F914AF  A5 53         		lda	sec100
3764
 5970  F914B1  8D 0D 00      		sta	!0+13
3765
 5971  F914B4  AB            		plb			; restore DBR
3766
 5972  F914B5
3767
 5973  F914B5  AE 0A FC      		ldx	CRXME		; save X mem setting
3768
 5974  F914B8  DA            		phx
3769
 5975  F914B9  8D 0B FC      		sta	!CRXMEON	; enable X mem in window $012000 - $013FFF
3770
 5976  F914BC  8B            		phb			; save DBR
3771
 5977  F914BD  A2 01         		ldx	#XMBANK
3772
 5978  F914BF  DA            		phx
3773
 5979  F914C0  AB            		plb			; set DBR to fat table cache
3774
 5980  F914C1  A0 02         		ldy	#2		; clear 2 8k-blocks
3775
 5981  F914C3  20 27 15      		jsr	clrxmem
3776
 5982  F914C6  A2 0A         		ldx	#10
3777
 5983  F914C8  9B            		txy			; set volume label
3778
 5984  F914C9  A9 08         		lda	#DA_VOLUME
3779
 5985  F914CB  99 01 20      		sta	!XMSTART+1,y
3780
 5986  F914CE  BF 53 41 00   	?10:	lda	>P0FAT+fcbs,x
3781
 5987  F914D2  99 00 20      		sta	!XMSTART,y
3782
 5988  F914D5  88            		dey
3783
  Tue Jul 17 11:00:20 2018                                                                                               Page   62
3784
 
3785
 
3786
 
3787
 
3788
 5989  F914D6  CA            		dex
3789
 5990  F914D7  10 F5         		bpl	?10
3790
 5991  F914D9                		ACC16
3791
 5992  F914D9  C2 20         		rep	#PMFLAG
3792
 5993                        		.LONGA	on
3793
 5994                        		.MNLIST
3794
 5995  F914DB  A5 48         		lda	ctime		; set creation time&date...
3795
 5996  F914DD  8D 0E 20      		sta	!XMSTART+14
3796
 5997  F914E0  8D 16 20      		sta	!XMSTART+22	; ...and write time&date
3797
 5998  F914E3  A5 4A         		lda	cdate
3798
 5999  F914E5  8D 10 20      		sta	!XMSTART+16
3799
 6000  F914E8  8D 18 20      		sta	!XMSTART+24
3800
 6001  F914EB                		ACC08
3801
 6002  F914EB  E2 20         		sep	#PMFLAG
3802
 6003                        		.LONGA	off
3803
 6004                        		.MNLIST
3804
 6005  F914ED  A5 53         		lda	sec100
3805
 6006  F914EF  8D 0D 20      		sta	!XMSTART+13
3806
 6007  F914F2  AB            		plb			; restore DBR
3807
 6008  F914F3  FA            		plx			; restore X mem setting
3808
 6009  F914F4  9D 0A FC      		sta	!CRXME,x
3809
 6010  F914F7  60            		rts
3810
 6011
3811
 6012                        	; new empty cluster
3812
 6013                        	; in:	A=cluster bank buffer
3813
 6014  F914F8                	newcls:
3814
 6015
3815
 6016                        		; clear 32k - buffer $80
3816
 6017  F914F8  AD CF FD      		lda	!VIA3+VIAPRANH
3817
 6018  F914FB  29 F8         		and	#$F8
3818
 6019  F914FD  8D CF FD      		sta	!VIA3+VIAPRANH	; set bank 0 (buffer $80)
3819
 6020  F91500  A9 00         		lda	#0
3820
 6021  F91502                		INDEX16
3821
 6022  F91502  C2 10         		rep	#PXFLAG
3822
 6023                        		.LONGI	on
3823
 6024                        		.MNLIST
3824
 6025  F91504  A2 FF 7F      		ldx	#$7FFF
3825
 6026  F91507  9F 00 80 02   	?01:	sta	>$028000,x
3826
 6027  F9150B  CA            		dex
3827
 6028  F9150C  10 F9         		bpl	?01
3828
 6029  F9150E                		INDEX08
3829
 6030  F9150E  E2 10         		sep	#PXFLAG
3830
 6031                        		.LONGI	off
3831
 6032                        		.MNLIST
3832
 6033
3833
 6034  F91510  AE 0A FC      		ldx	CRXME		; save X mem setting
3834
 6035  F91513  DA            		phx
3835
 6036  F91514  8D 0B FC      		sta	!CRXMEON	; enable X mem in window $012000 - $013FFF
3836
 6037  F91517  8B            		phb			; save DBR
3837
 6038  F91518  A2 01         		ldx	#XMBANK
3838
 6039  F9151A  DA            		phx
3839
 6040  F9151B  AB            		plb			; set DBR to fat table cache
3840
 6041  F9151C  A0 04         		ldy	#4		; clear 4 8k-blocks
3841
 6042                        		;jsr	clrxmem
3842
 6043  F9151E  20 51 15      		jsr	clrxmem2
3843
 6044
3844
 6045  F91521  AB            		plb			; restore DBR
3845
  Tue Jul 17 11:00:20 2018                                                                                               Page   63
3846
 
3847
 
3848
 
3849
 
3850
 6046  F91522  FA            		plx			; restore X mem setting
3851
 6047  F91523  9D 0A FC      		sta	!CRXME,x
3852
 6048  F91526  60            		rts
3853
 6049
3854
 6050                        	; clear x-mem buffer's
3855
 6051                        	; in:	A=starting bank
3856
 6052                        	;	Y=bank count
3857
 6053                        	;	DBR=x-mem bank
3858
 6054                        	; out:	x-mem bank set to starting bank
3859
 6055  F91527                	clrxmem:
3860
 6056  F91527  85 38         		sta	xbnk
3861
 6057  F91529  8F 28 FD 00   		sta	>PIA0+PIAPRA
3862
 6058  F9152D                	?10:	CPU16
3863
 6059  F9152D  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
3864
 6060                        		.LONGA	on
3865
 6061                        		.LONGI	on
3866
 6062                        		.MNLIST
3867
 6063  F9152F  A2 00 20      		ldx	#XMSTART	; start of x-mem window
3868
 6064  F91532  9E 00 00      	?15:	stz	!0,x
3869
 6065  F91535  E8            		inx
3870
 6066  F91536  E8            		inx
3871
 6067  F91537  E0 00 40      		cpx	#XMSTOP
3872
 6068  F9153A  90 F6         		bcc	?15
3873
 6069  F9153C                		CPU08
3874
 6070  F9153C  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
3875
 6071                        		.LONGA	off
3876
 6072                        		.LONGI	off
3877
 6073                        		.MNLIST
3878
 6074  F9153E  AF 28 FD 00   		lda	>PIA0+PIAPRA	; update x-mem bank
3879
 6075  F91542  1A            		inc	a
3880
 6076  F91543  8F 28 FD 00   		sta	>PIA0+PIAPRA
3881
 6077  F91547  88            		dey
3882
 6078  F91548  D0 E3         		bne	?10		; next block
3883
 6079  F9154A  A5 38         		lda	xbnk
3884
 6080  F9154C  8F 28 FD 00   		sta	>PIA0+PIAPRA
3885
 6081  F91550  60            		rts
3886
 6082
3887
 6083  F91551                	clrxmem2:
3888
 6084  F91551  85 38         		sta	xbnk
3889
 6085  F91553  8F 28 FD 00   		sta	>PIA0+PIAPRA
3890
 6086  F91557                	?10:	INDEX16
3891
 6087  F91557  C2 10         		rep	#PXFLAG
3892
 6088                        		.LONGI	on
3893
 6089                        		.MNLIST
3894
 6090  F91559  A2 00 20      		ldx	#XMSTART	; start of x-mem window
3895
 6091  F9155C  A9 00         		lda	#0
3896
 6092  F9155E  9D 00 00      	?15:	sta	!0,x
3897
 6093  F91561  E8            		inx
3898
 6094  F91562  1A            		inc	a
3899
 6095  F91563  E0 00 40      		cpx	#XMSTOP
3900
 6096  F91566  90 F6         		bcc	?15
3901
 6097  F91568                		CPU08
3902
 6098  F91568  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
3903
 6099                        		.LONGA	off
3904
 6100                        		.LONGI	off
3905
 6101                        		.MNLIST
3906
 6102  F9156A  AF 28 FD 00   		lda	>PIA0+PIAPRA	; update x-mem bank
3907
  Tue Jul 17 11:00:20 2018                                                                                               Page   64
3908
 
3909
 
3910
 
3911
 
3912
 6103  F9156E  1A            		inc	a
3913
 6104  F9156F  8F 28 FD 00   		sta	>PIA0+PIAPRA
3914
 6105  F91573  88            		dey
3915
 6106  F91574  D0 E1         		bne	?10		; next block
3916
 6107  F91576  A5 38         		lda	xbnk
3917
 6108  F91578  8F 28 FD 00   		sta	>PIA0+PIAPRA
3918
 6109  F9157C  60            		rts
3919
 6110  F9157D
3920
 6111                        	; write out root directory (xfatb=x-mem root dir. cache buffer)
3921
 6112  F9157D                	wrroot:
3922
 6113  F9157D  A5 39         		lda	lunit
3923
 6114  F9157F  48            		pha
3924
 6115  F91580  4B            		phk
3925
 6116  F91581  F4 A2 15      		pea	#!?10
3926
 6117  F91584  A9 05         		lda	#5
3927
 6118  F91586  48            		pha
3928
 6119  F91587                		BPRINTF
3929
 6120  F91587  02 11         		cop	$11
3930
 6121                        		.MNLIST
3931
 6122  F91589  A5 3E         		lda	pdev
3932
 6123  F9158B  48            		pha			; ata drive
3933
 6124  F9158C  A9 00         		lda	#0
3934
 6125  F9158E  48            		pha
3935
 6126  F9158F  D4 20         		pei	(root)		; root dir. lba
3936
 6127  F91591  A0 20         		ldy	#32
3937
 6128  F91593  5A            		phy			; write 32 sector
3938
 6129  F91594
3939
 6130                        		;pha			; A=0 -> x-mem buffer
3940
 6131                        		;pei	(xfatb)
3941
 6132                        		;lda	#$80		; verify after write
3942
 6133                        		;pha
3943
 6134                        		;ATAWRITE
3944
 6135
3945
 6136  F91594  F4 00 00      		pea	#$0		; buffer #
3946
 6137  F91597                		ATADMAWR
3947
 6138  F91597  02 42         		cop	$42
3948
 6139  F91599  01            		.DB	$01
3949
 6140                        		.MNLIST
3950
 6141  F9159A
3951
 6142  F9159A  B0 03         		bcs	?05
3952
 6143  F9159C  4C 41 16      		jmp	wrok
3953
 6144  F9159F  4C 4C 16      	?05:	jmp	wrerr		; error
3954
 6145
3955
 6146  F915A2  77 72 69 74 65 	?10:	.DB	'write root directory on drive <%c>...', 0
3956
               20 72 6F 6F 74
3957
               20 64 69 72 65
3958
               63 74 6F 72 79
3959
               20 6F 6E 20 64
3960
               72 69 76 65 20
3961
               3C 25 63 3E 2E
3962
               2E 2E 00
3963
 6147
3964
 6148                        	; write out PBR (pointer: pbrp)
3965
 6149  F915C8                	wrpbr:
3966
 6150  F915C8  A5 39         		lda	lunit
3967
 6151  F915CA  48            		pha
3968
 6152  F915CB  4B            		phk
3969
  Tue Jul 17 11:00:20 2018                                                                                               Page   65
3970
 
3971
 
3972
 
3973
 
3974
 6153  F915CC  F4 E9 15      		pea	#!?10
3975
 6154  F915CF  A9 05         		lda	#5
3976
 6155  F915D1  48            		pha
3977
 6156  F915D2                		BPRINTF
3978
 6157  F915D2  02 11         		cop	$11
3979
 6158                        		.MNLIST
3980
 6159  F915D4  A5 3E         		lda	pdev
3981
 6160  F915D6  48            		pha			; ata drive
3982
 6161  F915D7  A9 00         		lda	#0
3983
 6162  F915D9  48            		pha
3984
 6163  F915DA  D4 08         		pei	(hidsec)	; lba=partition start
3985
 6164  F915DC  A9 01         		lda	#1
3986
 6165  F915DE  48            		pha			; write 1 sector
3987
 6166  F915DF
3988
 6167                        		;lda	pbrp+2
3989
 6168                        		;pha			; buffer pointer
3990
 6169                        		;pei	(pbrp)
3991
 6170                        		;lda	#$80		; verify after write
3992
 6171                        		;pha
3993
 6172                        		;ATAWRITE
3994
 6173
3995
 6174  F915DF  F4 21 00      		pea	#$21		; buffer #
3996
 6175  F915E2                		ATADMAWR
3997
 6176  F915E2  02 42         		cop	$42
3998
 6177  F915E4  01            		.DB	$01
3999
 6178                        		.MNLIST
4000
 6179  F915E5
4001
 6180  F915E5  90 5A         		bcc	wrok
4002
 6181  F915E7  B0 63         		bcs	wrerr		; error
4003
 6182
4004
 6183  F915E9  77 72 69 74 65 	?10:	.DB	'write PBR on drive <%c>...', 0
4005
               20 50 42 52 20
4006
               6F 6E 20 64 72
4007
               69 76 65 20 3C
4008
               25 63 3E 2E 2E
4009
               2E 00
4010
 6184
4011
 6185                        	; write out MBR (pointer: tlp)
4012
 6186  F91604                	wrmbr:
4013
 6187  F91604  A5 39         		lda	lunit
4014
 6188  F91606  48            		pha
4015
 6189  F91607  4B            		phk
4016
 6190  F91608  F4 26 16      		pea	#!?10
4017
 6191  F9160B  A9 05         		lda	#5
4018
 6192  F9160D  48            		pha
4019
 6193  F9160E                		BPRINTF
4020
 6194  F9160E  02 11         		cop	$11
4021
 6195                        		.MNLIST
4022
 6196  F91610  A5 3E         		lda	pdev
4023
 6197  F91612  48            		pha			; ata drive
4024
 6198  F91613  A9 00         		lda	#0
4025
 6199  F91615  48            		pha
4026
 6200  F91616  F4 00 00      		pea	#0		; lba=0
4027
 6201  F91619  A9 01         		lda	#1
4028
 6202  F9161B  48            		pha			; write 1 sector
4029
 6203  F9161C
4030
 6204                        		;lda	tlp+2
4031
  Tue Jul 17 11:00:20 2018                                                                                               Page   66
4032
 
4033
 
4034
 
4035
 
4036
 6205                        		;pha			; buffer pointer
4037
 6206                        		;pei	(tlp)
4038
 6207                        		;lda	#$80		; verify after write
4039
 6208                        		;pha
4040
 6209                        		;ATAWRITE
4041
 6210  F9161C  F4 20 00      		pea	#$20		; buffer #
4042
 6211  F9161F                		ATADMAWR
4043
 6212  F9161F  02 42         		cop	$42
4044
 6213  F91621  01            		.DB	$01
4045
 6214                        		.MNLIST
4046
 6215  F91622
4047
 6216  F91622  90 1D         		bcc	wrok
4048
 6217  F91624  B0 26         		bcs	wrerr		; error
4049
 6218
4050
 6219  F91626  77 72 69 74 65 	?10:	.DB	'write MBR on drive <%c>...', 0
4051
               20 4D 42 52 20
4052
               6F 6E 20 64 72
4053
               69 76 65 20 3C
4054
               25 63 3E 2E 2E
4055
               2E 00
4056
 6220  F91641
4057
 6221  F91641                	wrok:
4058
 6222  F91641                		SCNPRINT
4059
 6223  F91641  02 01         		cop	$01
4060
 6224                        		.MNLIST
4061
 6225  F91643  64 6F 6E 65 2E 		.DB	'done.', 13, 0
4062
               0D 00
4063
 6226  F9164A  18            		clc
4064
 6227  F9164B  60            		rts			; CF=1 if error
4065
 6228
4066
 6229  F9164C                	wrerr:
4067
 6230  F9164C  DA            		phx			; bit error
4068
 6231  F9164D  5A            		phy			; error code
4069
 6232  F9164E  4B            		phk
4070
 6233  F9164F  F4 59 16      		pea	#!?10
4071
 6234  F91652  A9 06         		lda	#6
4072
 6235  F91654  48            		pha
4073
 6236  F91655                		BPRINTF
4074
 6237  F91655  02 11         		cop	$11
4075
 6238                        		.MNLIST
4076
 6239  F91657  38            		sec
4077
 6240  F91658  60            		rts
4078
 6241  F91659
4079
 6242  F91659  65 72 72 6F 72 	?10:	.DB	'error %02bX (bits error: %02bX).', 13, 0
4080
               20 25 30 32 62
4081
               58 20 28 62 69
4082
               74 73 20 65 72
4083
               72 6F 72 3A 20
4084
               25 30 32 62 58
4085
               29 2E 0D 00
4086
 6243
4087
 6244                        	; write out fat table (xfatb=x-mem fat cache buffer, X=fat)
4088
 6245  F9167B                	wrfat:
4089
 6246  F9167B  A5 39         		lda	lunit
4090
 6247  F9167D  48            		pha
4091
 6248  F9167E  DA            		phx
4092
 6249  F9167F  4B            		phk
4093
  Tue Jul 17 11:00:20 2018                                                                                               Page   67
4094
 
4095
 
4096
 
4097
 
4098
 6250  F91680  F4 9D 16      		pea	#!?10
4099
 6251  F91683  A9 06         		lda	#6
4100
 6252  F91685  48            		pha
4101
 6253  F91686                		BPRINTF
4102
 6254  F91686  02 11         		cop	$11
4103
 6255                        		.MNLIST
4104
 6256  F91688  A5 3E         		lda	pdev
4105
 6257  F9168A  48            		pha			; ata drive
4106
 6258  F9168B  A9 00         		lda	#0
4107
 6259  F9168D  48            		pha
4108
 6260  F9168E  D4 2C         		pei	(flba)		; fat table lba
4109
 6261  F91690  A4 18         		ldy	fatsiz
4110
 6262  F91692  5A            		phy			; write n sector
4111
 6263  F91693
4112
 6264                        		;pha			; A=0 -> x-mem buffer
4113
 6265                        		;pei	(xfatb)
4114
 6266                        		;lda	#$80		; verify after write
4115
 6267                        		;pha
4116
 6268                        		;ATAWRITE
4117
 6269
4118
 6270  F91693  F4 00 01      		pea	#$100		; buffer #
4119
 6271  F91696                		ATADMAWR
4120
 6272  F91696  02 42         		cop	$42
4121
 6273  F91698  01            		.DB	$01
4122
 6274                        		.MNLIST
4123
 6275  F91699
4124
 6276  F91699  90 A6         		bcc	wrok
4125
 6277  F9169B  B0 AF         		bcs	wrerr		; error
4126
 6278
4127
 6279  F9169D  77 72 69 74 65 	?10:	.DB	'write FAT%bu table on drive <%c>...', 0
4128
               20 46 41 54 25
4129
               62 75 20 74 61
4130
               62 6C 65 20 6F
4131
               6E 20 64 72 69
4132
               76 65 20 3C 25
4133
               63 3E 2E 2E 2E
4134
               00
4135
 6280
4136
 6281                        	; A=drive
4137
 6282  F916C1                	shpart:
4138
 6283  F916C1  AA            		tax
4139
 6284  F916C2  A0 00         		ldy	#0
4140
 6285  F916C4  20 83 11      		jsr	prenew		; move data of partition
4141
 6286  F916C7  B0 1D         		bcs	?30
4142
 6287  F916C9  A5 39         		lda	lunit
4143
 6288  F916CB  48            		pha
4144
 6289  F916CC  4B            		phk
4145
 6290  F916CD  24 41         		bit	lflag
4146
 6291  F916CF  30 0A         		bmi	?20		; valid partition
4147
 6292  F916D1  F4 0A 17      		pea	#!?110
4148
 6293  F916D4  A9 05         		lda	#5
4149
 6294  F916D6  48            		pha
4150
 6295  F916D7                		BPRINTF
4151
 6296  F916D7  02 11         		cop	$11
4152
 6297                        		.MNLIST
4153
 6298  F916D9  80 0B         		bra	?30
4154
 6299  F916DB  F4 E7 16      	?20:	pea	#!?100
4155
  Tue Jul 17 11:00:20 2018                                                                                               Page   68
4156
 
4157
 
4158
 
4159
 
4160
 6300  F916DE  A9 05         		lda	#5
4161
 6301  F916E0  48            		pha
4162
 6302  F916E1                		BPRINTF
4163
 6303  F916E1  02 11         		cop	$11
4164
 6304                        		.MNLIST
4165
 6305  F916E3  20 B5 17      		jsr	showprt
4166
 6306  F916E6  60            	?30:	rts
4167
 6307
4168
 6308  F916E7  0D 70 61 72 74 	?100:	.DB	13, 'partition summary on drive <%c>:', 13, 0
4169
               69 74 69 6F 6E
4170
               20 73 75 6D 6D
4171
               61 72 79 20 6F
4172
               6E 20 64 72 69
4173
               76 65 20 3C 25
4174
               63 3E 3A 0D 00
4175
 6309  F9170A  0D 6E 6F 20 76 	?110:	.DB	13, 'no valid partition found on drive <%c>.', 13, 0
4176
               61 6C 69 64 20
4177
               70 61 72 74 69
4178
               74 69 6F 6E 20
4179
               66 6F 75 6E 64
4180
               20 6F 6E 20 64
4181
               72 69 76 65 20
4182
               3C 25 63 3E 2E
4183
               0D 00
4184
 6310
4185
 6311  F91734                	atanewp:
4186
 6312                        		.PUBLIC atanewp
4187
 6313  F91734  0B            		phd
4188
 6314  F91735  F4 00 40      		pea	#P0LDT
4189
 6315  F91738  2B            		pld
4190
 6316  F91739  A0 00         		ldy	#0
4191
 6317  F9173B  20 EB 0E      		jsr	lfdisk
4192
 6318  F9173E  2B            		pld
4193
 6319  F9173F  6B            		rtl
4194
 6320
4195
 6321                        	; fixed disk pre-format routine
4196
 6322                        	; in:	X=logical drive
4197
 6323                        	;	Y=$FF if label is specified
4198
 6324  F91740                	prefmt:
4199
 6325  F91740  20 83 11      		jsr	prenew		; move data of partition
4200
 6326  F91743  B0 1E         		bcs	?30		; no valid partition
4201
 6327  F91745  A5 39         		lda	lunit
4202
 6328  F91747  48            		pha
4203
 6329  F91748  4B            		phk
4204
 6330  F91749  24 41         		bit	lflag
4205
 6331  F9174B  30 0A         		bmi	?20		; valid partition
4206
 6332  F9174D  F4 8B 17      		pea	#!?110
4207
 6333  F91750  A9 05         		lda	#5
4208
 6334  F91752  48            		pha
4209
 6335  F91753                		BPRINTF
4210
 6336  F91753  02 11         		cop	$11
4211
 6337                        		.MNLIST
4212
 6338  F91755  80 0C         		bra	?30
4213
 6339  F91757  F4 64 17      	?20:	pea	#!?100
4214
 6340  F9175A  A9 05         		lda	#5
4215
 6341  F9175C  48            		pha
4216
 6342  F9175D                		BPRINTF
4217
  Tue Jul 17 11:00:20 2018                                                                                               Page   69
4218
 
4219
 
4220
 
4221
 
4222
 6343  F9175D  02 11         		cop	$11
4223
 6344                        		.MNLIST
4224
 6345  F9175F  20 B5 17      		jsr	showprt
4225
 6346  F91762  18            		clc
4226
 6347  F91763  60            	?30:	rts
4227
 6348
4228
 6349  F91764  0D 66 6F 72 6D 	?100:	.DB	13, 'format main partition on drive <%c>:', 13, 0
4229
               61 74 20 6D 61
4230
               69 6E 20 70 61
4231
               72 74 69 74 69
4232
               6F 6E 20 6F 6E
4233
               20 64 72 69 76
4234
               65 20 3C 25 63
4235
               3E 3A 0D 00
4236
 6350  F9178B  0D 6E 6F 20 76 	?110:	.DB	13, 'no valid partition found on drive <%c>.', 13, 0
4237
               61 6C 69 64 20
4238
               70 61 72 74 69
4239
               74 69 6F 6E 20
4240
               66 6F 75 6E 64
4241
               20 6F 6E 20 64
4242
               72 69 76 65 20
4243
               3C 25 63 3E 2E
4244
               0D 00
4245
 6351  F917B5
4246
 6352                        	; print partition data
4247
 6353  F917B5                	showprt:
4248
 6354  F917B5  D4 06         		pei	(maxsec+2)
4249
 6355  F917B7  D4 04         		pei	(maxsec)
4250
 6356  F917B9  D4 06         		pei	(maxsec+2)
4251
 6357  F917BB  D4 04         		pei	(maxsec)
4252
 6358  F917BD  4B            		phk
4253
 6359  F917BE  F4 59 18      		pea	#!?10
4254
 6360  F917C1  A9 0C         		lda	#12
4255
 6361  F917C3  48            		pha
4256
 6362  F917C4                		BPRINTF
4257
 6363  F917C4  02 11         		cop	$11
4258
 6364                        		.MNLIST
4259
 6365  F917C6  D4 0A         		pei	(hidsec+2)
4260
 6366  F917C8  D4 08         		pei	(hidsec)
4261
 6367  F917CA  D4 0A         		pei	(hidsec+2)
4262
 6368  F917CC  D4 08         		pei	(hidsec)
4263
 6369  F917CE  4B            		phk
4264
 6370  F917CF  F4 79 18      		pea	#!?20
4265
 6371  F917D2  A9 0C         		lda	#12
4266
 6372  F917D4  48            		pha
4267
 6373  F917D5                		BPRINTF
4268
 6374  F917D5  02 11         		cop	$11
4269
 6375                        		.MNLIST
4270
 6376  F917D7  D4 0E         		pei	(totsec+2)
4271
 6377  F917D9  D4 0C         		pei	(totsec)
4272
 6378  F917DB  D4 0E         		pei	(totsec+2)
4273
 6379  F917DD  D4 0C         		pei	(totsec)
4274
 6380  F917DF  4B            		phk
4275
 6381  F917E0  F4 99 18      		pea	#!?30
4276
 6382  F917E3  A9 0C         		lda	#12
4277
 6383  F917E5  48            		pha
4278
 6384  F917E6                		BPRINTF
4279
  Tue Jul 17 11:00:20 2018                                                                                               Page   70
4280
 
4281
 
4282
 
4283
 
4284
 6385  F917E6  02 11         		cop	$11
4285
 6386                        		.MNLIST
4286
 6387  F917E8  D4 30         		pei	(remsec+2)
4287
 6388  F917EA  D4 2E         		pei	(remsec)
4288
 6389  F917EC  D4 30         		pei	(remsec+2)
4289
 6390  F917EE  D4 2E         		pei	(remsec)
4290
 6391  F917F0  4B            		phk
4291
 6392  F917F1  F4 B9 18      		pea	#!?40
4292
 6393  F917F4  A9 0C         		lda	#12
4293
 6394  F917F6  48            		pha
4294
 6395  F917F7                		BPRINTF
4295
 6396  F917F7  02 11         		cop	$11
4296
 6397                        		.MNLIST
4297
 6398  F917F9  D4 18         		pei	(fatsiz)
4298
 6399  F917FB  D4 18         		pei	(fatsiz)
4299
 6400  F917FD  4B            		phk
4300
 6401  F917FE  F4 D9 18      		pea	#!?50
4301
 6402  F91801  A9 08         		lda	#8
4302
 6403  F91803  48            		pha
4303
 6404  F91804                		BPRINTF
4304
 6405  F91804  02 11         		cop	$11
4305
 6406                        		.MNLIST
4306
 6407  F91806  D4 14         		pei	(clscnt)
4307
 6408  F91808  D4 14         		pei	(clscnt)
4308
 6409  F9180A  4B            		phk
4309
 6410  F9180B  F4 FD 18      		pea	#!?60
4310
 6411  F9180E  A9 08         		lda	#8
4311
 6412  F91810  48            		pha
4312
 6413  F91811                		BPRINTF
4313
 6414  F91811  02 11         		cop	$11
4314
 6415                        		.MNLIST
4315
 6416  F91813  A5 35         		lda	clssiz
4316
 6417  F91815  48            		pha
4317
 6418  F91816  48            		pha
4318
 6419  F91817  4B            		phk
4319
 6420  F91818  F4 21 19      		pea	#!?70
4320
 6421  F9181B  A9 06         		lda	#6
4321
 6422  F9181D  48            		pha
4322
 6423  F9181E                		BPRINTF
4323
 6424  F9181E  02 11         		cop	$11
4324
 6425                        		.MNLIST
4325
 6426  F91820  F4 00 00      		pea	#0
4326
 6427  F91823  D4 22         		pei	(fat1)
4327
 6428  F91825  4B            		phk
4328
 6429  F91826  F4 4F 19      		pea	#!?75
4329
 6430  F91829  A9 08         		lda	#8
4330
 6431  F9182B  48            		pha
4331
 6432  F9182C                		BPRINTF
4332
 6433  F9182C  02 11         		cop	$11
4333
 6434                        		.MNLIST
4334
 6435  F9182E  F4 00 00      		pea	#0
4335
 6436  F91831  D4 24         		pei	(fat2)
4336
 6437  F91833  4B            		phk
4337
 6438  F91834  F4 67 19      		pea	#!?80
4338
 6439  F91837  A9 08         		lda	#8
4339
 6440  F91839  48            		pha
4340
 6441  F9183A                		BPRINTF
4341
  Tue Jul 17 11:00:20 2018                                                                                               Page   71
4342
 
4343
 
4344
 
4345
 
4346
 6442  F9183A  02 11         		cop	$11
4347
 6443                        		.MNLIST
4348
 6444  F9183C  F4 00 00      		pea	#0
4349
 6445  F9183F  D4 20         		pei	(root)
4350
 6446  F91841  4B            		phk
4351
 6447  F91842  F4 7F 19      		pea	#!?85
4352
 6448  F91845  A9 08         		lda	#8
4353
 6449  F91847  48            		pha
4354
 6450  F91848                		BPRINTF
4355
 6451  F91848  02 11         		cop	$11
4356
 6452                        		.MNLIST
4357
 6453  F9184A  F4 00 00      		pea	#0
4358
 6454  F9184D  D4 26         		pei	(start)
4359
 6455  F9184F  4B            		phk
4360
 6456  F91850  F4 97 19      		pea	#!?90
4361
 6457  F91853  A9 08         		lda	#8
4362
 6458  F91855  48            		pha
4363
 6459  F91856                		BPRINTF
4364
 6460  F91856  02 11         		cop	$11
4365
 6461                        		.MNLIST
4366
 6462  F91858  60            		rts
4367
 6463
4368
 6464  F91859  74 6F 74 61 6C 	?10:	.DB	'total sector(s) : %08X %, +10u', 13, 0
4369
               20 73 65 63 74
4370
               6F 72 28 73 29
4371
               20 3A 20 25 30
4372
               38 58 20 25 2C
4373
               20 2B 31 30 75
4374
               0D 00
4375
 6465  F91879  70 61 72 74 69 	?20:	.DB	'partition start : %08X %, +10u', 13, 0
4376
               74 69 6F 6E 20
4377
               73 74 61 72 74
4378
               20 3A 20 25 30
4379
               38 58 20 25 2C
4380
               20 2B 31 30 75
4381
               0D 00
4382
 6466  F91899  70 61 72 74 69 	?30:	.DB	'partition size  : %08X %, +10u', 13, 0
4383
               74 69 6F 6E 20
4384
               73 69 7A 65 20
4385
               20 3A 20 25 30
4386
               38 58 20 25 2C
4387
               20 2B 31 30 75
4388
               0D 00
4389
 6467  F918B9  75 6E 75 73 65 	?40:	.DB	'unused sector(s): %08X %, +10u', 13, 0
4390
               64 20 73 65 63
4391
               74 6F 72 28 73
4392
               29 3A 20 25 30
4393
               38 58 20 25 2C
4394
               20 2B 31 30 75
4395
               0D 00
4396
 6468  F918D9  66 61 74 20 74 	?50:	.DB	'fat table size  : % 8.4hX %, +10hu', 13, 0
4397
               61 62 6C 65 20
4398
               73 69 7A 65 20
4399
               20 3A 20 25 20
4400
               38 2E 34 68 58
4401
               20 25 2C 20 2B
4402
               31 30 68 75 0D
4403
  Tue Jul 17 11:00:20 2018                                                                                               Page   72
4404
 
4405
 
4406
 
4407
 
4408
               00
4409
 6469  F918FD  63 6C 75 73 74 	?60:	.DB	'clusters count  : % 8.4hX %, +10hu', 13, 0
4410
               65 72 73 20 63
4411
               6F 75 6E 74 20
4412
               20 3A 20 25 20
4413
               38 2E 34 68 58
4414
               20 25 2C 20 2B
4415
               31 30 68 75 0D
4416
               00
4417
 6470  F91921  63 6C 75 73 74 	?70:	.DB	'cluster size    : % 8.4bX %, +10bu sector(s)', 13, 0
4418
               65 72 20 73 69
4419
               7A 65 20 20 20
4420
               20 3A 20 25 20
4421
               38 2E 34 62 58
4422
               20 25 2C 20 2B
4423
               31 30 62 75 20
4424
               73 65 63 74 6F
4425
               72 28 73 29 0D
4426
               00
4427
 6471  F9194F  66 61 74 31 20 	?75:	.DB	'fat1 table start: %08X', 13, 0
4428
               74 61 62 6C 65
4429
               20 73 74 61 72
4430
               74 3A 20 25 30
4431
               38 58 0D 00
4432
 6472  F91967  66 61 74 32 20 	?80:	.DB	'fat2 table start: %08X', 13, 0
4433
               74 61 62 6C 65
4434
               20 73 74 61 72
4435
               74 3A 20 25 30
4436
               38 58 0D 00
4437
 6473  F9197F  72 6F 6F 74 20 	?85:	.DB	'root dir. start : %08X', 13, 0
4438
               64 69 72 2E 20
4439
               73 74 61 72 74
4440
               20 3A 20 25 30
4441
               38 58 0D 00
4442
 6474  F91997  63 6C 75 73 74 	?90:	.DB	'cluster #2 start: %08X', 13, 0
4443
               65 72 20 23 32
4444
               20 73 74 61 72
4445
               74 3A 20 25 30
4446
               38 58 0D 00
4447
 6475
4448
 6476                        	; compute a new disk partition
4449
 6477  F919AF                	newprt:
4450
 6478  F919AF  A5 3E         		lda	pdev		; phisycal drive
4451
 6479  F919B1  0A            		asl	a
4452
 6480  F919B2  0A            		asl	a
4453
 6481  F919B3  AA            		tax
4454
 6482  F919B4  A5 00         		lda	defhsec
4455
 6483  F919B6  85 08         		sta	hidsec		; hidden sector's
4456
 6484  F919B8  64 09         		stz	hidsec+1
4457
 6485  F919BA                		ACC16
4458
 6486  F919BA  C2 20         		rep	#PMFLAG
4459
 6487                        		.LONGA	on
4460
 6488                        		.MNLIST
4461
 6489  F919BC  64 0A         		stz	hidsec+2
4462
 6490  F919BE  BD 12 00      		lda	!atasec,x	; max. disk usable sector's
4463
 6491  F919C1  85 04         		sta	maxsec
4464
 6492  F919C3  BD 14 00      		lda	!atasec+2,x
4465
  Tue Jul 17 11:00:20 2018                                                                                               Page   73
4466
 
4467
 
4468
 
4469
 
4470
 6493  F919C6  85 06         		sta	maxsec+2
4471
 6494  F919C8  A9 01 00      		lda	#1
4472
 6495  F919CB  85 16         		sta	rsvsec		; reserved sector for PBR
4473
 6496  F919CD  A9 20 00      		lda	#32
4474
 6497  F919D0  85 1A         		sta	rootsiz		; root directory sector's
4475
 6498  F919D2  A5 08         		lda	hidsec
4476
 6499  F919D4  1A            		inc	a		; leave one sector at partition end
4477
 6500  F919D5  85 2E         		sta	remsec
4478
 6501  F919D7  38            		sec
4479
 6502  F919D8  A5 04         		lda	maxsec
4480
 6503  F919DA  E5 2E         		sbc	remsec
4481
 6504  F919DC  85 0C         		sta	totsec		; total partition sector's
4482
 6505  F919DE  A5 06         		lda	maxsec+2
4483
 6506  F919E0  E5 0A         		sbc	hidsec+2	; this is null
4484
 6507  F919E2  85 0E         		sta	totsec+2
4485
 6508  F919E4  18            		clc
4486
 6509  F919E5  A5 08         		lda	hidsec		; compute total reserved sector's
4487
 6510  F919E7  65 16         		adc	rsvsec
4488
 6511  F919E9  65 1A         		adc	rootsiz
4489
 6512  F919EB  85 12         		sta	totrsv
4490
 6513  F919ED  A5 06         		lda	maxsec+2
4491
 6514  F919EF  C9 40 00      		cmp	#$0040		; disk size > 2gb?
4492
 6515  F919F2  90 1F         		bcc	?05		; no
4493
 6516  F919F4  A2 40         		ldx	#$40		; yes, so...
4494
 6517  F919F6  86 35         		stx	clssiz		; ...cluser size=64 sector's...
4495
 6518  F919F8  A2 06         		ldx	#6
4496
 6519  F919FA  86 36         		stx	clsshf
4497
 6520  F919FC  A9 00 01      		lda	#$0100		; ...and fat size=max (256 sector's)...
4498
 6521  F919FF  85 18         		sta	fatsiz
4499
 6522  F91A01  A9 F4 FF      		lda	#MAXF16-1
4500
 6523  F91A04  85 14         		sta	clscnt		; ...and cluster's count=max ($FFF4)...
4501
 6524  F91A06  A9 30 FF      		lda	#$FF30		; ...and set partition totsec=$3FFF30
4502
 6525  F91A09  85 0C         		sta	totsec
4503
 6526  F91A0B  A9 3F 00      		lda	#$003F
4504
 6527  F91A0E  85 0E         		sta	totsec+2
4505
 6528  F91A10  4C A3 1A      		jmp	?50		; done for disk > 2Gb
4506
 6529  F91A13                	?05:	CPU08			; now disk <= 2Gb
4507
 6530  F91A13  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
4508
 6531                        		.LONGA	off
4509
 6532                        		.LONGI	off
4510
 6533                        		.MNLIST
4511
 6534  F91A15  A5 06         		lda	maxsec+2
4512
 6535  F91A17  A2 00         		ldx	#0
4513
 6536  F91A19  DF 61 1C F9   	?10:	cmp	>CLSSIZE,x
4514
 6537  F91A1D  90 06         		bcc	?15		; X=shift
4515
 6538  F91A1F  E8            		inx
4516
 6539  F91A20  E0 07         		cpx	#7
4517
 6540  F91A22  90 F5         		bcc	?10
4518
 6541  F91A24  CA            		dex
4519
 6542  F91A25  BF 61 1C F9   	?15:	lda	>CLSSIZE,x
4520
 6543  F91A29  85 35         		sta	clssiz		; cluster size
4521
 6544  F91A2B  86 36         		stx	clsshf		; cluster shift
4522
 6545  F91A2D                		CPU16
4523
 6546  F91A2D  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
4524
 6547                        		.LONGA	on
4525
 6548                        		.LONGI	on
4526
 6549                        		.MNLIST
4527
  Tue Jul 17 11:00:20 2018                                                                                               Page   74
4528
 
4529
 
4530
 
4531
 
4532
 6550  F91A2F  38            		sec			; compute approximate fat size
4533
 6551  F91A30  A5 04         		lda	maxsec
4534
 6552  F91A32  E5 12         		sbc	totrsv
4535
 6553  F91A34  85 10         		sta	maxcnt
4536
 6554  F91A36  A5 06         		lda	maxsec+2
4537
 6555  F91A38  E9 00 00      		sbc	#0
4538
 6556  F91A3B  9B            		txy
4539
 6557  F91A3C  F0 06         		beq	?25		; no shift
4540
 6558  F91A3E  4A            	?20:	lsr	a		; divide by cluster size
4541
 6559  F91A3F  66 10         		ror	maxcnt
4542
 6560  F91A41  CA            		dex
4543
 6561  F91A42  D0 FA         		bne	?20
4544
 6562  F91A44  AA            	?25:	tax			; now C must be cleared
4545
 6563  F91A45  D0 59         		bne	?48		; error... shoul'nt happen
4546
 6564  F91A47                		CPU08
4547
 6565  F91A47  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
4548
 6566                        		.LONGA	off
4549
 6567                        		.LONGI	off
4550
 6568                        		.MNLIST
4551
 6569  F91A49  A5 11         		lda	maxcnt+1	; high byte is fat size!
4552
 6570  F91A4B  1A            		inc	a
4553
 6571  F91A4C  D0 01         		bne	?30
4554
 6572  F91A4E  E8            		inx			; fat size=256
4555
 6573  F91A4F  85 18         	?30:	sta	fatsiz
4556
 6574  F91A51  86 19         		stx	fatsiz+1
4557
 6575  F91A53                		ACC16CLC
4558
 6576  F91A53  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
4559
 6577                        		.LONGA	on
4560
 6578                        		.MNLIST
4561
 6579  F91A55  A5 16         	?35:	lda	rsvsec		; now compute clusters count
4562
 6580  F91A57  65 18         		adc	fatsiz
4563
 6581  F91A59  65 18         		adc	fatsiz
4564
 6582  F91A5B  65 1A         		adc	rootsiz
4565
 6583  F91A5D  85 14         		sta	clscnt
4566
 6584  F91A5F  38            		sec
4567
 6585  F91A60  A5 0C         		lda	totsec
4568
 6586  F91A62  E5 14         		sbc	clscnt
4569
 6587  F91A64  85 14         		sta	clscnt
4570
 6588  F91A66  A5 0E         		lda	totsec+2
4571
 6589  F91A68  E9 00 00      		sbc	#0
4572
 6590  F91A6B  A6 36         		ldx	clsshf
4573
 6591  F91A6D                		INDEX16
4574
 6592  F91A6D  C2 10         		rep	#PXFLAG
4575
 6593                        		.LONGI	on
4576
 6594                        		.MNLIST
4577
 6595  F91A6F  F0 06         		beq	?45
4578
 6596  F91A71  4A            	?40:	lsr	a
4579
 6597  F91A72  66 14         		ror	clscnt
4580
 6598  F91A74  CA            		dex
4581
 6599  F91A75  D0 FA         		bne	?40
4582
 6600  F91A77  AA            	?45:	tax			; now C must be cleared
4583
 6601  F91A78  D0 26         		bne	?48		; error... shoul'nt happen
4584
 6602  F91A7A                		INDEX08
4585
 6603  F91A7A  E2 10         		sep	#PXFLAG
4586
 6604                        		.LONGI	off
4587
 6605                        		.MNLIST
4588
 6606  F91A7C  A5 14         		lda	clscnt
4589
  Tue Jul 17 11:00:20 2018                                                                                               Page   75
4590
 
4591
 
4592
 
4593
 
4594
 6607  F91A7E  C9 F5 FF      		cmp	#MAXF16
4595
 6608  F91A81  90 04         		bcc	?46
4596
 6609  F91A83  A9 F4 FF      		lda	#MAXF16-1
4597
 6610  F91A86  18            		clc
4598
 6611  F91A87  1A            	?46:	inc	a		; add fake cluster 0&1
4599
 6612  F91A88  1A            		inc	a
4600
 6613  F91A89  69 FF 00      		adc	#$00FF		; round to fit sector
4601
 6614  F91A8C  29 00 FF      		and	#$FF00
4602
 6615  F91A8F  EB            		xba
4603
 6616  F91A90  90 03         		bcc	?47
4604
 6617  F91A92  69 00 01      		adc	#$0100
4605
 6618  F91A95  C5 18         	?47:	cmp	fatsiz
4606
 6619  F91A97  F0 0A         		beq	?50		; ok, fat size is right
4607
 6620  F91A99  90 08         		bcc	?50		; ok, fat size is right
4608
 6621  F91A9B  E6 18         		inc	fatsiz		; increment fat size
4609
 6622  F91A9D  18            		clc
4610
 6623  F91A9E  80 B5         		bra	?35		; try again
4611
 6624  F91AA0  38            	?48:	sec
4612
 6625  F91AA1  80 4D         		bra	?55
4613
 6626  F91AA3                	?50:	INDEX08
4614
 6627  F91AA3  E2 10         		sep	#PXFLAG
4615
 6628                        		.LONGI	off
4616
 6629                        		.MNLIST
4617
 6630  F91AA5  18            		clc
4618
 6631  F91AA6  A5 12         		lda	totrsv
4619
 6632  F91AA8  65 18         		adc	fatsiz
4620
 6633  F91AAA  65 18         		adc	fatsiz
4621
 6634  F91AAC  85 12         		sta	totrsv
4622
 6635  F91AAE  A5 14         		lda	clscnt
4623
 6636  F91AB0  85 2E         		sta	remsec
4624
 6637  F91AB2  1A            		inc	a
4625
 6638  F91AB3  1A            		inc	a
4626
 6639  F91AB4  85 28         		sta	maxcls
4627
 6640  F91AB6  A9 00 00      		lda	#0
4628
 6641  F91AB9  A6 36         		ldx	clsshf
4629
 6642  F91ABB  F0 06         		beq	?52
4630
 6643  F91ABD  06 2E         	?51:	asl	remsec
4631
 6644  F91ABF  2A            		rol	a
4632
 6645  F91AC0  CA            		dex
4633
 6646  F91AC1  D0 FA         		bne	?51
4634
 6647  F91AC3  85 30         	?52:	sta	remsec+2
4635
 6648  F91AC5  A5 2E         		lda	remsec
4636
 6649  F91AC7  18            		clc
4637
 6650  F91AC8  65 12         		adc	totrsv
4638
 6651  F91ACA  85 2E         		sta	remsec
4639
 6652  F91ACC  90 02         		bcc	?53
4640
 6653  F91ACE  E6 30         		inc	remsec+2
4641
 6654  F91AD0  A5 04         	?53:	lda	maxsec
4642
 6655  F91AD2  38            		sec
4643
 6656  F91AD3  E5 2E         		sbc	remsec
4644
 6657  F91AD5  85 2E         		sta	remsec
4645
 6658  F91AD7  A5 06         		lda	maxsec+2
4646
 6659  F91AD9  E5 30         		sbc	remsec+2
4647
 6660  F91ADB  85 30         		sta	remsec+2
4648
 6661  F91ADD  18            		clc
4649
 6662  F91ADE  A5 08         		lda	hidsec
4650
 6663  F91AE0  65 16         		adc	rsvsec
4651
  Tue Jul 17 11:00:20 2018                                                                                               Page   76
4652
 
4653
 
4654
 
4655
 
4656
 6664  F91AE2  85 22         		sta	fat1
4657
 6665  F91AE4  65 18         		adc	fatsiz
4658
 6666  F91AE6  85 24         		sta	fat2
4659
 6667  F91AE8  65 18         		adc	fatsiz
4660
 6668  F91AEA  85 20         		sta	root
4661
 6669  F91AEC  65 1A         		adc	rootsiz
4662
 6670  F91AEE  85 26         		sta	start
4663
 6671  F91AF0                	?55:	CPU08
4664
 6672  F91AF0  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
4665
 6673                        		.LONGA	off
4666
 6674                        		.LONGI	off
4667
 6675                        		.MNLIST
4668
 6676  F91AF2  60            		rts
4669
 6677
4670
 6678  F91AF3                	askfmt:
4671
 6679  F91AF3                		SCNPRINT
4672
 6680  F91AF3  02 01         		cop	$01
4673
 6681                        		.MNLIST
4674
 6682  F91AF5  63 6F 6E 74 69 		.DB	'continue with the quick format? <Y/N>?', 0
4675
               6E 75 65 20 77
4676
               69 74 68 20 74
4677
               68 65 20 71 75
4678
               69 63 6B 20 66
4679
               6F 72 6D 61 74
4680
               3F 20 3C 59 2F
4681
               4E 3E 3F 00
4682
 6683  F91B1C  20 90 1B      	?10:	jsr	getkey
4683
 6684  F91B1F  B0 FB         		bcs	?10		; control key
4684
 6685  F91B21  AA            		tax
4685
 6686  F91B22  EB            		xba
4686
 6687  F91B23  A8            		tay
4687
 6688  F91B24  D0 F6         		bne	?10		; CTL, ALT, SHIFT
4688
 6689  F91B26  E0 79         		cpx	#'y'
4689
 6690  F91B28  18            		clc
4690
 6691  F91B29  F0 04         		beq	?20
4691
 6692  F91B2B  E0 6E         		cpx	#'n'
4692
 6693  F91B2D  D0 ED         		bne	?10
4693
 6694  F91B2F  60            	?20:	rts
4694
 6695
4695
 6696                        	; return CF=0 if YES, CF=1 if NO
4696
 6697  F91B30                	askcont:
4697
 6698  F91B30                		SCNPRINT
4698
 6699  F91B30  02 01         		cop	$01
4699
 6700                        		.MNLIST
4700
 6701  F91B32  57 41 52 4E 49 		.DB	'WARNING! Proceeding, all data on the disk will be erased. Continue <Y/N>?', 0
4701
               4E 47 21 20 50
4702
               72 6F 63 65 65
4703
               64 69 6E 67 2C
4704
               20 61 6C 6C 20
4705
               64 61 74 61 20
4706
               6F 6E 20 74 68
4707
               65 20 64 69 73
4708
               6B 20 77 69 6C
4709
               6C 20 62 65 20
4710
               65 72 61 73 65
4711
               64 2E 20 43 6F
4712
               6E 74 69 6E 75
4713
  Tue Jul 17 11:00:20 2018                                                                                               Page   77
4714
 
4715
 
4716
 
4717
 
4718
               65 20 3C 59 2F
4719
               4E 3E 3F 00
4720
 6702  F91B7C  20 90 1B      	?10:	jsr	getkey
4721
 6703  F91B7F  B0 FB         		bcs	?10		; control key
4722
 6704  F91B81  AA            		tax
4723
 6705  F91B82  EB            		xba
4724
 6706  F91B83  A8            		tay
4725
 6707  F91B84  D0 F6         		bne	?10		; CTL, ALT, SHIFT
4726
 6708  F91B86  E0 79         		cpx	#'y'
4727
 6709  F91B88  18            		clc
4728
 6710  F91B89  F0 04         		beq	?20
4729
 6711  F91B8B  E0 6E         		cpx	#'n'
4730
 6712  F91B8D  D0 ED         		bne	?10
4731
 6713  F91B8F  60            	?20:	rts
4732
 6714  F91B90
4733
 6715                        	; wait a pressed key
4734
 6716  F91B90                	getkey:
4735
 6717  F91B90                	?02:	KBGETIN			; system call - get key
4736
 6718  F91B90  02 17         		cop	$17
4737
 6719                        		.MNLIST
4738
 6720  F91B92  C9 00         		cmp	#0
4739
 6721  F91B94  F0 FA         		beq	?02		; loop -- wait pressed key
4740
 6722  F91B96  AA            		tax			; X=key code
4741
 6723  F91B97  EB            		xba
4742
 6724  F91B98  18            		clc
4743
 6725  F91B99  A8            		tay			; Y=control key flag
4744
 6726  F91B9A  10 01         		bpl	?04
4745
 6727  F91B9C  38            		sec			; flag control key
4746
 6728  F91B9D  AF 64 01 00   	?04:	lda	>DP01ADDR+KbdFlag
4747
 6729  F91BA1  EB            		xba			; B = flag ALT, CTL, SHIFT
4748
 6730  F91BA2  18            		clc
4749
 6731  F91BA3  8A            		txa			; key code
4750
 6732  F91BA4  60            		rts
4751
 6733
4752
 6734                        	;---------------------------------------------------------------------------
4753
 6735                        	; compact time function's
4754
 6736                        	;---------------------------------------------------------------------------
4755
 6737
4756
 6738                        	; get compact time for file timestamp
4757
 6739                        	; return cpu in 16 bit mode
4758
 6740                        	; C=low compact time, X=high compact time
4759
 6741  F91BA5                	gctime16:
4760
 6742  F91BA5                		CPU08
4761
 6743  F91BA5  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
4762
 6744                        		.LONGA	off
4763
 6745                        		.LONGI	off
4764
 6746                        		.MNLIST
4765
 6747  F91BA7  0B            		phd
4766
 6748  F91BA8  F4 00 40      		pea	#P0LDT
4767
 6749  F91BAB  2B            		pld			; set dp page
4768
 6750  F91BAC  20 08 1C      		jsr	getrtc
4769
 6751  F91BAF  20 CA 1B      		jsr	cpctime
4770
 6752  F91BB2                		CPU16
4771
 6753  F91BB2  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
4772
 6754                        		.LONGA	on
4773
 6755                        		.LONGI	on
4774
 6756                        		.MNLIST
4775
  Tue Jul 17 11:00:20 2018                                                                                               Page   78
4776
 
4777
 
4778
 
4779
 
4780
 6757  F91BB4  A5 48         		lda	ctime
4781
 6758  F91BB6  A6 4A         		ldx	cdate
4782
 6759  F91BB8  2B            		pld
4783
 6760  F91BB9  60            		rts
4784
 6761  F91BBA
4785
 6762                        		.LONGA	off
4786
 6763                        		.LONGI	off
4787
 6764
4788
 6765                        	; get compact time for file timestamp
4789
 6766  F91BBA                	getctime:
4790
 6767  F91BBA  0B            		phd
4791
 6768  F91BBB  F4 00 42      		pea	#P0OS
4792
 6769  F91BBE  2B            		pld			; set dp page
4793
 6770  F91BBF  20 08 1C      		jsr	getrtc
4794
 6771  F91BC2  20 CA 1B      		jsr	cpctime
4795
 6772  F91BC5  2B            		pld
4796
 6773  F91BC6  60            		rts
4797
 6774
4798
 6775                        	; compact time
4799
 6776  F91BC7                	gettime:
4800
 6777  F91BC7  20 08 1C      		jsr	getrtc
4801
 6778  F91BCA                	cpctime:
4802
 6779  F91BCA  38            		sec
4803
 6780  F91BCB  A5 47         		lda	rtcyear		; subctract 1980
4804
 6781  F91BCD  E9 50         		sbc	#$50		; without century...
4805
 6782  F91BCF  18            		clc			; ...we assume century=20
4806
 6783  F91BD0  69 64         		adc	#$64		; add 100
4807
 6784  F91BD2  EB            		xba			; B = 0.127 (till 2101)
4808
 6785  F91BD3  A5 46         		lda	rtcmonth	; shift month
4809
 6786  F91BD5  0A            		asl	a
4810
 6787  F91BD6  0A            		asl	a
4811
 6788  F91BD7  0A            		asl	a
4812
 6789  F91BD8  0A            		asl	a
4813
 6790  F91BD9                		ACC16
4814
 6791  F91BD9  C2 20         		rep	#PMFLAG
4815
 6792                        		.LONGA	on
4816
 6793                        		.MNLIST
4817
 6794  F91BDB  0A            		asl	a		; shift year+month
4818
 6795  F91BDC                		ACC08
4819
 6796  F91BDC  E2 20         		sep	#PMFLAG
4820
 6797                        		.LONGA	off
4821
 6798                        		.MNLIST
4822
 6799  F91BDE  05 45         		ora	rtcday
4823
 6800  F91BE0  85 4A         		sta	cdate		; compact date
4824
 6801  F91BE2  EB            		xba
4825
 6802  F91BE3  85 4B         		sta	cdate+1
4826
 6803  F91BE5  A5 42         		lda	rtcsec
4827
 6804  F91BE7  4A            		lsr	a
4828
 6805  F91BE8  85 48         		sta	ctime
4829
 6806  F91BEA  64 53         		stz	sec100
4830
 6807  F91BEC  90 04         		bcc	?10
4831
 6808  F91BEE  A9 64         		lda	#100
4832
 6809  F91BF0  85 53         		sta	sec100		; millisecond stamp
4833
 6810  F91BF2  A5 44         	?10:	lda	rtchour
4834
 6811  F91BF4  EB            		xba
4835
 6812  F91BF5  A5 43         		lda	rtcmin
4836
 6813  F91BF7  0A            		asl	a
4837
  Tue Jul 17 11:00:20 2018                                                                                               Page   79
4838
 
4839
 
4840
 
4841
 
4842
 6814  F91BF8  0A            		asl	a
4843
 6815  F91BF9                		ACC16
4844
 6816  F91BF9  C2 20         		rep	#PMFLAG
4845
 6817                        		.LONGA	on
4846
 6818                        		.MNLIST
4847
 6819  F91BFB  0A            		asl	a
4848
 6820  F91BFC  0A            		asl	a
4849
 6821  F91BFD  0A            		asl	a
4850
 6822  F91BFE                		ACC08
4851
 6823  F91BFE  E2 20         		sep	#PMFLAG
4852
 6824                        		.LONGA	off
4853
 6825                        		.MNLIST
4854
 6826  F91C00  05 48         		ora	ctime		; compact time
4855
 6827  F91C02  85 48         		sta	ctime
4856
 6828  F91C04  EB            		xba
4857
 6829  F91C05  85 49         		sta	ctime+1
4858
 6830  F91C07  60            		rts
4859
 6831  F91C08
4860
 6832                        	; get real time clock
4861
 6833  F91C08                	getrtc:
4862
 6834  F91C08  8B            		phb
4863
 6835  F91C09  A9 00         		lda	#0
4864
 6836  F91C0B  48            		pha
4865
 6837  F91C0C  AB            		plb
4866
 6838  F91C0D  08            		php
4867
 6839  F91C0E  78            		sei
4868
 6840  F91C0F  A2 0A         		ldx	#RTCCTRLA	; set bank 1
4869
 6841  F91C11  8E 4C FD      		stx	RTCALE
4870
 6842  F91C14  A9 10         		lda	#$10
4871
 6843  F91C16  0C 4D FD      		tsb	RTCDATA
4872
 6844  F91C19  A2 4A         		ldx	#RTCEXTCTRLA	; check INCR bit 6
4873
 6845  F91C1B  8E 4C FD      		stx	RTCALE
4874
 6846  F91C1E  2C 4D FD      	?02:	bit	RTCDATA
4875
 6847  F91C21  70 FB         		bvs	?02
4876
 6848  F91C23  A2 00         		ldx	#0		; seconds
4877
 6849  F91C25  8E 4C FD      		stx	RTCALE
4878
 6850  F91C28  AD 4D FD      		lda	RTCDATA
4879
 6851  F91C2B  85 42         		sta	rtcsec
4880
 6852  F91C2D  E8            		inx
4881
 6853  F91C2E  E8            		inx
4882
 6854  F91C2F  8E 4C FD      		stx	RTCALE		; minutes
4883
 6855  F91C32  AD 4D FD      		lda	RTCDATA
4884
 6856  F91C35  85 43         		sta	rtcmin
4885
 6857  F91C37  E8            		inx
4886
 6858  F91C38  E8            		inx
4887
 6859  F91C39  8E 4C FD      		stx	RTCALE		; hours
4888
 6860  F91C3C  AD 4D FD      		lda	RTCDATA
4889
 6861  F91C3F  85 44         		sta	rtchour
4890
 6862  F91C41  E8            		inx
4891
 6863  F91C42  E8            		inx
4892
 6864  F91C43  E8            		inx
4893
 6865  F91C44  8E 4C FD      		stx	RTCALE		; day
4894
 6866  F91C47  AD 4D FD      		lda	RTCDATA
4895
 6867  F91C4A  85 45         		sta	rtcday
4896
 6868  F91C4C  E8            		inx
4897
 6869  F91C4D  8E 4C FD      		stx	RTCALE		; month
4898
 6870  F91C50  AD 4D FD      		lda	RTCDATA
4899
  Tue Jul 17 11:00:20 2018                                                                                               Page   80
4900
 
4901
 
4902
 
4903
 
4904
 6871  F91C53  85 46         		sta	rtcmonth
4905
 6872  F91C55  E8            		inx
4906
 6873  F91C56  8E 4C FD      		stx	RTCALE		; year
4907
 6874  F91C59  AD 4D FD      		lda	RTCDATA
4908
 6875  F91C5C  85 47         		sta	rtcyear
4909
 6876  F91C5E  28            		plp
4910
 6877  F91C5F  AB            		plb
4911
 6878  F91C60  60            		rts
4912
 6879
4913
 6880                        	;---------------------------------------------------------------------------
4914
 6881                        	; tables
4915
 6882                        	;---------------------------------------------------------------------------
4916
 6883  F91C61
4917
 6884                        	; sector's per cluster table
4918
 6885  F91C61                	CLSSIZE:
4919
 6886  F91C61  01 02 04 08 10 		.DB	$01, $02, $04, $08, $10, $20, $40
4920
               20 40
4921
 6887
4922
 6888          000007        	CLSCNT	.EQU	$-CLSSIZE
4923
 6889
4924
 6890                        	; sector's per cluster shift table
4925
 6891  F91C68                	CLSSHIFT:
4926
 6892  F91C68  00 01 02 03 04 		.DB	$00, $01, $02, $03, $04, $05, $06
4927
               05 06
4928
 6893  F91C6F
4929
 6894                        	; costant's for fat formatted floppy disk (D.D. & H.D. format)
4930
 6895                        	; root dir. entry count
4931
 6896  F91C6F                	FDROOT:
4932
 6897  F91C6F  7000 E000     		.DW	$0070, $00E0
4933
 6898                        	; total sector's
4934
 6899  F91C73                	FDSEC:
4935
 6900  F91C73  A005 400B     		.DW	$05A0, $0B40
4936
 6901                        	; fat size
4937
 6902  F91C77                	FDFAT:
4938
 6903  F91C77  0300 0900     		.DW	$0003, $0009
4939
 6904                        	; sector's per track
4940
 6905  F91C7B                	FDSPT:
4941
 6906  F91C7B  0900 1200     		.DW	9, 18
4942
 6907                        	; sector per cluster
4943
 6908  F91C7F                	FDCLS:
4944
 6909  F91C7F  02 01         		.DB	2, 1
4945
 6910                        	; shift value
4946
 6911  F91C81                	FDSHF:
4947
 6912  F91C81  01 00         		.DB	1, 0
4948
 6913                        	; media value
4949
 6914  F91C83                	FDMEDIA:
4950
 6915  F91C83  F9 F0         		.DB	$F9, $F0
4951
 6916
4952
 6917                        	; ata device PBR buffer pointer
4953
 6918  F91C85                	PBRPTR:
4954
 6919  F91C85  008C 008E     		.DW	.LOW16.PBR0ATA, .LOW16.PBR1ATA
4955
 6920  F91C89                	PBRPTR2:
4956
 6921  F91C89  01 01         		.DB	.SEG.PBR0ATA, .SEG.PBR1ATA
4957
 6922
4958
 6923                        	; standard label
4959
 6924  F91C8B                	PBRLBL:
4960
 6925  F91C8B  44 4F 53 20 44 		.DB	'DOS DISK   '
4961
  Tue Jul 17 11:00:20 2018                                                                                               Page   81
4962
 
4963
 
4964
 
4965
 
4966
               49 53 4B 20 20
4967
               20
4968
 6926
4969
 6927  F91C96                	NOLBL:
4970
 6928  F91C96  4E 4F 20 4E 41 		.DB	'NO NAME    '
4971
               4D 45 20 20 20
4972
               20
4973
 6929
4974
 6930                        	; standard fat12 system name
4975
 6931  F91CA1                	F12NAM:
4976
 6932  F91CA1  46 41 54 31 32 		.DB	'FAT12   '
4977
               20 20 20
4978
 6933
4979
 6934                        	; standard fat16 system name
4980
 6935  F91CA9                	F16NAM:
4981
 6936  F91CA9  46 41 54 31 36 		.DB	'FAT16   '
4982
               20 20 20
4983
 6937
4984
 6938                        	; boot sector header DD fat12
4985
 6939  F91CB1                	F12HDD:
4986
 6940  F91CB1  EB 34 90      		.DB	$EB, $34, $90
4987
 6941  F91CB4                	OEMNAM:
4988
 6942  F91CB4  49 42 4D 20 20 		.DB	'IBM  3.3'
4989
               33 2E 33
4990
 6943  F91CBC  00 02 02 01 00 		.DB	$00, $02, $02, $01, $00, $02
4991
               02
4992
 6944  F91CC2  70 00 A0 05 F9 		.DB	$70, $00, $A0, $05, $F9, $03, $00
4993
               03 00
4994
 6945  F91CC9  12 00 02 00   		.DB	$12, $00, $02, $00
4995
 6946  F91CCD
4996
 6947          00001C        	F12HSIZ	.EQU	($ - F12HDD)
4997
 6948
4998
 6949                        	; boot sector header HD fat12
4999
 6950  F91CCD                	F12HHD:
5000
 6951  F91CCD  EB 34 90      		.DB	$EB, $34, $90
5001
 6952  F91CD0  49 42 4D 20 20 		.DB	'IBM  3.3'
5002
               33 2E 33
5003
 6953  F91CD8  00 02 01 01 00 		.DB	$00, $02, $01, $01, $00, $02
5004
               02
5005
 6954  F91CDE  E0 00 40 0B F0 		.DB	$E0, $00, $40, $0B, $F0, $09, $00
5006
               09 00
5007
 6955  F91CE5  12 00 02 00   		.DB	$12, $00, $02, $00
5008
 
5009
 
5010
             Lines Assembled : 6423                  Errors : 0
5011
 
5012
 
5013