From 06022c9076b64070953dd3d071cb03779439e235 Mon Sep 17 00:00:00 2001 From: brandman211 Date: Thu, 6 Sep 2012 04:51:17 +0000 Subject: [PATCH] -Added Read/WriteMemory to the STIC so that it can access the RAM it needs to draw the screen. --Did the same for the PSG because why not. -Discovered that the Commando HLT happens after the CPU goes idle, so there's no point in further investigating the issue until I emulate that. -Parsed the BACKTAB cards for the STIC's Draw(). -Attempted to draw the screen using the aforementioned cards. --I'm only trying to apply color to the foreground. ---Instead of converting the FG color to RGBA, I'm making it all white for now. --There's clearly some sanity to what's being drawn, so I think each 8x8 card is being drawn in the right place. --I think the next step is trying to make each individual card draw properly. --I believe the algorithm for populating the FrameBuffer is VERY inefficient in the way it accesses memory. Will need some suggestions as to how I can rewrite this. --- BizHawk.Emulation/CPUs/CP1610/Execute.cs | 4 +- .../Consoles/Intellivision/Intellivision.cs | 4 + .../Consoles/Intellivision/MemoryMap.cs | 2 +- .../Consoles/Intellivision/PSG.cs | 6 + .../Consoles/Intellivision/STIC.cs | 105 +++++++++++++++++- 5 files changed, 114 insertions(+), 7 deletions(-) diff --git a/BizHawk.Emulation/CPUs/CP1610/Execute.cs b/BizHawk.Emulation/CPUs/CP1610/Execute.cs index defff0dd43..9833ebebbf 100644 --- a/BizHawk.Emulation/CPUs/CP1610/Execute.cs +++ b/BizHawk.Emulation/CPUs/CP1610/Execute.cs @@ -93,8 +93,8 @@ namespace BizHawk.Emulation.CPUs.CP1610 public int Execute() { /* - Take an interrupt if the previous instruction was interruptible, - interrupts are enabled, and IntRM has a falling edge. + Take an interrupt if the previous instruction was interruptible, + interrupts are enabled, and IntRM has a falling edge. */ if (FlagI && Interruptible && !IntRM && !Interrupted) { diff --git a/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs b/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs index a4daa0d722..a45c0a45e0 100644 --- a/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs +++ b/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs @@ -65,9 +65,13 @@ namespace BizHawk.Emulation.Consoles.Intellivision Cpu.Reset(); Stic = new STIC(); + Stic.ReadMemory = ReadMemory; + Stic.WriteMemory = WriteMemory; Stic.Reset(); Psg = new PSG(); + Psg.ReadMemory = ReadMemory; + Psg.WriteMemory = WriteMemory; Connect(); diff --git a/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs b/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs index f3b1aab9f8..14b6fb0769 100644 --- a/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs +++ b/BizHawk.Emulation/Consoles/Intellivision/MemoryMap.cs @@ -45,7 +45,7 @@ namespace BizHawk.Emulation.Consoles.Intellivision break; break; case 0x1000: - core = ExecutiveRom[addr - 0x1000]; + core = (ushort)(ExecutiveRom[addr - 0x1000] & 0x3FF); break; case 0x3000: if (addr <= 0x37FF) diff --git a/BizHawk.Emulation/Consoles/Intellivision/PSG.cs b/BizHawk.Emulation/Consoles/Intellivision/PSG.cs index 991ca4b24e..44116494b7 100644 --- a/BizHawk.Emulation/Consoles/Intellivision/PSG.cs +++ b/BizHawk.Emulation/Consoles/Intellivision/PSG.cs @@ -9,6 +9,12 @@ namespace BizHawk.Emulation.Consoles.Intellivision { private ushort[] Register = new ushort[16]; + public int TotalExecutedCycles; + public int PendingCycles; + + public Func ReadMemory; + public Func WriteMemory; + public ushort? ReadPSG(ushort addr) { if (addr >= 0x01F0 && addr <= 0x01FF) diff --git a/BizHawk.Emulation/Consoles/Intellivision/STIC.cs b/BizHawk.Emulation/Consoles/Intellivision/STIC.cs index 3748f9b5f2..0d3b399e31 100644 --- a/BizHawk.Emulation/Consoles/Intellivision/STIC.cs +++ b/BizHawk.Emulation/Consoles/Intellivision/STIC.cs @@ -13,10 +13,20 @@ namespace BizHawk.Emulation.Consoles.Intellivision public int TotalExecutedCycles; public int PendingCycles; - public int[] FrameBuffer = new int[160 * 96]; - public int[] GetVideoBuffer() { return FrameBuffer; } - public int VirtualWidth { get { return 160; } } - public int BufferWidth { get { return 160; } } + public Func ReadMemory; + public Func WriteMemory; + + public int[] FrameBuffer = new int[159 * 96]; + + public int[] GetVideoBuffer() + { + Background(); + Mobs(); + return FrameBuffer; + } + + public int VirtualWidth { get { return 159; } } + public int BufferWidth { get { return 159; } } public int VirtualHeight { get { return 192; } } public int BufferHeight { get { return 96; } } public int BackgroundColor { get { return 0; } } @@ -160,5 +170,92 @@ namespace BizHawk.Emulation.Consoles.Intellivision PendingCycles -= cycles; TotalExecutedCycles += cycles; } + + public int ColorToRGBA(int color) + { + return 0xFFFFFF; + } + + public void Background() + { + // The background is a 20x12 grid of "cards". + for (int card_row = 0; card_row < 12; card_row++) + { + for (int card_col = 0; card_col < 20; card_col++) + { + // The cards are stored sequentially in the System RAM. + ushort card = ReadMemory((ushort)(0x0200 + + (card_row * 20) + card_col)); + // Parse data from the card. + bool gram = ((card & 0x0800) != 0); + int card_num = card >> 3; + int fg = card & 0x0004; + if (Fgbg) + { + int bg = ((card >> 9) & 0x0008) | + ((card >> 11) & 0x0004) | + ((card >> 9) & 0x0002); + /* + Only 64 of the GROM's cards can be used in FGBG + Mode. + */ + card_num &= 0x0020; + } + else + { + bool advance = ((card & 0x2000) != 0); + if (gram) + { + // GRAM only has 64 cards. + card_num &= 0x0020; + fg |= (card >> 9) & 0x0008; + } + else + /* + All of the GROM's 256 cards can be used in Color + Stack Mode. + */ + card_num &= 0x0080; + } + // Each picture is 8x8 pixels. + for (int pict_row = 0; pict_row < 8; pict_row++) + { + /* + Each picture is stored sequentially in the GROM / GRAM, + and so are their rows. + */ + int row_mem = (card_num * 8) + (pict_row * 8); + byte row; + if (gram) + row = (byte)ReadMemory((ushort)(0x3800 + + row_mem)); + else + row = (byte)ReadMemory((ushort)(0x3000 + + row_mem)); + for (int pict_col = 0; pict_col < 8; pict_col++) + { + // The rightmost column does not get displayed. + if (card_col == 19 && pict_col == 0) + continue; + // If the pixel is on, give it the FG color. + if ((row & 0x1) != 0) + /* + The pixels go right as the bits get less + significant. + */ + FrameBuffer[((card_row * 159 * 8) + (card_col * 8) + + (pict_row * 159) + (7 - pict_col))] = + ColorToRGBA(fg); + row >>= 1; + } + } + } + } + } + + public void Mobs() + { + // TODO + } } }