#include unsigned char sram[0x8000]; void generate_new_sav(); int read_file(char * filename); void write_file(char * filename); main(int argc, char *argv[]) { if(argc!=3) { printf("use this program to patch LSDj v2 (32 kB) .sav files into LSDJ v3 (128 kB) .sav files\n\n"); printf("usage: lsdmerge source destination\n"); return 0; } read_file(argv[1]); write_file(argv[2]); return 1; } void write_file(char * filename) { FILE *out; out=fopen(filename, "rb+"); if(out==NULL) { unsigned int i; unsigned char zero=0; printf("couldn't open destination file '%s'\n",filename); printf("creating new file...\n"); out=fopen(filename, "wb"); for(i=0; i<131072; i++) { fwrite(&zero,1,1,out); } fclose(out); out=fopen(filename, "rb+"); } if(ferror(out)) { printf("file error %d",ferror(out)); exit(1); } fseek(out,0,SEEK_END); if(ftell(out)!=131072) { printf("error: destination file '%s' has wrong file length (should be 128 kB)", filename); exit(1); } fseek(out,0,SEEK_SET); fwrite(sram, 32768, 1, out); if(ferror(out)) { printf("file error %d when writing to '%s'",ferror(out),filename); exit(1); } fclose(out); printf("wrote file '%s' successfully",filename); } int read_file(char *filename) { FILE *in; int read; in=fopen(filename,"rb"); if(in==NULL) { printf("error: can't open file '%s'", filename); exit(1); } fseek(in,0,SEEK_END); if(ftell(in)!=32768) { printf("error: source file '%s' has wrong file length (should be 32 kB)", filename); exit(1); } fseek(in,0,SEEK_SET); read=fread(sram,1,32768,in); if(ferror(in)) { printf("file error %d when reading from '%s'",ferror(in),filename); exit(1); } fclose(in); return 1; }