Subversion Repositories MB01 Project

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 - 1
  Tue Jul 17 11:00:18 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\F8\usbdsk.asm
13
                       Output Filename : obj\F8\usbdsk.obj
14
                       Listing Has Been Relocated
15
 
16
 
17
 2583                        	.LIST		on
18
 2584
19
 2585  F8FFB1                		.INCLUDE inc\dirp00.inc
20
 2586                        	;----------------------------------------------------------
21
 2587                        	; DIRP00.ASM
22
 2588                        	; PROGETTO: B1601
23
 2589                        	;
24
 2590                        	; Variabili in Direct Page $00
25
 2591                        	;----------------------------------------------------------
26
 2592
27
 2593                        	; sezione COMMON -- questo permette di includere il file in piu' file
28
 2594
29
 2595                        	.LIST on
30
 2596
31
 2597                        	DIRP00:	.SECTION page0, ref_only, common	;Direct-Page 00
32
 2598
33
 2599  000000                		.ABSOLUTE		;; inizia sempre da $00
34
 2600  000000                		.ORG		0x00
35
 2601  000000
36
 2602  000000  0000          	JiffyClk	.DW			; contatore 10ms 32 bit
37
 2603  000002  0000          			.DW
38
 2604  000004                	SysTmr		.DS	SYSTMRCNT	; system timer 0 (10ms)
39
 2605  000008                	SysTMF		.DS	SYSTMRCNT	; flag timer (80 -> start)
40
 2606  00000C  00            	Bnk0Flag	.DB			; <7>: flag test RAM banco 0 ok
41
 2607                        						; <6>: flag warm reset
42
 2608  00000D  00            	RTCFlag		.DB
43
 2609
44
 2610  00000E                	diskstat	.DS	2	; flag device on ata bus #0 & #1
45
 2611                        					; <7>: device ready
46
 2612                        					; <6>: compact flash device (C.F.)
47
 2613                        					; <5>: device identification ok
48
 2614                        					; <4>: MBR loaded
49
 2615                        					; <3>: valid signature in MBR
50
 2616                        					; <2>: first partition found&active
51
 2617                        					; <1>:
52
 2618                        					; <0>: valid partition flag
53
 2619
54
 2620                        					; <7>: device ready
55
 2621                        					; <6>: USB device
56
 2622                        					; <5>: compact flash device (C.F.)
57
 2623                        					; <4>: device identification ok
58
 2624                        					; <3>: MBR loaded
59
 2625                        					; <2>: first partition found&active
60
 2626                        					; <1>: always 1
61
 2627                        					; <0>: valid partition flag
62
 2628  000010
63
  Tue Jul 17 11:00:18 2018                                                                                               Page    2
64
 
65
 
66
 
67
 
68
 2629
69
 2630          00000E        	atadev		.EQU	diskstat
70
 2631
71
 2632  000010                	usbdev		.DS	2	; flag flash disk on usb bus #0
72
 2633                        					; <7>: device plugged and ready
73
 2634                        					; <6>: always 1
74
 2635                        					; <5>: device identification ok
75
 2636                        					; <4>: MBR loaded
76
 2637                        					; <3>: valid signature in MBR
77
 2638                        					; <2>: first partition found&active
78
 2639                        					; <1>:
79
 2640                        					; <0>: valid partition flag
80
 2641
81
 2642  000012                	diskmax		.DS	16	; disk max. sector's
82
 2643          000012        	atasec		.EQU	diskmax
83
 2644          00001A        	usbsec		.EQU	diskmax+8
84
 2645
85
 2646
86
 2647  000022                	atambr		.DS	8	; data for first partition found in mbr
87
 2648                        					; first 3 bytes for start sector of partition
88
 2649                        					; last byte for partition type
89
 2650  00002A                	usbmbr		.DS	8
90
 2651
91
 2652  000032                	ataprt		.DS	8	; total sec's of first partition
92
 2653  00003A                	usbprt		.DS	8	; total sec's of first partition
93
 2654
94
 2655
95
 2656  000042  00            	usb0ch		.DB	; usb0 (ch375/ch376) flag
96
 2657                        				; <7>: module on
97
 2658                        				; <6>: ch376 flag
98
 2659                        				; <5:0>: chip version
99
 2660
100
 2661  000043  00            	usb0st		.DB	; usb0 status
101
 2662                        				; <7>: usb0 host mode ok
102
 2663                        				; <6>: flash disk attached flag
103
 2664                        				; <5>: usb device attached
104
 2665
105
 2666  000044  00            	fdcdrv		.DB		; phisycal drive status (drive #0)
106
 2667                        					; <7>: disk format established in bit 0&1
107
 2668                        					; <6>: double step seek done
108
 2669                        					; <5>: trust format bit's (set after ok r/w)
109
 2670                        					; <4>: write protect bit (if disk in drive)
110
 2671                        					; <3>: don't care
111
 2672                        					; <2>: don't care
112
 2673                        					; <1>: HD disk if set else DD disk
113
 2674                        					; <0>: CBM format if set else IBM format
114
 2675
115
 2676  000045  00            	vdrive		.DB		; virtual drive status (ram disk, drive #1)
116
 2677                        					; <7>: disk format established in bit 0&1
117
 2678                        					; <6>: change disk simulation (after format)
118
 2679                        					; <5>: don't care
119
 2680                        					; <4>: write protect bit (under sw control)
120
 2681                        					; <3>: don't care
121
 2682                        					; <2>: don't care
122
 2683                        					; <1>: HD disk if set else DD disk
123
 2684                        					; <0>: CBM format if set else IBM format
124
 2685
125
  Tue Jul 17 11:00:18 2018                                                                                               Page    3
126
 
127
 
128
 
129
 
130
 2686  000046  00            	fdcctl		.DB		; fdc controller status
131
 2687                        					; <7>: drive is attached
132
 2688                        					; <6>: drive need recalibration (restore)
133
 2689                        					; <5>: FDC controller ok
134
 2690                        					; <4>: motor on
135
 2691                        					; <3>: dma is active
136
 2692                        					; <2>: dma chip ok (post routine)
137
 2693                        					; <1>: clock rate (1=HD,0=DD)
138
 2694                        					; <0>: disk ready
139
 2695
140
 2696  000047  00            	fdctrk		.DB		; fd: current seek track
141
 2697  000048  00            	fdcerr		.DB		; fd: last error code
142
 2698  000049  00            	ataerr		.DB		; ata: last error code
143
 2699  00004A  00            	ataxer		.DB		; ata: last extended error code
144
 2700
145
 2701  00004B  00            	CtrlBrk		.DB		; flag CTRL+BREAK (NMI)
146
 2702
147
 2703  00004C  0000          	MemTop		.DW		; top memoria RAM
148
 2704  00004E  00            			.DB		; banco top mem
149
 2705
150
 2706  00004F  00            	DflTxtIn	.DB		; device di default text input
151
 2707  000050  00            	DflTxtOut	.DB		; device di default text output
152
 2708
153
 2709  000051                	COPPtr		LP		; long pointer for COP decoding
154
 2710  000054  00            	COPIdx		.DB		; COP signature/index
155
 2711
156
 2712  000055  00            	BiosEnt		.DB		; flag accesso a bios setup
157
 2713
158
 2714                        	; variabili utilizzate da ACIA
159
 2715  000056                	spwrk		.DS	$30
160
 2716
161
 2717                        	; bios mem
162
 2718  000086  0000          	nsize		.DW	; dimensione blocco da allocare
163
 2719                        	;bsize		.DW	; dimensione vera blocco free
164
 2720  000088  0000          	splitsz		.DW	; dimensione blocco splittato
165
 2721  00008A  0000          	bfree		.DW	; puntatore blocco free
166
 2722  00008C  0000          	hdrptr		.DW	; puntatore header heap
167
 2723
168
 2724  00008E  0000          	pbrklv		.DW	; current break level of current process
169
 2725  000090  0000          	pbrkmin		.DW	; minimum breal level of current process
170
 2726  000092  0000          	pbrkmax		.DW	; maximum breal level of current process
171
 2727  000094
172
 2728                        	; bios temp. work area
173
 2729  000094                	bwrktmp		.DS	$28
174
 2730
175
 2731  0000BC  00            	coptmp		.DB	; temp. used while cop
176
 2732
177
 2733  0000BD  00            	tstser		.DB	; check ser/usb test board post
178
 2734                        				; <7>: VIA2 ok
179
 2735                        				; <6>: PICRAM ok
180
 2736                        				; <1>: UART 16C550 ok
181
 2737                        				; <0>: R65C51 ok
182
 2738
183
 2739
184
 2740                        	;crc16		.DW
185
 2741
186
 2742  0000BD                		.RELATIVE
187
  Tue Jul 17 11:00:18 2018                                                                                               Page    4
188
 
189
 
190
 
191
 
192
 2743
193
 2744                        		.ENDS
194
 2745
195
 2746          [01]          	.IFDEF		_ACIA_INC_
196
 2747                        		.INCLUDE INC\SP.INC
197
 2748          [00]          	.ENDIF
198
 2749
199
 2758                        	.LIST on
200
 2759                        	;---------------------------------------------------------------------------
201
 2760                        	; Logical Drive Table (LDT) -- page 0 offset's
202
 2761                        	;---------------------------------------------------------------------------
203
 2762
204
 2763  F8FFB1                	 STRUCT		LDT
205
 2764                        	_LDT	.SECTION page0,common,ref_only,offset 0	;LDT Struct
206
 2765                        			;.ABSOLUTE
207
 2766                        			;.ORG	0
208
 2767                        		.MNLIST
209
 2768  000000  00            	ldt_fg1		.DB		; logical volume flag's
210
 2769                        					; <7>: device ready (fdc drive or ata device)
211
 2770                        					; <6>: if=1->HD/CF else->FD
212
 2771                        					; <1:0>: phisycal device number
213
 2772
214
 2773  000001  00            	ldt_fg2		.DB		; <7>: valid volume (fat volume or cbm disk)
215
 2774                        					; <6>: if=1->FAT else->CBM (FD only)
216
 2775                        					; <5>: disk format checked
217
 2776                        					; <1:0>: disk format (fdc only)
218
 2777
219
 2778  000002  0000          	ldt_root	.DW		; lba of root dir
220
 2779  000004  0000          	ldt_fat1	.DW		; lba of fat1 table
221
 2780  000006  0000          	ldt_fat2	.DW		; lba of fat2 table
222
 2781  000008  0000          	ldt_cls		.DW		; lba of first data cluster
223
 2782  00000A  0000          	ldt_max		.DW		; max usable cluster + 1
224
 2783  00000C  0000          	ldt_rent	.DW		; root dir. max. entries
225
 2784  00000E  0000          	ldt_cent	.DW		; max. entries in dir. cluster
226
 2785  000010  0000          	ldt_eoc		.DW		; end of cluster chain marker
227
 2786  000012  0000          	ldt_free	.DW		; count of free cluster's
228
 2787  000014  0000          	ldt_nxt		.DW		; next free cluster
229
 2788  000016  0000          	ldt_fsiz	.DW		; fat table size
230
 2789
231
 2790  000018  00            	ldt_csiz	.DB		; cluster size (1,2,4,8,16,32,64)
232
 2791  000019  00            	ldt_cshf	.DB		; cluster shift (0,1,2,3,4,5,6)
233
 2792  00001A  00            	ldt_rsiz	.DB		; root dir. size (sector's)
234
 2793  00001B  00            	ldt_mcls	.DB		; mask for clust. module: 00,01,03,07,0F,1F,3F
235
 2794  00001C  0000          	ldt_cdlp	.DW		; current working dir list pointer
236
 2795  00001E  0000          	ldt_cdcls	.DW		; current working dir start cluster
237
 2796  000020  00            	ldt_cdlvl	.DB		; current working dir level count
238
 2797
239
 2798  000021  00            	ldt_ptype	.DB
240
 2799  000022  0000 0000     	ldt_pstart	.LWORD
241
 2800  000026  0000 0000     	ldt_psize	.LWORD
242
 2801
243
 2802          000022        	ldt_fp		.EQU	ldt_pstart	; fat table buffer long pointer
244
 2803          000025        	ldt_fbuf	.EQU	ldt_pstart+3		; fat table: x-mem base bank/dma buffer
245
 2804
246
 2805          000026        	ldt_pbr		.EQU	ldt_psize		; long pointer to PBR cache buffer
247
 2806          000029        	ldt_fmt		.EQU	ldt_psize+3
248
 2807
249
  Tue Jul 17 11:00:18 2018                                                                                               Page    5
250
 
251
 
252
 
253
 
254
 2808  00002A                	 ESTRUCT	LDT
255
 2809  00002A                	LDTSIZE	.DS	0
256
 2810                        			;.RELATIVE
257
 2811                        			.ENDS
258
 2812                        		.MNLIST
259
 2813
260
 2814          [00]          	.ENDIF
261
 2815
262
 2816  F8FFB1
263
 2817                        	.LIST on
264
 2818
265
 2819                        	; page 0 local var's (declared in bios temp. work area)
266
 2820                        	_P0BTMP:	.SECTION page0, ref_only, offset bwrktmp	; DP Tmp. BIOS
267
 2821          000094        	USB0TMP_START	.EQU	$
268
 2822  000094  00            	usbtmp		.DB
269
 2823  000095  00            	nretry		.DB
270
 2824  000096  00            	seccnt		.DB
271
 2825  000097  00            	pktcnt		.DB
272
 2826  000098                	lba		.DS	4
273
 2827  00009C  0000          	bufndx		.DW
274
 2828  00009E                	bufp		LP
275
 2829  0000A1                	tlp		LP
276
 2830  0000A4  0000          	fatsize		.DW
277
 2831  0000A6  0000          	wseccnt		.DW
278
 2832  0000A8  0000          	freecnt		.DW
279
 2833  0000AA  0000          	nxtfree		.DW
280
 2834  0000AC  0000          	cluster		.DW
281
 2835  0000AE  0000          	maxcls		.DW
282
 2836  0000B0  00            	clssiz		.DB
283
 2837  0000B1  00            	sec256		.DB
284
 2838          0000A4        	usbbuf		.EQU	fatsize
285
 2839
286
 2840                        		.EXTERN PAGE0 ldt4
287
 2841
288
 2842          00001E        	USB0TMP_SIZ	.EQU	($-USB0TMP_START)
289
 2843                        		.ENDS
290
 2844
291
 2845                        	;---------------------------------------------------------------------------
292
 2846                        	; code segment -- bank $F8
293
 2847                        	;---------------------------------------------------------------------------
294
 2848
295
 2849                        		.CODEF8
296
 2850  F8B253
297
 2851                        		.LONGA	off
298
 2852                        		.LONGI	off
299
 2853
300
 2854                        	; called by ISR after plug flash disk
301
 2855  F8B253                	usbdskon:
302
 2856                        		.PUBLIC usbdskon
303
 2857
304
 2858  F8B253  A9 08         		lda	#CB2IFRB
305
 2859  F8B255  8D CE FD      		sta	!VIA3+VIAIER	; for now disable ch37x interrupt
306
 2860  F8B258  A9 0A         		lda	#10
307
 2861  F8B25A  85 95         		sta	nretry		; retries times
308
 2862  F8B25C  A9 40         		lda	#$40
309
 2863  F8B25E  04 43         		tsb	usb0st		; set bit <6>: plugged in
310
 2864  F8B260  24 42         		bit	usb0ch
311
  Tue Jul 17 11:00:18 2018                                                                                               Page    6
312
 
313
 
314
 
315
 
316
 2865  F8B262  50 03         		bvc	?ch5		; ch375
317
 2866  F8B264  4C F0 B2      		jmp	?ch6		; ch376
318
 2867  F8B267
319
 2868                        		; ch375: first of all send command CMD_DISK_INIT
320
 2869                        		;
321
 2870  F8B267  20 32 B7      	?ch5:	jsr	delay10ms	; delay
322
 2871  F8B26A  A9 51         		lda	#CMD_DISK_INIT	; init usb disk on ch375
323
 2872  F8B26C  20 0A B4      		jsr	cmdwait
324
 2873  F8B26F  90 0F         		bcc	?nxt
325
 2874  F8B271  24 43         		bit	usb0st
326
 2875  F8B273  50 74         		bvc	?off		; disconnected
327
 2876  F8B275  A5 43         		lda	usb0st
328
 2877  F8B277  4A            		lsr	a
329
 2878  F8B278  90 68         		bcc	?nod		; no flash disk
330
 2879  F8B27A  C6 95         		dec	nretry
331
 2880  F8B27C  D0 E9         		bne	?ch5		; try again
332
 2881  F8B27E  80 62         		bra	?nod		; no chances
333
 2882  F8B280  A9 00         	?nxt:	lda	#0
334
 2883  F8B282  85 95         		sta	nretry
335
 2884  F8B284  20 32 B7      	?ch51:	jsr	delay10ms
336
 2885  F8B287  A9 53         		lda	#CMD_DISK_SIZE	; get total sectors & sector size
337
 2886  F8B289  20 0A B4      		jsr	cmdwait
338
 2887  F8B28C  90 0F         		bcc	?nxt2
339
 2888  F8B28E  24 43         		bit	usb0st
340
 2889  F8B290  50 57         		bvc	?off		; disconnected
341
 2890  F8B292  A5 43         		lda	usb0st
342
 2891  F8B294  4A            		lsr	a
343
 2892  F8B295  90 4B         		bcc	?nod		; no flash disk
344
 2893  F8B297  C6 95         	?dec:	dec	nretry
345
 2894  F8B299  D0 E9         		bne	?ch51		; try again
346
 2895  F8B29B  F0 45         		beq	?nod		; no chances
347
 2896  F8B29D  A9 28         	?nxt2:	lda	#CMD_RD_USB_DATA
348
 2897  F8B29F  8D D1 FD      		sta	!usb0cmd	; read 8 bytes
349
 2898  F8B2A2  EA            		nop
350
 2899  F8B2A3  EA            		nop
351
 2900  F8B2A4  EA            		nop
352
 2901  F8B2A5  EA            		nop
353
 2902
354
 2903                        		; expect 8 bytes: 32 bit for total sectors...
355
 2904                        		; followed by 32 bit for sector size
356
 2905
357
 2906  F8B2A6  AD D0 FD      		lda	!usb0dat
358
 2907  F8B2A9  C9 08         		cmp	#$08
359
 2908  F8B2AB  D0 EA         		bne	?dec		; retry
360
 2909  F8B2AD
361
 2910                        		; data are in big endian, so get in reverse order
362
 2911  F8B2AD  A2 07         		ldx	#7
363
 2912  F8B2AF  AD D0 FD      	?lp1:	lda	!usb0dat
364
 2913  F8B2B2  95 A4         		sta	usbbuf,x
365
 2914  F8B2B4  CA            		dex
366
 2915  F8B2B5  10 F8         		bpl	?lp1
367
 2916  F8B2B7  A5 A5         		lda	usbbuf+1
368
 2917  F8B2B9  C9 02         		cmp	#$02		; just 512 bytes per sec.
369
 2918  F8B2BB  D0 25         		bne	?nod		; unsupported sector size
370
 2919  F8B2BD  A9 0B         		lda	#CMD_PREFIX	; set packet size per sector
371
 2920  F8B2BF  8D D1 FD      		sta	!usb0cmd
372
 2921  F8B2C2  EA            		nop
373
  Tue Jul 17 11:00:18 2018                                                                                               Page    7
374
 
375
 
376
 
377
 
378
 2922  F8B2C3  EA            		nop
379
 2923  F8B2C4  EA            		nop
380
 2924  F8B2C5  A9 39         		lda	#PFX_SET_PKT_P_SEC
381
 2925  F8B2C7  8D D0 FD      		sta	!usb0dat
382
 2926  F8B2CA  EA            		nop
383
 2927  F8B2CB  A9 08         		lda	#$08		; one sector = 8 packets (1 pack = 64 bytes)
384
 2928  F8B2CD  8D D0 FD      		sta	!usb0dat
385
 2929  F8B2D0  A5 A8         		lda	usbbuf+4
386
 2930  F8B2D2  85 1A         		sta	usbsec
387
 2931  F8B2D4  A5 A9         		lda	usbbuf+5
388
 2932  F8B2D6  85 1B         		sta	usbsec+1
389
 2933  F8B2D8  A5 AA         		lda	usbbuf+6
390
 2934  F8B2DA  85 1C         		sta	usbsec+2
391
 2935  F8B2DC  A5 AB         		lda	usbbuf+7
392
 2936  F8B2DE  85 1D         		sta	usbsec+3
393
 2937  F8B2E0  80 5F         		bra	?dev
394
 2938
395
 2939  F8B2E2  A9 20         	?nod:	lda	#$20
396
 2940  F8B2E4  04 43         		tsb	usb0st		; unknow device plugged
397
 2941  F8B2E6  4C 76 B3      		jmp	?end
398
 2942  F8B2E9
399
 2943  F8B2E9  A9 7F         	?off:	lda	#$7F
400
 2944  F8B2EB  14 43         		trb	usb0st		; device unplugged
401
 2945  F8B2ED  4C 76 B3      		jmp	?end
402
 2946
403
 2947                        		; handle flash disk plug on ch376 chip
404
 2948  F8B2F0  20 32 B7      	?ch6:	jsr	delay10ms	; delay
405
 2949  F8B2F3  A9 31         		lda	#CMD_DISK_MOUNT	; try to mount flash disk
406
 2950  F8B2F5  20 0A B4      		jsr	cmdwait
407
 2951  F8B2F8  90 0F         		bcc	?nxt3
408
 2952  F8B2FA  24 43         		bit	usb0st
409
 2953  F8B2FC  50 EB         		bvc	?off		; disconnected
410
 2954  F8B2FE  A5 43         		lda	usb0st
411
 2955  F8B300  4A            		lsr	a
412
 2956  F8B301  90 DF         		bcc	?nod		; no flash disk
413
 2957  F8B303  C6 95         		dec	nretry
414
 2958  F8B305  F0 DB         		beq	?nod		; no chances
415
 2959  F8B307  D0 E7         		bne	?ch6		; try again
416
 2960  F8B309  64 95         	?nxt3:	stz	nretry
417
 2961  F8B30B  20 32 B7      	?nxt31:	jsr	delay10ms	; delay
418
 2962  F8B30E  A9 3E         		lda	#CMD_DISK_CAPACITY
419
 2963  F8B310  20 0A B4      		jsr	cmdwait
420
 2964  F8B313  90 0F         		bcc	?nxt4
421
 2965  F8B315  24 43         		bit	usb0st
422
 2966  F8B317  50 D0         		bvc	?off		; disconnected
423
 2967  F8B319  A5 43         		lda	usb0st
424
 2968  F8B31B  4A            		lsr	a
425
 2969  F8B31C  90 C4         		bcc	?nod		; no flash disk
426
 2970  F8B31E  C6 95         	?dec1:	dec	nretry
427
 2971  F8B320  F0 C0         		beq	?nod		; no chances
428
 2972  F8B322  D0 E7         		bne	?nxt31		; try again
429
 2973  F8B324  A9 28         	?nxt4:	lda	#CMD_RD_USB_DATA
430
 2974  F8B326  8D D1 FD      		sta	!usb0cmd	; expect 4 bytes
431
 2975  F8B329  EA            		nop
432
 2976  F8B32A  EA            		nop
433
 2977  F8B32B  EA            		nop
434
 2978  F8B32C  EA            		nop
435
  Tue Jul 17 11:00:18 2018                                                                                               Page    8
436
 
437
 
438
 
439
 
440
 2979  F8B32D  AD D0 FD      		lda	!usb0dat
441
 2980  F8B330  C9 04         		cmp	#$04
442
 2981  F8B332  D0 EA         		bne	?dec1		; retry
443
 2982  F8B334  A0 04         		ldy	#4
444
 2983  F8B336  A2 00         		ldx	#0
445
 2984  F8B338  AD D0 FD      	?lp2:	lda	!usb0dat
446
 2985  F8B33B  95 1A         		sta	usbsec,x
447
 2986  F8B33D  E8            		inx
448
 2987  F8B33E  88            		dey
449
 2988  F8B33F  D0 F7         		bne	?lp2
450
 2989
451
 2990  F8B341  A9 58         	?dev:	lda	#CMD_DISK_INQUIRY
452
 2991  F8B343  20 0A B4      		jsr	cmdwait
453
 2992  F8B346  90 06         		bcc	?dev1
454
 2993  F8B348  24 43         		bit	usb0st
455
 2994  F8B34A  50 9D         		bvc	?off		; disconnected
456
 2995  F8B34C  80 94         		bra	?nod
457
 2996  F8B34E  20 E4 B3      	?dev1:	jsr	rddata
458
 2997  F8B351  8B            		phb
459
 2998  F8B352  A9 01         		lda	#^USBBUF
460
 2999  F8B354  48            		pha
461
 3000  F8B355  AB            		plb
462
 3001  F8B356  A2 FF         		ldx	#$FF
463
 3002  F8B358  E8            	?dev2:	inx
464
 3003  F8B359  BD C4 9D      		lda	!.LOW16.USBBUF+8,x
465
 3004  F8B35C  C9 20         		cmp	#' '		; skip beginning blanks
466
 3005  F8B35E  F0 F8         		beq	?dev2
467
 3006  F8B360  A0 00         		ldy	#0
468
 3007  F8B362  BD C4 9D      	?dev3:	lda	!.LOW16.USBBUF+8,x
469
 3008  F8B365  99 80 9D      		sta	USB0STR,y
470
 3009  F8B368  F0 04         		beq	?dev4
471
 3010  F8B36A  E8            		inx
472
 3011  F8B36B  C8            		iny
473
 3012  F8B36C  80 F4         		bra	?dev3
474
 3013  F8B36E  AB            	?dev4:	plb
475
 3014  F8B36F  A9 E0         		lda	#$E0
476
 3015  F8B371  85 10         		sta	usbdev
477
 3016  F8B373
478
 3017  F8B373  20 81 B3      		jsr	getmbr
479
 3018
480
 3019  F8B376  A9 08         	?end:	lda	#CB2IFRB
481
 3020  F8B378  8D CD FD      		sta	!VIA3+VIAIFR
482
 3021  F8B37B  A9 88         		lda	#CB2IFRB+$80
483
 3022  F8B37D  8D CE FD      		sta	!VIA3+VIAIER	; re-enable ch37x interrupt
484
 3023  F8B380  6B            		rtl
485
 3024
486
 3025  F8B381                	getmbr:
487
 3026                        		.EXTERN chkumbr
488
 3027  F8B381
489
 3028  F8B381  A9 01         		lda	#1
490
 3029  F8B383  85 96         		sta	seccnt
491
 3030  F8B385  A9 00         		lda	#<MBR0USB
492
 3031  F8B387  85 9E         		sta	bufp
493
 3032  F8B389  A9 94         		lda	#>MBR0USB
494
 3033  F8B38B  85 9F         		sta	bufp+1
495
 3034  F8B38D  A9 01         		lda	#^MBR0USB
496
 3035  F8B38F  85 A0         		sta	bufp+2
497
  Tue Jul 17 11:00:18 2018                                                                                               Page    9
498
 
499
 
500
 
501
 
502
 3036  F8B391  64 98         		stz	lba
503
 3037  F8B393  64 99         		stz	lba+1
504
 3038  F8B395  64 9A         		stz	lba+2
505
 3039  F8B397  64 9B         		stz	lba+3
506
 3040  F8B399  20 2D B5      		jsr	readsec
507
 3041  F8B39C  B0 35         		bcs	?end		; error
508
 3042  F8B39E  A2 02         		ldx	#2		; drive #2
509
 3043  F8B3A0  20 5F 90      		jsr	chkumbr		; check mbr
510
 3044  F8B3A3  B0 2E         		bcs	?end		; error
511
 3045  F8B3A5  A5 10         		lda	usbdev
512
 3046  F8B3A7  C9 FD         		cmp	#$FD
513
 3047  F8B3A9  38            		sec
514
 3048  F8B3AA  D0 27         		bne	?end
515
 3049  F8B3AC  A9 01         		lda	#1
516
 3050  F8B3AE  85 96         		sta	seccnt
517
 3051  F8B3B0  A9 00         		lda	#<PBR0USB
518
 3052  F8B3B2  85 9E         		sta	bufp
519
 3053  F8B3B4  A9 96         		lda	#>PBR0USB
520
 3054  F8B3B6  85 9F         		sta	bufp+1
521
 3055  F8B3B8  A9 01         		lda	#^PBR0USB
522
 3056  F8B3BA  85 A0         		sta	bufp+2
523
 3057  F8B3BC  A5 2A         		lda	usbmbr
524
 3058  F8B3BE  85 98         		sta	lba
525
 3059  F8B3C0  A5 2B         		lda	usbmbr+1
526
 3060  F8B3C2  85 99         		sta	lba+1
527
 3061  F8B3C4  A5 2C         		lda	usbmbr+2
528
 3062  F8B3C6  85 9A         		sta	lba+2
529
 3063  F8B3C8  64 9B         		stz	lba+3		; FAT16 only!!
530
 3064  F8B3CA  20 2D B5      		jsr	readsec
531
 3065  F8B3CD  B0 04         		bcs	?end
532
 3066  F8B3CF  A9 02         		lda	#$02
533
 3067  F8B3D1  04 10         		tsb	usbdev		; pbr ok
534
 3068  F8B3D3
535
 3069  F8B3D3  08            	?end:	php
536
 3070  F8B3D4  A5 55         		lda	BiosEnt
537
 3071  F8B3D6  4A            		lsr	a
538
 3072  F8B3D7  B0 09         		bcs	?done		; boot phase
539
 3073  F8B3D9                		TXT_CR
540
 3074  F8B3D9                		TXTPRCHAR
541
 3075                        		.MLIST
542
 3076  F8B3D9  02 08         		cop	$08
543
 3077                        		.MNLIST
544
 3078  F8B3DB  0D            		.DB	$0D
545
 3079                        		.MNLIST
546
 3080  F8B3DC  20 47 B6      		jsr	showusb0
547
 3081  F8B3DF  20 D1 B6      		jsr	shusb0fat
548
 3082  F8B3E2  28            	?done:	plp
549
 3083  F8B3E3  60            		rts
550
 3084  F8B3E4
551
 3085                        	; read block data
552
 3086  F8B3E4                	rddata:
553
 3087  F8B3E4  A9 28         		lda	#CMD_RD_USB_DATA
554
 3088  F8B3E6  8D D1 FD      		sta	!usb0cmd
555
 3089  F8B3E9  EA            		nop
556
 3090  F8B3EA  EA            		nop
557
 3091  F8B3EB  EA            		nop
558
 3092  F8B3EC  EA            		nop
559
  Tue Jul 17 11:00:18 2018                                                                                               Page   10
560
 
561
 
562
 
563
 
564
 3093  F8B3ED  AD D0 FD      		lda	!usb0dat
565
 3094  F8B3F0  F0 17         		beq	?end
566
 3095  F8B3F2  A8            		tay
567
 3096  F8B3F3  A2 00         		ldx	#0
568
 3097  F8B3F5  84 94         		sty	usbtmp
569
 3098  F8B3F7  AD D0 FD      	?lp:	lda	!usb0dat
570
 3099  F8B3FA  9F BC 9D 01   		sta	>USBBUF,x
571
 3100  F8B3FE  E8            		inx
572
 3101  F8B3FF  88            		dey
573
 3102  F8B400  D0 F5         		bne	?lp
574
 3103  F8B402  98            		tya
575
 3104  F8B403  9F BC 9D 01   		sta	>USBBUF,x
576
 3105  F8B407  A5 94         		lda	usbtmp
577
 3106  F8B409  60            	?end:	rts
578
 3107
579
 3108                        	; send command and wait interrupt
580
 3109  F8B40A                	cmdwait:
581
 3110  F8B40A  8D D1 FD      		sta	!usb0cmd
582
 3111  F8B40D  A9 01         		lda	#$01
583
 3112  F8B40F  14 43         		trb	usb0st		; clear retry flag: bit <0>
584
 3113  F8B411  A9 08         	?wi:	lda	#CB2IFRB
585
 3114  F8B413  2C CD FD      		bit	!VIA3+VIAIFR
586
 3115  F8B416  F0 F9         		beq	?wi		; wait interrupt
587
 3116  F8B418  8D CD FD      		sta	!VIA3+VIAIFR	; clear flag
588
 3117  F8B41B  A9 22         		lda	#CMD_GET_STATUS
589
 3118  F8B41D  8D D1 FD      		sta	!usb0cmd
590
 3119  F8B420  EA            		nop			; 2uS
591
 3120  F8B421  EA            		nop
592
 3121  F8B422  EA            		nop
593
 3122  F8B423  EA            		nop
594
 3123  F8B424  AD D0 FD      		lda	!usb0dat	; read interrupt code
595
 3124  F8B427  C9 14         		cmp	#USB_INT_SUCCESS
596
 3125  F8B429  F0 48         		beq	?ok
597
 3126  F8B42B  C9 16         		cmp	#USB_INT_DISCONNECT
598
 3127  F8B42D  F0 46         		beq	?off		; disconnected
599
 3128  F8B42F  24 42         		bit	usb0ch
600
 3129  F8B431  50 04         		bvc	?chk		; ch375: skip next test
601
 3130  F8B433  C9 82         		cmp	#ERR_DISK_DISCON
602
 3131  F8B435  F0 3E         		beq	?off		; disconnected (ch376 only)
603
 3132  F8B437  C9 1F         	?chk:	cmp	#USB_INT_DISK_ERR
604
 3133  F8B439  D0 3E         		bne	?nod		; no flash disk
605
 3134  F8B43B  24 42         		bit	usb0ch
606
 3135  F8B43D  50 0D         		bvc	?ch5		; ch375 handle in different way
607
 3136  F8B43F  A9 2B         		lda	#VAR_DISK_STATUS
608
 3137  F8B441  20 7B B4      		jsr	readvar8	; read internal status ch376
609
 3138  F8B444  F0 33         		beq	?nod		; unknow device
610
 3139  F8B446  C9 03         		cmp	#DEF_DISK_MOUNTED
611
 3140  F8B448  90 2F         		bcc	?nod		; unknow device
612
 3141  F8B44A  80 21         		bra	?ret		; set retry flag
613
 3142  F8B44C  A9 5A         	?ch5:	lda	#CMD_DISK_R_SENSE
614
 3143  F8B44E  8D D1 FD      		sta	!usb0cmd
615
 3144  F8B451  A9 08         	?wi2:	lda	#CB2IFRB
616
 3145  F8B453  2C CD FD      		bit	!VIA3+VIAIFR
617
 3146  F8B456  F0 F9         		beq	?wi2		; wait interrupt
618
 3147  F8B458  8D CD FD      		sta	!VIA3+VIAIFR	; clear flag
619
 3148  F8B45B
620
 3149  F8B45B  A9 22         		lda	#CMD_GET_STATUS
621
  Tue Jul 17 11:00:18 2018                                                                                               Page   11
622
 
623
 
624
 
625
 
626
 3150  F8B45D  8D D1 FD      		sta	!usb0cmd
627
 3151  F8B460  EA            		nop			; 2uS
628
 3152  F8B461  EA            		nop
629
 3153  F8B462  EA            		nop
630
 3154  F8B463  EA            		nop
631
 3155  F8B464  AD D0 FD      		lda	!usb0dat	; read interrupt code
632
 3156  F8B467  85 FD         		sta	$FD
633
 3157
634
 3158  F8B469  C9 14         		cmp	#USB_INT_SUCCESS
635
 3159  F8B46B  D0 0C         		bne	?nod		; unknow device
636
 3160  F8B46D  A9 01         	?ret:	lda	#$01
637
 3161  F8B46F  04 43         		tsb	usb0st		; set retry flag
638
 3162  F8B471  38            		sec
639
 3163  F8B472  60            		rts
640
 3164  F8B473  18            	?ok:	clc
641
 3165  F8B474  60            		rts
642
 3166  F8B475  A9 40         	?off:	lda	#$40
643
 3167  F8B477  14 43         		trb	usb0st		; clear bit <6>
644
 3168  F8B479  38            	?nod:	sec
645
 3169  F8B47A  60            		rts
646
 3170  F8B47B
647
 3171                        	; ch376 specific
648
 3172                        	; A = var 8
649
 3173                        	; return A = var. value
650
 3174  F8B47B                	readvar8:
651
 3175  F8B47B  EB            		xba
652
 3176  F8B47C  A9 0A         		lda	#CMD_READ_VAR8
653
 3177  F8B47E  8D D1 FD      		sta	!usb0cmd
654
 3178  F8B481  EA            		nop
655
 3179  F8B482  EA            		nop
656
 3180  F8B483  EA            		nop
657
 3181  F8B484  EB            		xba
658
 3182  F8B485  8D D0 FD      		sta	!usb0dat
659
 3183  F8B488  EA            		nop
660
 3184  F8B489  EA            		nop
661
 3185  F8B48A  EA            		nop
662
 3186  F8B48B  EA            		nop
663
 3187  F8B48C  AD D0 FD      		lda	!usb0dat
664
 3188  F8B48F  60            		rts
665
 3189
666
 3190                        	; scan fat table of usb #0 device
667
 3191                        	; first 64K of dma buffer are reserved to cluster read/write
668
 3192                        	; scan fat table reading 64 sectors at time
669
 3193  F8B490                	scanufat:
670
 3194  F8B490  64 A1         		stz	tlp		; init dma buffer pointer
671
 3195  F8B492  64 A2         		stz	tlp+1
672
 3196  F8B494  A9 02         		lda	#DMABNK
673
 3197  F8B496  85 A3         		sta	tlp+2
674
 3198  F8B498  AD C0 40      		lda	!P0LDT+ldt4+ldt_csiz
675
 3199  F8B49B  85 B0         		sta	clssiz
676
 3200  F8B49D                		ACC16
677
 3201  F8B49D  C2 20         		rep	#PMFLAG
678
 3202                        		.LONGA	on
679
 3203                        		.MNLIST
680
 3204  F8B49F  AD AC 40      		lda	!P0LDT+ldt4+ldt_fat1
681
 3205  F8B4A2  85 98         		sta	lba		; start sector of fat 1 table
682
 3206  F8B4A4  64 9A         		stz	lba+2
683
  Tue Jul 17 11:00:18 2018                                                                                               Page   12
684
 
685
 
686
 
687
 
688
 3207  F8B4A6  64 A8         		stz	freecnt		; count of free clusters
689
 3208  F8B4A8  64 AA         		stz	nxtfree		; free next cluster
690
 3209  F8B4AA  64 AC         		stz	cluster		; cluster sequence
691
 3210  F8B4AC  AD B2 40      		lda	!P0LDT+ldt4+ldt_max
692
 3211  F8B4AF  85 AE         		sta	maxcls		; max. cluster number + 1
693
 3212  F8B4B1                		ACC08
694
 3213  F8B4B1  E2 20         		sep	#PMFLAG
695
 3214                        		.LONGA	off
696
 3215                        		.MNLIST
697
 3216  F8B4B3  A2 00         		ldx	#0
698
 3217  F8B4B5  AD BE 40      		lda	!P0LDT+ldt4+ldt_fsiz
699
 3218  F8B4B8  85 A4         		sta	fatsize		; store fat table size
700
 3219  F8B4BA  D0 01         		bne	?st		; less than 256 sectors
701
 3220  F8B4BC  E8            		inx			; fat size = 256 sectors
702
 3221  F8B4BD  86 A5         	?st:	stx	fatsize+1
703
 3222  F8B4BF  64 A7         		stz	wseccnt+1
704
 3223  F8B4C1
705
 3224  F8B4C1                		ACC16
706
 3225  F8B4C1  C2 20         		rep	#PMFLAG
707
 3226                        		.LONGA	on
708
 3227                        		.MNLIST
709
 3228  F8B4C3  A5 A1         	?lp:	lda	tlp
710
 3229  F8B4C5  85 9E         		sta	bufp
711
 3230  F8B4C7  A6 A3         		ldx	tlp+2
712
 3231  F8B4C9  86 A0         		stx	bufp+2
713
 3232  F8B4CB  A5 A4         		lda	fatsize
714
 3233  F8B4CD  C9 40 00      		cmp	#64
715
 3234  F8B4D0  90 03         		bcc	?less
716
 3235  F8B4D2  A9 40 00      		lda	#64
717
 3236  F8B4D5                	?less:	ACC08
718
 3237  F8B4D5  E2 20         		sep	#PMFLAG
719
 3238                        		.LONGA	off
720
 3239                        		.MNLIST
721
 3240  F8B4D7  85 96         		sta	seccnt		; sectors count #
722
 3241  F8B4D9  85 A6         		sta	wseccnt
723
 3242  F8B4DB  20 2D B5      		jsr	readsec		; read fat
724
 3243  F8B4DE  B0 3E         		bcs	?err		; some errors
725
 3244  F8B4E0  A0 00         		ldy	#0
726
 3245  F8B4E2                		CPU16
727
 3246  F8B4E2  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
728
 3247                        		.LONGA	on
729
 3248                        		.LONGI	on
730
 3249                        		.MNLIST
731
 3250  F8B4E4  A5 A6         		lda	wseccnt
732
 3251  F8B4E6  EB            		xba
733
 3252  F8B4E7  0A            		asl	a		; bytes count #
734
 3253  F8B4E8  85 9C         		sta	bufndx
735
 3254  F8B4EA  A6 AC         		ldx	cluster
736
 3255  F8B4EC  B7 A1         	?lpf:	lda	[tlp],y		; scan fat table
737
 3256  F8B4EE  D0 08         		bne	?nxt		; not free
738
 3257  F8B4F0  E6 A8         		inc	freecnt		; update free cluster's count
739
 3258  F8B4F2  A5 AA         		lda	nxtfree		; already set?
740
 3259  F8B4F4  D0 02         		bne	?nxt		; yes
741
 3260  F8B4F6  86 AA         		stx	nxtfree		; set first free cluster
742
 3261  F8B4F8  E8            	?nxt:	inx			; update cluster number
743
 3262  F8B4F9  C8            		iny
744
 3263  F8B4FA  C8            		iny
745
  Tue Jul 17 11:00:18 2018                                                                                               Page   13
746
 
747
 
748
 
749
 
750
 3264  F8B4FB  E4 AE         		cpx	maxcls		; end of table?
751
 3265  F8B4FD  B0 1C         		bcs	?done		; yes
752
 3266  F8B4FF  C4 9C         		cpy	bufndx		; end of partial table?
753
 3267  F8B501  90 E9         		bcc	?lpf		; no
754
 3268  F8B503  86 AC         		stx	cluster		; save current cluster number
755
 3269  F8B505                		INDEX08
756
 3270  F8B505  E2 10         		sep	#PXFLAG
757
 3271                        		.LONGI	off
758
 3272                        		.MNLIST
759
 3273  F8B507  A5 A4         		lda	fatsize
760
 3274  F8B509  38            		sec
761
 3275  F8B50A  E5 A6         		sbc	wseccnt
762
 3276  F8B50C  F0 0D         		beq	?done		; end
763
 3277  F8B50E  85 A4         		sta	fatsize
764
 3278  F8B510  18            		clc
765
 3279  F8B511  A5 98         		lda	lba
766
 3280  F8B513  65 A6         		adc	wseccnt
767
 3281  F8B515  90 AC         		bcc	?lp
768
 3282  F8B517  E6 9A         		inc	lba+2
769
 3283  F8B519  80 A8         		bra	?lp
770
 3284  F8B51B                	?done:	CPU08
771
 3285  F8B51B  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
772
 3286                        		.LONGA	off
773
 3287                        		.LONGI	off
774
 3288                        		.MNLIST
775
 3289  F8B51D  18            		clc
776
 3290  F8B51E                	?err:	ACC16
777
 3291  F8B51E  C2 20         		rep	#PMFLAG
778
 3292                        		.LONGA	on
779
 3293                        		.MNLIST
780
 3294  F8B520  A5 A8         		lda	freecnt
781
 3295  F8B522  8D BA 40      		sta	!P0LDT+ldt4+ldt_free
782
 3296  F8B525  A5 AA         		lda	nxtfree
783
 3297  F8B527  8D BC 40      		sta	!P0LDT+ldt4+ldt_nxt
784
 3298  F8B52A                		ACC08
785
 3299  F8B52A  E2 20         		sep	#PMFLAG
786
 3300                        		.LONGA	off
787
 3301                        		.MNLIST
788
 3302  F8B52C  60            		rts
789
 3303  F8B52D
790
 3304                        	; read sector(s)
791
 3305  F8B52D                	readsec:
792
 3306  F8B52D  A9 08         		lda	#CB2IFRB
793
 3307  F8B52F  8D CE FD      		sta	!VIA3+VIAIER	; disable ch37x interrupt
794
 3308  F8B532  A9 08         		lda	#CB2IFRB
795
 3309  F8B534  8D CD FD      		sta	!VIA3+VIAIFR	; clear flag
796
 3310  F8B537  A9 54         		lda	#CMD_DISK_READ	; start to read sector(s)
797
 3311  F8B539  8D D1 FD      		sta	!usb0cmd
798
 3312  F8B53C  EA            		nop
799
 3313  F8B53D  EA            		nop
800
 3314  F8B53E  64 B1         		stz	sec256
801
 3315  F8B540  A5 98         		lda	lba		; send starting lba
802
 3316  F8B542  8D D0 FD      		sta	!usb0dat
803
 3317  F8B545  EA            		nop
804
 3318  F8B546  A5 99         		lda	lba+1
805
 3319  F8B548  8D D0 FD      		sta	!usb0dat
806
 3320  F8B54B  EA            		nop
807
  Tue Jul 17 11:00:18 2018                                                                                               Page   14
808
 
809
 
810
 
811
 
812
 3321  F8B54C  A5 9A         		lda	lba+2
813
 3322  F8B54E  8D D0 FD      		sta	!usb0dat
814
 3323  F8B551  EA            		nop
815
 3324  F8B552  A5 9B         		lda	lba+3
816
 3325  F8B554  8D D0 FD      		sta	!usb0dat
817
 3326  F8B557  A5 96         		lda	seccnt		; sector(s) count #
818
 3327  F8B559  D0 05         		bne	?go
819
 3328  F8B55B  3A            		dec	a
820
 3329  F8B55C  85 B1         		sta	sec256
821
 3330  F8B55E  85 96         		sta	seccnt
822
 3331  F8B560  8D D0 FD      	?go:	sta	!usb0dat
823
 3332  F8B563
824
 3333  F8B563  64 9C         		stz	bufndx
825
 3334  F8B565  64 9D         		stz	bufndx+1
826
 3335  F8B567  A9 08         		lda	#$08		; 8 packets per sector
827
 3336  F8B569  85 97         		sta	pktcnt
828
 3337  F8B56B  80 0B         		bra	?wi
829
 3338  F8B56D
830
 3339  F8B56D  A9 08         	?sct:	lda	#$08		; 8 packets per sector
831
 3340  F8B56F  85 97         		sta	pktcnt
832
 3341  F8B571  A9 55         	?pkt:	lda	#CMD_DISK_RD_GO	; read next packet
833
 3342  F8B573  8D D1 FD      		sta	!usb0cmd
834
 3343  F8B576  EA            		nop
835
 3344  F8B577  EA            		nop
836
 3345  F8B578  20 30 B6      	?wi:	jsr	waitint		; wait ch interrupt
837
 3346  F8B57B  C9 1D         		cmp	#USB_INT_DISK_READ
838
 3347  F8B57D  D0 38         		bne	?done		; finish or error
839
 3348  F8B57F  A9 28         		lda	#CMD_RD_USB_DATA
840
 3349  F8B581  8D D1 FD      		sta	!usb0cmd	; read a packet (64 bytes)
841
 3350  F8B584  EA            		nop
842
 3351  F8B585  EA            		nop
843
 3352  F8B586  EA            		nop
844
 3353  F8B587  EA            		nop
845
 3354  F8B588  AE D0 FD      		ldx	!usb0dat
846
 3355  F8B58B  E0 40         		cpx	#$40
847
 3356  F8B58D  D0 65         		bne	?err
848
 3357  F8B58F
849
 3358  F8B58F                		INDEX16
850
 3359  F8B58F  C2 10         		rep	#PXFLAG
851
 3360                        		.LONGI	on
852
 3361                        		.MNLIST
853
 3362  F8B591  A4 9C         		ldy	bufndx		; current buffer index
854
 3363  F8B593  AD D0 FD      	?rdl:	lda	!usb0dat	; read & store loop
855
 3364  F8B596  97 9E         		sta	[bufp],y
856
 3365  F8B598  C8            		iny
857
 3366  F8B599  CA            		dex
858
 3367  F8B59A  D0 F7         		bne	?rdl
859
 3368  F8B59C  84 9C         		sty	bufndx
860
 3369  F8B59E                		INDEX08
861
 3370  F8B59E  E2 10         		sep	#PXFLAG
862
 3371                        		.LONGI	off
863
 3372                        		.MNLIST
864
 3373  F8B5A0  C6 97         		dec	pktcnt		; more packets to read?
865
 3374  F8B5A2  D0 CD         		bne	?pkt		; yes
866
 3375  F8B5A4                		ACC16CLC
867
 3376  F8B5A4  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
868
 3377                        		.LONGA	on
869
  Tue Jul 17 11:00:18 2018                                                                                               Page   15
870
 
871
 
872
 
873
 
874
 3378                        		.MNLIST
875
 3379  F8B5A6  A5 9F         		lda	bufp+1
876
 3380  F8B5A8  69 02 00      		adc	#$0002		; update: add 512
877
 3381  F8B5AB  85 9F         		sta	bufp+1
878
 3382  F8B5AD  64 9C         		stz	bufndx
879
 3383  F8B5AF                		ACC08
880
 3384  F8B5AF  E2 20         		sep	#PMFLAG
881
 3385                        		.LONGA	off
882
 3386                        		.MNLIST
883
 3387  F8B5B1  C6 96         		dec	seccnt
884
 3388  F8B5B3  D0 B8         		bne	?sct		; next sector if any
885
 3389  F8B5B5  80 BA         		bra	?pkt		; get last interrupt
886
 3390  F8B5B7
887
 3391  F8B5B7  C9 14         	?done:	cmp	#USB_INT_SUCCESS
888
 3392  F8B5B9  D0 24         		bne	?tst		; test error condition
889
 3393  F8B5BB  A5 97         		lda	pktcnt		; pktcnt & seccnt must be both zero
890
 3394  F8B5BD  05 96         		ora	seccnt
891
 3395  F8B5BF  D0 3C         		bne	?sec
892
 3396  F8B5C1  24 B1         		bit	sec256
893
 3397  F8B5C3  10 17         		bpl	?ok		; finish
894
 3398                        		; read one more sector
895
 3399  F8B5C5                		ACC16CLC
896
 3400  F8B5C5  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
897
 3401                        		.LONGA	on
898
 3402                        		.MNLIST
899
 3403  F8B5C7  A5 98         		lda	lba
900
 3404  F8B5C9  69 FF 00      		adc	#255
901
 3405  F8B5CC  85 98         		sta	lba
902
 3406  F8B5CE  A5 9A         		lda	lba+2
903
 3407  F8B5D0  69 00 00      		adc	#0
904
 3408  F8B5D3  85 9A         		sta	lba+2
905
 3409  F8B5D5                		ACC08
906
 3410  F8B5D5  E2 20         		sep	#PMFLAG
907
 3411                        		.LONGA	off
908
 3412                        		.MNLIST
909
 3413  F8B5D7  E6 96         		inc	seccnt
910
 3414  F8B5D9  4C 2D B5      		jmp	readsec
911
 3415  F8B5DC  18            	?ok:	clc
912
 3416  F8B5DD  80 1F         		bra	?end
913
 3417  F8B5DF  C9 16         	?tst:	cmp	#USB_INT_DISCONNECT
914
 3418
915
 3419  F8B5E1  85 FF         		sta	$ff
916
 3420  F8B5E3
917
 3421  F8B5E3  F0 14         		beq	?off		; device unplugged
918
 3422  F8B5E5  C9 17         		cmp	#USB_INT_BUF_OVER
919
 3423  F8B5E7  F0 0B         		beq	?err		; sense disk error
920
 3424  F8B5E9  C9 1F         		cmp	#USB_INT_DISK_ERR
921
 3425  F8B5EB  F0 07         		beq	?err
922
 3426  F8B5ED  20 09 B6      		jsr	dskrdy
923
 3427  F8B5F0  B0 07         		bcs	?off		; unplugged?
924
 3428  F8B5F2  80 09         		bra	?sec
925
 3429  F8B5F4  20 19 B6      	?err:	jsr	dskerr
926
 3430  F8B5F7  80 04         		bra	?sec
927
 3431  F8B5F9  A9 7F         	?off:	lda	#$7F
928
 3432  F8B5FB  14 43         		trb	usb0st
929
 3433  F8B5FD  38            	?sec:	sec			; error flag
930
 3434  F8B5FE  A9 08         	?end:	lda	#CB2IFRB	; clear CB2 flag
931
  Tue Jul 17 11:00:18 2018                                                                                               Page   16
932
 
933
 
934
 
935
 
936
 3435  F8B600  8D CD FD      		sta	!VIA3+VIAIFR
937
 3436  F8B603  A9 88         		lda	#CB2IFRB+$80
938
 3437  F8B605  8D CE FD      		sta	!VIA3+VIAIER	; re-enable ch37x interrupt
939
 3438  F8B608  60            		rts
940
 3439
941
 3440                        	; test disk ready
942
 3441  F8B609                	dskrdy:
943
 3442  F8B609  A9 59         		lda	#CMD_DISK_READY
944
 3443  F8B60B  8D D1 FD      		sta	!usb0cmd
945
 3444  F8B60E  EA            		nop
946
 3445  F8B60F  20 30 B6      		jsr	waitint
947
 3446  F8B612  C9 14         		cmp	#USB_INT_SUCCESS
948
 3447  F8B614  18            		clc
949
 3448  F8B615  F0 01         		beq	?end
950
 3449  F8B617  38            		sec
951
 3450  F8B618  60            	?end:	rts
952
 3451
953
 3452                        	; sensing disk error
954
 3453  F8B619                	dskerr:
955
 3454  F8B619  A9 5A         		lda	#CMD_DISK_R_SENSE
956
 3455  F8B61B  8D D1 FD      		sta	!usb0cmd
957
 3456  F8B61E  EA            		nop
958
 3457  F8B61F  20 30 B6      		jsr	waitint
959
 3458  F8B622  C9 14         		cmp	#USB_INT_SUCCESS
960
 3459  F8B624  F0 02         		beq	?get
961
 3460  F8B626  38            		sec			; error
962
 3461  F8B627  60            		rts
963
 3462  F8B628  20 60 B7      	?get:	jsr	delay5ms
964
 3463  F8B62B  20 E4 B3      		jsr	rddata		; get error string
965
 3464  F8B62E  18            		clc
966
 3465  F8B62F  60            		rts
967
 3466
968
 3467  F8B630                	waitint:
969
 3468  F8B630  A9 08         		lda	#CB2IFRB
970
 3469  F8B632  2C CD FD      		bit	!VIA3+VIAIFR
971
 3470  F8B635  F0 F9         		beq	waitint		; wait interrupt
972
 3471  F8B637  8D CD FD      		sta	!VIA3+VIAIFR	; clear flag
973
 3472  F8B63A  A9 22         		lda	#CMD_GET_STATUS
974
 3473  F8B63C  8D D1 FD      		sta	!usb0cmd
975
 3474  F8B63F  EA            		nop			; 2uS
976
 3475  F8B640  EA            		nop
977
 3476  F8B641  EA            		nop
978
 3477  F8B642  EA            		nop
979
 3478  F8B643  AD D0 FD      		lda	!usb0dat	; read interrupt code
980
 3479  F8B646  60            		rts
981
 3480
982
 3481  F8B647                	showusb0:
983
 3482                        		.PUBLIC showusb0
984
 3483
985
 3484  F8B647  24 43         		bit	usb0st
986
 3485  F8B649  50 5A         		bvc	?end		; no device plugged
987
 3486  F8B64B  24 10         		bit	usbdev
988
 3487  F8B64D  10 28         		bpl	?unkn		; unknow device
989
 3488  F8B64F                		ACC16CLC
990
 3489  F8B64F  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
991
 3490                        		.LONGA	on
992
 3491                        		.MNLIST
993
  Tue Jul 17 11:00:18 2018                                                                                               Page   17
994
 
995
 
996
 
997
 
998
 3492  F8B651  A5 1A         		lda	usbsec
999
 3493  F8B653  85 98         		sta	lba
1000
 3494  F8B655  A5 1C         		lda	usbsec+2
1001
 3495  F8B657  A2 0B         		ldx	#11		; divide by 2048 (11 shift)...
1002
 3496  F8B659  4A            	?shr:	lsr	a		; ... and get rounded size in Mb
1003
 3497  F8B65A  66 98         		ror	lba
1004
 3498  F8B65C  CA            		dex
1005
 3499  F8B65D  D0 FA         		bne	?shr
1006
 3500  F8B65F  85 9A         		sta	lba+2
1007
 3501  F8B661  48            		pha			; 2
1008
 3502  F8B662  A5 98         		lda	lba
1009
 3503  F8B664  48            		pha			; 2
1010
 3504  F8B665                		ACC08
1011
 3505  F8B665  E2 20         		sep	#PMFLAG
1012
 3506                        		.LONGA	off
1013
 3507                        		.MNLIST
1014
 3508  F8B667  A9 01         		lda	#^USB0STR	; bank that hold device string
1015
 3509  F8B669  48            		pha
1016
 3510  F8B66A  F4 80 9D      		pea	#USB0STR
1017
 3511  F8B66D  4B            		phk			; format string
1018
 3512  F8B66E  F4 A6 B6      		pea	#?fstr
1019
 3513  F8B671  A9 0B         		lda	#11
1020
 3514  F8B673  48            		pha
1021
 3515  F8B674                		BPRINTF
1022
 3516  F8B674  02 11         		cop	$11
1023
 3517                        		.MNLIST
1024
 3518  F8B676  60            		rts
1025
 3519  F8B677
1026
 3520  F8B677                	?unkn:	SCNPRINT
1027
 3521  F8B677  02 01         		cop	$01
1028
 3522                        		.MNLIST
1029
 3523  F8B679  75 73 62 20 20 		.DB	'usb   #0:  unknow device (not flash disk).', $0D, $00
1030
               20 23 30 3A 20
1031
               20 75 6E 6B 6E
1032
               6F 77 20 64 65
1033
               76 69 63 65 20
1034
               28 6E 6F 74 20
1035
               66 6C 61 73 68
1036
               20 64 69 73 6B
1037
               29 2E 0D 00
1038
 3524  F8B6A5  60            	?end:	rts
1039
 3525
1040
 3526  F8B6A6                	?fstr:
1041
 3527                        		;.DB	'usb   #0:  flash disk:   %-42.41s %,7u Mb', 13, 0
1042
 3528  F8B6A6  75 73 62 20 20 		.DB	'usb   #0:  usb drive E:  %-42.41s %,7u Mb', 13, 0
1043
               20 23 30 3A 20
1044
               20 75 73 62 20
1045
               64 72 69 76 65
1046
               20 45 3A 20 20
1047
               25 2D 34 32 2E
1048
               34 31 73 20 25
1049
               2C 37 75 20 4D
1050
               62 0D 00
1051
 3529
1052
 3530  F8B6D1                	shusb0fat:
1053
 3531                        		.PUBLIC shusb0fat
1054
 3532                        		.EXTERN lusbldt
1055
  Tue Jul 17 11:00:18 2018                                                                                               Page   18
1056
 
1057
 
1058
 
1059
 
1060
 3533
1061
 3534  F8B6D1  24 10         		bit	usbdev
1062
 3535  F8B6D3  10 24         		bpl	?end		; no disk device plugged
1063
 3536  F8B6D5  22 05 03 F9   		jsl	lusbldt
1064
 3537  F8B6D9  B0 1E         		bcs	?end
1065
 3538  F8B6DB  20 90 B4      		jsr	scanufat
1066
 3539  F8B6DE                		ACC16			; print summary
1067
 3540  F8B6DE  C2 20         		rep	#PMFLAG
1068
 3541                        		.LONGA	on
1069
 3542                        		.MNLIST
1070
 3543  F8B6E0  A5 AE         		lda	maxcls
1071
 3544  F8B6E2  3A            		dec	a
1072
 3545  F8B6E3  3A            		dec	a
1073
 3546  F8B6E4  85 AE         		sta	maxcls
1074
 3547  F8B6E6                		ACC08
1075
 3548  F8B6E6  E2 20         		sep	#PMFLAG
1076
 3549                        		.LONGA	off
1077
 3550                        		.MNLIST
1078
 3551  F8B6E8  A5 B0         		lda	clssiz
1079
 3552  F8B6EA  48            		pha
1080
 3553  F8B6EB  D4 A8         		pei	(freecnt)
1081
 3554  F8B6ED  D4 AE         		pei	(maxcls)
1082
 3555  F8B6EF  4B            		phk
1083
 3556  F8B6F0  F4 FA B6      		pea	#!?fstr
1084
 3557  F8B6F3  A9 09         		lda	#9
1085
 3558  F8B6F5  48            		pha
1086
 3559  F8B6F6                		BPRINTF
1087
 3560  F8B6F6  02 11         		cop	$11
1088
 3561                        		.MNLIST
1089
 3562  F8B6F8  18            		clc
1090
 3563  F8B6F9  60            	?end:	rts
1091
 3564
1092
 3565  F8B6FA  25 2C 68 75 20 	?fstr:	.DB	'%,hu cluster(s) (free: %,hu, 1 cluster=%bu sector(s)).', 13, 0
1093
               63 6C 75 73 74
1094
               65 72 28 73 29
1095
               20 28 66 72 65
1096
               65 3A 20 25 2C
1097
               68 75 2C 20 31
1098
               20 63 6C 75 73
1099
               74 65 72 3D 25
1100
               62 75 20 73 65
1101
               63 74 6F 72 28
1102
               73 29 29 2E 0D
1103
               00
1104
 3566
1105
 3567
1106
 3568          009C40        	T10MS	.EQU	(10 * 1000 * PHI2)
1107
 3569  F8B732                	delay10ms:
1108
 3570  F8B732  A9 20         		lda	#$20		; T2 count PHI2 pulses
1109
 3571  F8B734  1C 0B FD      		trb	VIA0+VIAACR
1110
 3572  F8B737  A9 40         		lda	#<T10MS
1111
 3573  F8B739  8D 08 FD      		sta	!VIA0+VIAT2CL
1112
 3574  F8B73C  A9 9C         		lda	#>T10MS
1113
 3575  F8B73E  8D 09 FD      		sta	!VIA0+VIAT2CH
1114
 3576  F8B741  AD 0D FD      	?wl:	lda	!VIA0+VIAIFR
1115
 3577  F8B744  89 20         		bit	#T2IFRB
1116
 3578  F8B746  F0 F9         		beq	?wl
1117
  Tue Jul 17 11:00:18 2018                                                                                               Page   19
1118
 
1119
 
1120
 
1121
 
1122
 3579  F8B748  60            		rts
1123
 3580
1124
 3581          000FA0        	T01MS	.EQU	(1000 * PHI2)
1125
 3582  F8B749                	delay1ms:
1126
 3583  F8B749  A9 20         		lda	#$20		; T2 count PHI2 pulses
1127
 3584  F8B74B  1C 0B FD      		trb	VIA0+VIAACR
1128
 3585  F8B74E  A9 A0         		lda	#<T01MS
1129
 3586  F8B750  8D 08 FD      		sta	!VIA0+VIAT2CL
1130
 3587  F8B753  A9 0F         		lda	#>T01MS
1131
 3588  F8B755  8D 09 FD      		sta	!VIA0+VIAT2CH
1132
 3589  F8B758  AD 0D FD      	?wl:	lda	!VIA0+VIAIFR
1133
 3590  F8B75B  89 20         		bit	#T2IFRB
1134
 3591  F8B75D  F0 F9         		beq	?wl
1135
 3592  F8B75F  60            		rts
1136
 3593
1137
 3594          004E20        	T05MS	.EQU	(5000 * PHI2)
1138
 3595  F8B760                	delay5ms:
1139
 3596  F8B760  A9 20         		lda	#$20		; T2 count PHI2 pulses
1140
 3597  F8B762  1C 0B FD      		trb	VIA0+VIAACR
1141
 3598  F8B765  A9 20         		lda	#<T05MS
1142
 3599  F8B767  8D 08 FD      		sta	!VIA0+VIAT2CL
1143
 3600  F8B76A  A9 4E         		lda	#>T05MS
1144
 3601  F8B76C  8D 09 FD      		sta	!VIA0+VIAT2CH
1145
 3602  F8B76F  AD 0D FD      	?wl:	lda	!VIA0+VIAIFR
1146
 3603  F8B772  89 20         		bit	#T2IFRB
1147
 3604  F8B774  F0 F9         		beq	?wl
1148
 3605  F8B776  60            		rts
1149
 3606  F8B777
1150
 3607          000080        	T32US		.EQU	(32 * PHI2)
1151
 3608
1152
 3609  F8B777                	delay32us:
1153
 3610  F8B777  A9 20         		lda	#$20		; T2 count PHI2 pulses
1154
 3611  F8B779  1C 0B FD      		trb	VIA0+VIAACR
1155
 3612  F8B77C  A9 80         		lda	#T32US
1156
 3613  F8B77E  8D 08 FD      		sta	!VIA0+VIAT2CL
1157
 3614  F8B781  9C 09 FD      		stz	!VIA0+VIAT2CH
1158
 3615  F8B784  AD 0D FD      	?55:	lda	!VIA0+VIAIFR
1159
 3616  F8B787  89 20         		bit	#T2IFRB
1160
 3617  F8B789  F0 F9         		beq	?55
1161
 3618  F8B78B  60            		rts
1162
 
1163
 
1164
             Lines Assembled : 3528                  Errors : 0
1165
 
1166
 
1167