add function for computing the bytesize of the *.mcX file

This commit is contained in:
2025-08-27 10:08:18 +02:00
parent 7a45724de7
commit b7859d56d9
2 changed files with 12 additions and 0 deletions

View File

@@ -28,6 +28,15 @@ void mcx_delchunk(u8 *restrict buf, int chunk) {
memmove(head, tail, blen);
}
/* Sum together the 4th byte in each location integer to compute the sector size of all chunks.
* Multiplying by `0x1000`, and adding the size of the table itself. */
size_t mcx_calcsize(const u8 *restrict buf) {
size_t size = 0;
for (uint i = 0; i < 0x400; i++)
size += *(buf + (i * 4) + 3);
return (size * 0x1000) + 0x2000;
}
/* an `*.mcX` contains a `0x2000` byte long table, the first `0x1000` containing
* `0x400` entries of chunk data.
* This chunk data is big-endian, where bytes `0xFFFFFF00` represent the `0x1000` sector offset.

View File

@@ -18,6 +18,9 @@ struct mcx_chunk {
/* Deletes chunk `idx` from `buf`, moving all chunks downwards in the process. */
void mcx_delchunk(u8 *restrict buf, int idx);
/* Computes the byte size of the `*.mcX` file in `buf` and returns it. */
size_t mcx_calcsize(const u8 *restrict buf) NONNULL((1)) PURE;
/* indexes the chunks in an `*.mcX` file, writing `0x400` of entries to `chunks` */
void mcx_index(const u8 *restrict buf, struct mcx_chunk *restrict chunks) NONNULL((1, 2));