Re: A86: 86string


[Prev][Next][Index][Thread]

Re: A86: 86string




I wrote this C routine a while back, see if it helps.  It should compile
under any 16 or 32 bit compiler, including DJGPP.  I used Watcom,
personally.  Pass it a filename up to 8 chars, without the extension.  Make
sure the characters are valid for an 86 string name.  I got the idea for
fputc_sum from String85 by Dan Eble.  If it doesn't work, I probably cut
something wrong, so email me, not the list:

void save_map_str(char *name)
{
  FILE  *fp;
  unsigned short checksum;
  char *p;
  FileHeader header;
  char fname[12];

  strcpy(fname, name);
  strcat(fname, ".86s");
  
  memcpy(header.sig, "**TI86**", 8);
  header.ext_sig[0] = 0x1a;
  header.ext_sig[1] = 0x0a;
  header.ext_sig[2] = 0x00;
  memset(header.comment, 0, 42);
  memcpy(header.comment, "m86map ", 7); //MEdit level for Metroid 86
  header.file_len = 10 + strlen(name) + (MAXMAP * 8);

  printf("Saving map as %s...", fname);
  fp = fopen(fname, "wb");
  if (fp == NULL)
    printf("\nError opening %s.  Map not saved!\n", fname);
  else
  {
    fwrite(&header, sizeof(header), 1, fp);

    checksum = 0;
    fputc_sum(4 + strlen(name), fp, &checksum);
    fputc_sum(0, fp, &checksum);
    fputc_sum((DATASIZE + 2) % 256, fp, &checksum);
    fputc_sum((DATASIZE + 2) >> 8, fp, &checksum);
    fputc_sum(0x0c, fp, &checksum);
    fputc_sum(strlen(name), fp, &checksum);
    for(x = 0; x < strlen(name); x++)
      fputc_sum(name[x], fp, &checksum);
    fputc_sum((DATASIZE + 2) % 256, fp, &checksum);
    fputc_sum((DATASIZE + 2) >> 8, fp, &checksum);
    fputc_sum(DATASIZE % 256, fp, &checksum);
    fputc_sum(DATASIZE >> 8, fp, &checksum);


// call fputc_sum for every character here--this is the data portion

    fwrite(&checksum, 2, 1, fp);

    fclose(fp);
    if (errno != 0)
    {
      printf("\nError writting %s.  Map not saved!\n", fname);
      return;
    }
    printf("done!\n");
  }
}

fputc_sum(char c, FILE *fp, unsigned short *sum)
{
  *sum += c;
  fputc(c, fp);
}


At 05:23 PM 8/18/98 -0700, you wrote:
>
>Does anyone know how to compile a data file into an *.86s file
>on a DOS 5 system?
>
>
>-- 
>Tercero	 --  Email: mailto:tercero@busprod.com


--
David Phillips
mailto:electrum@tfs.net
ICQ: 13811951
AOL/AIM: Electrum32


References: