Mercurial > repos > blastem
annotate vgmplay.c @ 2055:c4d066d798c4 segacd
Fix prog RAM banking and Genesis to SCD cycle conversion. Arkagis Escape demo now works
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 18 Jan 2022 23:54:02 -0800 |
parents | 460e14497120 |
children | cfd53c94fffb |
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 | 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 | 13 #include <stdlib.h> |
14 #include <string.h> | |
890
12b1a8a32306
Fix so vgmplay builds again
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
15 #include "vgm.h" |
1944 | 16 #include "system.h" |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 #define MCLKS_NTSC 53693175 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #define MCLKS_PAL 53203395 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 #define MCLKS_PER_68K 7 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 #define MCLKS_PER_YM MCLKS_PER_68K |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 #define MCLKS_PER_Z80 15 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
26 |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
27 #ifdef DISABLE_ZLIB |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
28 #define VGMFILE FILE* |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
29 #define vgmopen fopen |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
30 #define vgmread fread |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
31 #define vgmseek fseek |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
32 #define vgmgetc fgetc |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
33 #define vgmclose fclose |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
34 #else |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
35 #include "zlib/zlib.h" |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
36 #define VGMFILE gzFile |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
37 #define vgmopen gzopen |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
38 #define vgmread gzfread |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
39 #define vgmseek gzseek |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
40 #define vgmgetc gzgetc |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
41 #define vgmclose gzclose |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
42 #endif |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
43 |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
44 |
1944 | 45 system_header *current_system; |
46 | |
1985 | 47 void system_request_exit(system_header *system, uint8_t force_release) |
48 { | |
49 } | |
50 | |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 void handle_keydown(int keycode) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 void handle_keyup(int keycode) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 |
466 | 59 void handle_joydown(int joystick, int button) |
60 { | |
61 } | |
62 | |
63 void handle_joyup(int joystick, int button) | |
64 { | |
65 } | |
66 | |
67 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value) | |
68 { | |
69 } | |
70 | |
1210
c95893007a83
Fix vgmplay and stateview targets
Michael Pavone <pavone@retrodev.com>
parents:
1196
diff
changeset
|
71 void handle_joy_axis(int joystick, int axis, int16_t value) |
c95893007a83
Fix vgmplay and stateview targets
Michael Pavone <pavone@retrodev.com>
parents:
1196
diff
changeset
|
72 { |
c95893007a83
Fix vgmplay and stateview targets
Michael Pavone <pavone@retrodev.com>
parents:
1196
diff
changeset
|
73 } |
c95893007a83
Fix vgmplay and stateview targets
Michael Pavone <pavone@retrodev.com>
parents:
1196
diff
changeset
|
74 |
1196
74e77aec9004
Fix stateview and vgmplay targets
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
75 void handle_joy_added(int joystick) |
74e77aec9004
Fix stateview and vgmplay targets
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
76 { |
74e77aec9004
Fix stateview and vgmplay targets
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
77 } |
74e77aec9004
Fix stateview and vgmplay targets
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
78 |
931
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
79 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay) |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
80 { |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
81 } |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
82 |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
83 void handle_mousedown(int mouse, int button) |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
84 { |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
85 } |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
86 |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
87 void handle_mouseup(int mouse, int button) |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
88 { |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
89 } |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
90 |
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
|
91 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
|
92 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
93 #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
|
94 #define MAX_SOUND_CYCLES 100000 |
466 | 95 tern_node * config; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
96 |
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
|
97 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
|
98 { |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
99 while (cycles > MAX_SOUND_CYCLES) |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
100 { |
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
|
101 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
|
102 cycles -= MAX_SOUND_CYCLES; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
103 } |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 *current_cycle += cycles; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 psg_run(p_context, *current_cycle); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 ym_run(y_context, *current_cycle); |
466 | 107 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
108 if (*current_cycle > CYCLE_LIMIT) { |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
109 *current_cycle -= CYCLE_LIMIT; |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
110 p_context->cycles -= CYCLE_LIMIT; |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
111 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
|
112 process_events(); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 } |
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 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 int main(int argc, char ** argv) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 { |
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
|
118 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
|
119 data_block *blocks = NULL; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
120 data_block *seek_block = NULL; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
121 uint32_t seek_offset; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
122 uint32_t block_offset; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
123 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 uint32_t fps = 60; |
466 | 125 config = load_config(argv[0]); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
126 render_init(320, 240, "vgm play", 0); |
466 | 127 |
514
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 } |
1002
8d032a368dd5
Made low pass filter frequency configurable
Michael Pavone <pavone@retrodev.com>
parents:
931
diff
changeset
|
132 |
1327
57637d17b59e
Fix vgmplay target for ternary tree changes
Michael Pavone <pavone@retrodev.com>
parents:
1210
diff
changeset
|
133 char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0", TVAL_PTR).ptrval; |
1002
8d032a368dd5
Made low pass filter frequency configurable
Michael Pavone <pavone@retrodev.com>
parents:
931
diff
changeset
|
134 uint32_t lowpass_cutoff = lowpass_cutoff_str ? atoi(lowpass_cutoff_str) : 3390; |
466 | 135 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 ym2612_context y_context; |
1558 | 137 ym_init(&y_context, MCLKS_NTSC, MCLKS_PER_YM, opts); |
466 | 138 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 psg_context p_context; |
1558 | 140 psg_init(&p_context, MCLKS_NTSC, MCLKS_PER_PSG); |
466 | 141 |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
142 VGMFILE * f = vgmopen(argv[1], "rb"); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 vgm_header header; |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
144 vgmread(&header, sizeof(header), 1, f); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 if (header.version < 0x150 || !header.data_offset) { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 header.data_offset = 0xC; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 } |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
148 vgmseek(f, header.data_offset + 0x34, SEEK_SET); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 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
|
150 uint8_t * data = malloc(data_size); |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
151 vgmread(data, 1, data_size, f); |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
152 vgmclose(f); |
466 | 153 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 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
|
155 uint32_t loop_count = 2; |
466 | 156 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 uint8_t * end = data + data_size; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 uint8_t * cur = data; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 uint32_t current_cycle = 0; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 while (cur < end) { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 uint8_t cmd = *(cur++); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 switch(cmd) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 case CMD_PSG_STEREO: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 //ignore for now |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 cur++; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 case CMD_PSG: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 psg_write(&p_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 case CMD_YM2612_0: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 ym_address_write_part1(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 ym_data_write(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 case CMD_YM2612_1: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 ym_address_write_part2(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 ym_data_write(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 case CMD_WAIT: { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 uint32_t wait_time = *(cur++); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 wait_time |= *(cur++) << 8; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 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
|
183 vgm_wait(&y_context, &p_context, ¤t_cycle, wait_time); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 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
|
187 vgm_wait(&y_context, &p_context, ¤t_cycle, 735 * mclks_sample); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 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
|
190 vgm_wait(&y_context, &p_context, ¤t_cycle, 882 * mclks_sample); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 } else { |
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
196 //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
|
197 return 0; |
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
198 } |
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
199 break; |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
200 case CMD_DATA: { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
201 cur++; //skip compat command |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
202 uint8_t data_type = *(cur++); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
203 uint32_t data_size = *(cur++); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
204 data_size |= *(cur++) << 8; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
205 data_size |= *(cur++) << 16; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
206 data_size |= *(cur++) << 24; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
207 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
|
208 data_block ** curblock = &blocks; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
209 while(*curblock) |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
210 { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
211 curblock = &((*curblock)->next); |
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 *curblock = malloc(sizeof(data_block)); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
214 (*curblock)->size = data_size; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
215 (*curblock)->type = data_type; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
216 (*curblock)->data = cur; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
217 (*curblock)->next = NULL; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
218 } else { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
219 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
|
220 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
221 cur += data_size; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
222 break; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
223 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
224 case CMD_DATA_SEEK: { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
225 uint32_t new_offset = *(cur++); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
226 new_offset |= *(cur++) << 8; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
227 new_offset |= *(cur++) << 16; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
228 new_offset |= *(cur++) << 24; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
229 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
|
230 seek_block = blocks; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
231 seek_offset = 0; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
232 block_offset = 0; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
233 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
234 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
|
235 { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
236 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
|
237 seek_block = seek_block->next; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
238 block_offset = 0; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
239 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
240 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
|
241 seek_offset = new_offset; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
242 break; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
243 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
244 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 default: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 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
|
247 uint32_t wait_time = (cmd & 0xF) + 1; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 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
|
249 vgm_wait(&y_context, &p_context, ¤t_cycle, wait_time); |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
250 } 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
|
251 if (seek_block) { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
252 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
|
253 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
|
254 seek_offset++; |
6800d30437c9
Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
511
diff
changeset
|
255 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
|
256 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
|
257 block_offset = 0; |
6800d30437c9
Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
511
diff
changeset
|
258 } |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
259 } else { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
260 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
|
261 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
262 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
|
263 if (wait_time) |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
264 { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
265 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
|
266 vgm_wait(&y_context, &p_context, ¤t_cycle, wait_time); |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
267 } |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 } 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
|
269 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
|
270 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 return 0; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 } |