Atari 2600 - DPC Mapper - add in clock cycle counting and some fixes, but still doesn't work, don't know why at this point

This commit is contained in:
adelikat 2013-04-20 22:09:19 +00:00
parent bad1d9502c
commit c577eb4854
2 changed files with 95 additions and 91 deletions

View File

@ -216,6 +216,7 @@ namespace BizHawk
if (CoreComm.Tracer.Enabled)
CoreComm.Tracer.Put(cpu.TraceState());
cpu.ExecuteOne();
mapper.ClockCpu();
//if (cpu.PendingCycles <= 0)
//{
// //Console.WriteLine("Tia clocks: " + tia.scanlinePos + " CPU pending: " + cpu.PendingCycles);
@ -294,5 +295,6 @@ namespace BizHawk
public virtual void WriteMemory(ushort addr, byte value) { core.BaseWriteMemory(addr, value); }
public virtual void SyncState(Serializer ser) { }
public virtual void Dispose() { }
public virtual void ClockCpu() { }
}
}

View File

@ -4,114 +4,115 @@
{
class mDPC : MapperBase
{
int bank_4k = 0;
IntBuffer Counters = new IntBuffer(8);
ByteBuffer Flags = new ByteBuffer(8);
IntBuffer Tops = new IntBuffer(8);
IntBuffer Bottoms = new IntBuffer(8);
ByteBuffer DisplayBank_2k = new ByteBuffer(2048);
byte RandomNumber = 0;
private ulong totalCycles = 0;
private ulong elapsedCycles = 0;
private double FractionalClocks;
bool[] MusicMode = new bool[3]; //TOOD: savestates
private int bank_4k = 0;
private IntBuffer Counters = new IntBuffer(8);
private ByteBuffer Flags = new ByteBuffer(8);
private IntBuffer Tops = new IntBuffer(8);
private IntBuffer Bottoms = new IntBuffer(8);
private ByteBuffer DisplayBank_2k = new ByteBuffer(2048);
private byte RandomNumber = 0;
private bool[] MusicMode = new bool[3]; //TOOD: savestates
public override byte PeekMemory(ushort addr)
{
return base.PeekMemory(addr); //TODO
}
public override void ClockCpu()
{
totalCycles++;
}
public override byte ReadMemory(ushort addr)
{
if (addr < 0x1000)
ClockRandomNumberGenerator();
addr &= 0x0FFF;
if (addr < 0x0040)
{
if (addr < 0x0040)
byte result = 0;
int index = addr & 0x07;
int function = (addr >> 3) & 0x07;
// Update flag register for selected data fetcher
if ((Counters[index] & 0x00ff) == Tops[index])
{
byte result = 0;
int index = addr & 0x07;
int function = (addr >> 3) & 0x07;
// Update flag register for selected data fetcher
if ((Counters[index] & 0x00ff) == Tops[index])
{
Flags[index] = 0xff;
}
else if ((Counters[index] & 0x00ff) == Bottoms[index])
{
Flags[index] = 0x00;
}
switch (function)
{
default:
result = 0;
break;
case 0x00:
if (index < 4)
{
result = RandomNumber;
}
else //it's a music read
{
byte[] MusicAmplitudes = {
0x00, 0x04, 0x05, 0x09, 0x06, 0x0a, 0x0b, 0x0f
};
//// Update the music data fetchers (counter & flag)
UpdateMusicModeDataFetchers();
byte i = 0;
if(MusicMode[0] && Flags[5] > 0)
{
i |= 0x01;
}
if(MusicMode[1] && Flags[6] > 0)
{
i |= 0x02;
}
if(MusicMode[2] && Flags[7] > 0)
{
i |= 0x04;
}
result = MusicAmplitudes[i];
}
break;
case 0x01:
result = DisplayBank_2k[2047 - Counters[index]];
break;
case 0x02:
result = DisplayBank_2k[2047 - (Counters[index] & Flags[index])];
break;
case 0x07:
result = Flags[index];
break;
}
// Clock the selected data fetcher's counter if needed
if ((index < 5) || ((index >= 5) && (!MusicMode[index - 5])))
{
Counters[index] = (Counters[index] - 1) & 0x07ff;
}
return result;
Flags[index] = 0xff;
}
else
else if ((Counters[index] & 0x00ff) == Bottoms[index])
{
return base.ReadMemory(addr);
Flags[index] = 0x00;
}
switch (function)
{
default:
result = 0;
break;
case 0x00:
if (index < 4)
{
result = RandomNumber;
}
else //it's a music read
{
byte[] MusicAmplitudes = {
0x00, 0x04, 0x05, 0x09, 0x06, 0x0a, 0x0b, 0x0f
};
//// Update the music data fetchers (counter & flag)
UpdateMusicModeDataFetchers();
byte i = 0;
if(MusicMode[0] && Flags[5] > 0)
{
i |= 0x01;
}
if(MusicMode[1] && Flags[6] > 0)
{
i |= 0x02;
}
if(MusicMode[2] && Flags[7] > 0)
{
i |= 0x04;
}
result = MusicAmplitudes[i];
}
break;
case 0x01:
result = DisplayBank_2k[2047 - Counters[index]];
break;
case 0x02:
result = DisplayBank_2k[2047 - (Counters[index] & Flags[index])];
break;
case 0x07:
result = Flags[index];
break;
}
// Clock the selected data fetcher's counter if needed
if ((index < 5) || ((index >= 5) && (!MusicMode[index - 5])))
{
Counters[index] = (Counters[index] - 1) & 0x07ff;
}
return result;
}
else
{
Address(addr);
return core.rom[(bank_4k << 12)+ (addr & 0xFFF)];
return core.rom[(bank_4k << 12) + addr];
}
}
public override void WriteMemory(ushort addr, byte value)
{
if (addr < 0x1000)
{
base.WriteMemory(addr, value);
}
addr &= 0x0FFF;
// Clock the random number generator. This should be done for every
@ -163,8 +164,6 @@
case 0x06: // Random Number Generator Reset
RandomNumber = 1;
break;
default:
break;
}
}
else
@ -176,11 +175,11 @@
private void Address(ushort addr)
{
if (addr == 0x1FF8)
if (addr == 0x0FF8)
{
bank_4k = 0;
}
else if (addr == 0x1FF9)
else if (addr == 0x0FF9)
{
bank_4k = 1;
}
@ -205,13 +204,16 @@
ser.Sync("RandomNumber", ref RandomNumber);
}
private double FractionalClocks;
private void UpdateMusicModeDataFetchers()
{
// Calculate the number of cycles since the last update
//int cycles = mySystem->cycles() - mySystemCycles;
//mySystemCycles = mySystem->cycles();
int cycles = 0; //TODO: need to get cycles!
ulong cycles = totalCycles - elapsedCycles;
elapsedCycles = totalCycles;
// Calculate the number of DPC OSC clocks since the last update
double clocks = ((20000.0 * cycles) / 1193191.66666667) + FractionalClocks;
int wholeClocks = (int)clocks;