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.
27 void DoOptionsMenu(void)
29 int OptionsMenuItemCount
= 1; // Count is 1 because we don't show the "Set ReactOS Boot Flags" menu item yet
30 char OptionsMenuItems
[2][80] = { "Boot Wizard", "Set ReactOS Boot Flags" /* i.e. Safe Mode, Last Known Good Configuration */ };
31 int OptionsMenuItemSelected
= 0;
33 while (OptionsMenuItemSelected
!= -1)
35 OptionsMenuItemSelected
= RunOptionsMenu(OptionsMenuItems
, OptionsMenuItemCount
, OptionsMenuItemSelected
, "[Advanced Options]");
37 switch (OptionsMenuItemSelected
)
46 void DoDiskOptionsMenu(void)
48 char DiskMenuItems
[25][80];
49 int DiskMenuItemCount
= 0;
50 int FloppyDiskMenuItemCount
= 0;
51 int HardDiskMenuItemCount
= 0;
52 int DiskMenuItemSelected
= 0;
57 FloppyDiskMenuItemCount
= (int)*((char *)((0x40 * 16) + 0x10)); // Get number of floppy disks from bios data area 40:10
58 if (FloppyDiskMenuItemCount
& 1)
59 FloppyDiskMenuItemCount
= (FloppyDiskMenuItemCount
>> 6) + 1;
61 FloppyDiskMenuItemCount
= 0;
62 HardDiskMenuItemCount
= (int)*((char *)((0x40 * 16) + 0x75)); // Get number of hard disks from bios data area 40:75
63 DiskMenuItemCount
= FloppyDiskMenuItemCount
+ HardDiskMenuItemCount
;
65 for (i
=0; i
<FloppyDiskMenuItemCount
; i
++)
67 strcpy(DiskMenuItems
[i
], "Floppy Disk ");
68 itoa(i
+ 1, temp
, 10);
69 strcat(DiskMenuItems
[i
], temp
);
72 for (i
=0; i
<HardDiskMenuItemCount
; i
++)
74 strcpy(DiskMenuItems
[i
+ FloppyDiskMenuItemCount
], "Hard Disk ");
75 itoa(i
+ 1, temp
, 10);
76 strcat(DiskMenuItems
[i
+ FloppyDiskMenuItemCount
], temp
);
77 strcat(DiskMenuItems
[i
+ FloppyDiskMenuItemCount
], " (");
78 itoa((get_heads(i
+0x80) * get_cylinders(i
+0x80) * get_sectors(i
+0x80)) / 2048, temp
, 10);
79 strcat(DiskMenuItems
[i
+ FloppyDiskMenuItemCount
], temp
);
80 strcat(DiskMenuItems
[i
+ FloppyDiskMenuItemCount
], " MB)");
83 DiskMenuItemSelected
= 0;
84 while (DiskMenuItemSelected
!= -1)
86 DiskMenuItemSelected
= RunOptionsMenu(DiskMenuItems
, DiskMenuItemCount
, DiskMenuItemSelected
, "[Boot Wizard]");
88 if (DiskMenuItemSelected
!= -1)
90 if (DiskMenuItemSelected
< FloppyDiskMenuItemCount
)
91 DoBootOptionsMenu(DiskMenuItemSelected
, DiskMenuItems
[DiskMenuItemSelected
]);
93 DoBootOptionsMenu((DiskMenuItemSelected
- FloppyDiskMenuItemCount
) + 0x80, DiskMenuItems
[DiskMenuItemSelected
]);
98 void DoBootOptionsMenu(int BootDriveNum
, char *BootDriveText
)
100 int BootOptionsMenuItemCount
= 2;
101 char BootOptionsMenuItems
[2][80] = { "Boot To ", "Pick A Boot Partition" };
102 int BootOptionsMenuItemSelected
= 0;
104 strcat(BootOptionsMenuItems
[0], BootDriveText
);
106 while (BootOptionsMenuItemSelected
!= -1)
108 BootOptionsMenuItemSelected
= RunOptionsMenu(BootOptionsMenuItems
, BootOptionsMenuItemCount
, BootOptionsMenuItemSelected
, "[Boot Options]");
110 switch (BootOptionsMenuItemSelected
)
113 BootDrive
= BootDriveNum
;
115 if (!biosdisk(_DISK_READ
, BootDrive
, 0, 0, 1, 1, (void*)0x7c00))
117 MessageBox("Disk Read Error");
121 // Check for validity
122 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
124 MessageBox("Invalid boot sector magic (0xaa55)");
128 RestoreScreen(pScreenBuffer
);
130 gotoxy(nCursorXPos
, nCursorYPos
);
137 if (BootDriveNum
< 0x80)
139 MessageBox("This option is not available for a floppy disk.");
143 DoBootPartitionOptionsMenu(BootDriveNum
);
150 void DoBootPartitionOptionsMenu(int BootDriveNum
)
156 int head
, sector
, cylinder
;
158 int BootOptionsMenuItemCount
= 0;
159 char BootOptionsMenuItems
[8][80];
160 int BootOptionsMenuItemSelected
= 0;
161 int head
, sector
, cylinder
;
167 BootDrive
= BootDriveNum
;
169 if (!biosdisk(_DISK_READ
, BootDrive
, 0, 0, 1, 1, SectorBuffer
))
171 MessageBox("Disk Read Error");
175 // Check for validity
176 if (*((WORD
*)(SectorBuffer
+ 0x1fe)) != 0xaa55)
178 MessageBox("Invalid partition table magic (0xaa55)");
186 // Check for valid partition
187 if (SectorBuffer
[offset
+ 4] != 0)
189 BootPartitions
[BootOptionsMenuItemCount
].partition_num
= i
;
190 BootPartitions
[BootOptionsMenuItemCount
].partition_type
= SectorBuffer
[offset
+ 4];
192 BootPartitions
[BootOptionsMenuItemCount
].head
= SectorBuffer
[offset
+ 1];
193 BootPartitions
[BootOptionsMenuItemCount
].sector
= (SectorBuffer
[offset
+ 2] & 0x3F);
194 BootPartitions
[BootOptionsMenuItemCount
].cylinder
= SectorBuffer
[offset
+ 3];
195 if (SectorBuffer
[offset
+ 2] & 0x80)
196 BootPartitions
[BootOptionsMenuItemCount
].cylinder
+= 0x200;
197 if (SectorBuffer
[offset
+ 2] & 0x40)
198 BootPartitions
[BootOptionsMenuItemCount
].cylinder
+= 0x100;
200 strcpy(BootOptionsMenuItems
[BootOptionsMenuItemCount
], "Boot To Partition ");
202 strcat(BootOptionsMenuItems
[BootOptionsMenuItemCount
], temp
);
203 strcat(BootOptionsMenuItems
[BootOptionsMenuItemCount
], " (Type: 0x");
204 itoa(BootPartitions
[BootOptionsMenuItemCount
].partition_type
, temp
, 16);
205 if (strlen(temp
) < 2)
206 strcat(BootOptionsMenuItems
[BootOptionsMenuItemCount
], "0");
207 strcat(BootOptionsMenuItems
[BootOptionsMenuItemCount
], temp
);
208 strcat(BootOptionsMenuItems
[BootOptionsMenuItemCount
], ")");
210 BootOptionsMenuItemCount
++;
216 while (BootOptionsMenuItemSelected
!= -1)
218 BootOptionsMenuItemSelected
= RunOptionsMenu(BootOptionsMenuItems
, BootOptionsMenuItemCount
, BootOptionsMenuItemSelected
, "[Boot Partition Options]");
220 if (BootOptionsMenuItemSelected
!= -1)
222 head
= BootPartitions
[BootOptionsMenuItemCount
].head
;
223 sector
= BootPartitions
[BootOptionsMenuItemCount
].sector
;
224 cylinder
= BootPartitions
[BootOptionsMenuItemCount
].cylinder
;
226 // Read partition boot sector
227 if (!biosdisk(_DISK_READ
, BootDrive
, head
, cylinder
, sector
, 1, (void*)0x7c00))
229 MessageBox("Disk Read Error");
233 // Check for validity
234 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
236 MessageBox("Invalid boot sector magic (0xaa55)");
240 RestoreScreen(pScreenBuffer
);
242 gotoxy(nCursorXPos
, nCursorYPos
);
250 int RunOptionsMenu(char OptionsMenuItems
[][80], int OptionsMenuItemCount
, int nOptionSelected
, char *OptionsMenuTitle
)
255 int nOptionsMenuBoxLeft
;
256 int nOptionsMenuBoxRight
;
257 int nOptionsMenuBoxTop
;
258 int nOptionsMenuBoxBottom
;
261 // Initialise the menu
262 InitOptionsMenu(&nOptionsMenuBoxLeft
, &nOptionsMenuBoxTop
, &nOptionsMenuBoxRight
, &nOptionsMenuBoxBottom
, OptionsMenuItemCount
);
267 DrawOptionsMenu(OptionsMenuItems
, OptionsMenuItemCount
, nOptionSelected
, OptionsMenuTitle
, nOptionsMenuBoxLeft
, nOptionsMenuBoxTop
, nOptionsMenuBoxRight
, nOptionsMenuBoxBottom
);
269 second
= getsecond();
274 // Check for a keypress
277 // Cancel the timeout
281 DrawOptionsMenu(OptionsMenuItems
, OptionsMenuItemCount
, nOptionSelected
, OptionsMenuTitle
, nOptionsMenuBoxLeft
, nOptionsMenuBoxTop
, nOptionsMenuBoxRight
, nOptionsMenuBoxBottom
);
289 key
= getch(); // Yes - so get the extended key
300 DrawOptionsMenu(OptionsMenuItems
, OptionsMenuItemCount
, nOptionSelected
, OptionsMenuTitle
, nOptionsMenuBoxLeft
, nOptionsMenuBoxTop
, nOptionsMenuBoxRight
, nOptionsMenuBoxBottom
);
304 if (nOptionSelected
< (OptionsMenuItemCount
- 1))
309 DrawOptionsMenu(OptionsMenuItems
, OptionsMenuItemCount
, nOptionSelected
, OptionsMenuTitle
, nOptionsMenuBoxLeft
, nOptionsMenuBoxTop
, nOptionsMenuBoxRight
, nOptionsMenuBoxBottom
);
313 //MessageBox("The Advanced Options are still being implemented.");
317 nOptionSelected
= -1;
323 // Update the date & time
328 if (getsecond() != second
)
330 second
= getsecond();
334 DrawOptionsMenu(OptionsMenuItems
, OptionsMenuItemCount
, nOptionSelected
, OptionsMenuTitle
, nOptionsMenuBoxLeft
, nOptionsMenuBoxTop
, nOptionsMenuBoxRight
, nOptionsMenuBoxBottom
);
343 return nOptionSelected
;
346 void InitOptionsMenu(int *nOptionsMenuBoxLeft
, int *nOptionsMenuBoxTop
, int *nOptionsMenuBoxRight
, int *nOptionsMenuBoxBottom
, int OptionsMenuItemCount
)
348 int height
= OptionsMenuItemCount
;
351 height
+= 1; // Allow room for top & bottom borders
352 width
+= 18; // Allow room for left & right borders, plus 8 spaces on each side
354 // Calculate the OS list box area
355 *nOptionsMenuBoxLeft
= (nScreenWidth
- width
) / 2;
356 *nOptionsMenuBoxRight
= *nOptionsMenuBoxLeft
+ width
;
357 *nOptionsMenuBoxTop
= (nScreenHeight
- height
) / 2 + 1;
358 *nOptionsMenuBoxBottom
= *nOptionsMenuBoxTop
+ height
;
361 void DrawOptionsMenu(char OptionsMenuItems
[][80], int OptionsMenuItemCount
, int nOptionSelected
, char *OptionsMenuTitle
, int nOptionsMenuBoxLeft
, int nOptionsMenuBoxTop
, int nOptionsMenuBoxRight
, int nOptionsMenuBoxBottom
)
365 int space
, space_left
, space_right
;
367 // Update the status bar
368 DrawStatusText(" Use \x18\x19 to select, then press ENTER. Press ESC to go back.");
370 DrawBox(nOptionsMenuBoxLeft
, nOptionsMenuBoxTop
, nOptionsMenuBoxRight
, nOptionsMenuBoxBottom
, D_VERT
, D_HORZ
, TRUE
, TRUE
, ATTR(cMenuFgColor
, cMenuBgColor
));
371 DrawText(nOptionsMenuBoxLeft
+ (((nOptionsMenuBoxRight
- nOptionsMenuBoxLeft
) - strlen(OptionsMenuTitle
)) / 2) + 1, nOptionsMenuBoxTop
, OptionsMenuTitle
, ATTR(cMenuFgColor
, cMenuBgColor
));
373 for(i
=0; i
<OptionsMenuItemCount
; i
++)
375 space
= (nOptionsMenuBoxRight
- nOptionsMenuBoxLeft
- 2) - strlen(OptionsMenuItems
[i
]);
376 space_left
= (space
/ 2) + 1;
377 space_right
= (space
- space_left
) + 1;
380 for(j
=0; j
<space_left
; j
++)
382 strcat(text
, OptionsMenuItems
[i
]);
383 for(j
=0; j
<space_right
; j
++)
386 if(i
== nOptionSelected
)
388 DrawText(nOptionsMenuBoxLeft
+1, nOptionsMenuBoxTop
+1+i
, text
, ATTR(cSelectedTextColor
, cSelectedTextBgColor
));
392 DrawText(nOptionsMenuBoxLeft
+1, nOptionsMenuBoxTop
+1+i
, text
, ATTR(cTextColor
, cMenuBgColor
));