Added a boot preferences utility. It is currently specific to GRUB2,
[AROS.git] / workbench / prefs / boot / booteditor.c
blob2bcfe024694d50b6fde30cb2ab8672108be8c8d7
1 /*
2 Copyright © 2013-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/locale.h>
11 #include <libraries/mui.h>
12 #include <zune/customclasses.h>
13 #include <zune/prefseditor.h>
15 #include <proto/exec.h>
16 #include <proto/intuition.h>
17 #include <proto/utility.h>
18 #include <proto/muimaster.h>
19 #include <proto/dos.h>
21 #include <string.h>
23 #include "locale.h"
24 #include "booteditor.h"
26 #include <proto/alib.h>
28 #define DEFAULT_WIDTH 1024
29 #define DEFAULT_HEIGHT 768
30 #define DEFAULT_REFRESH 60
31 #define MAX_LINE_LENGTH 500
33 static const TEXT grub_config_path[] = "SYS:boot/pc/grub/grub.cfg";
34 static const TEXT grub_config_path_tmp[] = "SYS:boot/pc/grub/grub.cfg.tmp";
35 static const TEXT accept_nums[] = "0123456789";
36 static CONST_STRPTR ata_buses_list[5] = {NULL};
37 static CONST_STRPTR debug_output_list[4] = {NULL};
38 static CONST_STRPTR gfx_type_list[5] = {NULL};
39 static CONST_STRPTR vesa_depth_list[4] = {NULL};
41 struct BootEditor_DATA
43 Object *gfx_type,
44 *gfx_composition,
45 *vesa_group,
46 *vesa_width,
47 *vesa_height,
48 *vesa_best_res,
49 *vesa_depth,
50 *vesa_refresh,
51 *vesa_default_refresh,
52 *ata_buses,
53 *ata_dma,
54 *ata_32bit,
55 *ata_poll,
56 *ata_multi,
57 *device_name,
58 *device_delay,
59 *usb_enable,
60 *acpi_enable,
61 *floppy_enable,
62 *debug_output,
63 *debug_mungwall,
64 *debug_usb;
67 static BOOL ReadBootArgs(CONST_STRPTR line, struct BootEditor_DATA *data);
68 static BOOL WriteBootArgs(BPTR file, struct BootEditor_DATA *data);
70 static Object *BootEditor__OM_NEW(Class *CLASS, Object *self,
71 struct opSet *message)
73 struct BootEditor_DATA temp_data, *data = &temp_data;
75 gfx_type_list[0] = _(MSG_GFX_TYPE_AUTO);
76 gfx_type_list[1] = _(MSG_GFX_TYPE_NATIVE);
77 gfx_type_list[2] = _(MSG_GFX_TYPE_VESA);
78 gfx_type_list[3] = _(MSG_GFX_TYPE_VGA);
80 vesa_depth_list[0] = _(MSG_GFX_DEPTH_TRUE);
81 vesa_depth_list[1] = _(MSG_GFX_DEPTH_HIGH);
82 vesa_depth_list[2] = _(MSG_GFX_DEPTH_LOW);
84 ata_buses_list[0] = _(MSG_ATA_BUS_ALL);
85 ata_buses_list[1] = _(MSG_ATA_BUS_PCI);
86 ata_buses_list[2] = _(MSG_ATA_BUS_LEGACY);
87 ata_buses_list[3] = _(MSG_ATA_BUS_NONE);
89 debug_output_list[0] = _(MSG_DEBUG_OUTPUT_NONE);
90 debug_output_list[1] = _(MSG_DEBUG_OUTPUT_MEMORY);
91 debug_output_list[2] = _(MSG_DEBUG_OUTPUT_SERIAL);
93 self = (Object *)DoSuperNewTags(CLASS, self, NULL,
94 MUIA_PrefsEditor_Name, __(MSG_NAME),
95 MUIA_PrefsEditor_Path, (IPTR)grub_config_path,
96 MUIA_PrefsEditor_CanTest, FALSE,
97 MUIA_PrefsEditor_CanUse, FALSE,
98 Child, (IPTR)ColGroup(2),
99 Child, (IPTR)VGroup,
100 GroupFrameT(_(MSG_GFX)),
101 Child, (IPTR)ColGroup(2),
102 Child, (IPTR)Label2(__(MSG_GFX_TYPE)),
103 Child, (IPTR)(data->gfx_type = (Object *)CycleObject,
104 MUIA_Cycle_Entries, (IPTR)gfx_type_list,
105 End),
106 Child, (IPTR)(data->gfx_composition =
107 MUI_MakeObject(MUIO_Checkmark, NULL)),
108 Child, (IPTR)HGroup,
109 Child, (IPTR)Label2(__(MSG_GFX_COMPOSITION)),
110 Child, (IPTR)HVSpace,
111 End,
112 Child, (IPTR)HVSpace,
113 Child, (IPTR)HVSpace,
114 End,
115 Child, (IPTR)(data->vesa_group = VGroup,
116 GroupFrameT(_(MSG_GFX_VESAMODE)),
117 Child, (IPTR)HGroup,
118 Child, (IPTR)(data->vesa_best_res =
119 MUI_MakeObject(MUIO_Checkmark, NULL)),
120 Child, (IPTR)Label2(__(MSG_GFX_BESTRES)),
121 Child, (IPTR)HVSpace,
122 End,
123 Child, (IPTR)ColGroup(2),
124 Child, (IPTR)Label2(__(MSG_GFX_WIDTH)),
125 Child, (IPTR)HGroup,
126 Child, (IPTR)(data->vesa_width =
127 (Object *)StringObject,
128 StringFrame,
129 MUIA_CycleChain, 1,
130 MUIA_String_Accept, (IPTR)accept_nums,
131 MUIA_FixWidthTxt, (IPTR)"00000",
132 End),
133 Child, (IPTR)HVSpace,
134 End,
135 Child, (IPTR)Label2(__(MSG_GFX_HEIGHT)),
136 Child, (IPTR)HGroup,
137 Child, (IPTR)(data->vesa_height =
138 (Object *)StringObject,
139 StringFrame,
140 MUIA_CycleChain, 1,
141 MUIA_String_Accept, (IPTR)accept_nums,
142 MUIA_FixWidthTxt, (IPTR)"00000",
143 End),
144 Child, (IPTR)HVSpace,
145 End,
146 Child, (IPTR)Label2(__(MSG_GFX_DEPTH)),
147 Child, (IPTR)(data->vesa_depth = (Object *)CycleObject,
148 MUIA_Cycle_Entries, (IPTR)vesa_depth_list,
149 End),
150 Child, (IPTR)Label2(__(MSG_GFX_REFRESH)),
151 Child, (IPTR)HGroup,
152 Child, (IPTR)(data->vesa_refresh =
153 (Object *)StringObject,
154 StringFrame,
155 MUIA_CycleChain, 1,
156 MUIA_String_Accept, (IPTR)accept_nums,
157 MUIA_FixWidthTxt, (IPTR)"0000",
158 End),
159 Child, (IPTR)Label2(__(MSG_GFX_HERTZ)),
160 Child, (IPTR)HVSpace,
161 End,
162 End,
163 Child, (IPTR)HGroup,
164 Child, (IPTR)(data->vesa_default_refresh =
165 MUI_MakeObject(MUIO_Checkmark, NULL)),
166 Child, (IPTR)Label2(__(MSG_GFX_DEFAULTREFRESH)),
167 Child, (IPTR)HVSpace,
168 End,
169 End),
170 End,
171 Child, (IPTR)VGroup,
172 Child, (IPTR)VGroup,
173 GroupFrameT(_(MSG_ATA)),
174 Child, (IPTR)HGroup,
175 Child, (IPTR)Label2(__(MSG_ATA_BUSES)),
176 Child, (IPTR)(data->ata_buses = (Object *)CycleObject,
177 MUIA_Cycle_Entries, (IPTR)ata_buses_list,
178 End),
179 End,
180 Child, (IPTR)ColGroup(2),
181 Child, (IPTR)(data->ata_dma =
182 MUI_MakeObject(MUIO_Checkmark, NULL)),
183 Child, (IPTR)HGroup,
184 Child, (IPTR)Label2(__(MSG_ATA_DMA)),
185 Child, (IPTR)HVSpace,
186 End,
187 Child, (IPTR)(data->ata_multi =
188 MUI_MakeObject(MUIO_Checkmark, NULL)),
189 Child, (IPTR)HGroup,
190 Child, (IPTR)Label2(__(MSG_ATA_MULTI)),
191 Child, (IPTR)HVSpace,
192 End,
193 Child, (IPTR)(data->ata_32bit =
194 MUI_MakeObject(MUIO_Checkmark, NULL)),
195 Child, (IPTR)HGroup,
196 Child, (IPTR)Label2(__(MSG_ATA_32BIT)),
197 Child, (IPTR)HVSpace,
198 End,
199 Child, (IPTR)(data->ata_poll =
200 MUI_MakeObject(MUIO_Checkmark, NULL)),
201 Child, (IPTR)HGroup,
202 Child, (IPTR)Label2(__(MSG_ATA_POLL)),
203 Child, (IPTR)HVSpace,
204 End,
205 Child, (IPTR)HVSpace,
206 Child, (IPTR)HVSpace,
207 End,
208 End,
209 Child, (IPTR)VGroup,
210 GroupFrameT(_(MSG_DEVICE)),
211 Child, (IPTR)ColGroup(2),
212 Child, (IPTR)Label2(__(MSG_DEVICE_NAME)),
213 Child, (IPTR)HGroup,
214 Child, (IPTR)(data->device_name =
215 (Object *)StringObject,
216 StringFrame,
217 MUIA_CycleChain, 1,
218 MUIA_String_Reject, (IPTR)":; ",
219 MUIA_FixWidthTxt, (IPTR)"000000000",
220 End),
221 Child, (IPTR)HVSpace,
222 End,
223 Child, (IPTR)Label2(__(MSG_DEVICE_DELAY)),
224 Child, (IPTR)HGroup,
225 Child, (IPTR)(data->device_delay =
226 (Object *)StringObject,
227 StringFrame,
228 MUIA_CycleChain, 1,
229 MUIA_String_Accept, (IPTR)accept_nums,
230 MUIA_FixWidthTxt, (IPTR)"000",
231 End),
232 Child, (IPTR)Label2(__(MSG_DEVICE_SECONDS)),
233 Child, (IPTR)HVSpace,
234 End,
235 End,
236 End,
237 End,
238 Child, (IPTR)ColGroup(2),
239 GroupFrameT(_(MSG_MISC)),
240 Child, (IPTR)(data->usb_enable =
241 MUI_MakeObject(MUIO_Checkmark, NULL)),
242 Child, (IPTR)HGroup,
243 Child, (IPTR)Label2(__(MSG_USB_ENABLE)),
244 Child, (IPTR)HVSpace,
245 End,
246 Child, (IPTR)(data->acpi_enable =
247 MUI_MakeObject(MUIO_Checkmark, NULL)),
248 Child, (IPTR)HGroup,
249 Child, (IPTR)Label2(__(MSG_ACPI_ENABLE)),
250 Child, (IPTR)HVSpace,
251 End,
252 Child, (IPTR)(data->floppy_enable =
253 MUI_MakeObject(MUIO_Checkmark, NULL)),
254 Child, (IPTR)HGroup,
255 Child, (IPTR)Label2(__(MSG_FLOPPY_ENABLE)),
256 Child, (IPTR)HVSpace,
257 End,
258 Child, (IPTR)HVSpace,
259 Child, (IPTR)HVSpace,
260 End,
261 Child, (IPTR)VGroup,
262 GroupFrameT(_(MSG_DEBUG)),
263 Child, (IPTR)HGroup,
264 Child, (IPTR)Label2(__(MSG_DEBUG_OUTPUT)),
265 Child, (IPTR)(data->debug_output = (Object *)CycleObject,
266 MUIA_Cycle_Entries, (IPTR)debug_output_list,
267 End),
268 End,
269 Child, (IPTR)ColGroup(2),
270 Child, (IPTR)(data->debug_mungwall =
271 MUI_MakeObject(MUIO_Checkmark, NULL)),
272 Child, (IPTR)HGroup,
273 Child, (IPTR)Label2(__(MSG_DEBUG_MUNGWALL)),
274 Child, (IPTR)HVSpace,
275 End,
276 Child, (IPTR)(data->debug_usb =
277 MUI_MakeObject(MUIO_Checkmark, NULL)),
278 Child, (IPTR)HGroup,
279 Child, (IPTR)Label2(__(MSG_DEBUG_USB)),
280 Child, (IPTR)HVSpace,
281 End,
282 End,
283 Child, (IPTR)HVSpace,
284 End,
285 End,
286 TAG_DONE
289 if (self != NULL)
291 data = INST_DATA(CLASS, self);
292 *data = temp_data;
294 /* Set up notifications */
296 DoMethod(data->gfx_type, MUIM_Notify,
297 MUIA_Cycle_Active, MUIV_EveryTime,
298 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
299 DoMethod(data->gfx_composition, MUIM_Notify,
300 MUIA_Selected, MUIV_EveryTime,
301 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
302 DoMethod(data->vesa_width, MUIM_Notify,
303 MUIA_String_Acknowledge, MUIV_EveryTime,
304 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
305 DoMethod(data->vesa_height, MUIM_Notify,
306 MUIA_String_Acknowledge, MUIV_EveryTime,
307 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
308 DoMethod(data->vesa_depth, MUIM_Notify,
309 MUIA_Cycle_Active, MUIV_EveryTime,
310 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
311 DoMethod(data->vesa_refresh, MUIM_Notify,
312 MUIA_String_Acknowledge, MUIV_EveryTime,
313 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
314 DoMethod(data->vesa_default_refresh, MUIM_Notify,
315 MUIA_Selected, MUIV_EveryTime,
316 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
317 DoMethod(data->vesa_best_res, MUIM_Notify,
318 MUIA_Selected, MUIV_EveryTime,
319 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
320 DoMethod(data->ata_buses, MUIM_Notify,
321 MUIA_Cycle_Active, MUIV_EveryTime,
322 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
323 DoMethod(data->ata_dma, MUIM_Notify,
324 MUIA_Selected, MUIV_EveryTime,
325 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
326 DoMethod(data->ata_multi, MUIM_Notify,
327 MUIA_Selected, MUIV_EveryTime,
328 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
329 DoMethod(data->ata_32bit, MUIM_Notify,
330 MUIA_Selected, MUIV_EveryTime,
331 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
332 DoMethod(data->ata_poll, MUIM_Notify,
333 MUIA_Selected, MUIV_EveryTime,
334 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
335 DoMethod(data->device_name, MUIM_Notify,
336 MUIA_String_Acknowledge, MUIV_EveryTime,
337 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
338 DoMethod(data->device_delay, MUIM_Notify,
339 MUIA_String_Acknowledge, MUIV_EveryTime,
340 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
341 DoMethod(data->usb_enable, MUIM_Notify,
342 MUIA_Selected, MUIV_EveryTime,
343 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
344 DoMethod(data->acpi_enable, MUIM_Notify,
345 MUIA_Selected, MUIV_EveryTime,
346 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
347 DoMethod(data->floppy_enable, MUIM_Notify,
348 MUIA_Selected, MUIV_EveryTime,
349 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
350 DoMethod(data->debug_output, MUIM_Notify,
351 MUIA_Cycle_Active, MUIV_EveryTime,
352 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
353 DoMethod(data->debug_mungwall, MUIM_Notify,
354 MUIA_Selected, MUIV_EveryTime,
355 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
356 DoMethod(data->debug_usb, MUIM_Notify,
357 MUIA_Selected, MUIV_EveryTime,
358 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
360 DoMethod(data->gfx_type, MUIM_Notify,
361 MUIA_Cycle_Active, 0,
362 (IPTR)data->vesa_group, 3, MUIM_Set, MUIA_Disabled, FALSE);
363 DoMethod(data->gfx_type, MUIM_Notify,
364 MUIA_Cycle_Active, 1,
365 (IPTR)data->vesa_group, 3, MUIM_Set, MUIA_Disabled, TRUE);
366 DoMethod(data->gfx_type, MUIM_Notify,
367 MUIA_Cycle_Active, 2,
368 (IPTR)data->vesa_group, 3, MUIM_Set, MUIA_Disabled, FALSE);
369 DoMethod(data->gfx_type, MUIM_Notify,
370 MUIA_Cycle_Active, 3,
371 (IPTR)data->vesa_group, 3, MUIM_Set, MUIA_Disabled, TRUE);
373 DoMethod(data->vesa_default_refresh, MUIM_Notify,
374 MUIA_Selected, MUIV_EveryTime,
375 (IPTR)data->vesa_refresh, 3, MUIM_Set, MUIA_Disabled,
376 MUIV_TriggerValue);
377 DoMethod(data->vesa_best_res, MUIM_Notify,
378 MUIA_Selected, MUIV_EveryTime,
379 (IPTR)data->vesa_width, 3, MUIM_Set, MUIA_Disabled,
380 MUIV_TriggerValue);
381 DoMethod(data->vesa_best_res, MUIM_Notify,
382 MUIA_Selected, MUIV_EveryTime,
383 (IPTR)data->vesa_height, 3, MUIM_Set, MUIA_Disabled,
384 MUIV_TriggerValue);
386 /* Set default values */
388 SET(data->gfx_composition, MUIA_Selected, TRUE);
389 SET(data->vesa_width, MUIA_String_Integer, DEFAULT_WIDTH);
390 SET(data->vesa_height, MUIA_String_Integer, DEFAULT_HEIGHT);
391 SET(data->vesa_refresh, MUIA_String_Integer, DEFAULT_REFRESH);
393 SET(data->ata_dma, MUIA_Selected, TRUE);
394 SET(data->ata_multi, MUIA_Selected, TRUE);
395 SET(data->ata_32bit, MUIA_Selected, TRUE);
397 SET(data->device_delay, MUIA_String_Integer, 0);
399 SET(data->usb_enable, MUIA_Selected, TRUE);
400 SET(data->acpi_enable, MUIA_Selected, TRUE);
403 return self;
406 static IPTR BootEditor__MUIM_Setup(Class *CLASS, Object *self, Msg message)
408 if (!DoSuperMethodA(CLASS, self, message))
409 return FALSE;
411 return TRUE;
414 static IPTR BootEditor__MUIM_Cleanup(Class *CLASS, Object *self, Msg message)
416 return DoSuperMethodA(CLASS, self, message);
419 static IPTR BootEditor__MUIM_PrefsEditor_ImportFH(Class *CLASS, Object *self,
420 struct MUIP_PrefsEditor_ImportFH *message)
422 struct BootEditor_DATA *data = INST_DATA(CLASS, self);
423 BPTR file;
424 TEXT line_buffer[MAX_LINE_LENGTH], *line;
425 BOOL success = TRUE, done = FALSE, found = FALSE;
427 /* Find first AROS boot entry, parse its arguments and put them in
428 * the GUI */
430 file = Open(grub_config_path, MODE_OLDFILE);
431 if (file == BNULL)
432 success = FALSE;
434 if (success)
436 while (!done && !found)
438 line = FGets(file, line_buffer, MAX_LINE_LENGTH);
439 if (line == NULL)
440 done = TRUE;
441 else if (strstr(line, "multiboot") != NULL
442 && strstr(line, "bootstrap") != NULL)
444 found = TRUE;
445 if (!ReadBootArgs(line, data))
446 success = FALSE;
451 if (file != NULL)
452 Close(file);
454 return success;
457 static IPTR BootEditor__MUIM_PrefsEditor_ExportFH(Class *CLASS, Object *self,
458 struct MUIP_PrefsEditor_ExportFH *message)
460 return FALSE;
463 static IPTR BootEditor__MUIM_PrefsEditor_Save(Class *CLASS, Object *self,
464 Msg message)
466 struct BootEditor_DATA *data = INST_DATA(CLASS, self);
467 BPTR old_file, new_file;
468 TEXT line_buffer[MAX_LINE_LENGTH], *line;
469 BOOL success = TRUE, done = FALSE, found = FALSE;
471 /* Find first AROS boot entry and replace its arguments with those
472 * chosen in the GUI */
474 old_file = Open(grub_config_path, MODE_OLDFILE);
475 new_file = Open(grub_config_path_tmp, MODE_NEWFILE);
476 if (old_file == BNULL && new_file == BNULL)
477 success = FALSE;
479 if (success)
481 while (!done)
483 line = FGets(old_file, line_buffer, MAX_LINE_LENGTH);
484 if (line == NULL)
485 done = TRUE;
486 else if (!found && strstr(line, "multiboot") != NULL
487 && strstr(line, "bootstrap") != NULL)
489 found = TRUE;
490 strstr(line, ".gz")[3] = '\0';
491 if (FPuts(new_file, line) != 0)
492 success = FALSE;
493 else if (!WriteBootArgs(new_file, data))
494 success = FALSE;
496 else
497 if (FPuts(new_file, line) != 0)
498 success = FALSE;
502 /* Close both files */
504 if (old_file != NULL)
505 Close(old_file);
506 if (new_file != NULL)
507 if (!Close(new_file))
508 success = FALSE;
510 /* Replace old file with new one */
512 if (success)
513 success = DeleteFile(grub_config_path);
515 if (success)
516 success = Rename(grub_config_path_tmp, grub_config_path);
518 return success;
521 static BOOL ReadBootArgs(CONST_STRPTR line, struct BootEditor_DATA *data)
523 UWORD choice, width = 0, height = 0, depth = 0, refresh = 0, delay = 0;
524 BOOL success = TRUE, best_res = FALSE, use_refresh = FALSE;
525 STRPTR options, p;
526 TEXT ch;
528 /* Graphics */
530 if (strstr(line, "nomonitors") != NULL
531 && strstr(line, "vesa=") == NULL)
532 choice = 3;
533 else if (strstr(line, "nomonitors") != NULL)
534 choice = 2;
535 else if (strstr(line, "vesa=") == NULL)
536 choice = 1;
537 else
538 choice = 0;
539 SET(data->gfx_type, MUIA_Cycle_Active, choice);
541 NNSET(data->gfx_composition, MUIA_Selected,
542 strstr(line, "nocomposition") == NULL);
544 /* VESA */
546 options = strstr(line, "vesa=");
547 if (options != NULL)
549 options += 5;
551 while (*options >= '0' && *options <= '9')
552 width = width * 10 + *options++ - '0';
553 if (*options++ == 'x')
555 while (*options >= '0' && *options <= '9')
556 height = height * 10 + *options++ - '0';
557 if (*options++ == 'x')
559 while (*options >= '0' && *options <= '9')
560 depth = depth * 10 + *options++ - '0';
562 else
563 depth = 32;
565 else
567 depth = width, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT;
568 best_res = TRUE;
570 NNSET(data->vesa_width, MUIA_String_Integer, width);
571 NNSET(data->vesa_height, MUIA_String_Integer, height);
572 SET(data->vesa_best_res, MUIA_Selected, best_res);
574 /* Check for user-set refresh rate */
575 if (*(options - 1) == '@')
577 while (*options >= '0' && *options <= '9')
578 refresh = refresh * 10 + *options++ - '0';
579 use_refresh = TRUE;
581 else
582 refresh = DEFAULT_REFRESH;
584 NNSET(data->vesa_refresh, MUIA_String_Integer, refresh);
585 SET(data->vesa_default_refresh, MUIA_Selected, !use_refresh);
587 if (depth > 16)
588 choice = 0;
589 else if (depth > 8)
590 choice = 1;
591 else
592 choice = 0;
593 NNSET(data->vesa_depth, MUIA_Cycle_Active, choice);
596 /* ATA */
598 options = strstr(line, "ATA=");
599 if (options != NULL)
601 if (strstr(options, "nopci") != NULL
602 && strstr(options, "nolegacy") != NULL)
603 choice = 3;
604 else if (strstr(options, "nopci") != NULL)
605 choice = 2;
606 else if (strstr(options, "nolegacy") != NULL)
607 choice = 1;
608 else
609 choice = 0;
610 NNSET(data->ata_buses, MUIA_Cycle_Active, choice);
612 if (strstr(options, "nodma") != NULL)
613 NNSET(data->ata_dma, MUIA_Selected, FALSE);
614 if (strstr(options, "nomulti") != NULL)
615 NNSET(data->ata_multi, MUIA_Selected, FALSE);
616 if (strstr(options, "32bit") == NULL)
617 NNSET(data->ata_multi, MUIA_Selected, FALSE);
618 if (strstr(options, "poll") != NULL)
619 NNSET(data->ata_poll, MUIA_Selected, TRUE);
622 /* Boot Device */
624 options = strstr(line, "bootdevice=");
625 if (options != NULL)
627 options += 11;
629 for (p = options; *p != ' ' && *p != '\n' && *p != '\0'; p++);
630 ch = *p;
631 *p = '\0';
632 NNSET(data->device_name, MUIA_String_Contents, options);
633 *p = ch;
636 options = strstr(line, "bootdelay=");
637 if (options != NULL)
639 options += 10;
641 while (*options >= '0' && *options <= '9')
642 delay = delay * 10 + *options++ - '0';
644 NNSET(data->device_delay, MUIA_String_Integer, delay);
646 /* Miscellaneous */
648 NNSET(data->usb_enable, MUIA_Selected,
649 strstr(line, "enableusb") != NULL);
650 NNSET(data->acpi_enable, MUIA_Selected,
651 strstr(line, "noacpi") == NULL);
652 NNSET(data->floppy_enable, MUIA_Selected,
653 strstr(line, "floppy=disabled") == NULL);
655 /* Debugging */
657 if (strstr(line, "debug=serial") != NULL)
658 choice = 2;
659 else if (strstr(line, "debug=memory") != NULL)
660 choice = 1;
661 else
662 choice = 0;
663 NNSET(data->debug_output, MUIA_Cycle_Active, choice);
665 NNSET(data->debug_mungwall, MUIA_Selected,
666 strstr(line, "mungwall") != NULL);
667 NNSET(data->debug_usb, MUIA_Selected,
668 strstr(line, "usbdebug") != NULL);
670 return success;
673 static BOOL WriteBootArgs(BPTR file, struct BootEditor_DATA *data)
675 UWORD count, choice, width, height, depth, delay;
676 BOOL success = TRUE;
677 CONST_STRPTR name;
679 /* VESA */
681 if((XGET(data->gfx_type, MUIA_Cycle_Active) & 1) == 0)
683 FPrintf(file, " vesa=");
684 if(!XGET(data->vesa_best_res, MUIA_Selected))
686 width = XGET(data->vesa_width, MUIA_String_Integer);
687 height = XGET(data->vesa_height, MUIA_String_Integer);
688 #if 0
689 FPrintf(file, "%ux%ux", width, height);
690 #else
691 FPrintf(file, "%ux", width);
692 FPrintf(file, "%ux", height);
693 #endif
695 choice = XGET(data->vesa_depth, MUIA_Cycle_Active);
696 if (choice == 0)
697 depth = 32;
698 else if (choice == 1)
699 depth = 16;
700 else
701 depth = 8;
702 FPrintf(file, "%u", depth);
703 if(!XGET(data->vesa_default_refresh, MUIA_Selected))
704 FPrintf(file, "@%u", XGET(data->vesa_refresh, MUIA_String_Integer));
707 /* Graphics */
709 if(XGET(data->gfx_type, MUIA_Cycle_Active) > 1)
710 FPrintf(file, " nomonitors");
711 if(!XGET(data->gfx_composition, MUIA_Selected))
712 FPrintf(file, " nocomposition");
714 /* ATA */
716 if(!XGET(data->ata_dma, MUIA_Selected) ||
717 !XGET(data->ata_multi, MUIA_Selected) ||
718 XGET(data->ata_32bit, MUIA_Selected) ||
719 XGET(data->ata_poll, MUIA_Selected) ||
720 XGET(data->ata_buses, MUIA_Cycle_Active) > 0)
722 count = 0;
723 FPrintf(file, " ATA=");
725 choice = XGET(data->ata_buses, MUIA_Cycle_Active);
726 if (choice == 1)
728 FPrintf(file, "nolegacy");
729 count++;
731 else if (choice == 2)
733 FPrintf(file, "nopci");
734 count++;
736 else if (choice == 3)
738 FPrintf(file, "nopci,nolegacy");
739 count += 2;
742 if(!XGET(data->ata_dma, MUIA_Selected))
744 if(count > 0)
745 FPrintf(file, ",");
746 FPrintf(file, "nodma");
747 count++;
749 if(!XGET(data->ata_multi, MUIA_Selected))
751 if(count > 0)
752 FPrintf(file, ",");
753 FPrintf(file, "nomulti");
754 count++;
756 if(XGET(data->ata_32bit, MUIA_Selected))
758 if(count > 0)
759 FPrintf(file, ",");
760 FPrintf(file, "32bit");
761 count++;
763 if(XGET(data->ata_poll, MUIA_Selected))
765 if(count > 0)
766 FPrintf(file, ",");
767 FPrintf(file, "poll");
768 count++;
772 /* Boot device */
774 GET(data->device_name, MUIA_String_Contents, &name);
775 if (*name != '\0')
776 FPrintf(file, " bootdevice=%s", name);
777 delay = XGET(data->device_delay, MUIA_String_Integer);
778 if(delay != 0)
779 FPrintf(file, " bootdelay=%u", delay);
781 /* Miscellaneous */
783 if(XGET(data->usb_enable, MUIA_Selected))
784 FPrintf(file, " enableusb");
785 if(!XGET(data->acpi_enable, MUIA_Selected))
786 FPrintf(file, " noacpi");
787 if(!XGET(data->floppy_enable, MUIA_Selected))
788 FPrintf(file, " floppy=disabled");
790 /* Debugging */
792 if(XGET(data->debug_output, MUIA_Cycle_Active) == 1)
793 FPrintf(file, " debug=memory");
794 else if(XGET(data->debug_output, MUIA_Cycle_Active) == 2)
795 FPrintf(file, " debug=serial");
796 if(XGET(data->debug_mungwall, MUIA_Selected))
797 FPrintf(file, " mungwall");
798 if(XGET(data->debug_usb, MUIA_Selected))
799 FPrintf(file, " usbdebug");
801 if (FPrintf(file, "\n") < 0)
802 success = FALSE;
804 return success;
807 ZUNE_CUSTOMCLASS_6
809 BootEditor, NULL, MUIC_PrefsEditor, NULL,
810 OM_NEW, struct opSet *,
811 MUIM_Setup, Msg,
812 MUIM_Cleanup, Msg,
813 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
814 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
815 MUIM_PrefsEditor_Save, Msg