Replace remaining bit-packed structs in audio with bitfields

This commit is contained in:
Jeffrey Pfau 2014-10-07 00:53:39 -07:00
parent d2adc2449a
commit 54bda1757e
2 changed files with 101 additions and 52 deletions

View File

@ -44,9 +44,30 @@ void GBAAudioReset(struct GBAAudio* audio) {
audio->nextSample = 0; audio->nextSample = 0;
audio->sampleRate = 0x8000; audio->sampleRate = 0x8000;
audio->soundbias = 0x200; audio->soundbias = 0x200;
audio->soundcntLo = 0; audio->volumeRight = 0;
audio->soundcntHi = 0; audio->volumeLeft = 0;
audio->soundcntX = 0; audio->ch1Right = false;
audio->ch2Right = false;
audio->ch3Right = false;
audio->ch4Right = false;
audio->ch1Left = false;
audio->ch2Left = false;
audio->ch3Left = false;
audio->ch4Left = false;
audio->volume = 0;
audio->volumeChA = false;
audio->volumeChB = false;
audio->chARight = false;
audio->chALeft = false;
audio->chATimer = false;
audio->chBRight = false;
audio->chBLeft = false;
audio->chBTimer = false;
audio->playingCh1 = false;
audio->playingCh2 = false;
audio->playingCh3 = false;
audio->playingCh4 = false;
audio->enable = false;
audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate; audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate;
CircleBufferClear(&audio->left); CircleBufferClear(&audio->left);
@ -366,15 +387,33 @@ void GBAAudioWriteSOUND4CNT_HI(struct GBAAudio* audio, uint16_t value) {
} }
void GBAAudioWriteSOUNDCNT_LO(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUNDCNT_LO(struct GBAAudio* audio, uint16_t value) {
audio->soundcntLo = value; audio->volumeRight = GBARegisterSOUNDCNT_LOGetVolumeRight(value);
audio->volumeLeft = GBARegisterSOUNDCNT_LOGetVolumeLeft(value);
audio->ch1Right = GBARegisterSOUNDCNT_LOGetCh1Right(value);
audio->ch2Right = GBARegisterSOUNDCNT_LOGetCh2Right(value);
audio->ch3Right = GBARegisterSOUNDCNT_LOGetCh3Right(value);
audio->ch4Right = GBARegisterSOUNDCNT_LOGetCh4Right(value);
audio->ch1Left = GBARegisterSOUNDCNT_LOGetCh1Left(value);
audio->ch2Left = GBARegisterSOUNDCNT_LOGetCh2Left(value);
audio->ch3Left = GBARegisterSOUNDCNT_LOGetCh3Left(value);
audio->ch4Left = GBARegisterSOUNDCNT_LOGetCh4Left(value);
} }
void GBAAudioWriteSOUNDCNT_HI(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUNDCNT_HI(struct GBAAudio* audio, uint16_t value) {
audio->soundcntHi = value; audio->volume = GBARegisterSOUNDCNT_HIGetVolume(value);
audio->volumeChA = GBARegisterSOUNDCNT_HIGetVolumeChA(value);
audio->volumeChB = GBARegisterSOUNDCNT_HIGetVolumeChB(value);
audio->chARight = GBARegisterSOUNDCNT_HIGetChARight(value);
audio->chALeft = GBARegisterSOUNDCNT_HIGetChALeft(value);
audio->chATimer = GBARegisterSOUNDCNT_HIGetChATimer(value);
audio->chBRight = GBARegisterSOUNDCNT_HIGetChBRight(value);
audio->chBLeft = GBARegisterSOUNDCNT_HIGetChBLeft(value);
audio->chBTimer = GBARegisterSOUNDCNT_HIGetChBTimer(value);
// TODO: Implement channel reset
} }
void GBAAudioWriteSOUNDCNT_X(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUNDCNT_X(struct GBAAudio* audio, uint16_t value) {
audio->soundcntX = (value & 0x80) | (audio->soundcntX & 0x0F); audio->enable = GBARegisterSOUNDCNT_XGetEnable(value);
} }
void GBAAudioWriteSOUNDBIAS(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUNDBIAS(struct GBAAudio* audio, uint16_t value) {

View File

@ -124,6 +124,38 @@ struct GBAAudioFIFO {
int8_t sample; int8_t sample;
}; };
DECL_BITFIELD(GBARegisterSOUNDCNT_LO, uint16_t);
DECL_BITS(GBARegisterSOUNDCNT_LO, VolumeRight, 0, 3);
DECL_BITS(GBARegisterSOUNDCNT_LO, VolumeLeft, 4, 3);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch1Right, 8);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch2Right, 9);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch3Right, 10);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch4Right, 11);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch1Left, 12);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch2Left, 13);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch3Left, 14);
DECL_BIT(GBARegisterSOUNDCNT_LO, Ch4Left, 15);
DECL_BITFIELD(GBARegisterSOUNDCNT_HI, uint16_t);
DECL_BITS(GBARegisterSOUNDCNT_HI, Volume, 0, 2);
DECL_BIT(GBARegisterSOUNDCNT_HI, VolumeChA, 2);
DECL_BIT(GBARegisterSOUNDCNT_HI, VolumeChB, 3);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChARight, 8);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChALeft, 9);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChATimer, 10);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChAReset, 11);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChBRight, 12);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChBLeft, 13);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChBTimer, 14);
DECL_BIT(GBARegisterSOUNDCNT_HI, ChBReset, 15);
DECL_BITFIELD(GBARegisterSOUNDCNT_X, uint16_t);
DECL_BIT(GBARegisterSOUNDCNT_X, PlayingCh1, 0);
DECL_BIT(GBARegisterSOUNDCNT_X, PlayingCh2, 1);
DECL_BIT(GBARegisterSOUNDCNT_X, PlayingCh3, 2);
DECL_BIT(GBARegisterSOUNDCNT_X, PlayingCh4, 3);
DECL_BIT(GBARegisterSOUNDCNT_X, Enable, 7);
struct GBAAudio { struct GBAAudio {
struct GBA* p; struct GBA* p;
@ -138,54 +170,32 @@ struct GBAAudio {
struct CircleBuffer left; struct CircleBuffer left;
struct CircleBuffer right; struct CircleBuffer right;
union { uint8_t volumeRight;
struct { uint8_t volumeLeft;
unsigned volumeRight : 3; bool ch1Right;
unsigned : 1; bool ch2Right;
unsigned volumeLeft : 3; bool ch3Right;
unsigned : 1; bool ch4Right;
unsigned ch1Right : 1; bool ch1Left;
unsigned ch2Right : 1; bool ch2Left;
unsigned ch3Right : 1; bool ch3Left;
unsigned ch4Right : 1; bool ch4Left;
unsigned ch1Left : 1;
unsigned ch2Left : 1;
unsigned ch3Left : 1;
unsigned ch4Left : 1;
};
uint16_t soundcntLo;
};
union { uint8_t volume;
struct { bool volumeChA;
unsigned volume : 2; bool volumeChB;
unsigned volumeChA : 1; bool chARight;
unsigned volumeChB : 1; bool chALeft;
unsigned : 4; bool chATimer;
unsigned chARight : 1; bool chBRight;
unsigned chALeft : 1; bool chBLeft;
unsigned chATimer : 1; bool chBTimer;
unsigned chAReset : 1;
unsigned chBRight : 1;
unsigned chBLeft : 1;
unsigned chBTimer : 1;
unsigned chBReset : 1;
};
uint16_t soundcntHi;
};
union { bool playingCh1;
struct { bool playingCh2;
unsigned playingCh1 : 1; bool playingCh3;
unsigned playingCh2 : 1; bool playingCh4;
unsigned playingCh3 : 1; bool enable;
unsigned playingCh4 : 1;
unsigned : 3;
unsigned enable : 1;
unsigned : 8;
};
uint16_t soundcntX;
};
unsigned sampleRate; unsigned sampleRate;