Coleco: implement TMS mode 3, clean up some debug code

This commit is contained in:
beirich 2012-11-26 01:44:17 +00:00
parent 5433bdacfd
commit 0bb30d4918
3 changed files with 84 additions and 50 deletions

View File

@ -27,8 +27,6 @@ namespace BizHawk.Emulation.Consoles.Coleco
Cpu.WriteMemory = WriteMemory; Cpu.WriteMemory = WriteMemory;
Cpu.ReadHardware = ReadPort; Cpu.ReadHardware = ReadPort;
Cpu.WriteHardware = WritePort; Cpu.WriteHardware = WritePort;
Cpu.Logger = (s) => Log.Error("COL", s);
//Cpu.Debug = true;
VDP = new TMS9918A(Cpu); VDP = new TMS9918A(Cpu);
PSG = new SN76489(); PSG = new SN76489();
@ -41,7 +39,6 @@ namespace BizHawk.Emulation.Consoles.Coleco
if (game["NoSkip"]) if (game["NoSkip"])
skipbios = false; skipbios = false;
Console.WriteLine("skipbios = {0}", skipbios);
LoadRom(rom, skipbios); LoadRom(rom, skipbios);
this.game = game; this.game = game;
SetupMemoryDomains(); SetupMemoryDomains();

View File

@ -96,9 +96,8 @@ namespace BizHawk.Emulation.Consoles.Coleco
VdpBuffer = value; VdpBuffer = value;
VRAM[VdpAddress] = value; VRAM[VdpAddress] = value;
if (!Mode16k) //if (!Mode16k)
Console.WriteLine("VRAM written while not in 16k addressing mode!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // Console.WriteLine("VRAM written while not in 16k addressing mode!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
//Log.Error("COL", "VRAM[{0:X4}] = {1:X2}", VdpAddress, value);
VdpAddress++; VdpAddress++;
VdpAddress &= 0x3FFF; VdpAddress &= 0x3FFF;
} }
@ -116,10 +115,6 @@ namespace BizHawk.Emulation.Consoles.Coleco
case 1: // Mode Control Register 2 case 1: // Mode Control Register 2
CheckVideoMode(); CheckVideoMode();
Cpu.NonMaskableInterrupt = (EnableInterrupts && InterruptPending); Cpu.NonMaskableInterrupt = (EnableInterrupts && InterruptPending);
if (!Mode16k)
//throw new Exception("4k bit is false! tell vec where you saw this happen pls!");
Console.WriteLine("4k bit is false! tell vec where you saw this happen pls!");
break; break;
case 2: // Name Table Base Address case 2: // Name Table Base Address
TmsPatternNameTableBase = (Registers[2] << 10) & 0x3C00; TmsPatternNameTableBase = (Registers[2] << 10) & 0x3C00;
@ -165,12 +160,9 @@ namespace BizHawk.Emulation.Consoles.Coleco
else if (Mode2Bit) TmsMode = 2; else if (Mode2Bit) TmsMode = 2;
else if (Mode3Bit) TmsMode = 3; else if (Mode3Bit) TmsMode = 3;
else TmsMode = 0; else TmsMode = 0;
Console.WriteLine("mode " + TmsMode);
if (TmsMode == 1) if (TmsMode == 1)
throw new Exception("TMS video mode 1! please tell vecna which game uses this!"); throw new Exception("TMS video mode 1! please tell vecna which game uses this!");
if (TmsMode == 3)
throw new Exception("TMS video mode 3! please tell vecna which game uses this!");
} }
void RenderScanline(int scanLine) void RenderScanline(int scanLine)
@ -188,6 +180,12 @@ namespace BizHawk.Emulation.Consoles.Coleco
RenderBackgroundM0(scanLine); RenderBackgroundM0(scanLine);
RenderTmsSprites(scanLine); RenderTmsSprites(scanLine);
} }
else if (TmsMode == 3)
{
RenderBackgroundM3(scanLine);
RenderTmsSprites(scanLine);
}
// This may seem silly but if I ever implement mode 1, sprites are not rendered in that.
} }
void RenderBackgroundM0(int scanLine) void RenderBackgroundM0(int scanLine)
@ -225,42 +223,77 @@ namespace BizHawk.Emulation.Consoles.Coleco
} }
} }
void RenderBackgroundM2(int scanLine) void RenderBackgroundM2(int scanLine)
{ {
if (DisplayOn == false) if (DisplayOn == false)
{ {
Array.Clear(FrameBuffer, scanLine * 256, 256); Array.Clear(FrameBuffer, scanLine * 256, 256);
return; return;
} }
int yrow = scanLine / 8; int yrow = scanLine / 8;
int yofs = scanLine % 8; int yofs = scanLine % 8;
int FrameBufferOffset = scanLine * 256; int FrameBufferOffset = scanLine * 256;
int PatternNameOffset = TmsPatternNameTableBase + (yrow * 32); int PatternNameOffset = TmsPatternNameTableBase + (yrow * 32);
int PatternGeneratorOffset = (((Registers[4] & 4) << 11) & 0x2000);// +((yrow / 8) * 0x100); int PatternGeneratorOffset = (((Registers[4] & 4) << 11) & 0x2000);
int ColorOffset = (ColorTableBase & 0x2000);// +((yrow / 8) * 0x100); int ColorOffset = (ColorTableBase & 0x2000);
int ScreenBGColor = PaletteTMS9918[Registers[7] & 0x0F]; int ScreenBGColor = PaletteTMS9918[Registers[7] & 0x0F];
for (int xc = 0; xc < 32; xc++) for (int xc = 0; xc < 32; xc++)
{ {
int pn = VRAM[PatternNameOffset++] + ((yrow / 8) * 0x100); int pn = VRAM[PatternNameOffset++] + ((yrow / 8) * 0x100);
int pv = VRAM[PatternGeneratorOffset + (pn * 8) + yofs]; int pv = VRAM[PatternGeneratorOffset + (pn * 8) + yofs];
int colorEntry = VRAM[ColorOffset + (pn * 8) + yofs]; int colorEntry = VRAM[ColorOffset + (pn * 8) + yofs];
int fgIndex = (colorEntry >> 4) & 0x0F; int fgIndex = (colorEntry >> 4) & 0x0F;
int bgIndex = colorEntry & 0x0F; int bgIndex = colorEntry & 0x0F;
int fgColor = fgIndex == 0 ? ScreenBGColor : PaletteTMS9918[fgIndex]; int fgColor = fgIndex == 0 ? ScreenBGColor : PaletteTMS9918[fgIndex];
int bgColor = bgIndex == 0 ? ScreenBGColor : PaletteTMS9918[bgIndex]; int bgColor = bgIndex == 0 ? ScreenBGColor : PaletteTMS9918[bgIndex];
FrameBuffer[FrameBufferOffset++] = ((pv & 0x80) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x80) > 0) ? fgColor : bgColor;
FrameBuffer[FrameBufferOffset++] = ((pv & 0x40) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x40) > 0) ? fgColor : bgColor;
FrameBuffer[FrameBufferOffset++] = ((pv & 0x20) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x20) > 0) ? fgColor : bgColor;
FrameBuffer[FrameBufferOffset++] = ((pv & 0x10) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x10) > 0) ? fgColor : bgColor;
FrameBuffer[FrameBufferOffset++] = ((pv & 0x08) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x08) > 0) ? fgColor : bgColor;
FrameBuffer[FrameBufferOffset++] = ((pv & 0x04) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x04) > 0) ? fgColor : bgColor;
FrameBuffer[FrameBufferOffset++] = ((pv & 0x02) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x02) > 0) ? fgColor : bgColor;
FrameBuffer[FrameBufferOffset++] = ((pv & 0x01) > 0) ? fgColor : bgColor; FrameBuffer[FrameBufferOffset++] = ((pv & 0x01) > 0) ? fgColor : bgColor;
} }
} }
void RenderBackgroundM3(int scanLine)
{
if (DisplayOn == false)
{
Array.Clear(FrameBuffer, scanLine * 256, 256);
return;
}
int yc = scanLine / 8;
bool top = (scanLine & 4) == 0; // am I in the top 4 pixels of an 8-pixel character?
int FrameBufferOffset = scanLine * 256;
int PatternNameOffset = TmsPatternNameTableBase + (yc * 32);
int ScreenBGColor = PaletteTMS9918[Registers[7] & 0x0F];
for (int xc = 0; xc < 32; xc++)
{
int pn = VRAM[PatternNameOffset++];
int pv = VRAM[PatternGeneratorBase + (pn * 8) + ((yc & 3) * 2) + (top ? 0 : 1)];
int lColorIndex = pv & 0xF;
int rColorIndex = pv >> 4;
int lColor = lColorIndex == 0 ? ScreenBGColor : PaletteTMS9918[lColorIndex];
int rColor = rColorIndex == 0 ? ScreenBGColor : PaletteTMS9918[rColorIndex];
FrameBuffer[FrameBufferOffset++] = lColor;
FrameBuffer[FrameBufferOffset++] = lColor;
FrameBuffer[FrameBufferOffset++] = lColor;
FrameBuffer[FrameBufferOffset++] = lColor;
FrameBuffer[FrameBufferOffset++] = rColor;
FrameBuffer[FrameBufferOffset++] = rColor;
FrameBuffer[FrameBufferOffset++] = rColor;
FrameBuffer[FrameBufferOffset ] = rColor;
}
}
byte[] ScanlinePriorityBuffer = new byte[256]; byte[] ScanlinePriorityBuffer = new byte[256];
byte[] SpriteCollisionBuffer = new byte[256]; byte[] SpriteCollisionBuffer = new byte[256];
@ -309,12 +342,13 @@ namespace BizHawk.Emulation.Consoles.Coleco
break; break;
} }
//if (i >= 5 && y==30)
// Console.WriteLine(i);
if (LargeSprites) Pattern &= 0xFC; // 16x16 sprites forced to 4-byte alignment if (LargeSprites) Pattern &= 0xFC; // 16x16 sprites forced to 4-byte alignment
int SpriteLine = scanLine - y; int SpriteLine = scanLine - y;
// pv contains the VRAM byte holding the pattern data for this character at this scanline.
// each byte contains the pattern data for each the 8 pixels on this line.
// the bit-shift further down on PV pulls out the relevant horizontal pixel.
byte pv = VRAM[SpritePatternGeneratorBase + (Pattern * 8) + SpriteLine]; byte pv = VRAM[SpritePatternGeneratorBase + (Pattern * 8) + SpriteLine];
for (int xp = 0; xp < SpriteSize && x + xp < 256; xp++) for (int xp = 0; xp < SpriteSize && x + xp < 256; xp++)
@ -404,7 +438,6 @@ namespace BizHawk.Emulation.Consoles.Coleco
} }
} }
Z80A Cpu; Z80A Cpu;
public TMS9918A(Z80A cpu) public TMS9918A(Z80A cpu)
{ {

View File

@ -12,6 +12,10 @@ using BizHawk.Emulation.Sound;
+ Try to clean up the organization of the source code. + Try to clean up the organization of the source code.
+ Lightgun/Paddle/etc if I get really bored + Lightgun/Paddle/etc if I get really bored
+ SG-1000 TMS does not fire sprite collision bit
+ SG-1000 TMS sprite doubling most likely does not work!
+ Maybe try to unify the Coleco TMS with SG-1000? Or at least pull in other TMS fixes.
**********************************************************/ **********************************************************/
namespace BizHawk.Emulation.Consoles.Sega namespace BizHawk.Emulation.Consoles.Sega