Example #1
0
File: setup.c Project: rj76/kq
/*! \brief Release memory used by samples
 * \author  : Josh Bolduc
 * \date ????????
 *
 *  Duh.
 */
void free_samples (void)
{
   int index;

   if (is_sound == 0)
      return;

   for (index = 0; index < MAX_SAMPLES; index++)
      unload_datafile_object (sfx[index]);
}
Example #2
0
File: enemyc.c Project: rj76/kq
/*! \brief Unload the data loaded by load_enemies()
 *
 * JB would have said 'duh' here! Not much explanation required.
 * \author PH
 * \date 2003????
 */
void unload_enemies (void)
{
   int i;
   if (enemies != NULL) {
      for (i = 0; i < enemies_n; ++i) {
         destroy_bitmap (enemies[i]->img);
         free (enemies[i]);
      }
      free (enemies);
      enemies = NULL;
      unload_datafile_object (enemy_pcx);
   }
}
Example #3
0
File: combat.c Project: rj76/kq
/*! \brief Really do combat once fighters have been inited
 *
 * \param   bg Background image
 * \param   mus Music
 * \param   is_rnd If !=0 then this is a random combat
 * \returns 1 if battle occurred
 */
static int do_combat (char *bg, char *mus, int is_rnd)
{
   int zoom_step;
   in_combat = 1;
   backart = load_datafile_object (PCX_DATAFILE, bg);
   if (is_rnd) {
      if ((numchrs == 1) && (pidx[0] == AYLA)) {
         hs = rand () % 100 + 1;
         ms = rand () % 3 + 1;
      } else {
         if (numchrs > 1 && (in_party (AYLA) > 0)) {
            hs = rand () % 20 + 1;
            ms = rand () % 5 + 1;
         } else {
            hs = rand () % 10 + 1;
            ms = rand () % 10 + 1;
         }
      }
   } else {
      hs = 10;
      ms = 10;
   }

   /*  RB: do the zoom at the beginning of the combat.  */
   pause_music ();
   set_music_volume ((gmvol / 250.0) * 0.75);
   play_music (mus, 0);
   if (stretch_view == 2) {
      do_transition (TRANS_FADE_OUT, 2);
      clear_bitmap (double_buffer);
      do_transition (TRANS_FADE_IN, 64);
   } else
      /* TT TODO:
       * Change this so when we zoom into the battle, it won't just zoom into the middle
       * of the screen.  Instead, it's going to zoom into the location where the player
       * is, so if he's on the side of the map somewhere...
       */
      for (zoom_step = 0; zoom_step < 9; zoom_step++) {
         poll_music ();

         /*  RB FIXME: stretching when 640x480, stretching when 320x240?  */
         /*            shouldn't one of those be the "common" size, and   */
         /*            therefore not needing to stretch it?               */
         /*            320x240 is the double_buffer size...               */
         if (stretch_view == 1)
            stretch_blit (double_buffer, screen, zoom_step * 16 + xofs,
                          zoom_step * 12 + yofs, 320 - (zoom_step * 32),
                          240 - (zoom_step * 24), 0, 0, 640, 480);

         else
            stretch_blit (double_buffer, screen, zoom_step * 16 + xofs,
                          zoom_step * 12 + yofs, 320 - (zoom_step * 32),
                          240 - (zoom_step * 24), 0, 0, 320, 240);

         /*  RB FIXME: should we vsync here rather than rest?  */
         kq_wait (100);
      }
   snap_togrid ();
   roll_initiative ();
   curx = 0;
   cury = 0;
   vspell = 0;
   combatend = 0;

   /*  RB: execute combat  */
   do_round ();
   unload_datafile_object (backart);
   set_music_volume (gmvol / 250.0);
   resume_music ();
   if (alldead)
      stop_music ();
   steps = 0;
   in_combat = 0;
   timer_count = 0;
   return (1);
}
Example #4
0
/*! \brief Main menu screen
 *
 * This is the main menu... just display the opening and then the menu and
 * then wait for input.  Also handles loading a saved game, and the config menu.
 *
 * \param   c zero if the splash (the bit with the staff and the eight heroes)
 *            should be displayed.
 * \returns 1 if new game, 0 if continuing, 2 if exit
 */
int start_menu (int skip_splash)
{
   int stop = 0, ptr = 0, redraw = 1, a, b;
   DATAFILE *bg;
   BITMAP *staff, *dudes, *tdudes;

#ifdef DEBUGMODE
   if (debugging == 0) {
#endif
      play_music ("oxford.s3m", 0);
      /* Play splash (with the staff and the heroes in circle */
      if (skip_splash == 0) {
         bg = load_datafile_object (PCX_DATAFILE, "KQT_PCX");
         staff = create_bitmap_ex (8, 72, 226);
         dudes = create_bitmap_ex (8, 112, 112);
         tdudes = create_bitmap_ex (8, 112, 112);
         blit ((BITMAP *) bg->dat, staff, 0, 7, 0, 0, 72, 226);
         blit ((BITMAP *) bg->dat, dudes, 80, 0, 0, 0, 112, 112);
         clear_bitmap (double_buffer);
         blit (staff, double_buffer, 0, 0, 124, 22, 72, 226);
         blit2screen (0, 0);

         kq_wait (1000);
         for (a = 0; a < 42; a++) {
            stretch_blit (staff, double_buffer, 0, 0, 72, 226, 124 - (a * 32),
                          22 - (a * 96), 72 + (a * 64), 226 + (a * 192));
            blit2screen (0, 0);
            kq_wait (100);
         }
         for (a = 0; a < 5; a++) {
            color_scale (dudes, tdudes, 53 - a, 53 + a);
            draw_sprite (double_buffer, tdudes, 106, 64);
            blit2screen (0, 0);
            kq_wait (100);
         }
         draw_sprite (double_buffer, dudes, 106, 64);
         blit2screen (0, 0);
         kq_wait (1000);
         destroy_bitmap (staff);
         destroy_bitmap (dudes);
         destroy_bitmap (tdudes);
		 unload_datafile_object(bg);
         /*
            TODO: this fade should actually be to white
            if (_color_depth == 8)
            fade_from (pal, whp, 1);
            else
          */
         do_transition (TRANS_FADE_WHITE, 1);
      }
      clear_to_color (double_buffer, 15);
      blit2screen (0, 0);
      set_palette (pal);
      bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX");
      for (a = 0; a < 16; a++) {
         clear_to_color (double_buffer, 15 - a);
         masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 60 - (a * 4),
                      320, 124);
         blit2screen (0, 0);
         kq_wait (a == 0 ? 500 : 100);
      }
      if (skip_splash == 0)
         kq_wait (500);
#ifdef DEBUGMODE
   } else {
      set_palette (pal);
      bg = load_datafile_object (PCX_DATAFILE, "TITLE_PCX");
   }
#endif

   reset_world ();

   /* Draw menu and handle menu selection */
   while (!stop) {
      if (redraw) {
         clear_bitmap (double_buffer);
         masked_blit ((BITMAP *) bg->dat, double_buffer, 0, 0, 0, 0, 320, 124);
         menubox (double_buffer, 112, 116, 10, 4, BLUE);
         print_font (double_buffer, 128, 124, _("Continue"), FNORMAL);
         print_font (double_buffer, 128, 132, _("New Game"), FNORMAL);
         print_font (double_buffer, 136, 140, _("Config"), FNORMAL);
         print_font (double_buffer, 144, 148, _("Exit"), FNORMAL);
         draw_sprite (double_buffer, menuptr, 112, ptr * 8 + 124);
         redraw = 0;
      }
      display_credits ();
      blit2screen (0, 0);
      readcontrols ();
      if (bhelp) {
         unpress ();
         show_help ();
         redraw = 1;
      }
      if (up) {
         unpress ();
         if (ptr > 0)
            ptr--;
         else
            ptr = 3;
         play_effect (SND_CLICK, 128);
         redraw = 1;
      }
      if (down) {
         unpress ();
         if (ptr < 3)
            ptr++;
         else
            ptr = 0;
         play_effect (SND_CLICK, 128);
         redraw = 1;
      }
      if (balt) {
         unpress ();
         if (ptr == 0) {        /* User selected "Continue" */
            if (snc[0] == 0 && snc[1] == 0 && snc[2] == 0 && snc[3] == 0
                && snc[4] == 0)
               stop = 2;
            else if (saveload (0) == 1)
               stop = 1;
            redraw = 1;
         } else if (ptr == 1) { /* User selected "New Game" */
            stop = 2;
         } else if (ptr == 2) { /* Config */
            clear (double_buffer);
            config_menu ();
            redraw = 1;

            /* TODO: Save Global Settings Here */
         } else if (ptr == 3) { /* Exit */
            unload_datafile_object (bg);
            klog (_("Then exit you shall!"));
            return 2;
         }
      }
   }
   unload_datafile_object (bg);
   if (stop == 2) {
      /* New game init */
      for (a = 0; a < MAXCHRS; a++)
         memcpy (&party[a], &players[a].plr, sizeof (s_player));
      init_players ();
      memset (progress, 0, SIZE_PROGRESS);
      memset (treasure, 0, SIZE_TREASURE);
      numchrs = 0;
      for (a = 0; a < NUMSHOPS; a++) {
         for (b = 0; b < SHOPITEMS; b++)
            shops[a].items_current[b] = shops[a].items_max[b];
      }
      for (b = 0; b < 2; b++) {
         for (a = 0; a < MAX_INV; a++)
            g_inv[a][b] = 0;
      }
   }
   return stop - 1;
}
Example #5
0
File: ex5.c Project: sdeming/alex
int main(int argc, char *argv[])
{
	DATAFILE *datf;
	BITMAP *scrFlip;
	BITMAP *scrMap;
	PALETTE pal;
	WINDOW *winInfo;
	long frames = 0L;
	float start_time, end_time;
	MAP *map, *overlay;
	int x = 0, y = 0;
	int old_x = -1, old_y = -1;
	int dx = 1, dy = 1;
	int view_w, view_h;
	int do_idle = 1;
	char s[128];

	// Default screen resolution to 320x200.
	screen_width = 320;
	screen_height = 200;

	// Read command line args.	Set screen size accordingly.
	if (argc > 2)
	{
		screen_width = atoi(argv[1]);
		screen_height = atoi(argv[2]);
	}
	right_size = 0;
	bottom_size = 0;

	printf("screen: %dX%d\n", screen_width, screen_height);

	// Initialize Allegro.	Great library!
	allegro_init();
	install_timer();
	install_keyboard();

	// Set graphics mode.
	if (set_gfx_mode(GFX_AUTODETECT, screen_width, screen_height, 0, 0) == -1)
	{
		printf("Cannot set video mode to %d, %d.\n", screen_width, screen_height);
		return 1;
	}

	// load comic font from ex4.
	datf = load_datafile_object("ex.dat", "comic12");
	if (datf == NULL)
	{
		allegro_exit();
		printf("Error loading ex.dat\n");
		return 1;
	}

	text_mode(-1);

	// load map
	//printf("loading map\n");
	map = load_map("tile1.wmp", "tile1.spr", pal);
	if (map == NULL)
	{
		allegro_exit();
		printf("Error loading map file.\n");
		return 1;
	}

	// load overlay
	//printf("loading overlay\n");
	overlay = load_map("tile1ovr.wmp", NULL, NULL);
	if (overlay == NULL)
	{
		allegro_exit();
		printf("Error loading overlay file.\n");
		return 1;
	}
	map_settileset(overlay, map->tileset);

	// Allocate buffers for our rendering.
	//printf("allocating buffers\n");
	scrFlip = create_bitmap(SCREEN_W, SCREEN_H);
	clear(scrFlip);
	scrMap = create_bitmap(SCREEN_W + map->t_width*2, SCREEN_H + map->t_height*2);

	// set palette
	//printf("setting palette\n");
	gui_setpalette(pal);

	// Build rgb_table.
	text_mode(makecol8(0, 0, 0));
	textout_centre(screen, font, "Building RGB table.", SCREEN_W>>1, 10, 100);
	create_rgb_table(&rgb_table, pal, rgb_table_callback);
	rgb_map = &rgb_table;

	// Build lighting table.
	text_mode(makecol8(0, 0, 0));
	textout_centre(screen, font, "Building lighting table.", SCREEN_W>>1, 10, 100);
	create_light_table(&light_table, pal, 64, 64, 64, rgb_table_callback);

	// Build translucency table.
	text_mode(makecol8(0, 0, 0));
	textout_centre(screen, font, "Building translucency table.", SCREEN_W>>1, 10, 100);
	create_trans_table(&trans_table, pal, 128, 128, 128, rgb_table_callback);

	color_map = &trans_table;

	// initialize gui
	gui_initialize(&light_table, &trans_table);

	// set map and overlay color tables
	map_settables(map, &trans_table, &light_table);
	map_settables(overlay, &trans_table, &light_table);

	// create info window
	winInfo = gui_create_window(128, 200, WB_THICK, WD_TRANSLUCENT);
	gui_move_window(winInfo, SCREEN_W-winInfo->window.w, 0);

	// set up vars.
	view_w = scrMap->w/map->t_width;
	view_h = scrMap->h/map->t_height;

	// setup time_to_blit interrupt.
	LOCK_VARIABLE(time_to_blit);
	LOCK_FUNCTION(time_to_blit_timer);
	install_int_ex(time_to_blit_timer, BPS_TO_TIMER(30));

	missed_frames = 0;
	// main loop.
	start_time = clock();
	while (1)
	{
		idle_time = 0;
		if (do_idle)
			while (!time_to_blit) idle_proc(); // lock it in at around 30 fps.
		time_to_blit = 0;
		if (idle_time < lowest_idle)
			lowest_idle = idle_time;
		if (idle_time > highest_idle)
			highest_idle = idle_time;

		// render map
		if (map_getx_tile(map, x) != old_x || map_gety_tile(map, y) != old_y)
		{
			render_map(map, scrMap, 0, 0, x, y, view_w, view_h);
			render_map(overlay, scrMap, 0, 0, x, y, view_w, view_h);
			old_x = map_getx_tile(map, x);
			old_y = map_gety_tile(map, y);
		}
		blit(scrMap, scrFlip, map_getx_offset(map, x), map_gety_offset(map, y), 0, 0, SCREEN_W-right_size, SCREEN_H-bottom_size);

		gui_clear_window(winInfo, makecol8(0, 0, 0));
		gui_textout_centre_window(winInfo, "Map Demo", 2, makecol8(255, 0, 0), -1);
		sprintf(s, "X: %d, Y: %d", x, y);
		gui_textout_centre_window(winInfo, s, 14, makecol8(0, 0, 255), -1);
		sprintf(s, "DX: %d, DY: %d", dx, dy);
		gui_textout_centre_window(winInfo, s, 24, makecol8(0, 0, 255), -1);
		sprintf(s, "X Ofs: %d", map_getx_offset(map, x));
		gui_textout_centre_window(winInfo, s, 34, makecol8(0, 0, 255), -1);
		sprintf(s, "Y Ofs: %d", map_gety_offset(map, y));
		gui_textout_centre_window(winInfo, s, 44, makecol8(0, 0, 255), -1);
		sprintf(s, "Idle: %d", idle_time);
		gui_textout_centre_window(winInfo, s, 64, makecol8(0, 255, 255), -1);
		sprintf(s, "Missed: %d", missed_frames);
		gui_textout_centre_window(winInfo, s, 74, makecol8(0, 255, 255), -1);
		gui_draw_window(winInfo, scrFlip);

		// blit it
		//vsync();
		blit(scrFlip, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

		// check keys
		if (key[KEY_SPACE])
		{
			break;
		}

		if (key[KEY_LSHIFT])
			do_idle = 0;
		else
			do_idle = 1;

		if (key[KEY_CONTROL])
			gui_set_window_styles(winInfo, -1, WD_BLIT);
		else
			gui_set_window_styles(winInfo, -1, WD_TRANSLUCENT);

		if (key[KEY_PGDN])
		{
			dx--;
			if (dx < 1)
				dx = 1;
			dy--;
			if (dy < 1)
				dy = 1;
		}
		if (key[KEY_PGUP])
		{
			dx++;
			dy++;
		}

		if (key[KEY_RIGHT])
		{
			x+=dx;
			if (x > (map->w_width-1) - SCREEN_W)
			{
				x-=dx;
			}
		}

		if (key[KEY_DOWN])
		{
			y+=dy;
			if (y > (map->w_height-1) - SCREEN_H)
			{
				y-=dy;
			}
		}

		if (key[KEY_LEFT])
		{
			x-=dx;
			if (x < 0)
			{
				x = 0;
			}
		}

		if (key[KEY_UP])
		{
			y-=dy;
			if (y < 0)
			{
				y = 0;
			}
		}

		// Increment frame counter.
		frames++;
	}
	end_time = clock();

	// Clean up.
	unload_datafile_object(datf);
	destroy_map(map);
	overlay->tileset=NULL;
	destroy_map(overlay);
	destroy_bitmap(scrFlip);
	destroy_bitmap(scrMap);

	// Close down allegro.
	allegro_exit();

	// Report.
	printf("Tile Map, Copyright 1997 by Scott Deming.\n");
	printf("\nHow'd we do?\n");
	printf("===============================================================================\n");
	printf("  Time:  %3.2f\n", (float) ((end_time-start_time) / 100));
	printf("Frames:  %lu\n", frames);
	printf("   FPS:  %3.2f\n", (float) (float) frames / (float) ((end_time-start_time) / 100));
	printf("Missed:  %d\n", missed_frames);
	printf("  Idle:  %d (lowest was %d, highest %d)\n", idle_time, lowest_idle, highest_idle);
	printf("Screen:  %dX%d\n", screen_width, screen_height);
	printf("-------------------------------------------------------------------------------\n");
	printf("Note:  If \"Idle\" starts to get close to zero then things should be done to\n");
	printf("       speed things up.  When idle proc hits zero, we'll start missing frames\n");
	printf("       (indicated by \"Missed\") and things can start to get a bit jerky.\n");
	printf("       If \"Missed\" is greater than 0, start optimizing.\n");
	printf("       If you turned off the 30 fps timer halt then your lowest idle will be 0.\n");

	return 0;
}
Example #6
0
static int load_resource(char *datafile, char *name, ICON_DATA *icon)
{
   DATAFILE *data;
   BITMAP *temp, *bitmap = NULL;
   RLE_SPRITE *rle_sprite;
   PALETTE palette;
   int size, type, i;
   int result = 0;
   
   if (datafile[0] != '\0') {
      data = load_datafile_object(datafile, name);
      if (!data) {
         fprintf(stderr, "Error loading object '%s' from %s\n", name, datafile);
	 return -1;
      }
      switch (data->type) {
      
         case DAT_BITMAP:
	    temp = (BITMAP *)data->dat;
	    bitmap = create_bitmap_ex(temp->vtable->color_depth, temp->w, temp->h);
	    blit(temp, bitmap, 0, 0, 0, 0, temp->w, temp->h);
	    break;
	    
	 case DAT_RLE_SPRITE:
	    rle_sprite = (RLE_SPRITE *)data->dat;
	    bitmap = create_bitmap_ex(rle_sprite->color_depth, rle_sprite->w, rle_sprite->h);
	    clear_to_color(bitmap, bitmap->vtable->mask_color);
	    draw_rle_sprite(bitmap, rle_sprite, 0, 0);
	    break;
	    
	 case DAT_PALETTE:
	    select_palette((RGB *)data->dat);
	    unload_datafile_object(data);
	    return 0;
	 
	 default:
	    fprintf(stderr, "'%s' is not a BITMAP, RLE_SPRITE or PALETTE object in datafile '%s'\n", name, datafile);
	    unload_datafile_object(data);
	    return -1;
      }
      unload_datafile_object(data);
   }
   else {
      bitmap = load_bitmap(name, palette);
      select_palette(palette);
      if (!bitmap) {
         fprintf(stderr, "Unable to load '%s'\n", name);
	 return -1;
      }
   }
   
   if (!icon) {
      size = MAX(bitmap->w, bitmap->h);
      if (size <= 16)
         type = ICON_SMALL;
      else if (size <= 32)
         type = ICON_LARGE;
      else if (size <= 48)
         type = ICON_HUGE;
      else
         type = ICON_THUMBNAIL;
      icon = &icon_data[type];
      if (flags & icon->defined) {
         for (i = 0; i < 3; i++) {
	    type = (type + 1) % 4;
	    icon = &icon_data[type];
	    if (!(flags & icon->defined))
	       break;
	 }
	 if (flags & icon->defined) {
	    fprintf(stderr, "Too many icon resources!");
	    result = -1;
	    goto exit_error;
	 }
      }
   }
   else {
      if (icon->scaled) {
         fprintf(stderr, "Multiple icon resources of the same size");
	 result = -1;
	 goto exit_error;
      }
   }
   icon->original = create_bitmap_ex(bitmap->vtable->color_depth, bitmap->w, bitmap->h);
   blit(bitmap, icon->original, 0, 0, 0, 0, bitmap->w, bitmap->h);
   result = scale_icon(icon);
   flags |= icon->defined;
   
exit_error:
   destroy_bitmap(bitmap);
   
   return result;
}
Example #7
0
int main(int argc, char *argv[])
{
   static char config_override[] = "[system]\nkeyboard = \n";
   RGB black_rgb = {0, 0, 0, 0};
   DATAFILE *font_data;
   int c;

   if (allegro_init() != 0)
      exit(EXIT_FAILURE);

   if (argc > 1) {
      if (strcmp(argv[1], "--split-altgr") == 0) {
         split_altgr = TRUE;
      }
      else {
         allegro_message("Error: unrecognized option\n");
         exit(EXIT_FAILURE);
      }
   }

   install_mouse();
   install_timer();

   push_config_state();
   override_config_data(config_override, sizeof(config_override));
   install_keyboard();
   pop_config_state();

   memcpy(orig_key_ascii_table, _key_ascii_table, sizeof(orig_key_ascii_table));
   memcpy(orig_key_capslock_table, _key_capslock_table, sizeof(orig_key_capslock_table));
   memcpy(orig_key_shift_table, _key_shift_table, sizeof(orig_key_shift_table));
   memcpy(orig_key_control_table, _key_control_table, sizeof(orig_key_control_table));
   memcpy(orig_key_altgr_lower_table, _key_altgr_lower_table, sizeof(orig_key_altgr_lower_table));
   memcpy(orig_key_altgr_upper_table, _key_altgr_upper_table, sizeof(orig_key_altgr_upper_table));
   memcpy(orig_key_accent1_lower_table, _key_accent1_lower_table, sizeof(orig_key_accent1_lower_table));
   memcpy(orig_key_accent1_upper_table, _key_accent1_upper_table, sizeof(orig_key_accent1_upper_table));
   memcpy(orig_key_accent2_lower_table, _key_accent2_lower_table, sizeof(orig_key_accent2_lower_table));
   memcpy(orig_key_accent2_upper_table, _key_accent2_upper_table, sizeof(orig_key_accent2_upper_table));
   memcpy(orig_key_accent3_lower_table, _key_accent3_lower_table, sizeof(orig_key_accent3_lower_table));
   memcpy(orig_key_accent3_upper_table, _key_accent3_upper_table, sizeof(orig_key_accent3_upper_table));
   memcpy(orig_key_accent4_lower_table, _key_accent4_lower_table, sizeof(orig_key_accent4_lower_table));
   memcpy(orig_key_accent4_upper_table, _key_accent4_upper_table, sizeof(orig_key_accent4_upper_table));

   memcpy(my_key_ascii_table, _key_ascii_table, sizeof(my_key_ascii_table));
   memcpy(my_key_capslock_table, _key_capslock_table, sizeof(my_key_capslock_table));
   memcpy(my_key_shift_table, _key_shift_table, sizeof(my_key_shift_table));
   memcpy(my_key_control_table, _key_control_table, sizeof(my_key_control_table));
   memcpy(my_key_altgr_lower_table, _key_altgr_lower_table, sizeof(my_key_altgr_lower_table));
   memcpy(my_key_altgr_upper_table, _key_altgr_upper_table, sizeof(my_key_altgr_upper_table));
   memcpy(my_key_accent1_lower_table, _key_accent1_lower_table, sizeof(my_key_accent1_lower_table));
   memcpy(my_key_accent1_upper_table, _key_accent1_upper_table, sizeof(my_key_accent1_upper_table));
   memcpy(my_key_accent2_lower_table, _key_accent2_lower_table, sizeof(my_key_accent2_lower_table));
   memcpy(my_key_accent2_upper_table, _key_accent2_upper_table, sizeof(my_key_accent2_upper_table));
   memcpy(my_key_accent3_lower_table, _key_accent3_lower_table, sizeof(my_key_accent3_lower_table));
   memcpy(my_key_accent3_upper_table, _key_accent3_upper_table, sizeof(my_key_accent3_upper_table));
   memcpy(my_key_accent4_lower_table, _key_accent4_lower_table, sizeof(my_key_accent4_lower_table));
   memcpy(my_key_accent4_upper_table, _key_accent4_upper_table, sizeof(my_key_accent4_upper_table));

   _key_ascii_table = my_key_ascii_table;
   _key_capslock_table = my_key_capslock_table;
   _key_shift_table = my_key_shift_table;
   _key_control_table = my_key_control_table;
   _key_altgr_lower_table = my_key_altgr_lower_table;
   _key_altgr_upper_table = my_key_altgr_upper_table;
   _key_accent1_lower_table = my_key_accent1_lower_table;
   _key_accent1_upper_table = my_key_accent1_upper_table;
   _key_accent2_lower_table = my_key_accent2_lower_table;
   _key_accent2_upper_table = my_key_accent2_upper_table;
   _key_accent3_lower_table = my_key_accent3_lower_table;
   _key_accent3_upper_table = my_key_accent3_upper_table;
   _key_accent4_lower_table = my_key_accent4_lower_table;
   _key_accent4_upper_table = my_key_accent4_upper_table;

   edit_menu[0].dp = _key_ascii_table;
   edit_menu[1].dp = _key_capslock_table;
   edit_menu[2].dp = _key_shift_table;
   edit_menu[3].dp = _key_control_table;
   edit_menu[4].dp = _key_altgr_lower_table;
   edit_menu[5].dp = _key_altgr_upper_table;
   edit_menu[6].dp = _key_accent1_lower_table;
   edit_menu[7].dp = _key_accent1_upper_table;
   edit_menu[8].dp = _key_accent2_lower_table;
   edit_menu[9].dp = _key_accent2_upper_table;
   edit_menu[10].dp = _key_accent3_lower_table;
   edit_menu[11].dp = _key_accent3_upper_table;
   edit_menu[12].dp = _key_accent4_lower_table;
   edit_menu[13].dp = _key_accent4_upper_table;

   if (!split_altgr)
      edit_menu[5].flags = D_DISABLED;

   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }

   set_palette(desktop_palette);
   set_color(0, &black_rgb);
   gui_fg_color = palette_color[255];
   gui_bg_color = palette_color[16];

   /* We set up colors to match screen color depth (in case it changed) */
   for (c = 0; main_dlg[c].proc; c++) {
      main_dlg[c].fg = palette_color[main_dlg[c].fg];
      main_dlg[c].bg = palette_color[main_dlg[c].bg];
   }
   for (c = 0; ascii_dlg[c].proc; c++) {
      ascii_dlg[c].fg = palette_color[ascii_dlg[c].fg];
      ascii_dlg[c].bg = palette_color[ascii_dlg[c].bg];
   }
   for (c = 0; editor_dlg[c].proc; c++) {
      editor_dlg[c].fg = palette_color[editor_dlg[c].fg];
      editor_dlg[c].bg = palette_color[editor_dlg[c].bg];
   }
   for (c = 0; accent_dlg[c].proc; c++) {
      accent_dlg[c].fg = palette_color[accent_dlg[c].fg];
      accent_dlg[c].bg = palette_color[accent_dlg[c].bg];
   }

   _key_standard_kb = FALSE;

   font_data = load_datafile_object ("keyconf.dat", "BASE_FONT");

   if (font_data)
      font = font_data->dat;

   do_dialog(main_dlg, -1);

   if (font_data)
      unload_datafile_object(font_data);

   return 0;
}