3 * Copyright (C) 1999, 2000 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 void LoadAndBootBootSector(int nOSToBoot
)
33 char szFileName
[1024];
36 // Find all the message box settings and run them
37 for (i
=1; i
<=GetNumSectionItems(OSList
[nOSToBoot
].name
); i
++)
39 ReadSectionSettingByNumber(OSList
[nOSToBoot
].name
, i
, name
, value
);
40 if (stricmp(name
, "MessageBox") == 0)
42 if (stricmp(name
, "MessageLine") == 0)
46 if (!ReadSectionSettingByName(OSList
[nOSToBoot
].name
, "BootDrive", name
, value
))
48 MessageBox("Boot drive not specified for selected OS!");
52 BootDrive
= atoi(value
);
55 if (ReadSectionSettingByName(OSList
[nOSToBoot
].name
, "BootPartition", name
, value
))
56 BootPartition
= atoi(value
);
58 if (!ReadSectionSettingByName(OSList
[nOSToBoot
].name
, "BootSector", name
, value
))
60 MessageBox("Boot sector file not specified for selected OS!");
64 if (!OpenDiskDrive(BootDrive
, BootPartition
))
66 MessageBox("Failed to open boot drive.");
70 strcpy(szFileName
, value
);
71 if (!OpenFile(szFileName
, &file
))
73 strcat(value
, " not found.");
79 if (ReadFile(&file
, 512, (void*)0x7c00) != 512)
81 MessageBox("Disk Read Error");
86 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
88 MessageBox("Invalid boot sector magic (0xaa55)");
92 RestoreScreen(pScreenBuffer
);
94 gotoxy(nCursorXPos
, nCursorYPos
);
100 void LoadAndBootPartition(int nOSToBoot
)
104 int head
, sector
, cylinder
;
108 // Find all the message box settings and run them
109 for (i
=1; i
<=GetNumSectionItems(OSList
[nOSToBoot
].name
); i
++)
111 ReadSectionSettingByNumber(OSList
[nOSToBoot
].name
, i
, name
, value
);
112 if (stricmp(name
, "MessageBox") == 0)
114 if (stricmp(name
, "MessageLine") == 0)
118 if (!ReadSectionSettingByName(OSList
[nOSToBoot
].name
, "BootDrive", name
, value
))
120 MessageBox("Boot drive not specified for selected OS!");
124 BootDrive
= atoi(value
);
126 if (!ReadSectionSettingByName(OSList
[nOSToBoot
].name
, "BootPartition", name
, value
))
128 MessageBox("Boot partition not specified for selected OS!");
132 BootPartition
= atoi(value
);
134 if (!biosdisk(_DISK_READ
, BootDrive
, 0, 0, 1, 1, SectorBuffer
))
136 MessageBox("Disk Read Error");
140 // Check for validity
141 if (*((WORD
*)(SectorBuffer
+ 0x1fe)) != 0xaa55)
143 MessageBox("Invalid partition table magic (0xaa55)");
147 offset
= 0x1BE + ((BootPartition
-1) * 0x10);
149 // Check for valid partition
150 if (SectorBuffer
[offset
+ 4] == 0)
152 MessageBox("Invalid boot partition");
156 head
= SectorBuffer
[offset
+ 1];
157 sector
= (SectorBuffer
[offset
+ 2] & 0x3F);
158 cylinder
= SectorBuffer
[offset
+ 3];
159 if (SectorBuffer
[offset
+ 2] & 0x80)
161 if (SectorBuffer
[offset
+ 2] & 0x40)
164 // Read partition boot sector
165 if (!biosdisk(_DISK_READ
, BootDrive
, head
, cylinder
, sector
, 1, (void*)0x7c00))
167 MessageBox("Disk Read Error");
171 // Check for validity
172 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
174 MessageBox("Invalid boot sector magic (0xaa55)");
178 RestoreScreen(pScreenBuffer
);
180 gotoxy(nCursorXPos
, nCursorYPos
);
186 void LoadAndBootDrive(int nOSToBoot
)
192 // Find all the message box settings and run them
193 for (i
=1; i
<=GetNumSectionItems(OSList
[nOSToBoot
].name
); i
++)
195 ReadSectionSettingByNumber(OSList
[nOSToBoot
].name
, i
, name
, value
);
196 if (stricmp(name
, "MessageBox") == 0)
198 if (stricmp(name
, "MessageLine") == 0)
202 if (!ReadSectionSettingByName(OSList
[nOSToBoot
].name
, "BootDrive", name
, value
))
204 MessageBox("Boot drive not specified for selected OS!");
208 BootDrive
= atoi(value
);
210 if (!biosdisk(_DISK_READ
, BootDrive
, 0, 0, 1, 1, (void*)0x7c00))
212 MessageBox("Disk Read Error");
216 // Check for validity
217 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
219 MessageBox("Invalid boot sector magic (0xaa55)");
223 RestoreScreen(pScreenBuffer
);
225 gotoxy(nCursorXPos
, nCursorYPos
);