summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xMakefile5
-rw-r--r--ffx-convert.cpp80
-rw-r--r--generic/Exceptions.cpp4
-rw-r--r--includes/Exceptions.h6
-rw-r--r--includes/Image.h2
-rw-r--r--includes/Input.h2
-rw-r--r--includes/Output.h2
-rw-r--r--includes/cdreader.h2
-rw-r--r--lzss-main.cpp4
9 files changed, 100 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 4d79654..cd4f9d4 100755
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ LDFLAGS=-lz `sdl-config --libs`
CXX=g++
SUBDIRS = psxdev generic lib Xenogears VP MegamanX5 PcsxSrc
-TARGET = lzss dlzss cd-tool str-player crypto-search bgrep dte-tool
+TARGET = lzss dlzss cd-tool str-player crypto-search bgrep dte-tool ffx-convert
all: subdirs ${TARGET}
@@ -36,6 +36,9 @@ crypto-search: crypto-search.o includes/generic.h lib/lib.a generic/generic.a Ma
bgrep: bgrep.o includes/generic.h generic/generic.a Makefile
${CXX} bgrep.o generic/generic.a -o bgrep ${LDFLAGS}
+ffx-convert: ffx-convert.o generic/generic.a Makefile
+ ${CXX} ffx-convert.o generic/generic.a -o ffx-convert ${LDFLAGS}
+
clean:
for d in ${SUBDIRS} ; do make -C $$d clean || exit -1 ; done
rm -f *.o ${TARGET} compil.c
diff --git a/ffx-convert.cpp b/ffx-convert.cpp
new file mode 100644
index 0000000..0fa6818
--- /dev/null
+++ b/ffx-convert.cpp
@@ -0,0 +1,80 @@
+#include <unistd.h>
+#include "generic.h"
+#include "Main.h"
+#include "Image.h"
+#include "Input.h"
+#include "Output.h"
+
+#define IMG_SX 256
+#define IMG_SY 256
+
+#define BLOC_SX 16
+#define BLOC_SY 8
+
+CODE_BEGINS
+
+Color LookUp(char i) {
+ return Color(i << 4, i << 4, i << 4, 255);
+}
+
+int transform(int x, int y) {
+ int numero_bloc_x = x / BLOC_SX;
+ int numero_bloc_y = y / BLOC_SY;
+
+ int numero_bloc = numero_bloc_y * (IMG_SX / BLOC_SX) + numero_bloc_x;
+
+ int bx = x % BLOC_SX;
+ int by = y % BLOC_SY;
+
+ return numero_bloc * BLOC_SX * BLOC_SY + by * BLOC_SX + bx;
+}
+
+virtual int startup() throw (GeneralException) {
+ int c;
+
+ while ((c = getopt(argc, argv, "")) != EOF) {
+ switch (c) {
+ default:
+ printm(M_ERROR, "Unknow option: %c\n", c);
+ throw Exit(-1);
+ }
+ }
+
+ if ((argc - optind) != 2) {
+ printm(M_ERROR, "Need two arguments\n");
+ throw Exit(-1);
+ }
+
+ Input * map = new Input(argv[optind]);
+ Output * tga = new Output(argv[optind + 1]);
+ Image * img = new Image(IMG_SX, IMG_SY);
+
+ map->seek(0x140);
+
+ char buffer[65536];
+
+ Byte b;
+
+ for (int i = 0; i < 32768; i++) {
+ int j = i << 1;
+ map->read(&b, 1);
+ buffer[j] = b & 0x0f;
+ buffer[j + 1] = (b & 0xf0) >> 4;
+ }
+
+ img->Fill();
+
+ for (int y = 0; y < IMG_SX; y++) {
+ for (int x = 0; x < IMG_SY; x++) {
+ img->SetPixel(x, y, LookUp(buffer[transform(x, y)]));
+ }
+ }
+
+ img->Prepare(FORMAT_TGA_BASIC);
+
+ copy(img, tga);
+
+ return 0;
+}
+
+CODE_ENDS
diff --git a/generic/Exceptions.cpp b/generic/Exceptions.cpp
index 510e0a3..1159cdd 100644
--- a/generic/Exceptions.cpp
+++ b/generic/Exceptions.cpp
@@ -157,3 +157,7 @@ pid_t xfork() throw (GeneralException) {
return p;
}
+
+void xexit(int status) throw (GeneralException) {
+ throw Exit(status);
+}
diff --git a/includes/Exceptions.h b/includes/Exceptions.h
index 49be085..74ad938 100644
--- a/includes/Exceptions.h
+++ b/includes/Exceptions.h
@@ -24,6 +24,7 @@ class Base {
static void free(unsigned char *& p);
static int pipe(int * p, int flag = 0);
static pid_t fork();
+ static void exit(int);
};
class String;
@@ -49,6 +50,7 @@ void xfree(unsigned char *&);
void * xrealloc(void *, size_t);
int xpipe(int *, int = 0) throw (GeneralException);
pid_t xfork() throw (GeneralException);
+void xexit(int) throw (GeneralException);
INLINE char * Base::strdup(const char * s) {
return xstrdup(s);
@@ -98,6 +100,10 @@ INLINE pid_t Base::fork() {
return xfork();
}
+INLINE void Base::exit(int status) {
+ xexit(status);
+}
+
class MemoryException : public GeneralException {
public:
MemoryException(ssize_t);
diff --git a/includes/Image.h b/includes/Image.h
index 09b4cb5..9bef556 100644
--- a/includes/Image.h
+++ b/includes/Image.h
@@ -7,7 +7,7 @@
enum {
FORMAT_TGA_BASIC
-} format_t;
+};
struct Color {
Color(unsigned char aR, unsigned char aG, unsigned char aB, unsigned char aA = 255) :
diff --git a/includes/Input.h b/includes/Input.h
index 1fb48c3..cb1428f 100644
--- a/includes/Input.h
+++ b/includes/Input.h
@@ -15,7 +15,7 @@ class Input : public Handle {
virtual bool CanWrite() const;
virtual bool CanRead() const;
virtual bool CanSeek() const;
- virtual off_t seek(off_t, int) throw (GeneralException);
+ virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
virtual String GetName() const;
virtual ssize_t GetSize() const;
virtual time_t GetModif() const;
diff --git a/includes/Output.h b/includes/Output.h
index 3ec5158..eb7b8a6 100644
--- a/includes/Output.h
+++ b/includes/Output.h
@@ -15,7 +15,7 @@ class Output : public Handle {
virtual bool CanWrite() const;
virtual bool CanRead() const;
virtual bool CanSeek() const;
- virtual off_t seek(off_t, int) throw (GeneralException);
+ virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
virtual String GetName() const;
protected:
diff --git a/includes/cdreader.h b/includes/cdreader.h
index ed3bc00..1909fe2 100644
--- a/includes/cdreader.h
+++ b/includes/cdreader.h
@@ -16,7 +16,7 @@ class cdreader : public Handle {
virtual bool CanRead() const;
virtual bool CanSeek() const;
virtual ssize_t read(void *buf, size_t count) throw (GeneralException);
- virtual off_t seek(off_t, int) throw (GeneralException);
+ virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
virtual String GetName() const;
virtual ssize_t GetSize() const;
virtual void getsector(void *, int = -1) throw (GeneralException);
diff --git a/lzss-main.cpp b/lzss-main.cpp
index d2d9c68..87d2a0f 100644
--- a/lzss-main.cpp
+++ b/lzss-main.cpp
@@ -395,7 +395,7 @@ LZSS_NAME + " compressor/decompressor version " + LZSS_VERSION + ",\n"
delete f1;
delete f2;
-
- exit(0);
+
+ return 0;
}
CODE_ENDS