aboutsummaryrefslogtreecommitdiff
path: root/tools/smxlink/timreader.cpp
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-04-06 10:11:07 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-04-06 10:11:07 +0800
commitf3e040230772f978540a71aea43dfde200992922 (patch)
treebd8ca31b72dd01e24980b073854e263589530f56 /tools/smxlink/timreader.cpp
downloadpsn00bsdk-f3e040230772f978540a71aea43dfde200992922.tar.gz
First commit
Diffstat (limited to 'tools/smxlink/timreader.cpp')
-rw-r--r--tools/smxlink/timreader.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/tools/smxlink/timreader.cpp b/tools/smxlink/timreader.cpp
new file mode 100644
index 0000000..a8fba94
--- /dev/null
+++ b/tools/smxlink/timreader.cpp
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <string.h>
+#include "timreader.h"
+
+int GetTimCoords(const char* fileName, TIM_COORDS *coords) {
+
+ FILE* fp = fopen(fileName, "rb");
+
+ if (fp == NULL)
+ return false;
+
+
+ unsigned int id;
+
+ fread(&id, 4, 1, fp);
+
+ if (id != 0x00000010) {
+
+ fclose(fp);
+ return false;
+
+ }
+
+ fread(&coords->flag, 4, 1, fp);
+
+ if (coords->flag.cf) {
+
+ fread(&coords->clutdata, 12, 1, fp);
+ fseek(fp, coords->clutdata.length-12, SEEK_CUR);
+
+ } else {
+
+ memset(&coords->clutdata, 0x00, 12);
+
+ }
+
+ fread(&coords->pixdata, 12, 1, fp);
+
+ fclose(fp);
+
+ return true;
+
+}
+
+unsigned short GetClut(int cx, int cy) {
+
+ unsigned short clut = (cx/16)&0x3f;
+ clut |= (cy&0x1ff)<<6;
+
+ return clut;
+
+}
+
+unsigned short GetTPage(int tp, int abr, int x, int y) {
+
+ unsigned short tpage = (x/64)&0xf; // Set X
+ tpage |= ((y/256)&0x1)<<4; // Set Y
+
+ tpage |= (abr&0x3)<<5; // Set blend mode
+ tpage |= (tp&0x3)<<7; // Set page mode
+ tpage |= 1<<9; // Set dither processing bit
+
+ return tpage;
+
+}