From b28ab42e18043e9a637494000cb2b9e3dbcf4b29 Mon Sep 17 00:00:00 2001 From: saxxonpike Date: Sat, 10 Nov 2012 07:42:05 +0000 Subject: [PATCH] commodore64: VIC now only sees character rom at $1000 and $9000 --- .../Computers/Commodore64/MemBus.cs | 51 +++++++++++-------- .../Computers/Commodore64/VicII.cs | 2 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs index e4c4b0799b..c861dfdf29 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs @@ -55,10 +55,10 @@ namespace BizHawk.Emulation.Computers.Commodore64 public MemoryLayout layout; // ram - public byte cia2A; - public byte cia2B; public byte[] colorRam; public byte[] ram; + public bool vicCharEnabled; + public ushort vicOffset; // registers public byte busData; @@ -98,7 +98,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 cia1 = newCia1; cia1.ports[0] = cia1PortA; cia1.ports[1] = cia1PortB; - + cia1PortA.WritePort = UpdateVicOffset; HardReset(); } @@ -191,6 +191,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 cpuPort = new DirectionalDataPort(0x37, 0x2F); layout = new MemoryLayout(); UpdateLayout(); + UpdateVicOffset(cia1PortA.Data); } public byte Peek(ushort addr) @@ -423,33 +424,39 @@ namespace BizHawk.Emulation.Computers.Commodore64 } } + private void UpdateVicOffset(byte val) + { + switch (cia1PortA.Data & 0x03) + { + case 0: + vicCharEnabled = false; + vicOffset = 0xC000; + break; + case 1: + vicCharEnabled = true; + vicOffset = 0x8000; + break; + case 2: + vicCharEnabled = false; + vicOffset = 0x4000; + break; + default: + vicCharEnabled = true; + vicOffset = 0x0000; + break; + } + } + public byte VicRead(ushort addr) { addr = (ushort)(addr & 0x3FFF); - if (addr >= 0x1000 && addr < 0x2000) + if (vicCharEnabled && (addr >= 0x1000 && addr < 0x2000)) { return charRom[addr & 0x0FFF]; } else { - int baseAddr = 0; - int videoOffsetIndex = cia1PortA.Data & 0x03; - switch (videoOffsetIndex) - { - case 0: - baseAddr = 0xC000 | addr; - break; - case 1: - baseAddr = 0x8000 | addr; - break; - case 2: - baseAddr = 0x4000 | addr; - break; - default: - baseAddr = addr; - break; - } - return ram[(ushort)baseAddr]; + return ram[addr | vicOffset]; } } diff --git a/BizHawk.Emulation/Computers/Commodore64/VicII.cs b/BizHawk.Emulation/Computers/Commodore64/VicII.cs index b924f46568..1e07796bd3 100644 --- a/BizHawk.Emulation/Computers/Commodore64/VicII.cs +++ b/BizHawk.Emulation/Computers/Commodore64/VicII.cs @@ -1109,7 +1109,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 else { spriteBits = (int)((regs.MSR[j] >> 30) & 0x2); - if ((!regs.MxXE[j]) || (rasterOffsetX & 0x1) != (regs.MxX[j] & 0x1)) + if ((!regs.MxXE[j]) || ((rasterOffsetX & 0x1) != (regs.MxX[j] & 0x1))) { regs.MSR[j] <<= 1; regs.MSRC[j]--;