comparison ym2612.c @ 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.
author Michael Pavone <pavone@retrodev.com>
date Sat, 31 Oct 2015 21:11:40 -0700
parents 25c9e9d39997
children 7068a9db6dd0
comparison
equal deleted inserted replaced
844:74e161fe7d39 845:3a18b5f63afc
55 #define BIT_TIMERB_ENABLE 0x2 55 #define BIT_TIMERB_ENABLE 0x2
56 #define BIT_TIMERA_OVEREN 0x4 56 #define BIT_TIMERA_OVEREN 0x4
57 #define BIT_TIMERB_OVEREN 0x8 57 #define BIT_TIMERB_OVEREN 0x8
58 #define BIT_TIMERA_RESET 0x10 58 #define BIT_TIMERA_RESET 0x10
59 #define BIT_TIMERB_RESET 0x20 59 #define BIT_TIMERB_RESET 0x20
60
61 #define BIT_TIMERA_LOAD 0x40
62 #define BIT_TIMERB_LOAD 0x80
60 63
61 #define BIT_STATUS_TIMERA 0x1 64 #define BIT_STATUS_TIMERA 0x1
62 #define BIT_STATUS_TIMERB 0x2 65 #define BIT_STATUS_TIMERB 0x2
63 66
64 enum { 67 enum {
239 #define YM_VOLUME_MULTIPLIER 2 242 #define YM_VOLUME_MULTIPLIER 2
240 #define YM_VOLUME_DIVIDER 3 243 #define YM_VOLUME_DIVIDER 3
241 #define YM_MOD_SHIFT 1 244 #define YM_MOD_SHIFT 1
242 245
243 #define TIMER_A_MAX 1023 246 #define TIMER_A_MAX 1023
244 #define TIMER_B_MAX (255*16) 247 #define TIMER_B_MAX 255
245 248
246 void ym_run(ym2612_context * context, uint32_t to_cycle) 249 void ym_run(ym2612_context * context, uint32_t to_cycle)
247 { 250 {
248 //printf("Running YM2612 from cycle %d to cycle %d\n", context->current_cycle, to_cycle); 251 //printf("Running YM2612 from cycle %d to cycle %d\n", context->current_cycle, to_cycle);
249 //TODO: Fix channel update order OR remap channels in register write 252 //TODO: Fix channel update order OR remap channels in register write
252 if (!context->current_op) { 255 if (!context->current_op) {
253 if (context->timer_control & BIT_TIMERA_ENABLE) { 256 if (context->timer_control & BIT_TIMERA_ENABLE) {
254 if (context->timer_a != TIMER_A_MAX) { 257 if (context->timer_a != TIMER_A_MAX) {
255 context->timer_a++; 258 context->timer_a++;
256 } else { 259 } else {
257 if (context->timer_control & BIT_TIMERA_OVEREN) { 260 if (context->timer_control & BIT_TIMERA_LOAD) {
261 context->timer_control &= ~BIT_TIMERA_LOAD;
262 } else if (context->timer_control & BIT_TIMERA_OVEREN) {
258 context->status |= BIT_STATUS_TIMERA; 263 context->status |= BIT_STATUS_TIMERA;
259 } 264 }
260 context->timer_a = context->timer_a_load; 265 context->timer_a = context->timer_a_load;
261 } 266 }
262 } 267 }
263 if (context->timer_control & BIT_TIMERB_ENABLE) { 268 if (!context->sub_timer_b) {
264 if (context->timer_b != TIMER_B_MAX) { 269 if (context->timer_control & BIT_TIMERB_ENABLE) {
265 context->timer_b++; 270 if (context->timer_b != TIMER_B_MAX) {
266 } else { 271 context->timer_b++;
267 if (context->timer_control & BIT_TIMERB_OVEREN) { 272 } else {
268 context->status |= BIT_STATUS_TIMERB; 273 if (context->timer_control & BIT_TIMERB_LOAD) {
269 } 274 context->timer_control &= ~BIT_TIMERB_LOAD;
270 context->timer_b = context->timer_b_load; 275 } else if (context->timer_control & BIT_TIMERB_OVEREN) {
271 } 276 context->status |= BIT_STATUS_TIMERB;
272 } 277 }
278 context->timer_b = context->timer_b_load;
279 }
280 }
281 }
282 context->sub_timer_b += 0x10;
273 //Update LFO 283 //Update LFO
274 if (context->lfo_enable) { 284 if (context->lfo_enable) {
275 if (context->lfo_counter) { 285 if (context->lfo_counter) {
276 context->lfo_counter--; 286 context->lfo_counter--;
277 } else { 287 } else {
670 case REG_TIMERA_LOW: 680 case REG_TIMERA_LOW:
671 context->timer_a_load &= 0xFFFC; 681 context->timer_a_load &= 0xFFFC;
672 context->timer_a_load |= value & 0x3; 682 context->timer_a_load |= value & 0x3;
673 break; 683 break;
674 case REG_TIMERB: 684 case REG_TIMERB:
675 context->timer_b_load = value * 16; 685 context->timer_b_load = value;
676 break; 686 break;
677 case REG_TIME_CTRL: { 687 case REG_TIME_CTRL: {
678 if (value & BIT_TIMERA_ENABLE && !(context->timer_control & BIT_TIMERA_ENABLE)) { 688 if (value & BIT_TIMERA_ENABLE && !(context->timer_control & BIT_TIMERA_ENABLE)) {
679 context->timer_a = context->timer_a_load; 689 context->timer_a = TIMER_A_MAX;
690 context->timer_control |= BIT_TIMERA_LOAD;
680 } 691 }
681 if (value & BIT_TIMERB_ENABLE && !(context->timer_control & BIT_TIMERB_ENABLE)) { 692 if (value & BIT_TIMERB_ENABLE && !(context->timer_control & BIT_TIMERB_ENABLE)) {
682 context->timer_b = context->timer_b_load; 693 context->timer_b = TIMER_B_MAX;
683 } 694 context->timer_control |= BIT_TIMERB_LOAD;
684 context->timer_control = value & 0xF; 695 }
696 context->timer_control &= (BIT_TIMERA_LOAD | BIT_TIMERB_LOAD);
697 context->timer_control |= value & 0xF;
685 if (value & BIT_TIMERA_RESET) { 698 if (value & BIT_TIMERA_RESET) {
686 context->status &= ~BIT_STATUS_TIMERA; 699 context->status &= ~BIT_STATUS_TIMERA;
687 } 700 }
688 if (value & BIT_TIMERB_RESET) { 701 if (value & BIT_TIMERB_RESET) {
689 context->status &= ~BIT_STATUS_TIMERB; 702 context->status &= ~BIT_STATUS_TIMERB;
835 printf("\n***Channel %d***\n" 848 printf("\n***Channel %d***\n"
836 "Algorithm: %d\n" 849 "Algorithm: %d\n"
837 "Feedback: %d\n" 850 "Feedback: %d\n"
838 "Pan: %s\n" 851 "Pan: %s\n"
839 "AMS: %d\n" 852 "AMS: %d\n"
840 "PMS: %d\n", 853 "PMS: %d\n",
841 channel+1, chan->algorithm, chan->feedback, 854 channel+1, chan->algorithm, chan->feedback,
842 chan->lr == 0xC0 ? "LR" : chan->lr == 0x80 ? "L" : chan->lr == 0x40 ? "R" : "", 855 chan->lr == 0xC0 ? "LR" : chan->lr == 0x80 ? "L" : chan->lr == 0x40 ? "R" : "",
843 chan->ams, chan->pms); 856 chan->ams, chan->pms);
844 for (int operator = channel * 4; operator < channel * 4+4; operator++) 857 for (int operator = channel * 4; operator < channel * 4+4; operator++)
845 { 858 {