Mercurial > repos > blastem
comparison psg.c @ 2243:0d1d5dccdd28
Initial implementation of oscilloscope debug view
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 22 Nov 2022 17:57:02 -0800 |
parents | 71b0cb7c34a6 |
children | 0e927fce8941 |
comparison
equal
deleted
inserted
replaced
2240:8e8db9141209 | 2243:0d1d5dccdd28 |
---|---|
17 context->clock_inc = clock_div; | 17 context->clock_inc = clock_div; |
18 for (int i = 0; i < 4; i++) { | 18 for (int i = 0; i < 4; i++) { |
19 context->volume[i] = 0xF; | 19 context->volume[i] = 0xF; |
20 } | 20 } |
21 context->pan = 0xFF; | 21 context->pan = 0xFF; |
22 } | |
23 | |
24 void psg_enable_scope(psg_context *context, oscilloscope *scope) | |
25 { | |
26 context->scope = scope; | |
27 static const char *names[] = { | |
28 "PSG #1", | |
29 "PSG #2", | |
30 "PSG #3", | |
31 "PSG Noise", | |
32 }; | |
33 for (int i = 0; i < 4; i++) | |
34 { | |
35 context->scope_channel[i] = scope_add_channel(scope, names[i], 53693175 / context->clock_inc); | |
36 } | |
22 } | 37 } |
23 | 38 |
24 void psg_free(psg_context *context) | 39 void psg_free(psg_context *context) |
25 { | 40 { |
26 render_free_source(context->audio); | 41 render_free_source(context->audio); |
89 }; | 104 }; |
90 | 105 |
91 void psg_run(psg_context * context, uint32_t cycles) | 106 void psg_run(psg_context * context, uint32_t cycles) |
92 { | 107 { |
93 while (context->cycles < cycles) { | 108 while (context->cycles < cycles) { |
109 uint8_t trigger[4] = {0,0,0,0}; | |
94 for (int i = 0; i < 4; i++) { | 110 for (int i = 0; i < 4; i++) { |
95 if (context->counters[i]) { | 111 if (context->counters[i]) { |
96 context->counters[i] -= 1; | 112 context->counters[i] -= 1; |
97 } | 113 } |
98 if (!context->counters[i]) { | 114 if (!context->counters[i]) { |
99 context->counters[i] = context->counter_load[i]; | 115 context->counters[i] = context->counter_load[i]; |
100 context->output_state[i] = !context->output_state[i]; | 116 context->output_state[i] = !context->output_state[i]; |
117 trigger[i] = context->output_state[i]; | |
101 if (i == 3 && context->output_state[i]) { | 118 if (i == 3 && context->output_state[i]) { |
102 context->noise_out = context->lsfr & 1; | 119 context->noise_out = context->lsfr & 1; |
103 context->lsfr = (context->lsfr >> 1) | (context->lsfr << 15); | 120 context->lsfr = (context->lsfr >> 1) | (context->lsfr << 15); |
104 if (context->noise_type) { | 121 if (context->noise_type) { |
105 //white noise | 122 //white noise |
112 } | 129 } |
113 | 130 |
114 int16_t left_accum = 0, right_accum = 0; | 131 int16_t left_accum = 0, right_accum = 0; |
115 uint8_t pan_left = 0x10, pan_right = 0x1; | 132 uint8_t pan_left = 0x10, pan_right = 0x1; |
116 | 133 |
134 int16_t value = 0; | |
117 for (int i = 0; i < 3; i++) { | 135 for (int i = 0; i < 3; i++) { |
118 if (context->output_state[i]) { | 136 if (context->output_state[i]) { |
119 int16_t value = volume_table[context->volume[i]]; | 137 value = volume_table[context->volume[i]]; |
120 if (context->pan & pan_left) { | 138 if (context->pan & pan_left) { |
121 left_accum += value; | 139 left_accum += value; |
122 } | 140 } |
123 if (context->pan & pan_right) { | 141 if (context->pan & pan_right) { |
124 right_accum += value; | 142 right_accum += value; |
125 } | 143 } |
126 pan_left <<= 1; | 144 pan_left <<= 1; |
127 pan_right <<= 1; | 145 pan_right <<= 1; |
128 } | 146 } |
129 } | 147 if (context->scope) { |
148 scope_add_sample(context->scope, context->scope_channel[i], value, trigger[i]); | |
149 } | |
150 } | |
151 value = 0; | |
130 if (context->noise_out) { | 152 if (context->noise_out) { |
131 int16_t value = volume_table[context->volume[3]]; | 153 value = volume_table[context->volume[3]]; |
132 if (context->pan & pan_left) { | 154 if (context->pan & pan_left) { |
133 left_accum += value; | 155 left_accum += value; |
134 } | 156 } |
135 if (context->pan & pan_right) { | 157 if (context->pan & pan_right) { |
136 right_accum += value; | 158 right_accum += value; |
137 } | 159 } |
160 } | |
161 if (context->scope) { | |
162 scope_add_sample(context->scope, context->scope_channel[3], value, trigger[3]); | |
138 } | 163 } |
139 | 164 |
140 render_put_stereo_sample(context->audio, left_accum, right_accum); | 165 render_put_stereo_sample(context->audio, left_accum, right_accum); |
141 | 166 |
142 context->cycles += context->clock_inc; | 167 context->cycles += context->clock_inc; |