summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2003-09-10 16:00:01 +0000
committerpixel <pixel>2003-09-10 16:00:01 +0000
commitae612d5361b66b7bcbafae3f36d851f7624aaae6 (patch)
treee32f3b5b3cd8f7670123e50a202a804a7cc9c186
parent40e45d8948a8b5315c83886b5218543cafae0c4a (diff)
Starting adding mips stuff
-rwxr-xr-xMakefile7
-rw-r--r--includes/cdutils.h6
-rw-r--r--includes/mips.h39
-rwxr-xr-xlib/Makefile2
-rw-r--r--lib/mips.cpp162
5 files changed, 213 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 7420f0b..323fe2b 100755
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
#!/usr/bin/make -f
-CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -Iincludes `sdl-config --cflags` -DHAVE_ZLIB `baltisot-config --cflags`
+CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Iincludes `sdl-config --cflags` -DHAVE_ZLIB `baltisot-config --cflags`
LDFLAGS=-lz `sdl-config --libs` `baltisot-config --libs`
CXX=g++
SUBDIRS = psxdev lib Xenogears VP MegamanX5
-TARGET = lzss dlzss cd-tool str-player crypto-search bgrep tile-convert
+TARGET = lzss dlzss cd-tool str-player crypto-search bgrep tile-convert mipspoke
all: subdirs ${TARGET}
@@ -33,6 +33,9 @@ str-player: str-player.o includes/cdutils.h includes/yazedc.h lib/lib.a psxdev/p
crypto-search: crypto-search.o lib/lib.a Makefile
${CXX} crypto-search.o lib/lib.a -o crypto-search ${LDFLAGS}
+mipspoke: mipspoke.o lib/lib.a Makefile
+ ${CXX} mipspoke.o lib/lib.a -o mipspoke ${LDFLAGS}
+
bgrep: bgrep.o Makefile
${CXX} bgrep.o -o bgrep ${LDFLAGS}
diff --git a/includes/cdutils.h b/includes/cdutils.h
index 91bb54c..86779ba 100644
--- a/includes/cdutils.h
+++ b/includes/cdutils.h
@@ -25,6 +25,12 @@
#include "Handle.h"
+#define MODE0 0
+#define MODE1 1
+#define MODE2 2
+#define MODE2_FORM1 3
+#define MODE2_FORM2 4
+#define MODE_RAW 5
#define GUESS 6
extern const long sec_sizes[];
diff --git a/includes/mips.h b/includes/mips.h
new file mode 100644
index 0000000..b0409ea
--- /dev/null
+++ b/includes/mips.h
@@ -0,0 +1,39 @@
+#ifndef __MIPS_H__
+#define __MIPS_H__
+#include <Exceptions.h>
+#include <generic.h>
+#include <Handle.h>
+
+class mips : public Base {
+ public:
+ Uint8 Read8(Uint32);
+ Uint16 Read16(Uint32);
+ Uint32 Read32(Uint32);
+ void Write8(Uint32, Uint8);
+ void Write16(Uint32, Uint16);
+ void Write32(Uint32, Uint32);
+ void unpatch8(Uint32);
+ void unpatch16(Uint32);
+ void unpatch32(Uint32);
+ bool IsPatched(Uint32);
+ void LoadEXE(Handle *);
+ void SaveEXE(Handle *);
+ Uint32 GetPC();
+ private:
+ void patch(Uint32, int);
+ void unpatch(Uint32, int);
+ Uint8 psyqhead[0x800];
+ Uint8 plainmemory[0x200000];
+ Uint8 patches[0x200000];
+ Uint8 patchesmap[0x200000 / 8];
+ Uint32 paddr, psize, startpc;
+
+ struct psyq {
+ Uint8 id[8];
+ Uint32 text, data, pc0, gp0, t_addr, t_size;
+ Uint32 d_addr, d_size, b_addr, b_size, s_addr, s_size;
+ Uint32 sp, fp, gp, ra, s0;
+ };
+};
+
+#endif
diff --git a/lib/Makefile b/lib/Makefile
index 8dda356..a7d7fe5 100755
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -3,7 +3,7 @@
CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Werror -I../includes -DHAVE_ZLIB -DUSE_CDREADER -DDEBUG `baltisot-config --cflags`
CXX=g++
-OBJECTS = cdutils.o lzss.o yazedc.o cdreader.o cdabstract.o
+OBJECTS = cdutils.o lzss.o yazedc.o cdreader.o cdabstract.o mips.o
TARGET = lib.a
all: ${TARGET}
diff --git a/lib/mips.cpp b/lib/mips.cpp
new file mode 100644
index 0000000..4956b9e
--- /dev/null
+++ b/lib/mips.cpp
@@ -0,0 +1,162 @@
+#include "mips.h"
+
+Uint8 mips::Read8(Uint32 mem) {
+ if ((mem < 0x80000000) || (mem >= 0x80200000)) {
+ printm(M_WARNING, "Reading at out of bound of memory: 0x%08x\n", mem);
+ return 0;
+ }
+
+ mem -= 0x80000000;
+
+ if (IsPatched(mem)) {
+ return patches[mem];
+ } else {
+ return plainmemory[mem];
+ }
+}
+
+Uint16 mips::Read16(Uint32 mem) {
+ Uint8 a, b;
+
+ if (mem & 1) {
+ printm(M_WARNING, "Read16 at a non 16-bits boundary: 0x%08x\n", mem);
+ }
+
+ a = Read8(mem);
+ b = Read8(mem + 1);
+
+ return a | (b << 8);
+}
+
+Uint32 mips::Read32(Uint32 mem) {
+ Uint8 a, b, c, d;
+
+ if (mem & 3) {
+ printm(M_WARNING, "Read32 at a non 32-bits boundary: 0x%08x\n", mem);
+ }
+
+ a = Read8(mem);
+ b = Read8(mem + 1);
+ c = Read8(mem + 2);
+ d = Read8(mem + 3);
+
+ return a | (b << 8) | (c << 16) | (d << 24);
+}
+
+void mips::Write8(Uint32 mem, Uint8 value) {
+ if ((mem < 0x80000000) || (mem > (0x80200000 - 1))) {
+ printm(M_WARNING, "Reading at out of bound of memory: 0x%08x\n", mem);
+ return;
+ }
+
+ mem -= 0x80000000;
+
+ patch(mem, 1);
+ patches[mem] = value;
+}
+
+void mips::Write16(Uint32 mem, Uint16 value) {
+ if ((mem < 0x80000000) || (mem > (0x80200000 - 2))) {
+ printm(M_WARNING, "Reading at out of bound of memory: 0x%08x\n", mem);
+ return;
+ }
+
+ mem -= 0x80000000;
+
+ patch(mem, 2);
+ patches[mem] = value & 0xff;
+ patches[mem + 1] = (value >> 8) & 0xff;
+}
+
+void mips::Write32(Uint32 mem, Uint32 value) {
+ if ((mem < 0x80000000) || (mem > (0x80200000 - 4))) {
+ printm(M_WARNING, "Reading at out of bound of memory: 0x%08x\n", mem);
+ return;
+ }
+
+ mem -= 0x80000000;
+
+ patch(mem, 4);
+ patches[mem] = value & 0xff;
+ patches[mem + 1] = (value >> 8) & 0xff;
+ patches[mem + 2] = (value >> 16) & 0xff;
+ patches[mem + 3] = (value >> 24) & 0xff;
+}
+
+void mips::unpatch8(Uint32 mem) {
+ unpatch(mem, 1);
+}
+
+void mips::unpatch16(Uint32 mem) {
+ unpatch(mem, 2);
+}
+
+void mips::unpatch32(Uint32 mem) {
+ unpatch(mem, 4);
+}
+
+bool mips::IsPatched(Uint32 mem) {
+ int mask, pos;
+
+ pos = mem / 8;
+ mask = 1 << (mem % 8);
+
+ return patchesmap[pos] &= mask;
+}
+
+void mips::LoadEXE(Handle * h) {
+ h->read(psyqhead, 0x800);
+ memset(plainmemory, 0, 0x200000);
+ paddr = ((psyq*)psyqhead)->t_addr;
+ psize = ((psyq*)psyqhead)->t_size;
+
+ printm(M_INFO, "Loading %i (%08x) bytes of data at %i (%08x).\n", psize, psize, paddr - 0x80000000, paddr);
+
+ h->read(plainmemory + paddr - 0x80000000, psize);
+}
+
+void mips::SaveEXE(Handle * h) {\
+ Uint32 i;
+
+ if (!*((Uint32 *)psyqhead))
+ return;
+ h->write(psyqhead, 0x800);
+ paddr = ((psyq*)psyqhead)->t_addr;
+ psize = ((psyq*)psyqhead)->t_size;
+
+ printm(M_INFO, "Writing %i (%08x) bytes of data from %i (%08x).\n", psize, psize, paddr - 0x80000000, paddr);
+
+ for (i = paddr - 0x80000000; i < psize; i++) {
+ h->writeU8(Read8(i));
+ }
+}
+
+Uint32 mips::GetPC() {
+ return startpc;
+}
+
+void mips::patch(Uint32 mem, int size) {
+ int mask, pos;
+
+ pos = mem / 8;
+ mask = 1 << (mem % 8);
+
+ patchesmap[pos] |= mask;
+
+ if (size != 1) {
+ patch(mem + 1, size - 1);
+ }
+}
+
+void mips::unpatch(Uint32 mem, int size) {
+ int mask, pos;
+
+ pos = mem / 8;
+ mask = ~(1 << (mem % 8));
+
+ patchesmap[pos] &= mask;
+
+ if (size != 1) {
+ unpatch(mem + 1, size - 1);
+ }
+}