Mercurial > repos > blastem
annotate vgmsplit.c @ 1506:ded16f3d7eb4 mame_interp
Super hacky integration of the version of Musashi from MAME
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 27 Dec 2017 13:46:52 -0800 |
parents | 215b5dabbc20 |
children |
rev | line source |
---|---|
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 /* |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 Copyright 2015 Michael Pavone |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 This file is part of BlastEm. |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 */ |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "ym2612.h" |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "vgm.h" |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <stdint.h> |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <stdio.h> |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <stdlib.h> |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include <string.h> |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #define OUT_CHANNELS 10 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #define DAC_CHANNEL 5 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #define PSG_BASE 6 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #define SAMPLE_THRESHOLD 100 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
18 uint32_t total_delay; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
19 void accum_wait(uint32_t *delays, uint32_t samples) |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
20 { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
21 total_delay += samples; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
22 for (int i = 0; i < OUT_CHANNELS; i++) |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
23 { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
24 delays[i] += samples; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
25 } |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
26 } |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
27 |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
28 void write_wait(uint8_t **out_buffer, uint32_t *delay) |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
29 { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
30 while (*delay >= 65535) |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
31 { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
32 *((*out_buffer)++) = CMD_WAIT; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
33 *((*out_buffer)++) = 0xFF; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
34 *((*out_buffer)++) = 0xFF; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
35 *delay -= 65535; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
36 } |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
37 if (*delay) { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
38 if (*delay == 735) { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
39 *((*out_buffer)++) = CMD_WAIT_60; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
40 } else if (*delay > 735 && *delay <= 751) { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
41 *((*out_buffer)++) = CMD_WAIT_60; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
42 *((*out_buffer)++) = CMD_WAIT_SHORT + *delay - 736; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
43 } else if (*delay == 882) { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
44 *((*out_buffer)++) = CMD_WAIT_50; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
45 } else if (*delay > 882 && *delay <= 898) { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
46 *((*out_buffer)++) = CMD_WAIT_50; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
47 *((*out_buffer)++) = CMD_WAIT_SHORT + *delay - 882; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
48 } else if (*delay <= 16) { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
49 *((*out_buffer)++) = CMD_WAIT_SHORT + *delay - 1; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
50 } else { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
51 *((*out_buffer)++) = CMD_WAIT; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
52 *((*out_buffer)++) = *delay; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
53 *((*out_buffer)++) = *delay >> 8; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
54 } |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
55 *delay = 0; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
56 } |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
57 } |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
58 |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 int main(int argc, char ** argv) |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 data_block *blocks = NULL; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 data_block *seek_block = NULL; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 uint32_t seek_offset; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 uint32_t block_offset; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 FILE * f = fopen(argv[1], "rb"); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 vgm_header header; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 size_t bytes = fread(&header, 1, sizeof(header), f); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 if (bytes != sizeof(header)) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 fputs("Error reading file\n", stderr); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 exit(1); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 if (header.version < 0x150 || !header.data_offset) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 header.data_offset = 0xC; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 fseek(f, header.data_offset + 0x34, SEEK_SET); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 uint32_t data_size = header.eof_offset + 4 - (header.data_offset + 0x34); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 uint8_t * data = malloc(data_size); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 data_size = fread(data, 1, data_size, f); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 fclose(f); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 uint8_t *buffers[OUT_CHANNELS]; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 uint8_t *out_pos[OUT_CHANNELS]; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 uint8_t has_real_data[OUT_CHANNELS]; |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
85 uint32_t delay[OUT_CHANNELS]; |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 buffers[0] = malloc(data_size * OUT_CHANNELS); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 out_pos[0] = buffers[0]; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 has_real_data[0] = 0; |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
90 delay[0] = 0; |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 for (int i = 1; i < OUT_CHANNELS; i++) |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 buffers[i] = buffers[i-1] + data_size; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 out_pos[i] = buffers[i]; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 has_real_data[i] = 0; |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
96 delay[i] = 0; |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 uint8_t * end = data + data_size; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 uint8_t * cur = data; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 uint32_t current_cycle = 0; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 uint8_t psg_latch = 0; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 uint8_t param,reg; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 uint8_t channel; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 uint32_t sample_count = 0; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 uint8_t last_cmd; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 while (cur < end) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 uint8_t cmd = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 switch(cmd) |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 case CMD_PSG_STEREO: |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 //ignore for now |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 cur++; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 case CMD_PSG: |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 param = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 if (param & 0x80) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 psg_latch = param; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 channel = param >> 5 & 3; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 } else { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 channel = psg_latch >> 5 & 3; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 } |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
123 write_wait(out_pos + PSG_BASE+channel, delay + PSG_BASE+channel); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 *(out_pos[PSG_BASE+channel]++) = cmd; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 *(out_pos[PSG_BASE+channel]++) = param; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 has_real_data[PSG_BASE+channel] = 1; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 case CMD_YM2612_0: |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 reg = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 param = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 if (reg < REG_KEY_ONOFF) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 for (int i = 0; i < 6; i++) |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
134 write_wait(out_pos + i, delay + i); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 *(out_pos[i]++) = cmd; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 *(out_pos[i]++) = reg; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 *(out_pos[i]++) = param; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } else if(reg == REG_DAC || reg == REG_DAC_ENABLE) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 if (reg == REG_DAC) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 sample_count++; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 channel = DAC_CHANNEL; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 } else if(reg == REG_KEY_ONOFF) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 channel = param & 7; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 if (channel > 2) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 channel--; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 if (param & 0xF0) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 has_real_data[channel] = 1; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 } else if (reg >= REG_FNUM_LOW_CH3 && reg < REG_ALG_FEEDBACK) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 channel = 2; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 } else { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 channel = 255; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 case CMD_YM2612_1: |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 if (cmd == CMD_YM2612_1) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 reg = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 param = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 channel = 255; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 if (channel >= PSG_BASE) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 if (reg >= REG_DETUNE_MULT && reg < REG_FNUM_LOW) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 channel = (cmd == CMD_YM2612_0 ? 0 : 3) + (reg & 0xC >> 2); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } else if ((reg >= REG_FNUM_LOW && reg < REG_FNUM_LOW_CH3) || (reg >= REG_ALG_FEEDBACK && reg < 0xC0)) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 channel = (cmd == CMD_YM2612_0 ? 0 : 3) + (reg & 0x3); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 } else { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 fprintf(stderr, "WARNING: Skipping nrecognized write to register %X on part %d\n", reg, (cmd == CMD_YM2612_0 ? 1 : 2)); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 if (channel < PSG_BASE) { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
174 write_wait(out_pos + channel, delay + channel); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 *(out_pos[channel]++) = cmd; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 *(out_pos[channel]++) = reg; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 *(out_pos[channel]++) = param; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 case CMD_WAIT: { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
181 uint32_t wait_time = *(cur++); |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
182 wait_time |= *(cur++) << 8; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
183 accum_wait(delay, wait_time); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 case CMD_WAIT_60: |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
187 accum_wait(delay, 735); |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
188 break; |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 case CMD_WAIT_50: |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
190 accum_wait(delay, 882); |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
191 break; |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 case CMD_END: |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 for (int i = 0; i < OUT_CHANNELS; i++) |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
195 write_wait(out_pos + i, delay + i); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 *(out_pos[i]++) = cmd; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 cur = end; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 case CMD_DATA: { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 uint8_t * start = cur - 1; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 cur++; //skip compat command |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 uint8_t data_type = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 uint32_t data_size = *(cur++); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 data_size |= *(cur++) << 8; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 data_size |= *(cur++) << 16; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 data_size |= *(cur++) << 24; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 if (cur + data_size > end) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 data_size = end - cur; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 cur += data_size; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 if (data_type == DATA_YM2612_PCM) { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
213 write_wait(out_pos + DAC_CHANNEL, delay + DAC_CHANNEL); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 memcpy(out_pos[DAC_CHANNEL], start, cur-start); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 out_pos[DAC_CHANNEL] += cur-start; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 } else { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 fprintf(stderr, "WARNING: Skipping data block with unrecognized type %X\n", data_type); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 case CMD_DATA_SEEK: { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
222 write_wait(out_pos + DAC_CHANNEL, delay + DAC_CHANNEL); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 memcpy(out_pos[DAC_CHANNEL], cur-1, 5); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 out_pos[DAC_CHANNEL] += 5; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 cur += 4; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 break; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 default: |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 if (cmd >= CMD_WAIT_SHORT && cmd < (CMD_WAIT_SHORT + 0x10)) { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
231 accum_wait(delay, (cmd & 0xF) + 1); |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
232 } else if (cmd >= CMD_YM2612_DAC && cmd < CMD_DAC_STREAM_SETUP) { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
233 write_wait(out_pos + DAC_CHANNEL, delay + DAC_CHANNEL); |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
234 *(out_pos[DAC_CHANNEL]++) = cmd; |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 for (int i = 0; i < OUT_CHANNELS; i++) |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 { |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
237 if (i != DAC_CHANNEL) |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
238 { |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
239 delay[i] += cmd & 0xF; |
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
240 } |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 sample_count++; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 } else { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 fprintf(stderr, "unimplemented command: %X at offset %X, last valid command was %X\n", cmd, (unsigned int)(cur - data - 1), last_cmd); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 exit(1); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 last_cmd = cmd; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 if (sample_count > SAMPLE_THRESHOLD) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 has_real_data[DAC_CHANNEL] = 1; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 for (int i = 0; i < OUT_CHANNELS; i++) |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 if (has_real_data[i]) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 char fname[11]; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 sprintf(fname, i < PSG_BASE ? "ym_%d.vgm" : "psg_%d.vgm", i < PSG_BASE ? i : i - PSG_BASE); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 f = fopen(fname, "wb"); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 if (!f) { |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 fprintf(stderr, "Failed to open %s for writing\n", fname); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 exit(1); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 data_size = out_pos[i] - buffers[i]; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 header.eof_offset = (header.data_offset + 0x34) + data_size - 4; |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
265 header.gd3_offset = 0; |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 fwrite(&header, 1, sizeof(header), f); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 fseek(f, header.data_offset + 0x34, SEEK_SET); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 fwrite(buffers[i], 1, data_size, f); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 fclose(f); |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 } |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 } |
850
215b5dabbc20
Make vgmsplit smarter about how it handles delays. Force GD3 offset to zero since it is not being copied currently
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
272 printf("total_delay: %d\n", total_delay); |
848
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 return 0; |
7068a9db6dd0
Wrote a buggy tool for splitting VGM files by channel
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 } |