summaryrefslogtreecommitdiff
path: root/csrc/mkf
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-10-01 21:38:19 +0800
committerIru Cai <mytbk920423@gmail.com>2018-10-01 21:38:19 +0800
commit6736d6764ba2541eeaa48b45b002acadb20b9b05 (patch)
tree61a6814db04e2550379e1fbbfd5e4a419c682af9 /csrc/mkf
parent63d7007905047e5f488e179a56d861dfaa17aa90 (diff)
downloadrich4-6736d6764ba2541eeaa48b45b002acadb20b9b05.tar.xz
mkf uses graph_st
Diffstat (limited to 'csrc/mkf')
-rw-r--r--csrc/mkf/graph_struct.c46
-rw-r--r--csrc/mkf/graph_struct.h19
-rw-r--r--csrc/mkf/mkf.c30
-rw-r--r--csrc/mkf/mkf.h10
4 files changed, 79 insertions, 26 deletions
diff --git a/csrc/mkf/graph_struct.c b/csrc/mkf/graph_struct.c
new file mode 100644
index 0000000..52aa207
--- /dev/null
+++ b/csrc/mkf/graph_struct.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 Iru Cai <mytbk920423@gmail.com>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "graph_struct.h"
+
+static inline void mem_copy_words(void *dst, void *src, size_t n)
+{
+ memcpy(dst, src, n*2);
+}
+
+struct graph_st * allocate_graph_st(int w, int h, int x, int y)
+{
+ struct graph_st * newst = (struct graph_st *)malloc(w * h * 2 + sizeof(graph_st));
+ newst->width = w;
+ newst->height = h;
+ newst->x = x;
+ newst->y = y;
+ newst->gdata = newst->data;
+ return newst;
+}
+
+/* crop graph a1 starting at (x, y) as laft-top coordinate,
+ * and get graph a2 with size w*h.
+ *
+ * this function looks buggy and can crash the game */
+
+struct graph_st * crop_graph(struct graph_st *a1, struct graph_st *a2, int x, int y, int w, int h)
+{
+ if (a2 == NULL) {
+ a2 = allocate_graph_st(w, h, 0, 0);
+ }
+
+ int16_t *src = &a1->gdata[a1->width * y + x];
+ int16_t *dst = a2->gdata;
+
+ for (int i = 0; i < h; i++) {
+ mem_copy_words(esi, ebx, w);
+ dst = dst + w;
+ src = src + a1->width;
+ }
+ return a2;
+}
diff --git a/csrc/mkf/graph_struct.h b/csrc/mkf/graph_struct.h
new file mode 100644
index 0000000..4859508
--- /dev/null
+++ b/csrc/mkf/graph_struct.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2018 Iru Cai <mytbk920423@gmail.com>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <stdint.h>
+
+struct graph_st
+{
+ int16_t width;
+ int16_t height;
+ int16_t x;
+ int16_t y;
+ int16_t * gdata;
+ int16_t data[0];
+};
+
+struct graph_st * allocate_graph_st(int w, int h, int x, int y);
+struct graph_st * crop_graph(struct graph_st *a1, struct graph_st *a2, int x, int y, int w, int h);
diff --git a/csrc/mkf/mkf.c b/csrc/mkf/mkf.c
index 63e7e2d..9a7e5aa 100644
--- a/csrc/mkf/mkf.c
+++ b/csrc/mkf/mkf.c
@@ -72,28 +72,22 @@ void unload_mkf(int mkf_idx)
static void update_spr_smp_ptr(void *s)
{
struct spr_smp *sst = (struct spr_smp*)s;
- int lastsz;
+ size_t lastsz;
if (strcmp(sst->sig, "SPR") == 0) {
- lastsz = sst->chunk_tab[0].chunk_sz;
- sst->chunk_tab[0].chunk_sz = (int32_t)s + sst->start_offset + 0x200;
-
- for (int i = 1; i < sst->nchunk; i++) {
- int t = sst->chunk_tab[i].chunk_sz;
- sst->chunk_tab[i].chunk_sz = lastsz + sst->chunk_tab[i-1].chunk_sz;
- lastsz = t;
- }
+ lastsz = (size_t)(sst->chunk_tab[0].gdata);
+ sst->chunk_tab[0].gdata = (int16_t*)(s + sst->start_offset + 0x200);
+ } else if (strcmp(sst->sig, "SMP") == 0) {
+ lastsz = (size_t)(sst->chunk_tab[0].gdata);
+ sst->chunk_tab[0].gdata = (int16_t*)(s + sst->start_offset);
+ } else {
+ return;
}
- if (strcmp(sst->sig, "SMP") == 0) {
- lastsz = sst->chunk_tab[0].chunk_sz;
- sst->chunk_tab[0].chunk_sz = (int32_t)s + sst->start_offset;
-
- for (int i = 1; i < sst->nchunk; i++) {
- int t = sst->chunk_tab[i].chunk_sz;
- sst->chunk_tab[i].chunk_sz = lastsz + sst->chunk_tab[i-1].chunk_sz;
- lastsz = t;
- }
+ for (int i = 1; i < sst->nchunk; i++) {
+ size_t t = (size_t)(sst->chunk_tab[i].gdata);
+ sst->chunk_tab[i].gdata = (int16_t*)((void*)(sst->chunk_tab[i-1].gdata) + lastsz);
+ lastsz = t;
}
}
diff --git a/csrc/mkf/mkf.h b/csrc/mkf/mkf.h
index ef1fa38..f42d709 100644
--- a/csrc/mkf/mkf.h
+++ b/csrc/mkf/mkf.h
@@ -1,4 +1,5 @@
#include <stdint.h>
+#include "graph_struct.h"
int load_mkf(const char *fn);
void unload_mkf(int mkf_idx);
@@ -11,12 +12,5 @@ struct spr_smp
char sig[4]; /* "SPR" or "SMP" */
int32_t nchunk;
int32_t start_offset;
- int32_t t3, t4; /* unused? */
- struct {
- /* in the file, it's the chunk size,
- * after read_mkf(), it becomes the start address */
- int32_t chunk_sz;
- int32_t v2, v3; /* unused? */
- } chunk_tab[0];
+ struct graph_st chunk_tab[0];
};
-