annotate rf5c164.c @ 2299:a1c9edf44c7e

Fix a place I missed a problem from the SDL2 upgrade
author Michael Pavone <pavone@retrodev.com>
date Thu, 09 Mar 2023 22:59:29 -0800
parents 9ead0fe69d9b
children 0343f0d5add0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdio.h>
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "rf5c164.h"
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 enum {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 ENV,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 PAN,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 FDL,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 FDH,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 LSL,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 LSH,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 ST,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 CTRL,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 CHAN_ENABLE
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 };
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 enum {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 START,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 NORMAL,
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 LOOP
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 };
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 #define FLAG_SOUNDING 0x80
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 #define FLAG_PENDING 0x01
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 void rf5c164_init(rf5c164* pcm, uint32_t mclks, uint32_t divider)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 pcm->audio = render_audio_source("rf5c164", mclks, divider * 384, 2);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 pcm->clock_step = divider * 4;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30
2164
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2145
diff changeset
31 void rf5c164_deinit(rf5c164* pcm)
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2145
diff changeset
32 {
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2145
diff changeset
33 render_free_source(pcm->audio);
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2145
diff changeset
34 }
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2145
diff changeset
35
2278
5a21bc0ec583 Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2276
diff changeset
36 void rf5c164_adjust_master_clock(rf5c164* pcm, uint32_t mclks)
5a21bc0ec583 Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2276
diff changeset
37 {
5a21bc0ec583 Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2276
diff changeset
38 render_audio_adjust_clock(pcm->audio, mclks, pcm->clock_step * 96);
5a21bc0ec583 Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2276
diff changeset
39 }
5a21bc0ec583 Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2276
diff changeset
40
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 //48 cycles per channel
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 //1 external write per 16 cycles
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 //3 external writes per channel/sample
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 // TCE pulse width is 200ns @ 10Mhz aka 2 cycles
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 // total cycle is longer than TCE pulse, guessing 4 cycles
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 // 12 memory access slots per channel sample
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 // 3 for external memory writes
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 // 1 for internal register writes?
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 // 1 for refresh?
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 // 6 for register reads?
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 // or maybe 7 for register reads and writes happen when register is read?
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 #define CHECK pcm->cycle += pcm->clock_step; pcm->step++; if (pcm->cycle >= cycle) break
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 #define CHECK_LOOP pcm->cycle += pcm->clock_step; pcm->step = 0; if (pcm->cycle >= cycle) break
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 static void write_if_not_sounding(rf5c164* pcm)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 if (!(pcm->flags & FLAG_SOUNDING) && (pcm->flags & FLAG_PENDING)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 && pcm->pending_address >= 0x1000) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 pcm->ram[(pcm->pending_address & 0xFFF) | pcm->ram_bank] = pcm->pending_byte;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 pcm->flags &= ~FLAG_PENDING;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 static void write_always(rf5c164* pcm)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 if ((pcm->flags & FLAG_PENDING) && pcm->pending_address >= 0x1000) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 pcm->ram[(pcm->pending_address & 0xFFF) | pcm->ram_bank] = pcm->pending_byte;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 pcm->flags &= ~FLAG_PENDING;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 void rf5c164_run(rf5c164* pcm, uint32_t cycle)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 //TODO: Timing of this is all educated guesses based on documentation, do some real measurements
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 while (pcm->cycle < cycle)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 switch (pcm->step)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 case 0:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 //handle internal memory write
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 // RF5C164 datasheet seems to suggest only 1 "internal memory" write every 48 cycles when the chip is not sounding (globally)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 // and 1 write every 384 cycles when the chip is sounding (globally). However, games seem to expect to be able to write faster than that
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 // RF5C68 datasheet suggests internal memory writes are unrestricted regardless of sounding status
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 /*if ((pcm->cur_channel == pcm->selected_channel || !(pcm->flags & FLAG_SOUNDING)) && (pcm->flags & FLAG_PENDING)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 && pcm->pending_address <= ST
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 ) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 printf("pcm_write commit chan %d, %X - %X @ %u\n", pcm->selected_channel, pcm->pending_address, pcm->pending_byte, pcm->cycle);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 pcm->channels[pcm->selected_channel].regs[pcm->pending_address] = pcm->pending_byte;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 pcm->flags &= ~FLAG_PENDING;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 }*/
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 case 1:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 if ((pcm->flags & FLAG_SOUNDING) && !(pcm->channel_enable & (1 << pcm->cur_channel))) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 if (pcm->channels[pcm->cur_channel].state == START) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 pcm->channels[pcm->cur_channel].cur_ptr = pcm->channels[pcm->cur_channel].regs[ST] << 19;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 //printf("chan %d START %X (%X raw)\n", pcm->cur_channel, pcm->channels[pcm->cur_channel].cur_ptr >> 11, pcm->channels[pcm->cur_channel].cur_ptr);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 pcm->channels[pcm->cur_channel].state = NORMAL;
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
100 pcm->channels[pcm->cur_channel].trigger = 1;
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 } else if (pcm->channels[pcm->cur_channel].state == LOOP) {
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
102 uint32_t old_ptr = pcm->channels[pcm->cur_channel].cur_ptr;
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 pcm->channels[pcm->cur_channel].cur_ptr = (pcm->channels[pcm->cur_channel].regs[LSH] << 19) | (pcm->channels[pcm->cur_channel].regs[LSL] << 11);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 //printf("chan %d LOOP %X (%X raw)\n", pcm->cur_channel, pcm->channels[pcm->cur_channel].cur_ptr >> 11, pcm->channels[pcm->cur_channel].cur_ptr);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 pcm->channels[pcm->cur_channel].state = NORMAL;
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
106 pcm->channels[pcm->cur_channel].trigger = old_ptr != pcm->channels[pcm->cur_channel].cur_ptr;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
107 } else {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
108 pcm->channels[pcm->cur_channel].trigger = 0;
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 case 2: {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 if ((pcm->flags & FLAG_SOUNDING) && !(pcm->channel_enable & (1 << pcm->cur_channel))) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 uint8_t byte = pcm->ram[pcm->channels[pcm->cur_channel].cur_ptr >> 11];
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 if (byte == 0xFF) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 pcm->channels[pcm->cur_channel].state = LOOP;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 } else {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 pcm->channels[pcm->cur_channel].sample = byte;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 case 3:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 write_always(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 case 4:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 if ((pcm->flags & FLAG_SOUNDING) && !(pcm->channel_enable & (1 << pcm->cur_channel))) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 pcm->channels[pcm->cur_channel].cur_ptr += (pcm->channels[pcm->cur_channel].regs[FDH] << 8) | pcm->channels[pcm->cur_channel].regs[FDL];
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 pcm->channels[pcm->cur_channel].cur_ptr &= 0x7FFFFFF;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 case 5:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 case 6:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 case 7:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 write_always(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 case 8:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 case 9:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 if ((pcm->flags & FLAG_SOUNDING) && !(pcm->channel_enable & (1 << pcm->cur_channel))) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 int16_t sample = pcm->channels[pcm->cur_channel].sample & 0x7F;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 if (!(pcm->channels[pcm->cur_channel].sample & 0x80)) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 sample = -sample;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 sample *= pcm->channels[pcm->cur_channel].regs[ENV];
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 int16_t left = (sample * (pcm->channels[pcm->cur_channel].regs[PAN] >> 4)) >> 5;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 int16_t right = (sample * (pcm->channels[pcm->cur_channel].regs[PAN] & 0xF)) >> 5;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 //printf("chan %d, raw %X, sample %d, left %d, right %d, ptr %X (raw %X)\n", pcm->cur_channel, pcm->channels[pcm->cur_channel].sample, sample, left, right, pcm->channels[pcm->cur_channel].cur_ptr >> 11, pcm->channels[pcm->cur_channel].cur_ptr);
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
157 if (pcm->scope) {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
158 scope_add_sample(pcm->scope, pcm->channels[pcm->cur_channel].scope_channel, sample, pcm->channels[pcm->cur_channel].trigger);
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
159 }
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 pcm->left += left;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 pcm->right += right;
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
162 } else if (pcm->scope) {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
163 scope_add_sample(pcm->scope, pcm->channels[pcm->cur_channel].scope_channel, 0, 0);
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 write_if_not_sounding(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 case 10:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 //refresh?
2128
b0dcf5c9f353 Fix some issues with PCM dma/CPU write conflicts
Michael Pavone <pavone@retrodev.com>
parents: 2082
diff changeset
169 //does refresh happen at the same rate when sounding disabled? warning in sega docs suggests maybe not
b0dcf5c9f353 Fix some issues with PCM dma/CPU write conflicts
Michael Pavone <pavone@retrodev.com>
parents: 2082
diff changeset
170 write_if_not_sounding(pcm);
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 CHECK;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 case 11:
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 write_always(pcm);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 pcm->cur_channel++;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 pcm->cur_channel &= 7;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 if (!pcm->cur_channel) {
2145
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
177 if (pcm->left > INT16_MAX) {
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
178 pcm->left = INT16_MAX;
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
179 } else if (pcm->left < INT16_MIN) {
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
180 pcm->left = INT16_MIN;
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
181 }
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
182 if (pcm->right > INT16_MAX) {
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
183 pcm->right = INT16_MAX;
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
184 } else if (pcm->right < INT16_MIN) {
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
185 pcm->right = INT16_MIN;
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
186 }
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 render_put_stereo_sample(pcm->audio, pcm->left, pcm->right);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 pcm->left = pcm->right = 0;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 CHECK_LOOP;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 void rf5c164_write(rf5c164* pcm, uint16_t address, uint8_t value)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 //printf("pcm_write %X - %X @ %u\n", address, value, pcm->cycle);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 if (address == CTRL) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 pcm->flags &= ~FLAG_SOUNDING;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 pcm->flags |= value & FLAG_SOUNDING;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 if (value & 0x40) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 pcm->selected_channel = value & 0x7;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 //printf("selected channel %d\n", pcm->selected_channel);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 } else {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 pcm->ram_bank = value << 12 & 0xF000;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 //printf("selected RAM bank %X\n", pcm->ram_bank);
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 if (!(pcm->flags & FLAG_SOUNDING)) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 pcm->left = pcm->right = 0;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 } else if (address == CHAN_ENABLE) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 uint8_t changed = pcm->channel_enable ^ value;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 pcm->channel_enable = value;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 for (int i = 0; i < 8; i++)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 int mask = 1 << i;
2145
62a53c052d9b PCM channel add should saturate on overflow, not wrap around
Michael Pavone <pavone@retrodev.com>
parents: 2128
diff changeset
217 if ((changed & mask) && !(mask & value)) {
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 pcm->channels[i].state = START;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 } else if (address <= ST) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
222 //See note in first step of rf5c164_run
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 pcm->channels[pcm->selected_channel].regs[address] = value;
2276
709036ee222a Don't set write pending flag for non-existent RF5C164 registers
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
224 } else if (address > 0x1000){
2082
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 pcm->pending_address = address;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 pcm->pending_byte = value;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 pcm->flags |= FLAG_PENDING;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 uint8_t rf5c164_read(rf5c164* pcm, uint16_t address)
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 if (address >= 0x10 && address < 0x20) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 uint16_t chan = address >> 1 & 0x7;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 if (address & 1) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 return pcm->channels[chan].cur_ptr >> 19;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 } else {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 return pcm->channels[chan].cur_ptr >> 11;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 } else if (address >= 0x1000 && !(pcm->flags & FLAG_SOUNDING)) {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 return pcm->ram[pcm->ram_bank | (address & 0xFFF)];
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 } else {
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 return 0xFF;
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 }
485834c0fea7 Forgot to add PCM source files
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 }
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
246
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
247 void rf5c164_enable_scope(rf5c164* pcm, oscilloscope *scope)
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
248 {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
249 static const char *names[] = {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
250 "Richo #1",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
251 "Richo #2",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
252 "Richo #3",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
253 "Richo #4",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
254 "Richo #5",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
255 "Richo #6",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
256 "Richo #7",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
257 "Richo #8",
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
258 };
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
259 pcm->scope = scope;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
260 for (int i = 0; i < 8; i ++)
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
261 {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
262 pcm->channels[i].scope_channel = scope_add_channel(scope, names[i], 50000000 / (pcm->clock_step * 96));
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
263 }
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
264 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
265
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
266 void rf5c164_serialize(rf5c164* pcm, serialize_buffer *buf)
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
267 {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
268 save_int32(buf, pcm->cycle);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
269 save_buffer16(buf, pcm->ram, sizeof(pcm->ram)/sizeof(*pcm->ram));
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
270 save_int16(buf, pcm->ram_bank);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
271 save_int16(buf, pcm->pending_address);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
272 save_int32(buf, pcm->left);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
273 save_int32(buf, pcm->right);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
274 for (int i = 0; i < 8; i++)
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
275 {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
276 rf5c164_channel *chan = pcm->channels + i;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
277 save_int32(buf, chan->cur_ptr);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
278 save_buffer8(buf, chan->regs, sizeof(chan->regs));
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
279 save_int8(buf, chan->sample);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
280 }
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
281 save_int8(buf, pcm->pending_byte);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
282 save_int8(buf, pcm->channel_enable);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
283 save_int8(buf, pcm->selected_channel);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
284 save_int8(buf, pcm->cur_channel);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
285 save_int8(buf, pcm->step);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
286 save_int8(buf, pcm->flags);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
287 }
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
288
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
289 void rf5c164_deserialize(deserialize_buffer *buf, void *vpcm)
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
290 {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
291 rf5c164 *pcm = vpcm;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
292 pcm->cycle = load_int32(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
293 load_buffer16(buf, pcm->ram, sizeof(pcm->ram)/sizeof(*pcm->ram));
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
294 pcm->ram_bank = load_int16(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
295 pcm->pending_address = load_int16(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
296 pcm->left = load_int32(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
297 pcm->right = load_int32(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
298 for (int i = 0; i < 8; i++)
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
299 {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
300 rf5c164_channel *chan = pcm->channels + i;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
301 chan->cur_ptr = load_int32(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
302 load_buffer8(buf, chan->regs, sizeof(chan->regs));
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
303 chan->sample = load_int8(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
304 }
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
305 pcm->pending_byte = load_int8(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
306 pcm->channel_enable = load_int8(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
307 pcm->selected_channel = load_int8(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
308 pcm->cur_channel = load_int8(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
309 pcm->step = load_int8(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
310 pcm->flags = load_int8(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
311 }