Mercurial > repos > blastem
annotate ymz263b.c @ 2688:b42f00a3a937 default tip
Fix default target. Ensure m68k.h and z80.h are built before anything else when no dep info is available
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Mar 2025 21:06:18 -0700 |
parents | e8eba0cd5444 |
children |
rev | line source |
---|---|
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include "ymz263b.h" |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "backend.h" |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 enum { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 YMZ_SELT, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 YMZ_LSI_TEST, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 YMZ_TIMER0_LOW, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 YMZ_TIMER0_HIGH, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 YMZ_TIMER_BASE, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 YMZ_TIMER1, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 YMZ_TIMER2_LOW, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 YMZ_TIMER2_HIGH, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 YMZ_TIMER_CTRL, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 YMZ_PCM_PLAY_CTRL, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 YMZ_PCM_VOL, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 YMZ_PCM_DATA, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 YMZ_PCM_CTRL, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 YMZ_MIDI_CTRL, |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 YMZ_MIDI_DATA |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 }; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 //YMZ_SELT |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 #define BIT_SELT 0x01 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 //YMZ_TIMER_CTRL |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 #define BIT_ST0 0x01 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 #define BIT_ST1 0x02 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 #define BIT_ST2 0x04 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 #define BIT_STBC 0x08 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #define BIT_T0_MSK 0x10 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 #define BIT_T1_MSK 0x20 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 #define BIT_T2_MSK 0x40 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 #define TIMER_RUN_MASK (BIT_ST0|BIT_ST1|BIT_ST2) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 #define TIMER_INT_MASK (BIT_T0_MSK|BIT_T1_MSK|BIT_T2_MSK) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 //YMZ_PCM_PLAY_CTRL |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
39 #define BIT_ADP_ST 0x01 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
40 #define BIT_PLY_REC 0x02 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
41 #define BIT_PCM 0x04 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
42 #define BIT_PAN_L 0x20 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
43 #define BIT_PAN_R 0x40 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 #define BIT_ADP_RST 0x80 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
46 //YMZ_PCM_FIFO_CTRL |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
47 #define BIT_DMA_ENB 0x01 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
48 #define BIT_MSK_FIF 0x02 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
49 #define BIT_DMA_MOD 0x80 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
50 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 //YMZ_MIDI_CTRL |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 #define BIT_MSK_RRQ 0x01 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 #define BIT_MRC_RST 0x02 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 #define BIT_MSK_TRQ 0x04 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 #define BIT_MTR_RST 0x08 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 #define BIT_MSK_MOV 0x10 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 #define BIT_MSK_POV 0x20 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 #define STATUS_FIF1 0x01 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 #define STATUS_FIF2 0x02 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 #define STATUS_RRQ 0x04 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 #define STATUS_TRQ 0x08 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 #define STATUS_T0 0x10 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 #define STATUS_T1 0x20 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 #define STATUS_T2 0x40 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 #define STATUS_OV 0x80 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
68 #define TIMER_DIVIDER 32 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 #define MIDI_BYTE_DIVIDER 170 |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
70 #define PCM_BASE_DIVIDER 12 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 #define FIFO_EMPTY 255 |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
73 void ymz263b_init(ymz263b *ymz, uint32_t master_clock, uint32_t clock_divider) |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 memset(ymz, 0, sizeof(*ymz)); |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
76 ymz->clock_inc = clock_divider * TIMER_DIVIDER; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
77 ymz->audio = render_audio_source("YMZ263B", master_clock, ymz->clock_inc * PCM_BASE_DIVIDER, 2); |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 ymz->base_regs[YMZ_SELT] = 1; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 ymz->pcm[0].regs[0] = BIT_ADP_RST; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 ymz->pcm[1].regs[0] = BIT_ADP_RST; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
81 ymz->pcm[0].counter = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
82 ymz->pcm[0].fifo_read = FIFO_EMPTY; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
83 ymz->pcm[1].counter = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
84 ymz->pcm[1].fifo_read = FIFO_EMPTY; |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 ymz->midi_regs[0] = BIT_MTR_RST | BIT_MRC_RST; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 ymz->midi_trs.read = ymz->midi_rcv.read = FIFO_EMPTY; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 ymz->status = 0; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
88 ymz->pcm_counter = PCM_BASE_DIVIDER; |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 |
2486
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
91 void ymz263b_free(ymz263b *ymz) |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
92 { |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
93 render_free_source(ymz->audio); |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
94 } |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
95 |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
96 void ymz263b_adjust_master_clock(ymz263b *ymz, uint32_t master_clock) |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
97 { |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
98 render_audio_adjust_clock(ymz->audio, master_clock, ymz->clock_inc * PCM_BASE_DIVIDER); |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
99 } |
e8eba0cd5444
Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents:
2471
diff
changeset
|
100 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 static uint8_t fifo_empty(ymz_midi_fifo *fifo) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 return fifo->read == FIFO_EMPTY; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 static uint8_t fifo_read(ymz_midi_fifo *fifo) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 uint8_t ret = fifo->fifo[fifo->read++]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 fifo->read &= 15; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 if (fifo->read == fifo->write) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 fifo->read = FIFO_EMPTY; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 return ret; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 static uint8_t fifo_write(ymz_midi_fifo *fifo, uint8_t value) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 uint8_t overflow = fifo->read == fifo->write; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 if (fifo->read == FIFO_EMPTY) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 fifo->read = fifo->write; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 fifo->fifo[fifo->write++] = value; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 fifo->write &= 15; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 return overflow; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 static uint8_t fifo_size(ymz_midi_fifo *fifo) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 if (fifo->read == FIFO_EMPTY) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 return 0; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 if (fifo->read == fifo->write) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 return 16; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 return (fifo->write - fifo->read) & 15; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
138 static uint8_t pcm_fifo_empty(ymz263b_pcm *pcm) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
139 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
140 return pcm->fifo_read == FIFO_EMPTY; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
141 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
142 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
143 static uint16_t pcm_fifo_read(ymz263b_pcm *pcm, uint8_t nibbles) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
144 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
145 uint16_t ret = 0; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
146 for (; nibbles && !pcm_fifo_empty(pcm); nibbles--) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
147 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
148 ret <<= 4; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
149 if (pcm->nibble) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
150 ret |= pcm->fifo[pcm->fifo_read++] & 0xF; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
151 pcm->fifo_read &= sizeof(pcm->fifo) - 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
152 pcm->nibble = 0; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
153 if (pcm->fifo_read == pcm->fifo_write) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
154 pcm->fifo_read = FIFO_EMPTY; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
155 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
156 } else { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
157 ret |= pcm->fifo[pcm->fifo_read] >> 4; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
158 pcm->nibble = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
159 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
160 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
161 return ret; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
162 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
163 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
164 static uint8_t pcm_fifo_write(ymz263b_pcm *pcm, uint8_t nibbles, uint16_t value) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
165 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
166 uint8_t overflow = 0; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
167 value <<= (4 - nibbles) * 4; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
168 for (; nibbles; nibbles--) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
169 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
170 if (pcm->nibble_write) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
171 pcm->fifo[pcm->fifo_write++] |= value >> 12; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
172 pcm->fifo_write &= sizeof(pcm->fifo) - 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
173 pcm->nibble_write = 0; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
174 } else { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
175 if (pcm->fifo_read == FIFO_EMPTY) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
176 pcm->fifo_read = pcm->fifo_write; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
177 } else if (pcm->fifo_read == pcm->fifo_write) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
178 overflow = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
179 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
180 pcm->fifo[pcm->fifo_write] = value >> 8 & 0xF0; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
181 pcm->nibble_write = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
182 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
183 value <<= 4; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
184 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
185 return overflow; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
186 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
187 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
188 static uint8_t pcm_fifo_free(ymz263b_pcm *pcm) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
189 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
190 if (pcm->fifo_read == FIFO_EMPTY) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
191 return sizeof(pcm->fifo); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
192 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
193 return (pcm->fifo_read - pcm->fifo_write) & (sizeof(pcm->fifo) - 1); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
194 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
195 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
196 static uint8_t pcm_dividers[] = {1, 2, 4, 6, 8}; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
197 static void ymz263b_pcm_run(ymz263b *ymz, ymz263b_pcm *pcm, int16_t *output) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
198 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
199 if ((pcm->regs[0] & (BIT_ADP_RST|BIT_ADP_ST)) != BIT_ADP_ST) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
200 //PCM channel is either in reset or not started |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
201 return; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
202 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
203 pcm->counter--; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
204 if (!pcm->counter) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
205 uint8_t fs = pcm->regs[0] >> 3 & 3; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
206 if (!(pcm->regs[0] & BIT_PCM)) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
207 //ADPCM can't use 44.1 kHz, but gains 5.5125 kHz |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
208 fs++; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
209 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
210 pcm->counter = pcm_dividers[fs]; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
211 uint8_t nibbles = (pcm->regs[3] >> 5 & 3) + 2; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
212 if (nibbles > 4) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
213 //4-bit format is encoded as the highest value for some reason |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
214 nibbles = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
215 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
216 //adlib driver suggests that FMT should be 3 for 4-bit ADPCM, but Copera games seem to use zero |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
217 //maybe FMT is ignored for ADPCM mode? |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
218 if (!(pcm->regs[0] & BIT_PCM)) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
219 nibbles = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
220 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
221 //adlib driver sets SELF to 5 for playback to trigger int "when less than 32 bytes in fifo" aka 96 bytes free |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
222 //adlib driver sets SELF to 3 for recording to trigger int "when more than 64 bytes in fifo" aka 64 bytes free |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
223 uint8_t fifo_threshold = ((pcm->regs[3] >> 2 & 7) + 1) << 4; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
224 if (pcm->regs[0] & BIT_PLY_REC) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
225 //Playback mode |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
226 uint16_t sample = pcm_fifo_read(pcm, nibbles); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
227 if (pcm->regs[0] & BIT_PCM) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
228 //TODO: Presumably SELT bit impacts this |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
229 if (sample & (1 << (nibbles * 4 - 1))) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
230 sample |= 0xFFF << (nibbles * 4); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
231 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
232 switch (nibbles) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
233 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
234 case 1: |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
235 sample <<= 8; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
236 break; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
237 case 2: |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
238 sample <<= 4; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
239 break; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
240 case 4: |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
241 //PCem's code seems to imply the "hole" is in the middle |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
242 //but that's ugly so hoping it's incorrect |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
243 sample >>= 4; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
244 break; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
245 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
246 pcm->output = sample; |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
247 if (pcm->output & 0x800) { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
248 pcm->output |= 0xF000; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
249 } else { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
250 pcm->output &= 0x0FFF; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
251 } |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
252 } else { |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
253 //This uses superctr's YMZ280B decoder as a reference |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
254 //That chip has 16-bit output, but supposedly is compatible |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
255 //with ADPCM data from the YM263B |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
256 //Currently I'm 'calculating as 16-bit internally and |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
257 //truncating to 12-bit on output |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
258 uint16_t mag = sample & 7; |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
259 int32_t delta = (((mag << 1) + 1) * pcm->adpcm_step) >> 3; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
260 if (delta > 0x7FFF) { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
261 delta = 0x7FFF; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
262 } |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
263 if (sample & 8) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
264 delta = -delta; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
265 } |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
266 int32_t value = ((int16_t)pcm->output); |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
267 value = (value * 254) >> 8; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
268 value += delta; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
269 if (value > 0x7FFF) { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
270 value = 0x7FFF; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
271 } else if (value < -0x8000) { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
272 value = -0x8000; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
273 } |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
274 pcm->output = value; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
275 |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
276 static const uint16_t step_adjust[8] = { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
277 230, 230, 230, 230, 307, 409, 512, 614 |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
278 }; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
279 int32_t step = pcm->adpcm_step * step_adjust[mag]; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
280 if (step > 24576) { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
281 step = 24576; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
282 } else if (step < 127) { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
283 step = 127; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
284 } |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
285 pcm->adpcm_step = step; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
286 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
287 if (pcm_fifo_free(pcm) > fifo_threshold) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
288 ymz->status |= pcm == &ymz->pcm[0] ? STATUS_FIF1 : STATUS_FIF2; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
289 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
290 } else { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
291 //Recording mode |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
292 //TODO: support recording actual audio input |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
293 if (pcm_fifo_write(pcm, nibbles, 0)) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
294 ymz->status |= STATUS_OV; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
295 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
296 if (pcm_fifo_free(pcm) < fifo_threshold) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
297 ymz->status |= pcm == &ymz->pcm[0] ? STATUS_FIF1 : STATUS_FIF2; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
298 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
299 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
300 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
301 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
302 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
303 if (pcm->regs[0] & BIT_PLY_REC) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
304 //TODO: Volume |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
305 int16_t value = pcm->output; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
306 if (!(pcm->regs[0] & BIT_PCM)) { |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
307 value >>= 4; |
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
308 } |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
309 if (pcm->regs[0] & BIT_PAN_L) { |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
310 output[0] += value; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
311 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
312 if (pcm->regs[0] & BIT_PAN_R) { |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
313 output[1] += value; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
314 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
315 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
316 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
317 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 void ymz263b_run(ymz263b *ymz, uint32_t target_cycle) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 uint8_t timer_ctrl = ymz->base_regs[YMZ_TIMER_CTRL]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 for (; ymz->cycle < target_cycle; ymz->cycle += ymz->clock_inc) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 if (timer_ctrl & BIT_ST0) { |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
324 ymz->timers[0]--; |
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
325 if (!ymz->timers[0]) { |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 ymz->timers[0] = ymz->base_regs[YMZ_TIMER0_HIGH] << 8 | ymz->base_regs[YMZ_TIMER0_LOW]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 ymz->status |= STATUS_T0; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 if (timer_ctrl & BIT_STBC) { |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
331 ymz->timers[3]--; |
2467
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
332 ymz->timers[3] &= 0xFFF; |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
333 if (!ymz->timers[3]) { |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 ymz->timers[3] = ymz->base_regs[YMZ_TIMER1] << 8 & 0xF00; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 ymz->timers[3] |= ymz->base_regs[YMZ_TIMER_BASE]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 if (timer_ctrl & BIT_ST1) { |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
338 ymz->timers[1]--; |
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
339 if (!ymz->timers[1]) { |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 ymz->timers[1] = ymz->base_regs[YMZ_TIMER1] >> 4; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 ymz->status |= STATUS_T1; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 if (timer_ctrl & BIT_ST2) { |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
346 ymz->timers[2]--; |
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
347 if (!ymz->timers[2]) { |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 ymz->timers[2] = ymz->base_regs[YMZ_TIMER2_HIGH] << 8 | ymz->base_regs[YMZ_TIMER2_LOW]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 ymz->status |= STATUS_T2; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 if (!(ymz->midi_regs[0] & BIT_MTR_RST) && !fifo_empty(&ymz->midi_trs)) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 if (ymz->midi_transmit) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 --ymz->midi_transmit; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 } else { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 ymz->midi_transmit = MIDI_BYTE_DIVIDER - 1; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 //TODO: send this byte to MIDI device |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 uint8_t byte = fifo_read(&ymz->midi_trs); |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 printf("MIDI Transmit: %X\n", byte); |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 if (fifo_empty(&ymz->midi_trs)) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 ymz->status |= STATUS_TRQ; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 } |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
367 ymz->pcm_counter--; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
368 if (!ymz->pcm_counter) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
369 ymz->pcm_counter = PCM_BASE_DIVIDER; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
370 int16_t output[2] = {0, 0}; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
371 ymz263b_pcm_run(ymz, &ymz->pcm[0], output); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
372 ymz263b_pcm_run(ymz, &ymz->pcm[1], output); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
373 render_put_stereo_sample(ymz->audio, output[0], output[1]); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
374 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
378 static uint32_t predict_fifo_thres(ymz263b *ymz, ymz263b_pcm *pcm) |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
379 { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
380 if ((pcm->regs[0] & (BIT_ADP_RST|BIT_ADP_ST)) != BIT_ADP_ST) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
381 //PCM channel is either in reset or not started |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
382 return CYCLE_NEVER; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
383 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
384 uint32_t next_pcm_cycle = ymz->cycle + ymz->pcm_counter * ymz->clock_inc; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
385 next_pcm_cycle += (pcm->counter - 1) * PCM_BASE_DIVIDER * ymz->clock_inc; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
386 uint32_t fifo_free = pcm_fifo_free(pcm); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
387 //convert to nibbles |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
388 fifo_free <<= 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
389 uint32_t fifo_threshold = ((pcm->regs[3] >> 2 & 7) + 1) << 5; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
390 uint32_t diff; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
391 if (pcm->regs[0] & BIT_PLY_REC) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
392 if (pcm->nibble) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
393 fifo_free++; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
394 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
395 diff = fifo_threshold - fifo_free + 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
396 } else { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
397 if (pcm->nibble_write) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
398 fifo_free--; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
399 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
400 diff = fifo_free - fifo_threshold + 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
401 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
402 uint32_t nibbles_per_samp = (pcm->regs[3] >> 5 & 3) + 2; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
403 if (nibbles_per_samp > 4) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
404 //4-bit format is encoded as the highest value for some reason |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
405 nibbles_per_samp = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
406 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
407 uint8_t fs = pcm->regs[0] >> 3 & 3; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
408 if (!(pcm->regs[0] & BIT_PCM)) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
409 //ADPCM can't use 44.1 kHz, but gains 5.5125 kHz |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
410 fs++; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
411 //see note in PCM playback code |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
412 nibbles_per_samp = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
413 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
414 diff /= nibbles_per_samp; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
415 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
416 next_pcm_cycle += diff * PCM_BASE_DIVIDER * pcm_dividers[fs] * ymz->clock_inc; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
417 return next_pcm_cycle; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
418 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
419 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 uint32_t ymz263b_next_int(ymz263b *ymz) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 { |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
422 //TODO: Handle MIDI receive interrupts |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 uint8_t enabled_ints = (~ymz->base_regs[YMZ_TIMER_CTRL]) & TIMER_INT_MASK; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 if (!(ymz->base_regs[YMZ_MIDI_CTRL] & (BIT_MTR_RST|BIT_MSK_TRQ))) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 enabled_ints |= STATUS_TRQ; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 } |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
427 if (!(ymz->pcm[0].regs[3] & BIT_MSK_FIF)) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
428 enabled_ints |= STATUS_FIF1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
429 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
430 if (!(ymz->pcm[1].regs[3] & BIT_MSK_FIF)) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
431 enabled_ints |= STATUS_FIF2; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
432 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 if (!enabled_ints) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 return CYCLE_NEVER; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 //Handle currently pending interrupts |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 if (enabled_ints & ymz->status) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 return ymz->cycle; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 } |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
440 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 uint32_t ret = CYCLE_NEVER; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 if (enabled_ints & STATUS_TRQ) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 uint8_t bytes = fifo_size(&ymz->midi_trs); |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 if (bytes) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 ret = ymz->cycle + (ymz->midi_transmit + 1) * ymz->clock_inc; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 if (bytes > 1) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 ret += MIDI_BYTE_DIVIDER * ymz->clock_inc * (bytes - 1); |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 } |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
451 |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
452 if (enabled_ints & STATUS_FIF1) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
453 uint32_t next_pcm = predict_fifo_thres(ymz, &ymz->pcm[0]); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
454 if (next_pcm < ret) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
455 ret = next_pcm; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
456 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
457 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
458 if (enabled_ints & STATUS_FIF2) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
459 uint32_t next_pcm = predict_fifo_thres(ymz, &ymz->pcm[1]); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
460 if (next_pcm < ret) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
461 ret = next_pcm; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
462 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
463 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
464 |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 enabled_ints >>= 4; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 //If timers aren't already expired, interrupts can't fire unless the timers are enabled |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 enabled_ints &= ymz->base_regs[YMZ_TIMER_CTRL]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 if (!(ymz->base_regs[YMZ_TIMER_CTRL] & BIT_STBC)) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 //Timer 1 and Timer 2 depend on the base timer |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 enabled_ints &= 1; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 if (enabled_ints & BIT_ST0) { |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
473 uint32_t t0 = ymz->cycle + (ymz->timers[0] ? ymz->timers[0] : 0x10000) * ymz->clock_inc; |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 if (t0 < ret) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 ret = t0; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 if (enabled_ints & (BIT_ST1|BIT_ST2)) { |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
479 uint32_t base = ymz->cycle + (ymz->timers[3] ? ymz->timers[3] : 0x1000) * ymz->clock_inc; |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 if (base < ret) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 uint32_t load = (ymz->base_regs[YMZ_TIMER1] << 8 & 0xF00) | ymz->base_regs[YMZ_TIMER_BASE]; |
2461
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
482 if (!load) { |
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
483 load = 0x1000; |
a25e8f304343
Fix handling of zero timer value
Michael Pavone <pavone@retrodev.com>
parents:
2460
diff
changeset
|
484 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 if (enabled_ints & BIT_ST1) { |
2467
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
486 uint32_t t1 = base + (ymz->timers[1] ? ymz->timers[1] - 1 : 0xF) * load * ymz->clock_inc; |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 if (t1 < ret) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 ret = t1; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 if (enabled_ints & BIT_ST2) { |
2467
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
492 uint32_t t2 = base + (ymz->timers[2] ? ymz->timers[2] - 1 : 0xFFFF) * load * ymz->clock_inc; |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 if (t2 < ret) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 ret = t2; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 return ret; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 void ymz263b_address_write(ymz263b *ymz, uint8_t value) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 ymz->address = value; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 void ymz263b_data_write(ymz263b *ymz, uint32_t channel, uint8_t value) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 if (channel) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 if (ymz->address >= YMZ_PCM_PLAY_CTRL && ymz->address < YMZ_MIDI_CTRL) { |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
511 if (ymz->address == YMZ_PCM_PLAY_CTRL) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
512 if (((value ^ ymz->pcm[1].regs[0]) & ymz->pcm[1].regs[0]) & BIT_ADP_RST) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
513 //Perform reset on falling edge of reset bit |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
514 ymz->pcm[1].counter = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
515 ymz->pcm[1].fifo_read = FIFO_EMPTY; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
516 ymz->pcm[1].nibble = ymz->pcm[1].nibble_write = 0; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
517 ymz->pcm[1].output = 0; |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
518 ymz->pcm[1].adpcm_step = 127; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
519 } |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
520 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 ymz->pcm[1].regs[ymz->address - YMZ_PCM_PLAY_CTRL] = value; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
522 if (ymz->address == YMZ_PCM_DATA) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
523 pcm_fifo_write(&ymz->pcm[1], 2, value); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
524 //Does an overflow here set the overflow statu sflag? |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
525 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 } else { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 if (ymz->address < YMZ_PCM_PLAY_CTRL) { |
2467
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
529 if (ymz->address == YMZ_TIMER_CTRL) { |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
530 uint8_t newly_set = (ymz->base_regs[ymz->address] ^ value) & value; |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
531 if (newly_set & BIT_ST0) { |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
532 ymz->timers[0] = ymz->base_regs[YMZ_TIMER0_HIGH] << 8 | ymz->base_regs[YMZ_TIMER0_LOW]; |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
533 } |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
534 if (newly_set & BIT_ST1) { |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
535 ymz->timers[1] = ymz->base_regs[YMZ_TIMER1] >> 4; |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
536 } |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
537 if (newly_set & BIT_ST2) { |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
538 ymz->timers[2] = ymz->base_regs[YMZ_TIMER2_HIGH] << 8 | ymz->base_regs[YMZ_TIMER2_LOW]; |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
539 } |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
540 if (newly_set & BIT_STBC) { |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
541 ymz->timers[0] = (ymz->base_regs[YMZ_TIMER1] << 8 | ymz->base_regs[YMZ_TIMER_BASE]) & 0xFFF; |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
542 } |
bf8a77a8ddc4
Fix some YMZ263B timer issues
Michael Pavone <pavone@retrodev.com>
parents:
2466
diff
changeset
|
543 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 ymz->base_regs[ymz->address] = value; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 } else if (ymz->address < YMZ_MIDI_CTRL) { |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
546 if (((value ^ ymz->pcm[0].regs[0]) & ymz->pcm[1].regs[0]) & BIT_ADP_RST) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
547 //Perform reset on falling edge of reset bit |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
548 ymz->pcm[0].counter = 1; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
549 ymz->pcm[0].fifo_read = FIFO_EMPTY; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
550 ymz->pcm[0].nibble = ymz->pcm[1].nibble_write = 0; |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
551 ymz->pcm[0].output = 0; |
2471
2f4c17b4fe10
Switch to YMZ280B ADPCM algorithm. Still sounds a little rough, but definitely much better than with the YM2610 ADPCM-A setup
Michael Pavone <pavone@retrodev.com>
parents:
2467
diff
changeset
|
552 ymz->pcm[0].adpcm_step = 127; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
553 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 ymz->pcm[0].regs[ymz->address - YMZ_PCM_PLAY_CTRL] = value; |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
555 if (ymz->address == YMZ_PCM_DATA) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
556 pcm_fifo_write(&ymz->pcm[0], 2, value); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
557 //Does an overflow here set the overflow statu sflag? |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
558 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
559 } else { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
560 ymz->midi_regs[ymz->address - YMZ_MIDI_CTRL] = value; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
561 if (ymz->address == YMZ_MIDI_DATA) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
562 ymz->status &= ~STATUS_TRQ; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
563 if (fifo_empty(&ymz->midi_trs)) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 ymz->midi_transmit = MIDI_BYTE_DIVIDER - 1; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
565 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
566 fifo_write(&ymz->midi_trs, value); |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
567 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
568 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
569 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
570 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
571 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
572 uint8_t ymz263b_data_read(ymz263b *ymz, uint32_t channel) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
573 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
574 //TODO: Supposedly only a few registers are actually readable |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
575 if (channel) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
576 if (ymz->address >= YMZ_PCM_PLAY_CTRL && ymz->address < YMZ_MIDI_CTRL) { |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
577 if (ymz->address == YMZ_PCM_DATA) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
578 return pcm_fifo_read(&ymz->pcm[1], 2); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
579 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
580 return ymz->pcm[1].regs[ymz->address - YMZ_PCM_PLAY_CTRL]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
581 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
582 } else { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
583 if (ymz->address < YMZ_PCM_PLAY_CTRL) { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 return ymz->base_regs[ymz->address]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
585 } else if (ymz->address < YMZ_MIDI_CTRL) { |
2466
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
586 if (ymz->address == YMZ_PCM_DATA) { |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
587 return pcm_fifo_read(&ymz->pcm[0], 2); |
b5640ac9aea9
Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents:
2461
diff
changeset
|
588 } |
2460
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
589 return ymz->pcm[0].regs[ymz->address - YMZ_PCM_PLAY_CTRL]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
590 } else { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
591 return ymz->midi_regs[ymz->address - YMZ_MIDI_CTRL]; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
592 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
593 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 return 0XFF; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
595 } |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 uint8_t ymz263b_status_read(ymz263b *ymz) |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 { |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 uint8_t ret = ymz->status; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 ymz->status = 0;//&= ~(STATUS_T0|STATUS_T1|STATUS_T2); |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 return ret; |
a4f8fa24764b
Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 } |