annotate vgmplay.c @ 905:b3b399665356

Don't try setting the window title on Android
author Michael Pavone <pavone@retrodev.com>
date Sat, 28 Nov 2015 14:49:34 -0800
parents 12b1a8a32306
children 126c0294c1e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 466
diff changeset
1 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 466
diff changeset
2 Copyright 2013 Michael Pavone
505
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
3 This file is part of BlastEm.
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 466
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.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 466
diff changeset
5 */
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "render.h"
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include "ym2612.h"
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "psg.h"
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
9 #include "config.h"
793
9aff36a172b2 Fix missing includes of util.h
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
10 #include "util.h"
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 #include <stdint.h>
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 #include <stdio.h>
805
3eced113081c Pre-release cleanup
Michael Pavone <pavone@retrodev.com>
parents: 793
diff changeset
13 #include <stdlib.h>
3eced113081c Pre-release cleanup
Michael Pavone <pavone@retrodev.com>
parents: 793
diff changeset
14 #include <string.h>
890
12b1a8a32306 Fix so vgmplay builds again
Michael Pavone <pavone@retrodev.com>
parents: 848
diff changeset
15 #include "vgm.h"
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 #define MCLKS_NTSC 53693175
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 #define MCLKS_PAL 53203395
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 #define MCLKS_PER_68K 7
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 #define MCLKS_PER_YM MCLKS_PER_68K
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22 #define MCLKS_PER_Z80 15
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16)
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 void handle_keydown(int keycode)
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 {
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 void handle_keyup(int keycode)
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 {
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
33 void handle_joydown(int joystick, int button)
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
34 {
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
35 }
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
36
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
37 void handle_joyup(int joystick, int button)
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
38 {
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
39 }
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
40
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
41 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value)
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
42 {
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
43 }
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
44
551
16ee0937c676 Fix type mismatch on headless global that was causing a crash in the vgm player on ARM
Michael Pavone <pavone@retrodev.com>
parents: 514
diff changeset
45 int headless = 0;
505
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
46
409
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 408
diff changeset
47 #define CYCLE_LIMIT MCLKS_NTSC/60
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
48 #define MAX_SOUND_CYCLES 100000
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
49 tern_node * config;
409
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 408
diff changeset
50
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
51 void vgm_wait(ym2612_context * y_context, psg_context * p_context, uint32_t * current_cycle, uint32_t cycles)
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 {
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
53 while (cycles > MAX_SOUND_CYCLES)
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
54 {
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
55 vgm_wait(y_context, p_context, current_cycle, MAX_SOUND_CYCLES);
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
56 cycles -= MAX_SOUND_CYCLES;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
57 }
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 *current_cycle += cycles;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 psg_run(p_context, *current_cycle);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 ym_run(y_context, *current_cycle);
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
61
409
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 408
diff changeset
62 if (*current_cycle > CYCLE_LIMIT) {
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 408
diff changeset
63 *current_cycle -= CYCLE_LIMIT;
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 408
diff changeset
64 p_context->cycles -= CYCLE_LIMIT;
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 408
diff changeset
65 y_context->current_cycle -= CYCLE_LIMIT;
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 408
diff changeset
66 process_events();
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 int main(int argc, char ** argv)
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 {
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
72 set_exe_str(argv[0]);
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
73 data_block *blocks = NULL;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
74 data_block *seek_block = NULL;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
75 uint32_t seek_offset;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
76 uint32_t block_offset;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
77
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78 uint32_t fps = 60;
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
79 config = load_config(argv[0]);
719
019d27995e32 Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents: 551
diff changeset
80 render_init(320, 240, "vgm play", 60, 0);
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
81
514
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
82 uint32_t opts = 0;
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
83 if (argc >= 3 && !strcmp(argv[2], "-y")) {
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
84 opts |= YM_OPT_WAVE_LOG;
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
85 }
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
86
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 ym2612_context y_context;
514
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
88 ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), opts);
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
89
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 psg_context p_context;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer());
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
92
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 FILE * f = fopen(argv[1], "rb");
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
94 vgm_header header;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 fread(&header, sizeof(header), 1, f);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
96 if (header.version < 0x150 || !header.data_offset) {
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 header.data_offset = 0xC;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 fseek(f, header.data_offset + 0x34, SEEK_SET);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 uint32_t data_size = header.eof_offset + 4 - (header.data_offset + 0x34);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 uint8_t * data = malloc(data_size);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 fread(data, 1, data_size, f);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 fclose(f);
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
104
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 uint32_t mclks_sample = MCLKS_NTSC / 44100;
514
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
106 uint32_t loop_count = 2;
466
bc9e0829ffc7 Fix vgmplay
Mike Pavone <pavone@retrodev.com>
parents: 409
diff changeset
107
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 uint8_t * end = data + data_size;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 uint8_t * cur = data;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 uint32_t current_cycle = 0;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 while (cur < end) {
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 uint8_t cmd = *(cur++);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 switch(cmd)
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 {
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 case CMD_PSG_STEREO:
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 //ignore for now
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 cur++;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 break;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 case CMD_PSG:
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 psg_write(&p_context, *(cur++));
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 break;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 case CMD_YM2612_0:
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 ym_address_write_part1(&y_context, *(cur++));
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 ym_data_write(&y_context, *(cur++));
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
125 break;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 case CMD_YM2612_1:
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 ym_address_write_part2(&y_context, *(cur++));
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 ym_data_write(&y_context, *(cur++));
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 break;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 case CMD_WAIT: {
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131 uint32_t wait_time = *(cur++);
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 wait_time |= *(cur++) << 8;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 wait_time *= mclks_sample;
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
134 vgm_wait(&y_context, &p_context, &current_cycle, wait_time);
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135 break;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 case CMD_WAIT_60:
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
138 vgm_wait(&y_context, &p_context, &current_cycle, 735 * mclks_sample);
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 break;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 case CMD_WAIT_50:
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
141 vgm_wait(&y_context, &p_context, &current_cycle, 882 * mclks_sample);
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 break;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 case CMD_END:
514
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
144 if (header.loop_offset && --loop_count) {
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
145 cur = data + header.loop_offset + 0x1C - (header.data_offset + 0x34);
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
146 } else {
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
147 //TODO: fade out
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
148 return 0;
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
149 }
f66c78cbdcaa Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents: 512
diff changeset
150 break;
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
151 case CMD_DATA: {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
152 cur++; //skip compat command
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
153 uint8_t data_type = *(cur++);
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
154 uint32_t data_size = *(cur++);
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
155 data_size |= *(cur++) << 8;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
156 data_size |= *(cur++) << 16;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
157 data_size |= *(cur++) << 24;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
158 if (data_type == DATA_YM2612_PCM) {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
159 data_block ** curblock = &blocks;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
160 while(*curblock)
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
161 {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
162 curblock = &((*curblock)->next);
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
163 }
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
164 *curblock = malloc(sizeof(data_block));
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
165 (*curblock)->size = data_size;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
166 (*curblock)->type = data_type;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
167 (*curblock)->data = cur;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
168 (*curblock)->next = NULL;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
169 } else {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
170 fprintf(stderr, "Skipping data block with unrecognized type %X\n", data_type);
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
171 }
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
172 cur += data_size;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
173 break;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
174 }
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
175 case CMD_DATA_SEEK: {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
176 uint32_t new_offset = *(cur++);
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
177 new_offset |= *(cur++) << 8;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
178 new_offset |= *(cur++) << 16;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
179 new_offset |= *(cur++) << 24;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
180 if (!seek_block || new_offset < seek_offset) {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
181 seek_block = blocks;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
182 seek_offset = 0;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
183 block_offset = 0;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
184 }
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
185 while (seek_block && (seek_offset - block_offset + seek_block->size) < new_offset)
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
186 {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
187 seek_offset += seek_block->size - block_offset;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
188 seek_block = seek_block->next;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
189 block_offset = 0;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
190 }
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
191 block_offset += new_offset-seek_offset;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
192 seek_offset = new_offset;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
193 break;
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
194 }
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
195
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 default:
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 if (cmd >= CMD_WAIT_SHORT && cmd < (CMD_WAIT_SHORT + 0x10)) {
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 uint32_t wait_time = (cmd & 0xF) + 1;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 wait_time *= mclks_sample;
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
200 vgm_wait(&y_context, &p_context, &current_cycle, wait_time);
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
201 } else if (cmd >= CMD_YM2612_DAC && cmd < CMD_DAC_STREAM_SETUP) {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
202 if (seek_block) {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
203 ym_address_write_part1(&y_context, 0x2A);
512
6800d30437c9 Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents: 511
diff changeset
204 ym_data_write(&y_context, seek_block->data[block_offset++]);
6800d30437c9 Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents: 511
diff changeset
205 seek_offset++;
6800d30437c9 Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents: 511
diff changeset
206 if (block_offset > seek_block->size) {
6800d30437c9 Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents: 511
diff changeset
207 seek_block = seek_block->next;
6800d30437c9 Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents: 511
diff changeset
208 block_offset = 0;
6800d30437c9 Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents: 511
diff changeset
209 }
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
210 } else {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
211 fputs("Encountered DAC write command but data seek pointer is invalid!\n", stderr);
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
212 }
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
213 uint32_t wait_time = (cmd & 0xF);
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
214 if (wait_time)
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
215 {
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
216 wait_time *= mclks_sample;
812
574495372d1c Finish OS X support in build_release script. Fix a name conflict in vgmplay on OS X. Call set_exe_str in vgmplay and stateview
Michael Pavone <pavone@retrodev.com>
parents: 805
diff changeset
217 vgm_wait(&y_context, &p_context, &current_cycle, wait_time);
511
2c1679058727 Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
218 }
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
219 } else {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 719
diff changeset
220 fatal_error("unimplemented command: %X at offset %X\n", cmd, (unsigned int)(cur - data - 1));
408
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
221 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
222 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
223 }
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
224 return 0;
a13a83934ba3 Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
225 }