-
Notifications
You must be signed in to change notification settings - Fork 0
/
zxay_dump.c
82 lines (67 loc) · 2.29 KB
/
zxay_dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* AYE ZXAYEMUL metadata editor
* by Chris Young 2021, 2022
* https://www.unsatisfactorysoftware.co.uk
*/
/* ZXAY debug routines */
#include <stdio.h>
#include <stdint.h>
#include "zxay_dump.h"
#include "zxay_file.h"
#include "zxay_misc.h"
static uint32_t offset = 0;
static void dump(uint8_t *structure, size_t size, int type)
{
int i = 0;
int j = 0;
if(size == 0) return;
if(type > 0) printf("[%04x] ", offset);
for(i = 0; i < size; i++) {
printf("%02x ", structure[i]);
if(((type == ZXAY_S_HEADER) && ((i == (PAUTHOR_OFFSET + 1)) || (i == (PMISC_OFFSET + 1)) || (i == (PSONGSSTRUCTURE_OFFSET + 1)))) ||
((type == ZXAY_S_SONG) && ((i == (PSONGNAME_OFFSET + 1)) || (i == (PSONGDATA_OFFSET + 1)))) ||
((type == ZXAY_S_SONGDATA) && ((i == (PPOINTS_OFFSET + 1)) || (i == (PADDRESSES_OFFSET + 1)))) ||
((type == ZXAY_S_BLKS) && (((i - (sizeof(struct zxay_songblks) * j)) == (OFFSET_OFFSET + 1)))) ) {
printf("{%04x} ", zxay_read_int16(structure + i - 1) + (offset + i - 1));
if((type == ZXAY_S_BLKS)) j++;
}
}
if(type == ZXAY_S_TEXT) printf("\n {%s}", structure);
printf("\n");
if(type > 0) offset += size;
}
void zxay_dump_struct(uint8_t *structure, size_t size, int type)
{
if(type == ZXAY_S_NONE) type = ZXAY_S_UNKNOWN;
dump(structure, size, type);
}
void zxay_dump(void *zxayemul, int level)
{
struct zxay_file *zxay = (struct zxay_file *)zxayemul;
int i = 0;
int b = 0;
char *blk = NULL;
printf("Header: ");
dump((char *)zxay->header, sizeof(struct zxay_header), 0);
for(i = 0; i <= zxay->header->NumOfSongs; i++) {
printf("Track %d:\n", i);
printf(" Song struct: ");
dump((char *)(zxay->songsstruct[i]), sizeof(struct zxay_song), 0);
printf(" Song data: ");
dump((char *)zxay->songdata[i], sizeof(struct zxay_songdata), 0);
printf(" Song ptrs: ");
dump((char *)zxay->songptrs[i], sizeof(struct zxay_songptrs), 0);
printf(" Song blks:\n");
blk = (char *)zxay->songblks[i];
for(b = 0; b < (zxay->songblkcount[i]); b++) {
printf(" Block %d: ", b);
dump(blk, sizeof(struct zxay_songblks), 0);
blk += sizeof(struct zxay_songblks);
if(level > 2) {
printf(" Data: ");
if(zxay->datablocks[i]->len[b] != 0) {
dump((char *)zxay->datablocks[i]->data[b], zxay->datablocks[i]->len[b], 0);
}
}
}
}
}