Ejemplo n.º 1
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_marker (const s_marker * m, PACKFILE * f)
{
   pack_fwrite (m->name, sizeof (m->name), f);
   pack_iputw (m->x, f);
   pack_iputw (m->y, f);
   return 0;
}
Ejemplo n.º 2
0
Archivo: mapdraw2.c Proyecto: rj76/kq
/*! \brief Save the current map
 *
 * Another even more useful than the original function
 */
void do_save_map (const char *filename)
{
   int p, q;
   PACKFILE *pf;

   pf = pack_fopen (filename, F_WRITE_PACKED);
   save_s_map (&gmap, pf);

   for (q = 0; q < 50; ++q) {
      save_s_entity (&gent[q], pf);
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (map[q * gmap.xsize + p], pf);
      }
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (b_map[q * gmap.xsize + p], pf);
      }
   }
   for (q = 0; q < gmap.ysize; ++q) {
      for (p = 0; p < gmap.xsize; ++p) {
         pack_iputw (f_map[q * gmap.xsize + p], pf);
      }
   }

   pack_fwrite (z_map, (gmap.xsize * gmap.ysize), pf);
   pack_fwrite (sh_map, (gmap.xsize * gmap.ysize), pf);
   pack_fwrite (o_map, (gmap.xsize * gmap.ysize), pf);
   pack_fclose (pf);
}                               /* save_map () */
Ejemplo n.º 3
0
/*! \brief Save all markers out to packfile
 *
 * Saves individual \sa s_marker objects to the specified PACKFILE.
 *
 * \param[out] marray - Current array of markers from whence data are pulled
 * \param[out] pf - PACKFILE to where data is written
 * \return     Non-0 on error, 0 on success
 */
size_t save_markers (s_marker_array *marray, PACKFILE *pf)
{
   size_t i;

   assert (marray && "marray == NULL");
   assert (pf && "pf == NULL");

   if (!marray || !pf) {
      printf ("NULL passed into save_markers()\n");
      return 1;
   }

   pack_iputw (marray->size, pf);
   if (pack_feof (pf)) {
      assert (0 && "pack_iputw() for marray->size received EOF signal.");
      printf ("Encountered EOF when writing marker array size.\n");
      return 2;
   }

   for (i = 0; i < marray->size; ++i) {
      pack_fwrite (marray->array[i].name, sizeof (marray->array[i].name), pf);
      pack_iputw (marray->array[i].x, pf);
      pack_iputw (marray->array[i].y, pf);

      if (pack_feof (pf)) {
         assert (0 && "pack_iputw() for marker->[xy] received EOF signal.");
         printf ("Encountered EOF when writing marker %dsize.\n", i);
         return 3;
      }
   }

   return 0;
}
Ejemplo n.º 4
0
void TiledMap::saveTo(PACKFILE *file)
{
	ASSERT(file);

	// Version info
	// Version 1: No version number stored, one layer in map
	// Version 2: First int is version number, second one the number of layers
	// Version 3: Object list stored at end of tile data.
	pack_iputw(3, file);
	// The map header
	pack_iputw(nrLayers, file);

	// The tile data
	for (int i = 0; i < nrLayers; i++) {
		mapLayers[i]->saveTo(file);
	}

	// Object data
	list<Object*>::iterator i;
	pack_iputw(objects.size(), file);
	for (i = objects.begin(); i != objects.end(); i++) {
		pack_iputw(int(TILES_W * (*i)->x), file);
		pack_iputw(int(TILES_H * (*i)->y), file);
		pack_fputs((*i)->className, file);
		pack_fputs("\n", file);
	}	

	// Extra newline fixes last tile not loaded.
	pack_fputs("\n", file);
}
Ejemplo n.º 5
0
int save_s_entity(s_entity *s, PACKFILE *f)
{
    pack_putc(s->chrx, f);
    pack_putc(0, f);             /* alignment */
    pack_iputw(s->x, f);
    pack_iputw(s->y, f);
    pack_iputw(s->tilex, f);
    pack_iputw(s->tiley, f);
    pack_putc(s->eid, f);
    pack_putc(s->active, f);
    pack_putc(s->facing, f);
    pack_putc(s->moving, f);
    pack_putc(s->movcnt, f);
    pack_putc(s->framectr, f);
    pack_putc(s->movemode, f);
    pack_putc(s->obsmode, f);
    pack_putc(s->delay, f);
    pack_putc(s->delayctr, f);
    pack_putc(s->speed, f);
    pack_putc(s->scount, f);
    pack_putc(s->cmd, f);
    pack_putc(s->sidx, f);
    pack_putc(s->extra, f);
    pack_putc(s->chasing, f);
    pack_iputw(0, f);            /* alignment */
    pack_iputl(s->cmdnum, f);
    pack_putc(s->atype, f);
    pack_putc(s->snapback, f);
    pack_putc(s->facehero, f);
    pack_putc(s->transl, f);
    pack_fwrite(s->script, sizeof(s->script), f);
    return 0;
}
Ejemplo n.º 6
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_bound (const s_bound * b, PACKFILE * f)
{
   pack_iputw (b->x1, f);
   pack_iputw (b->y1, f);
   pack_iputw (b->x2, f);
   pack_iputw (b->y2, f);
   pack_iputw (b->btile, f);
   return 0;
}
Ejemplo n.º 7
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_tileset (s_tileset * s, PACKFILE * f)
{
   int i;
   pack_fwrite (s->icon_set, sizeof (s->icon_set), f);
   for (i = 0; i < MAX_ANIM; ++i) {
      pack_iputw (s->tanim[i].start, f);
      pack_iputw (s->tanim[i].end, f);
      pack_iputw (s->tanim[i].delay, f);
   }
   return 0;
}
Ejemplo n.º 8
0
void save_entity(PACKFILE *file, ENTITY* data) {
     pack_iputl(data->x,file);
     pack_iputl(data->y,file);
     pack_iputl(data->speed,file);
     pack_putc(data->type,file);
     pack_iputw(data->data1,file);
     pack_iputw(data->data2,file);
     pack_iputw(data->data3,file);
     pack_iputw(data->data4,file);
     pack_iputw(data->health,file);
     pack_iputl(data->maxcooldown,file);
}
Ejemplo n.º 9
0
void save_level(PACKFILE *file,LEVEL *data) {
     int i;
     pack_iputw(data->sizey,file);
     pack_iputw(data->sizex,file);
     pack_putc(data->bgtype,file);
     if (data->bgtype == 1) for (i=0;i<600;i++) {pack_putc(getr24(data->lines[i]),file); pack_putc(getg24(data->lines[i]),file); pack_putc(getb24(data->lines[i]),file);}
     pack_iputw(data->entitycnt,file);
     pack_fwrite(data->map,data->length,file);
     for(i=0;i<data->entitycnt;i++) {
         save_entity(file,&data->entities[i]);
     }
}
Ejemplo n.º 10
0
void TiledMapLayer::saveTo(PACKFILE *file)
{
	ASSERT(file);

	// The layer header
	pack_iputw(mapWidth, file);
	pack_iputw(mapHeight, file);

	// The tile data
	for (int y = 0; y < mapHeight; y++)
		for (int x = 0; x < mapWidth; x++)
			getTile(Point(x,y))->saveTo(file);
}
Ejemplo n.º 11
0
/* saves a sample into the datafile format */
static int save_sample_in_datafile(DATAFILE *dat, AL_CONST int *fixed_prop, int pack, int pack_kids, int strip, int sort, int verbose, int extra, PACKFILE *f)
{
   SAMPLE *spl = (SAMPLE *)dat->dat;

   *allegro_errno = 0;

   pack_mputw((spl->stereo) ? -spl->bits : spl->bits, f);
   pack_mputw(spl->freq, f);
   pack_mputl(spl->len, f);
   if (spl->bits == 8) {
      pack_fwrite(spl->data, spl->len * ((spl->stereo) ? 2 : 1), f);
   }
   else {
      int i;

      for (i=0; i < (int)spl->len * ((spl->stereo) ? 2 : 1); i++) {
	 pack_iputw(((int16_t *)spl->data)[i], f);
      }
   }

   if (*allegro_errno)
      return FALSE;
   else
      return TRUE;
}
Ejemplo n.º 12
0
Archivo: disk.c Proyecto: rj76/kq
int save_s_map (s_map * sm, PACKFILE * f)
{
   int i;

   /* pack_putc (sm->map_no, f); */
   pack_putc (0, f); /* To maintain compatibility. */

   pack_putc (sm->zero_zone, f);
   pack_putc (sm->map_mode, f);
   pack_putc (sm->can_save, f);
   pack_putc (sm->tileset, f);
   pack_putc (sm->use_sstone, f);
   pack_putc (sm->can_warp, f);
   pack_putc (sm->extra_byte, f);
   pack_iputl (sm->xsize, f);
   pack_iputl (sm->ysize, f);
   pack_iputl (sm->pmult, f);
   pack_iputl (sm->pdiv, f);
   pack_iputl (sm->stx, f);
   pack_iputl (sm->sty, f);
   pack_iputl (sm->warpx, f);
   pack_iputl (sm->warpy, f);
   //pack_iputl (1, f);           /* Revision 1 */
   sm->revision = 2; // Force new revision: 2

   pack_iputl (sm->revision, f);           /* Revision 2 */
   pack_iputl (sm->extra_sdword2, f);
   pack_fwrite (sm->song_file, sizeof (sm->song_file), f);
   pack_fwrite (sm->map_desc, sizeof (sm->map_desc), f);

   /* Markers */
   pack_iputw (sm->num_markers, f);

   for (i = 0; i < sm->num_markers; ++i) {
      save_s_marker (&sm->markers[i], f);
   }

   /* Bounding boxes */
   pack_iputw (sm->num_bound_boxes, f);

   for (i = 0; i < sm->num_bound_boxes; ++i) {
      save_s_bound (&sm->bound_box[i], f);
   }

   return 0;
}
Ejemplo n.º 13
0
void Tile::saveTo(PACKFILE *file)
{
	// Write tile name to file
	if (tileType) {
		pack_fputs(tileType->getName(), file);
	}
	pack_fputs("\n", file);

	pack_iputw(obstacle, file);
}
Ejemplo n.º 14
0
/* exports a sample into an external file */
static int export_sample(AL_CONST DATAFILE *dat, AL_CONST char *filename)
{
   SAMPLE *spl = (SAMPLE *)dat->dat;
   int bps = spl->bits/8 * ((spl->stereo) ? 2 : 1);
   int len = spl->len * bps;
   int i;
   int16_t s;
   PACKFILE *f;

   errno = 0;
   
   f = pack_fopen(filename, F_WRITE);

   if (f) {
      pack_fputs("RIFF", f);                 /* RIFF header */
      pack_iputl(36+len, f);                 /* size of RIFF chunk */
      pack_fputs("WAVE", f);                 /* WAV definition */
      pack_fputs("fmt ", f);                 /* format chunk */
      pack_iputl(16, f);                     /* size of format chunk */
      pack_iputw(1, f);                      /* PCM data */
      pack_iputw((spl->stereo) ? 2 : 1, f);  /* mono/stereo data */
      pack_iputl(spl->freq, f);              /* sample frequency */
      pack_iputl(spl->freq*bps, f);          /* avg. bytes per sec */
      pack_iputw(bps, f);                    /* block alignment */
      pack_iputw(spl->bits, f);              /* bits per sample */
      pack_fputs("data", f);                 /* data chunk */
      pack_iputl(len, f);                    /* actual data length */

      if (spl->bits == 8) {
	 pack_fwrite(spl->data, len, f);     /* write the data */
      }
      else {
	 for (i=0; i < (int)spl->len * ((spl->stereo) ? 2 : 1); i++) {
	    s = ((int16_t *)spl->data)[i];
	    pack_iputw(s^0x8000, f);
	 }
      }

      pack_fclose(f);
   }

   return (errno == 0);
}
Ejemplo n.º 15
0
/*
 * Compresses all the frames in the animation and writes to a gif file.
 * Nothing else like extensions or comments is written.
 *
 * Returns 0 on success.
 *
 * Note: All bitmaps must have a color depth of 8.
 */
int
algif_save_raw_animation (const char *filename, GIF_ANIMATION *gif)
{
    int frame;
    int i, j;
    PACKFILE *file;

    file = pack_fopen (filename, "w");
    if (!file)
        return -1;

    pack_fwrite ("GIF89a", 6, file);
    pack_iputw (gif->width, file);
    pack_iputw (gif->height, file);
    /* 7 global palette
     * 456 color richness
     * 3 sorted
     * 012 palette bits
     */
    for (i = 1, j = 0; i < gif->palette.colors_count; i *= 2, j++);
    pack_putc ((j ? 128 : 0) + 64 + 32 + 16 + (j ? j - 1 : 0), file);
    pack_putc (gif->background_index, file);
    pack_putc (0, file);        /* No aspect ratio. */

    if (j)
        write_palette (file, &gif->palette, j);

    if (gif->loop != -1)
    /* Loop count extension. */
    {
        pack_putc (0x21, file); /* Extension Introducer. */
        pack_putc (0xff, file); /* Application Extension. */
        pack_putc (11, file);    /* Size. */
        pack_fwrite ("NETSCAPE2.0", 11, file);
        pack_putc (3, file); /* Size. */
        pack_putc (1, file);
        pack_iputw (gif->loop, file);
        pack_putc (0, file);
    }

    for (frame = 0; frame < gif->frames_count; frame++)
    {
        int w = gif->frames[frame].bitmap_8_bit->w;
        int h = gif->frames[frame].bitmap_8_bit->h;

        pack_putc (0x21, file); /* Extension Introducer. */
        pack_putc (0xf9, file); /* Graphic Control Extension. */
        pack_putc (4, file);    /* Size. */
        /* Disposal method, and enable transparency. */
        i = gif->frames[frame].disposal_method << 2;
        if (gif->frames[frame].transparent_index != -1)
            i |= 1;
        pack_putc (i, file);
        pack_iputw (gif->frames[frame].duration, file); /* In 1/100th seconds. */
        if (gif->frames[frame].transparent_index != -1)
            pack_putc (gif->frames[frame].transparent_index, file);       /* Transparent color index. */
        else
             pack_putc (0, file);
        pack_putc (0x00, file); /* Terminator. */

        pack_putc (0x2c, file); /* Image Descriptor. */
        pack_iputw (gif->frames[frame].xoff, file);
        pack_iputw (gif->frames[frame].yoff, file);
        pack_iputw (w, file);
        pack_iputw (h, file);

         /* 7: local palette
         * 6: interlaced
         * 5: sorted
         * 012: palette bits
         */

        for (i = 1, j = 0; i < gif->frames[frame].palette.colors_count; i *= 2, j++);
        pack_putc ((j ? 128 : 0) + (j ? j - 1 : 0), file);

        if (j)
            write_palette (file, &gif->frames[frame].palette, j);

        LZW_encode (file, gif->frames[frame].bitmap_8_bit);

        pack_putc (0x00, file); /* Terminator. */
    }

    pack_putc (0x3b, file);     /* Trailer. */

    pack_fclose (file);
    return 0;
}
Ejemplo n.º 16
0
/*! \brief Save game 92
 *
 * Save the game, using KQ Save Game Format 92 (Beta)
 * Author: Winter Knight
 *
 * \returns 0 if save failed, 1 if success
 */
static int save_game_92 (void)
{
   size_t a, b, c, d;
   PACKFILE *sdat;

   for (b = 0; b < PSIZE; b++) {
      sid[save_ptr][b] = 0;
      shp[save_ptr][b] = 0;
      smp[save_ptr][b] = 0;
      slv[save_ptr][b] = 0;
   }
   for (b = 0; b < numchrs; b++) {
      sid[save_ptr][b] = pidx[b];
      shp[save_ptr][b] = party[pidx[b]].hp * 100 / party[pidx[b]].mhp;
      if (party[pidx[b]].mmp > 0)
         smp[save_ptr][b] = party[pidx[b]].mp * 100 / party[pidx[b]].mmp;
      slv[save_ptr][b] = party[pidx[b]].lvl;
   }
   snc[save_ptr] = numchrs;
   sgp[save_ptr] = gp;
   smin[save_ptr] = kmin;
   shr[save_ptr] = khr;
   sprintf (strbuf, "sg%d.sav", save_ptr);
   sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_WRITE_PACKED);
   if (!sdat) {
      message (_("Could not save game data."), 255, 0, 0, 0);
      return 0;
   }


   pack_putc (kq_version, sdat);
   pack_iputl (gp, sdat);
   pack_iputw (shr[save_ptr], sdat);
   pack_iputw (smin[save_ptr], sdat);

   /* Save number of, and which characters are in the party */
   pack_iputw (numchrs, sdat);
   for (a = 0; a < numchrs; a++) {
      pack_iputw (pidx[a], sdat);
   }

   /* Save number of, and data on all characters in game */
   pack_iputw (MAXCHRS, sdat);
   for (a = 0; a < MAXCHRS; a++) {
      save_s_player (&party[a], sdat);
   }

   /* Save map name and location */
   pack_iputw (strlen (curmap), sdat);
   pack_fwrite (curmap, strlen (curmap), sdat);

   pack_iputw (g_ent[0].tilex, sdat);
   pack_iputw (g_ent[0].tiley, sdat);


   /* Save quest info */
   for (a = sizeof (progress); a > 0; a--) {
      if (progress[a - 1] > 0)
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++)
      pack_putc (progress[b], sdat);

   /* Save treasure info */
   for (a = sizeof (treasure); a > 0; a--) {
      if (treasure[a - 1] > 0)
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++)
      pack_putc (treasure[b], sdat);

   /* Save spell info (P_REPULSE is 48) */
   pack_iputw (sizeof (save_spells), sdat);
   for (a = 0; a < sizeof (save_spells); a++) { /* sizeof(save_spells) is 50 */
      pack_putc (save_spells[a], sdat);
   }

   /* Save player inventory */
   pack_iputw (MAX_INV, sdat);
   for (a = 0; a < MAX_INV; a++) {
      pack_iputw (g_inv[a][0], sdat);
      pack_iputw (g_inv[a][1], sdat);
   }

   /* Save special items */
   for (a = MAX_SPECIAL_ITEMS + 1; a > 0; a--) {
      if (player_special_items[a - 1])
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++) {
      pack_putc (player_special_items[b], sdat);
   }

   /* Save shop info (last visit time and number of items) */
   /* Find last index of shop that the player has visited. */
   for (a = num_shops; a > 0; a--) {
      if (shop_time[a - 1] > 0)
         break;
   }

   pack_iputw (a, sdat);
   for (b = 0; b < a; b++) {
      pack_iputw (shop_time[b], sdat);

      /* Find last valid (non-zero) shop item for this shop */
      for (c = SHOPITEMS; c > 0; c--)
         if (shops[b].items[c - 1] > 0)
            break;

      pack_iputw (c, sdat);
      for (d = 0; d < c; d++)
         pack_iputw (shops[b].items_current[d], sdat);
   }


   pack_fclose (sdat);
   return 1;
}
Ejemplo n.º 17
0
/*! \brief Save game
 *
 * You guessed it... save the game.
 *
 * \returns 0 if save failed, 1 if success
 */
static int save_game (void)
{
   PACKFILE *sdat;
   size_t a, b;

   return save_game_92 ();

   /* Rest of this function is no longer used */

   for (b = 0; b < PSIZE; b++) {
      sid[save_ptr][b] = 0;
      shp[save_ptr][b] = 0;
      smp[save_ptr][b] = 0;
      slv[save_ptr][b] = 0;
   }
   for (b = 0; b < numchrs; b++) {
      sid[save_ptr][b] = pidx[b];
      shp[save_ptr][b] = party[pidx[b]].hp * 100 / party[pidx[b]].mhp;
      if (party[pidx[b]].mmp > 0)
         smp[save_ptr][b] = party[pidx[b]].mp * 100 / party[pidx[b]].mmp;
      slv[save_ptr][b] = party[pidx[b]].lvl;
   }
   snc[save_ptr] = numchrs;
   sgp[save_ptr] = gp;
   smin[save_ptr] = kmin;
   shr[save_ptr] = khr;
   sprintf (strbuf, "sg%d.sav", save_ptr);
   sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_WRITE_PACKED);
   if (!sdat) {
      message (_("Could not save game data."), 255, 0, 0, 0);
      return 0;
   }
   pack_putc (kq_version, sdat);
   pack_iputl (numchrs, sdat);
   pack_iputl (gp, sdat);
   pack_iputl (shr[save_ptr], sdat);
   pack_iputl (smin[save_ptr], sdat);
   for (a = 0; a < PSIZE; a++) {
      pack_iputl (pidx[a], sdat);
   }
   for (a = 0; a < MAXCHRS; a++) {
      save_s_player (&party[a], sdat);
   }
   pack_fwrite (curmap, 16, sdat);
   for (a = 0; a < sizeof (progress); a++) {  /* sizeof(progress) is 1750 */
      pack_putc (progress[a], sdat);
   }
   for (a = 0; a < NUMSHOPS; a++) {           /* NUMSHOPS is 50 */
      pack_putc (shop_time[a], sdat);
   }
   for (a = 0; a < SIZE_SAVE_RESERVE1; a++) { /* SAVE_RESERVE_SIZE1 is 150 */
      pack_putc (0, sdat);
   }
   for (a = 0; a < sizeof (save_spells); a++) { /* sizeof(save_spells) is 50 */
      pack_putc (save_spells[a], sdat);
   }
   for (a = 0; a < sizeof (treasure); a++) {    /* sizeof(treasure) is 1000 */
      pack_putc (treasure[a], sdat);
   }
   for (a = 0; a < NUMSHOPS; a++) {
      for (b = 0; b < SHOPITEMS; b++) {
         pack_iputw (shops[a].items_current[b], sdat);
      }
   }
   for (a = 0; a < MAX_INV; a++) {
      pack_iputw (g_inv[a][0], sdat);
      pack_iputw (g_inv[a][1], sdat);
   }
   /* PH FIXME: do we _really_ want things like controls and screen */
   /* mode to be saved/loaded ? */
   /* WK: No. */
   pack_iputl (gsvol, sdat);
   pack_iputl (gmvol, sdat);
   pack_putc (windowed, sdat);
   pack_putc (stretch_view, sdat);
   pack_putc (wait_retrace, sdat);
   pack_iputl (kup, sdat);
   pack_iputl (kdown, sdat);
   pack_iputl (kleft, sdat);
   pack_iputl (kright, sdat);
   pack_iputl (kalt, sdat);
   pack_iputl (kctrl, sdat);
   pack_iputl (kenter, sdat);
   pack_iputl (kesc, sdat);
   pack_iputl (jbalt, sdat);
   pack_iputl (jbctrl, sdat);
   pack_iputl (jbenter, sdat);
   pack_iputl (jbesc, sdat);
   /* End worthless */
   pack_iputw (g_ent[0].tilex, sdat);
   pack_iputw (g_ent[0].tiley, sdat);
   pack_fclose (sdat);
   return 1;
}
Ejemplo n.º 18
0
/* saves a wave file to file pointer */
static int save_wav_fp(SAMPLE * sp, PACKFILE * fp)
{
	size_t channels, bits, freq;
	size_t data_size;
	size_t samples;
	size_t i, n;
	void * pval = NULL;
	unsigned short *data;

	eof_log("save_wav_fp() entered", 1);

	if(!sp || !fp)
	{
		return 0;
	}
	channels = sp->stereo ? (size_t)2 : (size_t)1;
	bits = (size_t)sp->bits;

	samples = (size_t)sp->len;
	data_size = samples * channels * (bits / 8);
	n = samples * channels;

	freq = (size_t)sp->freq;

	(void) pack_fputs("RIFF", fp);
	(void) pack_iputl(36 + (long)data_size, fp);
	(void) pack_fputs("WAVE", fp);

	(void) pack_fputs("fmt ", fp);
	(void) pack_iputl(16, fp);
	(void) pack_iputw(1, fp);
	(void) pack_iputw((int)channels, fp);
	(void) pack_iputl((long)freq, fp);
	(void) pack_iputl((long)(freq * channels * (bits / 8)), fp);	//ByteRate = SampleRate * NumChannels * BitsPerSample/8
	(void) pack_iputw((int)(channels * (bits / 8)), fp);
	(void) pack_iputw((int)bits, fp);

	(void) pack_fputs("data", fp);
	(void) pack_iputl((long)data_size, fp);

	if(bits == 8)
	{
		pval = sp->data;
		(void) pack_fwrite(pval, (long)(samples * channels), fp);
	}
	else if(bits == 16)
	{
		data = (unsigned short *)sp->data;
		for (i = 0; i < n; i++)
		{
			(void) pack_iputw((short)(data[i] - 0x8000), fp);
		}
	}
	else
	{
		(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "Unknown audio depth (%lu) when saving wav ALLEGRO_FILE.", (unsigned long) bits);
		eof_log(eof_log_string, 1);
		return 0;
	}

	return 1;
}