SpaceSprite *load_sprite(const char *string, TW_DATAFILE *data, int *index) { char buffy[512]; buffy[0] = 0; char *cp = buffy; char *tp; int argc, i; int rotations = 1; char **argv = get_config_argv("Objects", string, &argc); int count = 0; if (!argc) return NULL; count = atoi(argv[0]); if (!count) return NULL; tp = strchr(argv[0], 'r'); for (i = 1; i < argc; i += 1) { if ((argv[i][0] == '-') || (argv[i][0] == '+')) { cp += sprintf(cp, "%s ", argv[i]); } else if (argv[i][0] == 'r') tp = argv[i]; else {tw_error("load_sprite - unrecognized modifiers '%s'", argv[i]);} } if (tp) { rotations = atoi(tp+1); if (rotations == 0) rotations = 64; } SpaceSprite *sprite = NULL; int attrib = string_to_sprite_attributes(buffy); sprite = new SpaceSprite(&data[*index], count, attrib, rotations); for (i = 0; i < count; i += 1) { destroy_rle_sprite((RLE_SPRITE*)data[(*index)+i].dat); data[(*index)+i].dat = NULL; // brutal hack to free up the memory } *index += count; return sprite; }
int main(int argc, unsigned char **argv) { /* Variables located at IR.config */ int Resol_X, Resol_Y, count; char **screen; if (allegro_init() != 0) /* you should always do this at the start of Allegro programs */ return 1; set_config_file("config/Coco.config"); /* Read configuration file */ install_keyboard(); /* set up the keyboard handler */ install_timer(); /* set up the timer handler */ set_color_depth(32); /* Get screen resolution from Coco.config */ screen = get_config_argv("content", "SCREEN_SIZE", &count); Resol_X = atoi(screen[0]); Resol_Y = atoi(screen[1]); if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, Resol_X, Resol_Y, 0, 0) != 0) /* for X */ { if (set_gfx_mode(GFX_SAFE, Resol_X, Resol_Y, 0, 0) != 0) /* for console */ { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); return 1; } } /* Check if all images exists before trying to blit'em */ /* Add some protection */ set_palette(desktop_palette); /* set the color palette */ /* Read desired sampling time in IR.config */ Delay= (get_config_float("content", "Delay", 0)); iSP= (get_config_float("content", "iSP", 0)); SP= iSP*3.68; /* Go to Register the user and run the program after having hardware initialized */ Register(); return 0; }
void gui_init(void) { int x,y,n; /* Loop counters */ char ini_colours[256]; /* For reading in colour values from the ini */ char **ini_colvals; /* The array of ini colour values */ int argc; /* The number of ini colour values */ /* We need the mouse, so we'll init that */ install_mouse(); /* Read the desired width & height from the ini file */ GUI_SCREEN_W = get_config_int("[gui]","width",640); GUI_SCREEN_H = get_config_int("[gui]","height",480); /* Set the graphics mode */ set_gfx_mode(GFX_AUTODETECT,GUI_SCREEN_W,GUI_SCREEN_H,0,0); clear(screen); /* Create the back-buffer */ gui_buffer = create_bitmap(GUI_SCREEN_W, GUI_SCREEN_H); /* Create the mouse pointer bitmap */ gui_mouse = create_bitmap(11,19); /* Read in the colours from the ini file */ damp_gfx_palette[GUI_COLOUR_BACKGROUND].r = damp_gfx_palette[GUI_COLOUR_BACKGROUND].g = damp_gfx_palette[GUI_COLOUR_BACKGROUND].b = 32; damp_gfx_palette[GUI_COLOUR_SHADOW].r = damp_gfx_palette[GUI_COLOUR_SHADOW].g = damp_gfx_palette[GUI_COLOUR_SHADOW].b = 0; damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].r = damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].g = damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].b = 63; damp_gfx_palette[GUI_COLOUR_WINDOW].r = 63; damp_gfx_palette[GUI_COLOUR_WINDOW].g = damp_gfx_palette[GUI_COLOUR_WINDOW].b = 0; sprintf(ini_colours,get_config_string("[gui]","colours","gui_c_default")); ini_colvals = get_config_argv(ini_colours,"background",&argc); damp_gfx_palette[GUI_COLOUR_BACKGROUND].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_BACKGROUND].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_BACKGROUND].b = atoi(ini_colvals[2]) / 4; ini_colvals = get_config_argv(ini_colours,"titlebar",&argc); damp_gfx_palette[GUI_COLOUR_WINDOW].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_WINDOW].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_WINDOW].b = atoi(ini_colvals[2]) / 4; ini_colvals = get_config_argv(ini_colours,"highlight",&argc); damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_HIGHLIGHT].b = atoi(ini_colvals[2]) / 4; ini_colvals = get_config_argv(ini_colours,"shadow",&argc); damp_gfx_palette[GUI_COLOUR_SHADOW].r = atoi(ini_colvals[0]) / 4; damp_gfx_palette[GUI_COLOUR_SHADOW].g = atoi(ini_colvals[1]) / 4; damp_gfx_palette[GUI_COLOUR_SHADOW].b = atoi(ini_colvals[2]) / 4; set_palette(damp_gfx_palette); /* Initialise the variables */ gui_num_windows = 0; gui_window_dragging = -1; gui_titlebar_height = text_height(font)+4; gui_border_size = 4; /* Initialise the mouse pointer */ clear(gui_mouse); n=0; for(y=0;y<19;y++) for(x=0;x<11;x++) { if(gui_mouse_data[n] == 0) putpixel(gui_mouse,x,y,0); else if(gui_mouse_data[n] == 1) putpixel(gui_mouse,x,y,GUI_COLOUR_SHADOW); else putpixel(gui_mouse,x,y,GUI_COLOUR_HIGHLIGHT); n++; } }
// called only from ReadINIFileInfo for reading in the information from the // ini file and storing it globally static BOOL ReadFromDriverIniFile(void) { char * pBuffer = NULL; char Buffer[255]; int i, k; int argc; char ** argv; pBuffer = get_config_string("General", "Description", "None"); if (strcmp(pBuffer, "None") == 0) { DisplayError("Can't load .ini driver!"); return FALSE; } strncpy(GameDescription, pBuffer, MAX_GAME_DESCRIPTION); GameDescription[MAX_GAME_DESCRIPTION -1] = 0; if ((NumGfxBanks = get_config_int("Layout", "GfxDecodes", 0)) == 0) { DisplayError("INI file error 'GfxDecodes'"); return FALSE; } // if this fail the orientation will be 0 - which is OK. Orientation = get_config_int("Layout", "Orientation", 0); GfxBanks = malloc(NumGfxBanks * sizeof(SPRITE_PALETTE)); if (GfxBanks == NULL) { DisplayError("GfxBanks malloc failed"); return FALSE; } GfxBankExtraInfo = malloc(NumGfxBanks * sizeof(GFXBANKEXTRA)); if (GfxBankExtraInfo == NULL) { free(GfxBanks); DisplayError("GfxBanksExtra malloc failed"); return FALSE; } for (i = 0; i < NumGfxBanks; i++) { char GfxBank[10]; sprintf(GfxBank, "Decode%d", i+1); // read staight forward stuff from INI file GfxBanks[i].sprite_w = get_config_int(GfxBank, "width", -1); GfxBanks[i].sprite_h = get_config_int(GfxBank, "height", -1); GfxBanks[i].n_total = get_config_int(GfxBank, "total", -1); GfxBanks[i].first_sprite = 0; // set the position to the default GfxBankExtraInfo[i].planes = get_config_int(GfxBank, "planes", -1); GfxBankExtraInfo[i].startaddress = get_config_int(GfxBank, "start", -1); GfxBankExtraInfo[i].charincrement = get_config_int(GfxBank, "charincrement", -1); // did any fail? if ((GfxBanks[i].sprite_w == -1) || (GfxBanks[i].sprite_h == -1) || (GfxBanks[i].n_total == -1) || (GfxBankExtraInfo[i].planes == -1) || (GfxBankExtraInfo[i].startaddress == -1) || (GfxBankExtraInfo[i].charincrement == -1)) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt"); return FALSE; } // read plane offsets and store in array argv = get_config_argv(GfxBank, "planeoffsets", &argc); // sanity check if (argc != GfxBankExtraInfo[i].planes) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - planeoffsets"); return FALSE; } // copy planeoffsets in to array for (k = 0; k < argc; k++) GfxBankExtraInfo[i].planeoffsets[k] = atol(argv[k]); // read xoffsets and store in array get_config_int_array(GfxBank, "xoffsets", GfxBankExtraInfo[i].xoffset, &argc); // sanity check if (argc != GfxBanks[i].sprite_w) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - xoffsets"); return FALSE; } // read yoffsets and store in array get_config_int_array(GfxBank, "yoffsets", GfxBankExtraInfo[i].yoffset, &argc); // sanity check if (argc != GfxBanks[i].sprite_h) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - yoffsets"); return FALSE; } } // calculate the number of graphics roms NumGfxRoms = 0; do { NumGfxRoms++; sprintf(Buffer, "Rom%d", NumGfxRoms); pBuffer = get_config_string("GraphicsRoms", Buffer, "None"); } while (strcmp(pBuffer, "None") != 0); NumGfxRoms --; // is the ini file corrupt? if (NumGfxRoms == 0) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("INI file corrupt - graphicsroms"); return FALSE; } // allocate memory for appropriate number of structures; GfxRoms = malloc(NumGfxRoms * sizeof(GFXROM)); if (GfxRoms == NULL) { free(GfxBanks); free(GfxBankExtraInfo); DisplayError("GfxRoms malloc failed"); return FALSE; } // read the information in to the array for (i = 0; i < NumGfxRoms; i ++) { // read rom info and store in array sprintf(Buffer, "Rom%d", i+1); argv = get_config_argv("GraphicsRoms", Buffer, &argc); // sanity check if (argc != 3) // loadaddress,size,name { free(GfxBanks); free(GfxBankExtraInfo); free(GfxRoms); DisplayError("INI file corrupt - %s", Buffer); return FALSE; } // copy info in to array GfxRoms[i].LoadAddress = atol(argv[0]); GfxRoms[i].Size = atol(argv[1]); GfxRoms[i].Alternate = FALSE; // detect for Alternate byte loading flag if ((GfxRoms[i].Size & ALTERNATE_ROMS_DETECT) == ALTERNATE_ROMS_DETECT) { GfxRoms[i].Size &= ALTERNATE_ROMS_SIZE; GfxRoms[i].Alternate = TRUE; } strncpy(GfxRoms[i].ROMName, argv[2], MAX_ROM_NAME); GfxRoms[i].ROMName[MAX_ROM_NAME -1] = 0; } // finally read in the colour palettes or set defaults if none // exist if (ReadColourPalettes() == FALSE) { // free any allocated colour palettes for (i = 0; i < MAX_COL_PLANES; i++) { if (ColPalettes[i] != NULL) { free(ColPalettes[i]); ColPalettes[i] = NULL; NumColPalettes[i] = 0; } } free(GfxBanks); free(GfxBankExtraInfo); free(GfxRoms); return FALSE; } return TRUE; }
/* See README for details. */ void abitmap_init (char const *path, DATAFILE *datafile) { int i; int prev[10]; int cv; char str[1024]; DATAFILE *dat; cv = get_color_conversion (); set_color_conversion (COLORCONV_TOTAL | COLORCONV_KEEP_TRANS); used_bitmaps_cleanup (); push_config_state (); dat = set_theme_config (path, datafile); if (dat != datafile) used_dat = dat; theme->fg_color = get_color_string ("fg", "0x000000"); theme->bg_color = get_color_string ("bg", "0xffffff"); theme->mg_color = get_color_string ("mg", "0x808080"); theme->textpushx = get_config_int ("agup.cfg", "px", 0); theme->textpushy = get_config_int ("agup.cfg", "py", 0); for (i = 0; bload[i].name; i++) { int j; int s; char const *suffix[] = { "", "_hl", "_dis" }; for (s = 0; bload[i].name[s] == ' '; s++); for (j = 0; j < 3; j++) { char **argv = NULL; int argc = 0; BITMAP *bmp = NULL; int got_color = 0; theme->bitmaps[bload[i].elem][j].bmp = NULL; theme->bitmaps[bload[i].elem][j].flags = 0; theme->bitmaps[bload[i].elem][j].bl = 0; theme->bitmaps[bload[i].elem][j].br = 0; theme->bitmaps[bload[i].elem][j].bt = 0; theme->bitmaps[bload[i].elem][j].bb = 0; sprintf (str, "%s%s", bload[i].name + s, suffix[j]); argv = get_config_argv ("agup.cfg", str, &argc); TRACE ("%s: ", str); if (argc) { bmp = find_theme_bitmap (dat, argv[0]); } if (bmp) { int a; theme->bitmaps[bload[i].elem][j].bmp = bmp; for (a = 1; a < argc; a++) { if (!strcmp (argv[a], "stretch")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_H | ABMAP_STRETCH_V; else if (!strcmp (argv[a], "center")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_H | ABMAP_CENTER_V; else if (!strcmp (argv[a], "stretchh")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_H; else if (!strcmp (argv[a], "centerh")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_H; else if (!strcmp (argv[a], "alignh")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_H; else if (!strcmp (argv[a], "stretchv")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_V; else if (!strcmp (argv[a], "centerv")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_V; else if (!strcmp (argv[a], "alignv")) theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_V; else if (!strcmp (argv[a], "cut")) { int cx, cy, cw, ch; a++; if (a < argc) { cx = strtol (argv[a], NULL, 10); a++; if (a < argc) { cy = strtol (argv[a], NULL, 10); a++; if (a < argc) { cw = strtol (argv[a], NULL, 10); a++; if (a < argc) { BITMAP *sub; ch = strtol (argv[a], NULL, 10); if (cw <= 0) cw += bmp->w; if (ch <= 0) ch += bmp->h; sub = create_sub_bitmap (bmp, cx, cy, cw, ch); used_bitmap (sub, NULL); theme->bitmaps[bload[i].elem][j].bmp = sub; } } } } } else if (!strcmp (argv[a], "border")) { a++; if (a < argc) { theme->bitmaps[bload[i].elem][j].bl = strtol (argv[a], NULL, 10); a++; if (a < argc) { theme->bitmaps[bload[i].elem][j].br = strtol (argv[a], NULL, 10); a++; if (a < argc) { theme->bitmaps[bload[i].elem][j].bt = strtol (argv[a], NULL, 10); a++; if (a < argc) { theme->bitmaps[bload[i].elem][j].bb = strtol (argv[a], NULL, 10); } } } } } else if (!strcmp (argv[a], "color")) { a++; if (a < argc) { int rgb32 = strtol (argv[a], NULL, 0); theme->bitmaps[bload[i].elem][j].color = makecol (rgb32 >> 16, (rgb32 >> 8) & 255, rgb32 & 255); got_color = 1; TRACE ("color %06x ", rgb32); } } } TRACE ("loaded successfully.\n"); } else { /* If everything fails, try to inherit from another bitmap. */ if (j) {
int main(void) { int w,h,bpp; int windowed; int count; char **data; char *title; char *filename; int r,g,b; BITMAP *background; int display; RGB pal[256]; int x, y; /* you should always do this at the start of Allegro programs */ if (allegro_init() != 0) return 1; /* set up the keyboard handler */ install_keyboard(); /* save the current ini file, then set the program specific one */ push_config_state(); set_config_file("exconfig.ini"); /* the gfx mode is stored like this: * 640 480 16 * the get_config_argv() function returns a pointer to a char * array, and stores the size of the char array in an int */ data = get_config_argv("graphics", "mode", &count); if (count != 3) { /* We expect only 3 parameters */ allegro_message("Found %i parameters in graphics.mode instead of " "the 3 expected.\n", count); w = 320; h = 200; bpp = 8; } else { w = atoi(data[0]); h = atoi(data[1]); bpp = atoi(data[2]); } /* Should we use a windowed mode? * In the config file this is stored as either FALSE or TRUE. * So we need to read a string and see what it contains. * If the entry is not found, we use "FALSE" by default */ if (ustricmp(get_config_string("graphics", "windowed", "FALSE"), "FALSE") == 0) windowed = GFX_AUTODETECT_FULLSCREEN; else windowed = GFX_AUTODETECT_WINDOWED; /* the title string * The string returned is stored inside of the config system * and would be lost if we call pop_config_state(), so we create * a copy of it. */ title = ustrdup(get_config_string("content", "headline", "<no headline>")); /* the title color * once again this is stored as three ints in one line */ data = get_config_argv("content", "headercolor", &count); if (count != 3) { /* We expect only 3 parameters */ allegro_message("Found %i parameters in content.headercolor " "instead of the 3 expected.\n", count); r = g = b = 255; } else { r = atoi(data[0]); g = atoi(data[1]); b = atoi(data[2]); } /* The image file to read * The string returned is stored inside of the config system * and would be lost if we call pop_config_state(), so we create * a copy of it. */ filename = ustrdup(get_config_string("content", "image", "mysha.pcx")); /* and it's tiling mode */ display = get_config_int("content", "display", 0); if (display <0 || display > 2) { allegro_message("content.display must be within 0..2\n"); display = 0; } /* restore the old config file */ pop_config_state(); /* set the graphics mode */ set_color_depth(bpp); if (set_gfx_mode(windowed, w, h, 0, 0) != 0) { allegro_message("Unable to set mode %ix%i with %ibpp\n", w, h, bpp); free(filename); free(title); exit(-1); } /* Clear the screen */ clear_bitmap(screen); /* load the image */ background = load_bitmap(filename, pal); if (background != NULL) { set_palette(pal); switch (display) { case 0: /* stretch */ stretch_blit(background, screen, 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); break; case 1: /* center */ blit(background, screen, 0, 0, (SCREEN_W - background->w)/2, (SCREEN_H - background->h)/2, background->w, background->h); break; case 2: /* tile */ for (y = 0; y < SCREEN_H; y += background->h) for (x = 0; x < SCREEN_W; x += background->w) blit(background, screen, 0, 0, x, y, background->w, background->h); break; } } else { textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H/2, makecol(r,g,b), -1, "%s not found", filename); } textout_centre_ex(screen, font, title, SCREEN_W/2, 20, makecol(r,g,b), -1); readkey(); free(filename); free(title); return 0; }