2021-11-30 23:29:09 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "spec.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct Segment* g_segments;
|
|
|
|
int g_segmentsCount;
|
|
|
|
|
|
|
|
static void write_dmadata_table(FILE *fout)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2024-02-03 22:59:19 +00:00
|
|
|
for (i = 0; i < g_segmentsCount; i++) {
|
|
|
|
// Don't emit dma entry for segments set with NOLOAD
|
|
|
|
if (g_segments[i].flags & FLAG_NOLOAD) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:51:03 +00:00
|
|
|
fprintf(fout, "DEFINE_DMA_ENTRY(%s, \"%s\")\n", g_segments[i].name, g_segments[i].name);
|
2024-02-03 22:59:19 +00:00
|
|
|
}
|
2021-11-30 23:29:09 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 18:00:10 +00:00
|
|
|
static void write_compress_ranges(FILE *fout)
|
|
|
|
{
|
|
|
|
int i;
|
2024-02-03 22:59:19 +00:00
|
|
|
int rom_index = 0;
|
2024-01-24 18:00:10 +00:00
|
|
|
bool continue_list = false;
|
|
|
|
int stride_first = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < g_segmentsCount; i++) {
|
2024-02-03 22:59:19 +00:00
|
|
|
bool compress = g_segments[i].compress;
|
|
|
|
|
|
|
|
// Don't consider segments set with NOLOAD when calculating indices
|
|
|
|
if (g_segments[i].flags & FLAG_NOLOAD) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compress) {
|
2024-01-24 18:00:10 +00:00
|
|
|
if (stride_first == -1)
|
2024-02-03 22:59:19 +00:00
|
|
|
stride_first = rom_index;
|
2024-01-24 18:00:10 +00:00
|
|
|
}
|
2024-02-03 22:59:19 +00:00
|
|
|
if (!compress || i == g_segmentsCount - 1) {
|
2024-01-24 18:00:10 +00:00
|
|
|
if (stride_first != -1) {
|
2024-02-03 22:59:19 +00:00
|
|
|
int stride_last = compress ? rom_index : rom_index - 1;
|
2024-01-24 18:00:10 +00:00
|
|
|
if (continue_list) {
|
|
|
|
fprintf(fout, ",");
|
|
|
|
}
|
|
|
|
if (stride_first == stride_last) {
|
|
|
|
fprintf(fout, "%d", stride_first);
|
|
|
|
} else {
|
|
|
|
fprintf(fout, "%d-%d", stride_first, stride_last);
|
|
|
|
}
|
|
|
|
continue_list = true;
|
|
|
|
stride_first = -1;
|
|
|
|
}
|
|
|
|
}
|
2024-02-03 22:59:19 +00:00
|
|
|
|
|
|
|
rom_index++;
|
2024-01-24 18:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 23:29:09 +00:00
|
|
|
static void usage(const char *execname)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "zelda64 dmadata generation tool v0.01\n"
|
2024-01-24 18:00:10 +00:00
|
|
|
"usage: %s SPEC_FILE DMADATA_TABLE COMPRESS_RANGES\n"
|
2021-11-30 23:29:09 +00:00
|
|
|
"SPEC_FILE file describing the organization of object files into segments\n"
|
2024-01-24 18:34:34 +00:00
|
|
|
"DMADATA_TABLE filename of output dmadata table header\n"
|
2024-01-24 18:00:10 +00:00
|
|
|
"COMPRESS_RANGES filename to write which files are compressed (e.g. 0-5,7,10-20)\n",
|
2021-11-30 23:29:09 +00:00
|
|
|
execname);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
FILE *dmaout;
|
2024-01-24 18:00:10 +00:00
|
|
|
FILE *compress_ranges_out;
|
2021-11-30 23:29:09 +00:00
|
|
|
void *spec;
|
|
|
|
size_t size;
|
2022-01-23 23:09:02 +00:00
|
|
|
|
2024-01-24 18:00:10 +00:00
|
|
|
if (argc != 4)
|
2021-11-30 23:29:09 +00:00
|
|
|
{
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
spec = util_read_whole_file(argv[1], &size);
|
|
|
|
parse_rom_spec(spec, &g_segments, &g_segmentsCount);
|
|
|
|
|
|
|
|
dmaout = fopen(argv[2], "w");
|
|
|
|
if (dmaout == NULL)
|
|
|
|
util_fatal_error("failed to open file '%s' for writing", argv[2]);
|
|
|
|
write_dmadata_table(dmaout);
|
|
|
|
fclose(dmaout);
|
2024-01-24 18:00:10 +00:00
|
|
|
|
|
|
|
compress_ranges_out = fopen(argv[3], "w");
|
|
|
|
if (compress_ranges_out == NULL)
|
|
|
|
util_fatal_error("failed to open file '%s' for writing", argv[3]);
|
|
|
|
write_compress_ranges(compress_ranges_out);
|
|
|
|
fclose(compress_ranges_out);
|
|
|
|
|
2022-02-06 19:40:26 +00:00
|
|
|
free_rom_spec(g_segments, g_segmentsCount);
|
2021-11-30 23:29:09 +00:00
|
|
|
free(spec);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|