[Scummvm-cvs-logs] SF.net SVN: scummvm:[42253] tools/branches/gsoc2009-gui
Remere at users.sourceforge.net
Remere at users.sourceforge.net
Wed Jul 8 05:19:51 CEST 2009
Revision: 42253
http://scummvm.svn.sourceforge.net/scummvm/?rev=42253&view=rev
Author: Remere
Date: 2009-07-08 03:19:51 +0000 (Wed, 08 Jul 2009)
Log Message:
-----------
*Converted another 6 tools.
*Added a "xormode" property for files, that allows automatic xoring when reading / writing to files.
*Some other small fixes / additions.
Modified Paths:
--------------
tools/branches/gsoc2009-gui/compress_tucker.cpp
tools/branches/gsoc2009-gui/extract_loom_tg16.cpp
tools/branches/gsoc2009-gui/extract_mm_apple.cpp
tools/branches/gsoc2009-gui/extract_mm_c64.cpp
tools/branches/gsoc2009-gui/extract_mm_nes.cpp
tools/branches/gsoc2009-gui/extract_parallaction.cpp
tools/branches/gsoc2009-gui/extract_parallaction.h
tools/branches/gsoc2009-gui/extract_zak_c64.cpp
tools/branches/gsoc2009-gui/gui/tools.cpp
tools/branches/gsoc2009-gui/tool.cpp
tools/branches/gsoc2009-gui/tool.h
tools/branches/gsoc2009-gui/util.cpp
tools/branches/gsoc2009-gui/util.h
Added Paths:
-----------
tools/branches/gsoc2009-gui/extract_loom_tg16.h
tools/branches/gsoc2009-gui/extract_mm_apple.h
tools/branches/gsoc2009-gui/extract_mm_c64.h
tools/branches/gsoc2009-gui/extract_mm_nes.h
tools/branches/gsoc2009-gui/extract_zak_c64.h
Modified: tools/branches/gsoc2009-gui/compress_tucker.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_tucker.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/compress_tucker.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -330,7 +330,6 @@
temp_table[i].size = compress_file_raw(filepath, 1, output);
break;
}
- fclose(input);
}
current_offset += temp_table[i].size;
}
@@ -393,8 +392,6 @@
current_offset += audio_directory_size;
}
- fclose(output);
-
/* cleanup */
unlink(TEMP_WAV);
unlink(TEMP_RAW);
Modified: tools/branches/gsoc2009-gui/extract_loom_tg16.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_loom_tg16.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/extract_loom_tg16.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -23,29 +23,31 @@
#include "util.h"
#include <stdarg.h>
+#include "extract_loom_tg16.h"
+
/* if defined, generates a set of .LFL files */
/* if not defined, dumps all resources to separate files */
#define MAKE_LFLS
-uint8 read_cbyte (FILE *input, short *ctr) {
+uint8 read_cbyte (File &input, short *ctr) {
(*ctr) += 1;
- return readByte(input);
+ return input.readByte();
}
-uint16 read_cword (FILE *input, short *ctr) {
+uint16 read_cword (File &input, short *ctr) {
(*ctr) += 2;
- return readUint16LE(input);
+ return input.readU16LE();
}
-void write_cbyte (FILE *output, uint8 val, short *ctr) {
- writeByte(output, val);
+void write_cbyte (File &output, uint8 val, short *ctr) {
+ output.writeByte(val);
(*ctr) += 1;
}
-void write_cword (FILE *output, uint16 val, short *ctr) {
- writeUint16LE(output, val);
+void write_cword (File &output, uint16 val, short *ctr) {
+ output.writeU16LE(val);
(*ctr) += 2;
}
-void write_clong (FILE *output, uint32 val, short *ctr) {
- writeUint32LE(output, val);
+void write_clong (File &output, uint32 val, short *ctr) {
+ output.writeU32LE(val);
(*ctr) += 4;
}
@@ -67,12 +69,14 @@
t_iso ISO = NUM_ISOS;
-typedef struct _resource {
+struct t_resource {
uint32 offset[NUM_ISOS];
uint16 length[NUM_ISOS];
res_type type;
-} t_resource, *p_resource;
+};
+typedef t_resource * p_resource;
+
#define NUM_ROOMS 100
t_resource res_rooms[NUM_ROOMS] = {
{ {0x000000, 0x000000}, {0x0000, 0x0000}, RES_ROOM }, /* 0 */
@@ -778,7 +782,7 @@
return res->length[ISO];
}
-void extract_resource (FILE *input, FILE *output, p_resource res) {
+void ExtractLoomTG16::extract_resource(File &input, File &output, p_resource res) {
#ifdef MAKE_LFLS
uint16 j, off;
#endif
@@ -790,26 +794,26 @@
if ((r_offset(res) == 0) && (r_length(res) == 0))
return; /* if offset/length are both 0, skip it */
- fseek(input, r_offset(res), SEEK_SET);
+ input.seek(r_offset(res), SEEK_SET);
switch (res->type) {
case RES_CHARSET:
rlen = r_length(res);
- writeUint16LE(output, (uint16)(rlen + 4));
- writeUint16LE(output, 0);
+ output.writeU16LE((uint16)(rlen + 4));
+ output.writeU16LE(0);
/* Skip 4 bytes */
read_cword(input, &i);
read_cword(input, &i);
/* Write expected charset header */
- writeByte(output, 0x63);
- writeByte(output, 0x01);
- writeByte(output, 0x80);
- writeByte(output, 0x08);
+ output.writeByte(0x63);
+ output.writeByte(0x01);
+ output.writeByte(0x80);
+ output.writeByte(0x08);
for (i = 0; i < rlen - 4; i++)
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
break;
case RES_GLOBDATA:
rlen = read_cword(input,&i);
@@ -820,10 +824,10 @@
error("extract_resource(globdata) - length mismatch while extracting resource (was %04X, expected %04X)",rlen,r_length(res));
if (rtype != 0x11)
error("extract_resource(globdata) - resource tag is incorrect");
- writeUint32LE(output,(uint16)(rlen + 1));
- writeUint16LE(output,'O0'); /* 0O - Object Index */
+ output.writeU32LE((uint16)(rlen + 1));
+ output.writeU16LE('O0'); /* 0O - Object Index */
for (i = 5; i < rlen; i++)
- writeByte(output,readByte(input));
+ output.writeByte(input.readByte());
break;
#ifdef MAKE_LFLS
case RES_ROOM:
@@ -941,13 +945,13 @@
write_cbyte(output, read_cbyte(input, &i), &rlen);
break;
default:
- fseek(input, slen, SEEK_CUR);
+ input.seek(slen, SEEK_CUR);
error("extract_resource(room) - unknown resource tag encountered: len %04X type %02X", slen, stype);
}
}
- fseek(output, off, SEEK_SET);
- writeUint32LE(output, rlen);
- fseek(output, 0, SEEK_END);
+ output.seek(off, SEEK_SET);
+ output.writeU32LE(rlen);
+ output.seek(0, SEEK_END);
}
break;
@@ -963,10 +967,10 @@
error("extract_resource(costume) - length mismatch while extracting resource (was %04X, expected %04X)",rlen,r_length(res));
if (rtype != 0x03)
error("extract_resource(costume) - resource tag is incorrect");
- writeUint32LE(output,(uint16)(rlen + 1));
- writeUint16LE(output,'OC'); /* CO - Costume */
+ output.writeU32LE((uint16)(rlen + 1));
+ output.writeU16LE('OC'); /* CO - Costume */
for (i = 5; i < rlen; i++)
- writeByte(output,readByte(input));
+ output.writeByte(readByte(input));
break;
case RES_SCRIPT:
rlen = read_cword(input,&i);
@@ -977,10 +981,10 @@
error("extract_resource(script) - length mismatch while extracting resource (was %04X, expected %04X)", rlen, r_length(res));
if (rtype != 0x02)
error("extract_resource(script) - resource tag is incorrect");
- writeUint32LE(output,(uint16)(rlen + 1));
- writeUint16LE(output,'CS'); /* SC - Script */
+ output.writeU32LE((uint16)(rlen + 1));
+ output.writeU16LE('CS'); /* SC - Script */
for (i = 5; i < rlen; i++)
- writeByte(output,readByte(input));
+ output.writeByte(readByte(input));
break;
case RES_UNKNOWN:
#else
@@ -992,11 +996,10 @@
rlen = read_cword(input,&i);
if (rlen != r_length(res))
error("extract_resource - length mismatch while extracting resource (was %04X, expected %04X)", rlen, r_length(res));
- writeUint16LE(output,rlen);
+ output.writeUint16LE(rlen);
for (i = 2; i < rlen; i++)
- writeByte(output,readByte(input));
+ output.writeByte(readByte(input));
break;
- break;
#endif
default:
warning("extract_resource - unknown resource type %d specified", res->type);
@@ -1188,15 +1191,11 @@
uint32 sound_addr[NUM_SOUNDS];
} lfl_index;
#else /* !MAKE_LFLS */
-void dump_resource (FILE *input, const char *fn_template, int num, p_resource res) {
+void dump_resource (File &input, const char *fn_template, int num, p_resource res) {
char fname[256];
- FILE *output;
sprintf(fname, fn_template, num);
- output = fopen(fname, "wb");
- if (!output)
- error("Unable to create %s", fname);
+ File output(fname, "wb");
extract_resource(input, output, res);
- fclose(output);
}
#endif /* MAKE_LFLS */
@@ -1213,62 +1212,54 @@
}
}
-uint32 ISO_CRC (FILE *file) {
+uint32 ISO_CRC (File &file) {
uint32 CRC = 0xFFFFFFFF;
uint32 i, len;
- fseek(file, 0, SEEK_END);
+ file.seek(0, SEEK_END);
len = ftell(file);
- fseek(file, 0, SEEK_SET);
+ file.seek(0, SEEK_SET);
for (i = 0; i < len; i++)
CRC = (CRC >> 8) ^ CRCtable[(CRC ^ readByte(file)) & 0xFF];
return CRC ^ 0xFFFFFFFF;
}
-int export_main(extract_loom_tg16)(int argc, char *argv[]) {
+ExtractLoomTG16::ExtractLoomTG16(const std::string &name) : Tool(name) {
+ _helptext = "\nUsage: " + _name + " [-o outputdir = out/] <infile>";
+}
+
+void ExtractLoomTG16::execute() {
#ifdef MAKE_LFLS
- FILE *input, *output;
int i, j;
#else
- FILE *input;
int i;
#endif
uint32 CRC;
- int first_arg = 1;
- int last_arg = argc - 1;
- char fname[256];
- Filename inpath, outpath;
+ // We only got one input file
+ if (_inputPaths.size() > 1)
+ error("Only one input file expected!");
+ Filename inpath(_inputPaths[0]);
+ Filename &outpath = _outputPath;
- // Check if we should display some helpful text
- parseHelpArguments(argv, argc);
-
- // Continuing with finding out output directory
- // also make sure we skip those arguments
- if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
- first_arg += 2;
- else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
- last_arg -= 2;
- else
- // Standard output dir
+ if(outpath.empty())
+ // Standard output path
outpath.setFullPath("out/");
-
- input = fopen(argv[first_arg], "rb");
- if (!input)
- error("unable to open file %s for input", argv[first_arg]);
+ File input(inpath, "rb");
+
InitCRC();
CRC = ISO_CRC(input);
switch (CRC) {
case 0x29EED3C5: // dumpcd
case 0xE70FA498: // turborip
ISO = ISO_USA;
- notice("ISO contents verified as Loom USA (track 2)");
+ print("ISO contents verified as Loom USA (track 2)");
break;
case 0xD7B5F808: // dumpcd
case 0xCA757D06: // turborip
ISO = ISO_JPN;
- notice("ISO contents verified as Loom Japan (track 2)");
+ print("ISO contents verified as Loom Japan (track 2)");
break;
default:
error("ISO contents not recognized");
@@ -1279,15 +1270,13 @@
for (i = 0; lfls[i].num != -1; i++) {
p_lfl lfl = &lfls[i];
+ char fname[256];
sprintf(fname, "%02i.LFL", lfl->num);
-
outpath.setFullName(fname);
- output = fopen(outpath.getFullPath().c_str(), "wb");
- if (!output)
- error("unable to create %s", fname);
+ File output(outpath, "wb");
- notice("Creating %s...", fname);
+ print("Creating %s...", fname);
for (j = 0; lfl->entries[j] != NULL; j++) {
p_resource entry = lfl->entries[j];
switch (entry->type) {
@@ -1308,93 +1297,77 @@
lfl_index.sound_addr[entry - res_sounds] = (uint16)ftell(output);
break;
default:
- notice("Unknown resource type %d detected in LFL index!", entry->type);
+ print("Unknown resource type %d detected in LFL index!", entry->type);
break;
}
extract_resource(input, output, entry);
}
-
- fclose(output);
}
outpath.setFullName("00.LFL");
- output = fopen(outpath.getFullPath().c_str(), "wb");
- if (!output)
- error("Unable to create index file!");
- notice("Creating 00.LFL...");
+ File output(outpath, "wb");
+ print("Creating 00.LFL...");
lfl_index.num_rooms = NUM_ROOMS;
lfl_index.num_costumes = NUM_COSTUMES;
lfl_index.num_scripts = NUM_SCRIPTS;
lfl_index.num_sounds = NUM_SOUNDS;
- writeUint32LE(output, 8 + 5 * lfl_index.num_rooms);
- writeUint16LE(output, 'R0'); /* 0R - room index */
- writeUint16LE(output, lfl_index.num_rooms);
+ output.writeU32LE(8 + 5 * lfl_index.num_rooms);
+ output.writeU16LE('R0'); /* 0R - room index */
+ output.writeU16LE(lfl_index.num_rooms);
for (i = 0; i < lfl_index.num_rooms; i++) {
- writeByte(output, lfl_index.room_lfl[i]);
- writeUint32LE(output, lfl_index.room_addr[i]);
+ output.writeByte(lfl_index.room_lfl[i]);
+ output.writeU32LE(lfl_index.room_addr[i]);
}
- writeUint32LE(output, 8 + 5 * lfl_index.num_scripts);
- writeUint16LE(output, 'S0'); /* 0S - script index */
- writeUint16LE(output, lfl_index.num_scripts);
+ output.writeU32LE(8 + 5 * lfl_index.num_scripts);
+ output.writeU16LE('S0'); /* 0S - script index */
+ output.writeU16LE(lfl_index.num_scripts);
for (i = 0; i < lfl_index.num_scripts; i++) {
- writeByte(output, lfl_index.script_lfl[i]);
- writeUint32LE(output, lfl_index.script_addr[i]);
+ output.writeByte(lfl_index.script_lfl[i]);
+ output.writeU32LE(lfl_index.script_addr[i]);
}
- writeUint32LE(output, 8 + 5 * lfl_index.num_costumes);
- writeUint16LE(output, 'C0'); /* 0C - costume index */
- writeUint16LE(output, lfl_index.num_costumes);
+ output.writeU32LE(8 + 5 * lfl_index.num_costumes);
+ output.writeU16LE('C0'); /* 0C - costume index */
+ output.writeU16LE(lfl_index.num_costumes);
for (i = 0; i < lfl_index.num_costumes; i++) {
- writeByte(output, lfl_index.costume_lfl[i]);
- writeUint32LE(output, lfl_index.costume_addr[i]);
+ output.writeByte(lfl_index.costume_lfl[i]);
+ output.writeU32LE(lfl_index.costume_addr[i]);
}
/*
- writeUint32LE(output, 8 + 5 * lfl_index.num_sounds);
- writeUint16LE(output, 'N0'); 0N - sounds index
- writeUint16LE(output, lfl_index.num_sounds);
+ output.writeU32LE(8 + 5 * lfl_index.num_sounds);
+ output.writeU16LE('N0'); 0N - sounds index
+ output.writeU16LE(lfl_index.num_sounds);
for (i = 0; i < lfl_index.num_sounds; i++) {
- writeByte(output, lfl_index.sound_lfl[i]);
- writeUint32LE(output, lfl_index.sound_addr[i]);
+ output.writeByte(lfl_index.sound_lfl[i]);
+ output.writeU32LE(lfl_index.sound_addr[i]);
}
*/
extract_resource(input, output, &res_globdata);
- fclose(output);
-
outpath.setFullName("97.LFL");
- output = fopen(outpath.getFullPath().c_str(), "wb");
- if (!output)
- error("Unable to create charset file 97.LFL");
-
- notice("Creating 97.LFL...");
+ output.open(outpath, "wb");
+ print("Creating 97.LFL...");
extract_resource(input, output, &res_charset);
- fclose(output);
outpath.setFullName("98.LFL");
- output = fopen(outpath.getFullPath().c_str(), "wb");
- if (!output)
- error("Unable to create charset file 98.LFL");
- notice("Creating 98.LFL...");
+ output.open(outpath, "wb");
+ print("Creating 98.LFL...");
extract_resource(input, output, &res_charset);
- fclose(output);
outpath.setFullName("99.LFL");
- output = fopen(outpath.getFullPath().c_str(), "wb");
- if (!output)
- error("Unable to create charset file 99.LFL");
- notice("Creating 99.LFL...");
+ output.open(outpath, "wb");
+ print("Creating 99.LFL...");
extract_resource(input, output, &res_charset);
- fclose(output);
#else /* !MAKE_LFLS */
dump_resource(input, "globdata.dmp", 0, &res_globdata);
@@ -1411,13 +1384,13 @@
for (i = 0; i < NUM_SOUNDS; i++)
dump_resource(input, "sound-%d.dmp", i, &res_sounds[i]);
#endif /* MAKE_LFLS */
- notice("All done!");
- return 0;
+ print("All done!");
}
#ifdef STANDALONE_MAIN
int main(int argc, char *argv[]) {
- return export_main(extract_loom_tg16)(argc, argv);
+ ExtractLoomTG16 loom(argv[0]);
+ return loom.run(argc, argv);
}
#endif
Added: tools/branches/gsoc2009-gui/extract_loom_tg16.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_loom_tg16.h (rev 0)
+++ tools/branches/gsoc2009-gui/extract_loom_tg16.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -0,0 +1,43 @@
+/* extract_loom_tg16 - Extract data files from TG16 version of Loom
+ * Copyright (C) 2009 The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef EXTRACT_LOOM_TG16_H
+#define EXTRACT_LOOM_TG16_H
+
+#include "compress.h"
+
+struct t_resource;
+typedef t_resource * p_resource;
+
+class ExtractLoomTG16 : public Tool {
+public:
+ ExtractLoomTG16(const std::string &name = "extract_loom_tg16");
+
+ virtual void execute();
+
+protected:
+
+ void extract_resource(File &input, File &output, p_resource res);
+};
+
+#endif
+
Property changes on: tools/branches/gsoc2009-gui/extract_loom_tg16.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: tools/branches/gsoc2009-gui/extract_mm_apple.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_apple.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/extract_mm_apple.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -22,18 +22,8 @@
#include "util.h"
#include <stdarg.h>
+#include "extract_mm_apple.h"
-void writeByteAltApple(FILE *fp, uint8 b) {
- writeByte(fp, (uint8)(b ^ 0xFF));
-}
-
-void writeUint16LEAltApple(FILE *fp, uint16 value) {
- writeUint16LE(fp, (uint16)(value ^ 0xFFFF));
-}
-
-#define writeByte writeByteAltApple
-#define writeUint16LE writeUint16LEAltApple
-
#define NUM_ROOMS 55
unsigned char room_disks_apple[NUM_ROOMS], room_tracks_apple[NUM_ROOMS], room_sectors_apple[NUM_ROOMS];
@@ -52,134 +42,119 @@
3, 10, 1, 0, 0
};
-int export_main(extract_mm_apple)(int argc, char *argv[]) {
- const char *helptext = "\nUsage: %s [-o <output dir> = out/] <disk1.dsk> <disk2.dsk>\n";
+ExtractMMApple::ExtractMMApple(const std::string &name) : Tool(name) {
+ _helptext = "\nUsage: " + _name + " [-o <output dir> = out/] <disk1.dsk> <disk2.dsk>\n";
+}
- FILE *input1, *input2, *output;
+void ExtractMMApple::execute() {
int i, j;
unsigned short signature;
-
- int first_arg = 1;
- int last_arg = argc - 1;
-
char fname[256];
- Filename inpath, outpath;
- // Check if we should display some helpful text
- parseHelpArguments(argv, argc, helptext);
-
- // Continuing with finding out output directory
- // also make sure we skip those arguments
- if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
- first_arg += 2;
- else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
- last_arg -= 2;
- else
- // Standard output dir
+ // Two disks...
+ if (_inputPaths.size() != 2)
+ error("Two input files expected!");
+ Filename inpath1(_inputPaths[0]);
+ Filename inpath2(_inputPaths[1]);
+ Filename &outpath = _outputPath;
+
+ if(outpath.empty())
+ // Standard output path
outpath.setFullPath("out/");
- if (last_arg - first_arg == 1)
- error("Requires two disk files");
+ File input1(inpath1, "rb");
+ File input2(inpath2, "rb");
- if (!(input1 = fopen(argv[first_arg],"rb")))
- error("Unable to open file %s for input!",argv[first_arg]);
- ++first_arg;
- if (!(input2 = fopen(argv[first_arg],"rb")))
- error("Unable to open file %s for input!",argv[first_arg]);
+ input1.seek(142080, SEEK_SET);
+ input2.seek(143104, SEEK_SET);
- fseek(input1, 142080, SEEK_SET);
- fseek(input2, 143104, SEEK_SET);
-
/* check signature */
- signature = readUint16LE(input1);
+ signature = input1.readU16LE();
if (signature != 0x0A31)
error("Signature not found in disk 1!");
- signature = readUint16LE(input2);
+ signature = input2.readU16LE();
if (signature != 0x0032)
error("Signature not found in disk 2!");
outpath.setFullName("00.LFL");
- if (!(output = fopen(fname, "wb")))
- error("Unable to create index file!");
- notice("Creating 00.LFL...");
+ File output(fname, "wb");
+ // All output should be xored
+ output.setXorMode(0xFF);
+ print("Creating 00.LFL...");
/* write signature */
- writeUint16LE(output, signature);
+ output.writeU16LE(signature);
/* copy object flags */
for (i = 0; i < 256; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
/* copy room offsets */
for (i = 0; i < NUM_ROOMS; i++) {
- room_disks_apple[i] = readByte(input1);
- writeByte(output, room_disks_apple[i]);
+ room_disks_apple[i] = input1.readByte();
+ output.writeByte(room_disks_apple[i]);
}
for (i = 0; i < NUM_ROOMS; i++) {
- room_sectors_apple[i] = readByte(input1);
- writeByte(output, room_sectors_apple[i]);
- room_tracks_apple[i] = readByte(input1);
- writeByte(output, room_tracks_apple[i]);
+ room_sectors_apple[i] = input1.readByte();
+ output.writeByte(room_sectors_apple[i]);
+ room_tracks_apple[i] = input1.readByte();
+ output.writeByte(room_tracks_apple[i]);
}
/* copy costume offsets */
for (i = 0; i < 25; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 25; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
/* copy script offsets */
for (i = 0; i < 160; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 160; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
/* copy sound offsets */
for (i = 0; i < 70; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 70; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
/* NOTE: Extra 92 bytes of unknown data */
- fclose(output);
-
for (i = 0; i < NUM_ROOMS; i++) {
- FILE *input;
+ File *input;
if (room_disks_apple[i] == '1')
- input = input1;
+ input = &input1;
else if (room_disks_apple[i] == '2')
- input = input2;
+ input = &input2;
else
continue;
sprintf(fname, "%02i.LFL", i);
outpath.setFullName(fname);
- output = fopen(fname, "wb");
- if (output == NULL)
- error("Unable to create %s!", fname);
+ output.open(fname, "wb");
- notice("Creating %s...", fname);
- fseek(input, (SectorOffset[room_tracks_apple[i]] + room_sectors_apple[i]) * 256, SEEK_SET);
+ print("Creating %s...", fname);
+ input->seek((SectorOffset[room_tracks_apple[i]] + room_sectors_apple[i]) * 256, SEEK_SET);
for (j = 0; j < ResourcesPerFile[i]; j++) {
- unsigned short len = readUint16LE(input);
- writeUint16LE(output, len);
+ unsigned short len = input->readU16LE();
+ output.writeU16LE(len);
for (len -= 2; len > 0; len--)
- writeByte(output, readByte(input));
+ output.writeByte(input->readByte());
}
- rewind(input);
+ rewind(*input);
}
- notice("All done!");
- return 0;
+ print("All done!");
}
#ifdef STANDALONE_MAIN
int main(int argc, char *argv[]) {
- return export_main(extract_mm_apple)(argc, argv);
+ ExtractMMApple mmapple(argv[0]);
+ return mmapple.run(argc, argv);
}
#endif
Added: tools/branches/gsoc2009-gui/extract_mm_apple.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_apple.h (rev 0)
+++ tools/branches/gsoc2009-gui/extract_mm_apple.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -0,0 +1,43 @@
+/* extract_mm_apple - Extract data files from Apple II version of Maniac Mansion
+ * Copyright (C) 2009 The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL
+ * $Id
+ *
+ */
+
+#ifndef EXTRACT_MM_APPLE_H
+#define EXTRACT_MM_APPLE_H
+
+#include "compress.h"
+
+struct t_resource;
+typedef t_resource * p_resource;
+
+class ExtractMMApple : public Tool {
+public:
+ ExtractMMApple(const std::string &name = "extract_mm_apple");
+
+ virtual void execute();
+
+protected:
+
+ void dump_resource(File &input, const char *fn_template, int num, p_resource res);
+};
+
+#endif
+
Property changes on: tools/branches/gsoc2009-gui/extract_mm_apple.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: tools/branches/gsoc2009-gui/extract_mm_c64.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_c64.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/extract_mm_c64.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -22,18 +22,8 @@
#include "util.h"
#include <stdarg.h>
+#include "extract_mm_c64.h"
-void writeByteAlt(FILE *fp, uint8 b) {
- writeByte(fp, (uint8)(b ^ 0xFF));
-}
-
-void writeUint16LEAlt(FILE *fp, uint16 value) {
- writeUint16LE(fp, (uint16)(value ^ 0xFFFF));
-}
-
-#define writeByte writeByteAlt
-#define writeUint16LE writeUint16LEAlt
-
#define NUM_ROOMS 55
unsigned char room_disks[NUM_ROOMS], room_tracks[NUM_ROOMS], room_sectors[NUM_ROOMS];
@@ -53,131 +43,115 @@
3, 10, 1, 0, 0
};
-int export_main(extract_mm_c64)(int argc, char *argv[]) {
- const char *helptext = "\nUsage: %s [-o <output dir> = out/] <disk1.d64> <disk2.d64>\n";
-
- FILE *input1, *input2, *output;
+ExtractMMC64::ExtractMMC64(const std::string &name) : Tool(name) {
+ _helptext = "\nUsage: " + _name + " [-o <output dir> = out/] <disk1.d64> <disk2.d64>\n";
+}
+
+void ExtractMMC64::execute() {
int i, j;
unsigned short signature;
-
- int first_arg = 1;
- int last_arg = argc - 1;
-
char fname[256];
- Filename inpath, outpath;
-
- // Check if we should display some helpful text
- parseHelpArguments(argv, argc, helptext);
- // Continuing with finding out output directory
- // also make sure we skip those arguments
- if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
- first_arg += 2;
- else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
- last_arg -= 2;
- else
- // Standard output dir
+ // Two disks...
+ if (_inputPaths.size() != 2)
+ error("Two input files expected!");
+ Filename inpath1(_inputPaths[0]);
+ Filename inpath2(_inputPaths[1]);
+ Filename &outpath = _outputPath;
+
+ if(outpath.empty())
+ // Standard output path
outpath.setFullPath("out/");
+
+ File input1(inpath1, "rb");
+ File input2(inpath2, "rb");
- if (last_arg - first_arg == 1)
- error("Requires two disk files");
-
- if (!(input1 = fopen(argv[first_arg],"rb")))
- error("Unable to open file %s for input!",argv[first_arg]);
- ++first_arg;
- if (!(input2 = fopen(argv[first_arg],"rb")))
- error("Unable to open file %s for input!",argv[first_arg]);
-
/* check signature */
- signature = readUint16LE(input1);
+ signature = input1.readU16LE();
if (signature != 0x0A31)
error("Signature not found in disk 1!");
- signature = readUint16LE(input2);
+ signature = input2.readU16LE();
if (signature != 0x0132)
error("Signature not found in disk 2!");
outpath.setFullName("00.LFL");
- if (!(output = fopen(outpath.getFullPath().c_str(), "wb")))
- error("Unable to create index file!");
- notice("Creating 00.LFL...");
+ File output(outpath, "wb");
+ output.setXorMode(0xFF);
+ print("Creating 00.LFL...");
/* write signature */
writeUint16LE(output, signature);
/* copy object flags */
for (i = 0; i < 256; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
/* copy room offsets */
for (i = 0; i < NUM_ROOMS; i++) {
- room_disks[i] = readByte(input1);
- writeByte(output, room_disks[i]);
+ room_disks[i] = input1.readByte();
+ output.writeByte(room_disks[i]);
}
for (i = 0; i < NUM_ROOMS; i++) {
- room_sectors[i] = readByte(input1);
- writeByte(output, room_sectors[i]);
- room_tracks[i] = readByte(input1);
- writeByte(output, room_tracks[i]);
+ room_sectors[i] = input1.readByte();
+ output.writeByte(room_sectors[i]);
+ room_tracks[i] = input1.readByte();
+ output.writeByte(room_tracks[i]);
}
/* copy costume offsets */
for (i = 0; i < 25; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 25; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
/* copy script offsets */
for (i = 0; i < 160; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 160; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
/* copy sound offsets */
for (i = 0; i < 70; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 70; i++)
- writeUint16LE(output, readUint16LE(input1));
- fclose(output);
+ output.writeU16LE(input1.readU16LE());
+ output.close();
for (i = 0; i < NUM_ROOMS; i++) {
- FILE *input;
+ File *input;
+
if (room_disks[i] == '1')
- input = input1;
+ input = &input1;
else if (room_disks[i] == '2')
- input = input2;
+ input = &input2;
else
continue;
sprintf(fname, "%02i.LFL", i);
outpath.setFullName(fname);
- output = fopen(outpath.getFullPath().c_str(), "wb");
+ output.open(outpath, "wb");
- if (output == NULL) {
- error("Unable to create %s!", fname);
- }
+ print("Creating %s...", fname);
+ input->seek((SectorOffset[room_tracks[i]] + room_sectors[i]) * 256, SEEK_SET);
- notice("Creating %s...", fname);
- fseek(input, (SectorOffset[room_tracks[i]] + room_sectors[i]) * 256, SEEK_SET);
-
for (j = 0; j < ResourcesPerFile[i]; j++) {
- unsigned short len = readUint16LE(input);
- writeUint16LE(output, len);
+ unsigned short len = input->readU16LE();
+ output.writeU16LE(len);
for (len -= 2; len > 0; len--) {
- writeByte(output, readByte(input));
+ output.writeByte(input->readByte());
}
}
- rewind(input);
+ rewind(*input);
}
- notice("All done!");
-
- return 0;
+ print("All done!");
}
#ifdef STANDALONE_MAIN
int main(int argc, char *argv[]) {
- return export_main(extract_mm_c64)(argc, argv);
+ ExtractMMC64 mm_c64(argv[0]);
+ return mm_c64.run(argc, argv);
}
#endif
Added: tools/branches/gsoc2009-gui/extract_mm_c64.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_c64.h (rev 0)
+++ tools/branches/gsoc2009-gui/extract_mm_c64.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -0,0 +1,41 @@
+/* extract_mm_c64 - Extract data files from C64 version of Maniac Mansion
+ * Copyright (C) 2009 The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL
+ * $Id
+ *
+ */
+
+#ifndef EXTRACT_MM_C64_H
+#define EXTRACT_MM_C64_H
+
+#include "compress.h"
+
+struct t_resource;
+typedef t_resource * p_resource;
+
+class ExtractMMC64 : public Tool {
+public:
+ ExtractMMC64(const std::string &name = "extract_mm_c64");
+
+ virtual void execute();
+
+protected:
+};
+
+#endif
+
Property changes on: tools/branches/gsoc2009-gui/extract_mm_c64.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: tools/branches/gsoc2009-gui/extract_mm_nes.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_nes.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/extract_mm_nes.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -22,64 +22,14 @@
#include "util.h"
#include <stdarg.h>
+#include "extract_mm_nes.h"
/* if defined, generates a set of .LFL files */
/* if not defined, dumps all resources to separate files */
#define MAKE_LFLS
-#ifdef MAKE_LFLS
-void writeByteAltNES(FILE *fp, uint8 b) {
- writeByte(fp, (uint8)(b ^ 0xFF));
-}
-
-void writeUint16LEAltNES(FILE *fp, uint16 value) {
- writeUint16LE(fp, (uint16)(value ^ 0xFFFF));
-}
-
-#define writeByte writeByteAltNES
-#define writeUint16LE writeUint16LEAltNES
-#endif
-
-typedef enum _res_type {
- NES_UNKNOWN,
- NES_GLOBDATA,
- NES_ROOM,
- NES_SCRIPT,
- NES_SOUND,
- NES_COSTUME,
- NES_ROOMGFX,
- NES_COSTUMEGFX,
- NES_SPRPALS,
- NES_SPRDESC,
- NES_SPRLENS,
- NES_SPROFFS,
- NES_SPRDATA,
- NES_CHARSET,
- NES_PREPLIST
-} res_type;
-
-typedef enum _romset {
- ROMSET_USA,
- ROMSET_EUROPE,
- ROMSET_SWEDEN,
- ROMSET_FRANCE,
- ROMSET_GERMANY,
- ROMSET_SPAIN,
- NUM_ROMSETS
-} t_romset;
-
t_romset ROMset = NUM_ROMSETS;
-struct t_resource {
- uint32 offset;
- uint16 length;
-};
-
-struct t_resgroup {
- res_type type;
- const struct t_resource *langs[NUM_ROMSETS];
-};
-
const struct t_resource res_roomgfx_usa[40] = {
{ 0x04001, 0x03C9 }, { 0x043CA, 0x069E }, { 0x04A68, 0x0327 }, { 0x04D8F, 0x053B }, { 0x052CA, 0x06BE },
{ 0x05988, 0x0682 }, { 0x0600A, 0x0778 }, { 0x06782, 0x0517 }, { 0x06C99, 0x07FB }, { 0x07494, 0x07BE },
@@ -868,7 +818,7 @@
}
};
-void extract_resource (FILE *input, FILE *output, const struct t_resource *res, res_type type) {
+void ExtractMMNes::extract_resource(File &input, File &output, const struct t_resource *res, res_type type) {
uint16 len, i, j;
uint8 val;
uint8 cnt;
@@ -877,77 +827,77 @@
error("extract_resource - no resource specified");
if ((res->offset == 0) && (res->length == 0))
return; /* there are 8 scripts that are zero bytes long, so we should skip them */
- fseek(input, res->offset, SEEK_SET);
+ input.seek(res->offset, SEEK_SET);
switch (type) {
case NES_GLOBDATA:
len = res->length;
for (i = 0; i < len; i++)
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
break;
case NES_ROOMGFX:
case NES_COSTUMEGFX:
- writeUint16LE(output, (uint16)(res->length + 2));
- len = readByte(input);
- writeByte(output, (uint8)len);
+ output.writeU16LE((uint16)(res->length + 2));
+ len = input.readByte();
+ output.writeByte((uint8)len);
if (!len)
len = 256;
len = len << 4;
for (i = 0; i < len;) {
- cnt = readByte(input);
- writeByte(output, cnt);
+ cnt = input.readByte();
+ output.writeByte(cnt);
for (j = 0; j < (cnt & 0x7F); j++, i++)
if ((cnt & 0x80) || (j == 0))
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
}
if (ftell(input) - res->offset != res->length)
error("extract_resource - length mismatch while extracting graphics resource (was %04X, should be %04X)", ftell(input) - res->offset, res->length);
break;
case NES_ROOM:
case NES_SCRIPT:
- len = readUint16LE(input);
+ len = input.readU16LE();
if (len != res->length)
error("extract_resource - length mismatch while extracting room/script resource (was %04X, should be %04X)", len, res->length);
- fseek(input, -2, SEEK_CUR);
+ input.seek(-2, SEEK_CUR);
for (i = 0; i < len; i++)
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
break;
case NES_SOUND:
len = res->length + 2;
- val = readByte(input);
- cnt = readByte(input);
+ val = input.readByte();
+ cnt = input.readByte();
if ((val == 2) && (cnt == 100)) {
- writeUint16LE(output, len);
- writeByte(output, val);
- writeByte(output, cnt);
- cnt = readByte(input);
- writeByte(output, cnt);
+ output.writeU16LE(len);
+ output.writeByte(val);
+ output.writeByte(cnt);
+ cnt = input.readByte();
+ output.writeByte(cnt);
for (i = 0; i < cnt; i++)
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
for (i = 0; i < cnt; i++)
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
while (1) {
- val = readByte(input);
- writeByte(output, val);
+ val = input.readByte();
+ output.writeByte(val);
if (val >= 0xFE)
break;
}
} else if (((val == 0) || (val == 1) || (val == 4)) && (cnt == 10)) {
- writeUint16LE(output, len);
- writeByte(output, val);
- writeByte(output, cnt);
+ output.writeU16LE(len);
+ output.writeByte(val);
+ output.writeByte(cnt);
while (1) {
- val = readByte(input);
- writeByte(output, val);
+ val = input.readByte();
+ output.writeByte(val);
if (val >= 0xFE)
break;
if (val >= 0x10)
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
else {
- writeByte(output, readByte(input));
- writeByte(output, readByte(input));
- writeByte(output, readByte(input));
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
+ output.writeByte(input.readByte());
+ output.writeByte(input.readByte());
+ output.writeByte(input.readByte());
}
}
} else {
@@ -964,22 +914,22 @@
case NES_SPRDATA:
case NES_CHARSET:
len = res->length;
- writeUint16LE(output, (uint16)(len + 2));
+ output.writeU16LE((uint16)(len + 2));
for (i = 0; i < len; i++)
- writeByte(output, readByte(input));
+ output.writeByte(input.readByte());
break;
case NES_PREPLIST:
len = res->length;
- writeUint16LE(output, 0x002A);
- writeByte(output, ' ');
+ output.writeU16LE(0x002A);
+ output.writeByte(' ');
for (i = 1; i < 8; i++)
- writeByte(output, 0);
+ output.writeByte(0);
for (j = 0; j < 4; j++) {
- writeByte(output, ' ');
- for (i = 1; (val = readByte(input)); i++)
- writeByte(output, val);
+ output.writeByte(' ');
+ for (i = 1; (val = input.readByte()); i++)
+ output.writeByte(val);
for (; i < 8; i++)
- writeByte(output, 0);
+ output.writeByte(0);
}
break;
default:
@@ -1130,16 +1080,12 @@
#include "utils/pack-end.h" /* END STRUCT PACKING */
#else /* !MAKE_LFLS */
-void dump_resource (FILE *input, const char *fn_template, int num, const struct t_resource *res, res_type type) {
+void ExtractMMNES::dump_resource (File &input, const char *fn_template, int num, const struct t_resource *res, res_type type) {
char fname[256];
- FILE *output;
sprintf(fname, fn_template, num);
- output = fopen(fname, "wb");
- if (!output)
- error("unable to create %s", fname);
- notice("Extracting resource to %s", fname);
+ File output(fname, "wb");
+ print("Extracting resource to %s", fname);
extract_resource(input, output, res, type);
- fclose(output);
}
#endif /* MAKE_LFLS */
@@ -1155,52 +1101,39 @@
CRCtable[i] = n;
}
}
-static uint32 CheckROM(FILE *file) {
+static uint32 CheckROM(File &file) {
uint32 CRC = 0xFFFFFFFF;
uint32 i;
for (i = 0; i < 262144; i++)
- CRC = (CRC >> 8) ^ CRCtable[(CRC ^ readByte(file)) & 0xFF];
+ CRC = (CRC >> 8) ^ CRCtable[(CRC ^ file.readByte()) & 0xFF];
return CRC ^ 0xFFFFFFFF;
}
-int export_main(extract_mm_nes)(int argc, char *argv[]) {
- const char *helptext =
- "\nUsage: %s [-o <output dir> = out/] <infile.PRG>\n"
+ExtractMMNes::ExtractMMNes(const std::string &name) : Tool(name) {
+ _helptext =
+ "\nUsage: " + _name + " [-o <output dir> = out/] <infile.PRG>\n"
"\tSupported versions: USA, Europe, Sweden, France, Germany, Spain\n"
"\tJapanese version is NOT supported!\n";
+}
- FILE *input, *output;
+void ExtractMMNes::execute() {
int i, j;
uint32 CRC;
- int first_arg = 1;
- int last_arg = argc - 1;
+ // We only got one input file
+ if (_inputPaths.size() > 1)
+ error("Only one input file expected!");
+ Filename inpath(_inputPaths[0]);
+ Filename &outpath = _outputPath;
- char fname[256];
- Filename inpath, outpath;
+ File input(inpath, "rb");
- // Check if we should display some helpful text
- parseHelpArguments(argv, argc, helptext);
-
- // Continuing with finding out output directory
- // also make sure we skip those arguments
- if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
- first_arg += 2;
- else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
- last_arg -= 2;
- else
- // Standard output dir
- outpath.setFullPath("out/");
-
- if (!(input = fopen(argv[first_arg], "rb")))
- error("Unable to open file %s for input", argv[first_arg]);
-
- if ((readByte(input) == 'N') && (readByte(input) == 'E') && (readByte(input) == 'S') && (readByte(input) == 0x1A)) {
- printf("You have specified an iNES formatted ROM image, which is not supported.\n"
+ if ((input.readByte() == 'N') && (input.readByte() == 'E') && (input.readByte() == 'S') && (input.readByte() == 0x1A)) {
+ error(
+ "You have specified an iNES formatted ROM image, which is not supported.\n"
"You must input the PRG section only - see Maniac Mansion NES notes section of README.");
- return 1;
}
rewind(input);
@@ -1210,27 +1143,27 @@
switch (CRC) {
case 0x0D9F5BD1:
ROMset = ROMSET_USA;
- notice("ROM contents verified as Maniac Mansion (USA)");
+ print("ROM contents verified as Maniac Mansion (USA)");
break;
case 0xF59CFC3D:
ROMset = ROMSET_EUROPE;
- notice("ROM contents verified as Maniac Mansion (Europe)");
+ print("ROM contents verified as Maniac Mansion (Europe)");
break;
case 0x3F2BDA65:
ROMset = ROMSET_SWEDEN;
- notice("ROM contents verified as Maniac Mansion (Sweden)");
+ print("ROM contents verified as Maniac Mansion (Sweden)");
break;
case 0xF4B70BFE:
ROMset = ROMSET_FRANCE;
- notice("ROM contents verified as Maniac Mansion (France)");
+ print("ROM contents verified as Maniac Mansion (France)");
break;
case 0x60EA98A0:
ROMset = ROMSET_GERMANY;
- notice("ROM contents verified as Maniac Mansion (Germany)");
+ print("ROM contents verified as Maniac Mansion (Germany)");
break;
case 0xF5B2AFCA:
ROMset = ROMSET_SPAIN;
- notice("ROM contents verified as Maniac Mansion (Spain)");
+ print("ROM contents verified as Maniac Mansion (Spain)");
break;
case 0x3DA2085E:
error("Maniac Mansion (Japan) is not supported");
@@ -1244,14 +1177,16 @@
memset(&mm_lfl_index, 0, sizeof(struct t_lflindex));
for (i = 0; lfls[i].num != -1; i++) {
+ char fname[256];
const struct t_lfl *lfl = &lfls[i];
sprintf(fname, "%02i.LFL", lfl->num);
outpath.setFullName(fname);
- output = fopen(outpath.getFullPath().c_str(), "wb");
- if (!output)
- error("Unable to create %s", fname);
- notice("Creating %s...", fname);
+ File output(outpath, "wb");
+#ifdef MAKE_LFLS
+ output.setXorMode(0xFF);
+#endif
+ print("Creating %s...", fname);
for (j = 0; lfl->entries[j].type != NULL; j++) {
const struct t_lflentry *entry = &lfl->entries[j];
@@ -1314,21 +1249,20 @@
}
extract_resource(input, output, &entry->type->langs[ROMset][entry->index], entry->type->type);
}
- writeUint16LE(output, 0xF5D1);
- fclose(output);
+ output.writeU16LE(0xF5D1);
}
outpath.setFullName("00.LFL");
- output = fopen(outpath.getFullPath().c_str(), "wb");
- if (!output)
- error("Unable to create index file");
- notice("Creating 00.LFL...");
+ File output(outpath, "wb");
+#ifdef MAKE_LFLS
+ output.setXorMode(0xFF);
+#endif
+ print("Creating 00.LFL...");
- writeUint16LE(output, 0x4643);
+ output.writeU16LE(0x4643);
extract_resource(input, output, &res_globdata.langs[ROMset][0], res_globdata.type);
for (i = 0; i < (int)sizeof(struct t_lflindex); i++)
- writeByte(output, ((uint8 *)&mm_lfl_index)[i]);
- fclose(output);
+ output.writeByte(((uint8 *)&mm_lfl_index)[i]);
#else /* !MAKE_LFLS */
dump_resource(input, "globdata.dmp", 0, &res_globdata.langs[ROMset][0], res_globdata.type);
for (i = 0; i < 40; i++)
@@ -1354,15 +1288,13 @@
for (i = 0; i < 2; i++)
dump_resource(input, "sproffs-%d.dmp", i, &res_sproffs.langs[ROMset][i], res_sproffs.type);
#endif /* MAKE_LFLS */
- notice("All done!");
-
- return 0;
+ print("All done!");
}
-#if defined(UNIX) && defined(EXPORT_MAIN)
-int main(int argc, char *argv[]) __attribute__((weak));
+#ifdef STANDALONE_MAIN
int main(int argc, char *argv[]) {
- return export_main(extract_mm_nes)(argc, argv);
+ ExtractMMNes mm_nes(argv[0]);
+ return mm_nes.run(argc, argv);
}
#endif
Added: tools/branches/gsoc2009-gui/extract_mm_nes.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_nes.h (rev 0)
+++ tools/branches/gsoc2009-gui/extract_mm_nes.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -0,0 +1,79 @@
+/* extract_mm_nes - Extract data files from NES version of Maniac Mansion
+ * Copyright (C) 2009 The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef EXTRACT_MM_NES_H
+#define EXTRACT_MM_NES_H
+
+#include "compress.h"
+
+typedef enum _res_type {
+ NES_UNKNOWN,
+ NES_GLOBDATA,
+ NES_ROOM,
+ NES_SCRIPT,
+ NES_SOUND,
+ NES_COSTUME,
+ NES_ROOMGFX,
+ NES_COSTUMEGFX,
+ NES_SPRPALS,
+ NES_SPRDESC,
+ NES_SPRLENS,
+ NES_SPROFFS,
+ NES_SPRDATA,
+ NES_CHARSET,
+ NES_PREPLIST
+} res_type;
+
+typedef enum _romset {
+ ROMSET_USA,
+ ROMSET_EUROPE,
+ ROMSET_SWEDEN,
+ ROMSET_FRANCE,
+ ROMSET_GERMANY,
+ ROMSET_SPAIN,
+ NUM_ROMSETS
+} t_romset;
+
+struct t_resource {
+ uint32 offset;
+ uint16 length;
+};
+
+struct t_resgroup {
+ res_type type;
+ const struct t_resource *langs[NUM_ROMSETS];
+};
+
+class ExtractMMNes : public Tool {
+public:
+ ExtractMMNes(const std::string &name = "extract_mm_nes");
+
+ virtual void execute();
+
+protected:
+
+ void extract_resource(File &input, File &output, const t_resource *res, res_type type);
+ void dump_resource(File &input, const char *fn_template, int num, const t_resource *res, res_type type);
+};
+
+#endif
+
Property changes on: tools/branches/gsoc2009-gui/extract_mm_nes.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: tools/branches/gsoc2009-gui/extract_parallaction.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_parallaction.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/extract_parallaction.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -22,8 +22,7 @@
#include "extract_parallaction.h"
-Archive::Archive() {
- _file = NULL;
+Archive::Archive(Tool &tool) : _tool(tool) {
_fileData = NULL;
_fileSize = 0;
_filePos = 0;
@@ -34,11 +33,6 @@
Archive::~Archive() {
closeSubfile();
-
- if (_file)
- fclose(_file);
-
- _file = NULL;
}
bool Archive::isPackedSubfile(byte *data) {
@@ -64,7 +58,8 @@
}
void Archive::closeSubfile() {
- if (_fileData) free(_fileData);
+ if (_fileData)
+ free(_fileData);
_fileData = NULL;
_fileSize = 0;
_filePos = 0;
@@ -83,8 +78,8 @@
uint32 srcSize = _sizes[index];
byte *srcData = (byte *)malloc(srcSize);
- fseek(_file, srcOffset, SEEK_SET);
- fread(srcData, 1, srcSize, _file);
+ _file.seek(srcOffset, SEEK_SET);
+ _file.read(srcData, 1, srcSize);
if (isPackedSubfile(srcData)) {
_fileSize = getSizeOfPackedSubfile(srcData, srcSize);
@@ -120,13 +115,12 @@
void Archive::open(const char *filename, bool smallArchive) {
uint16 maxEntries = (smallArchive) ? 180 : 384;
- _file = fopen(filename, "rb");
- if (!_file) exit(10);
+ _file.open(filename, "rb");
strcpy(_name, filename);
- fseek(_file, ARCHIVE_HEADER_SIZE, SEEK_SET);
- fread(_names, maxEntries + 1, ARCHIVE_FILENAME_LEN, _file);
+ _file.seek(ARCHIVE_HEADER_SIZE, SEEK_SET);
+ _file.read(_names, maxEntries + 1, ARCHIVE_FILENAME_LEN);
uint32 i;
for (i = 0; i < maxEntries; i++) {
@@ -151,12 +145,12 @@
_numSlots = i;
- fprintf(stderr, "%i files found in %i slots (%i empty)\n", _numFiles, _numSlots, _numSlots - _numFiles);
+ _tool.print("%i files found in %i slots (%i empty)\n", _numFiles, _numSlots, _numSlots - _numFiles);
- fseek(_file, _numSlots * ARCHIVE_FILENAME_LEN + ARCHIVE_HEADER_SIZE, SEEK_SET);
+ _file.seek(_numSlots * ARCHIVE_FILENAME_LEN + ARCHIVE_HEADER_SIZE, SEEK_SET);
for (i = 0; i < _numSlots; i++) {
- _sizes[i] = readUint32BE(_file);
+ _sizes[i] = _file.readU32BE();
}
if (smallArchive) {
@@ -298,10 +292,31 @@
}
-void optDump(const char *file, Filename *outpath, bool smallArchive) {
- Archive arc;
- arc.open(file, smallArchive);
+ExtractParallaction::ExtractParallaction(const std::string &name) : Tool(name) {
+ _helptext = "\nUsage: " + _name + " [--small] [-o <output dir> = out/] <file>\n";
+}
+void ExtractParallaction::parseExtraArguments() {
+ if(_arguments[_arguments_parsed] == "--small") {
+ _small = true;
+ ++_arguments_parsed;
+ }
+}
+
+void ExtractParallaction::execute() {
+
+ // We only got one input file
+ if (_inputPaths.size() > 1)
+ error("Only one input file expected!");
+ Filename inpath(_inputPaths[0]);
+ Filename &outpath = _outputPath;
+
+ if(outpath.empty())
+ outpath.setFullPath("out/");
+
+ Archive arc(*this);
+ arc.open(inpath.getFullPath().c_str(), _small);
+
for (uint32 i = 0; i < arc._numFiles; i++) {
arc.openSubfile(i);
@@ -312,45 +327,17 @@
*d = *s == '/' ? '_' : *s;
*d = '\0';
- outpath->setFullName(d);
+ outpath.setFullName(d);
- FILE *ofile = fopen(outpath->getFullPath().c_str(), "wb");
- fwrite(arc._fileData, 1, arc._fileSize, ofile);
- fclose(ofile);
+ File ofile(outpath, "wb");
+ ofile.write(arc._fileData, 1, arc._fileSize);
}
}
-int export_main(extract_parallaction)(int argc, char *argv[]) {
- const char *helptext = "\nUsage: %s [--small] [-o <output dir> = out/] <file>\n";
-
- Filename outpath;
-
- parseHelpArguments(argv, argc, helptext);
-
- // Continuing with finding out output directory
- // also make sure we skip those arguments
- int arg = 1;
- if (parseOutputDirectoryArguments(&outpath, argv, argc, 1))
- arg += 2;
- else if (parseOutputDirectoryArguments(&outpath, argv, argc, argc - 3))
- arg -= 2;
- else
- // Standard output dir
- outpath.setFullPath("out/");
-
-
- if (strcmp(argv[arg], "--small") == 0) {
- optDump(argv[arg], &outpath, true);
- } else {
- optDump(argv[arg], &outpath, false);
- }
-
- return 0;
-}
-
#ifdef STANDALONE_MAIN
int main(int argc, char *argv[]) {
- return export_main(extract_parallaction)(argc, argv);
+ ExtractParallaction parallaction(argv[0]);
+ return parallaction.run(argc, argv);
}
#endif
Modified: tools/branches/gsoc2009-gui/extract_parallaction.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_parallaction.h 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/extract_parallaction.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -20,6 +20,10 @@
*
*/
+#ifndef EXTRACT_PARALLACTION_H
+#define EXTRACT_PARALLACTION_H
+
+#include "tool.h"
#include "util.h"
uint32 depackedlen(byte *packed, uint32 plen);
@@ -32,9 +36,12 @@
struct Archive {
+ // Required for printing errors
+ Tool &_tool;
+
uint32 _numSlots;
uint32 _numFiles;
- FILE *_file;
+ File _file;
char _name[260];
// file data
@@ -53,7 +60,7 @@
void readSubfile(byte* buf, uint32 size);
uint32 getSizeOfSubfile();
- Archive();
+ Archive(Tool &tool);
~Archive();
// debug stuff
@@ -68,3 +75,17 @@
void unpackSubfile(byte* packedData, uint32 packedSize);
};
+
+class ExtractParallaction : public Tool {
+public:
+ ExtractParallaction(const std::string &name = "extract_parallaction");
+
+ virtual void execute();
+
+protected:
+ void parseExtraArguments();
+
+ bool _small;
+};
+
+#endif
Modified: tools/branches/gsoc2009-gui/extract_zak_c64.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_zak_c64.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/extract_zak_c64.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -22,18 +22,8 @@
#include "util.h"
#include <stdarg.h>
+#include "extract_zak_c64.h"
-void writeByteAltC64(FILE *fp, uint8 b) {
- writeByte(fp, (uint8)(b ^ 0xFF));
-}
-
-void writeUint16LEAltC64(FILE *fp, uint16 value) {
- writeUint16LE(fp, (uint16)(value ^ 0xFFFF));
-}
-
-#define writeByte writeByteAltC64
-#define writeUint16LE writeUint16LEAltC64
-
#define NUM_ROOMS 59
unsigned char room_disks_c64[NUM_ROOMS], room_tracks_c64[NUM_ROOMS], room_sectors_c64[NUM_ROOMS];
@@ -53,128 +43,113 @@
3, 1, 2, 1, 2, 1, 10, 1, 1
};
-int export_main(extract_zak_c64)(int argc, char *argv[]) {
- const char *helptext = "\nUsage: %s [-o <output dir> = out/] <disk1.d64> <disk2.d64>\n";
+ExtractZakC64::ExtractZakC64(const std::string &name) : Tool(name) {
+ _helptext = "\nUsage: " + _name + " [-o <output dir> = out/] <disk1.d64> <disk2.d64>\n";
+}
- FILE *input1, *input2, *output;
+void ExtractZakC64::execute() {
int i, j;
unsigned short signature;
- int first_arg = 1;
- int last_arg = argc - 1;
-
char fname[1024];
- Filename outpath;
- // Check if we should display some helpful text
- parseHelpArguments(argv, argc, helptext);
-
- // Continuing with finding out output directory
- // also make sure we skip those arguments
- if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
- first_arg += 2;
- else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
- last_arg -= 2;
- else
- // Standard output dir
+ // Two disks...
+ if (_inputPaths.size() != 2)
+ error("Two input files expected!");
+ Filename inpath1(_inputPaths[0]);
+ Filename inpath2(_inputPaths[1]);
+ Filename &outpath = _outputPath;
+
+ if(outpath.empty())
+ // Standard output path
outpath.setFullPath("out/");
+
+ File input1(inpath1, "rb");
+ File input2(inpath2, "rb");
- if (last_arg - first_arg == 1)
- error("Requires two disk files");
-
- if (!(input1 = fopen(argv[first_arg],"rb")))
- error("Unable to open file %s for input!",argv[first_arg]);
- ++first_arg;
- if (!(input2 = fopen(argv[first_arg],"rb")))
- error("Unable to open file %s for input!",argv[first_arg]);
-
/* check signature */
- signature = readUint16LE(input1);
+ signature = input1.readU16LE();
if (signature != 0x0A31)
error("Signature not found in disk 1!");
- signature = readUint16LE(input2);
+ signature = input2.readU16LE();
if (signature != 0x0132)
error("Signature not found in disk 2!");
+
outpath.setFullName("00.LFL");
- if (!(output = fopen(outpath.getFullPath().c_str(), "wb")))
- error("Unable to create index file!");
- notice("Creating 00.LFL...");
+ File output(outpath, "wb");
+ output.setXorMode(0xFF);
+ error("Unable to create index file!");
+ print("Creating 00.LFL...");
/* write signature */
- writeUint16LE(output, signature);
+ output.writeU16LE(signature);
/* copy object flags */
for (i = 0; i < 775; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
/* copy room offsets */
for (i = 0; i < NUM_ROOMS; i++) {
- room_disks_c64[i] = readByte(input1);
- writeByte(output, room_disks_c64[i]);
+ room_disks_c64[i] = input1.readByte();
+ output.writeByte(room_disks_c64[i]);
}
for (i = 0; i < NUM_ROOMS; i++) {
- room_sectors_c64[i] = readByte(input1);
- writeByte(output, room_sectors_c64[i]);
- room_tracks_c64[i] = readByte(input1);
- writeByte(output, room_tracks_c64[i]);
+ room_sectors_c64[i] = input1.readByte();
+ output.writeByte(room_sectors_c64[i]);
+ room_tracks_c64[i] = input1.readByte();
+ output.writeByte(room_tracks_c64[i]);
}
/* copy costume offsets */
for (i = 0; i < 38; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 38; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
/* copy script offsets */
for (i = 0; i < 155; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 155; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
/* copy sound offsets */
for (i = 0; i < 127; i++)
- writeByte(output, readByte(input1));
+ output.writeByte(input1.readByte());
for (i = 0; i < 127; i++)
- writeUint16LE(output, readUint16LE(input1));
+ output.writeU16LE(input1.readU16LE());
- fclose(output);
+ output.close();
for (i = 0; i < NUM_ROOMS; i++) {
- FILE *input;
+ File *input;
if (room_disks_c64[i] == '1')
- input = input1;
+ input = &input1;
else if (room_disks_c64[i] == '2')
- input = input2;
+ input = &input2;
else
continue;
- sprintf(fname,"%02i.LFL", i);
+ sprintf(fname, "%02i.LFL", i);
outpath.setFullName(fname);
- output = fopen(outpath.getFullPath().c_str(), "wb");
+ output.open(outpath, "wb");
- if (output == NULL) {
- error("Unable to create %s!", fname);
- }
+ print("Creating %s...", fname);
+ input->seek((SectorOffset[room_tracks_c64[i]] + room_sectors_c64[i]) * 256, SEEK_SET);
- notice("Creating %s...", fname);
- fseek(input, (SectorOffset[room_tracks_c64[i]] + room_sectors_c64[i]) * 256, SEEK_SET);
-
for (j = 0; j < ResourcesPerFile[i]; j++) {
- unsigned short len = readUint16LE(input);
- writeUint16LE(output, len);
+ unsigned short len = input->readU16LE();
+ output.writeU16LE(len);
for (len -= 2; len > 0; len--) {
- writeByte(output, readByte(input));
+ output.writeByte(input->readByte());
}
}
- rewind(input);
+ rewind(*input);
}
- notice("All done!");
-
- return 0;
+ print("All done!");
}
#ifdef STANDALONE_MAIN
Added: tools/branches/gsoc2009-gui/extract_zak_c64.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_zak_c64.h (rev 0)
+++ tools/branches/gsoc2009-gui/extract_zak_c64.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -0,0 +1,38 @@
+/* extract_zak_c64 - Extract data files from C64 version of Zak McKracken
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef EXTRACT_ZAK_C64_H
+#define EXTRACT_ZAK_C64_H
+
+#include "tool.h"
+
+class ExtractZakC64 : public Tool {
+public:
+ ExtractZakC64(const std::string &name = "extract_zak_c64");
+
+ virtual void execute();
+
+protected:
+
+};
+
+#endif
Property changes on: tools/branches/gsoc2009-gui/extract_zak_c64.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: tools/branches/gsoc2009-gui/gui/tools.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/tools.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/gui/tools.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -45,6 +45,12 @@
#include "../compress_tucker.h"
#include "../extract_agos.h"
#include "../extract_gob_stk.h"
+#include "../extract_loom_tg16.h"
+#include "../extract_mm_apple.h"
+#include "../extract_mm_c64.h"
+#include "../extract_mm_nes.h"
+#include "../extract_parallaction.h"
+#include "../extract_zak_c64.h"
// Our global tools object, which holds all tools
@@ -57,33 +63,23 @@
// Compress agos also has a --mac parameter, need to add an additional page / option for this
addTool(new ToolGUI(new CompressAgos()));
-
// Compress gob also has a --f parameter, need to add an additional page / option for this
addTool(new ToolGUI(new CompressGob()));
-
- // Compress kyra...
addTool(new ToolGUI(new CompressKyra()));
-
- // Compress queen...
addTool(new ToolGUI(new CompressQueen()));
-
- // Compress saga...
addTool(new ToolGUI(new CompressSaga()));
-
- // Compress tinsel...
addTool(new ToolGUI(new CompressTinsel()));
-
- // Compress touche...
addTool(new ToolGUI(new CompressTouche(), wxT("/")));
-
- // Compress tucker...
addTool(new ToolGUI(new CompressTucker(), wxT("/")));
- // extract_agos
addTool(new ToolGUI(new ExtractAgos()));
-
- // extract_gob_stk
addTool(new ToolGUI(new ExtractGobStk()));
+ addTool(new ToolGUI(new ExtractLoomTG16()));
+ addTool(new ToolGUI(new ExtractMMApple()));
+ addTool(new ToolGUI(new ExtractMMC64()));
+ addTool(new ToolGUI(new ExtractMMNes()));
+ addTool(new ToolGUI(new ExtractParallaction()));
+ addTool(new ToolGUI(new ExtractZakC64()));
/* "Old" tool list, will be converted incrementally
// Compression tools
Modified: tools/branches/gsoc2009-gui/tool.cpp
===================================================================
--- tools/branches/gsoc2009-gui/tool.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/tool.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -122,6 +122,17 @@
throw ToolException(buf);
}
+void Tool::warning(const char *format, ...) {
+ char buf[4096];
+ va_list va;
+
+ va_start(va, format);
+ vsnprintf(buf, 4096, format, va);
+ va_end(va);
+
+ _internalPrint(_print_udata, (std::string("Warning: ") + buf).c_str());
+}
+
void Tool::print(const char *format, ...) {
char buf[4096] = "";
va_list va;
Modified: tools/branches/gsoc2009-gui/tool.h
===================================================================
--- tools/branches/gsoc2009-gui/tool.h 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/tool.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -43,6 +43,7 @@
void run();
void error(const char *format, ...);
+ void warning(const char *format, ...);
void print(const char *format, ...);
/** Returns name of the tool */
Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/util.cpp 2009-07-08 03:19:51 UTC (rev 42253)
@@ -291,6 +291,7 @@
File::File() {
_file = NULL;
_mode = FILEMODE_READ;
+ _xormode = 0;
}
File::File(const Filename &filepath, FileMode mode) {
@@ -350,6 +351,10 @@
_file = NULL;
}
+void File::setXorMode(uint8 xormode) {
+ _xormode = xormode;
+}
+
uint8 File::readByte() {
if (!_file)
throw FileException("File is not open");
@@ -357,6 +362,7 @@
throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
int u8 = fgetc(_file);
+ u8 ^= _xormode;
if (u8 == EOF)
throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
return (uint8)u8;
@@ -411,6 +417,8 @@
if ((_mode & FILEMODE_WRITE) == 0)
throw FileException("Tried to write to a file opened in read mode (" + _name.getFullPath() + ")");
+ b ^= _xormode;
+
if (fwrite(&b, 1, 1, _file) != 1)
throw FileException("Could not write to file (" + _name.getFullPath() + ")");
}
Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h 2009-07-08 01:07:41 UTC (rev 42252)
+++ tools/branches/gsoc2009-gui/util.h 2009-07-08 03:19:51 UTC (rev 42253)
@@ -351,7 +351,6 @@
/**
* Opens the given file path as an in/out stream, depending on the second argument
- * File is always opened in binary mode
*
* @param filename The file to open
* @param mode The mode to open the file in
@@ -363,8 +362,14 @@
* Closes the file, if it's open
*/
void close();
+
+ /**
+ * Sets the xor mode of the file, bytes written / read to the file
+ * will be XORed with this value. this value is *not* reset when opening a new file
+ * Only works for write* and read* operation, not for the array "read" and "write" methods
+ */
+ void setXorMode(uint8 xormode);
-
/**
* Read a single unsigned byte
* Throws FileException if file is not open / if read failed ended prematurely
@@ -459,8 +464,15 @@
FILE *_file;
/** The name of the file, used for better error messages */
Filename _name;
+ /** xor with this value while reading/writing (default 0), does not work for "read"/"write", only for byte operations */
+ uint8 _xormode;
};
+// This generates a warning when used, so we don't use fclose accidently on
+// a File object (this is a VERY EASY error to do when converting, and a warning
+// really helps find those cases)
+void fclose(File& f);
+
void displayHelp(const char *msg = NULL, const char *exename = NULL);
void parseHelpArguments(const char * const argv[], int argc, const char *msg = NULL);
bool parseOutputFileArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list