Mercurial > repos > blastem
annotate vgmplay.c @ 2195:40290a923886
Implement Game Gear start button and region register
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 21 Aug 2022 22:56:32 -0700 |
parents | cfd53c94fffb |
children |
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" |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
17 #include "rf5c164.h" |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #define MCLKS_NTSC 53693175 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #define MCLKS_PAL 53203395 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 #define MCLKS_PER_68K 7 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 #define MCLKS_PER_YM MCLKS_PER_68K |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 #define MCLKS_PER_Z80 15 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
27 |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
28 #ifdef DISABLE_ZLIB |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
29 #define VGMFILE FILE* |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
30 #define vgmopen fopen |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
31 #define vgmread fread |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
32 #define vgmseek fseek |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
33 #define vgmgetc fgetc |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
34 #define vgmclose fclose |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
35 #else |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
36 #include "zlib/zlib.h" |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
37 #define VGMFILE gzFile |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
38 #define vgmopen gzopen |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
39 #define vgmread gzfread |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
40 #define vgmseek gzseek |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
41 #define vgmgetc gzgetc |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
42 #define vgmclose gzclose |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
43 #endif |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
44 |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
45 |
1944 | 46 system_header *current_system; |
47 | |
1985 | 48 void system_request_exit(system_header *system, uint8_t force_release) |
49 { | |
50 } | |
51 | |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 void handle_keydown(int keycode) |
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 |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 void handle_keyup(int keycode) |
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 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 |
466 | 60 void handle_joydown(int joystick, int button) |
61 { | |
62 } | |
63 | |
64 void handle_joyup(int joystick, int button) | |
65 { | |
66 } | |
67 | |
68 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value) | |
69 { | |
70 } | |
71 | |
1210
c95893007a83
Fix vgmplay and stateview targets
Michael Pavone <pavone@retrodev.com>
parents:
1196
diff
changeset
|
72 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
|
73 { |
c95893007a83
Fix vgmplay and stateview targets
Michael Pavone <pavone@retrodev.com>
parents:
1196
diff
changeset
|
74 } |
c95893007a83
Fix vgmplay and stateview targets
Michael Pavone <pavone@retrodev.com>
parents:
1196
diff
changeset
|
75 |
1196
74e77aec9004
Fix stateview and vgmplay targets
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
76 void handle_joy_added(int joystick) |
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 } |
74e77aec9004
Fix stateview and vgmplay targets
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
79 |
931
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
80 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
|
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 |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
84 void handle_mousedown(int mouse, int button) |
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 |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
88 void handle_mouseup(int mouse, int button) |
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 } |
126c0294c1e4
Make stateview and vgmplay compile again
Michael Pavone <pavone@retrodev.com>
parents:
890
diff
changeset
|
91 |
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
|
92 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
|
93 |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
94 #include <limits.h> |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
95 #define ADJUST_BUFFER (12500000) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
96 #define MAX_NO_ADJUST (UINT_MAX-ADJUST_BUFFER) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
97 #define MAX_RUN_SAMPLES 128 |
466 | 98 tern_node * config; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
99 |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
100 typedef struct chip_info chip_info; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
101 typedef void (*run_fun)(void *context, uint32_t cycle); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
102 typedef void (*adjust_fun)(chip_info *chip); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
103 struct chip_info { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
104 void *context; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
105 run_fun run; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
106 adjust_fun adjust; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
107 uint32_t clock; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
108 uint32_t samples; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
109 }; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
110 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
111 uint32_t cycles_to_samples(uint32_t clock_rate, uint32_t cycles) |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 { |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
113 return ((uint64_t)cycles) * ((uint64_t)44100) / ((uint64_t)clock_rate); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
114 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
115 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
116 uint32_t samples_to_cycles(uint32_t clock_rate, uint32_t cycles) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
117 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
118 return ((uint64_t)cycles) * ((uint64_t)clock_rate) / ((uint64_t)44100); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
119 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
120 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
121 void ym_adjust(chip_info *chip) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
122 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
123 ym2612_context *ym = chip->context; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
124 if (ym->current_cycle >= MAX_NO_ADJUST) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
125 uint32_t deduction = ym->current_cycle - ADJUST_BUFFER; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
126 chip->samples -= cycles_to_samples(chip->clock, deduction); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
127 ym->current_cycle -= deduction; |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
128 } |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
129 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
130 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
131 void psg_adjust(chip_info *chip) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
132 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
133 psg_context *psg = chip->context; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
134 if (psg->cycles >= MAX_NO_ADJUST) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
135 uint32_t deduction = psg->cycles - ADJUST_BUFFER; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
136 chip->samples -= cycles_to_samples(chip->clock, deduction); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
137 psg->cycles -= deduction; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
138 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
139 } |
466 | 140 |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
141 void pcm_adjust(chip_info *chip) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
142 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
143 rf5c164 *pcm = chip->context; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
144 if (pcm->cycle >= MAX_NO_ADJUST) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
145 uint32_t deduction = pcm->cycle - ADJUST_BUFFER; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
146 chip->samples -= cycles_to_samples(chip->clock, deduction); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
147 pcm->cycle -= deduction; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
148 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
149 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
150 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
151 void vgm_wait(chip_info *chips, uint32_t num_chips, uint32_t *completed_samples, uint32_t samples) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
152 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
153 while (samples > MAX_RUN_SAMPLES) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
154 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
155 vgm_wait(chips, num_chips, completed_samples, MAX_RUN_SAMPLES); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
156 samples -= MAX_RUN_SAMPLES; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
157 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
158 *completed_samples += samples; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
159 for (uint32_t i = 0; i < num_chips; i++) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
160 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
161 chips[i].samples += samples; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
162 chips[i].run(chips[i].context, samples_to_cycles(chips[i].clock, chips[i].samples)); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
163 chips[i].adjust(chips + i); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
164 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
165 if (*completed_samples > 44100/60) { |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
408
diff
changeset
|
166 process_events(); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
170 chip_info chips[64]; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
171 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
172 uint8_t *find_block(data_block *head, uint32_t offset, uint32_t size) |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
173 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
174 if (!head) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
175 return NULL; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
176 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
177 while (head->size < offset) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
178 offset -= head->size; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
179 head = head->next; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
180 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
181 if (head->size - offset < size) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
182 return NULL; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
183 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
184 return head->data + offset; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
185 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
186 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 int main(int argc, char ** argv) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 { |
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
|
189 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
|
190 data_block *blocks = NULL; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
191 data_block *seek_block = NULL; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
192 data_block *pcm68_blocks = NULL; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
193 data_block *pcm164_blocks = NULL; |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
194 uint32_t seek_offset; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
195 uint32_t block_offset; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
196 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 uint32_t fps = 60; |
466 | 198 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
|
199 render_init(320, 240, "vgm play", 0); |
466 | 200 |
514
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 } |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
205 |
1327
57637d17b59e
Fix vgmplay target for ternary tree changes
Michael Pavone <pavone@retrodev.com>
parents:
1210
diff
changeset
|
206 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
|
207 uint32_t lowpass_cutoff = lowpass_cutoff_str ? atoi(lowpass_cutoff_str) : 3390; |
466 | 208 |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
209 VGMFILE f = vgmopen(argv[1], "rb"); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 vgm_header header; |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
211 vgmread(&header, sizeof(header), 1, f); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 if (header.version < 0x150 || !header.data_offset) { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 header.data_offset = 0xC; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 } |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
215 if (header.version <= 0x101) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
216 header.ym2612_clk = header.ym2413_clk; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
217 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
218 uint32_t num_chips = 0; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
219 rf5c164 *pcm68 = NULL; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
220 if ((header.data_offset + 0x34) >= 0x44) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
221 uint32_t pcm68_clock = 0; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
222 vgmseek(f, 0x40, SEEK_SET); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
223 vgmread(&pcm68_clock, sizeof(pcm68_clock), 1, f); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
224 if (pcm68_clock) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
225 pcm68 = calloc(sizeof(*pcm68), 1); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
226 rf5c164_init(pcm68, pcm68_clock, 1); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
227 chips[num_chips++] = (chip_info) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
228 .context = pcm68, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
229 .run = (run_fun)rf5c164_run, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
230 .adjust = pcm_adjust, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
231 .clock = pcm68_clock, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
232 .samples = 0 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
233 }; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
234 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
235 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
236 rf5c164 *pcm164 = NULL; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
237 if ((header.data_offset + 0x34) >= 0x70) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
238 uint32_t pcm164_clock = 0; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
239 vgmseek(f, 0x6C, SEEK_SET); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
240 vgmread(&pcm164_clock, sizeof(pcm164_clock), 1, f); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
241 if (pcm164_clock) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
242 pcm164 = calloc(sizeof(*pcm164), 1); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
243 rf5c164_init(pcm164, pcm164_clock, 1); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
244 chips[num_chips++] = (chip_info) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
245 .context = pcm164, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
246 .run = (run_fun)rf5c164_run, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
247 .adjust = pcm_adjust, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
248 .clock = pcm164_clock, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
249 .samples = 0 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
250 }; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
251 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
252 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
253 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
254 ym2612_context y_context; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
255 if (header.ym2612_clk) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
256 ym_init(&y_context, header.ym2612_clk, 1, opts); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
257 chips[num_chips++] = (chip_info) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
258 .context = &y_context, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
259 .run = (run_fun)ym_run, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
260 .adjust = ym_adjust, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
261 .clock = header.ym2612_clk, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
262 .samples = 0 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
263 }; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
264 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
265 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
266 psg_context p_context; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
267 if (header.sn76489_clk) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
268 psg_init(&p_context, header.sn76489_clk, 1); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
269 chips[num_chips++] = (chip_info) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
270 .context = &p_context, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
271 .run = (run_fun)psg_run, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
272 .adjust = psg_adjust, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
273 .clock = header.sn76489_clk, |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
274 .samples = 0 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
275 }; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
276 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
277 |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
278 vgmseek(f, header.data_offset + 0x34, SEEK_SET); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 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
|
280 uint8_t * data = malloc(data_size); |
2044
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
281 vgmread(data, 1, data_size, f); |
460e14497120
zlib support in vgmplay
Michael Pavone <pavone@retrodev.com>
parents:
1985
diff
changeset
|
282 vgmclose(f); |
466 | 283 |
514
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
284 uint32_t loop_count = 2; |
466 | 285 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 uint8_t * end = data + data_size; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 uint8_t * cur = data; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
288 uint32_t completed_samples = 0; |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 while (cur < end) { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 uint8_t cmd = *(cur++); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 switch(cmd) |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 case CMD_PSG_STEREO: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 //ignore for now |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 cur++; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 case CMD_PSG: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 psg_write(&p_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 case CMD_YM2612_0: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 ym_address_write_part1(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 ym_data_write(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 case CMD_YM2612_1: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 ym_address_write_part2(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 ym_data_write(&y_context, *(cur++)); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 case CMD_WAIT: { |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 uint32_t wait_time = *(cur++); |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 wait_time |= *(cur++) << 8; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
311 vgm_wait(chips, num_chips, &completed_samples, wait_time); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 case CMD_WAIT_60: |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
315 vgm_wait(chips, num_chips, &completed_samples, 735); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 case CMD_WAIT_50: |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
318 vgm_wait(chips, num_chips, &completed_samples, 882); |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 break; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 } else { |
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
324 //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
|
325 return 0; |
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
326 } |
f66c78cbdcaa
Implement per-channel wave logging and primitive looping support in vgm player.
Michael Pavone <pavone@retrodev.com>
parents:
512
diff
changeset
|
327 break; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
328 case CMD_PCM_WRITE: |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
329 if (end - cur < 11) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
330 fatal_error("early end of stream at offset %X\n", data-cur); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
331 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
332 cur++; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
333 { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
334 uint8_t chip_type = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
335 uint32_t read_offset = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
336 read_offset |= *(cur++) << 8; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
337 read_offset |= *(cur++) << 16; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
338 uint32_t write_offset = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
339 write_offset |= *(cur++) << 8; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
340 write_offset |= *(cur++) << 16; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
341 uint32_t size = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
342 size |= *(cur++) << 8; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
343 size |= *(cur++) << 16; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
344 if (chip_type == DATA_RF5C68) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
345 uint8_t *src = find_block(pcm68_blocks, read_offset, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
346 if (!src) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
347 printf("Failed to find RF6C68 data offset %X with size %X\n", read_offset, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
348 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
349 write_offset |= pcm68->ram_bank; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
350 write_offset &= 0xFFFF; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
351 if (size + write_offset > 0x10000) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
352 size = 0x10000 - write_offset; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
353 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
354 memcpy(pcm68->ram + write_offset, src, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
355 printf("rf5c68 PCM write read_offset %X, write_offset %X, size %X\n", read_offset, write_offset, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
356 } else if (chip_type == DATA_RF5C164) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
357 uint8_t *src = find_block(pcm164_blocks, read_offset, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
358 if (!src) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
359 printf("Failed to find RF6C68 data offset %X with size %X\n", read_offset, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
360 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
361 write_offset |= pcm164->ram_bank; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
362 write_offset &= 0xFFFF; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
363 if (size + write_offset > 0x10000) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
364 size = 0x10000 - write_offset; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
365 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
366 memcpy(pcm164->ram + write_offset, src, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
367 printf("rf5c164 PCM write read_offset %X, write_offset %X, size %X\n", read_offset, write_offset, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
368 } else { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
369 printf("unknown PCM write read_offset %X, write_offset %X, size %X\n", read_offset, write_offset, size); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
370 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
371 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
372 break; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
373 case CMD_PCM68_REG: |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
374 if (pcm68) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
375 uint8_t reg = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
376 uint8_t value = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
377 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
378 rf5c164_write(pcm68, reg, value); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
379 } else { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
380 printf("CMD_PCM68_REG without rf5c68 clock\n"); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
381 cur += 2; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
382 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
383 break; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
384 case CMD_PCM164_REG: |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
385 if (pcm164) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
386 uint8_t reg = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
387 uint8_t value = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
388 rf5c164_write(pcm164, reg, value); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
389 } else { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
390 printf("CMD_PCM164_REG without rf5c164 clock\n"); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
391 cur += 2; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
392 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
393 break; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
394 case CMD_PCM68_RAM: |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
395 if (pcm68) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
396 uint16_t address = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
397 address |= *(cur++) << 8; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
398 address &= 0xFFF; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
399 address |= 0x1000; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
400 uint8_t value = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
401 rf5c164_write(pcm68, address, value); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
402 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
403 break; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
404 case CMD_PCM164_RAM: |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
405 if (pcm164) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
406 uint16_t address = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
407 address |= *(cur++) << 8; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
408 address &= 0xFFF; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
409 address |= 0x1000; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
410 uint8_t value = *(cur++); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
411 rf5c164_write(pcm164, address, value); |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
412 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
413 break; |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
414 case CMD_DATA: { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
415 cur++; //skip compat command |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
416 uint8_t data_type = *(cur++); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
417 uint32_t data_size = *(cur++); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
418 data_size |= *(cur++) << 8; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
419 data_size |= *(cur++) << 16; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
420 data_size |= *(cur++) << 24; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
421 data_block **curblock = NULL; |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
422 if (data_type == DATA_YM2612_PCM) { |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
423 curblock = &blocks; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
424 } else if (data_type == DATA_RF5C68) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
425 curblock = &pcm68_blocks; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
426 } else if (data_type == DATA_RF5C164) { |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
427 curblock = &pcm164_blocks; |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
428 } |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
429 |
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
430 if (curblock) { |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
431 while(*curblock) |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
432 { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
433 curblock = &((*curblock)->next); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
434 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
435 *curblock = malloc(sizeof(data_block)); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
436 (*curblock)->size = data_size; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
437 (*curblock)->type = data_type; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
438 (*curblock)->data = cur; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
439 (*curblock)->next = NULL; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
440 } else { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
441 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
|
442 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
443 cur += data_size; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
444 break; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
445 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
446 case CMD_DATA_SEEK: { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
447 uint32_t new_offset = *(cur++); |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
448 new_offset |= *(cur++) << 8; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
449 new_offset |= *(cur++) << 16; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
450 new_offset |= *(cur++) << 24; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
451 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
|
452 seek_block = blocks; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
453 seek_offset = 0; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
454 block_offset = 0; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
455 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
456 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
|
457 { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
458 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
|
459 seek_block = seek_block->next; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
460 block_offset = 0; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
461 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
462 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
|
463 seek_offset = new_offset; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
464 break; |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
465 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
466 |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 default: |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 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
|
469 uint32_t wait_time = (cmd & 0xF) + 1; |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
470 vgm_wait(chips, num_chips, &completed_samples, wait_time); |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
471 } 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
|
472 if (seek_block) { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
473 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
|
474 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
|
475 seek_offset++; |
6800d30437c9
Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
511
diff
changeset
|
476 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
|
477 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
|
478 block_offset = 0; |
6800d30437c9
Increment sample pointer after reading a sample in VGM player
Michael Pavone <pavone@retrodev.com>
parents:
511
diff
changeset
|
479 } |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
480 } else { |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
481 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
|
482 } |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
483 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
|
484 if (wait_time) |
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
485 { |
2081
cfd53c94fffb
Initial stab at RF5C164 emulation
Michael Pavone <pavone@retrodev.com>
parents:
2044
diff
changeset
|
486 vgm_wait(chips, num_chips, &completed_samples, wait_time); |
511
2c1679058727
Add support for VGM 1.50 PCM data blocks
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
487 } |
408
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 } 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
|
489 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
|
490 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 } |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 return 0; |
a13a83934ba3
Add primitive vgm player for testing
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 } |