Tidy up stylecopy usage for the LR35902 set of libraries.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-07-21 13:11:00 +01:00
parent 7192b5c095
commit 8dea5746c4
26 changed files with 280 additions and 180 deletions

View File

@ -64,5 +64,12 @@
<Name>EightBit</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,4 +1,7 @@
namespace Fuse
// <copyright file="Lines.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
using System;
using System.Collections.Generic;

View File

@ -1,4 +1,7 @@
namespace Fuse
// <copyright file="RegisterState.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
using System;
using System.Collections.Generic;

View File

@ -1,4 +1,7 @@
namespace Fuse
// <copyright file="Results.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
using System.Collections.Generic;
@ -6,10 +9,10 @@
{
private readonly Lines lines;
public Dictionary<string, Result> Container { get; } = new Dictionary<string, Result>();
public Results(string path) => this.lines = new Lines(path);
public Dictionary<string, Result> Container { get; } = new Dictionary<string, Result>();
public void Read() => this.lines.Read();
public void Parse()

View File

@ -1,4 +1,7 @@
namespace Fuse
// <copyright file="Test.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
using System;
using System.Collections.Generic;

View File

@ -1,7 +1,9 @@
namespace Fuse
// <copyright file="TestEvent.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
using System;
using System.IO;
public class TestEvent
{

View File

@ -1,4 +1,7 @@
namespace Fuse
// <copyright file="Tests.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
using System.Collections.Generic;
@ -6,10 +9,10 @@
{
private readonly Lines lines;
public Dictionary<string, Test> Container { get; } = new Dictionary<string, Test>();
public Tests(string path) => this.lines = new Lines(path);
public Dictionary<string, Test> Container { get; } = new Dictionary<string, Test>();
public void Read() => this.lines.Read();
public void Parse()

4
Fuse/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="StyleCop.Analyzers" version="1.1.118" targetFramework="net472" developmentDependency="true" />
</packages>

View File

@ -1,11 +1,11 @@
// <copyright file="GameboyBus.cs" company="Adrian Conlon">
// <copyright file="Bus.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
using System;
using System.Collections.Generic;
namespace EightBit
{
using System;
using System.Collections.Generic;
namespace GameBoy
{
public abstract class Bus : EightBit.Bus
@ -175,6 +175,64 @@ namespace EightBit
return new MemoryMapping(this.highInternalRam, 0xff80, 0xffff, AccessLevel.ReadWrite);
}
protected override void OnWrittenByte()
{
base.OnWrittenByte();
var address = this.Address.Word;
var value = this.Data;
switch (address & 0xe000)
{
case 0x0000:
// Register 0: RAMCS gate data
if (this.ram)
{
throw new InvalidOperationException("Register 0: RAMCS gate data: Not handled!");
}
break;
case 0x2000:
// Register 1: ROM bank code
if (this.banked && this.higherRomBank)
{
// assert((address >= 0x2000) && (address < 0x4000));
// assert((value > 0) && (value < 0x20));
this.romBank = value & (byte)Mask.Mask5;
}
break;
case 0x4000:
// Register 2: ROM bank selection
if (this.banked)
{
throw new InvalidOperationException("Register 2: ROM bank selection: Not handled!");
}
break;
case 0x6000:
// Register 3: ROM/RAM change
if (this.banked)
{
switch (value & (byte)Mask.Mask1)
{
case 0:
this.higherRomBank = true;
this.ramBankSwitching = false;
break;
case 1:
this.higherRomBank = false;
this.ramBankSwitching = true;
break;
default:
throw new InvalidOperationException("Unreachable");
}
}
break;
}
}
private void ValidateCartridgeType()
{
this.rom = this.banked = this.ram = this.battery = false;
@ -266,60 +324,6 @@ namespace EightBit
}
}
protected override void OnWrittenByte()
{
base.OnWrittenByte();
var address = this.Address.Word;
var value = this.Data;
switch (address & 0xe000)
{
case 0x0000:
// Register 0: RAMCS gate data
if (this.ram)
{
throw new InvalidOperationException("Register 0: RAMCS gate data: Not handled!");
}
break;
case 0x2000:
// Register 1: ROM bank code
if (this.banked && this.higherRomBank)
{
//assert((address >= 0x2000) && (address < 0x4000));
//assert((value > 0) && (value < 0x20));
this.romBank = value & (byte)Mask.Mask5;
}
break;
case 0x4000:
// Register 2: ROM bank selection
if (this.banked)
{
throw new InvalidOperationException("Register 2: ROM bank selection: Not handled!");
}
break;
case 0x6000:
// Register 3: ROM/RAM change
if (this.banked)
{
switch (value & (byte)Mask.Mask1)
{
case 0:
this.higherRomBank = true;
this.ramBankSwitching = false;
break;
case 1:
this.higherRomBank = false;
this.ramBankSwitching = true;
break;
default:
throw new InvalidOperationException("Unreachable");
}
}
break;
}
}
private int RunRasterLines(int lines)
{
var count = 0;
@ -362,6 +366,7 @@ namespace EightBit
this.IO.TriggerInterrupt(Interrupts.VerticalBlank);
}
return this.RunRasterLines(lines);
}

View File

@ -10,7 +10,7 @@ namespace EightBit
Off,
Light,
Medium,
Dark
Dark,
}
}
}

View File

@ -14,7 +14,7 @@ namespace EightBit
DisplayControlStatus = Bits.Bit1, // LCDC Status
TimerOverflow = Bits.Bit2, // Timer Overflow
SerialTransfer = Bits.Bit3, // Serial Transfer
KeypadPressed = Bits.Bit4 // Hi-Lo transition of P10-P13
KeypadPressed = Bits.Bit4, // Hi-Lo transition of P10-P13
}
}
}

View File

@ -12,69 +12,70 @@ namespace EightBit
public const int BASE = 0xFF00;
// Port/Mode Registers
public const int P1 = 0x0; // R/W Mask5
public const int SB = 0x1; // R/W Mask8
public const int SC = 0x2; // R/W Bit7 | Bit0
public const int P1 = 0x0; // R/W Mask5
public const int SB = 0x1; // R/W Mask8
public const int SC = 0x2; // R/W Bit7 | Bit0
// Timer control
public const int DIV = 0x4; // R/W Mask8
public const int TIMA = 0x5; // R/W Mask8
public const int TMA = 0x6; // R/W Mask8
public const int TAC = 0x7; // R/W Mask3
public const int DIV = 0x4; // R/W Mask8
public const int TIMA = 0x5; // R/W Mask8
public const int TMA = 0x6; // R/W Mask8
public const int TAC = 0x7; // R/W Mask3
// Interrupt Flags
public const int IF = 0xF; // R/W Mask5
public const int IE = 0xFF; // R/W Mask5
public const int IF = 0xF; // R/W Mask5
public const int IE = 0xFF; // R/W Mask5
// Sound Registers
public const int NR10 = 0x10; // R/W Mask7
public const int NR11 = 0x11; // R/W Bit7 | Bit6
public const int NR12 = 0x12; // R/W Mask8
public const int NR13 = 0x13; // W 0
public const int NR14 = 0x14; // R/W Bit6
public const int NR21 = 0x16; // R/W Bit7 | Bit6
public const int NR22 = 0x17; // R/W Mask8
public const int NR23 = 0x18; // W 0
public const int NR24 = 0x19; // R/W Bit6
public const int NR30 = 0x1A; // R/W Bit7
public const int NR31 = 0x1B; // R/W Mask8
public const int NR32 = 0x1C; // R/W Bit6 | Bit5
public const int NR33 = 0x1D; // W 0
public const int NR34 = 0x1E; // R/W Bit6
public const int NR41 = 0x20; // R/W Mask6
public const int NR42 = 0x21; // R/W Mask8
public const int NR43 = 0x22; // R/W Mask8
public const int NR44 = 0x23; // R/W Bit6
public const int NR50 = 0x24; // R/W Mask8
public const int NR51 = 0x25; // R/W Mask8
public const int NR52 = 0x26; // R/W Mask8 Mask8
public const int NR10 = 0x10; // R/W Mask7
public const int NR11 = 0x11; // R/W Bit7 | Bit6
public const int NR12 = 0x12; // R/W Mask8
public const int NR13 = 0x13; // W 0
public const int NR14 = 0x14; // R/W Bit6
public const int NR21 = 0x16; // R/W Bit7 | Bit6
public const int NR22 = 0x17; // R/W Mask8
public const int NR23 = 0x18; // W 0
public const int NR24 = 0x19; // R/W Bit6
public const int NR30 = 0x1A; // R/W Bit7
public const int NR31 = 0x1B; // R/W Mask8
public const int NR32 = 0x1C; // R/W Bit6 | Bit5
public const int NR33 = 0x1D; // W 0
public const int NR34 = 0x1E; // R/W Bit6
public const int NR41 = 0x20; // R/W Mask6
public const int NR42 = 0x21; // R/W Mask8
public const int NR43 = 0x22; // R/W Mask8
public const int NR44 = 0x23; // R/W Bit6
public const int NR50 = 0x24; // R/W Mask8
public const int NR51 = 0x25; // R/W Mask8
public const int NR52 = 0x26; // R/W Mask8 Mask8
public const int WAVE_PATTERN_RAM_START = 0x30;
public const int WAVE_PATTERN_RAM_END = 0x3F;
// LCD Display Registers
public const int LCDC = 0x40; // R/W Mask8
public const int STAT = 0x41; // R/W Mask7
public const int SCY = 0x42; // R/W Mask8
public const int SCX = 0x43; // R/W Mask8
public const int LY = 0x44; // R Mask8 zeroed
public const int LYC = 0x45; // R/W Mask8
public const int DMA = 0x46; // W 0
public const int BGP = 0x47; // R/W Mask8
public const int OBP0 = 0x48; // R/W Mask8
public const int OBP1 = 0x49; // R/W Mask8
public const int WY = 0x4A; // R/W Mask8
public const int WX = 0x4B; // R/W Mask8
public const int LCDC = 0x40; // R/W Mask8
public const int STAT = 0x41; // R/W Mask7
public const int SCY = 0x42; // R/W Mask8
public const int SCX = 0x43; // R/W Mask8
public const int LY = 0x44; // R Mask8 zeroed
public const int LYC = 0x45; // R/W Mask8
public const int DMA = 0x46; // W 0
public const int BGP = 0x47; // R/W Mask8
public const int OBP0 = 0x48; // R/W Mask8
public const int OBP1 = 0x49; // R/W Mask8
public const int WY = 0x4A; // R/W Mask8
public const int WX = 0x4B; // R/W Mask8
// Boot rom control
public const int BOOT_DISABLE = 0x50;
private readonly Bus bus;
private readonly Register16 divCounter = new Register16(0xab, 0xcc);
private readonly Register16 dmaAddress = new Register16();
private int timerCounter = 0;
private int timerRate = 0;
private readonly Register16 dmaAddress = new Register16();
private bool dmaTransferActive = false;
private bool scanP15 = false;
@ -107,6 +108,26 @@ namespace EightBit
public bool TimerDisabled => (this.Peek((ushort)TAC) & (byte)Bits.Bit2) == 0;
public int TimerClockTicks
{
get
{
switch (this.TimerClock)
{
case 0b00:
return 1024; // 4.096 Khz
case 0b01:
return 16; // 262.144 Khz
case 0b10:
return 64; // 65.536 Khz
case 0b11:
return 256; // 16.384 Khz
}
throw new InvalidOperationException("Invalid timer clock specification");
}
}
public void Reset()
{
this.Poke((ushort)NR52, 0xf1);
@ -132,25 +153,6 @@ namespace EightBit
this.CheckTimer(cycles);
}
public int TimerClockTicks
{
get
{
switch (this.TimerClock)
{
case 0b00:
return 1024; // 4.096 Khz
case 0b01:
return 16; // 262.144 Khz
case 0b10:
return 64; // 65.536 Khz
case 0b11:
return 256; // 16.384 Khz
}
throw new InvalidOperationException("Invalid timer clock specification");
}
}
public void IncrementDIV(int cycles)
{
this.divCounter.Word += (ushort)cycles;
@ -342,10 +344,11 @@ namespace EightBit
var p11 = live && this.p11 ? 1 : 0;
var p12 = live && this.p12 ? 1 : 0;
var p13 = live && this.p13 ? 1 : 0;
this.Poke(port,
(byte)(p10 | (p11 << 1) | (p12 << 2) | (p13 << 3)
| (int)(Bits.Bit4 | Bits.Bit5 | Bits.Bit6 | Bits.Bit7)));
this.Poke(
port,
(byte)(p10 | (p11 << 1) | (p12 << 2) | (p13 << 3) | (int)(Bits.Bit4 | Bits.Bit5 | Bits.Bit6 | Bits.Bit7)));
}
break;
case SB:
break;

View File

@ -52,6 +52,7 @@
<ItemGroup>
<None Include="App.config" />
<AdditionalFiles Include="stylecop.json" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\EightBit\EightBit.csproj">
@ -67,5 +68,9 @@
<Name>LR35902</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<Analyzer Include="..\..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,4 +1,8 @@
namespace Fuse
// <copyright file="Program.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
public static class Program
{

View File

@ -1,12 +1,21 @@
namespace Fuse
// <copyright file="TestRunner.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
public enum Register
{
AF,
BC,
DE,
HL,
SP,
PC,
}
public class TestRunner : EightBit.GameBoy.Bus
{
public enum Register
{
AF, BC, DE, HL, SP, PC
};
private readonly Test test;
private readonly Result result;
private readonly EightBit.Ram ram = new EightBit.Ram(0x10000);
@ -58,6 +67,31 @@
public override void Initialize() => this.DisableGameRom();
private static void DumpDifference(string description, byte expected, byte actual)
{
var output = $"**** {description}, Expected: {expected:x2}, Got {actual:x2}";
System.Console.Error.WriteLine(output);
}
private static void DumpDifference(string highDescription, string lowDescription, EightBit.Register16 expected, EightBit.Register16 actual)
{
var expectedHigh = expected.High;
var expectedLow = expected.Low;
var actualHigh = actual.High;
var actualLow = actual.Low;
if (expectedHigh != actualHigh)
{
DumpDifference(highDescription, actualHigh, expectedHigh);
}
if (expectedLow != actualLow)
{
DumpDifference(lowDescription, actualLow, expectedLow);
}
}
private void InitialiseRegisters()
{
var testState = this.test.RegisterState;
@ -174,34 +208,10 @@
System.Console.Error.WriteLine($"**** Difference: Address: {address:x4} Expected: {expected:x2} Actual: {actual:x2}");
}
++address;
}
}
}
private static void DumpDifference(string description, byte expected, byte actual)
{
var output = $"**** {description}, Expected: {expected:x2}, Got {actual:x2}";
System.Console.Error.WriteLine(output);
}
private static void DumpDifference(string highDescription, string lowDescription, EightBit.Register16 expected, EightBit.Register16 actual)
{
var expectedHigh = expected.High;
var expectedLow = expected.Low;
var actualHigh = actual.High;
var actualLow = actual.Low;
if (expectedHigh != actualHigh)
{
DumpDifference(highDescription, actualHigh, expectedHigh);
}
if (expectedLow != actualLow)
{
DumpDifference(lowDescription, actualLow, expectedLow);
}
}
}
}

View File

@ -1,4 +1,7 @@
namespace Fuse
// <copyright file="TestSuite.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace Fuse
{
public class TestSuite
{
@ -47,6 +50,7 @@
++unimplementedCount;
}
}
System.Console.Out.WriteLine($"+++ Failed test count: {failedCount}");
System.Console.Out.WriteLine($"+++ Unimplemented test count: {unimplementedCount}");
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="StyleCop.Analyzers" version="1.1.118" targetFramework="net472" developmentDependency="true" />
</packages>

View File

@ -148,6 +148,10 @@ namespace EightBit
private static byte AdjustHalfCarrySub(byte input, byte before, byte value, int calculation) => SetBit(input, StatusBits.HC, CalculateHalfCarrySub(before, value, calculation));
private static byte Res(int n, byte operand) => (byte)(operand & ~(1 << n));
private static byte Set(int n, byte operand) => (byte)(operand | (1 << n));
private void DI() => this.IME = false;
private void EI() => this.IME = true;
@ -296,7 +300,7 @@ namespace EightBit
break;
}
case 1: // BIT y, r[z]
case 1: // BIT y, r[z]
this.Bit(y, this.R(z));
this.Tick(2);
if (z == 6)
@ -729,6 +733,7 @@ namespace EightBit
default:
throw new InvalidOperationException("Invalid operation mode");
}
break;
case 3: // Assorted operations
switch (y)
@ -1061,10 +1066,6 @@ namespace EightBit
this.F = SetBit(this.F, StatusBits.CF, carry);
}
private static byte Res(int n, byte operand) => (byte)(operand & ~(1 << n));
private static byte Set(int n, byte operand) => (byte)(operand | (1 << n));
private void DAA()
{
int updated = this.A;

View File

@ -63,5 +63,12 @@
<Name>EightBit</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,4 +1,4 @@
// <copyright file="LcdcControl.cs" company="Adrian Conlon">
// <copyright file="LcdStatusMode.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace EightBit
@ -10,7 +10,7 @@ namespace EightBit
HBlank = 0b00,
VBlank = 0b01,
SearchingOamRam = 0b10,
TransferringDataToLcd = 0b11
TransferringDataToLcd = 0b11,
}
}
}

View File

@ -1,4 +1,4 @@
// <copyright file="LcdcControl.cs" company="Adrian Conlon">
// <copyright file="LcdStatusModeEventArgs.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace EightBit

View File

@ -16,7 +16,7 @@ namespace EightBit
BackgroundCharacterDataSelection = Bits.Bit4,
WindowEnable = Bits.Bit5,
WindowCodeAreaSelection = Bits.Bit6,
LcdEnable = Bits.Bit7
LcdEnable = Bits.Bit7,
}
}
}

View File

@ -11,7 +11,7 @@ namespace EightBit
{
}
public ObjectAttribute(Ram ram, ushort address)
public ObjectAttribute(Ram ram, ushort address)
{
this.PositionY = ram.Peek(address);
this.PositionX = ram.Peek(++address);
@ -20,8 +20,11 @@ namespace EightBit
}
public byte PositionY { get; }
public byte PositionX { get; }
public byte Pattern { get; }
public byte Flags { get; }
public int Priority => this.Flags & (byte)Bits.Bit7;

View File

@ -1,4 +1,7 @@
using System.Reflection;
// <copyright file="AssemblyInfo.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

4
LR35902/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="StyleCop.Analyzers" version="1.1.118" targetFramework="net472" developmentDependency="true" />
</packages>

19
LR35902/stylecop.json Normal file
View File

@ -0,0 +1,19 @@
{
// ACTION REQUIRED: This file was automatically added to your project, but it
// will not take effect until additional steps are taken to enable it. See the
// following page for additional information:
//
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"documentInterfaces": false,
"documentExposedElements": false,
"documentInternalElements": false,
"documentPrivateElements": false,
"documentPrivateFields": false,
"companyName": "Adrian Conlon"
}
}
}