Electronics Btrieve Motorcycling Software If you find this site useful and want to support, click on few ads to throw some money into hat.

10 REM IDE Diagnostics and demos v1.0
20 REM ITMP - IDE temporary data
30 REM BASE - controller base address
40 REM LBA - logical block address to access
45 REM LBASECS - total number of accessible LBA sectors for device
50 REM ICS - IDE controller status
60 REM ICE - IDE controller error if lsb of ICS is set
70 REM CMD - command to send to controller
80 REM IHI,ILO - data bytes read from IDE
90 REM IX,IX1,IX2,IX3,IX4 - LBA conversion temp vars
1000 BASE=0E000H
1010 GOSUB 13000
1020 PRINT : PRINT : PRINT "1. Reset device"
1021 PRINT "2. Sleep device"
1022 PRINT "3. Idle device"
1023 PRINT "4. Standby device"
1024 PRINT "5. Query power mode"
1025 PRINT "6. Execute diagnostics" : PRINT "7. Identify device"
1026 PRINT "8. Recalibrate" : PRINT "9. Test read"
1027 PRINT : PRINT "Choose one?",
1028 I=GET : IF I=0 THEN GOTO 1028
1029 I=I-49 : PRINT I+1
1030 IF I<0 THEN GOTO 1020
1040 ON I GOSUB 2100,2200,2300,2400,2500,2600,2700,2800,2900
1050 GOTO 1020
2100 REM do reset
2110 GOSUB 13000
2120 RETURN 
2200 REM go to sleep
2210 CMD=0E6H : XBY(BASE+7)=CMD
2220 RETURN 
2300 REM go to idle mode
2310 CMD=0E1H : GOSUB 11000
2320 RETURN 
2400 REM go to standby mode
2410 CMD=0E0H : GOSUB 11000
2420 RETURN 
2500 REM query device power mode
2510 CMD=0E5H : GOSUB 11000
2520 I=XBY(BASE+2)
2525 PRINT "Device is in ",
2530 IF I=0 THEN PRINT "standby", : GOTO 2560
2540 IF I=255 THEN PRINT "active", : GOTO 2560
2550 PRINT "unknown",
2560 PRINT " mode"
2570 RETURN 
2600 REM execute diagnostics
2610 CMD=90H : GOSUB 11000
2620 PRINT "Diagnostics response ",XBY(BASE+1)
2630 RETURN 
2700 REM identify device (hex dump of the data)
2705 CMD=0ECH : GOSUB 11000
2720 FOR BC=0 TO 255 : ITMP=BC.AND.7 : IF ITMP=0 THEN PRINT : PH1. BC*2,
2740 GOSUB 12000 : PH0. IHI,ILO, : NEXT 
2770 PRINT : RETURN 
2800 REM recalibrate device (seek to 0)
2805 LBA=0 : GOSUB 10000
2810 CMD=10H : GOSUB 11000
2820 RETURN 
2900 REM test read
2920 FOR LBA=0 TO LBASECS-1
2922 PRINT "Reading sector#",LBA
2925 GOSUB 10000
2930 CMD=20H : GOSUB 11000
2940 GOSUB 2720
2950 PRINT : PRINT 
2955 IF GET<>0 THEN LBA=LBASECS
2960 NEXT 
2970 RETURN 
10000 REM Set LBA block number and sector count of 1
10005 IX=LBA : IX1=IX.AND.255
10020 IX=IX/256 : IX2=IX.AND.255
10040 IX=IX/256 : IX3=IX.AND.255
10060 IX=IX/256 : IX4=IX.AND.255
10075 XBY(BASE+6)=IX4+0E0H : XBY(BASE+3)=IX1 : XBY(BASE+4)=IX2
10080 XBY(BASE+5)=IX3 : XBY(BASE+2)=1
10100 RETURN 
11000 REM send a command to device, ensuring that device is ready
11010 ICS=XBY(BASE+7) : IF ICS.AND.040H<>040H THEN GOTO 11010
11030 XBY(BASE+7)=CMD
11040 ICS=XBY(BASE+7) : IF ICS>127 THEN GOTO 11040
11060 ITMP=ICS.AND.1 : IF ITMP=0 THEN RETURN 
11070 ICE=XBY(BASE+1) : PRINT "IDE ERROR#", : PH0. ICE
11090 RETURN 
12000 REM read one data word, return it in ILO and IHI
12005 ICS=XBY(BASE+7) : IF ICS.AND.040H=0 THEN GOTO 12005
12010 ILO=XBY(BASE+0) : IHI=XBY(BASE+16) : RETURN 
13000 REM reset device
13010 XBY(BASE+14)=6 : FOR ICS=0 TO 10 : NEXT 
13020 XBY(BASE+14)=2
13030 ICS=XBY(BASE+7) : IF ICS>127 THEN GOTO 13030
13050 REM read identification data and initialize device parameters
13055 PRINT "Please wait, configuring drive..."
13060 CMD=0ECH : GOSUB 11000
13070 FOR ITMP=0 TO 3 : GOSUB 12000 : NEXT 
13080 HEADS=IHI*256+ILO : GOSUB 12000 : GOSUB 12000 : GOSUB 12000
13090 SECS=IHI*256+ILO : FOR ITMP=7 TO 255 : GOSUB 12000 : NEXT 
13100 XBY(BASE+6)=HEADS-1+0E0H : XBY(BASE+2)=SECS : CMD=91H : GOSUB 11000
13110 CMD=0ECH : GOSUB 11000 : FOR ITMP=0 TO 53 : GOSUB 12000 : NEXT 
13120 GOSUB 12000 : CYLS=IHI*256+ILO
13130 GOSUB 12000 : HEADS=IHI*256+ILO
13140 GOSUB 12000 : SECS=IHI*256+ILO
13150 GOSUB 12000 : LBASECS=IHI*256+ILO
13160 GOSUB 12000 : LBASECS=(IHI*256+ILO)*65536+LBASECS
13170 FOR I=59 TO 255 : GOSUB 12000 : NEXT 
13190 PRINT CYLS,"Cylinders,",HEADS,"Heads,",SECS,"Sectors,",LBASECS,"Total"
13200 RETURN 
 
  

Copyright © Madis Kaal 2000-