0
|
1 PROCEDURE IDE_detect
|
|
2 (* IDE identify program
|
|
3 (* Do not have IDE driver enabled
|
|
4 (* while running this program!
|
|
5 (* Copyright 1996 By Jim Hathaway
|
|
6 (* Revised version 2 by L. Curtis Boyle, May, 1999
|
|
7 (* Version 2.1 by L. Curtis Boyle, Oct. 13/1999 - to handle ATAPI
|
|
8 (* Slight changes Oct. 20/1999 to show # of sectors in both hex & decimal
|
|
9 (* Changed to make it easier for changing controller address, and for handling
|
|
10 (* both the Master & Slave drives
|
|
11 (* - also bug fix (LBA mode was not detected correctly)
|
|
12 DIM bignum:REAL
|
|
13 DIM prompt:STRING[2]
|
|
14 DIM driveaccessmsg(4),driveerrors(5):STRING[32]
|
|
15 DIM ide(512):BYTE
|
|
16 (* 0=haven't checked yet, 1=found & ok, 2=not found, 3=found & error
|
|
17 DIM drivefound(2):INTEGER
|
|
18 DIM ready:INTEGER
|
|
19 DIM temp:BYTE
|
|
20 DIM counter:INTEGER
|
|
21 DIM driveselect(2):BYTE
|
|
22 DIM drivenumber:INTEGER
|
|
23 DIM baseaddress:REAL
|
|
24 DIM idestatus:BYTE
|
|
25 DIM ideerror:BYTE
|
|
26 DIM undon(2):BYTE
|
|
27 DIM undoff(2):BYTE
|
|
28 DIM invon(2):BYTE
|
|
29 DIM invoff(2):BYTE
|
|
30 undon(1)=$1f
|
|
31 undon(2)=$22
|
|
32 undoff(1)=$1f
|
|
33 undoff(2)=$23
|
|
34 invon(1)=$1f
|
|
35 invoff(1)=$1f
|
|
36 invon(2)=$20
|
|
37 invoff(2)=$21
|
|
38 driveaccessmsg(1)="Has not been checked"
|
|
39 driveaccessmsg(2)="Found & Ok"
|
|
40 driveaccessmsg(3)="Not found"
|
|
41 driveaccessmsg(4)="Found with error"
|
|
42 drivefound(1)=0
|
|
43 drivefound(2)=0
|
|
44 driveerrors(1)="No error detected"
|
|
45 driveerrors(2)="Formatter device error"
|
|
46 driveerrors(3)="Sector buffer error"
|
|
47 driveerrors(4)="EC circuitry error"
|
|
48 driveerrors(5)="Controlling microprocessor error"
|
|
49
|
|
50 driveselect(1)=$A0
|
|
51 driveselect(2)=$B0
|
|
52 PRINT CHR$(12);"IDE Detection program Version 2.1"
|
|
53 PRINT "Version 1.0 Copyright 1996 by Jim Hathaway"
|
|
54 PRINT "Version 2.1 Copyright Oct, 1999 by L. Curtis Boyle"
|
|
55 PRINT "Will detect both ATA and ATAPI devices."
|
|
56 (* Programmer's note: If this program checked and changed the busy flag in the
|
|
57 (* IDE driver's mem, we _COULD_ theoretically flag the driver busy while this
|
|
58 (* program is running.. although we would have to cheat like mad with the MMU
|
|
59 (* to accomplish this...
|
|
60 PRINT "Make sure you are NOT running an IDE driver while running this program!"
|
|
61 PRINT "If you are, hit <BREAK> now!"
|
|
62 PRINT "If you get bizarre results with a 2 drive system, make sure your Master/Slave"
|
|
63 PRINT "jumper settings don't conflict. The Ask Jeeves search engine (www.aj.com)"
|
|
64 PRINT "on the Internet has a lot of drive tech info available, including jumper"
|
|
65 PRINT "settings."
|
|
66 PRINT "Please select base address of controller:"
|
|
67 PRINT "<1> $FF50"
|
|
68 PRINT "<2> $FF70"
|
|
69 5 INPUT "Select <1-2>:";counter
|
|
70 IF counter<>1 AND counter<>2 THEN 5
|
|
71 IF counter=1 THEN
|
|
72 baseaddress=65360.
|
|
73 ELSE
|
|
74 baseaddress=65392.
|
|
75 ENDIF
|
|
76
|
|
77 (* Start with drive 0
|
|
78 drivenumber=1
|
|
79
|
|
80 (* Select drive 0 in NON-LBA mode, and do a Execute Drive Diagnostic command
|
|
81 10 POKE baseaddress+6.,driveselect(drivenumber)
|
|
82 POKE baseaddress+7.,$90
|
|
83
|
|
84 (* Need both DRDY (Drive Ready) & DSC (Drive Seek Complete) flags set
|
|
85 ready=$50
|
|
86 counter=5000
|
|
87 WHILE counter>0 DO
|
|
88 idestatus=PEEK(baseaddress+7.)
|
|
89 EXITIF idestatus=ready THEN
|
|
90 ENDEXIT
|
|
91 EXITIF LAND(idestatus,1)<>0 THEN
|
|
92 PRINT "Error detected during Drive Diagnostic"
|
|
93 ideerror=PEEK(baseaddress+1.)
|
|
94 temp=LAND(ideerror,$7f)
|
|
95 IF temp>1 THEN
|
|
96 PRINT "Error on drive 0"
|
|
97 drivefound(1)=3
|
|
98 IF temp<6 THEN
|
|
99 PRINT driveerrors(temp)
|
|
100 ELSE
|
|
101 PRINT " - unknown error # $";
|
|
102 PRINT USING "H2",ideerror
|
|
103 ENDIF
|
|
104 ENDIF
|
|
105 IF ideerror>=$80 THEN
|
|
106 PRINT "Error on drive 1"
|
|
107 drivefound(2)=3
|
|
108 POKE baseaddress+6.,driveselect(2)
|
|
109 counter=5000
|
|
110 REPEAT
|
|
111 idestatus=PEEK(baseaddress+7.)
|
|
112 UNTIL LAND(idestatus,$80)=0 OR counter=0
|
|
113 ideerror=PEEK(baseaddress+1.)
|
|
114 IF ideerror>0 AND ideerror<6 THEN
|
|
115 PRINT " - ";driveerrors(ideerror)
|
|
116 ELSE
|
|
117 PRINT " - unknown error # $";
|
|
118 PRINT USING "H2",ideerror
|
|
119 ENDIF
|
|
120 ENDIF
|
|
121 ENDEXIT
|
|
122 EXITIF idestatus=0 THEN
|
|
123 PRINT "IDE cable may be plugged in, but no power to drive 0"
|
|
124 counter=0
|
|
125 ENDEXIT
|
|
126 counter=counter-1
|
|
127 ENDWHILE
|
|
128 IF counter=0 THEN
|
|
129 PRINT "Error: Drive 0 did not respond to Drive Diagnostic command!!!!"
|
|
130 drivefound(1)=2
|
|
131 ELSE
|
|
132 IF drivefound(1)=0 THEN
|
|
133 PRINT "Drive 0 responded to Drive Diagnostic command"
|
|
134 drivefound(1)=1
|
|
135 ENDIF
|
|
136 ENDIF
|
|
137
|
|
138 (* Now, select drive 1 - check if it is there
|
|
139 POKE baseaddress+6.,driveselect(2)
|
|
140 REPEAT
|
|
141 idestatus=PEEK(baseaddress+7.)
|
|
142 UNTIL LAND(idestatus,$80)=0
|
|
143 IF LAND(idestatus,1)<>0 OR LAND(idestatus,$20)<>0 THEN
|
|
144 PRINT "Error flag or Write Fault flag set on status register for drive 1"
|
|
145 IF LAND(idestatus,1)=1 THEN
|
|
146 ideerror=PEEK(baseaddress+1.)
|
|
147 PRINT "Drive 1 error code=$";
|
|
148 PRINT USING "h2",iderror
|
|
149 ELSE
|
|
150 PRINT "Write Fault flag set - drive probably not plugged in"
|
|
151 drivefound(2)=2
|
|
152 ENDIF
|
|
153 ENDIF
|
|
154 IF drivefound(2)<>3 AND drivefound(2)<>2 THEN
|
|
155 IF idestatus=0 THEN
|
|
156 PRINT "There does not appear to be a drive 1"
|
|
157 drivefound(2)=2
|
|
158 ENDIF
|
|
159 IF drivefound(2)=0 THEN
|
|
160 drivefound(2)=1
|
|
161 ENDIF
|
|
162 ENDIF
|
|
163 PRINT
|
|
164
|
|
165 (* Select drive and identify
|
|
166 FOR drivenumber=1 TO 2
|
|
167 PUT #1,undon
|
|
168 PRINT "Checking drive ";drivenumber-1
|
|
169 PUT #1,undoff
|
|
170 IF drivefound(drivenumber)=1 THEN
|
|
171 PRINT "Sending IDE identify device command to drive ";drivenumber-1
|
|
172 POKE baseaddress+6.,driveselect(drivenumber)
|
|
173 POKE baseaddress+7.,$ec
|
|
174 counter=2000
|
|
175 REPEAT
|
|
176 counter=counter-1
|
|
177 UNTIL PEEK(baseaddress+7.)=ready+8 OR counter=0
|
|
178 IF counter=0 THEN
|
|
179 POKE baseaddress+7.,$a1
|
|
180 counter=2000
|
|
181 REPEAT
|
|
182 counter=counter-1
|
|
183 UNTIL PEEK(baseaddress+7.)=ready+8 OR counter=0
|
|
184 ELSE
|
|
185 PRINT "ATA Identified:"
|
|
186 GOTO 20
|
|
187 ENDIF
|
|
188 IF counter=0 THEN
|
|
189 PRINT "ERROR: Could not identify either ATA or ATAPI!"
|
|
190 END
|
|
191 ELSE
|
|
192 PRINT "ATAPI Identified:"
|
|
193 ENDIF
|
|
194 20 FOR counter=1 TO 512 STEP 2
|
|
195 ide(counter+1)=PEEK(baseaddress)
|
|
196 ide(counter)=PEEK(baseaddress+8.)
|
|
197 NEXT counter
|
|
198 PRINT "Model#= ";
|
|
199 PUT #1,invon
|
|
200 FOR counter=55 TO 90
|
|
201 PRINT CHR$(ide(counter));
|
|
202 NEXT counter
|
|
203 PUT #1,invoff
|
|
204 PRINT
|
|
205 PRINT "Firmware Revision=";
|
|
206 PUT #1,invon
|
|
207 FOR counter=47 TO 54
|
|
208 PRINT CHR$(ide(counter));
|
|
209 NEXT counter
|
|
210 PUT #1,invoff
|
|
211 PRINT
|
|
212 PRINT "Serial#= ";
|
|
213 PUT #1,invon
|
|
214 FOR counter=21 TO 41
|
|
215 PRINT CHR$(ide(counter));
|
|
216 NEXT counter
|
|
217 PUT #1,invoff
|
|
218 PRINT
|
|
219 PRINT USING "'Configuration=0x',H2,H2", ide(1), ide(2)
|
|
220 PRINT "Logical Cyls="; ide(3)*256+ide(4)
|
|
221 PRINT "Logical Heads="; ide(7)*256+ide(8)
|
|
222 PRINT "Logical Sectors="; ide(13)*256+ide(14)
|
|
223 (* Note: not using ide(115-118) for CHS sector count, since some older ATA-1
|
|
224 (* drives do NOT report it correctly.
|
|
225 bignum=(ide(3)*256.+ide(4))*(ide(7)*256.+ide(8))*(ide(13)*256.+ide(14))
|
|
226 PRINT USING "'# of user addressable sectors in CHS mode=',x13,R10.0";bignum
|
|
227 IF ide(96)=0 THEN
|
|
228 PRINT "READ/WRITE multiple not supported"
|
|
229 ELSE
|
|
230 PRINT ide(96); " Sectors per READ/WRITE multiple"
|
|
231 ENDIF
|
|
232 (* Bug fix - originally checked if equal to 1 (which it NEVER would be, since
|
|
233 (* we are LANDing the 2ND bit!)
|
|
234 IF LAND(ide(99),2)=2 THEN
|
|
235 PRINT "LBA is supported"
|
|
236 bignum=16777216.*ide(123)+65536.*ide(124)+256.*ide(121)+ide(122)
|
|
237 PRINT USING "'# of user addressable sectors in LBA mode=$',h2,h2,h2,h2,x4,R10.0";ide(123),ide(124),ide(121),ide(122),bignum
|
|
238 ELSE
|
|
239 PRINT "LBA is not supported"
|
|
240 ENDIF
|
|
241 PRINT "PIO data tranfer cycle timing="; ide(103)
|
|
242 PRINT "Current logical cylinders="; ide(109)*256+ide(110)
|
|
243 PRINT "Current logical heads="; ide(111)*256+ide(112)
|
|
244 PRINT "Current logical Sectors="; ide(113)*256+ide(114)
|
|
245 PRINT
|
|
246 INPUT "Press <ENTER> to continue:";prompt
|
|
247 ELSE
|
|
248 PRINT "Drive ";drivenumber-1;" not accessable:";
|
|
249 PRINT driveaccessmsg(drivefound(drivenumber)+1)
|
|
250 ENDIF
|
|
251 NEXT drivenumber
|
|
252 PRINT "Program finished."
|
|
253 END
|