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