home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / riscbsd / 1_1_beta / upgrades / bootloader / !BtRiscBSD_c_config < prev    next >
Encoding:
Text File  |  1996-02-26  |  24.7 KB  |  853 lines

  1. /*
  2.  * Copyright (c) 1995 Mark Brinicombe.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by Mark Brinicombe.
  16.  * 4. The name of the company nor the name of the author may be used to
  17.  *    endorse or promote products derived from this software without specific
  18.  *    prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26.  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29.  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  *
  31.  * RiscBSD kernel project
  32.  *
  33.  * config.c
  34.  *
  35.  * Bootloader configuration window management routines
  36.  *
  37.  * Created      : 26/04/95
  38.  * Last updated : 24/02/96
  39.  */
  40.  
  41. /* Include standard header files */
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46.  
  47. #include "wimp.h"
  48. #include "Event.h"       /* Event despatcher                             */
  49. #include "Error.h"       /* Error despatcher                             */
  50. #include "Window.h"      /* Window handling automation                   */
  51. #include "Icon.h"        /* Icon handling automation                     */
  52. #include "WimpSWIs.h"    /* Default event handlers                       */
  53. #include "IconExt.h"     /* Icon handling automation                     */
  54. #include "Screen.h"      /* Getting screen size info, etc   */
  55. #include "Msgs.h"
  56. #include "Menu.h"
  57. #include "SWI.h"
  58. #include "dlswis.h"
  59. #include "swiv.h"
  60.  
  61. #include "icons.h"
  62. #include "prototypes.h"
  63. #include "config.h"
  64.  
  65. /* Declare global variables */
  66.  
  67. window_handle config_window = NULL;
  68. window_handle config_backing = NULL;
  69. window_handle egowindow = NULL;
  70. menu_ptr rootdevpopup_menu = NULL;
  71. menu_ptr swapdevpopup_menu = NULL;
  72. menu_ptr ramdiscpopup_menu = NULL;
  73. Config config = {
  74.     "<BtRiscBSD$Dir>.^.NetBSD",
  75.     "/dev/wd0a",
  76.     "/dev/wd0b",
  77.     "X1024 Y768 C256 F60",
  78.     "",
  79.     32,
  80.     0,
  81.     0,
  82.     0,
  83.     0,
  84.     0,
  85.     0
  86. };
  87.  
  88. /* Declare external variables */
  89.  
  90. /* Local function prototypes */
  91.  
  92. BOOL Config_PaneHandler(event_pollblock *event, void *reference);
  93. BOOL Config_Close(event_pollblock *event, void *reference);
  94. BOOL Config_Click(event_pollblock *event, void *reference);
  95.  
  96. /* Now for the main code */
  97.  
  98.  
  99. /*
  100.  * Initialise the configuration module. This just loads the saved config file.
  101.  */
  102.  
  103. void Config_Initialise(void)
  104.   {
  105.     Config_Load(CONFIG_FILENAME);
  106.  
  107. /*  Create device popup menus */
  108.  
  109.     rootdevpopup_menu = Menu_CreateMenu("Root Devices",
  110.       "/dev/wd0a,/dev/wd1a,/dev/fd0a,/dev/fd1a,/dev/rd0a,/dev/rd1a,/dev/sd0a,/dev/sd1a,/dev/cd0a,/dev/cd1a");
  111.     if (!rootdevpopup_menu)
  112.       Msgs_ReportFatal(0x00000000, "err.0", "RootDevPopup");
  113.  
  114.     swapdevpopup_menu = Menu_CreateMenu("Swap Devices",
  115.       "/dev/wd0b,/dev/wd1b,/dev/sd0b,/dev/sd1b");
  116.     if (!swapdevpopup_menu)
  117.       Msgs_ReportFatal(0x00000000, "err.0", "SwapDevPopup");
  118.  
  119.     ramdiscpopup_menu = Menu_CreateMenu("Ramdisc",
  120.       "0K,1440K");
  121.     if (!ramdiscpopup_menu)
  122.       Msgs_ReportFatal(0x00000000, "err.0", "RamdiscPopup");
  123.  
  124.   }
  125.  
  126.  
  127. /*
  128.  * Load a new configuration file.
  129.  */
  130.  
  131. int Config_Load(char *filename)
  132.   {
  133.     FILE *filehandle;
  134.     char string[300];
  135.     char tag[40];
  136.     char value[256];
  137.     
  138.     filehandle = fopen(filename, "r");
  139.     if (!filehandle) return(1);
  140.  
  141.     fread(string, 12, 1, filehandle);
  142.     string[12] = 0;
  143.     if (strcmp(string, "#!BtRiscBSD\n") != 0)
  144.       {
  145.         fclose(filehandle);
  146.         return(2);
  147.       }
  148.  
  149.     while (!feof(filehandle))
  150.       {
  151.         if (fgets(string, 300, filehandle) == NULL)
  152.           continue;
  153.  
  154.         if (sscanf(string, "%[^:]: %[^\n]", tag, value) == 2)
  155.           {
  156.             if (strcmp(tag, "kernel") == 0)
  157.               strcpy(config.kernel, value);
  158.             if (strcmp(tag, "rootdev") == 0)
  159.               strcpy(config.root_dev, value);
  160.             if (strcmp(tag, "swapdev") == 0)
  161.               strcpy(config.swap_dev, value);
  162.             if (strcmp(tag, "screenmode") == 0)
  163.               strcpy(config.screenmode, value);
  164.             if (strcmp(tag, "other") == 0)
  165.               strcpy(config.other, value);
  166.             if (strcmp(tag, "ramdisc") == 0)
  167.               config.ramdisc = atoi(value);
  168.             if (strcmp(tag, "maxproc") == 0)
  169.               config.max_proc = atoi(value);
  170.             if (strcmp(tag, "flags") == 0)
  171.               sscanf(value, "%x", &config.flags);
  172.             if (strcmp(tag, "cpuflags") == 0)
  173.               sscanf(value, "%x", &config.cpu_flags);
  174.             if (strcmp(tag, "pmapdebug") == 0)
  175.               config.pmap_debug_level = atoi(value);
  176.             if (strcmp(tag, "kmodule") == 0)
  177.               config.kmodule = atoi(value);
  178.             if (strcmp(tag, "videodram") == 0)
  179.               config.video_dram = atoi(value);
  180.           }
  181.       }
  182.  
  183.     fclose(filehandle);
  184.     return(0);
  185.   }
  186.  
  187.  
  188. /*
  189.  * Save a configuration file
  190.  */
  191.  
  192. int Config_Save(char *filename)
  193.   {
  194.     FILE *filehandle;
  195.     
  196.     filehandle = fopen(filename, "w");
  197.     if (filehandle)
  198.       {
  199.         fprintf(filehandle, "#!BtRiscBSD\n");
  200.         fprintf(filehandle, "kernel: %s\n", config.kernel);
  201.         fprintf(filehandle, "rootdev: %s\n", config.root_dev);
  202.         fprintf(filehandle, "swapdev: %s\n", config.swap_dev);
  203.         fprintf(filehandle, "screenmode: %s\n", config.screenmode);
  204.         fprintf(filehandle, "other: %s\n", config.other);
  205.         fprintf(filehandle, "ramdisc: %dK\n", config.ramdisc);
  206.         fprintf(filehandle, "maxproc: %d\n", config.max_proc);
  207.         fprintf(filehandle, "flags: %08x\n", config.flags);
  208.         fprintf(filehandle, "cpuflags: %08x\n", config.cpu_flags);
  209.         fprintf(filehandle, "pmapdebug: %d\n", config.pmap_debug_level);
  210.         fprintf(filehandle, "kmodule: %dK\n", config.kmodule);
  211.         fprintf(filehandle, "videodram: %dK\n", config.video_dram);
  212.         fclose(filehandle);
  213.         swi(OS_File, IN(R0|R1|R2), 18, CONFIG_FILENAME, FILETYPE_UNIX);
  214.       }
  215.     else
  216.       return(1);
  217.  
  218.     return(0);
  219.   }
  220.  
  221.  
  222. /*
  223.  * Open the configuration window (the backing and the pane)
  224.  */
  225.  
  226. void Config_OpenWindow(void)
  227.   {
  228.     window_state wstate;
  229.     event_pollblock event;
  230.     attached_menu *at_menu;
  231.     icon_block istate;
  232.     FILE *filehandle;
  233.  
  234. /* Are we already open ? */
  235.  
  236.     if (config_backing)
  237.       {
  238.         Wimp_GetWindowState(config_backing, &wstate);
  239.         wstate.openblock.behind = -1;
  240.         event.data.openblock = wstate.openblock;
  241.         event.data.openblock.behind = -1;
  242.         Config_PaneHandler(&event, NULL);
  243.         return;
  244.       }
  245.  
  246. /* Create and open our main windows from the template "control". */
  247.  
  248.     config_window = Window_Create("configpane", 0);
  249.     config_backing = Window_CreateAndShow("config", 0, open_CENTERED);
  250.  
  251.     if (!config_backing || !config_window) Msgs_ReportFatal(0x00000000,
  252.       "err.1", "config");
  253.  
  254.     Wimp_GetIconState(config_backing, CONFIG_WINDOW_ICON_LOGO, &istate);
  255.     if (screen_bpp == 8)
  256.       strcpy(istate.data.indirectsprite.name, "riscbsd256");
  257.     else
  258.       strcpy(istate.data.indirectsprite.name, "riscbsd16");
  259.  
  260.     Icon_ForceRedraw(config_backing, CONFIG_WINDOW_ICON_LOGO);
  261.  
  262. /* Claim window-close events for the config window */
  263.  
  264.     Event_Claim(event_CLOSE, config_backing, event_ANY, Config_Close, NULL);
  265.  
  266. /* Claim the window open events to handle the pane */
  267.  
  268.     Event_Claim(event_OPEN, config_backing, event_ANY, Config_PaneHandler,
  269.       (void *)1);
  270.  
  271. /* Set the correct state for all the icons */
  272.  
  273.     Config_SetIcons();
  274.  
  275. /* Add mouse click handlers */
  276.  
  277.     Event_Claim(event_CLICK, config_backing, CONFIG_WINDOW_ICON_LOGO,
  278.       Config_Click, NULL);
  279.     Event_Claim(event_CLICK, config_backing, CONFIG_WINDOW_ICON_BOOT,
  280.       Config_Confirm, (void *)0x01);
  281.     Event_Claim(event_CLICK, config_backing, CONFIG_WINDOW_ICON_SAVE,
  282.       Config_Confirm, (void *)0x02);
  283.     Event_Claim(event_CLICK, config_backing, CONFIG_WINDOW_ICON_CANCEL,
  284.       Config_Confirm, (void *)0x03);
  285.  
  286.     at_menu = Menu_AttachMenu(rootdevpopup_menu, config_window,
  287.       CONFIG_PANE_ICON_ROOTDEV_POPUP, Config_RootDevPopup, NULL, NULL, NULL);
  288.     at_menu->flags |= MENU_FLAG_POPUP;
  289.  
  290.     at_menu = Menu_AttachMenu(rootdevpopup_menu, config_window,
  291.       CONFIG_PANE_ICON_ROOTDEV, Config_RootDevPopup, NULL, NULL, NULL);
  292.     at_menu->flags |= MENU_FLAG_POPUP;
  293.  
  294.     at_menu = Menu_AttachMenu(swapdevpopup_menu, config_window,
  295.       CONFIG_PANE_ICON_SWAPDEV_POPUP, Config_SwapDevPopup, NULL, NULL, NULL);
  296.     at_menu->flags |= MENU_FLAG_POPUP;
  297.  
  298.     at_menu = Menu_AttachMenu(swapdevpopup_menu, config_window,
  299.       CONFIG_PANE_ICON_SWAPDEV, Config_SwapDevPopup, NULL, NULL, NULL);
  300.     at_menu->flags |= MENU_FLAG_POPUP;
  301.  
  302.     at_menu = Menu_AttachMenu(ramdiscpopup_menu, config_window,
  303.       CONFIG_PANE_ICON_RAMDISC_POPUP, Config_RamdiscPopup, NULL, NULL, NULL);
  304.     at_menu->flags |= MENU_FLAG_POPUP;
  305.  
  306.     at_menu = Menu_AttachMenu(ramdiscpopup_menu, config_window,
  307.       CONFIG_PANE_ICON_RAMDISC, Config_RamdiscPopup, NULL, NULL, NULL);
  308.     at_menu->flags |= MENU_FLAG_POPUP;
  309.  
  310. /* Check for support for native booting */
  311.  
  312.     filehandle = fopen(NATIVE_SUPPORT, "r");
  313.     if (filehandle)
  314.       {
  315.         Icon_SetShade(config_window, CONFIG_PANE_ICON_NATIVE, 0);
  316.         fclose(filehandle);
  317.       }
  318.  
  319. /* Set the correct state for opening */
  320.  
  321.     Wimp_GetWindowState(config_backing, &wstate);
  322.     event.data.openblock = wstate.openblock;
  323.     event.data.openblock.behind = -1;
  324.     Config_PaneHandler(&event, NULL);
  325.   }
  326.  
  327.  
  328. /*
  329.  * Handle a open window request on the configuration window.
  330.  * We have to open both the backing window and the pane at the appropriate
  331.  * position.
  332.  */
  333.  
  334. BOOL Config_PaneHandler(event_pollblock *event, void *reference)
  335.   {
  336.     int x, y, w, h;
  337.     window_state wstate;
  338.  
  339. /* Are we on screen ? - Only check is this a forced refresh */
  340.  
  341.     if (reference == NULL)
  342.       {
  343.         Screen_CacheModeInfo();
  344.         if (event->data.openblock.screenrect.max.x > screen_size.x)
  345.           {
  346.             event->data.openblock.screenrect.min.x -=
  347.               (event->data.openblock.screenrect.max.x - screen_size.x);
  348.             event->data.openblock.screenrect.max.x = screen_size.x;
  349.           }
  350.  
  351.         if (event->data.openblock.screenrect.max.y > screen_size.y)
  352.           {
  353.             event->data.openblock.screenrect.min.y -=
  354.               (event->data.openblock.screenrect.max.y - (screen_size.y - 44));
  355.             event->data.openblock.screenrect.max.y = (screen_size.y - 44);
  356.           }
  357.       }
  358.  
  359. /* Calculate the dimensions of the config pane */
  360.  
  361.     x = event->data.openblock.screenrect.min.x + CONFIG_PANE_LEFT_OFFSET;
  362.     w = CONFIG_PANE_WIDTH;
  363.     y = event->data.openblock.screenrect.max.y - CONFIG_PANE_VERTICAL_OFFSET;
  364.  
  365.     Wimp_GetWindowState(config_backing, &wstate);
  366.     h = wstate.openblock.screenrect.max.y - wstate.openblock.screenrect.min.y
  367.         - 2 * CONFIG_PANE_VERTICAL_OFFSET;
  368.  
  369.     Wimp_GetWindowState(config_window, &wstate);
  370. /*    h = wstate.openblock.screenrect.max.y - wstate.openblock.screenrect.min.y;*/
  371.  
  372. /* If pane has changed reopen it */
  373.  
  374.     if (wstate.openblock.screenrect.min.x != x
  375.      || wstate.openblock.screenrect.max.x != x+w
  376.      || wstate.openblock.screenrect.max.y != y
  377.      || wstate.openblock.screenrect.min.y != y - h
  378.      || wstate.openblock.behind != event->data.openblock.behind)
  379.       {
  380.         wstate.openblock.screenrect.min.x = x;
  381.         wstate.openblock.screenrect.max.x = x + w;
  382.         wstate.openblock.screenrect.max.y = y;
  383.         wstate.openblock.screenrect.min.y = y - h;
  384.         wstate.openblock.behind = event->data.openblock.behind;
  385.         Wimp_OpenWindow(&wstate.openblock);
  386.       }
  387.  
  388. /* Now open the config window underneath the config pane */
  389.  
  390.     event->data.openblock.behind = config_window;
  391.     Wimp_OpenWindow(&(event->data.openblock));
  392.     return(TRUE);
  393.   }
  394.  
  395.  
  396. /*
  397.  * Close the configuration window.
  398.  */
  399.  
  400. BOOL Config_Close(event_pollblock *event, void *reference)
  401.   {
  402.     Config_GetIcons();
  403.  
  404.     Window_Delete(config_window);
  405.     Window_Delete(config_backing);
  406.     config_window = NULL;
  407.     config_backing = NULL;
  408.     return(1);
  409.   }
  410.  
  411.  
  412. /*
  413.  * Build the first line of the boot obey file.
  414.  */
  415.  
  416. void Config_BuildLine0(char *string)
  417.   {
  418.  
  419. /* Are we loading the kernel from the RiscBSD partition ? */
  420.  
  421.     if (config.flags & FLAG_NATIVE)
  422.       sprintf(string, "Run %s.%s", NATIVE_DIRECTORY, config.root_dev);
  423.     else
  424.       strcpy(string, "|Not using native kernel");
  425.   }
  426.  
  427.  
  428. /*
  429.  * Build the second line of the boot obey file.
  430.  */
  431.  
  432. void Config_BuildLine1(char *command)
  433.   {
  434.     char temp[256];
  435.  
  436. /* Build the command string */
  437.         
  438.     sprintf(command, "Run %s ", BOOTLOADER_FILENAME);
  439.     strcat(command, config.kernel);
  440.     strcat(command, " ");
  441.     if (config.root_dev[0])
  442.       {
  443.         sprintf(temp, "root=%s ", config.root_dev);
  444.         strcat(command, temp);
  445.       }
  446.     if (config.swap_dev[0])
  447.       {
  448.         sprintf(temp, "swap=%s ", config.swap_dev);
  449.         strcat(command, temp);
  450.       }
  451.     if (config.screenmode[0])
  452.       {
  453.         sprintf(temp, "screenmode=%s ", config.screenmode);
  454.         strcat(command, temp);
  455.       }
  456.     if (config.ramdisc > 0)
  457.       {
  458.         sprintf(temp, "ramdisc=%dK ", config.ramdisc);
  459.         strcat(command, temp);
  460.       }
  461.     sprintf(temp, "maxproc=%d ", config.max_proc);
  462.     strcat(command, temp);
  463.     if (config.flags & FLAG_SINGLE)
  464.       strcat(command, "single ");
  465.     if (config.flags & FLAG_KGDB)
  466.       strcat(command, "kgdb ");
  467.     if (config.cpu_flags & CPU_FLAG_NOCACHE)
  468.       strcat(command, "nocache ");
  469.     if (config.cpu_flags & CPU_FLAG_NOWRTBUF)
  470.       strcat(command, "nowritebuf ");
  471.     if (config.cpu_flags & CPU_FLAG_NOFPA)
  472.       strcat(command, "nofpa ");
  473.     if (config.cpu_flags & CPU_FLAG_FPA_CLK2)
  474.       strcat(command, "fpaclk2 ");
  475.  
  476.     if (config.flags & FLAG_PMAP_DEBUG)
  477.       {
  478.         sprintf(temp, "pmapdebug=%d ", config.pmap_debug_level);
  479.         strcat(command, temp);
  480.       }
  481.       
  482.     if (config.flags & FLAG_KMODULE)
  483.       {
  484.         sprintf(temp, "kmodule=%dK ", config.kmodule);
  485.         strcat(command, temp);
  486.       }
  487.  
  488.     if (config.flags & FLAG_TERMDEBUG)
  489.       strcat(command, "termdebug ");
  490.       
  491.  
  492.     if (config.flags & FLAG_SYMTAB)
  493.       strcat(command, "symtab ");
  494.  
  495.     if (config.flags & FLAG_DDBBOOT)
  496.       strcat(command, "kdb ");
  497.  
  498.     if (config.video_dram > 0)
  499.       {
  500.         sprintf(temp, "videodram=%dK ", config.video_dram);
  501.         strcat(command, temp);
  502.       }
  503.       
  504.     strcat(command, config.other);
  505.   }
  506.  
  507.  
  508. /*
  509.  * On of the main confirmation icons has been pressed
  510.  */
  511.  
  512. BOOL Config_Confirm(event_pollblock *event, void *reference)
  513.   {
  514.     int action = (int)reference;
  515.     FILE *filehandle;
  516.     char command[1024];
  517.     message_block message;
  518.  
  519. /*
  520.  * Update the config structure to reflect the current states of the
  521.  * icons.
  522.  */
  523.  
  524.     if (event)
  525.       Config_GetIcons();
  526.  
  527. /* Was it a save config request ? */
  528.     
  529.     if (action == 0x02)
  530.       {
  531.         if (Config_Save(CONFIG_FILENAME))
  532.           Msgs_Report(0x00000000, "err.4", CONFIG_FILENAME);
  533.  
  534. /* Open the fastboot file */
  535.  
  536.         filehandle = fopen(FASTBOOT_FILENAME, "w");
  537.         if (filehandle)
  538.           {
  539. /* Write the first command line to the fast boot file */
  540.             Config_BuildLine0(command);
  541.             fputs(command, filehandle);
  542.             fputc('\n', filehandle);
  543.  
  544. /* Write the second command line to the fast boot file */
  545.  
  546.             Config_BuildLine1(command);
  547.  
  548.             fputs(command, filehandle);
  549.             fputc('\n', filehandle);
  550.             fclose(filehandle);
  551.  
  552. /* Set the file type to obey */
  553.  
  554.             swi(OS_File, IN(R0|R1|R2), 18, FASTBOOT_FILENAME, FILETYPE_OBEY);
  555.           }            
  556.       }
  557.  
  558. /* Was it a boot request ? */
  559.  
  560.     if (action == 0x01)
  561.       {
  562.  
  563. /* Ok we should do something about unsaved data in applications... */
  564.  
  565. /* Instead of just booting we send a PREQUIT message to everybody.
  566.  * The we wait for the message to be returned as an acknowledgement
  567.  * before booting/
  568.  */
  569.  
  570.         message.header.size = sizeof(message_header);
  571.         message.header.yourref = 0;
  572.         message.header.action = message_PREQUIT;
  573.         message.header.sender = event_taskhandle;
  574.  
  575.         Wimp_SendMessage(event_SENDWANTACK, &message,
  576.           0, 0);
  577.  
  578. /*
  579.  * Build the first command line. This mounts a RiscBSD partition of booting
  580.  * with native kernel.
  581.  */
  582.  
  583. /*      Config_BuildLine0(command);
  584.         Wimp_StartTask(command);*/
  585.  
  586. /*
  587.  * Build the second command line. This actually runs the boot loader
  588.  */
  589.  
  590. /*        Config_BuildLine1(command);
  591.         Wimp_StartTask(command);    */
  592.      }
  593.  
  594. /* Junk the window if necessary */
  595.  
  596.  
  597.     if (action == 0x03 /*event && !event->data.mouse.button.data.adjust*/)
  598.       {
  599.         Config_Close(NULL, NULL);
  600.       }
  601.  
  602.     return(1);
  603.   }
  604.  
  605.  
  606. BOOL Message_Ack(event_pollblock *event, void *reference)
  607.   {
  608.     char command[1024];
  609.  
  610.     if (event->data.message.header.action == 8
  611.      && event->data.message.header.sender == event_taskhandle)
  612.       {
  613. /*
  614.  * Build the first command line. This mounts a RiscBSD partition of booting
  615.  * with native kernel.
  616.  */
  617.  
  618.         Config_BuildLine0(command);
  619.         Wimp_StartTask(command);
  620.  
  621. /*
  622.  * Build the second command line. This actually runs the boot loader
  623.  */
  624.  
  625.         Config_BuildLine1(command);
  626.         Wimp_StartTask(command);    
  627.       }
  628.     return(1);
  629.   }
  630.  
  631.  
  632. /* We need a keypress handler to pick up the restart PREQUIT key code
  633.  * (Closedown sequence)
  634.  */
  635.  
  636. BOOL Config_Keypress(event_pollblock *event, void *reference)
  637.   {
  638.     message_block message;
  639.  
  640.     if (event->data.key.code == 0x1fc)
  641.       {
  642.         message.header.size = sizeof(message_header);
  643.         message.header.yourref = 0;
  644.         message.header.action = message_PREQUIT;
  645.         message.header.sender = event_taskhandle;
  646.  
  647.         Wimp_SendMessage(event_SENDWANTACK, &message,
  648.           0, 0);
  649.         
  650.       }
  651.     else
  652.       Wimp_ProcessKey(event->data.key.code);
  653.     return(1);
  654.   }
  655.  
  656.  
  657.  
  658. /*
  659.  * Set the configuration pane icons to the correct states so that
  660.  * they match the config structure.
  661.  */
  662.  
  663. void Config_SetIcons(void)
  664.   {
  665.     Icon_SetText(config_window, CONFIG_PANE_ICON_KERNEL, config.kernel);
  666.     Icon_SetText(config_window, CONFIG_PANE_ICON_ROOTDEV, config.root_dev);
  667.     Icon_SetText(config_window, CONFIG_PANE_ICON_SWAPDEV, config.swap_dev);
  668.     Icon_SetText(config_window, CONFIG_PANE_ICON_SCREENMODE, config.screenmode);
  669.     Icon_SetText(config_window, CONFIG_PANE_ICON_OTHER, config.other);
  670.  
  671.     Icon_SetInteger(config_window, CONFIG_PANE_ICON_MAXPROC, config.max_proc);
  672.     Icon_printf(config_window, CONFIG_PANE_ICON_RAMDISC, "%dK", config.ramdisc);
  673.  
  674.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_SINGLE,
  675.       (config.flags & FLAG_SINGLE));
  676.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_NATIVE,
  677.       (config.flags & FLAG_NATIVE));
  678.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_KGDB,
  679.       (config.flags & FLAG_KGDB));
  680.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_NOCACHE,
  681.       (config.cpu_flags & CPU_FLAG_NOCACHE));
  682.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_NOWRTBUF,
  683.       (config.cpu_flags & CPU_FLAG_NOWRTBUF));
  684.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_NOFPA,
  685.       (config.cpu_flags & CPU_FLAG_NOFPA));
  686.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_FPA_CLK_2,
  687.       (config.cpu_flags & CPU_FLAG_FPA_CLK2));
  688.  
  689.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_PMAP_DEBUG,
  690.       (config.flags & FLAG_PMAP_DEBUG));
  691.     Icon_SetInteger(config_window, CONFIG_PANE_ICON_PMAP_DEBUG_VAL,
  692.        config.pmap_debug_level);
  693.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_KMODULE,
  694.       (config.flags & FLAG_KMODULE));
  695.     Icon_printf(config_window, CONFIG_PANE_ICON_KMODULE_VAL, "%dK",
  696.       config.kmodule);
  697.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_TERMDEBUG,
  698.       (config.flags & FLAG_TERMDEBUG));
  699.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_SYMBOL_TABLE,
  700.       (config.flags & FLAG_SYMTAB));
  701.     Icon_SetSelect(config_window, CONFIG_PANE_ICON_DDB_BOOT,
  702.       (config.flags & FLAG_DDBBOOT));
  703.  
  704.     Icon_printf(config_window, CONFIG_PANE_ICON_VIDEO_DRAM, "%dK", config.video_dram);
  705.   }
  706.  
  707.  
  708. /*
  709.  * Set the config structure to the correct states so that
  710.  * they match the configuration pane icons.
  711.  */
  712.  
  713.  
  714. void Config_GetIcons(void)
  715.   {
  716.     Icon_GetText(config_window, CONFIG_PANE_ICON_KERNEL, config.kernel);
  717.     Icon_GetText(config_window, CONFIG_PANE_ICON_ROOTDEV, config.root_dev);
  718.     Icon_GetText(config_window, CONFIG_PANE_ICON_SWAPDEV, config.swap_dev);
  719.     Icon_GetText(config_window, CONFIG_PANE_ICON_SCREENMODE, config.screenmode);
  720.     Icon_GetText(config_window, CONFIG_PANE_ICON_OTHER, config.other);
  721.  
  722.     config.max_proc = Icon_GetInteger(config_window, CONFIG_PANE_ICON_MAXPROC);
  723.     config.ramdisc = Icon_GetInteger(config_window, CONFIG_PANE_ICON_RAMDISC);
  724.  
  725.     config.flags = 0;
  726.     
  727.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_SINGLE))
  728.       config.flags |= FLAG_SINGLE;
  729.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_NATIVE))
  730.       config.flags |= FLAG_NATIVE;
  731.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_KGDB))
  732.       config.flags |= FLAG_KGDB;
  733.  
  734.     config.cpu_flags = 0;
  735.  
  736.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_NOCACHE))
  737.       config.cpu_flags |= CPU_FLAG_NOCACHE;
  738.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_NOWRTBUF))
  739.       config.cpu_flags |= CPU_FLAG_NOWRTBUF;
  740.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_NOFPA))
  741.       config.cpu_flags |= CPU_FLAG_NOFPA;
  742.      if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_FPA_CLK_2))
  743.       config.cpu_flags |= CPU_FLAG_FPA_CLK2;
  744.       
  745.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_PMAP_DEBUG))
  746.       config.flags |= FLAG_PMAP_DEBUG;
  747.     config.pmap_debug_level = Icon_GetInteger(config_window,
  748.       CONFIG_PANE_ICON_PMAP_DEBUG_VAL);
  749.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_KMODULE))
  750.       config.flags |= FLAG_KMODULE;
  751.     config.kmodule = Icon_GetInteger(config_window,
  752.       CONFIG_PANE_ICON_KMODULE_VAL);
  753.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_TERMDEBUG))
  754.       config.flags |= FLAG_TERMDEBUG;
  755.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_SYMBOL_TABLE))
  756.       config.flags |= FLAG_SYMTAB;
  757.     if (Icon_GetSelect(config_window, CONFIG_PANE_ICON_DDB_BOOT))
  758.       config.flags |= FLAG_DDBBOOT;
  759.  
  760.     config.video_dram = Icon_GetInteger(config_window, CONFIG_PANE_ICON_VIDEO_DRAM);
  761.  
  762.   }
  763.  
  764.  
  765. BOOL Config_Click(event_pollblock *event, void *reference)
  766.   {
  767.     if (egowindow) return(1);
  768.     
  769.     egowindow = Window_CreateAndShow("egotrip", 0, open_UNDERPOINTER);
  770.     if (egowindow)
  771.       {
  772.         Menu_HandleDbox(egowindow);
  773.         Window_Delete(egowindow);
  774.         egowindow = NULL;
  775.       }
  776.     else
  777.       Msgs_Report(0x00000000, "err.1", "egotrip");
  778.     return(1);
  779.   }
  780.  
  781.  
  782. /*
  783.  * Root device menu selection
  784.  */
  785.  
  786. BOOL Config_RootDevPopup(event_pollblock *event, void *reference)
  787.   {
  788.     int item = event->data.words[0];
  789.     menu_item *entry_ptr;
  790.  
  791.     entry_ptr = (menu_item *) (rootdevpopup_menu + 1);
  792.  
  793.     Icon_SetText(config_window, CONFIG_PANE_ICON_ROOTDEV,
  794.       entry_ptr[item].icondata.text);
  795.  
  796. /* Ok don't have a nice way to do this yet... */
  797.  
  798. /* Update the ramdisc as required */
  799.  
  800.     if (item != 4 && item != 5 && item != 8 && item != 9)
  801.       Icon_SetText(config_window, CONFIG_PANE_ICON_RAMDISC, "0K");
  802.     else
  803.       Icon_SetText(config_window, CONFIG_PANE_ICON_RAMDISC, "1440K");     
  804.  
  805. /* Update the swap dev as required */
  806.  
  807.     if (item == 0 || item == 1)
  808.       Icon_printf(config_window, CONFIG_PANE_ICON_SWAPDEV, "/dev/wd%db", item);
  809.     if (item == 6 || item == 7)
  810.       Icon_printf(config_window, CONFIG_PANE_ICON_SWAPDEV, "/dev/sd%db", item & 1);
  811.  
  812.     return(1);
  813.   }
  814.  
  815.  
  816. /*
  817.  * Swap device menu selection
  818.  */
  819.  
  820. BOOL Config_SwapDevPopup(event_pollblock *event, void *reference)
  821.   {
  822.     int item = event->data.words[0];
  823.     menu_item *entry_ptr;
  824.  
  825.     entry_ptr = (menu_item *) (swapdevpopup_menu + 1);
  826.  
  827.     Icon_SetText(config_window, CONFIG_PANE_ICON_SWAPDEV,
  828.       entry_ptr[item].icondata.text);
  829.     
  830.     return(1);
  831.   }
  832.  
  833.  
  834. /*
  835.  * Ramdisc menu selection
  836.  */
  837.  
  838. BOOL Config_RamdiscPopup(event_pollblock *event, void *reference)
  839.   {
  840.     int item = event->data.words[0];
  841.     menu_item *entry_ptr;
  842.  
  843.     entry_ptr = (menu_item *) (ramdiscpopup_menu + 1);
  844.  
  845.     Icon_SetText(config_window, CONFIG_PANE_ICON_RAMDISC,
  846.       entry_ptr[item].icondata.text);
  847.     
  848.     return(1);
  849.   }
  850.  
  851.  
  852. /* End of config.c */
  853.