source: trunk/bootcode/special/fatread.bas@ 201

Last change on this file since 201 was 57, checked in by Ben Rietbroek, 10 years ago

All source-files lowercased [v1.1.1-testing]

Some standard files like 'COPYING', 'LICENSE', etc. have not been
converted to lower case because they are usually distributed uppercased.

File size: 4.3 KB
Line 
1$COMPILE EXE
2
3Type LINUXIMG_13EXT_ControlType
4 SizePaket as WORD
5 NumBlocks as WORD
6 Transfer as DWORD
7 Absolut as DWORD
8 Absolut2 as DWORD
9End Type
10
11Dim LINUXIMG_13EXT_Control as shared LINUXIMG_13EXT_ControlType
12Dim LINUXIMG_13EXT_ControlPtr as shared DWORD
13LINUXIMG_13EXT_ControlPtr = VarPtr32(LINUXIMG_13EXT_Control)
14LINUXIMG_13EXT_Control.SizePaket = &h10
15
16! mov ah, &h41
17! mov bx, &h55AA
18! mov dl, &h80
19! int &h13
20! cmp bx, &h0AA55
21! je LINUXIMG_13EXT_Found
22LINUXIMG_13EXT_NotFound:
23print "þ INT 13h Extensions not found, you won't need this tool"
24end
25
26LINUXIMG_13EXT_Found:
27! and cx, 1
28! jz LINUXIMG_13EXT_NotFound
29print "þ INT 13h Extensions found"
30
31AbsPartitionBegin??? = 2618595
32'AbsPartitionBegin??? = 16065+63
33BootRecord$ = LINUXIMG_13EXT_ReadSector (&h80, AbsPartitionBegin???)
34SectorsPerCluster? = CvByt(BootRecord$,14)
35ReservedSectors?? = CvWrd(BootRecord$,15)
36FATcopies? = CvByt(BootRecord$,17)
37NumOfRootEntries?? = CvWrd(BootRecord$,18)
38SectorsPerFAT?? = CvWrd(BootRecord$,23)
39print ReservedSectors??, FATcopies?, NumOfRootEntries??, SectorsPerFAT??, SectorsPerCluster?
40
41FATstart??? = AbsPartitionBegin???+ReservedSectors??
42RootStart??? = FATstart???+(FATcopies?*SectorsPerFAT??)
43ClusterStart??? = RootStart???+NumOfRootEntries??/16
44
45CurEntry?? = 0: RootSector?? = 0
46Do
47 RootTable$ = LINUXIMG_13EXT_ReadSector (&h80, RootStart???+RootSector??)
48 LocalEntry?? = 0
49 Do
50 If Mid$(RootTable$,LocalEntry??*32+1,11) = "KERNELS " Then
51 KernelDirFound% = -1
52 else
53 Incr LocalEntry??
54 End If
55 Loop Until KernelDirFound% or LocalEntry??=>16
56 Incr RootSector??: Incr CurEntry??, 16
57 if inkey$<>"" Then End
58Loop Until KernelDirFound% or CurEntry??=NumOfRootEntries??
59
60If KernelDirFound% Then
61 DirFlags? = CvByt(RootTable$,LocalEntry??*32+12)
62 If DirFlags?=&h10 Then print "Valid Directory!"
63 ClusterStart?? = CvWrd(RootTable$,LocalEntry??*32+27)
64 print "Cluster start: ";ClusterStart??
65 print "Next Cluster: ";GetNextCluster(FATstart???, ClusterStart??)
66
67 DirCluster$ = GetClusterData (ClusterStart???, SectorsPerCluster?, ClusterStart??)
68 ClusterStart?? = CvWrd(DirCluster$,2*32+27)
69 print GetClusterData (ClusterStart???, SectorsPerCluster?, ClusterStart??)
70End If
71end
72
73Function GetClusterData (byval ClusterStart???, byval SectorsPerCluster?, byval ClusterNo??) as STRING
74 ClusterPos??? = (ClusterNo??-2)*SectorsPerCluster?
75
76 ClusterData$ = LINUXIMG_13EXT_ReadSector (&h80, ClusterStart???+ClusterPos???)
77 FUNCTION = ClusterData$
78End Function
79
80Function GetNextCluster (byval FATstart???, byval CurCluster??) as WORD
81 FATpos?? = (CurCluster?? mod 256)
82 FATsector?? = (CurCluster??-FATpos??)/256
83 FATpos?? = FATpos??*2
84
85 FATtable$ = LINUXIMG_13EXT_ReadSector (&h80, FATstart???+FATsector??)
86 NextCluster?? = CvWrd(FATtable$, FATpos??+1)
87
88 FUNCTION = NextCluster??
89End Function
90
91Function LINUXIMG_13EXT_ReadSector (byval Harddrive??, byval BlockNo???) as STRING
92 local MyBlock$
93 MyBlock$ = String$(512,0)
94 LINUXIMG_13EXT_Control.NumBlocks = 1
95 LINUXIMG_13EXT_Control.Transfer = StrPtr32(MyBlock$)
96 LINUXIMG_13EXT_Control.Absolut = BlockNo???
97 ! push ds
98 ! mov dl, Harddrive??
99 ! lds si, LINUXIMG_13EXT_ControlPtr
100 ! mov ah, &h42
101 ! int &h13
102 ! pop ds
103 ! jc LINUXIMG_13EXT_Error
104 FUNCTION = MyBlock$
105 Exit Function
106
107 LINUXIMG_13EXT_Error:
108 print "Error in partition-table/Bad sector on harddisc."
109 end
110End Function
111
112Sub LINUXIMG_13EXT_WriteSectors (byval Harddrive??, byval BlockNo???, byval DataBlock$)
113 local MyBlock$
114 If len(DataBlock$)<5120 Then
115 DataBlock$ = DataBlock$ + String$(5120-len(DataBlock$),0)
116 End If
117 LINUXIMG_13EXT_Control.NumBlocks = 10
118 LINUXIMG_13EXT_Control.Transfer = StrPtr32(DataBlock$)
119 LINUXIMG_13EXT_Control.Absolut = BlockNo???
120 ! push ds
121 ! mov dl, Harddrive??
122 ! lds si, LINUXIMG_13EXT_ControlPtr
123 ! mov ah, &h43 ; Write !
124 ! int &h13
125 ! pop ds
126 ! jc LINUXIMG_13EXT_ErrorWrite
127 Exit Sub
128
129 LINUXIMG_13EXT_ErrorWrite:
130 print "Error, while writing to disc."
131 end
132End Sub
Note: See TracBrowser for help on using the repository browser.