Subversion Repositories MB01 Project

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 - 1
  Tue Jul 17 11:00:21 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\utils.asm
13
                       Output Filename : obj\F9\utils.obj
14
                       Listing Has Been Relocated
15
 
16
 
17
 2603                        	.LIST		on
18
 2604
19
 2605  F8FFB1                		.INCLUDE inc\dirp00.inc
20
 2606                        	;----------------------------------------------------------
21
 2607                        	; DIRP00.ASM
22
 2608                        	; PROGETTO: B1601
23
 2609                        	;
24
 2610                        	; Variabili in Direct Page $00
25
 2611                        	;----------------------------------------------------------
26
 2612
27
 2613                        	; sezione COMMON -- questo permette di includere il file in piu' file
28
 2614
29
 2615                        	.LIST on
30
 2616
31
 2617                        	DIRP00:	.SECTION page0, ref_only, common	;Direct-Page 00
32
 2618
33
 2619  000000                		.ABSOLUTE		;; inizia sempre da $00
34
 2620  000000                		.ORG		0x00
35
 2621  000000
36
 2622  000000  0000          	JiffyClk	.DW			; contatore 10ms 32 bit
37
 2623  000002  0000          			.DW
38
 2624  000004                	SysTmr		.DS	SYSTMRCNT	; system timer 0 (10ms)
39
 2625  000008                	SysTMF		.DS	SYSTMRCNT	; flag timer (80 -> start)
40
 2626  00000C  00            	Bnk0Flag	.DB			; <7>: flag test RAM banco 0 ok
41
 2627                        						; <6>: flag warm reset
42
 2628  00000D  00            	RTCFlag		.DB
43
 2629
44
 2630  00000E                	diskstat	.DS	2	; flag device on ata bus #0 & #1
45
 2631                        					; <7>: device ready
46
 2632                        					; <6>: compact flash device (C.F.)
47
 2633                        					; <5>: device identification ok
48
 2634                        					; <4>: MBR loaded
49
 2635                        					; <3>: valid signature in MBR
50
 2636                        					; <2>: first partition found&active
51
 2637                        					; <1>:
52
 2638                        					; <0>: valid partition flag
53
 2639
54
 2640                        					; <7>: device ready
55
 2641                        					; <6>: USB device
56
 2642                        					; <5>: compact flash device (C.F.)
57
 2643                        					; <4>: device identification ok
58
 2644                        					; <3>: MBR loaded
59
 2645                        					; <2>: first partition found&active
60
 2646                        					; <1>: always 1
61
 2647                        					; <0>: valid partition flag
62
 2648  000010
63
  Tue Jul 17 11:00:21 2018                                                                                               Page    2
64
 
65
 
66
 
67
 
68
 2649
69
 2650          00000E        	atadev		.EQU	diskstat
70
 2651
71
 2652  000010                	usbdev		.DS	2	; flag flash disk on usb bus #0
72
 2653                        					; <7>: device plugged and ready
73
 2654                        					; <6>: always 1
74
 2655                        					; <5>: device identification ok
75
 2656                        					; <4>: MBR loaded
76
 2657                        					; <3>: valid signature in MBR
77
 2658                        					; <2>: first partition found&active
78
 2659                        					; <1>:
79
 2660                        					; <0>: valid partition flag
80
 2661
81
 2662  000012                	diskmax		.DS	16	; disk max. sector's
82
 2663          000012        	atasec		.EQU	diskmax
83
 2664          00001A        	usbsec		.EQU	diskmax+8
84
 2665
85
 2666
86
 2667  000022                	atambr		.DS	8	; data for first partition found in mbr
87
 2668                        					; first 3 bytes for start sector of partition
88
 2669                        					; last byte for partition type
89
 2670  00002A                	usbmbr		.DS	8
90
 2671
91
 2672  000032                	ataprt		.DS	8	; total sec's of first partition
92
 2673  00003A                	usbprt		.DS	8	; total sec's of first partition
93
 2674
94
 2675
95
 2676  000042  00            	usb0ch		.DB	; usb0 (ch375/ch376) flag
96
 2677                        				; <7>: module on
97
 2678                        				; <6>: ch376 flag
98
 2679                        				; <5:0>: chip version
99
 2680
100
 2681  000043  00            	usb0st		.DB	; usb0 status
101
 2682                        				; <7>: usb0 host mode ok
102
 2683                        				; <6>: flash disk attached flag
103
 2684                        				; <5>: usb device attached
104
 2685
105
 2686  000044  00            	fdcdrv		.DB		; phisycal drive status (drive #0)
106
 2687                        					; <7>: disk format established in bit 0&1
107
 2688                        					; <6>: double step seek done
108
 2689                        					; <5>: trust format bit's (set after ok r/w)
109
 2690                        					; <4>: write protect bit (if disk in drive)
110
 2691                        					; <3>: don't care
111
 2692                        					; <2>: don't care
112
 2693                        					; <1>: HD disk if set else DD disk
113
 2694                        					; <0>: CBM format if set else IBM format
114
 2695
115
 2696  000045  00            	vdrive		.DB		; virtual drive status (ram disk, drive #1)
116
 2697                        					; <7>: disk format established in bit 0&1
117
 2698                        					; <6>: change disk simulation (after format)
118
 2699                        					; <5>: don't care
119
 2700                        					; <4>: write protect bit (under sw control)
120
 2701                        					; <3>: don't care
121
 2702                        					; <2>: don't care
122
 2703                        					; <1>: HD disk if set else DD disk
123
 2704                        					; <0>: CBM format if set else IBM format
124
 2705
125
  Tue Jul 17 11:00:21 2018                                                                                               Page    3
126
 
127
 
128
 
129
 
130
 2706  000046  00            	fdcctl		.DB		; fdc controller status
131
 2707                        					; <7>: drive is attached
132
 2708                        					; <6>: drive need recalibration (restore)
133
 2709                        					; <5>: FDC controller ok
134
 2710                        					; <4>: motor on
135
 2711                        					; <3>: dma is active
136
 2712                        					; <2>: dma chip ok (post routine)
137
 2713                        					; <1>: clock rate (1=HD,0=DD)
138
 2714                        					; <0>: disk ready
139
 2715
140
 2716  000047  00            	fdctrk		.DB		; fd: current seek track
141
 2717  000048  00            	fdcerr		.DB		; fd: last error code
142
 2718  000049  00            	ataerr		.DB		; ata: last error code
143
 2719  00004A  00            	ataxer		.DB		; ata: last extended error code
144
 2720
145
 2721  00004B  00            	CtrlBrk		.DB		; flag CTRL+BREAK (NMI)
146
 2722
147
 2723  00004C  0000          	MemTop		.DW		; top memoria RAM
148
 2724  00004E  00            			.DB		; banco top mem
149
 2725
150
 2726  00004F  00            	DflTxtIn	.DB		; device di default text input
151
 2727  000050  00            	DflTxtOut	.DB		; device di default text output
152
 2728
153
 2729  000051                	COPPtr		LP		; long pointer for COP decoding
154
 2730  000054  00            	COPIdx		.DB		; COP signature/index
155
 2731
156
 2732  000055  00            	BiosEnt		.DB		; flag accesso a bios setup
157
 2733
158
 2734                        	; variabili utilizzate da ACIA
159
 2735  000056                	spwrk		.DS	$30
160
 2736
161
 2737                        	; bios mem
162
 2738  000086  0000          	nsize		.DW	; dimensione blocco da allocare
163
 2739                        	;bsize		.DW	; dimensione vera blocco free
164
 2740  000088  0000          	splitsz		.DW	; dimensione blocco splittato
165
 2741  00008A  0000          	bfree		.DW	; puntatore blocco free
166
 2742  00008C  0000          	hdrptr		.DW	; puntatore header heap
167
 2743
168
 2744  00008E  0000          	pbrklv		.DW	; current break level of current process
169
 2745  000090  0000          	pbrkmin		.DW	; minimum breal level of current process
170
 2746  000092  0000          	pbrkmax		.DW	; maximum breal level of current process
171
 2747  000094
172
 2748                        	; bios temp. work area
173
 2749  000094                	bwrktmp		.DS	$28
174
 2750
175
 2751  0000BC  00            	coptmp		.DB	; temp. used while cop
176
 2752
177
 2753  0000BD  00            	tstser		.DB	; check ser/usb test board post
178
 2754                        				; <7>: VIA2 ok
179
 2755                        				; <6>: PICRAM ok
180
 2756                        				; <1>: UART 16C550 ok
181
 2757                        				; <0>: R65C51 ok
182
 2758
183
 2759
184
 2760                        	;crc16		.DW
185
 2761
186
 2762  0000BD                		.RELATIVE
187
  Tue Jul 17 11:00:21 2018                                                                                               Page    4
188
 
189
 
190
 
191
 
192
 2763
193
 2764                        		.ENDS
194
 2765
195
 2766          [01]          	.IFDEF		_ACIA_INC_
196
 2767                        		.INCLUDE INC\SP.INC
197
 2768          [00]          	.ENDIF
198
 2769
199
 2793                        	.LIST on
200
 2794
201
 2795                        	;---------------------------------------------------------------------------
202
 2796
203
 2797          000020        	HPLMAX		.EQU	32		; Max. subdirectory level
204
 2798
205
 2799          000200        	BCBCNT		.EQU	$200		; BCB's struct's count #
206
 2800          000C00        	BCBXBNK		.EQU	$0C00		; starting BCB x-mem buffer #
207
 2801          000040        	DMACNT		.EQU	64
208
 2802
209
 2803          0000E0        	FAT0X		.EQU	$E0		; x-mem bank for fat table of ata #0
210
 2804          0000F0        	FAT1X		.EQU	$F0		; x-mem bank for fat table of ata #1
211
 2805
212
 2806  F8FFB1                		.INCLUDE INC\LDT.INC
213
 2807                        	; LDT.INC
214
 2808
215
 2809          [01]          	.IFNDEF		__LDT_INC__
216
 2810          000001        	__LDT_INC__	.SET	1
217
 2811
218
 2812                        	.LIST on
219
 2813                        	;---------------------------------------------------------------------------
220
 2814                        	; Logical Drive Table (LDT) -- page 0 offset's
221
 2815                        	;---------------------------------------------------------------------------
222
 2816
223
 2817  F8FFB1                	 STRUCT		LDT
224
 2818                        	_LDT	.SECTION page0,common,ref_only,offset 0	;LDT Struct
225
 2819                        			;.ABSOLUTE
226
 2820                        			;.ORG	0
227
 2821                        		.MNLIST
228
 2822  000000  00            	ldt_fg1		.DB		; logical volume flag's
229
 2823                        					; <7>: device ready (fdc drive or ata device)
230
 2824                        					; <6>: if=1->HD/CF else->FD
231
 2825                        					; <1:0>: phisycal device number
232
 2826
233
 2827  000001  00            	ldt_fg2		.DB		; <7>: valid volume (fat volume or cbm disk)
234
 2828                        					; <6>: if=1->FAT else->CBM (FD only)
235
 2829                        					; <5>: disk format checked
236
 2830                        					; <1:0>: disk format (fdc only)
237
 2831
238
 2832  000002  0000          	ldt_root	.DW		; lba of root dir
239
 2833  000004  0000          	ldt_fat1	.DW		; lba of fat1 table
240
 2834  000006  0000          	ldt_fat2	.DW		; lba of fat2 table
241
 2835  000008  0000          	ldt_cls		.DW		; lba of first data cluster
242
 2836  00000A  0000          	ldt_max		.DW		; max usable cluster + 1
243
 2837  00000C  0000          	ldt_rent	.DW		; root dir. max. entries
244
 2838  00000E  0000          	ldt_cent	.DW		; max. entries in dir. cluster
245
 2839  000010  0000          	ldt_eoc		.DW		; end of cluster chain marker
246
 2840  000012  0000          	ldt_free	.DW		; count of free cluster's
247
 2841  000014  0000          	ldt_nxt		.DW		; next free cluster
248
 2842  000016  0000          	ldt_fsiz	.DW		; fat table size
249
  Tue Jul 17 11:00:21 2018                                                                                               Page    5
250
 
251
 
252
 
253
 
254
 2843
255
 2844  000018  00            	ldt_csiz	.DB		; cluster size (1,2,4,8,16,32,64)
256
 2845  000019  00            	ldt_cshf	.DB		; cluster shift (0,1,2,3,4,5,6)
257
 2846  00001A  00            	ldt_rsiz	.DB		; root dir. size (sector's)
258
 2847  00001B  00            	ldt_mcls	.DB		; mask for clust. module: 00,01,03,07,0F,1F,3F
259
 2848  00001C  0000          	ldt_cdlp	.DW		; current working dir list pointer
260
 2849  00001E  0000          	ldt_cdcls	.DW		; current working dir start cluster
261
 2850  000020  00            	ldt_cdlvl	.DB		; current working dir level count
262
 2851
263
 2852  000021  00            	ldt_ptype	.DB
264
 2853  000022  0000 0000     	ldt_pstart	.LWORD
265
 2854  000026  0000 0000     	ldt_psize	.LWORD
266
 2855
267
 2856          000022        	ldt_fp		.EQU	ldt_pstart	; fat table buffer long pointer
268
 2857          000025        	ldt_fbuf	.EQU	ldt_pstart+3		; fat table: x-mem base bank/dma buffer
269
 2858
270
 2859          000026        	ldt_pbr		.EQU	ldt_psize		; long pointer to PBR cache buffer
271
 2860          000029        	ldt_fmt		.EQU	ldt_psize+3
272
 2861
273
 2862  00002A                	 ESTRUCT	LDT
274
 2863  00002A                	LDTSIZE	.DS	0
275
 2864                        			;.RELATIVE
276
 2865                        			.ENDS
277
 2866                        		.MNLIST
278
 2867
279
 2868          [00]          	.ENDIF
280
 2869
281
 2870  F8FFB1
282
 2871                        	;---------------------------------------------------------------------------
283
 2872                        	; Hierarchical Path List (HPL) -- 16 bit offset's
284
 2873                        	;---------------------------------------------------------------------------
285
 2874
286
 2875  F8FFB1                	 LSTRUCT	HPL
287
 2876                        	_HPL	.SECTION common,ref_only,offset 0	;HPL Struct
288
 2877                        		.MNLIST
289
 2878  000000  0000          	hpl_cls		.DW		; parent cluster
290
 2879  000002  0000          	hpl_ix		.DW		; entry index in parent cluster
291
 2880  000004                	hpl_fcb		.DS	11	; fcb name
292
 2881  00000F  00            	hpl_lst		.DB		; unused
293
 2882  000010                	 ESTRUCT	HPL
294
 2883  000010                	HPLSIZE	.DS	0
295
 2884                        			;.RELATIVE
296
 2885                        			.ENDS
297
 2886                        		.MNLIST
298
 2887
299
 2888                        	;---------------------------------------------------------------------------
300
 2889                        	; Buffer Control Block (BCB) -- 16 bit offset's
301
 2890                        	;---------------------------------------------------------------------------
302
 2891
303
 2892  F8FFB1                	 LSTRUCT	BCB
304
 2893                        	_BCB	.SECTION common,ref_only,offset 0	;BCB Struct
305
 2894                        		.MNLIST
306
 2895  000000  0000          	bcb_next	.DW			; next logical linked BCB
307
 2896  000002  00            	bcb_drv		.DB			; logical drive
308
 2897  000003  00            	bcb_sec		.DB			; sector offset
309
 2898  000004  0000          	bcb_cls		.DW			; cluster
310
 2899  000006  0000          	bcb_lba		.DW			; sector lba address
311
  Tue Jul 17 11:00:21 2018                                                                                               Page    6
312
 
313
 
314
 
315
 
316
 2900  000008  0000          	bcb_lbah	.DW			; lba high
317
 2901          000008        	bcb_head	.EQU	bcb_lbah	; floppy head
318
 2902  00000A  0000          	bcb_buf		.DW			; x-mem buffer number
319
 2903          00000A        	bcb_trk		.EQU	bcb_buf		; floppy track(low) & sector(hi)
320
 2904  00000C  0000          	bcb_ptr		.DW			; buffer pointer
321
 2905  00000E  0000          	bcb_xbnk	.DW			; buffer pointer hi & x-mem bank
322
 2906          00000E        	bcb_dma		.EQU	bcb_xbnk	; buffer pointer hi & dma buffer
323
 2907  000010                	 ESTRUCT	BCB
324
 2908  000010                	BCBSIZE	.DS	0
325
 2909                        			;.RELATIVE
326
 2910                        			.ENDS
327
 2911                        		.MNLIST
328
 2912
329
 2913                        	;---------------------------------------------------------------------------
330
 2914                        	; hash Control Block (BCB) -- 16 bit offset's
331
 2915                        	;---------------------------------------------------------------------------
332
 2916
333
 2917  F8FFB1                	 LSTRUCT	HCB
334
 2918                        	_HCB	.SECTION common,ref_only,offset 0	;HCB Struct
335
 2919                        		.MNLIST
336
 2920  000000  0000          	hcb_next	.DW		; pointer to next HCB
337
 2921  000002  0000          	hcb_cls		.DW		; cluster number
338
 2922  000004  0000          	hcb_seq		.DW		; sequence number + logical drive number
339
 2923  000006  0000          	hcb_cnt		.DW		; number of hashed entries
340
 2924  000008                	hcb_data	.DS	0	; hash buffer data
341
 2925  000008                	 ESTRUCT	HCB
342
 2926  000008                	HCBSIZE	.DS	0
343
 2927                        			;.RELATIVE
344
 2928                        			.ENDS
345
 2929                        		.MNLIST
346
 2930
347
 2931                        	;---------------------------------------------------------------------------
348
 2932                        	; TOS Working Segment
349
 2933                        	;---------------------------------------------------------------------------
350
 2934
351
 2935          000001        	WKB		.EQU	.SEG.TOSSEG	; TOS working bank
352
 2936
353
 2937          010000        	TS		.SET	TOSSEG
354
 2938          01FFFF        	TE		.SET	TOSSEG + $FFFF
355
 2939          018C00        	TO0		.SET	$018C00
356
 2940          019E00        	TO1		.SET	TOSWKM
357
 2941
358
 2942                        	.comment @
359
 2943                        	_TOS0:	.SECTION ref_only, common, offset TO0, range TS TE ;FAT Struct's
360
 2944                        	_TOS0_START	.DS	0
361
 2945
362
 2946                        	_pbr0		.DS	512
363
 2947                        	_pbr1		.DS	512
364
 2948                        	_pbr2		.DS	512
365
 2949                        	_pbr3		.DS	512
366
 2950
367
 2951                        	_TOS0_END	.DS	0
368
 2952                        	TOS0SIZ		.EQU	(_TOS0_END - _TOS0_START)
369
 2953                        	.ENDS
370
 2954                        	@
371
 2955
372
 2956                        	_TOS1:	.SECTION ref_only, common, offset TO1, range TS TE ;FAT Struct's
373
  Tue Jul 17 11:00:21 2018                                                                                               Page    7
374
 
375
 
376
 
377
 
378
 2957  019E00                	_TOS1_START	.DS	0
379
 2958
380
 2959                        	; current working directory HPL
381
 2960  019E00                	cwdl0		.DS	(HPLSIZE*HPLMAX)
382
 2961  01A000                	cwdl1		.DS	(HPLSIZE*HPLMAX)
383
 2962  01A200                	cwdl2		.DS	(HPLSIZE*HPLMAX)
384
 2963  01A400                	cwdl3		.DS	(HPLSIZE*HPLMAX)
385
 2964
386
 2965                        	; current building path HPL
387
 2966  01A600                	cbpl		.DS	(HPLSIZE*HPLMAX)
388
 2967          01A600        	HPL_CLS		.EQU	hpl_cls+cbpl
389
 2968          01A602        	HPL_IX		.EQU	hpl_ix+cbpl
390
 2969          01A604        	HPL_FCB		.EQU	hpl_fcb+cbpl
391
 2970
392
 2971                        	; BCB list's
393
 2972  01A800                	bcbstart	.DS	(BCBCNT*BCBSIZE)
394
 2973  01C800                	bcbend		.DS	0
395
 2974  01C800                	dmastart	.DS	(DMACNT*BCBSIZE)
396
 2975  01CC00                	dmaend		.DS	0
397
 2976  01CC00                	dma0s		.DS	(17*BCBSIZE)
398
 2977  01CD10                	dma1s		.DS	(17*BCBSIZE)
399
 2978
400
 2979  01CE20                	_TOS1_END	.DS	0
401
 2980          003020        	TOS1SIZ		.EQU	(_TOS1_END - _TOS1_START)
402
 2981                        	.ENDS
403
 2982
404
 2983                        	;---------------------------------------------------------------------------
405
 2984                        	; HCB Segment
406
 2985                        	;---------------------------------------------------------------------------
407
 2986
408
 2987          000004        	HCBBNK		.EQU	.SEG.HCBSEG
409
 2988          040000        	HS		.SET	HCBSEG
410
 2989          04FFFF        	HE		.SET	HCBSEG + $FFFF
411
 2990          040000        	HO		.SET	HCBSEG
412
 2991
413
 2992                        	_HCBS:	.SECTION ref_only, common, offset HO, range HS HE	;HCB's List
414
 2993  040000                	hcb_bnk		.DS	8
415
 2994  040008                	hcbstart	.DS	0
416
 2995                        	.ENDS
417
 2996
418
 2997                        	;.comment @
419
 2998                        	;---------------------------------------------------------------------------
420
 2999                        	; direct page for LDT var's
421
 3000                        	;---------------------------------------------------------------------------
422
 3001
423
 3002                        	; P0OS
424
 3003                        	DPOS:	.SECTION page0, common, ref_only, offset 0	;OS Main D.P.
425
 3004
426
 3005                        	;sysbuf		.DS	2	; floppy track 0 cache buffer
427
 3006  000000  00            	defhsec		.DB		; default hidden sector's in fdisk
428
 3007  000001  00            			.DB
429
 3008  000002  0000          	cmdstk		.DW		; saved stack on TOS command's
430
 3009  000004                	bpath		.DS	80
431
 3010
432
 3011  000054                	bpath1		.DS	0
433
 3012                        	.ENDS
434
 3013                        	;@
435
  Tue Jul 17 11:00:21 2018                                                                                               Page    8
436
 
437
 
438
 
439
 
440
 3014
441
 3015                        	; P0LDT
442
 3016                        	DPLDT:	.SECTION page0, common, ref_only, offset 0	;LDT D.P.
443
 3017
444
 3018  000000                	ldt0		.DS	LDTSIZE
445
 3019  00002A                	ldt1		.DS	LDTSIZE
446
 3020  000054                	ldt2		.DS	LDTSIZE
447
 3021  00007E                	ldt3		.DS	LDTSIZE
448
 3022  0000A8                	ldt4		.DS	LDTSIZE
449
 3023
450
 3024  0000D2                	ldtp		.DS	6	; pointer to LDT's in DPLDT page
451
 3025
452
 3026  0000D8                	sysbuf		.DS	4	; floppy track 0 cache buffer
453
 3027
454
 3028                        	.ENDS
455
 3029
456
 3030                        	;---------------------------------------------------------------------------
457
 3031                        	; direct page for FAT var's
458
 3032                        	;---------------------------------------------------------------------------
459
 3033
460
 3034                        	; P0FAT
461
 3035                        	DPFAT:	.SECTION page0, common, ref_only, offset 0	;FAT D.P.
462
 3036
463
 3037  000000  0000          	ostos		.DW		; saved top of stack
464
 3038  000002  00            	ioerr		.DB		; i/o error
465
 3039  000003  00            	ioerr2		.DB		; extended i/o error
466
 3040  000004  0000          	hcbroot		.DW		; HCB struct's list
467
 3041  000006  0000          	hcblst		.DW		; the last one HCB
468
 3042  000008  00            	hsiz		.DB		; how many sector's an HCB can hold
469
 3043  000009  00            	hlog2		.DB		; shift count related to hsiz
470
 3044  00000A  0000          	bcbroot		.DW		; BCB buffer's list
471
 3045  00000C  0000          	bcblst		.DW		; the last one BCB
472
 3046  00000E  0000          	dmaroot		.DW		; dma BCB buffer's list
473
 3047  000010  0000          	dmalst		.DW		; the last one dma BCB
474
 3048  000012  0000          	dmabcb		.DW		; BCB list for floppy root, cluster#2,#3&#4
475
 3049  000014  00            	fspt		.DB		; sector per track (floppy)
476
 3050  000015  00            	pdrive		.DB		; phisycal drive number
477
 3051  000016  00            	bplvl		.DB		; subdir level while build path
478
 3052  000017  00            	defdrv		.DB		; default drive
479
 3053
480
 3054                        	; the first block of ldt_ var's is copied from the LDT struct
481
 3055  000018  00            	ldtfg1		.DB		; logical volume flag's
482
 3056                        					; <7>: device ready (fdc drive or ata device)
483
 3057                        					; <6>: if=1->HD/CF else->FD
484
 3058                        					; <0>: phisycal device number
485
 3059
486
 3060  000019  00            	ldtfg2		.DB		; <7>: valid volume (fat volume or cbm disk)
487
 3061                        					; <6>: if=1->FAT else->CBM (FD only)
488
 3062                        					; <5>: disk format checked
489
 3063                        					; <1:0>: disk format (fdc only)
490
 3064
491
 3065  00001A                	ldtfp		LP		; fat table buffer long pointer
492
 3066  00001D  00            	ldtfbuf		.DB		; fat table: x-mem base bank/dma buffer
493
 3067
494
 3068  00001E  0000          	ldtroot		.DW		; lba of root dir
495
 3069  000020  0000          	ldtfat1		.DW		; lba of fat1 table
496
 3070  000022  0000          	ldtfat2		.DW		; lba of fat2 table
497
  Tue Jul 17 11:00:21 2018                                                                                               Page    9
498
 
499
 
500
 
501
 
502
 3071  000024  0000          	ldtcls		.DW		; lba of first data cluster
503
 3072  000026  0000          	ldtmax		.DW		; max usable cluster + 1
504
 3073  000028  00            	ldtcsiz		.DB		; cluster size (1,2,4,8,16,32,64)
505
 3074  000029  00            	ldtcshf		.DB		; cluster shift (0,1,2,3,4,5,6)
506
 3075  00002A  00            	ldtfsiz		.DB		; fat table size (if 0 -> 256)
507
 3076  00002B  00            	ldtrsiz		.DB		; root dir. size (sector's)
508
 3077  00002C  0000          	ldtrent		.DW		; root dir. max. entries
509
 3078  00002E  0000          	ldtcent		.DW		; max. entries in dir. cluster
510
 3079  000030  0000          	ldteoc		.DW		; end of cluster chain marker
511
 3080  000032  00            	ldtmcls		.DB		; mask for clust. module: 00,01,03,07,0F,1F,3F
512
 3081  000033  00            	ldtfmt		.DB		; floppy disk format (0,1,2, FF if ata device)
513
 3082  000034  0000          	ldtcdlp		.DW		; current working dir list pointer
514
 3083  000036  0000          	ldtcdcls	.DW		; current working dir start cluster
515
 3084  000038  0000          	ldtfree		.DW		; count of free cluster's
516
 3085  00003A  0000          	ldtnxt		.DW		; next free cluster
517
 3086  00003C  00            	ldtcdlvl	.DB		; current working dir level count
518
 3087  00003D                	ldtpbr		LP		; long pointer to PBR cache buffer
519
 3088
520
 3089  000040  0000          	chdcls		.DW		; last accessed chained dir. cluster
521
 3090  000042  0000          	clsofs		.DW		; cluster's offset from start of chain
522
 3091
523
 3092                        	; not change order of the 2 following var's: will be accessed as 16 bit var
524
 3093  000044  00            	entofs		.DB		; entry offset from start of sector
525
 3094  000045  00            	secofs		.DB		; sector's offset from start of cluster
526
 3095
527
 3096  000046  0000          	dircls		.DW		; directory cluster
528
 3097  000048  0000          	dcnt		.DW		; directory entry counter
529
 3098  00004A  0000          	lba		.DW		; lba sector address
530
 3099  00004C  0000          	lbah		.DW		; lba is 24 bit's only
531
 3100  00004E  0000          	xbuf		.DW		; x-mem buffer transfer number
532
 3101
533
 3102          00004C        	fhead		.EQU	lbah	; fd head
534
 3103          00004E        	ftrack		.EQU	xbuf	; fd track
535
 3104          00004F        	fsec		.EQU	xbuf+1	; fd sector
536
 3105
537
 3106  000050  00            	dfcbtyp		.DB		; FCB type to search
538
 3107  000051  00            	dfcbatt		.DB		; attribute of found FCB
539
 3108
540
 3109  000052  00            	curdrv		.DB		; current logical drive
541
 3110  000053                	fcbs		.DS	11	; file control block name
542
 3111
543
 3112                        	;dcmask		.DW		; mask to start of cluster
544
 3113                        					; FFF0, FFE0, FFC0, FF80, FF00, FE00
545
 3114
546
 3115  00005E  0000          	fcbp		.DW		; FCB buffer long pointer
547
 3116  000060  0000          			.DW		; low=fcbp+2, high=x-mem bank or dma buffer
548
 3117          000061        	dmabuf		.EQU	fcbp+3	; dma buffer #
549
 3118          000061        	xmbank		.EQU	fcbp+3	; x-mem bank #
550
 3119
551
 3120                        	; temp area
552
 3121  000062  00            	hcbseq		.DB
553
 3122  000063  00            	hcbdrv		.DB
554
 3123  000064  0000          	bcbcls		.DW
555
 3124  000066  00            	bcbdrv		.DB
556
 3125  000067  00            	bcbsec		.DB
557
 3126
558
 3127  000068  0000          	thash		.DW
559
  Tue Jul 17 11:00:21 2018                                                                                               Page   10
560
 
561
 
562
 
563
 
564
 3128          000068        	hcbrec	.EQU	thash
565
 3129          000068        	wtmp	.EQU	thash
566
 3130
567
 3131  00006A  0000          	hlast		.DW
568
 3132  00006C  0000          	hcbcls		.DW
569
 3133  00006E  0000          	hcbx		.DW
570
 3134  000070  0000          	hcby		.DW
571
 3135          00006A        	tmpp	.EQU	hlast	; temp. long pointer
572
 3136          00006E        	tmpx	.EQU	hcbx
573
 3137          00006F        	wild	.EQU	hcbx+1
574
 3138          000070        	fsiz	.EQU	hcby
575
 3139          000071        	fptr	.EQU	hcby+1
576
 3140          00006E        	ldrv	.EQU	hcbx
577
 3141          00006F        	tmpldt	.EQU	hcbx+1
578
 3142
579
 3143  000072  0000          	fhash		.DW
580
 3144  000074  0000          	fcbofs		.DW
581
 3145  000076  00            	bcbload		.DB
582
 3146  000077  00            	xstart		.DB
583
 3147  000078  00            	xend		.DB
584
 3148  000079  00            	seccnt		.DB
585
 3149  00007A  00            	maxseq		.DB
586
 3150  00007B  00            	dsiz		.DB
587
 3151
588
 3152  00007C  00            	haswld		.DB
589
 3153  00007D  00            	strix		.DB
590
 3154  00007E                	pathp		LP		; long pointer to path string
591
 3155
592
 3156                        	; TEMP
593
 3157  000081  0000          	quot		.DW
594
 3158  000083  0000          	dvsor		.DW
595
 3159  000085  0000          	troot		.DW
596
 3160  000087  0000          	tlst		.DW
597
 3161  000089  0000          	bdmask		.DW
598
 3162  00008B  0000          	bcmask		.DW
599
 3163
600
 3164  00008D  00            	hcbuse		.DB
601
 3165
602
 3166                        	.ENDS
603
 3167
604
 3171                        	.LIST on
605
 3172
606
 3173                        	;---------------------------------------------------------------------------
607
 3174                        	; code segment -- bank $F9
608
 3175                        	;---------------------------------------------------------------------------
609
 3176
610
 3177                        		.CODEF9
611
 3178                        		.EXTERN oserror
612
 3179                        		.EXTERN bldldt						; fsint.sm
613
 3180                        		.PUBLIC mxdrv, fndhcb, fndbuf, cls2lba
614
 3181
615
 3182                        		.LONGA	off
616
 3183                        		.LONGI	off
617
 3184
618
 3185                        	; switch logical drive
619
 3186                        	;
620
 3187                        	;	entry:	A = logical drive number
621
  Tue Jul 17 11:00:21 2018                                                                                               Page   11
622
 
623
 
624
 
625
 
626
 3188                        	;
627
 3189                        	;	exit:	curdrv = current logical drive number
628
 3190                        	;		pdrive = current phsycal drive
629
 3191                        	;		LDT struct of the drive moved in page 0
630
 3192                        	;
631
 3193                        	;	use:	A,X,Y
632
 3194                        	;
633
 3195                        	;	note:	if any error this function never return to the caller
634
 3196                        	;
635
 3197                        	;-----
636
 3198  F92423                	mxdrv:
637
 3199                        	;-----
638
 3200  F92423  C9 04         		cmp	#MAXDRV
639
 3201  F92425  90 05         		bcc	?02
640
 3202  F92427  A9 0F         		lda	#ED_DRIVE	; invalid drive
641
 3203  F92429  4C 12 24      		jmp	oserror
642
 3204  F9242C  A8            	?02:	tay			; drive to select
643
 3205  F9242D  BE D2 40      		ldx	!P0LDT+ldtp,y	; LDT pointer
644
 3206  F92430  3C 00 40      		bit	!P0LDT+ldt_fg1,x	; drive flag
645
 3207  F92433  10 33         		bpl	?05		; drive not ready
646
 3208  F92435  70 41         		bvs	?10		; fixed disk: we can trust...
647
 3209  F92437  84 6E         		sty	ldrv
648
 3210  F92439  86 6F         		stx	tmpldt
649
 3211  F9243B  BD 00 40      		lda	!P0LDT+ldt_fg1,x
650
 3212  F9243E  29 01         		and	#1
651
 3213  F92440  AA            		tax
652
 3214  F92441                		FDCTST			; check media inside drive
653
 3215  F92441  02 30         		cop	$30
654
 3216  F92443  03            		.DB	$03
655
 3217                        		.MNLIST
656
 3218  F92444  B0 0B         		bcs	?04		; media changed or not ready?
657
 3219  F92446  A6 6F         		ldx	tmpldt
658
 3220  F92448  BD 01 40      		lda	!P0LDT+ldt_fg2,x
659
 3221  F9244B  89 20         		bit	#$20		; test bit 5
660
 3222  F9244D  D0 25         		bne	?08		; ok, disk already checked
661
 3223  F9244F  F0 1C         		beq	?06		; must check disk
662
 3224  F92451  5A            	?04:	phy			; save error code
663
 3225  F92452  DA            		phx			; save phisycal drive
664
 3226  F92453  A6 6E         		ldx	ldrv		; discard any HCB block for this drive
665
 3227  F92455  20 46 25      		jsr	hdscdrv
666
 3228  F92458  A6 6E         		ldx	ldrv		; discard any buffer for this drive
667
 3229  F9245A  20 8A 28      		jsr	bdscdrv
668
 3230  F9245D  FA            		plx			; restore phisycal drive
669
 3231  F9245E  7A            		ply			; restore fdc error code
670
 3232  F9245F  C0 11         		cpy	#FDC_CHANGE	; check error code
671
 3233  F92461  D0 05         		bne	?05		; disk not ready
672
 3234  F92463                		FDCTST			; check again
673
 3235  F92463  02 30         		cop	$30
674
 3236  F92465  03            		.DB	$03
675
 3237                        		.MNLIST
676
 3238  F92466  90 05         		bcc	?06		; ok
677
 3239  F92468  A9 15         	?05:	lda	#ED_NOTRDY	; disk not ready
678
 3240  F9246A  4C 12 24      		jmp	oserror
679
 3241  F9246D  A5 6E         	?06:	lda	ldrv
680
 3242  F9246F  20 BA 08      		jsr	bldldt		; build LDT table for this drive
681
 3243  F92472  B0 44         		bcs	?40
682
 3244  F92474  A6 6F         	?08:	ldx	tmpldt
683
  Tue Jul 17 11:00:21 2018                                                                                               Page   12
684
 
685
 
686
 
687
 
688
 3245  F92476  A4 6E         		ldy	ldrv
689
 3246  F92478  BD 01 40      	?10:	lda	!P0LDT+ldt_fg2,x
690
 3247  F9247B  29 A0         		and	#$A0		; bit 7&5 will be set
691
 3248  F9247D  C9 A0         		cmp	#$A0
692
 3249  F9247F  D0 35         		bne	?34		; invalid format
693
 3250  F92481  C4 52         		cpy	curdrv		; change drive?
694
 3251  F92483  F0 30         		beq	?20		; no, use current table
695
 3252  F92485  84 52         		sty	curdrv		; set up curdrv
696
 3253  F92487  9B            		txy			; LDT pointer
697
 3254  F92488  A2 29         		ldx	#LDTSIZE-1	; move LDT table in current page 0
698
 3255  F9248A  B9 29 40      	?12:	lda	!P0LDT+ldt0+LDTSIZE-1,y
699
 3256  F9248D  95 18         		sta	ldtfg1,x
700
 3257  F9248F  88            		dey
701
 3258  F92490  CA            		dex
702
 3259  F92491  10 F7         		bpl	?12
703
 3260  F92493  29 01         		and	#1
704
 3261  F92495  85 15         		sta	pdrive
705
 3262  F92497  A8            		tay
706
 3263  F92498  24 18         		bit	ldtfg1
707
 3264  F9249A  70 19         		bvs	?20		; fixed disk
708
 3265  F9249C  A9 09         		lda	#9		; 9 sec. per track
709
 3266  F9249E  A6 33         		ldx	ldtfmt
710
 3267  F924A0  F0 02         		beq	?14
711
 3268  F924A2  A9 12         		lda	#18		; 18 sec. per track
712
 3269  F924A4  85 14         	?14:	sta	fspt
713
 3270  F924A6                		ACC16
714
 3271  F924A6  C2 20         		rep	#PMFLAG
715
 3272                        		.LONGA	on
716
 3273                        		.MNLIST
717
 3274  F924A8  A9 00 CC      		lda	#dma0s
718
 3275  F924AB  BB            		tyx
719
 3276  F924AC  F0 03         		beq	?18
720
 3277  F924AE  A9 10 CD      		lda	#dma1s
721
 3278  F924B1  85 12         	?18:	sta	dmabcb
722
 3279  F924B3                		ACC08
723
 3280  F924B3  E2 20         		sep	#PMFLAG
724
 3281                        		.LONGA	off
725
 3282                        		.MNLIST
726
 3283  F924B5  60            	?20:	rts
727
 3284
728
 3285  F924B6  A9 0B         	?34:	lda	#ED_FORMAT
729
 3286  F924B8  4C 12 24      	?40:	jmp	oserror
730
 3287
731
 3288                        	;---------------------------------------------------------------------------
732
 3289                        	; HCB helpers
733
 3290                        	;---------------------------------------------------------------------------
734
 3291  F924BB
735
 3292  F924BB                	fndhcb2:
736
 3293  F924BB  8B            		phb			; save current DBR
737
 3294  F924BC  A9 00         		lda	#^hcb_data
738
 3295  F924BE  48            		pha
739
 3296  F924BF  AB            		plb			; set DBR to HCB struct's
740
 3297  F924C0                		CPU16
741
 3298  F924C0  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
742
 3299                        		.LONGA	on
743
 3300                        		.LONGI	on
744
 3301                        		.MNLIST
745
  Tue Jul 17 11:00:21 2018                                                                                               Page   13
746
 
747
 
748
 
749
 
750
 3302  F924C2  20 C9 24      		jsr	fndhcb
751
 3303  F924C5                		CPU08
752
 3304  F924C5  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
753
 3305                        		.LONGA	off
754
 3306                        		.LONGI	off
755
 3307                        		.MNLIST
756
 3308  F924C7  AB            		plb			; restore DBR
757
 3309  F924C8  60            		rts
758
 3310
759
 3311                        	; find HCB for given drive,cluster and sequence
760
 3312                        	;
761
 3313                        	;	entry:	hcbcls  = cluster (=0 if root dir.)
762
 3314                        	;		hcbseq  = sector offset sequence
763
 3315                        	;		hcbdrv  = logical drive
764
 3316                        	;		DBR	= bank that hold HCB struct's
765
 3317                        	;		CF	= 0 if exact match required
766
 3318                        	;		CF	= 1 if we want to recycle oldest HCB
767
 3319                        	;
768
 3320                        	;	exit:	CF	= 0 if HCB found
769
 3321                        	;		hcbroot	= HCB pointer if found
770
 3322                        	;		buffer loaded from disk
771
 3323                        	;		CF	= 1 if HCB was not found
772
 3324                        	;
773
 3325                        	;	use:	C,X,Y
774
 3326                        	;
775
 3327                        	;	note:	this routine should be called with 16 bit cpu mode
776
 3328                        	;
777
 3329                        	;------
778
 3330  F924C9                	fndhcb:
779
 3331                        	;------
780
 3332  F924C9  64 68         		stz	hcbrec		; recycle flag
781
 3333  F924CB  90 02         		bcc	?05		; no recycle
782
 3334  F924CD  C6 68         		dec	hcbrec		; =$FFFF, recycle
783
 3335  F924CF  A6 04         	?05:	ldx	hcbroot		; start from head of list
784
 3336  F924D1  80 07         		bra	?15
785
 3337  F924D3  BD 00 00      	?10:	lda	!hcb_next,x	; onto the next entry
786
 3338  F924D6  F0 15         		beq	?20		; no one there...
787
 3339  F924D8  9B            		txy			; Y=previous HCB
788
 3340  F924D9  AA            		tax			; X=current HCB
789
 3341  F924DA  BD 04 00      	?15:	lda	!hcb_seq,x	; sequence+drive
790
 3342  F924DD  30 0E         		bmi	?20		; from here start the free list
791
 3343  F924DF  C5 62         		cmp	hcbseq		; does seq+drive match?
792
 3344  F924E1  D0 F0         		bne	?10		; goto next if not
793
 3345  F924E3  BD 02 00      		lda	!hcb_cls,x
794
 3346  F924E6  C5 6C         		cmp	hcbcls		; does cluster match?
795
 3347  F924E8  D0 E9         		bne	?10		; goto next if not
796
 3348  F924EA  18            		clc			; HCB found
797
 3349  F924EB  F0 12         		beq	?30		; we have a match: find & load buffer
798
 3350  F924ED  38            	?20:	sec			; we have been all along the chain w/no luck
799
 3351  F924EE  24 68         		bit	hcbrec		; do we want to recycle oldest HCB?
800
 3352  F924F0  10 2C         		bpl	?40		; no, so HCB not found & exit with CF=1
801
 3353  F924F2  9E 06 00      		stz	hcb_cnt,x	; recycle oldest HCB...
802
 3354  F924F5  A5 62         		lda	hcbseq
803
 3355  F924F7  9D 04 00      		sta	!hcb_seq,x	; ...so mark as us, but with nothing in it
804
 3356  F924FA  A5 6C         		lda	hcbcls
805
 3357  F924FC  9D 02 00      		sta	!hcb_cls,x
806
 3358  F924FF  08            	?30:	php			; save carry
807
  Tue Jul 17 11:00:21 2018                                                                                               Page   14
808
 
809
 
810
 
811
 
812
 3359  F92500  E4 04         		cpx	hcbroot		; this HCB is the head of list?
813
 3360  F92502  F0 0D         		beq	?32		; yes, no need to move ahead
814
 3361  F92504  BD 00 00      		lda	!hcb_next,x	; get link to the rest of chain
815
 3362  F92507  99 00 00      		sta	!hcb_next,y	; unlink ourselves from chain
816
 3363  F9250A  A5 04         		lda	hcbroot
817
 3364  F9250C  86 04         		stx	hcbroot		; move current entry at the head...
818
 3365  F9250E  9D 00 00      		sta	!hcb_next,x	; ...and relink the rest of the chain
819
 3366  F92511  E4 06         	?32:	cpx	hcblst		; this HCB was the last one of list?
820
 3367  F92513  D0 02         		bne	?35		; no
821
 3368  F92515  84 06         		sty	hcblst		; yes...so the previous become the last one
822
 3369  F92517  28            	?35:	plp			; restore carry
823
 3370  F92518  90 04         		bcc	?40		; HCB found, not need to fill it
824
 3371  F9251A  20 A6 25      		jsr	hcbfill		; fill it
825
 3372  F9251D  18            		clc
826
 3373  F9251E  60            	?40:	rts
827
 3374
828
 3375                        		.LONGA	off		; for assembler
829
 3376                        		.LONGI	off
830
 3377
831
 3378                        	; discard HCB for given drive, cluster and sequence
832
 3379                        	;
833
 3380                        	;	entry:	C = cluster
834
 3381                        	;		X = logical drive
835
 3382                        	;		Y = sequence #
836
 3383                        	;
837
 3384                        	;	out:	nothing
838
 3385                        	;
839
 3386                        	;	use:	all
840
 3387                        	;
841
 3388                        	; 	note:
842
 3389                        	;-------
843
 3390  F9251F                	hdscblk:
844
 3391                        	;-------
845
 3392  F9251F                		ACC16
846
 3393  F9251F  C2 20         		rep	#PMFLAG
847
 3394                        		.LONGA	on
848
 3395                        		.MNLIST
849
 3396  F92521  85 6C         		sta	hcbcls		; cluster to discard
850
 3397  F92523  86 63         		stx	hcbdrv		; drive
851
 3398  F92525  84 62         		sty	hcbseq		; sequence
852
 3399  F92527  A9 FF FF      		lda	#$FFFF
853
 3400  F9252A  85 89         		sta	bdmask		; drive+sec mask
854
 3401  F9252C  85 8B         		sta	bcmask		; cluster mask
855
 3402  F9252E  80 27         		bra	hdscrd		; discard
856
 3403
857
 3404                        	; discard HCB's for given drive & cluster
858
 3405                        	;
859
 3406                        	;	entry:	C = cluster
860
 3407                        	;		X = logical drive
861
 3408                        	;
862
 3409                        	;	out:	nothing
863
 3410                        	;
864
 3411                        	;	use:	all
865
 3412                        	;
866
 3413                        	; 	note:
867
 3414                        	;-------
868
 3415  F92530                	hdsccls:
869
  Tue Jul 17 11:00:21 2018                                                                                               Page   15
870
 
871
 
872
 
873
 
874
 3416                        	;-------
875
 3417  F92530                		ACC16
876
 3418  F92530  C2 20         		rep	#PMFLAG
877
 3419                        		.LONGA	on
878
 3420                        		.MNLIST
879
 3421  F92532  85 6C         		sta	hcbcls		; cluster to discard
880
 3422  F92534  86 63         		stx	hcbdrv		; drive
881
 3423  F92536  A0 00         		ldy	#0
882
 3424  F92538  84 62         		sty	hcbseq		; all sector's
883
 3425  F9253A  A9 FF FF      		lda	#$FFFF
884
 3426  F9253D  85 8B         		sta	bcmask		; cluster mask
885
 3427  F9253F  A9 00 FF      		lda	#$FF00
886
 3428  F92542  85 89         		sta	bdmask		; drive mask (all sector's)
887
 3429  F92544  80 11         		bra	hdscrd		; discard
888
 3430
889
 3431                        	; discard HCB's for given drive
890
 3432                        	;
891
 3433                        	;	entry:	X = logical drive
892
 3434                        	;
893
 3435                        	;	out:	nothing
894
 3436                        	;
895
 3437                        	;	use:	all
896
 3438                        	;
897
 3439                        	; 	note:
898
 3440                        	;-------
899
 3441  F92546                	hdscdrv:
900
 3442                        	;-------
901
 3443  F92546                		ACC16
902
 3444  F92546  C2 20         		rep	#PMFLAG
903
 3445                        		.LONGA	on
904
 3446                        		.MNLIST
905
 3447  F92548  64 6C         		stz	hcbcls		; all cluster's
906
 3448  F9254A  86 63         		stx	hcbdrv		; drive
907
 3449  F9254C  A0 00         		ldy	#0
908
 3450  F9254E  84 62         		sty	hcbseq		; all sector's
909
 3451  F92550  64 8B         		stz	bcmask		; cluster mask (all cluster's)
910
 3452  F92552  A9 00 FF      		lda	#$FF00
911
 3453  F92555  85 89         		sta	bdmask		; drive mask (all sector's)
912
 3454
913
 3455                        	; discard HCB's
914
 3456  F92557                	hdscrd:
915
 3457  F92557  8B            		phb			; save dbr
916
 3458  F92558  A2 04         		ldx	#HCBBNK		; set working dbr
917
 3459  F9255A  DA            		phx
918
 3460  F9255B  AB            		plb
919
 3461  F9255C                		CPU16
920
 3462  F9255C  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
921
 3463                        		.LONGA	on
922
 3464                        		.LONGI	on
923
 3465                        		.MNLIST
924
 3466  F9255E  A6 04         		ldx	hcbroot		; list root
925
 3467  F92560  80 07         		bra	?15
926
 3468  F92562  BD 00 00      	?10:	lda	!hcb_next,x	; next BCB
927
 3469  F92565  F0 3B         		beq	?30		; done
928
 3470  F92567  9B            		txy			; Y=previous BCB
929
 3471  F92568  AA            		tax			; X=current BCB
930
 3472  F92569  BD 04 00      	?15:	lda	!hcb_seq,x
931
  Tue Jul 17 11:00:21 2018                                                                                               Page   16
932
 
933
 
934
 
935
 
936
 3473  F9256C  30 34         		bmi	?30		; no more BCB...done
937
 3474  F9256E  25 89         		and	bdmask		; mask drive+sec
938
 3475  F92570  C5 62         		cmp	hcbseq		; match?
939
 3476  F92572  D0 EE         		bne	?10		; no...go to next BCB
940
 3477  F92574  BD 02 00      		lda	!hcb_cls,x
941
 3478  F92577  25 8B         		and	bcmask		; mask cluster
942
 3479  F92579  C5 64         		cmp	bcbcls		; match?
943
 3480  F9257B  D0 E5         		bne	?10		; no...go to next BCB
944
 3481  F9257D  BD 00 00      		lda	!hcb_next,x	; get link to the rest of chain
945
 3482  F92580  E4 04         		cpx	hcbroot		; is the root of the list?
946
 3483  F92582  D0 04         		bne	?20		; no
947
 3484  F92584  85 04         		sta	hcbroot		; unlink ourselves from chain
948
 3485  F92586  80 03         		bra	?25
949
 3486  F92588  99 00 00      	?20:	sta	!hcb_next,y	; unlink ourselves from chain
950
 3487  F9258B  48            	?25:	pha			; next BCB to check
951
 3488  F9258C  A9 FF FF      		lda	#$FFFF		; put this BCB in free list
952
 3489  F9258F  9D 04 00      		sta	!hcb_seq,x
953
 3490  F92592  A5 06         		lda	hcblst		; the actual last one
954
 3491  F92594  86 06         		stx	hcblst		; this BCB become the last one
955
 3492  F92596  9E 00 00      		stz	!hcb_next,x
956
 3493  F92599  AA            		tax			; link the rest of list to the last one
957
 3494  F9259A  A5 06         		lda	hcblst
958
 3495  F9259C  9D 00 00      		sta	!hcb_next,x
959
 3496  F9259F  FA            		plx			; next BCB to check
960
 3497  F925A0  D0 C7         		bne	?15
961
 3498  F925A2                	?30:	CPU08
962
 3499  F925A2  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
963
 3500                        		.LONGA	off
964
 3501                        		.LONGI	off
965
 3502                        		.MNLIST
966
 3503  F925A4  AB            		plb			; restore dbr
967
 3504  F925A5  60            		rts
968
 3505
969
 3506                        	; fill an HCB with many hashed entries as much is possible
970
 3507                        	;
971
 3508                        	;	entry:	hcbroot = HCB pointer
972
 3509                        	;		hcbcls  = cluster (=0 if root dir.)
973
 3510                        	;		hcbseq  = sector offset sequence
974
 3511                        	;		hcbdrv  = logical drive
975
 3512                        	;		DBR     = bank that hold HCB struct's
976
 3513                        	;
977
 3514                        	;	exit:	HCB is filled with hashed directory entries
978
 3515                        	;		hcb_cnt field is negative if no more entries
979
 3516                        	;
980
 3517                        	;	use:	C,X,Y
981
 3518                        	;
982
 3519                        	;	note:	this routine can be called in any cpu mode (8/16 bit)
983
 3520                        	;
984
 3521                        	;-------
985
 3522  F925A6                	hcbfill:
986
 3523                        	;-------
987
 3524  F925A6  08            		php
988
 3525  F925A7                		CPU08
989
 3526  F925A7  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
990
 3527                        		.LONGA	off
991
 3528                        		.LONGI	off
992
 3529                        		.MNLIST
993
  Tue Jul 17 11:00:21 2018                                                                                               Page   17
994
 
995
 
996
 
997
 
998
 3530  F925A9  A5 62         		lda	hcbseq		; what sequence number?
999
 3531  F925AB  F0 08         		beq	?10		; first...start at offset zero
1000
 3532  F925AD  A6 09         		ldx	hlog2		; shift count
1001
 3533  F925AF  F0 04         		beq	?10		; no shift (HCB can contain 1 sector)
1002
 3534  F925B1  0A            	?05:	asl	a
1003
 3535  F925B2  CA            		dex
1004
 3536  F925B3  D0 FC         		bne	?05
1005
 3537  F925B5  85 45         	?10:	sta	secofs
1006
 3538  F925B7  A8            		tay			; Y=sector's offset
1007
 3539  F925B8  A5 7B         		lda	dsiz		; directory size in sector's
1008
 3540  F925BA  38            		sec
1009
 3541  F925BB  E5 45         		sbc	secofs		; how many sector's left to hash...
1010
 3542  F925BD  C5 08         		cmp	hsiz		; do we support this many?
1011
 3543  F925BF  90 02         		bcc	?15
1012
 3544  F925C1  A5 08         		lda	hsiz		; ...else limit it to this many
1013
 3545  F925C3  AA            	?15:	tax			; X=sector's count
1014
 3546  F925C4                		ACC16
1015
 3547  F925C4  C2 20         		rep	#PMFLAG
1016
 3548                        		.LONGA	on
1017
 3549                        		.MNLIST
1018
 3550  F925C6  A5 04         		lda	hcbroot
1019
 3551  F925C8  85 6A         		sta	hlast		; starting hash code pointer
1020
 3552  F925CA  84 45         	?20:	sty	secofs		; Y=sector offset
1021
 3553  F925CC  86 79         		stx	seccnt		; X=sector's count
1022
 3554  F925CE  A5 6C         		lda	hcbcls		; C=cluster
1023
 3555  F925D0  A6 63         		ldx	hcbdrv		; X=drive
1024
 3556  F925D2  38            		sec			; preread from disk
1025
 3557  F925D3  20 83 26      		jsr	fndbuf		; find & fill sector buffer (can return CF=1)
1026
 3558  F925D6  20 10 26      		jsr	hcbblk		; hash 16 entries (preserve CF)
1027
 3559  F925D9  A6 79         		ldx	seccnt
1028
 3560  F925DB  CA            		dex			; how many sector's left?
1029
 3561  F925DC  F0 23         		beq	?40		; all sector's loaded&hashed
1030
 3562  F925DE  B0 05         		bcs	?30		; no more entries after this sector...
1031
 3563  F925E0  A4 45         		ldy	secofs
1032
 3564  F925E2  C8            		iny			; next sector
1033
 3565  F925E3  80 E5         		bra	?20		; load&hash next sector
1034
 3566  F925E5                	?30:	CPU16
1035
 3567  F925E5  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1036
 3568                        		.LONGA	on
1037
 3569                        		.LONGI	on
1038
 3570                        		.MNLIST
1039
 3571  F925E7  8A            		txa
1040
 3572  F925E8  0A            		asl	a
1041
 3573  F925E9  0A            		asl	a
1042
 3574  F925EA  0A            		asl	a
1043
 3575  F925EB  0A            		asl	a
1044
 3576  F925EC  A8            		tay			; we have this many null entries
1045
 3577  F925ED  A6 6A         		ldx	hlast		; last hash code ptr
1046
 3578  F925EF  9E 08 00      	?35:	stz	!hcb_data,x	; zap rest of cluster
1047
 3579  F925F2  E8            		inx
1048
 3580  F925F3  E8            		inx
1049
 3581  F925F4  88            		dey
1050
 3582  F925F5  D0 F8         		bne	?35
1051
 3583  F925F7  86 6A         		stx	hlast		; update last ptr
1052
 3584  F925F9  A4 04         		ldy	hcbroot
1053
 3585  F925FB  18            		clc
1054
 3586  F925FC  79 06 00      		adc	hcb_cnt,y
1055
  Tue Jul 17 11:00:21 2018                                                                                               Page   18
1056
 
1057
 
1058
 
1059
 
1060
 3587  F925FF  80 07         		bra	?45		; no more entries...
1061
 3588  F92601  90 0B         	?40:	bcc	?50		; more entries...
1062
 3589  F92603  A4 04         		ldy	hcbroot
1063
 3590  F92605  B9 06 00      		lda	hcb_cnt,y
1064
 3591  F92608  09 00 80      	?45:	ora	#$8000		; negative count: no more entries after...
1065
 3592  F9260B  99 06 00      		sta	hcb_cnt,y
1066
 3593  F9260E  28            	?50:	plp
1067
 3594  F9260F  60            		rts
1068
 3595
1069
 3596                        		.LONGA	off		; for assembler
1070
 3597                        		.LONGI	off
1071
 3598
1072
 3599                        	; hash a directory block (16 entries)
1073
 3600                        	;
1074
 3601                        	;	entry:	hcbroot = HCB pointer
1075
 3602                        	;		hlast   = start pointer where store hash codes
1076
 3603                        	;		fcbp    = long pointer to directory block
1077
 3604                        	;		DBR     = bank that hold HCB struct's
1078
 3605                        	;
1079
 3606                        	;	exit:	hlast=pointer to next available free entry
1080
 3607                        	;
1081
 3608                        	;	use:	C,X,Y
1082
 3609                        	;
1083
 3610                        	;	note:	this routine can be called in any cpu mode (8/16 bit)
1084
 3611                        	;
1085
 3612                        	;------
1086
 3613  F92610                	hcbblk:
1087
 3614                        	;------
1088
 3615  F92610  08            		php			; save status
1089
 3616  F92611                		CPU16
1090
 3617  F92611  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1091
 3618                        		.LONGA	on
1092
 3619                        		.LONGI	on
1093
 3620                        		.MNLIST
1094
 3621  F92613  A2 10 00      		ldx	#16		; 16 entries
1095
 3622  F92616  DA            	?05:	phx			; save counter
1096
 3623  F92617  64 68         		stz	thash		; reset hash code
1097
 3624  F92619  A7 5E         		lda	[fcbp]
1098
 3625  F9261B  29 FF 00      		and	#$00FF		; mask off 2nd character
1099
 3626  F9261E  F0 41         		beq	?15		; empty entry so thash=0
1100
 3627  F92620  C9 E5 00      		cmp	#$00E5
1101
 3628  F92623  F0 3A         		beq	?10		; deleted entry so thash=0
1102
 3629  F92625  AA            		tax			; save first character
1103
 3630  F92626  A0 0B 00      		ldy	#11		; get attribute
1104
 3631  F92629  B7 5E         		lda	[fcbp],y
1105
 3632  F9262B  29 3F 00      		and	#$003F		; long file name entry?
1106
 3633  F9262E  C9 0F 00      		cmp	#$000F
1107
 3634  F92631  F0 2C         		beq	?10		; yes so thash=0
1108
 3635  F92633  8A            		txa
1109
 3636  F92634                		CPU08
1110
 3637  F92634  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1111
 3638                        		.LONGA	off
1112
 3639                        		.LONGI	off
1113
 3640                        		.MNLIST
1114
 3641  F92636  29 7F         		and	#$7F
1115
 3642  F92638  85 69         		sta	thash+1		; initialize hash code MSB
1116
 3643  F9263A  A2 0A         		ldx	#10		; involve other 10 characters...
1117
  Tue Jul 17 11:00:21 2018                                                                                               Page   19
1118
 
1119
 
1120
 
1121
 
1122
 3644  F9263C  A0 01         		ldy	#1		; ...starting from 2nd
1123
 3645  F9263E                	?08:	ACC16
1124
 3646  F9263E  C2 20         		rep	#PMFLAG
1125
 3647                        		.LONGA	on
1126
 3648                        		.MNLIST
1127
 3649  F92640  A5 68         		lda	thash		; this simulate a 17 bit rotation
1128
 3650  F92642  0A            		asl	a		; CF=old A<15>
1129
 3651  F92643  69 00 00      		adc	#$0000		; A<0>=CF=old A<15>
1130
 3652  F92646  85 68         		sta	thash
1131
 3653  F92648                		ACC08
1132
 3654  F92648  E2 20         		sep	#PMFLAG
1133
 3655                        		.LONGA	off
1134
 3656                        		.MNLIST
1135
 3657  F9264A  B7 5E         		lda	[fcbp],y	; get next char
1136
 3658  F9264C  29 7F         		and	#$7F
1137
 3659  F9264E  45 68         		eor	thash		; xor char into the hash code
1138
 3660  F92650  85 68         		sta	thash
1139
 3661  F92652  C8            		iny
1140
 3662  F92653  CA            		dex
1141
 3663  F92654  D0 E8         		bne	?08		; repeat for all characters
1142
 3664  F92656                		CPU16CLC
1143
 3665  F92656  C2 31         		rep	#(PMFLAG.OR.PXFLAG.OR.PCFLAG)
1144
 3666                        		.LONGA	on
1145
 3667                        		.LONGI	on
1146
 3668                        		.MNLIST
1147
 3669  F92658  A5 68         		lda	thash
1148
 3670  F9265A  D0 05         		bne	?15		; thash=0 reserved for empty/deleted/lfn entry
1149
 3671  F9265C  1A            		inc	a
1150
 3672  F9265D  80 02         		bra	?15
1151
 3673  F9265F  A5 68         	?10:	lda	thash		; here thash=0
1152
 3674  F92661  FA            	?15:	plx			; restore counter
1153
 3675  F92662  A4 6A         		ldy	hlast		; Y=hash code data pointer
1154
 3676  F92664  99 08 00      		sta	hcb_data,y
1155
 3677  F92667  C8            		iny			; bump ptr
1156
 3678  F92668  C8            		iny
1157
 3679  F92669  84 6A         		sty	hlast
1158
 3680  F9266B  A5 5E         		lda	fcbp		; here always CF=0
1159
 3681  F9266D  69 20 00      		adc	#32		; bump fcbp pointer
1160
 3682  F92670  85 5E         		sta	fcbp
1161
 3683  F92672  CA            		dex
1162
 3684  F92673  D0 A1         		bne	?05		; next entry
1163
 3685  F92675  18            		clc
1164
 3686  F92676  A6 04         		ldx	hcbroot
1165
 3687  F92678  BD 06 00      		lda	!hcb_cnt,x	; update entries count
1166
 3688  F9267B  69 10 00      		adc	#16
1167
 3689  F9267E  9D 06 00      		sta	!hcb_cnt,x
1168
 3690  F92681  28            		plp			; restore cpu status
1169
 3691  F92682  60            		rts
1170
 3692
1171
 3693                        		.LONGA	off		; for assembler
1172
 3694                        		.LONGI	off
1173
 3695  F92683
1174
 3696                        	;---------------------------------------------------------------------------
1175
 3697                        	; disk buffer's handler
1176
 3698                        	;---------------------------------------------------------------------------
1177
 3699
1178
 3700                        	; find buffer for given drive,cluster&sector's offset
1179
  Tue Jul 17 11:00:21 2018                                                                                               Page   20
1180
 
1181
 
1182
 
1183
 
1184
 3701                        	;
1185
 3702                        	;	entry:	C  = cluster (16 bit)
1186
 3703                        	;		X  = logical drive
1187
 3704                        	;		Y  = sector's offset from cluster start
1188
 3705                        	;		CF = 1 if will preread buffer
1189
 3706                        	;
1190
 3707                        	;	exit:	fcbp=long pointer to sector, x-mem bank set to right value
1191
 3708                        	;		xbuf=transfer buffer number
1192
 3709                        	;		lba&lbah=sector address
1193
 3710                        	;		BCB pointer moved at head of list (bcbroot)
1194
 3711                        	;		buffer loaded from disk sector if caller wished it
1195
 3712                        	;		CF=1 if this sector is the last useful sector of directory
1196
 3713                        	;
1197
 3714                        	;	use:	C,X,Y
1198
 3715                        	;
1199
 3716                        	;	note:	this routine can be called in any cpu mode (8/16 bit)
1200
 3717                        	;		if disk error this routine never return to the caller
1201
 3718                        	;
1202
 3719                        	;------
1203
 3720  F92683                	fndbuf:
1204
 3721                        	;------
1205
 3722  F92683  18            		clc			; normal exit carry flag
1206
 3723  F92684  08            		php			; save cpu status
1207
 3724  F92685                		CPU08
1208
 3725  F92685  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1209
 3726                        		.LONGA	off
1210
 3727                        		.LONGI	off
1211
 3728                        		.MNLIST
1212
 3729  F92687  64 76         		stz	bcbload		; preread flag
1213
 3730  F92689  90 02         		bcc	?05		; no preread
1214
 3731  F9268B  C6 76         		dec	bcbload		; preread
1215
 3732  F9268D  8B            	?05:	phb			; save current DBR
1216
 3733  F9268E  86 66         		stx	bcbdrv		; logical drive
1217
 3734  F92690  84 67         		sty	bcbsec		; sector's offset
1218
 3735  F92692  A2 01         		ldx	#^bcbstart
1219
 3736  F92694  DA            		phx
1220
 3737  F92695  AB            		plb			; set DBR to BCB struct's
1221
 3738  F92696  24 18         		bit	ldtfg1		; ata device or floppy?
1222
 3739  F92698                		CPU16
1223
 3740  F92698  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1224
 3741                        		.LONGA	on
1225
 3742                        		.LONGI	on
1226
 3743                        		.MNLIST
1227
 3744  F9269A  85 64         		sta	bcbcls		; cluster #
1228
 3745  F9269C  70 03         		bvs	?08		; ata device
1229
 3746  F9269E  4C 58 27      		jmp	?50		; floppy disk
1230
 3747  F926A1  A6 0A         	?08:	ldx	bcbroot		; start from head of list
1231
 3748  F926A3  80 07         		bra	?15		; search BCB
1232
 3749  F926A5  BD 00 00      	?10:	lda	!bcb_next,x	; onto the next entry
1233
 3750  F926A8  F0 23         		beq	?20		; no one there...
1234
 3751  F926AA  9B            		txy			; Y=previous BCB
1235
 3752  F926AB  AA            		tax			; X=current BCB
1236
 3753  F926AC  BD 02 00      	?15:	lda	!bcb_drv,x
1237
 3754  F926AF  30 1C         		bmi	?20		; from here start the free list
1238
 3755  F926B1  C5 66         		cmp	bcbdrv		; does drive+sector match?
1239
 3756  F926B3  D0 F0         		bne	?10		; goto next if not
1240
 3757  F926B5  BD 04 00      		lda	!bcb_cls,x
1241
  Tue Jul 17 11:00:21 2018                                                                                               Page   21
1242
 
1243
 
1244
 
1245
 
1246
 3758  F926B8  C5 64         		cmp	bcbcls		; does cluster match?
1247
 3759  F926BA  D0 E9         		bne	?10		; goto next if not
1248
 3760  F926BC  BD 06 00      		lda	!bcb_lba,x	; we have a match...
1249
 3761  F926BF  85 4A         		sta	lba		; ...so get lba address of sector...
1250
 3762  F926C1  BD 08 00      		lda	!bcb_lbah,x
1251
 3763  F926C4  85 4C         		sta	lbah
1252
 3764  F926C6  BD 0A 00      		lda	!bcb_buf,x	; ...and get transfer buffer #
1253
 3765  F926C9  85 4E         		sta	xbuf
1254
 3766  F926CB  80 52         		bra	?30		; set buffer pointer
1255
 3767  F926CD  A5 66         	?20:	lda	bcbdrv		; or is the first one free BCB...
1256
 3768  F926CF  9D 02 00      		sta	!bcb_drv,x	; ...or we recycle the oldest one
1257
 3769  F926D2  A5 64         		lda	bcbcls		; ...and we use it
1258
 3770  F926D4  9D 04 00      		sta	!bcb_cls,x
1259
 3771  F926D7  BD 0A 00      		lda	!bcb_buf,x	; get transfer buffer #
1260
 3772  F926DA  85 4E         		sta	xbuf
1261
 3773  F926DC  DA            		phx			; save current BCB ptr
1262
 3774  F926DD  5A            		phy			; save previous BCB ptr
1263
 3775  F926DE  A5 64         		lda	bcbcls		; ...and compute lba address of sector
1264
 3776  F926E0                		CPU08
1265
 3777  F926E0  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1266
 3778                        		.LONGA	off
1267
 3779                        		.LONGI	off
1268
 3780                        		.MNLIST
1269
 3781  F926E2  A6 67         		ldx	bcbsec		; sector offset within cluster
1270
 3782  F926E4  20 2D 29      		jsr	cls2lba		; get lba of sector
1271
 3783  F926E7  18            		clc
1272
 3784  F926E8  24 76         		bit	bcbload		; need to preread buffer?
1273
 3785  F926EA  10 1A         		bpl	?25		; no
1274
 3786  F926EC  A5 18         		lda	ldtfg1
1275
 3787  F926EE  29 01         		and	#1
1276
 3788  F926F0  48            		pha			; phisycal device
1277
 3789  F926F1  A5 4C         		lda	lbah		; 24 bit lba only
1278
 3790  F926F3  48            		pha
1279
 3791  F926F4  D4 4A         		pei	(lba)		; lba address
1280
 3792  F926F6  A9 01         		lda	#1
1281
 3793  F926F8  48            		pha			; read one sec
1282
 3794  F926F9  A9 00         		lda	#0
1283
 3795  F926FB  48            		pha			; x-mem buffer
1284
 3796  F926FC  D4 4E         		pei	(xbuf)		; buffer#
1285
 3797  F926FE  48            		pha			; flag (ignored)
1286
 3798  F926FF                		ATAREAD			; read from ata device
1287
 3799  F926FF  02 40         		cop	$40
1288
 3800  F92701  00            		.DB	$00
1289
 3801                        		.MNLIST
1290
 3802  F92702  84 02         		sty	ioerr		; save i/o error if any
1291
 3803  F92704  86 03         		stx	ioerr2		; save bit error if any
1292
 3804  F92706                	?25:	CPU16
1293
 3805  F92706  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1294
 3806                        		.LONGA	on
1295
 3807                        		.LONGI	on
1296
 3808                        		.MNLIST
1297
 3809  F92708  7A            		ply			; restore previous BCB
1298
 3810  F92709  FA            		plx			; restore current BCB ptr
1299
 3811  F9270A  90 09         		bcc	?27		; no i/o error
1300
 3812  F9270C  A9 FF FF      		lda	#$FFFF		; invalidate buffer
1301
 3813  F9270F  9D 02 00      		sta	!bcb_drv,x
1302
 3814  F92712  4C 5D 28      		jmp	?200
1303
  Tue Jul 17 11:00:21 2018                                                                                               Page   22
1304
 
1305
 
1306
 
1307
 
1308
 3815  F92715  A5 4A         	?27:	lda	lba		; save lba address onto current BCB
1309
 3816  F92717  9D 06 00      		sta	!bcb_lba,x
1310
 3817  F9271A  A5 4C         		lda	lbah
1311
 3818  F9271C  9D 08 00      		sta	!bcb_lbah,x
1312
 3819  F9271F  BD 0C 00      	?30:	lda	!bcb_ptr,x	; set buffer pointer
1313
 3820  F92722  85 5E         		sta	fcbp
1314
 3821  F92724  BD 0E 00      		lda	!bcb_xbnk,x
1315
 3822  F92727  85 60         		sta	fcbp+2		; set hi ptr & x-mem bank
1316
 3823  F92729  E4 0A         		cpx	bcbroot		; this BCB is at the head of list?
1317
 3824  F9272B  F0 13         		beq	?35		; yes, not need to move
1318
 3825  F9272D  BD 00 00      		lda	!bcb_next,x	; get link to the rest of chain
1319
 3826  F92730  99 00 00      		sta	!bcb_next,y	; unlink ourselves from chain
1320
 3827  F92733  A5 0A         		lda	bcbroot
1321
 3828  F92735  86 0A         		stx	bcbroot		; move current entry at the head...
1322
 3829  F92737  9D 00 00      		sta	!bcb_next,x	; ...and relink the rest of the chain
1323
 3830  F9273A  E4 0C         		cpx	bcblst		; this BCB was the last one of list?
1324
 3831  F9273C  D0 02         		bne	?35		; no
1325
 3832  F9273E  84 0C         		sty	bcblst		; yes...so the previous become the last one
1326
 3833  F92740  A0 FE 01      	?35:	ldy	#$01FE		; pointer to last directory entry
1327
 3834  F92743                		ACC08
1328
 3835  F92743  E2 20         		sep	#PMFLAG
1329
 3836                        		.LONGA	off
1330
 3837                        		.MNLIST
1331
 3838  F92745  A5 61         		lda	fcbp+3
1332
 3839  F92747  8F 28 FD 00   		sta	>PIA0+PIAPRA	; set x-mem bank
1333
 3840  F9274B  AB            		plb			; restore DBR
1334
 3841  F9274C  B7 5E         		lda	[fcbp],y	; get first name character
1335
 3842  F9274E  D0 06         		bne	?38		; not null entry, exit with CF=0
1336
 3843  F92750  A3 01         		lda	$01,s		; no more entry after this sector...
1337
 3844  F92752  09 01         		ora	#PCFLAG		; ...so set CF in saved status
1338
 3845  F92754  83 01         		sta	$01,s
1339
 3846  F92756  28            	?38:	plp
1340
 3847  F92757  60            		rts
1341
 3848
1342
 3849                        	?50:	; find dma buffer (C=cluster)
1343
 3850
1344
 3851                        		.LONGA	off		; remember... here cpu mode 16 bit
1345
 3852                        		.LONGI	off
1346
 3853
1347
 3854  F92758  C9 05         		cmp	#5		; root dir, cluser #2,#3&#4 ijn separate list
1348
 3855  F9275A  B0 03         		bcs	?55
1349
 3856  F9275C  4C 24 28      		jmp	?100
1350
 3857  F9275F  A6 0E         	?55:	ldx	dmaroot		; start from head of list
1351
 3858  F92761  80 07         		bra	?65		; search BCB
1352
 3859  F92763  BD 00 00      	?60:	lda	!bcb_next,x	; onto the next entry
1353
 3860  F92766  F0 31         		beq	?70		; no one there...
1354
 3861  F92768  9B            		txy			; Y=previous BCB
1355
 3862  F92769  AA            		tax			; X=current BCB
1356
 3863  F9276A  BD 02 00      	?65:	lda	!bcb_drv,x
1357
 3864  F9276D  30 2A         		bmi	?70		; from here start the free list
1358
 3865  F9276F  C5 66         		cmp	bcbdrv		; does drive+sector match?
1359
 3866  F92771  D0 F0         		bne	?60		; goto next if not
1360
 3867  F92773  BD 04 00      		lda	!bcb_cls,x
1361
 3868  F92776  C5 64         		cmp	bcbcls		; does cluster match?
1362
 3869  F92778  D0 E9         		bne	?60		; goto next if not
1363
 3870  F9277A  BD 06 00      		lda	!bcb_lba,x	; we have a match...
1364
 3871  F9277D  85 4A         		sta	lba		; ...so get lba address of sector...
1365
  Tue Jul 17 11:00:21 2018                                                                                               Page   23
1366
 
1367
 
1368
 
1369
 
1370
 3872  F9277F                		ACC08
1371
 3873  F9277F  E2 20         		sep	#PMFLAG
1372
 3874                        		.LONGA	off
1373
 3875                        		.MNLIST
1374
 3876  F92781  BD 08 00      		lda	!bcb_head,x
1375
 3877  F92784  85 4C         		sta	fhead		; ...and head...
1376
 3878  F92786                		ACC16
1377
 3879  F92786  C2 20         		rep	#PMFLAG
1378
 3880                        		.LONGA	on
1379
 3881                        		.MNLIST
1380
 3882  F92788  BD 0A 00      		lda	!bcb_trk,x
1381
 3883  F9278B  85 4E         		sta	ftrack		; ...and track & sector
1382
 3884  F9278D  BD 0C 00      		lda	!bcb_ptr,x	; set buffer pointer
1383
 3885  F92790  85 5E         		sta	fcbp
1384
 3886  F92792  BD 0E 00      		lda	!bcb_dma,x
1385
 3887  F92795  85 60         		sta	fcbp+2		; set hi ptr & dma buffer
1386
 3888  F92797  80 62         		bra	?80		; done
1387
 3889  F92799  A5 66         	?70:	lda	bcbdrv		; or is the first one free BCB...
1388
 3890  F9279B  9D 02 00      		sta	!bcb_drv,x	; ...or we recycle the oldest one
1389
 3891  F9279E  A5 64         		lda	bcbcls		; ...and we use it
1390
 3892  F927A0  9D 04 00      		sta	!bcb_cls,x
1391
 3893  F927A3  BD 0C 00      		lda	!bcb_ptr,x	; set buffer pointer
1392
 3894  F927A6  85 5E         		sta	fcbp
1393
 3895  F927A8  BD 0E 00      		lda	!bcb_dma,x
1394
 3896  F927AB  85 60         		sta	fcbp+2		; set hi ptr & dma buffer
1395
 3897  F927AD  DA            		phx			; save current BCB ptr
1396
 3898  F927AE  5A            		phy			; save previous BCB ptr
1397
 3899  F927AF  A5 64         		lda	bcbcls		; ...and compute lba address of sector
1398
 3900  F927B1                		CPU08
1399
 3901  F927B1  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1400
 3902                        		.LONGA	off
1401
 3903                        		.LONGI	off
1402
 3904                        		.MNLIST
1403
 3905  F927B3  A6 67         		ldx	bcbsec		; sector offset within cluster
1404
 3906  F927B5  20 2D 29      		jsr	cls2lba		; get lba of sector
1405
 3907  F927B8  20 5E 29      		jsr	lba2hts		; get floppy tuplet H,T,S
1406
 3908  F927BB  18            		clc
1407
 3909  F927BC  24 76         		bit	bcbload		; need to preread buffer?
1408
 3910  F927BE  10 1E         		bpl	?75		; no
1409
 3911  F927C0  A5 18         		lda	ldtfg1		; read sector from floppy disk
1410
 3912  F927C2  29 01         		and	#1
1411
 3913  F927C4  48            		pha			; phisycal device
1412
 3914  F927C5  A5 4E         		lda	ftrack
1413
 3915  F927C7  A6 4C         		ldx	fhead
1414
 3916  F927C9  A4 4F         		ldy	fsec
1415
 3917  F927CB  48            		pha			; track
1416
 3918  F927CC  DA            		phx			; head
1417
 3919  F927CD  5A            		phy			; sector
1418
 3920  F927CE  A9 01         		lda	#1		; read one sector
1419
 3921  F927D0  48            		pha
1420
 3922  F927D1  A5 61         		lda	dmabuf
1421
 3923  F927D3  48            		pha			; dma buffer #
1422
 3924  F927D4  A5 33         		lda	ldtfmt
1423
 3925  F927D6  48            		pha			; format
1424
 3926  F927D7                		FDCREAD			; fdc read
1425
 3927  F927D7  02 31         		cop	$31
1426
 3928  F927D9  00            		.DB	$00
1427
  Tue Jul 17 11:00:21 2018                                                                                               Page   24
1428
 
1429
 
1430
 
1431
 
1432
 3929                        		.MNLIST
1433
 3930  F927DA  84 02         		sty	ioerr		; save i/o error if any
1434
 3931  F927DC  64 03         		stz	ioerr2		; no extended i/o error for fdc
1435
 3932  F927DE                	?75:	CPU16
1436
 3933  F927DE  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1437
 3934                        		.LONGA	on
1438
 3935                        		.LONGI	on
1439
 3936                        		.MNLIST
1440
 3937  F927E0  7A            		ply			; restore previous BCB
1441
 3938  F927E1  FA            		plx			; restore current BCB ptr
1442
 3939  F927E2  90 08         		bcc	?77		; ok, no read errror
1443
 3940  F927E4  A9 FF FF      		lda	#$FFFF		; invalidate buffer
1444
 3941  F927E7  9D 02 00      		sta	!bcb_drv,x
1445
 3942  F927EA  80 71         		bra	?200		; i/o error
1446
 3943  F927EC  A5 4A         	?77:	lda	lba		; store lba address onto current BCB
1447
 3944  F927EE  9D 06 00      		sta	!bcb_lba,x
1448
 3945  F927F1  A5 4C         		lda	fhead		; store head
1449
 3946  F927F3  9D 08 00      		sta	!bcb_head,x
1450
 3947  F927F6  A5 4E         		lda	ftrack		; store track&sector
1451
 3948  F927F8  9D 0A 00      		sta	!bcb_trk,x
1452
 3949  F927FB  E4 0E         	?80:	cpx	dmaroot		; this BCB is at the head of list?
1453
 3950  F927FD  F0 13         		beq	?85		; yes, not need to move
1454
 3951  F927FF  BD 00 00      		lda	!bcb_next,x	; get link to the rest of chain
1455
 3952  F92802  99 00 00      		sta	!bcb_next,y	; unlink ourselves from chain
1456
 3953  F92805  A5 0E         		lda	dmaroot
1457
 3954  F92807  86 0E         		stx	dmaroot		; move current entry at the head...
1458
 3955  F92809  9D 00 00      		sta	!bcb_next,x	; ...and relink the rest of the chain
1459
 3956  F9280C  E4 10         		cpx	dmalst		; this BCB was the last one of list?
1460
 3957  F9280E  D0 02         		bne	?85		; no
1461
 3958  F92810  84 10         		sty	dmalst		; yes...so the previous become the last one
1462
 3959  F92812  A0 FE 01      	?85:	ldy	#$01FE		; pointer to last directory entry
1463
 3960  F92815                		ACC08
1464
 3961  F92815  E2 20         		sep	#PMFLAG
1465
 3962                        		.LONGA	off
1466
 3963                        		.MNLIST
1467
 3964  F92817  AB            		plb			; restore DBR
1468
 3965  F92818  B7 5E         		lda	[fcbp],y	; get first name character
1469
 3966  F9281A  D0 06         		bne	?90		; not null entry, exit with CF=0
1470
 3967  F9281C  A3 01         		lda	$01,s		; no more entry after this sector...
1471
 3968  F9281E  09 01         		ora	#PCFLAG		; ...so set CF in saved status
1472
 3969  F92820  83 01         		sta	$01,s
1473
 3970  F92822  28            	?90:	plp
1474
 3971  F92823  60            		rts
1475
 3972
1476
 3973                        	; floppy disk root dir, cluster #2,#3,#4
1477
 3974  F92824  A6 12         	?100:	ldx	dmabcb		; BCB list in systerm track (track 0)
1478
 3975  F92826  80 06         		bra	?115
1479
 3976  F92828  BD 00 00      	?110:	lda	!bcb_next,x	; onto the next entry
1480
 3977  F9282B  F0 30         		beq	?120		; no one there...
1481
 3978  F9282D  AA            		tax			; X=current BCB
1482
 3979  F9282E  BD 02 00      	?115:	lda	!bcb_drv,x
1483
 3980  F92831  30 2A         		bmi	?120		; from here start the free list
1484
 3981  F92833  C5 66         		cmp	bcbdrv		; does drive+sector match?
1485
 3982  F92835  D0 F1         		bne	?110		; goto next if not
1486
 3983  F92837  BD 04 00      		lda	!bcb_cls,x
1487
 3984  F9283A  C5 64         		cmp	bcbcls		; does cluster match?
1488
 3985  F9283C  D0 EA         		bne	?110		; goto next if not
1489
  Tue Jul 17 11:00:21 2018                                                                                               Page   25
1490
 
1491
 
1492
 
1493
 
1494
 3986  F9283E  BD 06 00      		lda	!bcb_lba,x	; we have a match...
1495
 3987  F92841  85 4A         		sta	lba		; ...so get lba address of sector...
1496
 3988  F92843                		ACC08
1497
 3989  F92843  E2 20         		sep	#PMFLAG
1498
 3990                        		.LONGA	off
1499
 3991                        		.MNLIST
1500
 3992  F92845  BD 08 00      		lda	!bcb_head,x
1501
 3993  F92848  85 4C         		sta	fhead		; ...and head...
1502
 3994  F9284A                		ACC16
1503
 3995  F9284A  C2 20         		rep	#PMFLAG
1504
 3996                        		.LONGA	on
1505
 3997                        		.MNLIST
1506
 3998  F9284C  BD 0A 00      		lda	!bcb_trk,x
1507
 3999  F9284F  85 4E         		sta	ftrack		; ...and track & sector
1508
 4000  F92851  BD 0C 00      		lda	!bcb_ptr,x	; set buffer pointer
1509
 4001  F92854  85 5E         		sta	fcbp
1510
 4002  F92856  BD 0E 00      		lda	!bcb_dma,x
1511
 4003  F92859  85 60         		sta	fcbp+2		; set hi ptr & dma buffer
1512
 4004  F9285B  80 B5         		bra	?85		; done
1513
 4005                        	?120:	; no BCB...should'nt happen this
1514
 4006
1515
 4007                        		;
1516
 4008  F9285D
1517
 4009                        	?200:	; i/o error
1518
 4010                        		; load from disk error
1519
 4011  F9285D                		CPU08
1520
 4012  F9285D  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1521
 4013                        		.LONGA	off
1522
 4014                        		.LONGI	off
1523
 4015                        		.MNLIST
1524
 4016  F9285F  AB            		plb			; restore DBR
1525
 4017  F92860  28            		plp
1526
 4018  F92861  38            		sec			; error
1527
 4019  F92862  60            		rts
1528
 4020
1529
 4021                        	; discard buffer for given drive, cluster & sector offset
1530
 4022                        	;
1531
 4023                        	;	mode:	A/M/X/Y 8 bit
1532
 4024                        	;
1533
 4025                        	;	entry:	C = cluster
1534
 4026                        	;		X = logical drive
1535
 4027                        	;		Y = sector offset within cluster
1536
 4028                        	;
1537
 4029                        	;	out:	BCB's list affected
1538
 4030                        	;
1539
 4031                        	;	use:	all
1540
 4032                        	;
1541
 4033                        	; 	note:
1542
 4034                        	;-------
1543
 4035  F92863                	bdscsec:
1544
 4036                        	;-------
1545
 4037  F92863                		ACC16
1546
 4038  F92863  C2 20         		rep	#PMFLAG
1547
 4039                        		.LONGA	on
1548
 4040                        		.MNLIST
1549
 4041  F92865  85 64         		sta	bcbcls		; cluster to discard
1550
 4042  F92867  86 66         		stx	bcbdrv		; drive
1551
  Tue Jul 17 11:00:21 2018                                                                                               Page   26
1552
 
1553
 
1554
 
1555
 
1556
 4043  F92869  84 67         		sty	bcbsec		; sector
1557
 4044  F9286B  A9 FF FF      		lda	#$FFFF
1558
 4045  F9286E  85 89         		sta	bdmask		; drive+sec mask
1559
 4046  F92870  85 8B         		sta	bcmask		; cluster mask
1560
 4047  F92872  80 27         		bra	bdscrd		; discard
1561
 4048
1562
 4049                        	; discard buffer's of given drive & cluster
1563
 4050                        	;
1564
 4051                        	;	mode:	A/M/X/Y 8 bit
1565
 4052                        	;
1566
 4053                        	;	entry:	C = cluster
1567
 4054                        	;		X = logical drive
1568
 4055                        	;
1569
 4056                        	;	out:	BCB's list affected
1570
 4057                        	;
1571
 4058                        	;	use:	all
1572
 4059                        	;
1573
 4060                        	; 	note:
1574
 4061                        	;-------
1575
 4062  F92874                	bdsccls:
1576
 4063                        	;-------
1577
 4064  F92874                		ACC16
1578
 4065  F92874  C2 20         		rep	#PMFLAG
1579
 4066                        		.LONGA	on
1580
 4067                        		.MNLIST
1581
 4068  F92876  85 64         		sta	bcbcls		; cluster to discard
1582
 4069  F92878  86 66         		stx	bcbdrv		; drive
1583
 4070  F9287A  A0 00         		ldy	#0
1584
 4071  F9287C  84 67         		sty	bcbsec		; all sector's
1585
 4072  F9287E  A9 FF FF      		lda	#$FFFF
1586
 4073  F92881  85 8B         		sta	bcmask		; cluster mask
1587
 4074  F92883  A9 FF 00      		lda	#$00FF
1588
 4075  F92886  85 89         		sta	bdmask		; drive mask (all sector's)
1589
 4076  F92888  80 11         		bra	bdscrd		; discard
1590
 4077
1591
 4078                        	; discard buffer's of given drive
1592
 4079                        	;
1593
 4080                        	;	mode:	A/M/X/Y 8 bit
1594
 4081                        	;
1595
 4082                        	;	entry:	X = logical drive
1596
 4083                        	;
1597
 4084                        	;	out:	BCB's list affected
1598
 4085                        	;
1599
 4086                        	;	use:	all
1600
 4087                        	;
1601
 4088                        	; 	note:
1602
 4089                        	;-------
1603
 4090  F9288A                	bdscdrv:
1604
 4091                        	;-------
1605
 4092  F9288A                		ACC16
1606
 4093  F9288A  C2 20         		rep	#PMFLAG
1607
 4094                        		.LONGA	on
1608
 4095                        		.MNLIST
1609
 4096  F9288C  64 64         		stz	bcbcls		; all cluster's
1610
 4097  F9288E  86 66         		stx	bcbdrv		; drive
1611
 4098  F92890  A0 00         		ldy	#0
1612
 4099  F92892  84 67         		sty	bcbsec		; all sector's
1613
  Tue Jul 17 11:00:21 2018                                                                                               Page   27
1614
 
1615
 
1616
 
1617
 
1618
 4100  F92894  64 8B         		stz	bcmask		; cluster mask (all cluster's)
1619
 4101  F92896  A9 FF 00      		lda	#$00FF
1620
 4102  F92899  85 89         		sta	bdmask		; drive mask (all sector's)
1621
 4103
1622
 4104                        	; discard buffer's
1623
 4105  F9289B                	bdscrd:
1624
 4106  F9289B  A0 00         		ldy	#0
1625
 4107  F9289D  E0 02         		cpx	#ATADRV
1626
 4108  F9289F  90 01         		bcc	?02
1627
 4109  F928A1  88            		dey
1628
 4110  F928A2  84 6F         	?02:	sty	ldrv+1		; flag fdc/ata
1629
 4111  F928A4  8B            		phb			; save dbr
1630
 4112  F928A5  A2 01         		ldx	#WKB		; set working dbr
1631
 4113  F928A7  DA            		phx
1632
 4114  F928A8  AB            		plb
1633
 4115  F928A9                		CPU16
1634
 4116  F928A9  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1635
 4117                        		.LONGA	on
1636
 4118                        		.LONGI	on
1637
 4119                        		.MNLIST
1638
 4120  F928AB  A6 0A         		ldx	bcbroot		; fixed disk list
1639
 4121  F928AD  A4 0C         		ldy	bcblst
1640
 4122  F928AF  24 6E         		bit	ldrv
1641
 4123  F928B1  30 04         		bmi	?05
1642
 4124  F928B3  A6 0E         		ldx	dmaroot		; fd list
1643
 4125  F928B5  A4 10         		ldy	dmalst
1644
 4126  F928B7  86 85         	?05:	stx	troot		; head of list
1645
 4127  F928B9  84 87         		sty	tlst		; end of list
1646
 4128  F928BB  80 07         		bra	?15
1647
 4129  F928BD  BD 00 00      	?10:	lda	!bcb_next,x	; next BCB
1648
 4130  F928C0  F0 3B         		beq	?30		; done
1649
 4131  F928C2  9B            		txy			; Y=previous BCB
1650
 4132  F928C3  AA            		tax			; X=current BCB
1651
 4133  F928C4  BD 02 00      	?15:	lda	!bcb_drv,x
1652
 4134  F928C7  30 34         		bmi	?30		; no more BCB...done
1653
 4135  F928C9  25 89         		and	bdmask		; mask drive+sec
1654
 4136  F928CB  C5 66         		cmp	bcbdrv		; match?
1655
 4137  F928CD  D0 EE         		bne	?10		; no...go to next BCB
1656
 4138  F928CF  BD 04 00      		lda	!bcb_cls,x
1657
 4139  F928D2  25 8B         		and	bcmask		; mask cluster
1658
 4140  F928D4  C5 64         		cmp	bcbcls		; match?
1659
 4141  F928D6  D0 E5         		bne	?10		; no...go to next BCB
1660
 4142  F928D8  BD 00 00      		lda	!bcb_next,x	; get link to the rest of chain
1661
 4143  F928DB  E4 85         		cpx	troot		; is the root of the list?
1662
 4144  F928DD  D0 04         		bne	?20		; no
1663
 4145  F928DF  85 85         		sta	troot		; unlink ourselves from chain
1664
 4146  F928E1  80 03         		bra	?25
1665
 4147  F928E3  99 00 00      	?20:	sta	!bcb_next,y	; unlink ourselves from chain
1666
 4148  F928E6  48            	?25:	pha			; next BCB to check
1667
 4149  F928E7  A9 FF FF      		lda	#$FFFF		; put this BCB in free list
1668
 4150  F928EA  9D 02 00      		sta	!bcb_drv,x
1669
 4151  F928ED  A5 87         		lda	tlst		; the actual last one
1670
 4152  F928EF  86 87         		stx	tlst		; this BCB become the last one
1671
 4153  F928F1  9E 00 00      		stz	!bcb_next,x
1672
 4154  F928F4  AA            		tax			; link the rest of list to the last one
1673
 4155  F928F5  A5 87         		lda	tlst
1674
 4156  F928F7  9D 00 00      		sta	!bcb_next,x
1675
  Tue Jul 17 11:00:21 2018                                                                                               Page   28
1676
 
1677
 
1678
 
1679
 
1680
 4157  F928FA  FA            		plx			; next BCB to check
1681
 4158  F928FB  D0 C7         		bne	?15
1682
 4159  F928FD  A6 85         	?30:	ldx	troot
1683
 4160  F928FF  A4 85         		ldy	troot
1684
 4161  F92901  24 6E         		bit	ldrv
1685
 4162  F92903  30 20         		bmi	?35
1686
 4163  F92905  86 0E         		stx	dmaroot		; update fd list
1687
 4164  F92907  84 10         		sty	dmalst
1688
 4165  F92909  A5 8B         		lda	bcmask		; discard drive?
1689
 4166  F9290B  D0 1C         		bne	?40		; no
1690
 4167  F9290D  A2 00 CC      		ldx	#dma0s
1691
 4168  F92910  A5 66         		lda	bcbdrv
1692
 4169  F92912  29 FF 00      		and	#$00FF
1693
 4170  F92915  F0 03         		beq	?32		; drive #0
1694
 4171  F92917  A2 10 CD      		ldx	#dma1s
1695
 4172  F9291A  A9 FF FF      	?32:	lda	#$FFFF
1696
 4173  F9291D  9D 02 00      		sta	!bcb_drv,x	; empty list
1697
 4174  F92920  9E 00 00      		stz	!bcb_next,x
1698
 4175  F92923  80 04         		bra	?40
1699
 4176  F92925  86 0A         	?35:	stx	bcbroot		; update fixed disk list
1700
 4177  F92927  84 0C         		sty	bcblst
1701
 4178  F92929                	?40:	CPU08
1702
 4179  F92929  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1703
 4180                        		.LONGA	off
1704
 4181                        		.LONGI	off
1705
 4182                        		.MNLIST
1706
 4183  F9292B  AB            		plb			; restore dbr
1707
 4184  F9292C  60            		rts
1708
 4185
1709
 4186                        	;---------------------------------------------------------------------------
1710
 4187                        	; utilities
1711
 4188                        	;---------------------------------------------------------------------------
1712
 4189
1713
 4190                        	; compute lba address from a given cluster
1714
 4191                        	;
1715
 4192                        	;	entry:	C = cluster (16 bit) -- if C = 0 return lba of root directory
1716
 4193                        	;		X = sector offset (8 bit)
1717
 4194                        	;
1718
 4195                        	;	exit:	lba and lbah filled with lba address
1719
 4196                        	;
1720
 4197                        	; 	use:	C,X,Y
1721
 4198                        	;
1722
 4199                        	;	note:	this routine should be called in 8 bit cpu mode
1723
 4200                        	;
1724
 4201                        	;-------
1725
 4202  F9292D                	cls2lba:
1726
 4203                        	;-------
1727
 4204  F9292D  86 68         		stx	wtmp		; sector's offset...
1728
 4205  F9292F  64 69         		stz	wtmp+1		;...extended to 16 bit
1729
 4206  F92931  A6 29         		ldx	ldtcshf		; shift count#
1730
 4207  F92933                		CPU16
1731
 4208  F92933  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1732
 4209                        		.LONGA	on
1733
 4210                        		.LONGI	on
1734
 4211                        		.MNLIST
1735
 4212  F92935  64 4C         		stz	lbah
1736
 4213  F92937  A8            		tay			; compute lba for root dir.?
1737
  Tue Jul 17 11:00:21 2018                                                                                               Page   29
1738
 
1739
 
1740
 
1741
 
1742
 4214  F92938  F0 15         		beq	?20		; yes
1743
 4215  F9293A  3A            		dec	a		; skip fake cluster#0&#1
1744
 4216  F9293B  3A            		dec	a
1745
 4217  F9293C  9B            		txy
1746
 4218  F9293D  F0 06         		beq	?10		; no shift
1747
 4219  F9293F  0A            	?05:	asl	a		; compute lba base
1748
 4220  F92940  26 4C         		rol	lbah
1749
 4221  F92942  CA            		dex
1750
 4222  F92943  D0 FA         		bne	?05
1751
 4223  F92945  18            	?10:	clc
1752
 4224  F92946  A4 4C         		ldy	lbah		; Y=lbah
1753
 4225  F92948  65 24         		adc	ldtcls		; add offset of first data sector
1754
 4226  F9294A  90 06         		bcc	?32
1755
 4227  F9294C  C8            		iny
1756
 4228  F9294D  80 02         		bra	?30
1757
 4229  F9294F  A5 1E         	?20:	lda	ldtroot		; lba address of root dir. (here Y=0)
1758
 4230  F92951  18            	?30:	clc
1759
 4231  F92952  65 68         	?32:	adc	wtmp		; add sector's offset
1760
 4232  F92954  85 4A         		sta	lba
1761
 4233  F92956  90 01         		bcc	?40
1762
 4234  F92958  C8            		iny			; update lbah
1763
 4235  F92959  84 4C         	?40:	sty	lbah
1764
 4236  F9295B                		CPU08
1765
 4237  F9295B  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1766
 4238                        		.LONGA	off
1767
 4239                        		.LONGI	off
1768
 4240                        		.MNLIST
1769
 4241  F9295D  60            		rts
1770
 4242
1771
 4243                        		.LONGA	off		; for assembler
1772
 4244                        		.LONGI	off
1773
 4245
1774
 4246                        	; translate lba address into tuplet (H,T,S) for floppy disk operation
1775
 4247                        	;
1776
 4248                        	; remind:
1777
 4249                        	;	H   = head number (0..1)
1778
 4250                        	;	T   = track number (0..79)
1779
 4251                        	;	S   = sector number (1..max) where max=9 or 18
1780
 4252                        	;	SPT = sector per tack (18 or 36)
1781
 4253                        	;
1782
 4254                        	;	LBA = (H + 2*T)*SPT + (S - 1)
1783
 4255                        	;
1784
 4256                        	;	T   = LBA / (2 * SPT)
1785
 4257                        	;	L   = LBA MOD (2 * SPT)
1786
 4258                        	;	H   = L / P
1787
 4259                        	;	S   = (L MOD P) + 1
1788
 4260                        	;
1789
 4261                        	;	entry:	lba = lba address
1790
 4262                        	;		fspt = sector per track
1791
 4263                        	;
1792
 4264                        	;	exit:	fhead, ftrack, fsec
1793
 4265                        	;
1794
 4266                        	;	use:	all
1795
 4267                        	;
1796
 4268                        	;-------
1797
 4269  F9295E                	lba2hts:
1798
 4270                        	;-------
1799
  Tue Jul 17 11:00:21 2018                                                                                               Page   30
1800
 
1801
 
1802
 
1803
 
1804
 4271  F9295E  A5 14         		lda	fspt
1805
 4272  F92960  0A            		asl	a		; 2*SPT
1806
 4273  F92961  85 83         		sta	dvsor
1807
 4274  F92963  64 84         		stz	dvsor+1		; divisor=2*SPT
1808
 4275  F92965  A5 4B         		lda	lba+1
1809
 4276  F92967  EB            		xba
1810
 4277  F92968  A5 4A         		lda	lba		; C=lba
1811
 4278  F9296A  20 81 29      		jsr	fudiv		; return C=quotient
1812
 4279  F9296D  85 4E         		sta	ftrack		; store track, ignore B (should be null)
1813
 4280  F9296F  A0 00         		ldy	#0		; Y=head
1814
 4281  F92971  A6 83         		ldx	dvsor		; remainder (L)
1815
 4282  F92973  8A            		txa
1816
 4283  F92974  38            		sec
1817
 4284  F92975  E5 14         		sbc	fspt		; get sector & head
1818
 4285  F92977  90 02         		bcc	?10		; L <  SPT so head=0, sec=L+1
1819
 4286  F92979  C8            		iny			; head=1
1820
 4287  F9297A  AA            		tax			; L >= SPT so head=1, sec=L-SPT+1
1821
 4288  F9297B  E8            	?10:	inx			; X=sector
1822
 4289  F9297C  84 4C         		sty	fhead
1823
 4290  F9297E  86 4F         		stx	fsec
1824
 4291  F92980  60            		rts
1825
 4292
1826
 4293                        	; fast unsigned division 16 bit
1827
 4294                        	;
1828
 4295                        	;	entry:	C = 16 bit dividend
1829
 4296                        	;		dvsor = 16 bit divisor
1830
 4297                        	;
1831
 4298                        	;	exit:	C = quot = 16 bit quotient
1832
 4299                        	;		dvsor = 16 bit remainder
1833
 4300                        	;
1834
 4301                        	;	use:	all
1835
 4302                        	;
1836
 4303                        	;	note:	no check for null divisor
1837
 4304                        	;
1838
 4305                        	;-----
1839
 4306  F92981                	fudiv:
1840
 4307                        	;-----
1841
 4308  F92981  A2 01         		ldx	#1		; bit counter
1842
 4309  F92983                		CPU16
1843
 4310  F92983  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
1844
 4311                        		.LONGA	on
1845
 4312                        		.LONGI	on
1846
 4313                        		.MNLIST
1847
 4314                        		;ldy	lba		; Y=dividend
1848
 4315  F92985  A8            		tay
1849
 4316  F92986  64 81         		stz	quot		; init quotient
1850
 4317  F92988  A5 83         		lda	dvsor		; C=divisor
1851
 4318  F9298A  0A            	?10:	asl	a		; shift divisor: get leftmost bit
1852
 4319  F9298B  B0 06         		bcs	?20		; go to division
1853
 4320  F9298D  E8            		inx
1854
 4321  F9298E  E0 11 00      		cpx	#17		; test all divisor bit's
1855
 4322  F92991  D0 F7         		bne	?10
1856
 4323  F92993  6A            	?20:	ror	a		; put shifted-out bit back
1857
 4324  F92994  85 83         		sta	dvsor
1858
 4325  F92996  98            	?30:	tya			; get dividend
1859
 4326  F92997  38            		sec
1860
 4327  F92998  E5 83         		sbc	dvsor
1861
  Tue Jul 17 11:00:21 2018                                                                                               Page   31
1862
 
1863
 
1864
 
1865
 
1866
 4328  F9299A  90 01         		bcc	?40		; can't subctract, retain old dividend
1867
 4329  F9299C  A8            		tay			; Y=new dividend
1868
 4330  F9299D  26 81         	?40:	rol	quot		; shift carry into quotient (1 if division)
1869
 4331  F9299F  46 83         		lsr	dvsor		; shift right divisor for next subtract
1870
 4332  F929A1  CA            		dex
1871
 4333  F929A2  D0 F2         		bne	?30
1872
 4334  F929A4  84 83         		sty	dvsor		; store remainder
1873
 4335  F929A6  A5 81         		lda	quot		; C=quotient
1874
 4336  F929A8                		CPU08
1875
 4337  F929A8  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1876
 4338                        		.LONGA	off
1877
 4339                        		.LONGI	off
1878
 4340                        		.MNLIST
1879
 4341  F929AA  60            		rts
1880
 4342
1881
 4343  F929AB                	ftest:
1882
 4344  F929AB  0B            		phd
1883
 4345  F929AC  F4 00 41      		pea	#P0FAT
1884
 4346  F929AF  2B            		pld
1885
 4347  F929B0  86 14         		stx	fspt
1886
 4348  F929B2  85 4A         		sta	lba
1887
 4349  F929B4  EB            		xba
1888
 4350  F929B5  85 4B         		sta	lba+1
1889
 4351  F929B7  20 5E 29      		jsr	lba2hts
1890
 4352  F929BA  A9 00         		lda	#0
1891
 4353  F929BC  EB            		xba
1892
 4354  F929BD  A5 4E         		lda	ftrack
1893
 4355  F929BF  A6 4F         		ldx	fsec
1894
 4356  F929C1  A4 4C         		ldy	fhead
1895
 4357  F929C3  2B            		pld
1896
 4358  F929C4  00 00         		brk
1897
 4359  F929C6  00 00         		brk
1898
 4360  F929C8
1899
 4361                        	;---------------------------------------------------------------------------
1900
 4362                        	; tables
1901
 4363                        	;---------------------------------------------------------------------------
1902
 4364
1903
 4365  F929C8  3A 2E 3B 2C 3D 	dlmstr	.DB	':.;,=+\<>|/"[]'	; path delimeters
1904
               2B 5C 3C 3E 7C
1905
               2F 22 5B 5D
1906
 4366          00000E        	DLMSTR	.EQU	$-dlmstr
1907
 4367
1908
 4368  F929D6                	devlst:
1909
 4369  F929D6  43 4F 4E 20 20 		.DB	'CON     '	; Keyboard and display
1910
               20 20 20
1911
 4370  F929DE  4B 45 59 42 44 		.DB	'KEYBD$  '	; Keyboard
1912
               24 20 20
1913
 4371  F929E6  53 43 52 45 45 		.DB	'SCREEN$ '	; Display
1914
               4E 24 20
1915
 4372  F929EE  43 4F 4E 53 4F 		.DB	'CONSOLE$'
1916
               4C 45 24
1917
 4373  F929F6  50 52 4E 20 20 		.DB	'PRN     '	; System list device, usually a parallel port
1918
               20 20 20
1919
 4374  F929FE  4C 53 54 20 20 		.DB	'LST     '	; System list device, usually a parallel port
1920
               20 20 20
1921
 4375  F92A06  4C 50 54 31 20 		.DB	'LPT1    '	; First parallel printer port
1922
               20 20 20
1923
  Tue Jul 17 11:00:21 2018                                                                                               Page   32
1924
 
1925
 
1926
 
1927
 
1928
 4376  F92A0E  4C 50 54 32 20 		.DB	'LPT2    '	; Second parallel printer port
1929
               20 20 20
1930
 4377  F92A16  4C 50 54 33 20 		.DB	'LPT3    '	; Third parallel printer port
1931
               20 20 20
1932
 4378  F92A1E  41 55 58 20 20 		.DB	'AUX     '	; Auxiliary device, usually a serial port
1933
               20 20 20
1934
 4379  F92A26  43 4F 4D 31 20 		.DB	'COM1    '	; First serial communications port
1935
               20 20 20
1936
 4380  F92A2E  43 4F 4D 32 20 		.DB	'COM2    '	; Second serial communications port
1937
               20 20 20
1938
 4381  F92A36  43 4F 4D 33 20 		.DB	'COM3    '	; Third serial communications port
1939
               20 20 20
1940
 4382  F92A3E  43 4F 4D 34 20 		.DB	'COM4    '	; Fourth serial communications port
1941
               20 20 20
1942
 4383  F92A46  4E 55 4C 20 20 		.DB	'NUL     '	; Bit-bucket device
1943
               20 20 20
1944
 4384  F92A4E  24 49 44 4C 45 		.DB	'$IDLE$  '	; Bit-bucket device
1945
               24 20 20
1946
 4385  F92A56  43 4C 4F 43 4B 		.DB	'CLOCK$  '	; System real-time clock
1947
               24 20 20
1948
 4386  F92A5E  43 4C 4F 43 4B 		.DB	'CLOCK   '	; System real-time clock
1949
               20 20 20
1950
 4387  F92A66  43 4F 4E 46 49 		.DB	'CONFIG$ '
1951
               47 24 20
1952
 4388  F92A6E  00            		.DB	0
1953
 
1954
 
1955
             Lines Assembled : 4199                  Errors : 0
1956
 
1957
 
1958