Commit 3f887b7f authored by Sergio Costas's avatar Sergio Costas

Cleaning code

parent 0e4f477b
......@@ -63,7 +63,7 @@ SPK_AY::SPK_AY() {
/* emulates the AY-3-8912 during TSTADOS tstates */
void SPK_AY::play_ay (int tstados) {
static unsigned int noise = 1; // init value assigned on AY chip reset
static unsigned int env_period, noise_period, tone_period_a,tone_period_b,tone_period_c;
......@@ -73,20 +73,20 @@ void SPK_AY::play_ay (int tstados) {
* Matthew Westcott, adjusted as Philip Kendall described in a followup to his post,
* then scaled to 0..0xff. Taken from FUSE.
*/
static const unsigned int levels[16] = {
0x00, 0x03, 0x05, 0x07,
0x0A, 0x0F, 0x15, 0x23,
0x2B, 0x43, 0x5A, 0x73,
0x92, 0xAF, 0xD9, 0xFF
};
if (!this->ay_emul)
return;
this->tst_ay += tstados;
this->tst_ay2 += tstados;
// A note about the period of tones, noise and envelope: careful studies of the chip
// output prove that it counts up from 0 until the counter becomes
// greater or equal to the period. This is an important when the
......@@ -94,18 +94,18 @@ void SPK_AY::play_ay (int tstados) {
// Also, note that period = 0 is the same as period = 1. This is mentioned
// in the YM2203 data sheets. However, this does NOT apply to the Envelope
// period. In that case, period = 0 is half as period = 1.
//The frequency of AY-3-8912 is half the ZX Spectrum frequency
//Envelope
//Envelope frequency is 1/(256*envelop_period) of AY-3-8912 frequency
if (this->tst_ay2 > 127) {
this->tst_ay2 -= 128;
env_period=2*(((unsigned int) this->ay_registers[11]) + 256 * ((unsigned int) (this->ay_registers[12])));
if (!env_period) env_period = 1;
if (this->aych_envel<env_period) // to check
this->aych_envel++;
else {
......@@ -130,7 +130,7 @@ void SPK_AY::play_ay (int tstados) {
this->ay_envel_value = -1;
}
if (this->ay_envel_way & 0x04) // cycle started?
{
{
switch ((this->
ay_registers[13]) & 0x0F)
{
......@@ -205,28 +205,27 @@ void SPK_AY::play_ay (int tstados) {
}
}
}
}
//Tone and noise
//Tone frequency is 1/(16*tone_period) of AY-3-8912 frequency
//Noise frequency is 1/(16*noise_period) of AY-3-8912 frequency
while (this->tst_ay > 15)
{
while (this->tst_ay > 15) {
this->tst_ay -= 16;
tone_period_a= ((unsigned int) this->ay_registers[0]) + 256 * ((unsigned int) ((this->ay_registers[1]) & 0x0F));
tone_period_b= ((unsigned int) this->ay_registers[2]) + 256 * ((unsigned int) ((this->ay_registers[3]) & 0x0F));
tone_period_c= ((unsigned int) this->ay_registers[4]) + 256 * ((unsigned int) ((this->ay_registers[5]) & 0x0F));
noise_period= ((unsigned int) this->ay_registers[6]) & 0x1F;
if (!noise_period) noise_period = 1;
if (tone_period_a * llsound->freq < 110841) //Freq_camp > cpufreq/(2*16*tone_period)
if (!noise_period)
noise_period = 1;
if (tone_period_a * llsound->freq < 110841) { //Freq_camp > cpufreq/(2*16*tone_period)
this->aych_a =1;
else
{
} else {
if (this->aych_a<tone_period_a)
this->aych_a++;
else
......@@ -248,7 +247,7 @@ void SPK_AY::play_ay (int tstados) {
this->aych_b =0;
}
}
if (tone_period_c * llsound->freq < 110841) //Freq_camp > cpufreq/(2*16*tone_period)
this->aych_c =1;
else
......@@ -261,24 +260,24 @@ void SPK_AY::play_ay (int tstados) {
this->aych_c =0;
}
}
if (this->aych_n<noise_period)
this->aych_n++;
else
{
//from FUSE
//rng is 17-bit shift reg, bit 0 is output.
//input is bit 0 xor bit 2.
/*
if( ( noise & 1 ) ^ ( ( noise & 2 ) ? 1 : 0 ) ) this->ayval_n = !this->ayval_n;
noise |= ( ( noise & 1 ) ^ ( ( noise & 4 ) ? 1 : 0 ) ) ? 0x20000 : 0;
noise >>= 1;
*/
//From MAME AY
/* The Random Number Generator of the 8910 is a 17-bit shift */
/* register. The input to the shift register is bit0 XOR bit3 */
......@@ -289,42 +288,38 @@ void SPK_AY::play_ay (int tstados) {
/* bit0, relying on the fact that after three shifts of the */
/* register, what now is bit3 will become bit0, and will */
/* invert, if necessary, bit14, which previously was bit17. */
if ((noise+1)&2) this->ayval_n = !this->ayval_n; //xor bit 1 and 2
if( noise & 1 ) {
noise ^= 0x24000 ;
if ((noise+1)&2) {
this->ayval_n = !this->ayval_n; //xor bit 1 and 2
}
if( noise & 1 ) {
noise ^= 0x24000 ;
}
noise >>= 1 ;
noise >>= 1 ;
this->aych_n =0;
}
}
// Volume
//Each channel max 51
if (this->ay_registers[8] & 0x10)
this->vol_a =
(unsigned char) (levels[this->ay_envel_value]*(unsigned int) llsound->volume/80);
else
this->vol_a =
(unsigned char) (levels[this->ay_registers[8] &0x0F]*(unsigned int) llsound->volume/80);
if (this->ay_registers[10] & 0x10)
this->vol_c =
(unsigned char) (levels[this->ay_envel_value] *(unsigned int) llsound->volume/80);
else
this->vol_c =
(unsigned char) (levels[this->ay_registers[10] & 0x0F] *(unsigned int) llsound->volume/80);
if (this->ay_registers[8] & 0x10) {
this->vol_a = (unsigned char) (levels[this->ay_envel_value]*(unsigned int) llsound->volume/80);
} else {
this->vol_a = (unsigned char) (levels[this->ay_registers[8] &0x0F]*(unsigned int) llsound->volume/80);
}
if (this->ay_registers[9] & 0x10)
this->vol_b =
(unsigned char) (levels[this->ay_envel_value] *(unsigned int) llsound->volume/80);
else
this->vol_b =
(unsigned char)(levels[this->ay_registers[9] &0x0F] *(unsigned int) llsound->volume/80);
if (this->ay_registers[10] & 0x10) {
this->vol_c = (unsigned char) (levels[this->ay_envel_value] *(unsigned int) llsound->volume/80);
} else {
this->vol_c = (unsigned char) (levels[this->ay_registers[10] & 0x0F] *(unsigned int) llsound->volume/80);
}
if (this->ay_registers[9] & 0x10) {
this->vol_b = (unsigned char) (levels[this->ay_envel_value] *(unsigned int) llsound->volume/80);
} else {
this->vol_b = (unsigned char)(levels[this->ay_registers[9] &0x0F] *(unsigned int) llsound->volume/80);
}
}
}
......@@ -396,9 +391,9 @@ void SPK_AY::play_sound (int tstados) {
else
this->sound_current_value=0;
value = this->sound_current_value;
//Mixer
// The 8912 has three outputs, each output is the mix of one of the three
// tone generators and of the (single) noise generator. The two are mixed
// BEFORE going into the DAC. The formula to mix each channel is:
......@@ -411,7 +406,7 @@ void SPK_AY::play_sound (int tstados) {
// Setting the output to 1 is necessary because a disabled channel is locked
// into the ON state (see above); and it has no effect if the volume is 0.
// If the volume is 0, increase the counter, but don't touch the output.
if (this->ay_emul) { // if emulation is ON, emulate it
//this->ayval_n = 1;
if (((this->ayval_a || (this->ay_registers[7] & 0x01))&&(this->ayval_n || (this->ay_registers[7] & 0x08))))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment