Debian Codegraph @

src/engine/platform/sound/tia/AudioChannel.cpp

raw
1 //============================================================================
2 //
3 // SSSS tt lll lll
4 // SS SS tt ll ll
5 // SS tttttt eeee ll ll aaaa
6 // SSSS tt ee ee ll ll aa
7 // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8 // SS SS tt ee ll ll aa aa
9 // SSSS ttt eeeee llll llll aaaaa
10 //
11 // Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony
12 // and the Stella Team
13 //
14 // See the file "License.txt" for information on usage and redistribution of
15 // this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 //============================================================================
17
18 #include "AudioChannel.h"
19
20 namespace TIA {
21
22 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 void AudioChannel::reset()
24 {
25 myAudc = myAudv = myAudf = 0;
26 myClockEnable = myNoiseFeedback = myNoiseCounterBit4 = myPulseCounterHold = false;
27 myDivCounter = myPulseCounter = myNoiseCounter = 0;
28 }
29
30 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 void AudioChannel::phase0()
32 {
33 if (myClockEnable) {
34 myNoiseCounterBit4 = myNoiseCounter & 0x01;
35
36 switch (myAudc & 0x03) {
37 case 0x00:
38 case 0x01:
39 myPulseCounterHold = false;
40 break;
41
42 case 0x02:
43 myPulseCounterHold = (myNoiseCounter & 0x1e) != 0x02;
44 break;
45
46 case 0x03:
47 myPulseCounterHold = !myNoiseCounterBit4;
48 break;
49 }
50
51 switch (myAudc & 0x03) {
52 case 0x00:
53 myNoiseFeedback =
54 ((myPulseCounter ^ myNoiseCounter) & 0x01) ||
55 !(myNoiseCounter || (myPulseCounter != 0x0a)) ||
56 !(myAudc & 0x0c);
57
58 break;
59
60 default:
61 myNoiseFeedback =
62 (((myNoiseCounter & 0x04) ? 1 : 0) ^ (myNoiseCounter & 0x01)) ||
63 myNoiseCounter == 0;
64
65 break;
66 }
67 }
68
69 myClockEnable = myDivCounter == myAudf;
70
71 if (myDivCounter == myAudf || myDivCounter == 0x1f) {
72 myDivCounter = 0;
73 } else {
74 ++myDivCounter;
75 }
76 }
77
78 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79 unsigned char AudioChannel::phase1()
80 {
81 if (myClockEnable) {
82 bool pulseFeedback = false;
83 switch (myAudc >> 2) {
84 case 0x00:
85 pulseFeedback =
86 (((myPulseCounter & 0x02) ? 1 : 0) ^ (myPulseCounter & 0x01)) &&
87 (myPulseCounter != 0x0a) &&
88 (myAudc & 0x03);
89
90 break;
91
92 case 0x01:
93 pulseFeedback = !(myPulseCounter & 0x08);
94 break;
95
96 case 0x02:
97 pulseFeedback = !myNoiseCounterBit4;
98 break;
99
100 case 0x03:
101 pulseFeedback = !((myPulseCounter & 0x02) || !(myPulseCounter & 0x0e));
102 break;
103 }
104
105 myNoiseCounter >>= 1;
106 if (myNoiseFeedback) {
107 myNoiseCounter |= 0x10;
108 }
109
110 if (!myPulseCounterHold) {
111 myPulseCounter = ~(myPulseCounter >> 1) & 0x07;
112
113 if (pulseFeedback) {
114 myPulseCounter |= 0x08;
115 }
116 }
117 }
118
119 return (myPulseCounter & 0x01) * myAudv;
120 }
121
122 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123 void AudioChannel::audc(unsigned char value)
124 {
125 myAudc = value & 0x0f;
126 }
127
128 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
129 void AudioChannel::audv(unsigned char value)
130 {
131 myAudv = value & 0x0f;
132 }
133
134 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135 void AudioChannel::audf(unsigned char value)
136 {
137 myAudf = value & 0x1f;
138 }
139
140 }