Subversion Repositories MB01 Project

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 - 1
  Tue Jul 17 11:00:15 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\ata.asm
13
                       Output Filename : obj\F8\ata.obj
14
                       Listing Has Been Relocated
15
 
16
 
17
 2585                        	.LIST		on
18
 2586
19
 2587  F8FFB1                		.INCLUDE inc\dirp00.inc
20
 2588                        	;----------------------------------------------------------
21
 2589                        	; DIRP00.ASM
22
 2590                        	; PROGETTO: B1601
23
 2591                        	;
24
 2592                        	; Variabili in Direct Page $00
25
 2593                        	;----------------------------------------------------------
26
 2594
27
 2595                        	; sezione COMMON -- questo permette di includere il file in piu' file
28
 2596
29
 2597                        	.LIST on
30
 2598
31
 2599                        	DIRP00:	.SECTION page0, ref_only, common	;Direct-Page 00
32
 2600
33
 2601  000000                		.ABSOLUTE		;; inizia sempre da $00
34
 2602  000000                		.ORG		0x00
35
 2603  000000
36
 2604  000000  0000          	JiffyClk	.DW			; contatore 10ms 32 bit
37
 2605  000002  0000          			.DW
38
 2606  000004                	SysTmr		.DS	SYSTMRCNT	; system timer 0 (10ms)
39
 2607  000008                	SysTMF		.DS	SYSTMRCNT	; flag timer (80 -> start)
40
 2608  00000C  00            	Bnk0Flag	.DB			; <7>: flag test RAM banco 0 ok
41
 2609                        						; <6>: flag warm reset
42
 2610  00000D  00            	RTCFlag		.DB
43
 2611
44
 2612  00000E                	diskstat	.DS	2	; flag device on ata bus #0 & #1
45
 2613                        					; <7>: device ready
46
 2614                        					; <6>: compact flash device (C.F.)
47
 2615                        					; <5>: device identification ok
48
 2616                        					; <4>: MBR loaded
49
 2617                        					; <3>: valid signature in MBR
50
 2618                        					; <2>: first partition found&active
51
 2619                        					; <1>:
52
 2620                        					; <0>: valid partition flag
53
 2621
54
 2622                        					; <7>: device ready
55
 2623                        					; <6>: USB device
56
 2624                        					; <5>: compact flash device (C.F.)
57
 2625                        					; <4>: device identification ok
58
 2626                        					; <3>: MBR loaded
59
 2627                        					; <2>: first partition found&active
60
 2628                        					; <1>: always 1
61
 2629                        					; <0>: valid partition flag
62
 2630  000010
63
  Tue Jul 17 11:00:15 2018                                                                                               Page    2
64
 
65
 
66
 
67
 
68
 2631
69
 2632          00000E        	atadev		.EQU	diskstat
70
 2633
71
 2634  000010                	usbdev		.DS	2	; flag flash disk on usb bus #0
72
 2635                        					; <7>: device plugged and ready
73
 2636                        					; <6>: always 1
74
 2637                        					; <5>: device identification ok
75
 2638                        					; <4>: MBR loaded
76
 2639                        					; <3>: valid signature in MBR
77
 2640                        					; <2>: first partition found&active
78
 2641                        					; <1>:
79
 2642                        					; <0>: valid partition flag
80
 2643
81
 2644  000012                	diskmax		.DS	16	; disk max. sector's
82
 2645          000012        	atasec		.EQU	diskmax
83
 2646          00001A        	usbsec		.EQU	diskmax+8
84
 2647
85
 2648
86
 2649  000022                	atambr		.DS	8	; data for first partition found in mbr
87
 2650                        					; first 3 bytes for start sector of partition
88
 2651                        					; last byte for partition type
89
 2652  00002A                	usbmbr		.DS	8
90
 2653
91
 2654  000032                	ataprt		.DS	8	; total sec's of first partition
92
 2655  00003A                	usbprt		.DS	8	; total sec's of first partition
93
 2656
94
 2657
95
 2658  000042  00            	usb0ch		.DB	; usb0 (ch375/ch376) flag
96
 2659                        				; <7>: module on
97
 2660                        				; <6>: ch376 flag
98
 2661                        				; <5:0>: chip version
99
 2662
100
 2663  000043  00            	usb0st		.DB	; usb0 status
101
 2664                        				; <7>: usb0 host mode ok
102
 2665                        				; <6>: flash disk attached flag
103
 2666                        				; <5>: usb device attached
104
 2667
105
 2668  000044  00            	fdcdrv		.DB		; phisycal drive status (drive #0)
106
 2669                        					; <7>: disk format established in bit 0&1
107
 2670                        					; <6>: double step seek done
108
 2671                        					; <5>: trust format bit's (set after ok r/w)
109
 2672                        					; <4>: write protect bit (if disk in drive)
110
 2673                        					; <3>: don't care
111
 2674                        					; <2>: don't care
112
 2675                        					; <1>: HD disk if set else DD disk
113
 2676                        					; <0>: CBM format if set else IBM format
114
 2677
115
 2678  000045  00            	vdrive		.DB		; virtual drive status (ram disk, drive #1)
116
 2679                        					; <7>: disk format established in bit 0&1
117
 2680                        					; <6>: change disk simulation (after format)
118
 2681                        					; <5>: don't care
119
 2682                        					; <4>: write protect bit (under sw control)
120
 2683                        					; <3>: don't care
121
 2684                        					; <2>: don't care
122
 2685                        					; <1>: HD disk if set else DD disk
123
 2686                        					; <0>: CBM format if set else IBM format
124
 2687
125
  Tue Jul 17 11:00:15 2018                                                                                               Page    3
126
 
127
 
128
 
129
 
130
 2688  000046  00            	fdcctl		.DB		; fdc controller status
131
 2689                        					; <7>: drive is attached
132
 2690                        					; <6>: drive need recalibration (restore)
133
 2691                        					; <5>: FDC controller ok
134
 2692                        					; <4>: motor on
135
 2693                        					; <3>: dma is active
136
 2694                        					; <2>: dma chip ok (post routine)
137
 2695                        					; <1>: clock rate (1=HD,0=DD)
138
 2696                        					; <0>: disk ready
139
 2697
140
 2698  000047  00            	fdctrk		.DB		; fd: current seek track
141
 2699  000048  00            	fdcerr		.DB		; fd: last error code
142
 2700  000049  00            	ataerr		.DB		; ata: last error code
143
 2701  00004A  00            	ataxer		.DB		; ata: last extended error code
144
 2702
145
 2703  00004B  00            	CtrlBrk		.DB		; flag CTRL+BREAK (NMI)
146
 2704
147
 2705  00004C  0000          	MemTop		.DW		; top memoria RAM
148
 2706  00004E  00            			.DB		; banco top mem
149
 2707
150
 2708  00004F  00            	DflTxtIn	.DB		; device di default text input
151
 2709  000050  00            	DflTxtOut	.DB		; device di default text output
152
 2710
153
 2711  000051                	COPPtr		LP		; long pointer for COP decoding
154
 2712  000054  00            	COPIdx		.DB		; COP signature/index
155
 2713
156
 2714  000055  00            	BiosEnt		.DB		; flag accesso a bios setup
157
 2715
158
 2716                        	; variabili utilizzate da ACIA
159
 2717  000056                	spwrk		.DS	$30
160
 2718
161
 2719                        	; bios mem
162
 2720  000086  0000          	nsize		.DW	; dimensione blocco da allocare
163
 2721                        	;bsize		.DW	; dimensione vera blocco free
164
 2722  000088  0000          	splitsz		.DW	; dimensione blocco splittato
165
 2723  00008A  0000          	bfree		.DW	; puntatore blocco free
166
 2724  00008C  0000          	hdrptr		.DW	; puntatore header heap
167
 2725
168
 2726  00008E  0000          	pbrklv		.DW	; current break level of current process
169
 2727  000090  0000          	pbrkmin		.DW	; minimum breal level of current process
170
 2728  000092  0000          	pbrkmax		.DW	; maximum breal level of current process
171
 2729  000094
172
 2730                        	; bios temp. work area
173
 2731  000094                	bwrktmp		.DS	$28
174
 2732
175
 2733  0000BC  00            	coptmp		.DB	; temp. used while cop
176
 2734
177
 2735  0000BD  00            	tstser		.DB	; check ser/usb test board post
178
 2736                        				; <7>: VIA2 ok
179
 2737                        				; <6>: PICRAM ok
180
 2738                        				; <1>: UART 16C550 ok
181
 2739                        				; <0>: R65C51 ok
182
 2740
183
 2741
184
 2742                        	;crc16		.DW
185
 2743
186
 2744  0000BD                		.RELATIVE
187
  Tue Jul 17 11:00:15 2018                                                                                               Page    4
188
 
189
 
190
 
191
 
192
 2745
193
 2746                        		.ENDS
194
 2747
195
 2748          [01]          	.IFDEF		_ACIA_INC_
196
 2749                        		.INCLUDE INC\SP.INC
197
 2750          [00]          	.ENDIF
198
 2751
199
 2759                        	.LIST on
200
 2760
201
 2761                        	; direct page for bios disk data
202
 2762                        	_DPDSK:	.SECTION page0, ref_only, common, offset 0	;DISK ID D.P.
203
 2763
204
 2764                        			;.ABSOLUTE
205
 2765                        			;.ORG	0x00
206
 2766
207
 2767  000000                	_atamod0	.DS	41	; model string device ata #0
208
 2768  000029                	_ataser0	.DS	21	; serial string device ata #0
209
 2769  00003E                	_atarev0	.DS	9	; revision string device ata #0
210
 2770
211
 2771  000047                	_atamod1	.DS	41	; model string device ata #1
212
 2772  000070                	_ataser1	.DS	21	; serial string device ata #1
213
 2773  000085                	_atarev1	.DS	9	; revision string device ata #1
214
 2774
215
 2775  00008E                	_usbdsc0	.DS	32	; identification string device usb #0
216
 2776  0000AE                	_usbdsc1	.DS	32	; identification string device usb #1
217
 2777
218
 2778  0000CE                	_maxsecs	.DS	16	; disk max. sector's
219
 2779
220
 2780  0000DE                	_DPDSK_END	.DS	0
221
 2781
222
 2782                        			;.RELATIVE
223
 2783
224
 2784                        		.ENDS
225
 2788                        	.LIST on
226
 2789
227
 2790                        		;.INCLUDE inc\BIOSSEG.INC
228
 2791
229
 2792  F8FFB1
230
 2793          000004        	WRITETRASF	.EQU	$04	; write transfer: read ATA, write MEM
231
 2794          000008        	READTRASF	.EQU	$08	; read  transfer: read MEM, write ATA
232
 2795
233
 2796          0007D0        	BUSYTMO		.EQU	2000	; 2000ms (timer PB6) - busy timeout
234
 2797          0007D0        	INTTMO		.EQU	2000	; 2000ms (timer PB6) - interrupt timeout
235
 2798          00270F        	T2MS5		.EQU	((2500 * PHI2) - 1)	; timeout 2.5ms
236
 2799          009C3F        	T2MS10		.EQU	((10000 * PHI2) - 1)	; timeout 10ms
237
 2800
238
 2801          000B40        	XBMIN		.EQU	$0B40	; min. x-mem buffer
239
 2802          001000        	XBMAX		.EQU	$1000	; max. x-mem buffer + 1
240
 2803          000001        	MBMIN		.EQU	$01	; min. buffer bank
241
 2804          0000F0        	MBMAX		.EQU	$F0	; max. buffer bank + 1
242
 2805          000800        	MDMAX		.EQU	$0800	; max. dma buffer
243
 2806
244
 2807          000020        	READSECTOR	.EQU	$20	; read sector(s)
245
 2808          000030        	WRITESECTOR	.EQU	$30	; write sector(s)
246
 2809          0000C8        	READDMA		.EQU	$C8	; read dma sectors
247
 2810          0000CA        	WRITEDMA	.EQU	$CA	; write dma sectors
248
 2811
249
  Tue Jul 17 11:00:15 2018                                                                                               Page    5
250
 
251
 
252
 
253
 
254
 2812                        	;FLUSHCACHE	.EQU	$E7
255
 2813          0000EC        	IDENTDEV	.EQU	$EC	; identify device
256
 2814
257
 2815                        	; page 0 local var's (declared in bios temp. work area)
258
 2816                        	_P0BTMP:	.SECTION page0, ref_only, offset bwrktmp	; DP Tmp. BIOS
259
 2817          000094        	ATATMP_START	.EQU	$
260
 2818
261
 2819  000094  00            	drive		.DB		; ata #0 or ata #1 device
262
 2820  000095                	lba		DS	3	; 24 bit sector address
263
 2821  000098  00            	secnum		.DB		; sector(s) count # (if 0 -> 256 sec.)
264
 2822  000099  00            	seccnt		.DB		; copy of secnum
265
 2823  00009A  00            	ifrbit		.DB		; bit to test on VIA3 IFR
266
 2824  00009B  00            	cmdfg		.DB		; flag for load command block reg's
267
 2825  00009C  00            	ataop		.DB		; ata operation flag
268
 2826                        					; <7>=0->read, 1->write
269
 2827                        					; <6>=1 compare (ignored in dma mode)
270
 2828  00009D  00            	memfg		.DB		; using buffer in x-mem flag
271
 2829  00009E  00            	drdyf		.DB		; test alt. status reg. while read/write block
272
 2830  00009F  00            	match		.DB		; compare result (match if not null)
273
 2831  0000A0                	bufp		LP		; in/out buffer long pointer
274
 2832  0000A3                	memp		LP		; start buffer pointer
275
 2833  0000A6  0000          	xbuf		.DW		; x-mem buffer # ($0B40..$0FFF)
276
 2834                        					; dma buffer # ($0000..$7FFF)
277
 2835  0000A8  00            	xbnk		.DB		; starting x-mem bank
278
 2836  0000A9  00            	xsave		.DB		; save x-mem setting
279
 2837  0000AA  0000          	nlba		.DW		; total sector's count #
280
 2838  0000AC  0000          	ncnt		.DW		; dma words count #
281
 2839  0000AE  00            	tmp		.DB		; temp
282
 2840  0000AF  00            	ataofs		.DB		; temp: ata offset address
283
 2841  0000B0  0000          	wtmp		.DW		; temp. word
284
 2842  0000B2  0000          	mbrsgn		.DW		; mbr signature
285
 2843  0000B4  0000          	mbrfg		.DW		; mbr first partition flag
286
 2844  0000B6  00            	tmpy		.DB
287
 2845  0000B7  00            	dmareq		.DB
288
 2846
289
 2847          000024        	ATATMP_SIZ	.EQU	($-ATATMP_START)
290
 2848                        		.ENDS
291
 2849
292
 2850                        	;---------------------------------------------------------------------------
293
 2851                        	; code segment -- bank $F8
294
 2852                        	;---------------------------------------------------------------------------
295
 2853
296
 2854                        		.CODEF8
297
 2855  F88839
298
 2856                        		.LONGA	off
299
 2857                        		.LONGI	off
300
 2858  F88839
301
 2859                        	;---------------------------------------------------------------------------
302
 2860                        	; System interface
303
 2861                        	;---------------------------------------------------------------------------
304
 2862
305
 2863                        	;---------------------------------------------------------------------------
306
 2864                        	; sys_atadma - read/write sectors in ata device (dma mode)
307
 2865                        	;
308
 2866                        	; prototype: sys_atadma(bDev, dwSec, bNum, nBuf)
309
 2867                        	;
310
 2868                        	; Params (7 bytes):
311
  Tue Jul 17 11:00:15 2018                                                                                               Page    6
312
 
313
 
314
 
315
 
316
 2869                        	;	bDev	= ata device # (0..1)
317
 2870                        	;	dwSec	= 24 bit address of first sector (LBA)
318
 2871                        	;	bNum	= number of sectors to read/write; if bNum=0 then bNum=256
319
 2872                        	;	nBuf	= dma buffer # ($0000..$07FF)
320
 2873                        	;
321
 2874                        	; Out:
322
 2875                        	;	CF = 0 if operation completed successfully
323
 2876                        	;		C  = uncahnged
324
 2877                        	;		X  = unchanged
325
 2878                        	;		Y  = unchanged
326
 2879                        	;	CF = 1 if error
327
 2880                        	;		C  = unchanged
328
 2881                        	;		X  = extended error code (if any)
329
 2882                        	;		Y  = error code
330
 2883                        	;	Status register always preserved except carry
331
 2884
332
 2885                        	; params offset
333
 2886          000013        	nBuf	.SET	STKPRMS
334
 2887          000015        	bNum	.SET	STKPRMS + 2
335
 2888          000016        	dwSec	.SET	STKPRMS + 3
336
 2889          000019        	bDev	.SET	STKPRMS + 6
337
 2890
338
 2891  F88839                	sys_atadma:
339
 2892                        		.GLOBAL	sys_atadma
340
 2893
341
 2894  F88839  64 49         		stz	ataerr		; clear error var's
342
 2895  F8883B  64 4A         		stz	ataxer
343
 2896  F8883D                		ACC16			; retrieve function number
344
 2897  F8883D  C2 20         		rep	#PMFLAG
345
 2898                        		.LONGA	on
346
 2899                        		.MNLIST
347
 2900  F8883F  A3 10         		lda	STKPCL,s	; pointer to byte after signature
348
 2901  F88841  85 51         		sta	COPPtr
349
 2902  F88843  1A            		inc	a		; update return address
350
 2903  F88844  83 10         		sta	STKPCL,s
351
 2904  F88846  A3 16         		lda	dwSec,s		; get 16 bit param's
352
 2905  F88848  85 95         		sta	lba
353
 2906  F8884A  A3 13         		lda	nBuf,s
354
 2907  F8884C  C9 00 08      		cmp	#MDMAX
355
 2908  F8884F  B0 5A         		bcs	?11		; buffer overflow
356
 2909  F88851  85 A6         		sta	xbuf
357
 2910  F88853                		ACC08			; A,M -> 8 bit
358
 2911  F88853  E2 20         		sep	#PMFLAG
359
 2912                        		.LONGA	off
360
 2913                        		.MNLIST
361
 2914  F88855  A3 12         		lda	STKPBR,s	; bank where was executed cop instruction
362
 2915  F88857  85 53         		sta	COPPtr+2
363
 2916  F88859  A7 51         		lda	[COPPtr]	; byte after signature
364
 2917  F8885B  C9 02         		cmp	#$02		; right value: 0,1
365
 2918  F8885D  90 04         		bcc	?00		; ok
366
 2919  F8885F  A9 08         		lda	#ATA_BADOP	; invalid function
367
 2920  F88861  80 4C         		bra	?20		; set error & exit
368
 2921  F88863  AA            	?00:	tax			; X=operation (0=read,1=verify,2=write)
369
 2922  F88864  BF 98 91 F8   		lda	>OPTAB2,x
370
 2923  F88868  85 9C         		sta	ataop		; operation ($00, $80)
371
 2924  F8886A  A3 18         		lda	dwSec+2,s
372
 2925  F8886C  85 97         		sta	lba+2		; store first sector lba
373
  Tue Jul 17 11:00:15 2018                                                                                               Page    7
374
 
375
 
376
 
377
 
378
 2926  F8886E  A0 00         		ldy	#0
379
 2927  F88870  A3 15         		lda	bNum,s
380
 2928  F88872  85 98         		sta	secnum		; sector's count #
381
 2929  F88874  85 B0         		sta	wtmp		; for check
382
 2930  F88876  D0 01         		bne	?02		; less than 256
383
 2931  F88878  C8            		iny			; = 256
384
 2932  F88879  84 B1         	?02:	sty	wtmp+1		; for later check
385
 2933  F8887B  A3 19         		lda	bDev,s		; device
386
 2934  F8887D  29 01         		and	#1		; 0 or 1
387
 2935  F8887F  AA            		tax
388
 2936  F88880  34 0E         		bit	atadev,x	; ready?
389
 2937  F88882  30 04         		bmi	?03		; yes
390
 2938  F88884  A9 01         		lda	#ATA_NOTREADY	; not ready
391
 2939  F88886  80 27         		bra	?20		; set error & exit
392
 2940  F88888  86 94         	?03:	stx	drive
393
 2941  F8888A  A5 B0         		lda	wtmp
394
 2942  F8888C  85 AD         		sta	ncnt+1		; ncnt = words count
395
 2943  F8888E  64 AC         		stz	ncnt
396
 2944  F88890                		ACC16CLC
397
 2945  F88890  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
398
 2946                        		.LONGA	on
399
 2947                        		.MNLIST
400
 2948  F88892  C6 AC         		dec	ncnt		; dma need words count - 1
401
 2949  F88894  A5 A6         		lda	xbuf		; buffer #
402
 2950  F88896  65 B0         		adc	wtmp		; add sec. #
403
 2951  F88898  C9 01 08      		cmp	#MDMAX+1	; buffer overflow?
404
 2952  F8889B  B0 0E         		bcs	?11		; yes
405
 2953  F8889D  3A            		dec	a		; final buffer
406
 2954  F8889E                		ACC08
407
 2955  F8889E  E2 20         		sep	#PMFLAG
408
 2956                        		.LONGA	off
409
 2957                        		.MNLIST
410
 2958  F888A0  EB            		xba			; transfer must be in one 64Kw bank
411
 2959  F888A1  C5 A7         		cmp	xbuf+1
412
 2960  F888A3  D0 08         		bne	?12		; error: not same bank
413
 2961  F888A5  20 10 8C      		jsr	dmardwr		; execute dma transfer
414
 2962  F888A8  B0 05         		bcs	?20		; error
415
 2963  F888AA  6B            		rtl
416
 2964  F888AB                	?11:	ACC08
417
 2965  F888AB  E2 20         		sep	#PMFLAG
418
 2966                        		.LONGA	off
419
 2967                        		.MNLIST
420
 2968  F888AD  A9 0A         	?12:	lda	#ATA_MEM	; bad buffer
421
 2969  F888AF  AA            	?20:	tax
422
 2970  F888B0  A9 00         		lda	#0		; report extended error if any
423
 2971  F888B2  83 0C         		sta	STKXR+1,s
424
 2972  F888B4  E0 04         		cpx	#ATA_EBIT
425
 2973  F888B6  D0 01         		bne	?22
426
 2974  F888B8  98            		tya			; extended error
427
 2975  F888B9  83 0B         	?22:	sta	STKXR,s
428
 2976  F888BB  85 4A         		sta	ataxer		; extended error code
429
 2977  F888BD  8A            		txa			; A=error code
430
 2978  F888BE  85 49         		sta	ataerr
431
 2979  F888C0  38            		sec
432
 2980  F888C1  6B            		rtl
433
 2981
434
 2982                        	;---------------------------------------------------------------------------
435
  Tue Jul 17 11:00:15 2018                                                                                               Page    8
436
 
437
 
438
 
439
 
440
 2983                        	; sys_atarw - read/write/verify sectors in ata device (pio mode)
441
 2984                        	;
442
 2985                        	; prototype: sys_atarw(bDev, dwSec, bNum, lpBuf, bFlag)
443
 2986                        	;
444
 2987                        	; Params (9 bytes):
445
 2988                        	;	bDev	= ata device # (0..1)
446
 2989                        	;	dwSec	= 24 bit address of first sector (LBA)
447
 2990                        	;	bNum	= number of sectors to read/write; if bNum=0 then bNum=256
448
 2991                        	;	lpBuf	= long pointer to buffer
449
 2992                        	;			if bank(lpBuf+2)=0 or bank=1 buffer is in the x-mem
450
 2993                        	;			and in this case lpBuf store the x-mem buffer;
451
 2994                        	;			x-mem buffer can be only in range $0B40..$0FFF
452
 2995                        	;			if conventional memory, bank must be in range $01..$EF
453
 2996                        	;	bFlag	= flag
454
 2997                        	;			<7>: verify data after writing
455
 2998                        	;			ignored in read/verify operation
456
 2999                        	;
457
 3000                        	; Out:
458
 3001                        	;	CF = 0 if operation completed successfully
459
 3002                        	;		C  = uncahnged
460
 3003                        	;		X  = unchanged
461
 3004                        	;		Y  = unchanged
462
 3005                        	;	CF = 1 if error
463
 3006                        	;		C  = unchanged
464
 3007                        	;		X  = extended error code (if any)
465
 3008                        	;		Y  = error code
466
 3009                        	;	Status register always preserved except carry
467
 3010
468
 3011                        	; params offset
469
 3012          000013        	bFlag	.SET	STKPRMS
470
 3013          000014        	lpBuf	.SET	STKPRMS + 1
471
 3014          000017        	bNum	.SET	STKPRMS + 4
472
 3015          000018        	dwSec	.SET	STKPRMS + 5
473
 3016          00001B        	bDev	.SET	STKPRMS + 8
474
 3017
475
 3018  F888C2                	sys_atarw:
476
 3019                        		.GLOBAL	sys_atarw
477
 3020
478
 3021  F888C2  64 49         		stz	ataerr		; clear error var's
479
 3022  F888C4  64 4A         		stz	ataxer
480
 3023  F888C6                		ACC16			; retrieve function number
481
 3024  F888C6  C2 20         		rep	#PMFLAG
482
 3025                        		.LONGA	on
483
 3026                        		.MNLIST
484
 3027  F888C8  A3 10         		lda	STKPCL,s	; pointer to byte after signature
485
 3028  F888CA  85 51         		sta	COPPtr
486
 3029  F888CC  1A            		inc	a		; update return address
487
 3030  F888CD  83 10         		sta	STKPCL,s
488
 3031  F888CF  A3 18         		lda	dwSec,s		; get 16 bit param's
489
 3032  F888D1  85 95         		sta	lba
490
 3033  F888D3  A3 14         		lda	lpBuf,s
491
 3034  F888D5  85 A3         		sta	memp
492
 3035  F888D7                		ACC08			; A,M -> 8 bit
493
 3036  F888D7  E2 20         		sep	#PMFLAG
494
 3037                        		.LONGA	off
495
 3038                        		.MNLIST
496
 3039  F888D9  A3 12         		lda	STKPBR,s	; bank where was executed cop instruction
497
  Tue Jul 17 11:00:15 2018                                                                                               Page    9
498
 
499
 
500
 
501
 
502
 3040  F888DB  85 53         		sta	COPPtr+2
503
 3041  F888DD  A7 51         		lda	[COPPtr]	; byte after signature
504
 3042  F888DF  C9 03         		cmp	#$03		; right value: 0,1,2
505
 3043  F888E1  90 05         		bcc	?00		; ok
506
 3044  F888E3  A9 08         		lda	#ATA_BADOP	; invalid function
507
 3045  F888E5  4C 7E 89      		jmp	?20		; set error & exit
508
 3046  F888E8  AA            	?00:	tax			; X=operation (0=read,1=verify,2=write)
509
 3047  F888E9  BF 95 91 F8   		lda	>OPTAB,x
510
 3048  F888ED  10 0B         		bpl	?01		; read/verify (ignore bFlag)
511
 3049  F888EF  A8            		tay
512
 3050  F888F0  A3 13         		lda	bFlag,s		; verify flag (after write)?
513
 3051  F888F2  30 03         		bmi	?00a		; yes
514
 3052  F888F4  98            		tya
515
 3053  F888F5  80 03         		bra	?01		; no
516
 3054  F888F7  98            	?00a:	tya
517
 3055  F888F8  09 40         		ora	#$40		; yes, set verify flag
518
 3056  F888FA  85 9C         	?01:	sta	ataop		; operation ($00, $40, $80, $C0)
519
 3057  F888FC  A3 1A         		lda	dwSec+2,s
520
 3058  F888FE  85 97         		sta	lba+2		; store first sector lba
521
 3059  F88900  A0 00         		ldy	#0
522
 3060  F88902  A3 17         		lda	bNum,s
523
 3061  F88904  85 98         		sta	secnum		; sector's count #
524
 3062  F88906  85 B0         		sta	wtmp		; for check
525
 3063  F88908  D0 01         		bne	?02		; less than 256
526
 3064  F8890A  C8            		iny			; = 256
527
 3065  F8890B  84 B1         	?02:	sty	wtmp+1		; for later check
528
 3066  F8890D  A3 1B         		lda	bDev,s		; device
529
 3067  F8890F  29 01         		and	#1		; 0 or 1
530
 3068  F88911  AA            		tax
531
 3069  F88912  34 0E         		bit	atadev,x	; ready?
532
 3070  F88914  30 04         		bmi	?03		; yes
533
 3071  F88916  A9 01         		lda	#ATA_NOTREADY	; not ready
534
 3072  F88918  80 64         		bra	?20		; set error & exit
535
 3073  F8891A  86 94         	?03:	stx	drive
536
 3074  F8891C  64 9D         		stz	memfg
537
 3075  F8891E  A3 16         		lda	lpBuf+2,s	; buffer bank
538
 3076  F88920  C9 01         		cmp	#MBMIN		; x-mem buffer?
539
 3077  F88922  B0 24         		bcs	?08		; no, conventional memory
540
 3078  F88924                		ACC16
541
 3079  F88924  C2 20         		rep	#PMFLAG
542
 3080                        		.LONGA	on
543
 3081                        		.MNLIST
544
 3082  F88926  A0 00         		ldy	#0		; assume no error
545
 3083  F88928  A5 A3         		lda	memp		; check x-mem buffer
546
 3084  F8892A  85 A6         		sta	xbuf
547
 3085  F8892C  C9 40 0B      		cmp	#XBMIN
548
 3086  F8892F  90 0A         		bcc	?04		; error
549
 3087  F88931  18            		clc
550
 3088  F88932  65 B0         		adc	wtmp		; add sector's count
551
 3089  F88934  B0 05         		bcs	?04		; overflow error
552
 3090  F88936  C9 01 10      		cmp	#XBMAX+1
553
 3091  F88939  90 02         		bcc	?06		; buffer limits ok
554
 3092  F8893B  A0 09         	?04:	ldy	#ATA_XMEM	; Y=x-mem buffer error
555
 3093  F8893D                	?06:	ACC08
556
 3094  F8893D  E2 20         		sep	#PMFLAG
557
 3095                        		.LONGA	off
558
 3096                        		.MNLIST
559
  Tue Jul 17 11:00:15 2018                                                                                               Page   10
560
 
561
 
562
 
563
 
564
 3097  F8893F  98            		tya
565
 3098  F88940  D0 3C         		bne	?20		; set error & exit
566
 3099  F88942  A9 80         		lda	#$80
567
 3100  F88944  85 9D         		sta	memfg
568
 3101  F88946  80 27         		bra	?14		; ok, good x-mem buffer
569
 3102  F88948  85 A5         	?08:	sta	memp+2		; store buffer bank
570
 3103  F8894A  C9 F0         		cmp	#MBMAX		; over max. bank?
571
 3104  F8894C  B0 1D         		bcs	?12		; yes, error
572
 3105  F8894E  AA            		tax			; X=bank
573
 3106  F8894F                		ACC16
574
 3107  F8894F  C2 20         		rep	#PMFLAG
575
 3108                        		.LONGA	on
576
 3109                        		.MNLIST
577
 3110  F88951  64 AC         		stz	nlba+2		; high word (only low byte significative)
578
 3111  F88953  A5 B0         		lda	wtmp		; convert secnum in bytes
579
 3112  F88955  A0 09         		ldy	#9		; 9 shift (mult by 512)
580
 3113  F88957  0A            	?10:	asl	a		; low word
581
 3114  F88958  26 AC         		rol	nlba+2		; shift high word
582
 3115  F8895A  88            		dey
583
 3116  F8895B  D0 FA         		bne	?10
584
 3117  F8895D  18            		clc
585
 3118  F8895E  65 A3         		adc	memp
586
 3119  F88960  85 AA         		sta	nlba		; end address: low word
587
 3120  F88962                		ACC08
588
 3121  F88962  E2 20         		sep	#PMFLAG
589
 3122                        		.LONGA	off
590
 3123                        		.MNLIST
591
 3124  F88964  8A            		txa			; start bank
592
 3125  F88965  65 AC         		adc	nlba+2		; end address: bank
593
 3126  F88967  C9 F0         		cmp	#MBMAX
594
 3127  F88969  90 04         		bcc	?14		; ok, good buffer
595
 3128  F8896B  A9 0A         	?12:	lda	#ATA_MEM	; bad buffer
596
 3129  F8896D  80 0F         		bra	?20		; set error & exit
597
 3130  F8896F  24 9C         	?14:	bit	ataop
598
 3131  F88971  30 06         		bmi	?18		; write op
599
 3132  F88973  20 31 8B      		jsr	readsct
600
 3133  F88976  B0 06         		bcs	?20		; read error
601
 3134  F88978  6B            	?16:	rtl			; ok, no error
602
 3135  F88979  20 F0 89      	?18:	jsr	writesct
603
 3136  F8897C  90 FA         		bcc	?16		; write ok
604
 3137  F8897E  AA            	?20:	tax
605
 3138  F8897F  A9 00         		lda	#0		; report extended error if any
606
 3139  F88981  83 0C         		sta	STKXR+1,s
607
 3140  F88983  E0 04         		cpx	#ATA_EBIT
608
 3141  F88985  D0 01         		bne	?22
609
 3142  F88987  98            		tya			; extended error
610
 3143  F88988  83 0B         	?22:	sta	STKXR,s
611
 3144  F8898A  85 4A         		sta	ataxer		; extended error code
612
 3145  F8898C  8A            		txa			; A=error code
613
 3146  F8898D  85 49         		sta	ataerr
614
 3147  F8898F  38            		sec
615
 3148  F88990  6B            		rtl
616
 3149
617
 3150                        	;---------------------------------------------------------------------------
618
 3151                        	; sys_atactl - control function
619
 3152                        	;
620
 3153                        	; prototype: sys_atactl(A=function#, X=device#)
621
  Tue Jul 17 11:00:15 2018                                                                                               Page   11
622
 
623
 
624
 
625
 
626
 3154                        	;
627
 3155                        	; Functions:
628
 3156                        	;	A=$00: 	reset device X
629
 3157                        	;	A=$01: 	identify device X
630
 3158                        	;	A=$02: 	load mbr of device X
631
 3159                        	;	A=$03: 	load pbr of device X
632
 3160                        	;
633
 3161                        	; Out:
634
 3162                        	;	CF = 0 if operation completed successfully
635
 3163                        	;	CF = 1 if error
636
 3164                        	;		C  = unchanged
637
 3165                        	;		X  = extended error code (if any)
638
 3166                        	;		Y  = error code
639
 3167                        	;	Status register always preserved except carry
640
 3168  F88991                	sys_atactl:
641
 3169                        		.GLOBAL	sys_atactl
642
 3170
643
 3171  F88991  64 49         		stz	ataerr		; clear error var's
644
 3172  F88993  64 4A         		stz	ataxer
645
 3173  F88995  A3 0B         		lda	STKXR,s
646
 3174  F88997  29 01         		and	#1
647
 3175  F88999  85 94         		sta	drive
648
 3176  F8899B  AA            		tax
649
 3177  F8899C  34 0E         		bit	atadev,x
650
 3178  F8899E  10 37         		bpl	?10		; not ready
651
 3179  F889A0  8A            		txa
652
 3180  F889A1  F0 02         		beq	?02
653
 3181  F889A3  A2 10         		ldx	#ATAOFS
654
 3182  F889A5  86 AF         	?02:	stx	ataofs
655
 3183  F889A7  A3 0D         		lda	STKCR,s		; function#
656
 3184  F889A9  C9 04         		cmp	#$04
657
 3185  F889AB  B0 2E         		bcs	?12		; invalid function
658
 3186  F889AD  A8            		tay
659
 3187  F889AE  D0 05         		bne	?04
660
 3188  F889B0  20 1F 8E      		jsr	devres		; 0: reset device
661
 3189  F889B3  80 1F         		bra	?08
662
 3190  F889B5  A6 94         	?04:	ldx	drive
663
 3191  F889B7  3A            		dec	a
664
 3192  F889B8  F0 11         		beq	?06		; 1: ident
665
 3193  F889BA  3A            		dec	a
666
 3194  F889BB  F0 03         		beq	?05		; 2: load mbr
667
 3195  F889BD  20 BE 8A      		jsr	getpbr		; 3: load pbr
668
 3196  F889C0  A9 E2         	?05:	lda	#11100010B
669
 3197  F889C2  35 0E         		and	atadev,x
670
 3198  F889C4  95 0E         		sta	atadev,x
671
 3199  F889C6  20 70 90      		jsr	chkmbr		; 2: load mbr
672
 3200  F889C9  80 09         		bra	?08
673
 3201  F889CB  A9 DF         	?06:	lda	#11011111B	; 1: ident
674
 3202  F889CD  35 0E         		and	atadev,x
675
 3203  F889CF  95 0E         		sta	atadev,x
676
 3204  F889D1  20 80 8E      		jsr	ident
677
 3205  F889D4  B0 07         	?08:	bcs	?14
678
 3206  F889D6  6B            		rtl
679
 3207  F889D7  A9 01         	?10:	lda	#ATA_NOTREADY	; not ready
680
 3208  F889D9  80 02         		bra	?14		; set error & exit
681
 3209  F889DB  A9 08         	?12:	lda	#ATA_BADOP	; invalid function
682
 3210  F889DD  AA            	?14:	tax
683
  Tue Jul 17 11:00:15 2018                                                                                               Page   12
684
 
685
 
686
 
687
 
688
 3211  F889DE  A9 00         		lda	#0		; report extended error if any
689
 3212  F889E0  83 0C         		sta	STKXR+1,s
690
 3213  F889E2  E0 04         		cpx	#ATA_EBIT
691
 3214  F889E4  D0 01         		bne	?16
692
 3215  F889E6  98            		tya			; extended error
693
 3216  F889E7  83 0B         	?16:	sta	STKXR,s
694
 3217  F889E9  85 4A         		sta	ataxer		; extended error code
695
 3218  F889EB  8A            		txa			; A=error code
696
 3219  F889EC  85 49         		sta	ataerr
697
 3220  F889EE  38            		sec
698
 3221  F889EF  6B            		rtl
699
 3222
700
 3223                        	;---------------------------------------------------------------------------
701
 3224                        	; basic read/write routines
702
 3225                        	;---------------------------------------------------------------------------
703
 3226
704
 3227                        		.LONGA	off
705
 3228                        		.LONGI	off
706
 3229
707
 3230                        	; write N (0..256) sector(s) on ata device
708
 3231                        	; in:	drive=0 or 1 (ata #0 or ata #1 device)
709
 3232                        	;	lba[0..2]=24 bits starting sector address
710
 3233                        	;	secnum=sector(s) count (if 0 -> 256 sect.)
711
 3234                        	;	memp=long pointer to input buffer
712
 3235                        	;	memfg<7>=flag buffer x-mem
713
 3236                        	;	xbuf=x-mem buffer # if using x-mem ($0B40..$0FFF)
714
 3237                        	;	ataop<6>=flag compare data after writing
715
 3238                        	; Out:	CF=0 if no error
716
 3239                        	;	CF=1 if error, A=error code, Y=error reg.
717
 3240                        	; use:	all
718
 3241  F889F0                	writesct:
719
 3242  F889F0  20 E8 8D      		jsr	setbuf		; set buffer pointer
720
 3243  F889F3  A9 80         		lda	#$80
721
 3244  F889F5  85 9B         		sta	cmdfg		; load command block registers
722
 3245  F889F7  A9 80         		lda	#$80
723
 3246  F889F9  14 9C         		trb	ataop		; we know is a write op...
724
 3247  F889FB  A0 30         		ldy	#WRITESECTOR	; write sectors PIO mode
725
 3248  F889FD  20 78 8D      		jsr	sndcmd		; return X=ata offset
726
 3249  F88A00  EA            		nop			; delay before to access status reg. (400ns)
727
 3250  F88A01  EA            		nop
728
 3251  F88A02  EA            		nop
729
 3252  F88A03  EA            		nop
730
 3253                        		;bra	?w1
731
 3254  F88A04  3C AE FD      		bit	!ATAALTST,x	; dummy read
732
 3255  F88A07  BD A7 FD      	?w0:	lda	!ATAST,x	; read status reg.
733
 3256  F88A0A  30 FB         		bmi	?w0		; wait BUSY bit=0
734
 3257  F88A0C  89 21         		bit	#ATADFB+ATAERRB
735
 3258  F88A0E  D0 47         		bne	?idle		; error
736
 3259  F88A10  89 08         		bit	#ATADRQ		; ready to transfer?
737
 3260  F88A12  D0 18         		bne	?wrb		; yes, write data block
738
 3261  F88A14  80 F1         		bra	?w0		; wait for DRQ
739
 3262  F88A16  3C AE FD      	?loop:	bit	!ATAALTST,x	; dummy read
740
 3263  F88A19  BD A7 FD      	?w1:	lda	!ATAST,x	; read status reg.
741
 3264  F88A1C  30 FB         		bmi	?w1		; wait BUSY bit=0
742
 3265  F88A1E  89 08         		bit	#ATADRQ		; end of transfer or error?
743
 3266  F88A20  F0 35         		beq	?idle		; yes
744
 3267  F88A22  A4 99         		ldy	seccnt
745
  Tue Jul 17 11:00:15 2018                                                                                               Page   13
746
 
747
 
748
 
749
 
750
 3268  F88A24  D0 06         		bne	?wrb		; more blocks
751
 3269  F88A26  A9 40         		lda	#$40
752
 3270  F88A28  04 9E         		tsb	drdyf		; data loss
753
 3271  F88A2A  E6 99         		inc	seccnt
754
 3272  F88A2C  20 F3 8C      	?wrb:	jsr	wrblk		; write data block (256 words)
755
 3273  F88A2F  C6 99         		dec	seccnt		; update left count #
756
 3274  F88A31  20 8B 8C      	?int:	jsr	waitint		; wait interrupt assertion within timeout
757
 3275  F88A34  90 E0         		bcc	?loop		; ok, read status reg.
758
 3276
759
 3277                        		; no int. assertion: this happen if device expect more data block
760
 3278                        		; write out data block until DRQ bit reset
761
 3279  F88A36  A9 40         		lda	#$40
762
 3280  F88A38  04 9E         		tsb	drdyf		; signal this error
763
 3281  F88A3A  BD AE FD      	?w2:	lda	!ATAALTST,x
764
 3282  F88A3D  89 08         		bit	#ATADRQ
765
 3283  F88A3F  F0 0B         		beq	?w3		; no drq
766
 3284  F88A41  9E AA FD      		stz	!ATAPORT,x	; latch data high byte
767
 3285  F88A44  9E AB FD      		stz	!ATAPORT+1,x	; latch data high byte
768
 3286  F88A47  9E A8 FD      		stz	!ATADATA,x	; write
769
 3287  F88A4A  80 EE         		bra	?w2
770
 3288  F88A4C  BD AE FD      	?w3:	lda	!ATAALTST,x
771
 3289  F88A4F  BD AE FD      		lda	!ATAALTST,x
772
 3290  F88A52  BD A7 FD      		lda	!ATAST,x
773
 3291  F88A55  30 DA         		bmi	?int
774
 3292
775
 3293  F88A57  24 9E         	?idle:	bit	drdyf		; test interrupt timeout error
776
 3294  F88A59  50 07         		bvc	?chk		; no, so test error condition
777
 3295  F88A5B  20 1F 8E      		jsr	devres		; reset device because write error
778
 3296  F88A5E  A9 02         		lda	#ATA_DLOSS	; data loss while writing
779
 3297  F88A60  80 28         		bra	?err
780
 3298  F88A62  89 20         	?chk:	bit	#ATADFB		; device fault bit ?
781
 3299  F88A64  F0 04         		beq	?chk1		; no
782
 3300  F88A66  A9 03         		lda	#ATA_FAULT	; yes
783
 3301  F88A68  80 20         		bra	?err
784
 3302  F88A6A  89 01         	?chk1:	bit	#ATAERRB	; error bit ?
785
 3303  F88A6C  F0 07         		beq	?chk2		; no...so write ok
786
 3304  F88A6E  BC A1 FD      		ldy	!ATAERROR,x	; read error register
787
 3305  F88A71  A9 04         		lda	#ATA_EBIT	; error bits
788
 3306  F88A73  80 15         		bra	?err
789
 3307  F88A75  A5 99         	?chk2:	lda	seccnt		; all blocks was written?
790
 3308  F88A77  F0 07         		beq	?ok		; yes
791
 3309  F88A79  20 1F 8E      		jsr	devres		; reset device because premature ending
792
 3310  F88A7C  A9 05         		lda	#ATA_DEVRES
793
 3311  F88A7E  80 0A         		bra	?err
794
 3312  F88A80  18            	?ok:	clc			; assume no error
795
 3313  F88A81  24 9C         		bit	ataop		; request for verify data?
796
 3314  F88A83  50 06         		bvc	?done		; no, exit (no error)
797
 3315  F88A85  20 16 8B      		jsr	cmpsct		; compare written data
798
 3316  F88A88  90 01         		bcc	?done		; ok, no error
799
 3317                        		;lda	#ATA_VERF	; assume always data verify error
800
 3318  F88A8A  38            	?err:	sec			; error flag
801
 3319  F88A8B  24 9D         	?done:	bit	memfg		; using x-mem?
802
 3320  F88A8D  10 05         		bpl	?rts		; no
803
 3321  F88A8F  A6 A9         		ldx	xsave
804
 3322  F88A91  9D 0A FC      		sta	!CRXME,x	; restore
805
 3323  F88A94  60            	?rts:	rts
806
 3324
807
  Tue Jul 17 11:00:15 2018                                                                                               Page   14
808
 
809
 
810
 
811
 
812
 3325                        	; load MBR in memory
813
 3326                        	; in:	drive
814
 3327  F88A95                	getmbr:
815
 3328  F88A95                		ACC16			; set pointer for MBR
816
 3329  F88A95  C2 20         		rep	#PMFLAG
817
 3330                        		.LONGA	on
818
 3331                        		.MNLIST
819
 3332  F88A97  A9 00 88      		lda	#MBR0ATA
820
 3333  F88A9A  A6 94         		ldx	drive
821
 3334  F88A9C  F0 03         		beq	?02
822
 3335  F88A9E  A9 00 8A      		lda	#MBR1ATA
823
 3336  F88AA1  85 A3         	?02:	sta	memp
824
 3337  F88AA3  85 A0         		sta	bufp
825
 3338  F88AA5  64 95         		stz	lba		; read sector=0
826
 3339  F88AA7                		ACC08
827
 3340  F88AA7  E2 20         		sep	#PMFLAG
828
 3341                        		.LONGA	off
829
 3342                        		.MNLIST
830
 3343  F88AA9  A9 01         		lda	#^MBR0ATA
831
 3344  F88AAB  85 A5         		sta	memp+2
832
 3345  F88AAD  85 A2         		sta	bufp+2
833
 3346  F88AAF  64 97         		stz	lba+2
834
 3347  F88AB1  64 9C         		stz	ataop		; just read
835
 3348  F88AB3  64 9D         		stz	memfg		; no x-mem
836
 3349  F88AB5  A9 01         		lda	#1
837
 3350  F88AB7  85 98         		sta	secnum		; read just one block
838
 3351  F88AB9
839
 3352  F88AB9  4C D9 8B      		jmp	_dmald
840
 3353  F88ABC
841
 3354  F88ABC  80 7E         		bra	readsct2
842
 3355
843
 3356                        	; load PBR in memory
844
 3357                        	; in:	drive
845
 3358  F88ABE                	getpbr:
846
 3359  F88ABE  A5 94         		lda	drive
847
 3360  F88AC0  0A            		asl	a
848
 3361  F88AC1  0A            		asl	a
849
 3362  F88AC2  AA            		tax			; index to access atambr var
850
 3363  F88AC3                		ACC16			; set pointer for MBR
851
 3364  F88AC3  C2 20         		rep	#PMFLAG
852
 3365                        		.LONGA	on
853
 3366                        		.MNLIST
854
 3367  F88AC5  A9 00 8C      		lda	#PBR0ATA
855
 3368  F88AC8  A4 94         		ldy	drive
856
 3369  F88ACA  F0 03         		beq	?02
857
 3370  F88ACC  A9 00 8E      		lda	#PBR1ATA
858
 3371  F88ACF  85 A3         	?02:	sta	memp
859
 3372  F88AD1  85 A0         		sta	bufp
860
 3373  F88AD3  B5 22         		lda	atambr,x
861
 3374  F88AD5  85 95         		sta	lba		; read pbr sector
862
 3375  F88AD7                		ACC08
863
 3376  F88AD7  E2 20         		sep	#PMFLAG
864
 3377                        		.LONGA	off
865
 3378                        		.MNLIST
866
 3379  F88AD9  A9 01         		lda	#^MBR0ATA
867
 3380  F88ADB  85 A5         		sta	memp+2
868
 3381  F88ADD  85 A2         		sta	bufp+2
869
  Tue Jul 17 11:00:15 2018                                                                                               Page   15
870
 
871
 
872
 
873
 
874
 3382  F88ADF  B5 24         		lda	atambr+2,x
875
 3383  F88AE1  85 97         		sta	lba+2
876
 3384  F88AE3  64 9C         		stz	ataop		; just read
877
 3385  F88AE5  64 9D         		stz	memfg		; no x-mem
878
 3386  F88AE7  A9 01         		lda	#1
879
 3387  F88AE9  85 98         		sta	secnum		; read just one block
880
 3388  F88AEB
881
 3389  F88AEB  4C D9 8B      		jmp	_dmald
882
 3390
883
 3391  F88AEE  80 4C         		bra	readsct2
884
 3392
885
 3393                        	; get identification device data
886
 3394                        	; in:	drive
887
 3395  F88AF0                	getid:
888
 3396  F88AF0                		ACC16			; set pointer for identification data
889
 3397  F88AF0  C2 20         		rep	#PMFLAG
890
 3398                        		.LONGA	on
891
 3399                        		.MNLIST
892
 3400  F88AF2  A9 00 90      		lda	#ID0ATA
893
 3401  F88AF5  A6 94         		ldx	drive
894
 3402  F88AF7  F0 03         		beq	?02
895
 3403  F88AF9  A9 00 92      		lda	#ID1ATA
896
 3404  F88AFC  85 A3         	?02:	sta	memp
897
 3405  F88AFE  85 A0         		sta	bufp
898
 3406  F88B00                		ACC08
899
 3407  F88B00  E2 20         		sep	#PMFLAG
900
 3408                        		.LONGA	off
901
 3409                        		.MNLIST
902
 3410  F88B02  A9 01         		lda	#^ID0ATA
903
 3411  F88B04  85 A5         		sta	memp+2
904
 3412  F88B06  85 A2         		sta	bufp+2
905
 3413  F88B08  64 9B         		stz	cmdfg		; no load command block registers
906
 3414  F88B0A  64 9C         		stz	ataop		; just read
907
 3415  F88B0C  64 9D         		stz	memfg		; no x-mem
908
 3416  F88B0E  A9 01         		lda	#1
909
 3417  F88B10  85 98         		sta	secnum		; read just one block
910
 3418  F88B12  A0 EC         		ldy	#IDENTDEV	; identify device command
911
 3419  F88B14  80 2E         		bra	piord		; pio mode read
912
 3420  F88B16
913
 3421                        	; compare buffer with ata device after writing
914
 3422  F88B16                	cmpsct:
915
 3423  F88B16  A5 A3         		lda	memp		; restore buffer
916
 3424  F88B18  85 A0         		sta	bufp
917
 3425  F88B1A  A5 A4         		lda	memp+1
918
 3426  F88B1C  85 A1         		sta	bufp+1
919
 3427  F88B1E  A5 A5         		lda	memp+2
920
 3428  F88B20  85 A2         		sta	bufp+2
921
 3429  F88B22  24 9D         		bit	memfg		; using x-mem?
922
 3430  F88B24  10 16         		bpl	readsct2	; no
923
 3431  F88B26  A9 40         		lda	#$40
924
 3432  F88B28  14 9D         		trb	memfg		; no restore x-mem setting when finish
925
 3433  F88B2A  A5 A8         		lda	xbnk
926
 3434  F88B2C  8D 28 FD      		sta	!PIA0+PIAPRA	; set bank
927
 3435  F88B2F  80 0B         		bra	readsct2
928
 3436
929
 3437                        	; read/compare N (0..256) sector(s) on ata device
930
 3438                        	; in:	drive=0 or 1 (ata #0 or ata #1 device)
931
  Tue Jul 17 11:00:15 2018                                                                                               Page   16
932
 
933
 
934
 
935
 
936
 3439                        	;	lba[0..2]=24 bits starting sector address
937
 3440                        	;	secnum=sector(s) count (if 0 -> 256 sect.)
938
 3441                        	;	memp=long pointer to input buffer
939
 3442                        	;	memfg<7>=flag buffer x-mem
940
 3443                        	;	memfg<6>=restore x-mem setting on exit
941
 3444                        	;	xbuf=x-mem buffer # if using x-mem ($0B40..$0FFF)
942
 3445                        	;	ataop<6>=flag compare data
943
 3446                        	; Out:	CF=0 if no error
944
 3447                        	;	CF=1 if error, A=error code, Y=error reg.
945
 3448                        	; use:	all
946
 3449  F88B31                	readsct:
947
 3450  F88B31  24 9D         		bit	memfg		; using x-mem?
948
 3451  F88B33  10 04         		bpl	?02		; no
949
 3452  F88B35  A9 40         		lda	#$40
950
 3453  F88B37  04 9D         		tsb	memfg		; restore x-mem setting when finish
951
 3454  F88B39  20 E8 8D      	?02:	jsr	setbuf		; set buffer pointer
952
 3455
953
 3456                        	; entry point for compare after writing
954
 3457  F88B3C                	readsct2:
955
 3458  F88B3C  A9 80         		lda	#$80
956
 3459  F88B3E  85 9B         		sta	cmdfg		; load command block registers
957
 3460  F88B40  85 9F         		sta	match		; good compare
958
 3461  F88B42  A0 20         		ldy	#READSECTOR	; read sector(s) command
959
 3462
960
 3463                        	; entry point for identify device
961
 3464  F88B44                	piord:
962
 3465  F88B44  20 78 8D      		jsr	sndcmd		; return X=ata offset
963
 3466  F88B47  A5 9A         		lda	ifrbit		; check interrupt
964
 3467  F88B49  2C CD FD      	?w1:	bit	VIA3+VIAIFR	; test CA1/CB1 transition
965
 3468  F88B4C  F0 FB         		beq	?w1		; wait interrupt assertion from ata device
966
 3469  F88B4E  8D CD FD      		sta	VIA3+VIAIFR	; clear interrupt flag
967
 3470  F88B51  BD A7 FD      	?w2:	lda	!ATAST,x	; wait BUSY bit=0
968
 3471  F88B54  30 FB         		bmi	?w2
969
 3472  F88B56  89 08         		bit	#ATADRQ		; ready to read a data block?
970
 3473  F88B58  D0 2E         		bne	?rdb		; yes, read first data block
971
 3474  F88B5A  89 21         		bit	#ATADFB+ATAERRB
972
 3475  F88B5C  D0 45         		bne	?chk		; error -- stop
973
 3476  F88B5E  80 F1         		bra	?w2		; some CF need time to set DRQ
974
 3477  F88B60  20 8B 8C      	?loop:	jsr	waitint		; wait interrupt assertion within timeout
975
 3478  F88B63  90 1A         		bcc	?w4		; ok, read status reg.
976
 3479  F88B65  A9 40         		lda	#$40		; no interrupt assertion
977
 3480  F88B67  04 9E         		tsb	drdyf		; signal this error
978
 3481  F88B69  BD AE FD      	?w3:	lda	!ATAALTST,x
979
 3482  F88B6C  89 08         		bit	#ATADRQ		; device expect more data block to transfer?
980
 3483  F88B6E  F0 05         		beq	?w30		; no...continue... keep error condition
981
 3484  F88B70  BD A8 FD      		lda	!ATADATA,x	; read wrong data and discard...
982
 3485  F88B73  80 F4         		bra	?w3		; ...until end of data block
983
 3486  F88B75  BD AE FD      	?w30:	lda	!ATAALTST,x
984
 3487  F88B78  BD A7 FD      		lda	!ATAST,x
985
 3488  F88B7B  10 19         		bpl	?tst
986
 3489  F88B7D  00 00         		brk
987
 3490  F88B7F  BD A7 FD      	?w4:	lda	!ATAST,x
988
 3491  F88B82  30 FB         		bmi	?w4
989
 3492  F88B84  89 08         		bit	#ATADRQ		; device expect more data block to transfer?
990
 3493  F88B86  F0 0E         		beq	?tst		; no... check error condition
991
 3494  F88B88  20 B9 8C      	?rdb:	jsr	rdblk		; read a block (256 words)
992
 3495  F88B8B  C6 99         	?nxt:	dec	seccnt		; update left blocks count #
993
  Tue Jul 17 11:00:15 2018                                                                                               Page   17
994
 
995
 
996
 
997
 
998
 3496  F88B8D  D0 D1         		bne	?loop		; continue until all sectors was readden
999
 3497  F88B8F  BD A7 FD      	?idle:	lda	!ATAST,x	; read status reg.
1000
 3498  F88B92  10 02         		bpl	?tst
1001
 3499  F88B94  00 00         		brk
1002
 3500  F88B96  24 9E         	?tst:	bit	drdyf		; test interrupt timeout error
1003
 3501  F88B98  50 09         		bvc	?chk		; no, so test error condition
1004
 3502  F88B9A  20 1F 8E      		jsr	devres		; reset device because read error
1005
 3503  F88B9D  A9 05         		lda	#ATA_DEVRES	; data loss while reading
1006
 3504  F88B9F  A9 FF         		lda	#$FF
1007
 3505  F88BA1  80 29         		bra	?err
1008
 3506  F88BA3  89 20         	?chk:	bit	#ATADFB		; device fault bit ?
1009
 3507  F88BA5  F0 04         		beq	?chk1		; no
1010
 3508  F88BA7  A9 03         		lda	#ATA_FAULT	; yes
1011
 3509  F88BA9  80 21         		bra	?err		; error
1012
 3510  F88BAB  89 01         	?chk1:	bit	#ATAERRB	; error bit ?
1013
 3511  F88BAD  F0 07         		beq	?chk2		; no... all seem good
1014
 3512  F88BAF  BC A1 FD      		ldy	!ATAERROR,x	; read error register
1015
 3513  F88BB2  A9 04         		lda	#ATA_EBIT	; error bits
1016
 3514  F88BB4  80 16         		bra	?err
1017
 3515  F88BB6  A4 99         	?chk2:	ldy	seccnt
1018
 3516  F88BB8  F0 07         		beq	?chk3
1019
 3517  F88BBA  20 1F 8E      		jsr	devres		; reset device because read error
1020
 3518  F88BBD  A9 02         		lda	#ATA_DLOSS	; data loss while reading
1021
 3519  F88BBF  80 0B         		bra	?err
1022
 3520  F88BC1  18            	?chk3:	clc			; assume no error
1023
 3521  F88BC2  24 9C         		bit	ataop		; was compare data operation?
1024
 3522  F88BC4  50 07         		bvc	?done		; no, exit (no error)
1025
 3523  F88BC6  A4 9F         		ldy	match		; all match?
1026
 3524  F88BC8  D0 03         		bne	?done		; ok, good compare
1027
 3525  F88BCA  A9 06         		lda	#ATA_VERF	; compare error
1028
 3526  F88BCC  38            	?err:	sec			; error flag
1029
 3527  F88BCD  24 9D         	?done:	bit	memfg		; using x-mem?
1030
 3528  F88BCF  10 07         		bpl	?rts		; no
1031
 3529  F88BD1  50 05         		bvc	?rts		; no restore x-mem setting
1032
 3530  F88BD3  A6 A9         		ldx	xsave
1033
 3531  F88BD5  9D 0A FC      		sta	!CRXME,x	; restore
1034
 3532  F88BD8  60            	?rts:	rts
1035
 3533
1036
 3534                        	; load DMA mbr/pbr
1037
 3535  F88BD9                	_dmald:
1038
 3536  F88BD9  64 A6         		stz	xbuf
1039
 3537  F88BDB  64 A7         		stz	xbuf+1
1040
 3538  F88BDD  64 AD         		stz	ncnt+1
1041
 3539  F88BDF  A9 FF         		lda	#$FF
1042
 3540  F88BE1  85 AC         		sta	ncnt
1043
 3541  F88BE3  20 10 8C      		jsr	dmardwr
1044
 3542  F88BE6  B0 27         		bcs	?100
1045
 3543  F88BE8  A9 08         		lda	#$08		; PB3 VIA3
1046
 3544  F88BEA  1C C0 FD      		trb	VIA3+VIAPRB	; enable 1Mb buffer
1047
 3545  F88BED  AD CF FD      		lda	!VIA3+VIAPRANH
1048
 3546  F88BF0  29 F8         		and	#$F8
1049
 3547  F88BF2  8D CF FD      		sta	!VIA3+VIAPRANH	; set bank
1050
 3548
1051
 3549  F88BF5  A0 00         		ldy	#0
1052
 3550  F88BF7  64 A0         		stz	bufp
1053
 3551  F88BF9  64 A1         		stz	bufp+1
1054
 3552  F88BFB  A9 02         		lda	#2
1055
  Tue Jul 17 11:00:15 2018                                                                                               Page   18
1056
 
1057
 
1058
 
1059
 
1060
 3553  F88BFD  85 A2         		sta	bufp+2
1061
 3554  F88BFF                		INDEX16
1062
 3555  F88BFF  C2 10         		rep	#PXFLAG
1063
 3556                        		.LONGI	on
1064
 3557                        		.MNLIST
1065
 3558  F88C01  A2 00 02      		ldx	#$200
1066
 3559  F88C04  B7 A0         	?10:	lda	[bufp],y
1067
 3560  F88C06  97 A3         		sta	[memp],y
1068
 3561  F88C08  C8            		iny
1069
 3562  F88C09  CA            		dex
1070
 3563  F88C0A  D0 F8         		bne	?10
1071
 3564  F88C0C                		INDEX08
1072
 3565  F88C0C  E2 10         		sep	#PXFLAG
1073
 3566                        		.LONGI	off
1074
 3567                        		.MNLIST
1075
 3568  F88C0E  18            		clc
1076
 3569  F88C0F  60            	?100:	rts
1077
 3570
1078
 3571                        	; read/write N (0..256) sector(s) on ata device in dma mode
1079
 3572                        	; in:	drive = 0 or 1 (ata #0 or ata #1 device)
1080
 3573                        	;	ataop = ata operation flag: <7>=0->read, 1->write
1081
 3574                        	;	lba[0..2] = 24 bits starting sector address
1082
 3575                        	;	secnum = sector(s) count (if 0 -> 256 sect.)
1083
 3576                        	;	xbuf = dma buffer #
1084
 3577                        	;	ncnt = words count # - 1
1085
 3578                        	; Out:	CF=0 if no error
1086
 3579                        	;	CF=1 if error, A=error code, Y=error reg.
1087
 3580                        	; use:	all
1088
 3581  F88C10                	dmardwr:
1089
 3582  F88C10  A9 80         		lda	#$80
1090
 3583  F88C12  85 9B         		sta	cmdfg		; load command block registers
1091
 3584  F88C14  A6 94         		ldx	drive
1092
 3585  F88C16  BF 9E 91 F8   		lda	>DMAREQ,x
1093
 3586  F88C1A  85 B1         		sta	wtmp+1		; check dmareq line
1094
 3587  F88C1C  20 FA 90      		jsr	dmaset		; dma setup
1095
 3588  F88C1F  A0 C8         		ldy	#READDMA	; read sector(s) command
1096
 3589  F88C21  24 9C         		bit	ataop
1097
 3590  F88C23  10 02         		bpl	?do
1098
 3591  F88C25  A0 CA         		ldy	#WRITEDMA	; write sector(s) command
1099
 3592  F88C27  20 78 8D      	?do:	jsr	sndcmd		; return X=ata offset
1100
 3593  F88C2A  64 99         		stz	seccnt
1101
 3594  F88C2C  EA            		nop
1102
 3595  F88C2D  EA            		nop
1103
 3596  F88C2E  EA            		nop
1104
 3597  F88C2F  EA            		nop
1105
 3598  F88C30  BF AE FD 00   		lda	>ATAALTST,x
1106
 3599  F88C34  BF A7 FD 00   	?w0:	lda	>ATAST,x	; wait
1107
 3600  F88C38  29 88         		and	#ATABSY+ATADRQ
1108
 3601  F88C3A  F0 25         		beq	?chk		; end - check error
1109
 3602  F88C3C
1110
 3603                        		;lda	!VIA3+VIAPRANH
1111
 3604                        		;and	wtmp+1		; dma request?
1112
 3605                        		;beq	?w0		; no
1113
 3606  F88C3C  AF 88 FD 00   		lda	>DMA0SR
1114
 3607  F88C40  25 B7         		and	dmareq
1115
 3608  F88C42  F0 F0         		beq	?w0
1116
 3609
1117
  Tue Jul 17 11:00:15 2018                                                                                               Page   19
1118
 
1119
 
1120
 
1121
 
1122
 3610  F88C44  A9 02         		lda	#$02		; enable dma
1123
 3611  F88C46  1C 0F FD      		trb	VIA0+VIAPRANH
1124
 3612
1125
 3613                        		;nop
1126
 3614                        		;nop
1127
 3615                        		;nop
1128
 3616                        		;nop
1129
 3617                        		;lda	ifrbit		; check interrupt
1130
 3618                        	;?w1:	bit	VIA3+VIAIFR	; test CA1/CB1 transition
1131
 3619                        	;	beq	?w1		; wait interrupt assertion from ata device
1132
 3620                        	;	sta	!VIA3+VIAIFR	; clear interrupt flag
1133
 3621
1134
 3622  F88C49  20 8B 8C      		jsr	waitint
1135
 3623  F88C4C  A9 02         		lda	#$02		; disable dma
1136
 3624  F88C4E  0C 0F FD      		tsb	VIA0+VIAPRANH
1137
 3625  F88C51  90 0A         		bcc	?tst		; seem good: error test
1138
 3626  F88C53
1139
 3627                        		; no interrupt whitin timeout
1140
 3628  F88C53  AF 88 FD 00   		lda	>DMA0SR		; clear status flag
1141
 3629  F88C57  8F 8D FD 00   		sta	>DMA0WMCLR	; reset dma controller
1142
 3630  F88C5B  80 23         		bra	?res		; data loss
1143
 3631  F88C5D
1144
 3632  F88C5D  BF A7 FD 00   	?tst:	lda	>ATAST,x	; clear interrupt
1145
 3633  F88C61  89 20         	?chk:	bit	#ATADFB		; device fault bit ?
1146
 3634  F88C63  F0 04         		beq	?chk1		; no
1147
 3635  F88C65  A9 03         		lda	#ATA_FAULT	; yes
1148
 3636  F88C67  80 20         		bra	?err		; error
1149
 3637  F88C69  89 01         	?chk1:	bit	#ATAERRB	; error bit ?
1150
 3638  F88C6B  F0 07         		beq	?chk2		; no... all seem good
1151
 3639  F88C6D  BC A1 FD      		ldy	!ATAERROR,x	; read error register
1152
 3640  F88C70  A9 04         		lda	#ATA_EBIT	; error bits
1153
 3641  F88C72  80 15         		bra	?err
1154
 3642  F88C74                	?chk2:
1155
 3643                        		; check TC on dma status
1156
 3644  F88C74  A5 B0         		lda	wtmp
1157
 3645  F88C76  A6 94         		ldx	drive
1158
 3646  F88C78  3F 9A 91 F8   		and	>DMACHNL,x
1159
 3647  F88C7C  F0 05         		beq	?loss		; data loss: no TC
1160
 3648  F88C7E
1161
 3649                        		;ldy	seccnt
1162
 3650                        		;beq	?chk3
1163
 3651  F88C7E  D0 07         		bne	?chk3
1164
 3652
1165
 3653  F88C80  20 1F 8E      	?res:	jsr	devres		; reset device because read error
1166
 3654  F88C83  A9 02         	?loss:	lda	#ATA_DLOSS	; data loss while reading
1167
 3655  F88C85  80 02         		bra	?err
1168
 3656  F88C87  18            	?chk3:	clc			; assume no error
1169
 3657  F88C88  60            		rts
1170
 3658  F88C89  38            	?err:	sec			; error flag
1171
 3659  F88C8A  60            		rts
1172
 3660
1173
 3661  F88C8B                	waitint:
1174
 3662  F88C8B  A9 20         		lda	#$20		; set T2 count PB6 pulse (1ms)
1175
 3663  F88C8D  0C 0B FD      		tsb	VIA0+VIAACR
1176
 3664  F88C90  A9 D0         		lda	#<INTTMO	; interrupt timeout
1177
 3665  F88C92  8D 08 FD      		sta	!VIA0+VIAT2CL
1178
 3666  F88C95  A9 07         		lda	#>INTTMO
1179
  Tue Jul 17 11:00:15 2018                                                                                               Page   20
1180
 
1181
 
1182
 
1183
 
1184
 3667  F88C97  8D 09 FD      		sta	!VIA0+VIAT2CH
1185
 3668  F88C9A  78            		sei
1186
 3669  F88C9B  A5 9A         	?10:	lda	ifrbit		; flag bit for test CA1/CB1
1187
 3670  F88C9D  2C CD FD      		bit	VIA3+VIAIFR
1188
 3671  F88CA0  D0 11         		bne	?20		; interrupt assertion (exit with CF=0)
1189
 3672  F88CA2  A9 20         		lda	#T2IFRB
1190
 3673  F88CA4  2C 0D FD      		bit	VIA0+VIAIFR
1191
 3674  F88CA7  F0 F2         		beq	?10		; wait for INTTMO ms
1192
 3675  F88CA9  A5 9A         		lda	ifrbit		; flag bit for test CA1/CB1
1193
 3676  F88CAB  2C CD FD      		bit	VIA3+VIAIFR
1194
 3677  F88CAE  D0 03         		bne	?20		; interrupt assertion
1195
 3678  F88CB0  58            		cli
1196
 3679  F88CB1  38            		sec			; timeout
1197
 3680  F88CB2  60            		rts
1198
 3681  F88CB3  8D CD FD      	?20:	sta	VIA3+VIAIFR	; clear interrupt flag
1199
 3682  F88CB6  58            		cli
1200
 3683  F88CB7  18            		clc
1201
 3684  F88CB8  60            		rts
1202
 3685
1203
 3686                        	;---------------------------------------------------------------------------
1204
 3687                        	; low level routines
1205
 3688                        	;---------------------------------------------------------------------------
1206
 3689
1207
 3690                        		.LONGA	off
1208
 3691                        		.LONGI	off
1209
 3692
1210
 3693                        	; read/compare data block (512 bytes) from ata device
1211
 3694                        	; in:	X=offset ata address
1212
 3695                        	;	ataop<6>=1 if compare, else read
1213
 3696                        	;	match=not null
1214
 3697                        	;	bufp=long pointer to input buffer
1215
 3698                        	;	drdyf<7>=1 if need test DRDY bit in alternate status
1216
 3699                        	;	memfg<7>=flag buffer in x-mem
1217
 3700                        	;out:	bufp updated
1218
 3701                        	;	match=0 if not match
1219
 3702                        	; use:	A,Y
1220
 3703  F88CB9                	rdblk:
1221
 3704  F88CB9  08            		php			; save I flag
1222
 3705  F88CBA  78            		sei			; disable interrupt
1223
 3706  F88CBB  A0 00         		ldy	#0		; buffer index
1224
 3707  F88CBD                		INDEX16			; X,Y 16 bit - XH,YH cleared
1225
 3708  F88CBD  C2 10         		rep	#PXFLAG
1226
 3709                        		.LONGI	on
1227
 3710                        		.MNLIST
1228
 3711  F88CBF  24 9C         		bit	ataop		; test bit 6: compare?
1229
 3712  F88CC1  70 16         		bvs	?12		; yes
1230
 3713  F88CC3
1231
 3714  F88CC3                		ACC16
1232
 3715  F88CC3  C2 20         		rep	#PMFLAG
1233
 3716                        		.LONGA	on
1234
 3717                        		.MNLIST
1235
 3718  F88CC5  BF A8 FD 00   	?02:	lda	>ATADATA,x	; latch data
1236
 3719  F88CC9  BD AA FD      		lda	!ATAPORT,x	; read latched data
1237
 3720  F88CCC  97 A0         		sta	[bufp],y
1238
 3721  F88CCE  C8            		iny
1239
 3722  F88CCF  C8            		iny
1240
 3723                        		;bit	drdyf		; test DRDY bit in alternate status?
1241
  Tue Jul 17 11:00:15 2018                                                                                               Page   21
1242
 
1243
 
1244
 
1245
 
1246
 3724                        		;bpl	?06		; no
1247
 3725                        	?04:	;bit	!ATAALTST-1,x	; wait DRDY bit high
1248
 3726                        		;bvc	?04
1249
 3727  F88CD0  C0 00 02      	?06:	cpy	#$0200
1250
 3728  F88CD3  90 F0         		bcc	?02		; loop 512 bytes
1251
 3729  F88CD5                		ACC08
1252
 3730  F88CD5  E2 20         		sep	#PMFLAG
1253
 3731                        		.LONGA	off
1254
 3732                        		.MNLIST
1255
 3733  F88CD7  80 4B         		bra	updp		; update bufp pointer
1256
 3734
1257
 3735                        		; compare data block
1258
 3736  F88CD9                	?12:	ACC16
1259
 3737  F88CD9  C2 20         		rep	#PMFLAG
1260
 3738                        		.LONGA	on
1261
 3739                        		.MNLIST
1262
 3740  F88CDB  BF A8 FD 00   		lda	>ATADATA,x	; read data low, latch data high
1263
 3741  F88CDF  BD AA FD      		lda	!ATAPORT,x	; read latched data
1264
 3742  F88CE2  D7 A0         		cmp	[bufp],y
1265
 3743  F88CE4                		ACC08
1266
 3744  F88CE4  E2 20         		sep	#PMFLAG
1267
 3745                        		.LONGA	off
1268
 3746                        		.MNLIST
1269
 3747  F88CE6  F0 02         		beq	?14
1270
 3748  F88CE8  64 9F         		stz	match		; no match
1271
 3749  F88CEA  C8            	?14:	iny
1272
 3750  F88CEB  C8            		iny
1273
 3751                        		;bit	drdyf		; test DRDY bit in alternate status?
1274
 3752                        		;bpl	?18		; no
1275
 3753                        	?16:	;bit	!ATAALTST,x	; wait DRDY bit high
1276
 3754                        		;bvc	?16
1277
 3755  F88CEC  C0 00 02      	?18:	cpy	#$0200
1278
 3756  F88CEF  90 E8         		bcc	?12		; loop 512 bytes
1279
 3757  F88CF1  80 31         		bra	updp		; update bufp pointer
1280
 3758
1281
 3759                        	; write data block (512 bytes) on ata device
1282
 3760                        	; In:	X=offset ata address
1283
 3761                        	;	bufp=long pointer to output buffer
1284
 3762                        	;	drdyf<7>=flag test DRDY bit in alternate status
1285
 3763                        	;	memfg<7>=flag buffer in x-mem
1286
 3764                        	; out:	bufp updated
1287
 3765                        	; use:	A,Y
1288
 3766  F88CF3                	wrblk:
1289
 3767                        		.LONGA	off
1290
 3768                        		.LONGI	off
1291
 3769
1292
 3770  F88CF3  08            		php			; save I flag
1293
 3771  F88CF4  78            		sei			; disable interrupt
1294
 3772  F88CF5  A0 00         		ldy	#0		; buffer index
1295
 3773  F88CF7
1296
 3774  F88CF7                		INDEX16			; X,Y 16 bit - XH,YH cleared
1297
 3775  F88CF7  C2 10         		rep	#PXFLAG
1298
 3776                        		.LONGI	on
1299
 3777                        		.MNLIST
1300
 3778
1301
 3779                        		;lda	#$20			; /MW0 high
1302
 3780                        		;trb	VIA1+VIAPRB
1303
  Tue Jul 17 11:00:15 2018                                                                                               Page   22
1304
 
1305
 
1306
 
1307
 
1308
 3781
1309
 3782  F88CF9                		ACC16
1310
 3783  F88CF9  C2 20         		rep	#PMFLAG
1311
 3784                        		.LONGA	on
1312
 3785                        		.MNLIST
1313
 3786                        	?02:	;ACC16
1314
 3787  F88CFB  B7 A0         		lda	[bufp],y	; read data
1315
 3788  F88CFD  9F AA FD 00   		sta	>ATAPORT,x	; latch data
1316
 3789                        		;ACC08
1317
 3790  F88D01
1318
 3791  F88D01  A9 00 00      		lda	#0			; /MW0 low
1319
 3792  F88D04  0C 00 00      		tsb	!0
1320
 3793  F88D07  A9 00 00      		lda	#0			; /MW0 low
1321
 3794  F88D0A  0C 00 00      		tsb	!0
1322
 3795  F88D0D  A9 00 00      		lda	#0			; /MW0 low
1323
 3796  F88D10  0C 00 00      		tsb	!0
1324
 3797
1325
 3798  F88D13  9F A8 FD 00   		sta	>ATADATA,x	; send data low + latched data high
1326
 3799  F88D17  C8            		iny
1327
 3800  F88D18  C8            		iny
1328
 3801                        		;lda	#$20			; /MW0 high
1329
 3802                        		;bit	$ff
1330
 3803                        		;bpl	?04
1331
 3804                        		;tsb	VIA1+VIAPRB
1332
 3805  F88D19
1333
 3806                        		;bit	drdyf		; test DRDY bit in alternate status?
1334
 3807                        		;bpl	?06		; no
1335
 3808                        	?04:	;lda	>ATAALTST-1,x
1336
 3809                        		;bit	!ATAALTST,x
1337
 3810  F88D19  BF AE FD 00   		lda	>ATAALTST,x
1338
 3811                        		;bmi	?04
1339
 3812                        		;bvc	?04
1340
 3813                        		;asl	a
1341
 3814                        		;bpl	?04		; wait DRDY bit high
1342
 3815
1343
 3816  F88D1D  C0 00 02      	?06:	cpy	#$0200
1344
 3817  F88D20  90 D9         		bcc	?02		; loop 512 bytes
1345
 3818  F88D22                		ACC08
1346
 3819  F88D22  E2 20         		sep	#PMFLAG
1347
 3820                        		.LONGA	off
1348
 3821                        		.MNLIST
1349
 3822                        		;lda	#$20			; /MW0 high
1350
 3823                        		;tsb	VIA1+VIAPRB
1351
 3824  F88D24
1352
 3825                        	; update bufp pointer after read/write data block
1353
 3826  F88D24                	updp:
1354
 3827                        		.LONGI	on
1355
 3828
1356
 3829  F88D24  A4 A1         		ldy	bufp+1		; update bufp
1357
 3830  F88D26  C8            		iny
1358
 3831  F88D27  C8            		iny
1359
 3832  F88D28  84 A1         		sty	bufp+1
1360
 3833  F88D2A  24 9D         		bit	memfg		; buffer in x-mem?
1361
 3834  F88D2C  10 0F         		bpl	?10		; no, all done
1362
 3835  F88D2E  A4 A0         		ldy	bufp
1363
 3836  F88D30  C0 00 40      		cpy	#XMSTOP		; still in x-mem window?
1364
 3837  F88D33  90 08         		bcc	?10		; yes, all done
1365
  Tue Jul 17 11:00:15 2018                                                                                               Page   23
1366
 
1367
 
1368
 
1369
 
1370
 3838  F88D35  A0 00 20      		ldy	#XMSTART	; restart at x-mem beginning window...
1371
 3839  F88D38  84 A0         		sty	bufp
1372
 3840  F88D3A  EE 28 FD      		inc	!PIA0+PIAPRA	; ...and at next x-mem bank
1373
 3841  F88D3D                	?10:	CPU08
1374
 3842  F88D3D  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1375
 3843                        		.LONGA	off
1376
 3844                        		.LONGI	off
1377
 3845                        		.MNLIST
1378
 3846  F88D3F  28            		plp			; restore I flag
1379
 3847  F88D40  60            		rts
1380
 3848
1381
 3849                        	; enable 8bit transfer
1382
 3850  F88D41                	set8:
1383
 3851  F88D41  A9 01         		lda	#$01
1384
 3852  F88D43  80 02         		bra	setmode
1385
 3853
1386
 3854  F88D45                	set16:
1387
 3855  F88D45  A9 81         		lda	#$81
1388
 3856
1389
 3857  F88D47                	setmode:
1390
 3858  F88D47  48            		pha
1391
 3859  F88D48  A6 94         		ldx	drive		; ata device #
1392
 3860  F88D4A  BF A0 91 F8   		lda	>IFRTST,x
1393
 3861  F88D4E  85 9A         		sta	ifrbit		; save right IFR bit to test
1394
 3862  F88D50  8A            		txa
1395
 3863  F88D51  F0 02         		beq	?02		; offset of ata 0
1396
 3864  F88D53  A2 10         		ldx	#ATAOFS		; offset of ata 1
1397
 3865  F88D55  9E AE FD      	?02:	stz	!ATACTRL,x	; enable ata device to assert interrupt
1398
 3866  F88D58  68            		pla
1399
 3867  F88D59  9D A1 FD      		sta	!ATAFEAT,x
1400
 3868  F88D5C  A5 9A         		lda	ifrbit
1401
 3869  F88D5E  8D CD FD      		sta	!VIA3+VIAIFR	; clear CA1/CB1 flag in IFR
1402
 3870  F88D61  A9 EF         		lda	#$EF		; command
1403
 3871  F88D63  9D A7 FD      		sta	!ATACMD,x	; store command
1404
 3872  F88D66  A5 9A         		lda	ifrbit
1405
 3873  F88D68  78            		sei
1406
 3874  F88D69  2C CD FD      	?10:	bit	!VIA3+VIAIFR
1407
 3875  F88D6C  F0 FB         		beq	?10
1408
 3876  F88D6E  58            		cli
1409
 3877  F88D6F  BD A7 FD      		lda	!ATAST,x
1410
 3878  F88D72  BD A1 FD      		lda	!ATAERROR,x
1411
 3879  F88D75  85 FF         		sta	$ff
1412
 3880  F88D77  60            		rts
1413
 3881
1414
 3882                        	; send a command to ata device
1415
 3883                        	; after sending a command will wait for interrupt
1416
 3884                        	; in:	Y=command
1417
 3885                        	;	drive=0 or 1 (ata #0 or ata #1 device)
1418
 3886                        	;	cmdfg<7>=flag load command block registers
1419
 3887                        	;	lba[0..2]=24 bits starting lba (if need)
1420
 3888                        	;	secnum=sector(s) count (if need)
1421
 3889                        	; out:	X=offset ata address
1422
 3890                        	;	irfbit=bit for test CA1/CB1 on VIA 1 (int. line for ata0/1)
1423
 3891                        	;	seccnt=sector(s) count while read/write block
1424
 3892                        	; use:	A,X,Y
1425
 3893  F88D78                	sndcmd:
1426
 3894  F88D78  A5 98         		lda	secnum
1427
  Tue Jul 17 11:00:15 2018                                                                                               Page   24
1428
 
1429
 
1430
 
1431
 
1432
 3895  F88D7A  85 99         		sta	seccnt		; save sector(s) count #
1433
 3896  F88D7C  A6 94         		ldx	drive		; ata device #
1434
 3897  F88D7E  BF A0 91 F8   		lda	>IFRTST,x
1435
 3898  F88D82  85 9A         		sta	ifrbit		; save right IFR bit to test
1436
 3899  F88D84  64 9E         		stz	drdyf
1437
 3900  F88D86  34 0E         		bit	atadev,x	; set drdy flag for C.F.
1438
 3901  F88D88  50 04         		bvc	?01
1439
 3902  F88D8A  A9 80         		lda	#$80
1440
 3903  F88D8C  85 9E         		sta	drdyf
1441
 3904  F88D8E  8A            	?01:	txa
1442
 3905  F88D8F  F0 02         		beq	?01a		; offset of ata 0
1443
 3906  F88D91  A2 10         		ldx	#ATAOFS		; offset of ata 1
1444
 3907  F88D93                	?01a:
1445
 3908  F88D93  A9 40         		lda	#$40
1446
 3909  F88D95  9F A6 FD 00   		sta	>ATADEV,x
1447
 3910
1448
 3911                        		;stz	!ATADEV,x
1449
 3912  F88D99  EA            		nop
1450
 3913  F88D9A  3C AE FD      	?01c:	bit	!ATAALTST,x	: wait device ready
1451
 3914  F88D9D  30 FB         		bmi	?01c
1452
 3915  F88D9F  50 F9         		bvc	?01c
1453
 3916  F88DA1
1454
 3917  F88DA1  A9 00         		lda	#0
1455
 3918  F88DA3  9F AE FD 00   		sta	>ATACTRL,x	; enable ata device to assert interrupt
1456
 3919  F88DA7
1457
 3920                        		;stz	!ATACTRL,x	; enable ata device to assert interrupt
1458
 3921  F88DA7  EA            		nop
1459
 3922  F88DA8  24 9B         		bit	cmdfg
1460
 3923  F88DAA  10 2B         		bpl	?15
1461
 3924  F88DAC
1462
 3925                        		;lda	#0		; dev. reg. for command that not need params
1463
 3926                        		;sta	!ATADEV,x
1464
 3927                        		;bit	cmdfg
1465
 3928                        		;bpl	?02a
1466
 3929  F88DAC  A9 40         	?02:	lda	#$40		; device 0 & lba is limited to 24 bits
1467
 3930  F88DAE  9F A6 FD 00   		sta	>ATADEV,x	; store dev. register
1468
 3931                        		;nop
1469
 3932                        		;nop
1470
 3933                        		;nop
1471
 3934                        		;nop
1472
 3935  F88DB2  3C AE FD      	?02a:	bit	!ATAALTST,x	: wait device ready
1473
 3936  F88DB5  30 FB         		bmi	?02a
1474
 3937  F88DB7  50 F9         		bvc	?02a
1475
 3938                        		;stz	!ATACTRL,x	; enable ata device to assert interrupt
1476
 3939                        		;nop
1477
 3940                        		;nop
1478
 3941                        		;lda	#0		; dev. reg. for command that not need params
1479
 3942                        		;bit	cmdfg
1480
 3943                        		;bpl	?04
1481
 3944                        		;lda	#$E0		; device 0 & lba is limited to 24 bits
1482
 3945                        		;lda	#$40
1483
 3946                        	?04:	;sta	>ATADEV,x	; store dev. register
1484
 3947                        	?06:	;sta	>ATADEV,x
1485
 3948                        		;bit	!ATAALTST,x	; wait device ready
1486
 3949                        		;bmi	?06
1487
 3950                        		;bvc	?06
1488
 3951                        		;bit	cmdfg		; will load command block register's?
1489
  Tue Jul 17 11:00:15 2018                                                                                               Page   25
1490
 
1491
 
1492
 
1493
 
1494
 3952                        		;bpl	?16		; no
1495
 3953  F88DB9  A5 99         		lda	seccnt		; store sectors count
1496
 3954  F88DBB  9F A2 FD 00   		sta	>ATASCTCNT,x
1497
 3955                        	?08:	;bit	!ATAALTST,x	; wait device ready
1498
 3956                        		;bmi	?08
1499
 3957                        		;bvc	?08
1500
 3958  F88DBF  A5 95         		lda	lba		; store starting sector
1501
 3959  F88DC1  9F A3 FD 00   		sta	>ATALBAL,x
1502
 3960                        	?10:	;bit	!ATAALTST,x	; wait device ready
1503
 3961                        		;bmi	?10
1504
 3962                        		;bvc	?10
1505
 3963  F88DC5  A5 96         		lda	lba+1
1506
 3964  F88DC7  9F A4 FD 00   		sta	>ATALBAM,x
1507
 3965                        	?12:	;bit	!ATAALTST,x	; wait device ready
1508
 3966                        		;bmi	?12
1509
 3967                        		;bvc	?12
1510
 3968  F88DCB  A5 97         		lda	lba+2
1511
 3969  F88DCD  9F A5 FD 00   		sta	>ATALBAH,x
1512
 3970                        	?14:	;bit	!ATAALTST,x	; wait device ready
1513
 3971                        		;bmi	?14
1514
 3972                        		;bvc	?14
1515
 3973  F88DD1  A9 40         		lda	#$40
1516
 3974  F88DD3  9F A6 FD 00   		sta	>ATADEV,x	; store dev. register
1517
 3975  F88DD7  3C AE FD      	?15:	bit	!ATAALTST,x	; wait device ready
1518
 3976  F88DDA  30 FB         		bmi	?15
1519
 3977  F88DDC  50 F9         		bvc	?15
1520
 3978
1521
 3979  F88DDE  A5 9A         	?16:	lda	ifrbit
1522
 3980  F88DE0  8D CD FD      		sta	!VIA3+VIAIFR	; clear CA1/CB1 flag in IFR
1523
 3981  F88DE3  98            		tya			; command
1524
 3982  F88DE4  9D A7 FD      		sta	!ATACMD,x	; store command
1525
 3983  F88DE7  60            		rts
1526
 3984
1527
 3985                        	; set buffer pointer
1528
 3986                        	; use: A,B,X
1529
 3987  F88DE8                	setbuf:
1530
 3988  F88DE8  A6 A5         		ldx	memp+2
1531
 3989  F88DEA  24 9D         		bit	memfg		; using x-mem?
1532
 3990  F88DEC                		ACC16
1533
 3991  F88DEC  C2 20         		rep	#PMFLAG
1534
 3992                        		.LONGA	on
1535
 3993                        		.MNLIST
1536
 3994  F88DEE  10 26         		bpl	?10		; no, just set bufp=memp
1537
 3995  F88DF0  A5 A6         		lda	xbuf		; x-mem buffer #
1538
 3996  F88DF2  0A            		asl	a		; x16 -> B=x-mem bank
1539
 3997  F88DF3  0A            		asl	a
1540
 3998  F88DF4  0A            		asl	a
1541
 3999  F88DF5  0A            		asl	a
1542
 4000  F88DF6  EB            		xba			; 00xx,10xx,20xx,...,E0xx,F0xx
1543
 4001  F88DF7  AA            		tax			; X=x-mem bank
1544
 4002  F88DF8  86 A8         		stx	xbnk		; save starting bank
1545
 4003  F88DFA  8E 28 FD      		stx	PIA0+PIAPRA	; set bank
1546
 4004  F88DFD  29 00 F0      		and	#$F000		; mask off
1547
 4005  F88E00  4A            		lsr	a		; 00xx,02xx,04xx,...,1Cxx,1Exx
1548
 4006  F88E01  4A            		lsr	a
1549
 4007  F88E02  4A            		lsr	a		; 0000,0200,0400,...,1C00,1E00
1550
 4008  F88E03  09 00 20      		ora	#XMSTART	; point to starting buffer
1551
  Tue Jul 17 11:00:15 2018                                                                                               Page   26
1552
 
1553
 
1554
 
1555
 
1556
 4009  F88E06  85 A3         		sta	memp
1557
 4010  F88E08  AE 0A FC      		ldx	CRXME		; save x-mem setting
1558
 4011  F88E0B  86 A9         		stx	xsave
1559
 4012  F88E0D  8E 0B FC      		stx	CRXMEON		; enable x-mem in window $012000 - $013FFF
1560
 4013  F88E10  A2 01         		ldx	#XMBANK
1561
 4014  F88E12  86 A5         		stx	memp+2
1562
 4015  F88E14  80 02         		bra	?20
1563
 4016  F88E16  A5 A3         	?10:	lda	memp		; set bufp=memp
1564
 4017  F88E18  85 A0         	?20:	sta	bufp
1565
 4018  F88E1A  86 A2         		stx	bufp+2
1566
 4019  F88E1C                		ACC08
1567
 4020  F88E1C  E2 20         		sep	#PMFLAG
1568
 4021                        		.LONGA	off
1569
 4022                        		.MNLIST
1570
 4023  F88E1E  60            		rts
1571
 4024
1572
 4025                        	; software reset on ata device
1573
 4026                        	; in:	X=offset ata address
1574
 4027  F88E1F                	devres:
1575
 4028  F88E1F  A9 04         		lda	#CTRLSRST	; software reset control
1576
 4029  F88E21  9D AE FD      		sta	!ATACTRL,x
1577
 4030  F88E24  20 55 8E      		jsr	?40		; delay 16uS (need at least 5uS)
1578
 4031  F88E27  9E AE FD      		stz	ATACTRL,x	; stop software reset
1579
 4032  F88E2A  20 3B 8E      		jsr	?20		; wait for 2.5ms
1580
 4033  F88E2D  20 5E 8E      		jsr	wbusy		; wait busy low
1581
 4034  F88E30  30 05         		bmi	?04		; device not ready
1582
 4035  F88E32  0A            		asl	a		; N=DRDY status bit
1583
 4036  F88E33  10 02         		bpl	?04		; device not ready
1584
 4037  F88E35  18            		clc
1585
 4038  F88E36  60            		rts
1586
 4039  F88E37  A9 01         	?04:	lda	#ATA_NOTREADY
1587
 4040  F88E39  38            		sec			; error
1588
 4041  F88E3A  60            		rts
1589
 4042
1590
 4043  F88E3B  A9 20         	?20:	lda	#$20		; timer 2.5mS
1591
 4044  F88E3D  1C 0B FD      		trb	VIA0+VIAACR
1592
 4045  F88E40  A9 0F         		lda	#<T2MS5
1593
 4046  F88E42  8D 08 FD      		sta	VIA0+VIAT2CL
1594
 4047  F88E45  A9 27         		lda	#>T2MS5
1595
 4048  F88E47  8D 09 FD      		sta	VIA0+VIAT2CH
1596
 4049  F88E4A                	?22:	TASKSW
1597
 4050  F88E4A  02 00         		cop	FN_TASKSW
1598
 4051  F88E4C  00            		.DB	$00
1599
 4052                        		.MNLIST
1600
 4053  F88E4D  A9 20         		lda	#T2IFRB
1601
 4054  F88E4F  2C 0D FD      		bit	VIA0+VIAIFR
1602
 4055  F88E52  F0 F6         		beq	?22
1603
 4056  F88E54  60            		rts
1604
 4057
1605
 4058  F88E55  A9 09         	?40:	lda	#9		; 16uS delay
1606
 4059  F88E57  3A            	?42:	dec	a
1607
 4060  F88E58  D0 FD         		bne	?42
1608
 4061  F88E5A  EA            		nop
1609
 4062  F88E5B  EA            		nop
1610
 4063  F88E5C  EA            		nop
1611
 4064  F88E5D  60            		rts
1612
 4065
1613
  Tue Jul 17 11:00:15 2018                                                                                               Page   27
1614
 
1615
 
1616
 
1617
 
1618
 4066                        	; wait for status bit busy low within BUSYTMO timeout
1619
 4067                        	; in:	X=ata # offset
1620
 4068                        	;	NF=0 if status bit busy low
1621
 4069                        	;	NF=1 if status bit busy high or if timeout
1622
 4070                        	; use:	A
1623
 4071  F88E5E                	wbusy:
1624
 4072  F88E5E  A9 20         		lda	#$20		; set T2 count PB6 pulse (1ms)
1625
 4073  F88E60  0C 0B FD      		tsb	VIA0+VIAACR
1626
 4074  F88E63  A9 D0         		lda	#<BUSYTMO	; timeout status bit busy
1627
 4075  F88E65  8D 08 FD      		sta	!VIA0+VIAT2CL
1628
 4076  F88E68  A9 07         		lda	#>BUSYTMO
1629
 4077  F88E6A  8D 09 FD      		sta	!VIA0+VIAT2CH
1630
 4078  F88E6D  BD A7 FD      	?10:	lda	!ATAST,x	; read status
1631
 4079  F88E70  10 0D         		bpl	?20		; OK - busy -> L, return NF = 0
1632
 4080  F88E72                		TASKSW			; switch task while wait
1633
 4081  F88E72  02 00         		cop	FN_TASKSW
1634
 4082  F88E74  00            		.DB	$00
1635
 4083                        		.MNLIST
1636
 4084  F88E75  A9 20         		lda	#T2IFRB
1637
 4085  F88E77  2C 0D FD      		bit	VIA0+VIAIFR	; test timeout
1638
 4086  F88E7A  F0 F1         		beq	?10		; loop
1639
 4087  F88E7C  BD A7 FD      		lda	!ATAST,x	; read status - return NF = busy bit
1640
 4088  F88E7F  60            	?20:	rts
1641
 4089
1642
 4090                        	; get device identification data
1643
 4091                        	; in:	drive
1644
 4092                        	; out:	CF=1 if error, A=error code
1645
 4093  F88E80                	ident:
1646
 4094  F88E80  A6 94         		ldx	drive
1647
 4095  F88E82  B5 0E         		lda	atadev,x
1648
 4096  F88E84  29 DF         		and	#11011111B
1649
 4097  F88E86  95 0E         		sta	atadev,x
1650
 4098  F88E88  29 9F         		and	#10011111B
1651
 4099  F88E8A  85 B6         		sta	tmpy		; hard disk flag
1652
 4100  F88E8C  8A            		txa
1653
 4101  F88E8D  0A            		asl	a
1654
 4102  F88E8E  0A            		asl	a
1655
 4103  F88E8F  AA            		tax
1656
 4104  F88E90  86 B0         		stx	wtmp		; index for atasec var. access
1657
 4105  F88E92                		ACC16
1658
 4106  F88E92  C2 20         		rep	#PMFLAG
1659
 4107                        		.LONGA	on
1660
 4108                        		.MNLIST
1661
 4109  F88E94  74 12         		stz	atasec,x	; clear atasec var.
1662
 4110  F88E96  74 14         		stz	atasec+2,x
1663
 4111  F88E98                		ACC08
1664
 4112  F88E98  E2 20         		sep	#PMFLAG
1665
 4113                        		.LONGA	off
1666
 4114                        		.MNLIST
1667
 4115  F88E9A  20 F0 8A      		jsr	getid
1668
 4116  F88E9D  B0 6E         		bcs	?10		; error
1669
 4117  F88E9F  A0 00         		ldy	#0
1670
 4118  F88EA1  98            		tya
1671
 4119  F88EA2                		INDEX16
1672
 4120  F88EA2  C2 10         		rep	#PXFLAG
1673
 4121                        		.LONGI	on
1674
 4122                        		.MNLIST
1675
  Tue Jul 17 11:00:15 2018                                                                                               Page   28
1676
 
1677
 
1678
 
1679
 
1680
 4123  F88EA4  18            	?02:	clc			; loop checksum computation
1681
 4124  F88EA5  77 A3         		adc	[memp],y
1682
 4125  F88EA7  C8            		iny
1683
 4126  F88EA8  C0 00 02      		cpy	#$200
1684
 4127  F88EAB  90 F7         		bcc	?02
1685
 4128  F88EAD  EB            		xba			; B = checksum
1686
 4129  F88EAE  88            		dey
1687
 4130  F88EAF  88            		dey
1688
 4131  F88EB0  B7 A3         		lda	[memp],y
1689
 4132  F88EB2  C9 A5         		cmp	#$A5		; valid signature checksum?
1690
 4133  F88EB4                		INDEX08
1691
 4134  F88EB4  E2 10         		sep	#PXFLAG
1692
 4135                        		.LONGI	off
1693
 4136                        		.MNLIST
1694
 4137  F88EB6  D0 03         		bne	?04		; no -- assume data ok
1695
 4138  F88EB8  EB            		xba			; checksum vill be zero
1696
 4139  F88EB9  D0 53         		bne	?15		; wrong checksum
1697
 4140  F88EBB  A0 14         	?04:	ldy	#10*2		; offset 'serial number' string
1698
 4141  F88EBD  A2 0A         		ldx	#10		; words length
1699
 4142  F88EBF  20 12 8F      		jsr	?50		; adjust string
1700
 4143  F88EC2  A0 2E         		ldy	#23*2		; offset 'firmware revision' string
1701
 4144  F88EC4  A2 04         		ldx	#4		; words length
1702
 4145  F88EC6  20 12 8F      		jsr	?50		; adjust string
1703
 4146  F88EC9  A0 36         		ldy	#27*2		; offset 'model name' string
1704
 4147  F88ECB  A2 14         		ldx	#20		; words length
1705
 4148  F88ECD  20 12 8F      		jsr	?50		; adjust string
1706
 4149  F88ED0  A2 14         		ldx	#10*2		; pointer to 'serial number' string
1707
 4150  F88ED2  A0 27         		ldy	#(10*2)+(10*2)-1	; pointer to end of string
1708
 4151  F88ED4  20 21 8F      		jsr	?60		; terminate string
1709
 4152  F88ED7  A2 36         		ldx	#27*2		; pointer to 'model name' string
1710
 4153  F88ED9  A0 5D         		ldy	#(27*2)+(20*2)-1	; pointer to end of string
1711
 4154  F88EDB  20 21 8F      		jsr	?60		; terminate string
1712
 4155  F88EDE  A0 78         		ldy	#60*2		; word 60/61: total sector's count #
1713
 4156  F88EE0  A6 B0         		ldx	wtmp
1714
 4157  F88EE2                		ACC16
1715
 4158  F88EE2  C2 20         		rep	#PMFLAG
1716
 4159                        		.LONGA	on
1717
 4160                        		.MNLIST
1718
 4161  F88EE4  B7 A3         		lda	[memp],y
1719
 4162  F88EE6  85 AA         		sta	nlba
1720
 4163  F88EE8  95 12         		sta	atasec,x	; store max. user sectors
1721
 4164  F88EEA  C8            		iny
1722
 4165  F88EEB  C8            		iny
1723
 4166  F88EEC  B7 A3         		lda	[memp],y
1724
 4167  F88EEE  85 AC         		sta	nlba+2
1725
 4168  F88EF0  95 14         		sta	atasec+2,x
1726
 4169  F88EF2  A7 A3         		lda	[memp]		; C.F. identification
1727
 4170  F88EF4  A6 94         		ldx	drive
1728
 4171  F88EF6  A4 B6         		ldy	tmpy		; hard disk flag
1729
 4172  F88EF8  C9 8A 84      		cmp	#$848A		; classic word 0 for C.F.
1730
 4173  F88EFB  F0 07         		beq	?06		; is C.F.
1731
 4174  F88EFD  C9 4A 04      		cmp	#$044A		; alternate word 0 for CF
1732
 4175  F88F00  F0 02         		beq	?06		; is C.F.
1733
 4176  F88F02  94 0E         		sty	atadev,x	; is H.D.
1734
 4177  F88F04                	?06:	ACC08
1735
 4178  F88F04  E2 20         		sep	#PMFLAG
1736
 4179                        		.LONGA	off
1737
  Tue Jul 17 11:00:15 2018                                                                                               Page   29
1738
 
1739
 
1740
 
1741
 
1742
 4180                        		.MNLIST
1743
 4181  F88F06  B5 0E         		lda	atadev,x
1744
 4182  F88F08  09 20         		ora	#$20		; flag identify ok
1745
 4183  F88F0A  95 0E         		sta	atadev,x
1746
 4184  F88F0C  18            		clc			; no error
1747
 4185  F88F0D  60            	?10:	rts
1748
 4186  F88F0E  A9 07         	?15:	lda	#ATA_IDCKS	; checksum error
1749
 4187  F88F10  38            		sec
1750
 4188  F88F11  60            		rts
1751
 4189
1752
 4190                        		; swap low byte with high byte in string
1753
 4191                        		; Y = string offset
1754
 4192                        		; X = words string length
1755
 4193  F88F12                	?50:	ACC16
1756
 4194  F88F12  C2 20         		rep	#PMFLAG
1757
 4195                        		.LONGA	on
1758
 4196                        		.MNLIST
1759
 4197  F88F14  B7 A3         	?52:	lda	[memp],y
1760
 4198  F88F16  EB            		xba
1761
 4199  F88F17  97 A3         		sta	[memp],y
1762
 4200  F88F19  C8            		iny
1763
 4201  F88F1A  C8            		iny
1764
 4202  F88F1B  CA            		dex
1765
 4203  F88F1C  D0 F6         		bne	?52
1766
 4204  F88F1E                		ACC08
1767
 4205  F88F1E  E2 20         		sep	#PMFLAG
1768
 4206                        		.LONGA	off
1769
 4207                        		.MNLIST
1770
 4208  F88F20  60            		rts
1771
 4209
1772
 4210                        		; terminate serial string and model string with null
1773
 4211                        		; Y=end of string
1774
 4212                        		; X=start of string
1775
 4213  F88F21  86 AE         	?60:	stx	tmp
1776
 4214  F88F23  B7 A3         	?62:	lda	[memp],y
1777
 4215  F88F25  C9 20         		cmp	#' '
1778
 4216  F88F27  D0 05         		bne	?64
1779
 4217  F88F29  88            		dey
1780
 4218  F88F2A  C4 AE         		cpy	tmp
1781
 4219  F88F2C  B0 F5         		bcs	?62
1782
 4220  F88F2E  C8            	?64:	iny
1783
 4221  F88F2F  A9 00         		lda	#0
1784
 4222  F88F31  97 A3         		sta	[memp],y
1785
 4223  F88F33  60            		rts
1786
 4224
1787
 4225                        	;--------------------------------------------------------------------------
1788
 4226                        	; init routines
1789
 4227                        	;---------------------------------------------------------------------------
1790
 4228
1791
 4229                        		.LONGA	off
1792
 4230                        		.LONGI	off
1793
 4231
1794
 4232                        	; check & init ata devices
1795
 4233  F88F34                	initata:
1796
 4234                        		.PUBLIC initata
1797
 4235
1798
 4236  F88F34                		ACC16
1799
  Tue Jul 17 11:00:15 2018                                                                                               Page   30
1800
 
1801
 
1802
 
1803
 
1804
 4237  F88F34  C2 20         		rep	#PMFLAG
1805
 4238                        		.LONGA	on
1806
 4239                        		.MNLIST
1807
 4240  F88F36  A9 00 88      		lda	#!MBR0ATA	; clear ident, MBR & PBR data mem
1808
 4241  F88F39  85 A0         		sta	bufp
1809
 4242  F88F3B  A2 01         		ldx	#^MBR0ATA
1810
 4243  F88F3D  86 A2         		stx	bufp+2
1811
 4244  F88F3F  A0 00         		ldy	#0
1812
 4245  F88F41                		INDEX16
1813
 4246  F88F41  C2 10         		rep	#PXFLAG
1814
 4247                        		.LONGI	on
1815
 4248                        		.MNLIST
1816
 4249  F88F43  98            		tya			; clear A
1817
 4250  F88F44  97 A0         	?02:	sta	[bufp],y
1818
 4251  F88F46  C8            		iny
1819
 4252  F88F47  C8            		iny
1820
 4253  F88F48  C0 00 0C      		cpy	#$0C00
1821
 4254  F88F4B  90 F7         		bcc	?02
1822
 4255  F88F4D                		CPU08
1823
 4256  F88F4D  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
1824
 4257                        		.LONGA	off
1825
 4258                        		.LONGI	off
1826
 4259                        		.MNLIST
1827
 4260  F88F4F  AA            		tax			; device #0
1828
 4261  F88F50  20 5F 8F      		jsr	?04
1829
 4262  F88F53                		TASKSW
1830
 4263  F88F53  02 00         		cop	FN_TASKSW
1831
 4264  F88F55  00            		.DB	$00
1832
 4265                        		.MNLIST
1833
 4266  F88F56  A2 01         		ldx	#1		; device #1
1834
 4267  F88F58  20 5F 8F      		jsr	?04
1835
 4268  F88F5B                		TASKSW
1836
 4269  F88F5B  02 00         		cop	FN_TASKSW
1837
 4270  F88F5D  00            		.DB	$00
1838
 4271                        		.MNLIST
1839
 4272  F88F5E  60            		rts
1840
 4273
1841
 4274                        	; check devices on bus ata
1842
 4275                        	; in:	X=device ata #
1843
 4276  F88F5F  86 94         	?04:	stx	drive
1844
 4277  F88F61  74 0E         		stz	atadev,x	; clear device flag
1845
 4278  F88F63  8A            		txa
1846
 4279  F88F64  F0 02         		beq	?06		; offset of ata #0=0
1847
 4280  F88F66  A2 10         		ldx	#ATAOFS
1848
 4281  F88F68  86 AF         	?06:	stx	ataofs
1849
 4282  F88F6A  20 3C 90      		jsr	?60		; print start msg
1850
 4283  F88F6D  A6 AF         		ldx	ataofs
1851
 4284  F88F6F  20 5E 8E      		jsr	wbusy		; wait for busy flag low
1852
 4285  F88F72  30 1B         		bmi	?10		; assume no device on ata #0
1853
 4286  F88F74  20 D3 8F      		jsr	?30		; check device signature
1854
 4287  F88F77
1855
 4288  F88F77  A9 00         		lda	#$00
1856
 4289  F88F79  9D A6 FD      		sta	!ATADEV,x	; store dev. register
1857
 4290
1858
 4291  F88F7C  B0 1B         		bcs	?15		; not found or not HD/CF
1859
 4292  F88F7E
1860
 4293          [01]          		.IFDEF 	MODE8
1861
  Tue Jul 17 11:00:15 2018                                                                                               Page   31
1862
 
1863
 
1864
 
1865
 
1866
 4294                        		jsr	set8
1867
 4295          [00]          		.ENDIF
1868
 4296  F88F7E
1869
 4297  F88F7E  20 80 8E      		jsr	ident		; identify device
1870
 4298  F88F81  B0 44         		bcs	?25		; error (A=error code)
1871
 4299  F88F83  24 55         		bit	BiosEnt
1872
 4300  F88F85  50 03         		bvc	?08		; skip
1873
 4301  F88F87  20 FD 8F      		jsr	?50		; print identification data
1874
 4302  F88F8A  20 1F 8E      	?08:	jsr	devres
1875
 4303                        		;jsr	chkmbr		; load&check MBR
1876
 4304  F88F8D  18            		clc			; no error
1877
 4305  F88F8E  60            		rts
1878
 4306
1879
 4307  F88F8F  20 B3 8F      	?10:	jsr	?20		; print 'device not found'
1880
 4308  F88F92                		SCNPRINT
1881
 4309  F88F92  02 01         		cop	$01
1882
 4310                        		.MNLIST
1883
 4311  F88F94  2E 0D 00      		.DB	'.', 13, 0
1884
 4312  F88F97  38            		sec
1885
 4313  F88F98  60            		rts
1886
 4314
1887
 4315  F88F99  20 B3 8F      	?15:	jsr	?20		; print 'device not found'
1888
 4316  F88F9C                		SCNPRINT
1889
 4317  F88F9C  02 01         		cop	$01
1890
 4318                        		.MNLIST
1891
 4319  F88F9E  20 6F 72 20 6E 		.DB	' or not H.D./C.F.', 13, 0
1892
               6F 74 20 48 2E
1893
               44 2E 2F 43 2E
1894
               46 2E 0D 00
1895
 4320  F88FB1  38            		sec
1896
 4321  F88FB2  60            		rts
1897
 4322
1898
 4323  F88FB3                	?20:	SCNPRINT
1899
 4324  F88FB3  02 01         		cop	$01
1900
 4325                        		.MNLIST
1901
 4326  F88FB5  64 65 76 69 63 		.DB	'device not found', $00
1902
               65 20 6E 6F 74
1903
               20 66 6F 75 6E
1904
               64 00
1905
 4327  F88FC6  60            		rts
1906
 4328
1907
 4329                        	?25:	; fail to identify device
1908
 4330  F88FC7  48            		pha			; error code
1909
 4331  F88FC8  4B            		phk
1910
 4332  F88FC9  F4 B4 91      		pea	#!STR2
1911
 4333  F88FCC  A9 05         		lda	#5
1912
 4334  F88FCE  48            		pha
1913
 4335  F88FCF                		BPRINTF
1914
 4336  F88FCF  02 11         		cop	$11
1915
 4337                        		.MNLIST
1916
 4338  F88FD1  38            		sec
1917
 4339  F88FD2  60            		rts
1918
 4340
1919
 4341                        	; check device signature after reset
1920
 4342                        	; in:	drive=ata #
1921
 4343                        	;	ataofs=ata # offset
1922
 4344                        	; out:	CF=0 if found device
1923
  Tue Jul 17 11:00:15 2018                                                                                               Page   32
1924
 
1925
 
1926
 
1927
 
1928
 4345                        	;	CF=1 if not device or not HD/CF
1929
 4346  F88FD3  A4 AF         	?30:	ldy	ataofs
1930
 4347  F88FD5  A2 03         		ldx	#3		; test signature device HD/CF
1931
 4348  F88FD7  BF A2 91 F8   	?34:	lda	>ATASGN,x
1932
 4349  F88FDB  D9 A2 FD      		cmp	!ATASCTCNT,y	; test signature
1933
 4350  F88FDE  D0 1B         		bne	?36		; no HD/CF
1934
 4351  F88FE0  C8            		iny
1935
 4352  F88FE1  CA            		dex
1936
 4353  F88FE2  10 F3         		bpl	?34
1937
 4354  F88FE4  B9 A2 FD      		lda	!ATASCTCNT,y	; device #
1938
 4355  F88FE7  29 10         		and	#$10		; mask dev bit
1939
 4356  F88FE9  D0 10         		bne	?36		; will be 0
1940
 4357  F88FEB  C8            		iny
1941
 4358  F88FEC  B9 A2 FD      		lda	!ATASCTCNT,y	; status reg.
1942
 4359  F88FEF  29 40         		and	#ATADRDY	; DRDY bit will be set
1943
 4360  F88FF1  F0 08         		beq	?36		; device not found or not HD/CF
1944
 4361  F88FF3  A9 C0         		lda	#$C0		; flag device
1945
 4362  F88FF5  A6 94         		ldx	drive		; for now force C.F type
1946
 4363  F88FF7  95 0E         		sta	atadev,x	; found device on ata #
1947
 4364  F88FF9  18            		clc
1948
 4365  F88FFA  60            		rts
1949
 4366  F88FFB  38            	?36:	sec
1950
 4367  F88FFC  60            		rts
1951
 4368
1952
 4369                        	?50:	; print identification string
1953
 4370  F88FFD  A6 94         		ldx	drive
1954
 4371  F88FFF  34 0E         		bit	atadev,x
1955
 4372  F89001                		ACC16CLC
1956
 4373  F89001  C2 21         		rep	#(PMFLAG.OR.PCFLAG)
1957
 4374                        		.LONGA	on
1958
 4375                        		.MNLIST
1959
 4376  F89003  A9 DA 91      		lda	#!STR3
1960
 4377  F89006  50 03         		bvc	?51
1961
 4378  F89008  A9 E8 91      		lda	#!STR4
1962
 4379  F8900B  85 B0         	?51:	sta	wtmp		; H.D or C.F string
1963
 4380  F8900D  A9 36 00      		lda	#27*2
1964
 4381  F89010  65 A3         		adc	memp
1965
 4382  F89012  85 A0         		sta	bufp		; model name string
1966
 4383  F89014  A5 AA         		lda	nlba
1967
 4384  F89016  85 95         		sta	lba
1968
 4385  F89018  A5 AC         		lda	nlba+2
1969
 4386  F8901A  A2 0B         		ldx	#11		; divide by 2048 (11 shift)...
1970
 4387  F8901C  4A            	?52:	lsr	a		; ... and get rounded size in Mb
1971
 4388  F8901D  66 95         		ror	lba
1972
 4389  F8901F  CA            		dex
1973
 4390  F89020  D0 FA         		bne	?52
1974
 4391  F89022  85 97         		sta	lba+2
1975
 4392  F89024  48            		pha			; 2
1976
 4393  F89025  A5 95         		lda	lba
1977
 4394  F89027  48            		pha			; 2
1978
 4395  F89028                		ACC08
1979
 4396  F89028  E2 20         		sep	#PMFLAG
1980
 4397                        		.LONGA	off
1981
 4398                        		.MNLIST
1982
 4399  F8902A  A5 A5         		lda	memp+2
1983
 4400  F8902C  48            		pha			; 1
1984
 4401  F8902D  D4 A0         		pei	(bufp)		; 2
1985
  Tue Jul 17 11:00:15 2018                                                                                               Page   33
1986
 
1987
 
1988
 
1989
 
1990
 4402  F8902F  4B            		phk			; 1
1991
 4403  F89030  D4 B0         		pei	(wtmp)		; 2
1992
 4404  F89032  4B            		phk			; 1
1993
 4405  F89033  F4 F6 91      		pea	#!STRF1		; 2
1994
 4406  F89036  A9 0E         		lda	#14		; 1
1995
 4407  F89038  48            		pha
1996
 4408  F89039                		BPRINTF
1997
 4409  F89039  02 11         		cop	$11
1998
 4410                        		.MNLIST
1999
 4411  F8903B  60            		rts
2000
 4412
2001
 4413                        	; print check message at boot
2002
 4414                        	; in:	drive=ata # device
2003
 4415  F8903C  24 55         	?60:	bit	BiosEnt
2004
 4416  F8903E  50 0C         		bvc	?62		; skip
2005
 4417  F89040  A6 94         		ldx	drive
2006
 4418  F89042  DA            		phx
2007
 4419  F89043  4B            		phk
2008
 4420  F89044  F4 A6 91      		pea	#!STR1
2009
 4421  F89047  A9 05         		lda	#5
2010
 4422  F89049  48            		pha
2011
 4423  F8904A                		BPRINTF
2012
 4424  F8904A  02 11         		cop	$11
2013
 4425                        		.MNLIST
2014
 4426  F8904C  60            	?62:	rts
2015
 4427
2016
 4428                        	; long version
2017
 4429  F8904D                	lchkmbr:
2018
 4430                        		.PUBLIC lchkmbr
2019
 4431
2020
 4432  F8904D  8B            		phb
2021
 4433  F8904E  0B            		phd
2022
 4434  F8904F  F4 00 00      		pea	#0
2023
 4435  F89052  2B            		pld
2024
 4436  F89053  A9 00         		lda	#0
2025
 4437  F89055  48            		pha
2026
 4438  F89056  AB            		plb
2027
 4439  F89057  86 94         		stx	drive
2028
 4440  F89059  20 70 90      		jsr	chkmbr
2029
 4441  F8905C  2B            		pld
2030
 4442  F8905D  AB            		plb
2031
 4443  F8905E  6B            		rtl
2032
 4444
2033
 4445                        	; check mbr for usb flash disk
2034
 4446  F8905F                	chkumbr:
2035
 4447                        		.PUBLIC chkumbr
2036
 4448
2037
 4449  F8905F  86 94         		stx	drive
2038
 4450  F89061                		ACC16			; set pointer for MBR
2039
 4451  F89061  C2 20         		rep	#PMFLAG
2040
 4452                        		.LONGA	on
2041
 4453                        		.MNLIST
2042
 4454  F89063  A9 00 94      		lda	#MBR0USB
2043
 4455  F89066  85 A3         		sta	memp
2044
 4456  F89068                		ACC08
2045
 4457  F89068  E2 20         		sep	#PMFLAG
2046
 4458                        		.LONGA	off
2047
  Tue Jul 17 11:00:15 2018                                                                                               Page   34
2048
 
2049
 
2050
 
2051
 
2052
 4459                        		.MNLIST
2053
 4460  F8906A  A9 01         		lda	#^MBR0USB
2054
 4461  F8906C  85 A5         		sta	memp+2
2055
 4462  F8906E  80 06         		bra	chkmbr2
2056
 4463
2057
 4464                        	; load & check MBR on device
2058
 4465                        	; in:	drive
2059
 4466                        	; out:	CF=1 if error, A=error code
2060
 4467  F89070                	chkmbr:
2061
 4468  F89070  20 95 8A      		jsr	getmbr		; load MBR
2062
 4469  F89073  90 01         		bcc	chkmbr2
2063
 4470  F89075  60            		rts			; error
2064
 4471  F89076
2065
 4472                        	; entry point for usb flash disk
2066
 4473  F89076                	chkmbr2:
2067
 4474  F89076  A9 10         		lda	#$10		; set bit mbr loaded
2068
 4475  F89078  85 AE         		sta	tmp
2069
 4476  F8907A                		CPU16
2070
 4477  F8907A  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
2071
 4478                        		.LONGA	on
2072
 4479                        		.LONGI	on
2073
 4480                        		.MNLIST
2074
 4481  F8907C  A0 FE 01      		ldy	#$01FE		; signature pointer
2075
 4482  F8907F  B7 A3         		lda	[memp],y
2076
 4483  F89081  85 B2         		sta	mbrsgn		; mbr signature
2077
 4484  F89083  A0 C2 01      		ldy	#$01C2		; partition type pointer
2078
 4485  F89086  B7 A3         		lda	[memp],y
2079
 4486  F89088  85 B0         		sta	wtmp		; partition type
2080
 4487  F8908A  A0 C6 01      		ldy	#$01C6		; partition start pointer
2081
 4488  F8908D  B7 A3         		lda	[memp],y
2082
 4489  F8908F  85 AA         		sta	nlba		; partition start
2083
 4490  F89091  C8            		iny
2084
 4491  F89092  C8            		iny
2085
 4492  F89093  B7 A3         		lda	[memp],y
2086
 4493  F89095  85 AC         		sta	nlba+2
2087
 4494  F89097  A0 BE 01      		ldy	#$01BE		; partition flag pointer
2088
 4495  F8909A  B7 A3         		lda	[memp],y
2089
 4496  F8909C  85 B4         		sta	mbrfg		; partition flag
2090
 4497  F8909E  A5 B2         		lda	mbrsgn
2091
 4498  F890A0  C9 55 AA      		cmp	#$AA55
2092
 4499  F890A3                		CPU08
2093
 4500  F890A3  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
2094
 4501                        		.LONGA	off
2095
 4502                        		.LONGI	off
2096
 4503                        		.MNLIST
2097
 4504  F890A5  D0 49         		bne	?20		; invalid mbr signature
2098
 4505  F890A7  A9 18         		lda	#$18		; add valid mbr signature flag
2099
 4506  F890A9  85 AE         		sta	tmp
2100
 4507  F890AB  A5 B4         		lda	mbrfg
2101
 4508  F890AD  F0 02         		beq	?vv
2102
 4509  F890AF  10 3F         		bpl	?20		; first partition invalid
2103
 4510  F890B1  A9 1C         	?vv:	lda	#$1C		; add active partition flag
2104
 4511  F890B3  85 AE         		sta	tmp
2105
 4512  F890B5  A5 94         		lda	drive
2106
 4513  F890B7  0A            		asl	a
2107
 4514  F890B8  0A            		asl	a
2108
 4515  F890B9  AA            		tax			; index for access to atambr var
2109
  Tue Jul 17 11:00:15 2018                                                                                               Page   35
2110
 
2111
 
2112
 
2113
 
2114
 4516  F890BA  A5 B0         		lda	wtmp		; partition type
2115
 4517  F890BC  A8            		tay
2116
 4518  F890BD  95 25         		sta	atambr+3,x	; store partition type
2117
 4519  F890BF  A5 AC         		lda	nlba+2		; store partition start
2118
 4520  F890C1  95 24         		sta	atambr+2,x
2119
 4521  F890C3  A5 AB         		lda	nlba+1
2120
 4522  F890C5  95 23         		sta	atambr+1,x
2121
 4523  F890C7  A5 AA         		lda	nlba
2122
 4524  F890C9  95 22         		sta	atambr,x
2123
 4525  F890CB  A5 AD         		lda	nlba+3		; must be 0
2124
 4526  F890CD  D0 21         		bne	?20
2125
 4527  F890CF  C0 06         		cpy	#$06		; just FAT16 type
2126
 4528  F890D1  F0 08         		beq	?10
2127
 4529  F890D3  C0 04         		cpy	#$04		; FAT 16 for disk less than 32Mb
2128
 4530  F890D5  F0 04         		beq	?10
2129
 4531  F890D7  C0 0E         		cpy	#$0E
2130
 4532  F890D9  D0 15         		bne	?20
2131
 4533  F890DB                	?10:	CPU16
2132
 4534  F890DB  C2 30         		rep	#(PMFLAG.OR.PXFLAG)
2133
 4535                        		.LONGA	on
2134
 4536                        		.LONGI	on
2135
 4537                        		.MNLIST
2136
 4538  F890DD  A0 CA 01      		ldy	#$01CA		; partition sec's count pointer
2137
 4539  F890E0  B7 A3         		lda	[memp],y
2138
 4540  F890E2  95 32         		sta	ataprt,x
2139
 4541  F890E4  C8            		iny
2140
 4542  F890E5  C8            		iny
2141
 4543  F890E6  B7 A3         		lda	[memp],y
2142
 4544  F890E8  95 34         		sta	ataprt+2,x
2143
 4545  F890EA                		CPU08
2144
 4546  F890EA  E2 30         		sep	#(PMFLAG.OR.PXFLAG)
2145
 4547                        		.LONGA	off
2146
 4548                        		.LONGI	off
2147
 4549                        		.MNLIST
2148
 4550  F890EC  A9 1D         		lda	#$1D		; add valid partition type
2149
 4551  F890EE  85 AE         		sta	tmp
2150
 4552  F890F0  A6 94         	?20:	ldx	drive		; update device flag
2151
 4553  F890F2  B5 0E         		lda	atadev,x
2152
 4554  F890F4  05 AE         		ora	tmp
2153
 4555  F890F6  95 0E         		sta	atadev,x
2154
 4556  F890F8  18            		clc
2155
 4557  F890F9  60            	?30:	rts
2156
 4558
2157
 4559                        	; dma setup for a transfer cycle on channel 1/2
2158
 4560                        	; in:	drive = 0 or 1 (ata #0 or ata #1 device)
2159
 4561                        	;	ataop = ata operation flag: <7>=0->read, 1->write
2160
 4562                        	;	ncnt = words count - 1 #
2161
 4563                        	;	xbuf = dma buffer # ($0000..$07FF)
2162
 4564  F890FA                	dmaset:
2163
 4565                        		; dma buffer is organized in 8 x 128Kb banks or 8 x 64Kw banks
2164
 4566                        		; PB0..PB2 of VIA3 set MA16..MA18 lines of 512Kw ram (DMA access)
2165
 4567                        		;
2166
 4568  F890FA  AF 88 FD 00   		lda	>DMA0SR		; clear status flag
2167
 4569  F890FE  8F 8D FD 00   		sta	>DMA0WMCLR
2168
 4570  F89102
2169
 4571  F89102  A9 00         		lda	#$00
2170
 4572  F89104  8F 88 FD 00   		sta	>DMA0WCMD
2171
  Tue Jul 17 11:00:15 2018                                                                                               Page   36
2172
 
2173
 
2174
 
2175
 
2176
 4573  F89108
2177
 4574  F89108  AD C0 FD      		lda	!VIA3+VIAPRB	; set bank
2178
 4575  F8910B  29 E8         		and	#11101000B	; mask off 3 lower's bits, clear PB4 (ata 0)
2179
 4576  F8910D  05 A7         		ora	xbuf+1		; high byte of buffer # select the bank
2180
 4577  F8910F  09 20         		ora	#00100000B	; set /FDC line high (ata dma access)
2181
 4578  F89111  A6 94         		ldx	drive
2182
 4579  F89113  F0 02         		beq	?via		; select ata 0
2183
 4580  F89115  09 10         		ora	#00010000B	; select ata 1 (PB4 high)
2184
 4581  F89117  8D C0 FD      	?via:	sta	!VIA3+VIAPRB	; set bank & ata #
2185
 4582  F8911A  BF 9A 91 F8   		lda	>DMACHNL,x
2186
 4583  F8911E  85 B0         		sta	wtmp		; dma channel
2187
 4584  F89120  09 04         		ora	#$04
2188
 4585  F89122  8F 8A FD 00   		sta	>DMA0WMSKB	; mask off bit channel 1/2
2189
 4586  F89126  BF 9C 91 F8   		lda	>DMAREQB,x
2190
 4587  F8912A  85 B7         		sta	dmareq
2191
 4588  F8912C  A9 04         		lda	#WRITETRASF
2192
 4589  F8912E  24 9C         		bit	ataop
2193
 4590  F89130  10 02         		bpl	?set		; read: dma read ata port and write buffer
2194
 4591  F89132  A9 08         		lda	#READTRASF	; write: dma read buffer and write to ata
2195
 4592  F89134  05 B0         	?set:	ora	wtmp		; channel -  A=transfer mode
2196
 4593  F89136  8F 8B FD 00   		sta	>DMA0MODE	; set DMA transfer mode
2197
 4594                        		;lda	xbuf		; high address
2198
 4595  F8913A  9B            		txy
2199
 4596  F8913B  8F 8C FD 00   		sta	>DMA0WCLRFF	; clear F/F
2200
 4597  F8913F  D0 1F         		bne	?chn2		; set channel 2
2201
 4598  F89141
2202
 4599                        		; set channel 1
2203
 4600  F89141  A9 00         		lda	#0
2204
 4601  F89143  8F 82 FD 00   		sta	>DMAC0+DMAADDR1	; store low buffer address
2205
 4602  F89147  A5 A6         		lda	xbuf		; high address
2206
 4603  F89149  8F 82 FD 00   		sta	>DMAC0+DMAADDR1	; store high buffer address
2207
 4604  F8914D  EA            		nop
2208
 4605  F8914E  8F 8C FD 00   		sta	>DMA0WCLRFF	; clear F/F
2209
 4606  F89152  A5 AC         		lda	ncnt		; low count
2210
 4607  F89154  8F 83 FD 00   		sta	>DMAC0+DMACNT1	; store low count
2211
 4608  F89158  A5 AD         		lda	ncnt+1		; high count
2212
 4609  F8915A  8F 83 FD 00   		sta	>DMAC0+DMACNT1	; store high count
2213
 4610  F8915E  80 1D         		bra	?cnt
2214
 4611  F89160
2215
 4612                        		; set channel 2
2216
 4613  F89160  A9 00         	?chn2:	lda	#0
2217
 4614  F89162  8F 84 FD 00   		sta	>DMAC0+DMAADDR2	; store low buffer address
2218
 4615  F89166  A5 A6         		lda	xbuf		; high address
2219
 4616  F89168  8F 84 FD 00   		sta	>DMAC0+DMAADDR2	; store high buffer address
2220
 4617  F8916C  EA            		nop
2221
 4618  F8916D  8F 8C FD 00   		sta	>DMA0WCLRFF	; clear F/F
2222
 4619  F89171  A5 AC         		lda	ncnt		; low count
2223
 4620  F89173  8F 85 FD 00   		sta	>DMAC0+DMACNT2	; store low count
2224
 4621  F89177  A5 AD         		lda	ncnt+1		; high count
2225
 4622  F89179  8F 85 FD 00   		sta	>DMAC0+DMACNT2	; store high count
2226
 4623  F8917D  8F 8C FD 00   	?cnt:	sta	>DMA0WCLRFF	; clear F/F
2227
 4624  F89181  A5 B0         		lda	wtmp
2228
 4625  F89183  8F 8A FD 00   		sta	>DMA0WMSKB	; un-mask bit channel 1/2
2229
 4626  F89187  A9 04         		lda	#00000100B	; VIA0 PA3 set dma direction
2230
 4627  F89189  24 9C         		bit	ataop
2231
 4628  F8918B  30 04         		bmi	?dir		; clear direction (write to ata)
2232
 4629  F8918D  0C 0F FD      		tsb	VIA0+VIAPRANH	; set direction (write to mem)
2233
  Tue Jul 17 11:00:15 2018                                                                                               Page   37
2234
 
2235
 
2236
 
2237
 
2238
 4630  F89190  60            		rts
2239
 4631  F89191  1C 0F FD      	?dir:	trb	VIA0+VIAPRANH	; clear direction
2240
 4632  F89194  60            		rts
2241
 4633  F89195
2242
 4634                        	;--------------------------------------------------------------------------
2243
 4635                        	; tables
2244
 4636                        	;---------------------------------------------------------------------------
2245
 4637
2246
 4638                        	; operation flag (read, verify, write)
2247
 4639  F89195                	OPTAB:
2248
 4640  F89195  00 40 80      		.DB	$00, $40, $80
2249
 4641
2250
 4642                        	; dma operations: read, write
2251
 4643  F89198                	OPTAB2:
2252
 4644  F89198  00 80         		.DB	$00, $80
2253
 4645
2254
 4646                        	; dma channel related to drive #
2255
 4647  F8919A                	DMACHNL:
2256
 4648  F8919A  01 02         		.DB	$01, $02
2257
 4649
2258
 4650                        	; dma channel request bit related to drive #
2259
 4651  F8919C                	DMAREQB:
2260
 4652  F8919C  20 40         		.DB	$20, $40
2261
 4653
2262
 4654                        	; DMAREQ bit (PA7, PA6)
2263
 4655  F8919E                	DMAREQ:
2264
 4656  F8919E  80 40         		.DB	$80, $40
2265
 4657
2266
 4658                        	; for test VIA1 IFR (interrupt from ata device)
2267
 4659  F891A0                	IFRTST:
2268
 4660  F891A0  02 01         		.DB	CA1IFRB, CA2IFRB
2269
 4661
2270
 4662                        	; HD/CF signature (in reverse order)
2271
 4663  F891A2                	ATASGN:
2272
 4664  F891A2  00 00 01 01   		.DB	$00, $00, $01, $01
2273
 4665
2274
 4666  F891A6                	STR1:
2275
 4667  F891A6  61 74 61 20 20 		.DB	'ata   #%bu...', 0
2276
               20 23 25 62 75
2277
               2E 2E 2E 00
2278
 4668
2279
 4669  F891B4                	STR2:
2280
 4670  F891B4  66 61 69 6C 20 		.DB	'fail to identify device (error %bu).', 13, 0
2281
               74 6F 20 69 64
2282
               65 6E 74 69 66
2283
               79 20 64 65 76
2284
               69 63 65 20 28
2285
               65 72 72 6F 72
2286
               20 25 62 75 29
2287
               2E 0D 00
2288
 4671
2289
 4672  F891DA                	STR3:
2290
 4673  F891DA  48 61 72 64 20 		.DB	'Hard Disk    ', 0
2291
               44 69 73 6B 20
2292
               20 20 20 00
2293
 4674
2294
 4675  F891E8                	STR4:
2295
  Tue Jul 17 11:00:15 2018                                                                                               Page   38
2296
 
2297
 
2298
 
2299
 
2300
 4676  F891E8  43 6F 6D 70 61 		.DB	'Compact Flash', 0
2301
               63 74 20 46 6C
2302
               61 73 68 00
2303
 4677  F891F6
2304
 4678  F891F6                	STRF1:
2305
 4679  F891F6  25 73 20 25 2D 		.DB	'%s %-42.41s %,7u Mb', 13, 0
2306
               34 32 2E 34 31
2307
               73 20 25 2C 37
2308
               75 20 4D 62 0D
2309
               00
2310
 4680
2311
 4681                        	; string's address (drive # indexed)
2312
 4682  F8920B                	DSKMODEL:
2313
 4683  F8920B  00 47 8E AE   		.DB	<_atamod0, <_atamod1, <_usbdsc0, <_usbdsc1
2314
 4684
2315
 4685  F8920F                	DSKMODELH:
2316
 4686  F8920F  00 00 00 00   		.DB	>_atamod0, >_atamod1, >_usbdsc0, >_usbdsc1
2317
 4687  F89213
2318
 4688  F89213                	DSKSER:
2319
 4689  F89213  29 70         		.DB	<_ataser0, <_ataser1
2320
 4690
2321
 4691  F89215                	DSKSERH:
2322
 4692  F89215  00 00         		.DB	>_ataser0, >_ataser1
2323
 4693  F89217
2324
 4694  F89217                	DSKREV:
2325
 4695  F89217  3E 85         		.DB	<_atarev0, <_atarev1
2326
 4696
2327
 4697  F89219                	DSKREVH:
2328
 4698  F89219  00 00         		.DB	>_atarev0, >_atarev1
2329
 
2330
 
2331
             Lines Assembled : 4510                  Errors : 0
2332
 
2333
 
2334