mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 07:35:45 +01:00
add function for computing the bytesize of the *.mcX file
This commit is contained in:
@@ -28,6 +28,15 @@ void mcx_delchunk(u8 *restrict buf, int chunk) {
|
|||||||
memmove(head, tail, blen);
|
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
|
/* an `*.mcX` contains a `0x2000` byte long table, the first `0x1000` containing
|
||||||
* `0x400` entries of chunk data.
|
* `0x400` entries of chunk data.
|
||||||
* This chunk data is big-endian, where bytes `0xFFFFFF00` represent the `0x1000` sector offset.
|
* This chunk data is big-endian, where bytes `0xFFFFFF00` represent the `0x1000` sector offset.
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ struct mcx_chunk {
|
|||||||
/* Deletes chunk `idx` from `buf`, moving all chunks downwards in the process. */
|
/* Deletes chunk `idx` from `buf`, moving all chunks downwards in the process. */
|
||||||
void mcx_delchunk(u8 *restrict buf, int idx);
|
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` */
|
/* 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));
|
void mcx_index(const u8 *restrict buf, struct mcx_chunk *restrict chunks) NONNULL((1, 2));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user