Binary script with a separate text table file. A lot like 2XT-PJADV, so similar it might even be a successor.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4
5 #include <deque>
6
7 void fread_or_die(void * a, size_t b, int c, FILE * d)
8 {
9 int got = fread(a, b, c, d);
10 if(feof(d)) {puts("feof"); exit(0);}
11 if(ferror(d)) {puts("ferror"); exit(0);}
12 if(got != c) {exit(0);}
13 }
14
15 int main()
16 {
17 auto fs = fopen("SCRIPT.SRC", "rb");
18 auto ft = fopen("TEXT.DAT", "rb");
19 auto fo = fopen("script.txt", "wb");
20
21 fseek(fs, 12, SEEK_SET);
22
23 std::deque<uint32_t> stack;
24
25 while(!feof(fs) and !ferror(fs))
26 {
27
28 uint32_t command;
29 fread_or_die(&command, 4, 1, fs);
30 if(command != 0x0001001F and command != 0x00010017)
31 {
32 //fprintf(fo, "skipping %08X at %08X\n", command, ftell(fs)-4);
33 continue;
34 }
35 if(command == 0x0001001F)
36 {
37 uint32_t value;
38 fread_or_die(&value, 4, 1, fs);
39 //fprintf(fo, "pushing %08X at %08X\n", value, ftell(fs)-4);
40 stack.push_front(value);
41 }
42 if(command == 0x00010017)
43 {
44 uint32_t value;
45 fread_or_die(&value, 4, 1, fs);
46 if(value == 0x00020002 || value == 0x0002000F)
47 {
48 stack.pop_front();
49 stack.pop_front();
50 uint32_t addr = stack.front()+4;
51 stack.clear();
52 fseek(ft, addr, SEEK_SET);
53 int c = fgetc(ft);
54 //fprintf(fo, "%08X\n", value);
55 //fprintf(fo, "%08X\n", addr-4);
56 //fprintf(fo, "%08X\n", ftell(fs));
57 while(c > 0)
58 {
59 fputc(c, fo);
60 c = fgetc(ft);
61 }
62 fputc('\n', fo);
63 }
64 else
65 {
66 //fprintf(fo, "%08X\n", value);
67 }
68 }
69 }
70 }