-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.c
171 lines (158 loc) · 4.58 KB
/
main.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/****************************************************
*Part of SPC2IT, read readme.md for more information*
****************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include "sound.h"
#include "it.h"
#include "emu.h"
#include "sneese_spc.h"
#ifdef _WIN32
#undef realpath
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#endif
int main(int argc, char **argv)
{
size_t u8Size = sizeof(u8);
if (!(u8Size == 1))
printf("Warning: wrong size u8: %zu \n", u8Size);
size_t u16Size = sizeof(u16);
if (!(u16Size == 2))
printf("Warning: wrong size u16: %zu \n", u16Size);
size_t u32Size = sizeof(u32);
if (!(u32Size == 4))
printf("Warning: wrong size u32: %zu \n", u32Size);
size_t u64Size = sizeof(u64);
if (!(u64Size == 8))
printf("Warning: wrong size u64: %zu \n", u64Size);
size_t s8Size = sizeof(s8);
if (!(s8Size == 1))
printf("Warning: wrong size s8: %zu \n", s8Size);
size_t s16Size = sizeof(s16);
if (!(s16Size == 2))
printf("Warning: wrong size s16: %zu \n", s16Size);
size_t s32Size = sizeof(s32);
if (!(s32Size == 4))
printf("Warning: wrong size s32: %zu \n", s32Size);
size_t s64Size = sizeof(s64);
if (!(s64Size == 8))
printf("Warning: wrong size s64: %zu \n", s64Size);
size_t ITFileHeaderSize = sizeof(ITFileHeader);
if (!(ITFileHeaderSize == 192))
printf("Warning: wrong size ITFileHeader: %zu \n", ITFileHeaderSize);
size_t ITFileSampleSize = sizeof(ITFileSample);
if (!(ITFileSampleSize == 80))
printf("Warning: wrong size ITFileSample: %zu \n", ITFileSampleSize);
size_t ITFilePatternSize = sizeof(ITFilePattern);
if (!(ITFilePatternSize == 8))
printf("Warning: wrong size ITFilePattern: %zu \n", ITFilePatternSize);
size_t SPCFileSize = sizeof(SPCFile);
if (!(SPCFileSize == 65920))
printf("Warning: wrong size SPCFile: %zu \n", SPCFileSize);
s32 seconds, limit, ITrows;
char fn[PATH_MAX];
s32 i;
fn[0] = 0;
ITrows = 200; // Default 200 IT rows/pattern
limit = 0; // Will be set later
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
switch (argv[i][1])
{
case 'r':
i++;
ITrows = atoi(argv[i]);
break;
case 't':
i++;
limit = atoi(argv[i]);
break;
default:
printf("Warning: unrecognized option '-%c'\n", argv[i][1]);
}
else
realpath(argv[i], fn);
}
if (fn[0] == 0)
{
printf(" SPC2IT - converts SPC700 sound files to the Impulse Tracker format\n\n");
printf(" Usage: spc2it [options] <filename>\n");
printf(" Where <filename> is any .spc or .sp# file\n\n");
printf(" Options: ");
printf("-t x Specify a time limit in seconds [60 default]\n");
printf(" -d xxxxxxxx Voices to disable (1-8) [none default]\n");
printf(" -r xxx Specify IT rows per pattern [200 default]\n");
exit(0);
}
printf("\n");
printf("Filepath: %s\n", fn);
if (ITStart(ITrows))
{
printf("Error: failed to initialize pattern buffers\n");
exit(1);
}
if (SPCInit(fn)) // Reset SPC and load state
{
printf("Error: failed to initialize emulation\n");
exit(1);
}
if (SNDInit())
{
printf("Error: failed to initialize sound\n");
exit(1);
}
if ((!limit) && (SPCtime))
limit = SPCtime;
else if (!limit)
limit = 60;
printf("Time (seconds): %i\n", limit);
printf("IT Parameters:\n");
printf(" Rows/pattern: %d\n", ITrows);
printf("ID info:\n");
printf(" Song: %s\n", SPCInfo->SongTitle);
printf(" Game: %s\n", SPCInfo->GameTitle);
printf(" Dumper: %s\n", SPCInfo->DumperName);
printf(" Comments: %s\n", SPCInfo->Comment);
printf(" Created on: %s\n", SPCInfo->Date);
printf("\n");
fflush(stdout);
SNDNoteOn(SPC_DSP[0x4c]);
seconds = SNDratecnt = 0;
while (true)
{
ITMix();
if (ITUpdate())
break;
SNDratecnt += 1;
SPC_START(2048000 / (SPCUpdateRate * 2)); // emulate the SPC700
if (SNDratecnt >= SPCUpdateRate)
{
SNDratecnt -= SPCUpdateRate;
seconds++; // count number of seconds
printf("Progress: %f%%\r", (((f64)seconds / limit) * 100));
fflush(stdout);
if (seconds == limit)
break;
}
}
printf("\n\nSaving file...\n");
for (i = 0; i < PATH_MAX; i++)
if (fn[i] == 0)
break;
for (; i > 0; i--)
if (fn[i] == '.')
{
strcpy(&fn[i + 1], "it");
break;
}
if (ITWrite(fn))
printf("Error: failed to write %s.\n", fn);
else
printf("Wrote to %s successfully.\n", fn);
Reset_SPC();
return 0;
}