• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revision30e92a5fa2e77b862bc91e4099f6d19ae776b506 (tree)
Time2018-06-13 05:06:06
AuthorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[VM][FM7][SOUND][WIP] Fixing wrong frequency after load_state with RELICS.This is WIP.

Change Summary

Incremental Difference

--- a/source/src/vm/fm7/fm7.cpp
+++ b/source/src/vm/fm7/fm7.cpp
@@ -130,6 +130,19 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
130130 if((config.dipswitch & FM7_DIPSW_MIDI_ON) != 0) uart[2] = new I8251(this, emu);
131131
132132
133+#if defined(_FM77AV_VARIANTS)
134+ alu = new MB61VH010(this, emu);
135+ keyboard_beep = new BEEP(this, emu);
136+#endif
137+ keyboard = new KEYBOARD(this, emu);
138+ display = new DISPLAY(this, emu);
139+#if defined(_FM8)
140+ mainio = new FM8_MAINIO(this, emu);
141+#else
142+ mainio = new FM7_MAINIO(this, emu);
143+#endif
144+ mainmem = new FM7_MAINMEM(this, emu);
145+
133146 // basic devices
134147 // I/Os
135148 #if defined(HAS_DMA)
@@ -201,18 +214,6 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
201214 #if defined(_FM77L4)
202215 l4crtc = new HD46505(this, emu);;
203216 #endif
204-#if defined(_FM77AV_VARIANTS)
205- alu = new MB61VH010(this, emu);
206- keyboard_beep = new BEEP(this, emu);
207-#endif
208- keyboard = new KEYBOARD(this, emu);
209- display = new DISPLAY(this, emu);
210-#if defined(_FM8)
211- mainio = new FM8_MAINIO(this, emu);
212-#else
213- mainio = new FM7_MAINIO(this, emu);
214-#endif
215- mainmem = new FM7_MAINMEM(this, emu);
216217
217218 #if defined(_FM8) || defined(_FM7) || defined(_FMNEW7)
218219 if((config.dipswitch & FM7_DIPSW_CONNECT_KANJIROM) != 0) {
@@ -820,7 +821,7 @@ void VM::initialize_sound(int rate, int samples)
820821 keyboard_beep->initialize_sound(rate, 2400.0, 512);
821822 # endif
822823 #endif
823- pcm1bit->initialize_sound(rate, 2000);
824+ pcm1bit->initialize_sound(rate, 8000);
824825 //drec->initialize_sound(rate, 0);
825826 }
826827
@@ -1214,7 +1215,7 @@ void VM::set_vm_frame_rate(double fps)
12141215 if(event != NULL) event->set_frames_per_sec(fps);
12151216 }
12161217
1217-#define STATE_VERSION 9
1218+#define STATE_VERSION 10
12181219 #include "../../statesub.h"
12191220
12201221 void VM::decl_state(void)
@@ -1276,6 +1277,9 @@ bool VM::load_state(FILEIO* state_fio)
12761277 return false;
12771278 }
12781279 }
1280+ update_config();
1281+ mainio->restore_opn();
1282+
12791283 return true;
12801284 }
12811285
--- a/source/src/vm/fm7/fm7_mainio.cpp
+++ b/source/src/vm/fm7/fm7_mainio.cpp
@@ -129,6 +129,7 @@ FM7_MAINIO::FM7_MAINIO(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, paren
129129 opn_address[i] = 0x00;
130130 opn_data[i] = 0x00;
131131 opn_cmdreg[i] = 0;
132+ opn_prescaler_type[i] = 1;
132133 }
133134 intstat_whg = false;
134135 intstat_thg = false;
@@ -229,7 +230,7 @@ void FM7_MAINIO::initialize()
229230 event_2hd_nmi = -1;
230231 nmi_delay = 300;
231232 #endif
232- reset_printer();
233+ //reset_printer();
233234 }
234235
235236 void FM7_MAINIO::reset()
@@ -2129,16 +2130,20 @@ void FM7_MAINIO::decl_state(void)
21292130 DECL_STATE_ENTRY_UINT32_ARRAY(opn_stat, 4);
21302131 DECL_STATE_ENTRY_UINT8_ARRAY(opn_cmdreg, 4);
21312132 DECL_STATE_ENTRY_UINT8_ARRAY(opn_ch3mode, 4);
2133+ DECL_STATE_ENTRY_UINT8_ARRAY(opn_prescaler_type, 4);
2134+ //DECL_STATE_ENTRY_2D_ARRAY(opn_keys, 4, 4);
21322135
21332136 DECL_STATE_ENTRY_2D_ARRAY(opn_regs, 4, 0x100);
2134-
2137+
2138+ //DECL_STATE_ENTRY_1D_ARRAY((uint8_t *)opn_keys, 16);
2139+
2140+ //DECL_STATE_ENTRY_1D_ARRAY((uint8_t *)opn_regs, 0x400);
21352141 }
21362142 void FM7_MAINIO::save_state(FILEIO *state_fio)
21372143 {
21382144 if(state_entry != NULL) state_entry->save_state(state_fio);
21392145 }
21402146
2141-
21422147 bool FM7_MAINIO::load_state(FILEIO *state_fio)
21432148 {
21442149 int ch;
@@ -2148,9 +2153,11 @@ bool FM7_MAINIO::load_state(FILEIO *state_fio)
21482153 bool mb = false;
21492154 if(state_entry != NULL) {
21502155 mb = state_entry->load_state(state_fio);
2156+ if(mb) {
21512157 #if defined(HAS_DMA)
2152- dma_addr = dma_addr & 0x1f;
2158+ dma_addr = dma_addr & 0x1f;
21532159 #endif
2160+ }
21542161 }
21552162 this->out_debug_log(_T("Load State: MAINIO: id=%d stat=%s\n"), this_device_id, (mb) ? _T("OK") : _T("NG"));
21562163 return mb;
--- a/source/src/vm/fm7/fm7_mainio.h
+++ b/source/src/vm/fm7/fm7_mainio.h
@@ -179,7 +179,8 @@ class FM7_MAINIO : public DEVICE {
179179 uint32_t opn_stat[4];
180180 uint8_t opn_cmdreg[4]; // OPN register, bit 3-0, maybe dummy.
181181 uint8_t opn_ch3mode[4];
182-
182+ uint8_t opn_prescaler_type[4];
183+
183184 /* FD47 */
184185 bool intstat_whg; // bit3 : OPN interrupt. '0' = happened.
185186 /* FD53 */
@@ -517,7 +518,8 @@ public:
517518
518519 virtual void write_signal(int id, uint32_t data, uint32_t mask);
519520 virtual uint32_t read_signal(int id);
520-
521+ void restore_opn(void);
522+
521523 virtual void event_callback(int event_id, int err);
522524 virtual void reset();
523525 virtual void update_config();
--- a/source/src/vm/fm7/sound.cpp
+++ b/source/src/vm/fm7/sound.cpp
@@ -28,18 +28,58 @@ void FM7_MAINIO::reset_sound(void)
2828 opn_address[i] = 0;
2929 opn_stat[i] = 0;
3030 opn_ch3mode[i] = 0x00;
31+ opn_prescaler_type[i] = 1;
32+ memset(opn_regs[i], 0x00, 0x100 * sizeof(uint8_t));
3133 if(opn[i] != NULL) {
3234 opn[i]->reset();
33- opn[i]->write_data8(0, 0x2e);
34- opn[i]->write_data8(1, 0); // set prescaler
35- opn[i]->write_data8(0, 0x27);
36- opn[i]->write_data8(1, 0x00);
35+
36+ for(int ch = 0x00; ch < 0x0e; ch++) { // PSG from XM7.
37+ if(ch == 7) {
38+ opn[i]->set_reg(ch, 0xff);
39+ } else {
40+ opn[i]->set_reg(ch, 0x00);
41+ }
42+ }
43+ for(int ch = 0x30; ch < 0x40; ch++) { // MUL, DT from XM7.
44+ if((ch & 0x03) != 3) {
45+ opn[i]->set_reg(ch, 0);
46+ }
47+ }
48+ for(int ch = 0x40; ch < 0x50; ch++) { // TL
49+ if((ch & 0x03) != 3) {
50+ opn[i]->set_reg(ch, 0x7f);
51+ opn_regs[i][ch] = 0x7f;
52+ }
53+ }
54+ for(int ch = 0x50; ch < 0x60; ch++) { // AR
55+ if((ch & 0x03) != 3) {
56+ opn[i]->set_reg(ch, 0x1f);
57+ opn_regs[i][ch] = 0x1f;
58+ }
59+ }
60+ for(int ch = 0x60; ch < 0xb4; ch++) { // MISC
61+ if((ch & 0x03) != 3) {
62+ opn[i]->set_reg(ch, 0x7f);
63+ opn_regs[i][ch] = 0x7f;
64+ }
65+ }
66+ for(int ch = 0x80; ch < 0x90; ch++) { // SL/RR
67+ if((ch & 0x03) != 3) {
68+ opn[i]->set_reg(ch, 0xff);
69+ opn_regs[i][ch] = 0xff;
70+ }
71+ }
72+ // Note
3773 for(j = 0; j < 3; j++) {
3874 opn[i]->set_reg(0x28, j | 0xfe);
75+ opn_regs[i][0x28] = (uint8_t)(j | 0xfe);
76+ //opn_keys[i][j] = j | 0xfe;
3977 }
40-// opn[i]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
78+ opn[i]->write_io8(0, 0x2e);
79+ opn[i]->write_io8(1, 0); // set prescaler
80+ opn[i]->write_io8(0, 0x27);
81+ opn[i]->write_io8(1, 0x00);
4182 }
42-
4383 }
4484 //#endif
4585 #if !defined(_FM77AV_VARIANTS)
@@ -107,6 +147,50 @@ void FM7_MAINIO::reset_sound(void)
107147 # endif
108148 }
109149
150+// After loading state, OPN's prescaler needs to reset.
151+void FM7_MAINIO::restore_opn(void)
152+{
153+ for(int i = 0; i < 3; i++) {
154+ if(opn[i] != NULL) {
155+#if 0
156+ for(int j = 0x0; j < 0x0d; j++) {
157+ if((j < 0x08) || (j > 0x0a)) {
158+ opn[i]->set_reg(j, opn_regs[i][j]);
159+ } else {
160+ opn[i]->set_reg(j, 0);
161+ }
162+ }
163+ for(int j = 0x30; j < 0xb4; j++) {
164+ opn[i]->set_reg(j, opn_regs[i][j]);
165+ }
166+#endif
167+ int pre = opn_prescaler_type[i];
168+ if((pre >= 0) && (pre < 3)) {
169+ opn[i]->set_reg(pre + 0x2d, 0);
170+ }
171+ // Key
172+ for(int j = 0; j < 3; j++) {
173+ //opn[i]->set_reg(0x28, opn_keys[i][j]);
174+ }
175+ opn[i]->set_reg(0x27, opn_regs[i][0x27]);
176+ }
177+ }
178+# if !defined(_FM77AV_VARIANTS)
179+ if(psg != NULL) {
180+#if 0
181+ for(int j = 0x0; j < 0x0d; j++) {
182+ if((j < 0x08) || (j > 0x0a)) {
183+ psg->set_reg(j, opn_regs[3][j]);
184+ } else {
185+ psg->set_reg(j, 0);
186+ }
187+ }
188+#endif
189+ //psg->set_reg(0x27, opn_regs[3][0x27]);
190+ psg->set_reg(0x2e, 0);
191+ }
192+#endif
193+}
110194
111195 void FM7_MAINIO::set_psg(uint8_t val)
112196 {
@@ -140,19 +224,25 @@ void FM7_MAINIO::set_psg_cmd(uint8_t cmd)
140224 // Write to FD16, same as
141225 void FM7_MAINIO::write_opn_reg(int index, uint32_t addr, uint32_t data)
142226 {
227+ //printf("OPN: #%d REG=%02x VAL=%02x\n", index, addr, data);
143228 # if !defined(_FM77AV_VARIANTS)
144229 if(index == 3) { // PSG
145230 psg->write_io8(0, addr & 0x0f);
146231 psg->write_io8(1, data);
232+ opn_regs[index][addr] = data;
147233 return;
148234 }
149235 # endif
236+
150237 if((addr >= 0x2d) && (addr < 0x30)) {
238+ opn_prescaler_type[index] = addr - 0x2d;
151239 opn[index]->write_io8(0, addr);
240+ opn_regs[index][addr] = 0;
152241 return;
153- }
154- if(addr == 0x27) {
242+ } else if(addr == 0x27) {
155243 opn_ch3mode[index] = data & 0xc0;
244+ } else if(addr == 0x28) {
245+ //opn_keys[index][data & 3] = data;
156246 }
157247 opn[index]->write_io8(0, addr);
158248 opn[index]->write_io8(1, data);
@@ -191,10 +281,12 @@ void FM7_MAINIO::set_opn(int index, uint8_t val)
191281 opn_address[index] = val;
192282 //#if !defined(_FM8)
193283 if((val > 0x2c) && (val < 0x30)) {
284+ opn_prescaler_type[index] = val - 0x2d;
194285 opn_data[index] = 0;
195286 opn[index]->write_io8(0, val);
196287 opn[index]->write_io8(1, 0);
197288 }
289+
198290 //#endif
199291 }
200292 break;
@@ -261,7 +353,7 @@ void FM7_MAINIO::set_opn_cmd(int index, uint8_t cmd)
261353 if(psg == NULL) return;
262354 }
263355 # endif
264- uint32_t mask[16] = { // Parameter is related by XM7. Thanks Ryu.
356+ static const uint32_t mask[16] = { // Parameter is related by XM7. Thanks Ryu.
265357 0xff, 0x0f, 0xff, 0x0f,
266358 0xff, 0x0f, 0x1f, 0xff,
267359 0x1f, 0x1f, 0x1f, 0xff,
@@ -299,6 +391,7 @@ void FM7_MAINIO::set_opn_cmd(int index, uint8_t cmd)
299391 opn_address[index] = val;
300392 //#if !defined(_FM8)
301393 if((val > 0x2c) && (val < 0x30)) {
394+ opn_prescaler_type[index] = val - 0x2d;
302395 opn_data[index] = 0;
303396 opn[index]->write_io8(0, val);
304397 opn[index]->write_io8(1, 0);
@@ -336,7 +429,7 @@ void FM7_MAINIO::opn_note_on(int index)
336429 {
337430 uint8_t r;
338431 //#if !defined(_FM8)
339- if((index < 0) || (index >= 2)) return;
432+ if((index < 0) || (index >= 3)) return;
340433 // Not on for CSM mode. From XM7. Thanks, Ryu.
341434 r = opn_ch3mode[index];
342435 if ((r & 0xc0) == 0x80) {
Show on old repository browser