Mercurial > repos > blastem
annotate ym2612.c @ 1802:1d1198f16279
Fix a couple of minor cases of extra precision in LFO implementation
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 26 Mar 2019 22:27:23 -0700 |
parents | 5278b6e44fc1 |
children | a851d36e24bb |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
2 Copyright 2013 Michael Pavone |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike 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:
451
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:
451
diff
changeset
|
5 */ |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include <string.h> |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
7 #include <math.h> |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
8 #include <stdio.h> |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
9 #include <stdlib.h> |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "ym2612.h" |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
11 #include "render.h" |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
12 #include "wave.h" |
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:
483
diff
changeset
|
13 #include "blastem.h" |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
15 //#define DO_DEBUG_PRINT |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
16 #ifdef DO_DEBUG_PRINT |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
17 #define dfprintf fprintf |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
18 #define dfopen(var, fname, mode) var=fopen(fname, mode) |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
19 #else |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
20 #define dfprintf |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
21 #define dfopen(var, fname, mode) |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
22 #endif |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
23 |
535
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
24 #define BUSY_CYCLES_ADDRESS 17 |
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
25 #define BUSY_CYCLES_DATA_LOW 83 |
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
26 #define BUSY_CYCLES_DATA_HIGH 47 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
27 #define OP_UPDATE_PERIOD 144 |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 #define BIT_TIMERA_ENABLE 0x1 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 #define BIT_TIMERB_ENABLE 0x2 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #define BIT_TIMERA_OVEREN 0x4 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 #define BIT_TIMERB_OVEREN 0x8 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 #define BIT_TIMERA_RESET 0x10 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 #define BIT_TIMERB_RESET 0x20 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
36 #define BIT_TIMERA_LOAD 0x40 |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
37 #define BIT_TIMERB_LOAD 0x80 |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
38 |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 #define BIT_STATUS_TIMERA 0x1 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 #define BIT_STATUS_TIMERB 0x2 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
42 static uint32_t ym_calc_phase_inc(ym2612_context * context, ym_operator * operator, uint32_t op); |
935
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
43 |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
44 enum { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
45 PHASE_ATTACK, |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
46 PHASE_DECAY, |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
47 PHASE_SUSTAIN, |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
48 PHASE_RELEASE |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
49 }; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
50 |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
51 uint8_t did_tbl_init = 0; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
52 //According to Nemesis, real hardware only uses a 256 entry quarter sine table; however, |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
53 //memory is cheap so using a half sine table will probably save some cycles |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
54 //a full sine table would be nice, but negative numbers don't get along with log2 |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
55 #define SINE_TABLE_SIZE 512 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
56 static uint16_t sine_table[SINE_TABLE_SIZE]; |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
57 //Similar deal here with the power table for log -> linear conversion |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
58 //According to Nemesis, real hardware only uses a 256 entry table for the fractional part |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
59 //and uses the whole part as a shift amount. |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
60 #define POW_TABLE_SIZE (1 << 13) |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
61 static uint16_t pow_table[POW_TABLE_SIZE]; |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
62 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
63 static uint16_t rate_table_base[] = { |
362 | 64 //main portion |
65 0,1,0,1,0,1,0,1, | |
66 0,1,0,1,1,1,0,1, | |
67 0,1,1,1,0,1,1,1, | |
68 0,1,1,1,1,1,1,1, | |
69 //top end | |
70 1,1,1,1,1,1,1,1, | |
71 1,1,1,2,1,1,1,2, | |
72 1,2,1,2,1,2,1,2, | |
73 1,2,2,2,1,2,2,2, | |
74 }; | |
75 | |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
76 static uint16_t rate_table[64*8]; |
362 | 77 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
78 static uint8_t lfo_timer_values[] = {108, 77, 71, 67, 62, 44, 8, 5}; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
79 static uint8_t lfo_pm_base[][8] = { |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
80 {0, 0, 0, 0, 0, 0, 0, 0}, |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
81 {0, 0, 0, 0, 4, 4, 4, 4}, |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
82 {0, 0, 0, 4, 4, 4, 8, 8}, |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
83 {0, 0, 4, 4, 8, 8, 0xc, 0xc}, |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
84 {0, 0, 4, 8, 8, 8, 0xc,0x10}, |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
85 {0, 0, 8, 0xc,0x10,0x10,0x14,0x18}, |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
86 {0, 0,0x10,0x18,0x20,0x20,0x28,0x30}, |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
87 {0, 0,0x20,0x30,0x40,0x40,0x50,0x60} |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
88 }; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
89 static int16_t lfo_pm_table[128 * 32 * 8]; |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
90 |
930
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
91 int16_t ams_shift[] = {8, 1, -1, -2}; |
740
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
92 |
362 | 93 #define MAX_ENVELOPE 0xFFC |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
94 #define YM_DIVIDER 2 |
374 | 95 #define CYCLE_NEVER 0xFFFFFFFF |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
96 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
97 static uint16_t round_fixed_point(double value, int dec_bits) |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
98 { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
99 return value * (1 << dec_bits) + 0.5; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
100 } |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
101 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
102 static FILE * debug_file = NULL; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
103 static uint32_t first_key_on=0; |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
104 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
105 static ym2612_context * log_context = NULL; |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
106 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
107 static void ym_finalize_log() |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
108 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
109 if (!log_context) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
110 return; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
111 } |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
112 for (int i = 0; i < NUM_CHANNELS; i++) { |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
113 if (log_context->channels[i].logfile) { |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
114 wave_finalize(log_context->channels[i].logfile); |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
115 } |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
116 } |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
117 log_context = NULL; |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
118 } |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
119 |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
120 void ym_adjust_master_clock(ym2612_context * context, uint32_t master_clock) |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
121 { |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
122 render_audio_adjust_clock(context->audio, master_clock, context->clock_inc * NUM_OPERATORS); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
123 } |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
124 |
859
46bb673eed4e
Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents:
853
diff
changeset
|
125 #ifdef __ANDROID__ |
46bb673eed4e
Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents:
853
diff
changeset
|
126 #define log2(x) (log(x)/log(2)) |
46bb673eed4e
Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents:
853
diff
changeset
|
127 #endif |
46bb673eed4e
Load config file and rom.db from appropriate locations on Android
Michael Pavone <pavone@retrodev.com>
parents:
853
diff
changeset
|
128 |
1308
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
129 |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
130 #define TIMER_A_MAX 1023 |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
131 #define TIMER_B_MAX 255 |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
132 |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
133 void ym_reset(ym2612_context *context) |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
134 { |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
135 memset(context->part1_regs, 0, sizeof(context->part1_regs)); |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
136 memset(context->part2_regs, 0, sizeof(context->part2_regs)); |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
137 memset(context->operators, 0, sizeof(context->operators)); |
1654
4637ab86be8c
Preserve WAVE logging FILE * across YM2612 device reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
138 FILE* savedlogs[NUM_CHANNELS]; |
4637ab86be8c
Preserve WAVE logging FILE * across YM2612 device reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
139 for (int i = 0; i < NUM_CHANNELS; i++) |
4637ab86be8c
Preserve WAVE logging FILE * across YM2612 device reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
140 { |
4637ab86be8c
Preserve WAVE logging FILE * across YM2612 device reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
141 savedlogs[i] = context->channels[i].logfile; |
4637ab86be8c
Preserve WAVE logging FILE * across YM2612 device reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
142 } |
1308
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
143 memset(context->channels, 0, sizeof(context->channels)); |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
144 memset(context->ch3_supp, 0, sizeof(context->ch3_supp)); |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
145 context->selected_reg = 0; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
146 context->csm_keyon = 0; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
147 context->ch3_mode = 0; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
148 context->dac_enable = 0; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
149 context->status = 0; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
150 context->timer_a_load = 0; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
151 context->timer_b_load = 0; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
152 //TODO: Confirm these on hardware |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
153 context->timer_a = TIMER_A_MAX; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
154 context->timer_b = TIMER_B_MAX; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
155 |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
156 //TODO: Reset LFO state |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
157 |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
158 //some games seem to expect that the LR flags start out as 1 |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
159 for (int i = 0; i < NUM_CHANNELS; i++) { |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
160 context->channels[i].lr = 0xC0; |
1654
4637ab86be8c
Preserve WAVE logging FILE * across YM2612 device reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
161 context->channels[i].logfile = savedlogs[i]; |
1308
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
162 } |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
163 context->write_cycle = CYCLE_NEVER; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
164 for (int i = 0; i < NUM_OPERATORS; i++) { |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
165 context->operators[i].envelope = MAX_ENVELOPE; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
166 context->operators[i].env_phase = PHASE_RELEASE; |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
167 } |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
168 } |
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
169 |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
170 void ym_init(ym2612_context * context, uint32_t master_clock, uint32_t clock_div, uint32_t options) |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
172 static uint8_t registered_finalize; |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
173 dfopen(debug_file, "ym_debug.txt", "w"); |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 memset(context, 0, sizeof(*context)); |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
379
diff
changeset
|
175 context->clock_inc = clock_div * 6; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
176 context->audio = render_audio_source(master_clock, context->clock_inc * NUM_OPERATORS, 2); |
1308
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
177 |
369
fc820ab1394b
Fix left/right enable default value
Mike Pavone <pavone@retrodev.com>
parents:
365
diff
changeset
|
178 //some games seem to expect that the LR flags start out as 1 |
fc820ab1394b
Fix left/right enable default value
Mike Pavone <pavone@retrodev.com>
parents:
365
diff
changeset
|
179 for (int i = 0; i < NUM_CHANNELS; i++) { |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
180 if (options & YM_OPT_WAVE_LOG) { |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
181 char fname[64]; |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
182 sprintf(fname, "ym_channel_%d.wav", i); |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
183 FILE * f = context->channels[i].logfile = fopen(fname, "wb"); |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
184 if (!f) { |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
185 fprintf(stderr, "Failed to open WAVE log file %s for writing\n", fname); |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
186 continue; |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
187 } |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
188 if (!wave_init(f, master_clock / (context->clock_inc * NUM_OPERATORS), 16, 1)) { |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
189 fclose(f); |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
190 context->channels[i].logfile = NULL; |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
191 } |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
192 } |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
193 } |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
194 if (options & YM_OPT_WAVE_LOG) { |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
406
diff
changeset
|
195 log_context = context; |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
196 if (!registered_finalize) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
197 atexit(ym_finalize_log); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
198 registered_finalize = 1; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
199 } |
369
fc820ab1394b
Fix left/right enable default value
Mike Pavone <pavone@retrodev.com>
parents:
365
diff
changeset
|
200 } |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
201 if (!did_tbl_init) { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
202 //populate sine table |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
203 for (int32_t i = 0; i < 512; i++) { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
204 double sine = sin( ((double)(i*2+1) / SINE_TABLE_SIZE) * M_PI_2 ); |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
205 |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
206 //table stores 4.8 fixed pointed representation of the base 2 log |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
207 sine_table[i] = round_fixed_point(-log2(sine), 8); |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
208 } |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
209 //populate power table |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
210 for (int32_t i = 0; i < POW_TABLE_SIZE; i++) { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
211 double linear = pow(2, -((double)((i & 0xFF)+1) / 256.0)); |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
212 int32_t tmp = round_fixed_point(linear, 11); |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
213 int32_t shift = (i >> 8) - 2; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
214 if (shift < 0) { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
215 tmp <<= 0-shift; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
216 } else { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
217 tmp >>= shift; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
218 } |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
219 pow_table[i] = tmp; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
220 } |
362 | 221 //populate envelope generator rate table, from small base table |
222 for (int rate = 0; rate < 64; rate++) { | |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
223 for (int cycle = 0; cycle < 8; cycle++) { |
362 | 224 uint16_t value; |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
225 if (rate < 2) { |
362 | 226 value = 0; |
365
3ba3b6656fff
Actually save the shifted phase inc after applying the block shift
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
227 } else if (rate >= 60) { |
362 | 228 value = 8; |
365
3ba3b6656fff
Actually save the shifted phase inc after applying the block shift
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
229 } else if (rate < 8) { |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
230 value = rate_table_base[((rate & 6) == 6 ? 16 : 0) + cycle]; |
365
3ba3b6656fff
Actually save the shifted phase inc after applying the block shift
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
231 } else if (rate < 48) { |
362 | 232 value = rate_table_base[(rate & 0x3) * 8 + cycle]; |
233 } else { | |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
234 value = rate_table_base[32 + (rate & 0x3) * 8 + cycle] << ((rate - 48) >> 2); |
362 | 235 } |
365
3ba3b6656fff
Actually save the shifted phase inc after applying the block shift
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
236 rate_table[rate * 8 + cycle] = value; |
362 | 237 } |
238 } | |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
239 //populate LFO PM table from small base table |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
240 //seems like there must be a better way to derive this |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
241 for (int freq = 0; freq < 128; freq++) { |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
242 for (int pms = 0; pms < 8; pms++) { |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
243 for (int step = 0; step < 32; step++) { |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
244 int16_t value = 0; |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
245 for (int bit = 0x40, shift = 0; bit > 0; bit >>= 1, shift++) { |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
246 if (freq & bit) { |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
247 value += lfo_pm_base[pms][(step & 0x8) ? 7-step & 7 : step & 7] >> shift; |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
248 } |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
249 } |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
250 if (step & 0x10) { |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
251 value = -value; |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
252 } |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
253 lfo_pm_table[freq * 256 + pms * 32 + step] = value; |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
254 } |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
255 } |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
256 } |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
257 } |
1308
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1301
diff
changeset
|
258 ym_reset(context); |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
259 ym_enable_zero_offset(context, 1); |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 } |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
262 void ym_free(ym2612_context *context) |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
263 { |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1450
diff
changeset
|
264 render_free_source(context->audio); |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
265 if (context == log_context) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
266 ym_finalize_log(); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
267 } |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
268 free(context); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
269 } |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
859
diff
changeset
|
270 |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
271 void ym_enable_zero_offset(ym2612_context *context, uint8_t enabled) |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
272 { |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
273 if (enabled) { |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
274 context->zero_offset = 0x70; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
275 context->volume_mult = 79; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
276 context->volume_div = 120; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
277 } else { |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
278 context->zero_offset = 0; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
279 context->volume_mult = 2; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
280 context->volume_div = 3; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
281 } |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
282 } |
381
7815ebbbd705
Fix modulation shift value
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
283 #define YM_MOD_SHIFT 1 |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
284 |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
285 #define CSM_MODE 0x80 |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
286 |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
287 #define SSG_ENABLE 8 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
288 #define SSG_INVERT 4 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
289 #define SSG_ALTERNATE 2 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
290 #define SSG_HOLD 1 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
291 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
292 #define SSG_CENTER 0x800 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
293 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
294 static void start_envelope(ym_operator *op, ym_channel *channel) |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
295 { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
296 //Deal with "infinite" attack rates |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
297 uint8_t rate = op->rates[PHASE_ATTACK]; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
298 if (rate) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
299 uint8_t ks = channel->keycode >> op->key_scaling;; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
300 rate = rate*2 + ks; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
301 } |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
302 if (rate >= 62) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
303 op->env_phase = PHASE_DECAY; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
304 op->envelope = 0; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
305 } else { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
306 op->env_phase = PHASE_ATTACK; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
307 } |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
308 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
309 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
310 static void keyon(ym_operator *op, ym_channel *channel) |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
311 { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
312 start_envelope(op, channel); |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
313 op->phase_counter = 0; |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
314 op->inverted = op->ssg & SSG_INVERT; |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
315 } |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
316 |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
317 static const uint8_t keyon_bits[] = {0x10, 0x40, 0x20, 0x80}; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
318 |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
319 static void keyoff(ym_operator *op) |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
320 { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
321 op->env_phase = PHASE_RELEASE; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
322 if (op->inverted) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
323 //Nemesis says the inversion state doesn't change here, but I don't see how that is observable either way |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
324 op->inverted = 0; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
325 op->envelope = (SSG_CENTER - op->envelope) & MAX_ENVELOPE; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
326 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
327 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
328 |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
329 static void csm_keyoff(ym2612_context *context) |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
330 { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
331 context->csm_keyon = 0; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
332 uint8_t changes = 0xF0 ^ context->channels[2].keyon; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
333 for (uint8_t op = 2*4, bit = 0; op < 3*4; op++, bit++) |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
334 { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
335 if (changes & keyon_bits[bit]) { |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
336 keyoff(context->operators + op); |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
337 } |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
338 } |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
339 } |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
340 |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 void ym_run(ym2612_context * context, uint32_t to_cycle) |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 { |
362 | 343 //printf("Running YM2612 from cycle %d to cycle %d\n", context->current_cycle, to_cycle); |
344 //TODO: Fix channel update order OR remap channels in register write | |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
379
diff
changeset
|
345 for (; context->current_cycle < to_cycle; context->current_cycle += context->clock_inc) { |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
346 //Update timers at beginning of 144 cycle period |
403 | 347 if (!context->current_op) { |
348 if (context->timer_control & BIT_TIMERA_ENABLE) { | |
349 if (context->timer_a != TIMER_A_MAX) { | |
350 context->timer_a++; | |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
351 if (context->csm_keyon) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
352 csm_keyoff(context); |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
353 } |
403 | 354 } else { |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
355 if (context->timer_control & BIT_TIMERA_LOAD) { |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
356 context->timer_control &= ~BIT_TIMERA_LOAD; |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
357 } else if (context->timer_control & BIT_TIMERA_OVEREN) { |
403 | 358 context->status |= BIT_STATUS_TIMERA; |
359 } | |
360 context->timer_a = context->timer_a_load; | |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
361 if (!context->csm_keyon && context->ch3_mode == CSM_MODE) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
362 context->csm_keyon = 0xF0; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
363 uint8_t changes = 0xF0 ^ context->channels[2].keyon;; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
364 for (uint8_t op = 2*4, bit = 0; op < 3*4; op++, bit++) |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
365 { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
366 if (changes & keyon_bits[bit]) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
367 keyon(context->operators + op, context->channels + 2); |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
368 } |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
369 } |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
370 } |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
371 } |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 } |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
373 if (!context->sub_timer_b) { |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
374 if (context->timer_control & BIT_TIMERB_ENABLE) { |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
375 if (context->timer_b != TIMER_B_MAX) { |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
376 context->timer_b++; |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
377 } else { |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
378 if (context->timer_control & BIT_TIMERB_LOAD) { |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
379 context->timer_control &= ~BIT_TIMERB_LOAD; |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
380 } else if (context->timer_control & BIT_TIMERB_OVEREN) { |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
381 context->status |= BIT_STATUS_TIMERB; |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
382 } |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
383 context->timer_b = context->timer_b_load; |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
384 } |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
385 } |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
386 } |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
387 context->sub_timer_b += 0x10; |
740
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
388 //Update LFO |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
389 if (context->lfo_enable) { |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
390 if (context->lfo_counter) { |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
391 context->lfo_counter--; |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
392 } else { |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
393 context->lfo_counter = lfo_timer_values[context->lfo_freq]; |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
394 context->lfo_am_step += 2; |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
395 context->lfo_am_step &= 0xFE; |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
396 context->lfo_pm_step = context->lfo_am_step / 8; |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
397 } |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
398 } |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
399 } |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
400 //Update Envelope Generator |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
401 if (!(context->current_op % 3)) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
402 uint32_t env_cyc = context->env_counter; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
403 uint32_t op = context->current_env_op; |
362 | 404 ym_operator * operator = context->operators + op; |
405 ym_channel * channel = context->channels + op/4; | |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
406 uint8_t rate; |
929
0ee8cfcc06d1
Change where decay to sustain transition happens to match hardware when decay rate is slow or 0
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
407 if (operator->env_phase == PHASE_DECAY && operator->envelope >= operator->sustain_level) { |
0ee8cfcc06d1
Change where decay to sustain transition happens to match hardware when decay rate is slow or 0
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
408 //operator->envelope = operator->sustain_level; |
0ee8cfcc06d1
Change where decay to sustain transition happens to match hardware when decay rate is slow or 0
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
409 operator->env_phase = PHASE_SUSTAIN; |
0ee8cfcc06d1
Change where decay to sustain transition happens to match hardware when decay rate is slow or 0
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
410 } |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
411 rate = operator->rates[operator->env_phase]; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
412 if (rate) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
413 uint8_t ks = channel->keycode >> operator->key_scaling;; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
414 rate = rate*2 + ks; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
415 if (rate > 63) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
416 rate = 63; |
362 | 417 } |
418 } | |
419 uint32_t cycle_shift = rate < 0x30 ? ((0x2F - rate) >> 2) : 0; | |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
420 if (first_key_on) { |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
421 dfprintf(debug_file, "Operator: %d, env rate: %d (2*%d+%d), env_cyc: %d, cycle_shift: %d, env_cyc & ((1 << cycle_shift) - 1): %d\n", op, rate, operator->rates[operator->env_phase], channel->keycode >> operator->key_scaling,env_cyc, cycle_shift, env_cyc & ((1 << cycle_shift) - 1)); |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
422 } |
362 | 423 if (!(env_cyc & ((1 << cycle_shift) - 1))) { |
424 uint32_t update_cycle = env_cyc >> cycle_shift & 0x7; | |
852
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
425 uint16_t envelope_inc = rate_table[rate * 8 + update_cycle]; |
362 | 426 if (operator->env_phase == PHASE_ATTACK) { |
427 //this can probably be optimized to a single shift rather than a multiply + shift | |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
428 if (first_key_on) { |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
429 dfprintf(debug_file, "Changing op %d envelope %d by %d(%d * %d) in attack phase\n", op, operator->envelope, (~operator->envelope * envelope_inc) >> 4, ~operator->envelope, envelope_inc); |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
430 } |
513
24ebabd89162
Properly clamp envelope value to zero when it overflows during the attack phase. This fixes a number of instruments that sounded rather wrong as well as the missing melody line from Mushroom Hill Zone in Sonic and Knuckles
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
431 uint16_t old_env = operator->envelope; |
852
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
432 operator->envelope += ((~operator->envelope * envelope_inc) >> 4) & 0xFFFFFFFC; |
513
24ebabd89162
Properly clamp envelope value to zero when it overflows during the attack phase. This fixes a number of instruments that sounded rather wrong as well as the missing melody line from Mushroom Hill Zone in Sonic and Knuckles
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
433 if (operator->envelope > old_env) { |
24ebabd89162
Properly clamp envelope value to zero when it overflows during the attack phase. This fixes a number of instruments that sounded rather wrong as well as the missing melody line from Mushroom Hill Zone in Sonic and Knuckles
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
434 //Handle overflow |
24ebabd89162
Properly clamp envelope value to zero when it overflows during the attack phase. This fixes a number of instruments that sounded rather wrong as well as the missing melody line from Mushroom Hill Zone in Sonic and Knuckles
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
435 operator->envelope = 0; |
24ebabd89162
Properly clamp envelope value to zero when it overflows during the attack phase. This fixes a number of instruments that sounded rather wrong as well as the missing melody line from Mushroom Hill Zone in Sonic and Knuckles
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
436 } |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
437 if (!operator->envelope) { |
362 | 438 operator->env_phase = PHASE_DECAY; |
439 } | |
440 } else { | |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
441 if (first_key_on) { |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
442 dfprintf(debug_file, "Changing op %d envelope %d by %d in %s phase\n", op, operator->envelope, envelope_inc, |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
443 operator->env_phase == PHASE_SUSTAIN ? "sustain" : (operator->env_phase == PHASE_DECAY ? "decay": "release")); |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
444 } |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
445 if (operator->ssg) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
446 if (operator->envelope < SSG_CENTER) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
447 envelope_inc *= 4; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
448 } else { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
449 envelope_inc = 0; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
450 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
451 } |
852
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
452 //envelope value is 10-bits, but it will be used as a 4.8 value |
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
453 operator->envelope += envelope_inc << 2; |
362 | 454 //clamp to max attenuation value |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
455 if ( |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
456 operator->envelope > MAX_ENVELOPE |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
457 || (operator->env_phase == PHASE_RELEASE && operator->envelope >= SSG_CENTER) |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
458 ) { |
362 | 459 operator->envelope = MAX_ENVELOPE; |
460 } | |
461 } | |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
462 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
463 context->current_env_op++; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
464 if (context->current_env_op == NUM_OPERATORS) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
465 context->current_env_op = 0; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
466 context->env_counter++; |
362 | 467 } |
468 } | |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
469 |
362 | 470 //Update Phase Generator |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
471 uint32_t channel = context->current_op / 4; |
362 | 472 if (channel != 5 || !context->dac_enable) { |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
473 uint32_t op = context->current_op; |
362 | 474 //printf("updating operator %d of channel %d\n", op, channel); |
475 ym_operator * operator = context->operators + op; | |
476 ym_channel * chan = context->channels + channel; | |
396
09328dbe6700
Fix output of algorithm 4 and make some other minor YM2612 core improvements
Mike Pavone <pavone@retrodev.com>
parents:
386
diff
changeset
|
477 uint16_t phase = operator->phase_counter >> 10 & 0x3FF; |
935
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
478 operator->phase_counter += ym_calc_phase_inc(context, operator, context->current_op); |
371
0f8a759f1ff4
Use signed ints for things that represent signed values in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
370
diff
changeset
|
479 int16_t mod = 0; |
1656
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
480 if (op & 3) { |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
481 if (operator->mod_src[0]) { |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
482 mod = *operator->mod_src[0]; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
483 if (operator->mod_src[1]) { |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
484 mod += * |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
485 operator->mod_src[1]; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
486 } |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
487 mod >>= YM_MOD_SHIFT; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
488 } |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
489 } else { |
377 | 490 if (chan->feedback) { |
527
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
491 mod = (chan->op1_old + operator->output) >> (10-chan->feedback); |
377 | 492 } |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
493 } |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
494 uint16_t env = operator->envelope; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
495 if (operator->ssg) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
496 if (env >= SSG_CENTER) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
497 if (operator->ssg & SSG_ALTERNATE) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
498 if (operator->env_phase != PHASE_RELEASE && ( |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
499 !(operator->ssg & SSG_HOLD) || ((operator->ssg ^ operator->inverted) & SSG_INVERT) == 0 |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
500 )) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
501 operator->inverted ^= SSG_INVERT; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
502 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
503 } else if (!(operator->ssg & SSG_HOLD)) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
504 phase = operator->phase_counter = 0; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
505 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
506 if ( |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
507 (operator->env_phase == PHASE_DECAY || operator->env_phase == PHASE_SUSTAIN) |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
508 && !(operator->ssg & SSG_HOLD) |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
509 ) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
510 start_envelope(operator, chan); |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
511 env = operator->envelope; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
512 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
513 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
514 if (operator->inverted) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
515 env = (SSG_CENTER - env) & MAX_ENVELOPE; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
516 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
517 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
518 env += operator->total_level; |
740
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
519 if (operator->am) { |
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
520 uint16_t base_am = (context->lfo_am_step & 0x80 ? context->lfo_am_step : ~context->lfo_am_step) & 0x7E; |
930
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
521 if (ams_shift[chan->ams] >= 0) { |
1802
1d1198f16279
Fix a couple of minor cases of extra precision in LFO implementation
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
522 env += (base_am >> ams_shift[chan->ams]) & MAX_ENVELOPE; |
930
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
523 } else { |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
524 env += base_am << (-ams_shift[chan->ams]); |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
525 } |
740
25c9e9d39997
Fix LFO counter update speed and implement amplitude modulation
Michael Pavone <pavone@retrodev.com>
parents:
739
diff
changeset
|
526 } |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
527 if (env > MAX_ENVELOPE) { |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
528 env = MAX_ENVELOPE; |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
529 } |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
530 if (first_key_on) { |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
531 dfprintf(debug_file, "op %d, base phase: %d, mod: %d, sine: %d, out: %d\n", op, phase, mod, sine_table[(phase+mod) & 0x1FF], pow_table[sine_table[phase & 0x1FF] + env]); |
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
532 } |
527
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
533 //if ((channel != 0 && channel != 4) || chan->algorithm != 5) { |
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
534 phase += mod; |
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
535 //} |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
536 |
371
0f8a759f1ff4
Use signed ints for things that represent signed values in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
370
diff
changeset
|
537 int16_t output = pow_table[sine_table[phase & 0x1FF] + env]; |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
538 if (phase & 0x200) { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
539 output = -output; |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
540 } |
527
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
541 if (op % 4 == 0) { |
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
542 chan->op1_old = operator->output; |
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
543 } |
362 | 544 operator->output = output; |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
545 //Update the channel output if we've updated all operators |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
546 if (op % 4 == 3) { |
362 | 547 if (chan->algorithm < 4) { |
548 chan->output = operator->output; | |
549 } else if(chan->algorithm == 4) { | |
396
09328dbe6700
Fix output of algorithm 4 and make some other minor YM2612 core improvements
Mike Pavone <pavone@retrodev.com>
parents:
386
diff
changeset
|
550 chan->output = operator->output + context->operators[channel * 4 + 2].output; |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
551 } else { |
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
552 output = 0; |
362 | 553 for (uint32_t op = ((chan->algorithm == 7) ? 0 : 1) + channel*4; op < (channel+1)*4; op++) { |
554 output += context->operators[op].output; | |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
555 } |
362 | 556 chan->output = output; |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
557 } |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
558 if (first_key_on) { |
371
0f8a759f1ff4
Use signed ints for things that represent signed values in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
370
diff
changeset
|
559 int16_t value = context->channels[channel].output & 0x3FE0; |
0f8a759f1ff4
Use signed ints for things that represent signed values in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
370
diff
changeset
|
560 if (value & 0x2000) { |
0f8a759f1ff4
Use signed ints for things that represent signed values in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
370
diff
changeset
|
561 value |= 0xC000; |
0f8a759f1ff4
Use signed ints for things that represent signed values in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
370
diff
changeset
|
562 } |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
563 dfprintf(debug_file, "channel %d output: %d\n", channel, (value * context->volume_mult) / context->volume_div); |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
564 } |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
565 } |
362 | 566 //puts("operator update done"); |
359
cc39629e8d06
YM2612 WIP snapshot before register refactor
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
567 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
568 context->current_op++; |
396
09328dbe6700
Fix output of algorithm 4 and make some other minor YM2612 core improvements
Mike Pavone <pavone@retrodev.com>
parents:
386
diff
changeset
|
569 if (context->current_op == NUM_OPERATORS) { |
09328dbe6700
Fix output of algorithm 4 and make some other minor YM2612 core improvements
Mike Pavone <pavone@retrodev.com>
parents:
386
diff
changeset
|
570 context->current_op = 0; |
965
5257e85364ed
Implemented linear resampling and low pass filter for the YM2612
Michael Pavone <pavone@retrodev.com>
parents:
936
diff
changeset
|
571 |
5257e85364ed
Implemented linear resampling and low pass filter for the YM2612
Michael Pavone <pavone@retrodev.com>
parents:
936
diff
changeset
|
572 int16_t left = 0, right = 0; |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
573 for (int i = 0; i < NUM_CHANNELS; i++) { |
521
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
574 int16_t value = context->channels[i].output; |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
575 if (value > 0x1FE0) { |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
576 value = 0x1FE0; |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
577 } else if (value < -0x1FF0) { |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
578 value = -0x1FF0; |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
579 } else { |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
580 value &= 0x3FE0; |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
581 if (value & 0x2000) { |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
582 value |= 0xC000; |
7565ec2ac652
Fix overflow handling on FM channel output
Michael Pavone <pavone@retrodev.com>
parents:
513
diff
changeset
|
583 } |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
379
diff
changeset
|
584 } |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
585 if (value >= 0) { |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
586 value += context->zero_offset; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
587 } else { |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
588 value -= context->zero_offset; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
589 } |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
590 if (context->channels[i].logfile) { |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
591 fwrite(&value, sizeof(value), 1, context->channels[i].logfile); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
592 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
593 if (context->channels[i].lr & 0x80) { |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
594 left += (value * context->volume_mult) / context->volume_div; |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
379
diff
changeset
|
595 } |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
596 if (context->channels[i].lr & 0x40) { |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1656
diff
changeset
|
597 right += (value * context->volume_mult) / context->volume_div; |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
598 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
599 } |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
600 render_put_stereo_sample(context->audio, left, right); |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
601 } |
965
5257e85364ed
Implemented linear resampling and low pass filter for the YM2612
Michael Pavone <pavone@retrodev.com>
parents:
936
diff
changeset
|
602 |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 } |
535
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
604 if (context->current_cycle >= context->write_cycle + (context->busy_cycles * context->clock_inc / 6)) { |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 context->status &= 0x7F; |
374 | 606 context->write_cycle = CYCLE_NEVER; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 } |
362 | 608 //printf("Done running YM2612 at cycle %d\n", context->current_cycle, to_cycle); |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 } |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 void ym_address_write_part1(ym2612_context * context, uint8_t address) |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 { |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
613 //printf("address_write_part1: %X\n", address); |
362 | 614 context->selected_reg = address; |
615 context->selected_part = 0; | |
535
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
616 context->write_cycle = context->current_cycle; |
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
617 context->busy_cycles = BUSY_CYCLES_ADDRESS; |
650
55b550fe8891
Set the busy flag after a YM-2612 address write
Michael Pavone <pavone@retrodev.com>
parents:
535
diff
changeset
|
618 context->status |= 0x80; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
619 } |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
620 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
621 void ym_address_write_part2(ym2612_context * context, uint8_t address) |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
622 { |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
623 //printf("address_write_part2: %X\n", address); |
362 | 624 context->selected_reg = address; |
625 context->selected_part = 1; | |
535
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
626 context->write_cycle = context->current_cycle; |
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
627 context->busy_cycles = BUSY_CYCLES_ADDRESS; |
650
55b550fe8891
Set the busy flag after a YM-2612 address write
Michael Pavone <pavone@retrodev.com>
parents:
535
diff
changeset
|
628 context->status |= 0x80; |
362 | 629 } |
630 | |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
631 static uint8_t fnum_to_keycode[] = { |
362 | 632 //F11 = 0 |
633 0,0,0,0,0,0,0,1, | |
634 //F11 = 1 | |
635 2,3,3,3,3,3,3,3 | |
636 }; | |
637 | |
638 //table courtesy of Nemesis | |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
639 static uint32_t detune_table[][4] = { |
362 | 640 {0, 0, 1, 2}, //0 (0x00) |
641 {0, 0, 1, 2}, //1 (0x01) | |
642 {0, 0, 1, 2}, //2 (0x02) | |
643 {0, 0, 1, 2}, //3 (0x03) | |
644 {0, 1, 2, 2}, //4 (0x04) | |
645 {0, 1, 2, 3}, //5 (0x05) | |
646 {0, 1, 2, 3}, //6 (0x06) | |
647 {0, 1, 2, 3}, //7 (0x07) | |
648 {0, 1, 2, 4}, //8 (0x08) | |
649 {0, 1, 3, 4}, //9 (0x09) | |
650 {0, 1, 3, 4}, //10 (0x0A) | |
651 {0, 1, 3, 5}, //11 (0x0B) | |
652 {0, 2, 4, 5}, //12 (0x0C) | |
653 {0, 2, 4, 6}, //13 (0x0D) | |
654 {0, 2, 4, 6}, //14 (0x0E) | |
655 {0, 2, 5, 7}, //15 (0x0F) | |
656 {0, 2, 5, 8}, //16 (0x10) | |
657 {0, 3, 6, 8}, //17 (0x11) | |
658 {0, 3, 6, 9}, //18 (0x12) | |
659 {0, 3, 7,10}, //19 (0x13) | |
660 {0, 4, 8,11}, //20 (0x14) | |
661 {0, 4, 8,12}, //21 (0x15) | |
662 {0, 4, 9,13}, //22 (0x16) | |
663 {0, 5,10,14}, //23 (0x17) | |
664 {0, 5,11,16}, //24 (0x18) | |
665 {0, 6,12,17}, //25 (0x19) | |
666 {0, 6,13,19}, //26 (0x1A) | |
667 {0, 7,14,20}, //27 (0x1B) | |
668 {0, 8,16,22}, //28 (0x1C) | |
669 {0, 8,16,22}, //29 (0x1D) | |
670 {0, 8,16,22}, //30 (0x1E) | |
671 {0, 8,16,22} | |
672 }; //31 (0x1F) | |
673 | |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1002
diff
changeset
|
674 static uint32_t ym_calc_phase_inc(ym2612_context * context, ym_operator * operator, uint32_t op) |
362 | 675 { |
676 uint32_t chan_num = op / 4; | |
677 //printf("ym_update_phase_inc | channel: %d, op: %d\n", chan_num, op); | |
678 //base frequency | |
679 ym_channel * channel = context->channels + chan_num; | |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
680 uint32_t inc, detune; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
681 if (chan_num == 2 && context->ch3_mode && (op < (2*4 + 3))) { |
738
8972378e314f
Fix register to operator mapping for channel 3 special mode
Michael Pavone <pavone@retrodev.com>
parents:
650
diff
changeset
|
682 //supplemental fnum registers are in a different order than normal slot paramters |
936
f1a8124ad881
Fix register to operator mapping for channel 3 special mode and actually get it right this time
Michael Pavone <pavone@retrodev.com>
parents:
935
diff
changeset
|
683 int index = op-2*4; |
f1a8124ad881
Fix register to operator mapping for channel 3 special mode and actually get it right this time
Michael Pavone <pavone@retrodev.com>
parents:
935
diff
changeset
|
684 if (index < 2) { |
f1a8124ad881
Fix register to operator mapping for channel 3 special mode and actually get it right this time
Michael Pavone <pavone@retrodev.com>
parents:
935
diff
changeset
|
685 index ^= 1; |
f1a8124ad881
Fix register to operator mapping for channel 3 special mode and actually get it right this time
Michael Pavone <pavone@retrodev.com>
parents:
935
diff
changeset
|
686 } |
738
8972378e314f
Fix register to operator mapping for channel 3 special mode
Michael Pavone <pavone@retrodev.com>
parents:
650
diff
changeset
|
687 inc = context->ch3_supp[index].fnum; |
935
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
688 if (channel->pms) { |
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
689 inc = inc * 2 + lfo_pm_table[(inc & 0x7F0) * 16 + channel->pms + context->lfo_pm_step]; |
1802
1d1198f16279
Fix a couple of minor cases of extra precision in LFO implementation
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
690 inc &= 0xFFF; |
935
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
691 } |
738
8972378e314f
Fix register to operator mapping for channel 3 special mode
Michael Pavone <pavone@retrodev.com>
parents:
650
diff
changeset
|
692 if (!context->ch3_supp[index].block) { |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
693 inc >>= 1; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
694 } else { |
738
8972378e314f
Fix register to operator mapping for channel 3 special mode
Michael Pavone <pavone@retrodev.com>
parents:
650
diff
changeset
|
695 inc <<= (context->ch3_supp[index].block-1); |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
696 } |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
697 //detune |
738
8972378e314f
Fix register to operator mapping for channel 3 special mode
Michael Pavone <pavone@retrodev.com>
parents:
650
diff
changeset
|
698 detune = detune_table[context->ch3_supp[index].keycode][operator->detune & 0x3]; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 } else { |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
700 inc = channel->fnum; |
935
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
701 if (channel->pms) { |
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
702 inc = inc * 2 + lfo_pm_table[(inc & 0x7F0) * 16 + channel->pms + context->lfo_pm_step]; |
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
703 } |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
704 if (!channel->block) { |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
705 inc >>= 1; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
706 } else { |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
707 inc <<= (channel->block-1); |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
708 } |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
709 //detune |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
710 detune = detune_table[channel->keycode][operator->detune & 0x3]; |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
711 } |
935
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
712 if (channel->pms) { |
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
713 inc >>= 1; |
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
714 } |
739
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
715 if (operator->detune & 0x4) { |
362 | 716 inc -= detune; |
717 //this can underflow, mask to 17-bit result | |
718 inc &= 0x1FFFF; | |
719 } else { | |
720 inc += detune; | |
721 } | |
722 //multiple | |
723 if (operator->multiple) { | |
724 inc *= operator->multiple; | |
739
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
725 inc &= 0xFFFFF; |
362 | 726 } else { |
727 //0.5 | |
728 inc >>= 1; | |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
729 } |
365
3ba3b6656fff
Actually save the shifted phase inc after applying the block shift
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
730 //printf("phase_inc for operator %d: %d, block: %d, fnum: %d, detune: %d, multiple: %d\n", op, inc, channel->block, channel->fnum, detune, operator->multiple); |
935
01fb50390b27
Remove phase increment caching. Fix LFO phase modulation calculation
Michael Pavone <pavone@retrodev.com>
parents:
930
diff
changeset
|
731 return inc; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
732 } |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
733 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
734 void ym_data_write(ym2612_context * context, uint8_t value) |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
735 { |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
736 if (context->selected_reg >= YM_REG_END) { |
362 | 737 return; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
739 if (context->selected_part) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
740 if (context->selected_reg < YM_PART2_START) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
741 return; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
742 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
743 context->part2_regs[context->selected_reg - YM_PART2_START] = value; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
744 } else { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
745 if (context->selected_reg < YM_PART1_START) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
746 return; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
747 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
748 context->part1_regs[context->selected_reg - YM_PART1_START] = value; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
448
diff
changeset
|
749 } |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
750 dfprintf(debug_file, "write of %X to reg %X in part %d\n", value, context->selected_reg, context->selected_part+1); |
362 | 751 if (context->selected_reg < 0x30) { |
752 //Shared regs | |
753 switch (context->selected_reg) | |
754 { | |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
755 //TODO: Test reg |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
756 case REG_LFO: |
532
666210adf87b
Comment out LFO debug printf
Mike Pavone <pavone@retrodev.com>
parents:
527
diff
changeset
|
757 /*if ((value & 0x8) && !context->lfo_enable) { |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
758 printf("LFO Enabled, Freq: %d\n", value & 0x7); |
532
666210adf87b
Comment out LFO debug printf
Mike Pavone <pavone@retrodev.com>
parents:
527
diff
changeset
|
759 }*/ |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
760 context->lfo_enable = value & 0x8; |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
761 if (!context->lfo_enable) { |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
762 context->lfo_am_step = context->lfo_pm_step = 0; |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
763 } |
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
764 context->lfo_freq = value & 0x7; |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
765 |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
766 break; |
362 | 767 case REG_TIMERA_HIGH: |
768 context->timer_a_load &= 0x3; | |
769 context->timer_a_load |= value << 2; | |
770 break; | |
771 case REG_TIMERA_LOW: | |
772 context->timer_a_load &= 0xFFFC; | |
773 context->timer_a_load |= value & 0x3; | |
774 break; | |
775 case REG_TIMERB: | |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
776 context->timer_b_load = value; |
362 | 777 break; |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
778 case REG_TIME_CTRL: { |
403 | 779 if (value & BIT_TIMERA_ENABLE && !(context->timer_control & BIT_TIMERA_ENABLE)) { |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
780 context->timer_a = TIMER_A_MAX; |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
781 context->timer_control |= BIT_TIMERA_LOAD; |
403 | 782 } |
783 if (value & BIT_TIMERB_ENABLE && !(context->timer_control & BIT_TIMERB_ENABLE)) { | |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
784 context->timer_b = TIMER_B_MAX; |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
785 context->timer_control |= BIT_TIMERB_LOAD; |
403 | 786 } |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
787 context->timer_control &= (BIT_TIMERA_LOAD | BIT_TIMERB_LOAD); |
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
788 context->timer_control |= value & 0xF; |
403 | 789 if (value & BIT_TIMERA_RESET) { |
790 context->status &= ~BIT_STATUS_TIMERA; | |
791 } | |
792 if (value & BIT_TIMERB_RESET) { | |
793 context->status &= ~BIT_STATUS_TIMERB; | |
794 } | |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
795 if (context->ch3_mode == CSM_MODE && (value & 0xC0) != CSM_MODE && context->csm_keyon) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
796 csm_keyoff(context); |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
797 } |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
798 context->ch3_mode = value & 0xC0; |
362 | 799 break; |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
800 } |
362 | 801 case REG_KEY_ONOFF: { |
802 uint8_t channel = value & 0x7; | |
386
6e5c4f3ab0e2
Fix channel mapping in key on/off register
Mike Pavone <pavone@retrodev.com>
parents:
383
diff
changeset
|
803 if (channel != 3 && channel != 7) { |
6e5c4f3ab0e2
Fix channel mapping in key on/off register
Mike Pavone <pavone@retrodev.com>
parents:
383
diff
changeset
|
804 if (channel > 2) { |
6e5c4f3ab0e2
Fix channel mapping in key on/off register
Mike Pavone <pavone@retrodev.com>
parents:
383
diff
changeset
|
805 channel--; |
6e5c4f3ab0e2
Fix channel mapping in key on/off register
Mike Pavone <pavone@retrodev.com>
parents:
383
diff
changeset
|
806 } |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
807 uint8_t changes = channel == 2 |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
808 ? (value | context->csm_keyon) ^ (context->channels[channel].keyon | context->csm_keyon) |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
809 : value ^ context->channels[channel].keyon; |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
810 context->channels[channel].keyon = value & 0xF0; |
851
b10cf2c921ad
Fix mapping of key on/off reg bits to operators
Michael Pavone <pavone@retrodev.com>
parents:
848
diff
changeset
|
811 for (uint8_t op = channel * 4, bit = 0; op < (channel + 1) * 4; op++, bit++) { |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
812 if (changes & keyon_bits[bit]) { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
813 if (value & keyon_bits[bit]) { |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
814 first_key_on = 1; |
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
815 //printf("Key On for operator %d in channel %d\n", op, channel); |
1300
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
816 keyon(context->operators + op, context->channels + channel); |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
817 } else { |
4b893b02444e
Basic implementation of CSM mode that should handle documented edge cases. Dodesn't handle the weird undocumented edge cases I don't have a good understanding of yet though
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
818 //printf("Key Off for operator %d in channel %d\n", op, channel); |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
819 keyoff(context->operators + op); |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
820 } |
362 | 821 } |
822 } | |
823 } | |
824 break; | |
825 } | |
826 case REG_DAC: | |
827 if (context->dac_enable) { | |
828 context->channels[5].output = (((int16_t)value) - 0x80) << 6; | |
396
09328dbe6700
Fix output of algorithm 4 and make some other minor YM2612 core improvements
Mike Pavone <pavone@retrodev.com>
parents:
386
diff
changeset
|
829 //printf("DAC Write %X(%d) @ %d\n", value, context->channels[5].output, context->current_cycle); |
362 | 830 } |
831 break; | |
832 case REG_DAC_ENABLE: | |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
833 //printf("DAC Enable: %X\n", value); |
362 | 834 context->dac_enable = value & 0x80; |
835 break; | |
836 } | |
837 } else if (context->selected_reg < 0xA0) { | |
838 //part | |
839 uint8_t op = context->selected_part ? (NUM_OPERATORS/2) : 0; | |
840 //channel in part | |
841 if ((context->selected_reg & 0x3) != 0x3) { | |
370
5f215603d001
Fix register to operator mapping. Fix rate table generation. Add TL to envelope value rather than using it as a limit for the attack phase.
Mike Pavone <pavone@retrodev.com>
parents:
369
diff
changeset
|
842 op += 4 * (context->selected_reg & 0x3) + ((context->selected_reg & 0xC) / 4); |
362 | 843 //printf("write targets operator %d (%d of channel %d)\n", op, op % 4, op / 4); |
844 ym_operator * operator = context->operators + op; | |
845 switch (context->selected_reg & 0xF0) | |
846 { | |
847 case REG_DETUNE_MULT: | |
848 operator->detune = value >> 4 & 0x7; | |
849 operator->multiple = value & 0xF; | |
850 break; | |
851 case REG_TOTAL_LEVEL: | |
852 operator->total_level = (value & 0x7F) << 5; | |
853 break; | |
854 case REG_ATTACK_KS: | |
376 | 855 operator->key_scaling = 3 - (value >> 6); |
362 | 856 operator->rates[PHASE_ATTACK] = value & 0x1F; |
857 break; | |
858 case REG_DECAY_AM: | |
739
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
859 operator->am = value & 0x80; |
362 | 860 operator->rates[PHASE_DECAY] = value & 0x1F; |
861 break; | |
862 case REG_SUSTAIN_RATE: | |
863 operator->rates[PHASE_SUSTAIN] = value & 0x1F; | |
864 break; | |
865 case REG_S_LVL_R_RATE: | |
866 operator->rates[PHASE_RELEASE] = (value & 0xF) << 1 | 1; | |
852
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
867 operator->sustain_level = (value & 0xF0) << 3; |
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
868 if (operator->sustain_level == 0x780) { |
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
869 operator->sustain_level = MAX_ENVELOPE; |
5de8759b87af
Fix some bugs in the attack phase and sustain level in the envelope generator
Michael Pavone <pavone@retrodev.com>
parents:
851
diff
changeset
|
870 } |
362 | 871 break; |
1301
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
872 case REG_SSG_EG: |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
873 if (!(value & SSG_ENABLE)) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
874 value = 0; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
875 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
876 if ((value ^ operator->ssg) & SSG_INVERT) { |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
877 operator->inverted ^= SSG_INVERT; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
878 } |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
879 operator->ssg = value; |
babff81e4cfd
Initial implementation of YM2612 SSG-EG mode
Michael Pavone <pavone@retrodev.com>
parents:
1300
diff
changeset
|
880 break; |
362 | 881 } |
882 } | |
883 } else { | |
884 uint8_t channel = context->selected_reg & 0x3; | |
885 if (channel != 3) { | |
886 if (context->selected_part) { | |
887 channel += 3; | |
888 } | |
889 //printf("write targets channel %d\n", channel); | |
890 switch (context->selected_reg & 0xFC) | |
891 { | |
892 case REG_FNUM_LOW: | |
893 context->channels[channel].block = context->channels[channel].block_fnum_latch >> 3 & 0x7; | |
894 context->channels[channel].fnum = (context->channels[channel].block_fnum_latch & 0x7) << 8 | value; | |
895 context->channels[channel].keycode = context->channels[channel].block << 2 | fnum_to_keycode[context->channels[channel].fnum >> 7]; | |
896 break; | |
897 case REG_BLOCK_FNUM_H:{ | |
898 context->channels[channel].block_fnum_latch = value; | |
899 break; | |
900 } | |
383
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
901 case REG_FNUM_LOW_CH3: |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
902 if (channel < 3) { |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
903 context->ch3_supp[channel].block = context->ch3_supp[channel].block_fnum_latch >> 3 & 0x7; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
904 context->ch3_supp[channel].fnum = (context->ch3_supp[channel].block_fnum_latch & 0x7) << 8 | value; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
905 context->ch3_supp[channel].keycode = context->ch3_supp[channel].block << 2 | fnum_to_keycode[context->ch3_supp[channel].fnum >> 7]; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
906 } |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
907 break; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
908 case REG_BLOCK_FN_CH3: |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
909 if (channel < 3) { |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
910 context->ch3_supp[channel].block_fnum_latch = value; |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
911 } |
72933100c55c
Initial implementation of channel 3 special mode
Mike Pavone <pavone@retrodev.com>
parents:
382
diff
changeset
|
912 break; |
362 | 913 case REG_ALG_FEEDBACK: |
914 context->channels[channel].algorithm = value & 0x7; | |
1656
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
915 switch (context->channels[channel].algorithm) |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
916 { |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
917 case 0: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
918 //operator 3 modulated by operator 2 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
919 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+2].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
920 context->operators[channel*4+1].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
921 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
922 //operator 2 modulated by operator 1 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
923 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
924 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
925 //operator 4 modulated by operator 3 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
926 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+1].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
927 context->operators[channel*4+3].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
928 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
929 case 1: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
930 //operator 3 modulated by operator 1+2 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
931 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
932 context->operators[channel*4+1].mod_src[1] = &context->operators[channel*4+2].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
933 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
934 //operator 2 unmodulated |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
935 context->operators[channel*4+2].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
936 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
937 //operator 4 modulated by operator 3 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
938 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+1].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
939 context->operators[channel*4+3].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
940 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
941 case 2: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
942 //operator 3 modulated by operator 2 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
943 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+2].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
944 context->operators[channel*4+1].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
945 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
946 //operator 2 unmodulated |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
947 context->operators[channel*4+2].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
948 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
949 //operator 4 modulated by operator 1+3 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
950 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
951 context->operators[channel*4+3].mod_src[1] = &context->operators[channel*4+1].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
952 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
953 case 3: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
954 //operator 3 unmodulated |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
955 context->operators[channel*4+1].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
956 context->operators[channel*4+1].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
957 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
958 //operator 2 modulated by operator 1 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
959 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
960 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
961 //operator 4 modulated by operator 2+3 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
962 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+2].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
963 context->operators[channel*4+3].mod_src[1] = &context->operators[channel*4+1].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
964 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
965 case 4: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
966 //operator 3 unmodulated |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
967 context->operators[channel*4+1].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
968 context->operators[channel*4+1].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
969 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
970 //operator 2 modulated by operator 1 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
971 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
972 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
973 //operator 4 modulated by operator 3 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
974 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+1].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
975 context->operators[channel*4+3].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
976 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
977 case 5: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
978 //operator 3 modulated by operator 1 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
979 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
980 context->operators[channel*4+1].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
981 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
982 //operator 2 modulated by operator 1 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
983 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
984 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
985 //operator 4 modulated by operator 1 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
986 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
987 context->operators[channel*4+3].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
988 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
989 case 6: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
990 //operator 3 unmodulated |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
991 context->operators[channel*4+1].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
992 context->operators[channel*4+1].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
993 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
994 //operator 2 modulated by operator 1 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
995 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
996 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
997 //operator 4 unmodulated |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
998 context->operators[channel*4+3].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
999 context->operators[channel*4+3].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1000 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1001 case 7: |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1002 //everything is an output so no modulation (except for op 1 feedback) |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1003 context->operators[channel*4+1].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1004 context->operators[channel*4+1].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1005 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1006 context->operators[channel*4+2].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1007 |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1008 context->operators[channel*4+3].mod_src[0] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1009 context->operators[channel*4+3].mod_src[1] = NULL; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1010 break; |
804f13c090b4
Optimize YM operator modulation
Mike Pavone <pavone@retrodev.com>
parents:
1654
diff
changeset
|
1011 } |
362 | 1012 context->channels[channel].feedback = value >> 3 & 0x7; |
527
7df7f493b3b6
Fix operator 1 self-feedback
Michael Pavone <pavone@retrodev.com>
parents:
522
diff
changeset
|
1013 //printf("Algorithm %d, feedback %d for channel %d\n", value & 0x7, value >> 3 & 0x7, channel); |
362 | 1014 break; |
1015 case REG_LR_AMS_PMS: | |
411
baf4688901f2
Initial stab at LFO phase modulation
Mike Pavone <pavone@retrodev.com>
parents:
407
diff
changeset
|
1016 context->channels[channel].pms = (value & 0x7) * 32; |
362 | 1017 context->channels[channel].ams = value >> 4 & 0x3; |
1018 context->channels[channel].lr = value & 0xC0; | |
369
fc820ab1394b
Fix left/right enable default value
Mike Pavone <pavone@retrodev.com>
parents:
365
diff
changeset
|
1019 //printf("Write of %X to LR_AMS_PMS reg for channel %d\n", value, channel); |
362 | 1020 break; |
1021 } | |
1022 } | |
1023 } | |
448
e85a107e6ec0
Fix handling of key on in YM2612 core
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
1024 |
362 | 1025 context->write_cycle = context->current_cycle; |
535
aaa77e351c24
Better emulation of the YM-2612 busy flag
Mike Pavone <pavone@retrodev.com>
parents:
532
diff
changeset
|
1026 context->busy_cycles = context->selected_reg < 0xA0 ? BUSY_CYCLES_DATA_LOW : BUSY_CYCLES_DATA_HIGH; |
374 | 1027 context->status |= 0x80; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1028 } |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1029 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1030 uint8_t ym_read_status(ym2612_context * context) |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1031 { |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1032 return context->status; |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1033 } |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1034 |
739
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1035 void ym_print_channel_info(ym2612_context *context, int channel) |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1036 { |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1037 ym_channel *chan = context->channels + channel; |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1038 printf("\n***Channel %d***\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1039 "Algorithm: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1040 "Feedback: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1041 "Pan: %s\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1042 "AMS: %d\n" |
845
3a18b5f63afc
Small fix to how manual YM-2612 timer reloads work. Seems to better match a small test program and gets audio to match up in TM.EE's "I've got Italo Inside" track.
Michael Pavone <pavone@retrodev.com>
parents:
740
diff
changeset
|
1043 "PMS: %d\n", |
739
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1044 channel+1, chan->algorithm, chan->feedback, |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1045 chan->lr == 0xC0 ? "LR" : chan->lr == 0x80 ? "L" : chan->lr == 0x40 ? "R" : "", |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1046 chan->ams, chan->pms); |
930
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1047 if (channel == 2) { |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1048 printf( |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1049 "Mode: %X: %s\n", |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1050 context->ch3_mode, context->ch3_mode ? "special" : "normal"); |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1051 } |
739
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1052 for (int operator = channel * 4; operator < channel * 4+4; operator++) |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1053 { |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1054 int dispnum = operator - channel * 4 + 1; |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1055 if (dispnum == 2) { |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1056 dispnum = 3; |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1057 } else if (dispnum == 3) { |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1058 dispnum = 2; |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1059 } |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1060 ym_operator *op = context->operators + operator; |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1061 printf("\nOperator %d:\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1062 " Multiple: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1063 " Detune: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1064 " Total Level: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1065 " Attack Rate: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1066 " Key Scaling: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1067 " Decay Rate: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1068 " Sustain Level: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1069 " Sustain Rate: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1070 " Release Rate: %d\n" |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1071 " Amplitude Modulation %s\n", |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1072 dispnum, op->multiple, op->detune, op->total_level, |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1073 op->rates[PHASE_ATTACK], op->key_scaling, op->rates[PHASE_DECAY], |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1074 op->sustain_level, op->rates[PHASE_SUSTAIN], op->rates[PHASE_RELEASE], |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1075 op->am ? "On" : "Off"); |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1076 } |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1077 } |
2317bdca03b4
Add a basic YM-2612 command to the debugger. Fix negative detune values and get the correct precision for the multiplication step of phase inc calculation
Michael Pavone <pavone@retrodev.com>
parents:
738
diff
changeset
|
1078 |
930
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1079 void ym_print_timer_info(ym2612_context *context) |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1080 { |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1081 printf("***Timer A***\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1082 "Current Value: %d\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1083 "Load Value: %d\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1084 "Triggered: %s\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1085 "Enabled: %s\n\n", |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1086 context->timer_a, |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1087 context->timer_a_load, |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1088 context->status & BIT_STATUS_TIMERA ? "yes" : "no", |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1089 context->timer_control & BIT_TIMERA_ENABLE ? "yes" : "no"); |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1090 printf("***Timer B***\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1091 "Current Value: %d\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1092 "Load Value: %d\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1093 "Triggered: %s\n" |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1094 "Enabled: %s\n\n", |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1095 context->timer_b, |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1096 context->timer_b_load, |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1097 context->status & BIT_STATUS_TIMERB ? "yes" : "no", |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1098 context->timer_control & BIT_TIMERB_ENABLE ? "yes" : "no"); |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1099 } |
f33e8d88ab6f
Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents:
929
diff
changeset
|
1100 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1101 void ym_serialize(ym2612_context *context, serialize_buffer *buf) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1102 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1103 save_buffer8(buf, context->part1_regs, YM_PART1_REGS); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1104 save_buffer8(buf, context->part2_regs, YM_PART2_REGS); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1105 for (int i = 0; i < NUM_OPERATORS; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1106 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1107 save_int32(buf, context->operators[i].phase_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1108 save_int16(buf, context->operators[i].envelope); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1109 save_int16(buf, context->operators[i].output); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1110 save_int8(buf, context->operators[i].env_phase); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1111 save_int8(buf, context->operators[i].inverted); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1112 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1113 for (int i = 0; i < NUM_CHANNELS; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1114 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1115 save_int16(buf, context->channels[i].output); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1116 save_int16(buf, context->channels[i].op1_old); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1117 //Due to the latching behavior, these need to be saved |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1118 //even though duplicate info is probably in the regs array |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1119 save_int8(buf, context->channels[i].block); |
1450
08bc099a622f
Save entirety of fnum register, not just the low 8 bits
Michael Pavone <pavone@retrodev.com>
parents:
1447
diff
changeset
|
1120 save_int16(buf, context->channels[i].fnum); |
1447
a094815b1168
Save and restore YM2612 timer control and keyon/off state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1121 save_int8(buf, context->channels[i].keyon); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1122 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1123 for (int i = 0; i < 3; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1124 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1125 //Due to the latching behavior, these need to be saved |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1126 //even though duplicate info is probably in the regs array |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1127 save_int8(buf, context->ch3_supp[i].block); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1128 save_int8(buf, context->ch3_supp[i].fnum); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1129 } |
1447
a094815b1168
Save and restore YM2612 timer control and keyon/off state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1130 save_int8(buf, context->timer_control); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1131 save_int16(buf, context->timer_a); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1132 save_int8(buf, context->timer_b); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1133 save_int8(buf, context->sub_timer_b); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1134 save_int16(buf, context->env_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1135 save_int8(buf, context->current_op); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1136 save_int8(buf, context->current_env_op); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1137 save_int8(buf, context->lfo_counter); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1138 save_int8(buf, context->csm_keyon); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1139 save_int8(buf, context->status); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1140 save_int8(buf, context->selected_reg); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1141 save_int8(buf, context->selected_part); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1142 save_int32(buf, context->current_cycle); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1143 save_int32(buf, context->write_cycle); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1144 save_int32(buf, context->busy_cycles); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1145 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1146 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1147 void ym_deserialize(deserialize_buffer *buf, void *vcontext) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1148 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1149 ym2612_context *context = vcontext; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1150 uint8_t temp_regs[YM_PART1_REGS]; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1151 load_buffer8(buf, temp_regs, YM_PART1_REGS); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1152 context->selected_part = 0; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1153 for (int i = 0; i < YM_PART1_REGS; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1154 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1155 uint8_t reg = YM_PART1_START + i; |
1447
a094815b1168
Save and restore YM2612 timer control and keyon/off state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1156 if (reg == REG_TIME_CTRL) { |
a094815b1168
Save and restore YM2612 timer control and keyon/off state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1157 context->ch3_mode = temp_regs[i] & 0xC0; |
a094815b1168
Save and restore YM2612 timer control and keyon/off state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1158 } else if (reg != REG_FNUM_LOW && reg != REG_KEY_ONOFF) { |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1159 context->selected_reg = reg; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1160 ym_data_write(context, temp_regs[i]); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1161 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1162 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1163 load_buffer8(buf, temp_regs, YM_PART2_REGS); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1164 context->selected_part = 1; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1165 for (int i = 0; i < YM_PART2_REGS; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1166 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1167 uint8_t reg = YM_PART2_START + i; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1168 if (reg != REG_FNUM_LOW) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1169 context->selected_reg = reg; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1170 ym_data_write(context, temp_regs[i]); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1171 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1172 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1173 for (int i = 0; i < NUM_OPERATORS; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1174 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1175 context->operators[i].phase_counter = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1176 context->operators[i].envelope = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1177 context->operators[i].output = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1178 context->operators[i].env_phase = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1179 if (context->operators[i].env_phase > PHASE_RELEASE) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1180 context->operators[i].env_phase = PHASE_RELEASE; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1181 } |
1450
08bc099a622f
Save entirety of fnum register, not just the low 8 bits
Michael Pavone <pavone@retrodev.com>
parents:
1447
diff
changeset
|
1182 context->operators[i].inverted = load_int8(buf) != 0 ? SSG_INVERT : 0; |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1183 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1184 for (int i = 0; i < NUM_CHANNELS; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1185 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1186 context->channels[i].output = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1187 context->channels[i].op1_old = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1188 context->channels[i].block = load_int8(buf); |
1450
08bc099a622f
Save entirety of fnum register, not just the low 8 bits
Michael Pavone <pavone@retrodev.com>
parents:
1447
diff
changeset
|
1189 context->channels[i].fnum = load_int16(buf); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1190 context->channels[i].keycode = context->channels[i].block << 2 | fnum_to_keycode[context->channels[i].fnum >> 7]; |
1447
a094815b1168
Save and restore YM2612 timer control and keyon/off state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1191 context->channels[i].keyon = load_int8(buf); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1192 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1193 for (int i = 0; i < 3; i++) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1194 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1195 context->ch3_supp[i].block = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1196 context->ch3_supp[i].fnum = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1197 context->ch3_supp[i].keycode = context->ch3_supp[i].block << 2 | fnum_to_keycode[context->ch3_supp[i].fnum >> 7]; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1198 } |
1447
a094815b1168
Save and restore YM2612 timer control and keyon/off state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1199 context->timer_control = load_int8(buf); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1200 context->timer_a = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1201 context->timer_b = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1202 context->sub_timer_b = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1203 context->env_counter = load_int16(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1204 context->current_op = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1205 if (context->current_op >= NUM_OPERATORS) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1206 context->current_op = 0; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1207 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1208 context->current_env_op = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1209 if (context->current_env_op >= NUM_OPERATORS) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1210 context->current_env_op = 0; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1211 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1212 context->lfo_counter = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1213 context->csm_keyon = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1214 context->status = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1215 context->selected_reg = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1216 context->selected_part = load_int8(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1217 context->current_cycle = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1218 context->write_cycle = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1219 context->busy_cycles = load_int32(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1356
diff
changeset
|
1220 } |