Skip to content

Commit ccc99ac

Browse files
authored
Standardized encoding charset and added .gitattributes file (#24)
1 parent 2ed8ce7 commit ccc99ac

File tree

109 files changed

+6511
-6554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+6511
-6554
lines changed

.gitattributes

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Normalize all text files to LF in repository, auto-convert to native line endings on checkout
2+
* text=auto
3+
4+
# Explicitly declare text files (they'll use native line endings per platform)
5+
*.cs text
6+
*.xaml text
7+
*.json text
8+
*.md text
9+
*.config text
10+
*.props text
11+
*.targets text
12+
*.csproj text
13+
*.slnx text
14+
15+
# Declare files that are always binary
16+
*.png binary
17+
*.jpg binary
18+
*.jpeg binary
19+
*.gif binary
20+
*.ico binary
21+
*.dll binary
22+
*.exe binary
23+
*.pdb binary

src/.editorconfig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Remove the line below if you want to inherit .editorconfig settings from higher directories
22
root = true
33

4+
# All files
5+
[*]
6+
charset = utf-8
7+
insert_final_newline = false
8+
trim_trailing_whitespace = true
9+
410
# C# files
511
[*.cs]
612

@@ -11,8 +17,7 @@ indent_size = 2
1117
indent_style = space
1218
tab_width = 2
1319

14-
# New line preferences
15-
end_of_line = crlf
20+
# New line preferences
1621
insert_final_newline = false
1722

1823
#### .NET Code Actions ####
Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,110 @@
1-
using Chip8.Instructions;
2-
using Moq;
3-
using NUnit.Framework;
4-
using NUnit.Framework.Legacy;
5-
using System.Collections.Generic;
6-
using System.IO;
7-
using System.Linq;
8-
9-
namespace Chip8.Tests;
10-
11-
public class CompilationAndDecompilationOfSampleApplications
12-
{
13-
[Test]
14-
[Ignore("Executed manually")]
15-
public void LoadingThenRetrievingApplicationInEmulator_ReturnsSameByteArray()
16-
{
17-
var directory = new DirectoryInfo(@"..\..\..\..\..\games");
18-
foreach (var file in Directory.EnumerateFiles(directory.FullName).Where(x => !x.EndsWith(".c8")))
19-
{
20-
var originalGame = File.ReadAllBytes(file);
21-
22-
var emulator = new Emulator(new Cpu(), new Mock<IDisplay>().Object, new Mock<IKeyboard>().Object, new Mock<ISound>().Object);
23-
emulator.LoadApplication(originalGame);
24-
25-
var gameFromEmulator = emulator.GetApplication();
26-
27-
CollectionAssert.AreEqual(originalGame, gameFromEmulator, $"File: {file}");
28-
//File.WriteAllBytes(file, gameFromEmulator);
29-
}
30-
}
31-
32-
[Test]
33-
[Ignore("Executed manually")]
34-
public void DecompiledApplication_IsSameAs_AlreadyDecompiledApplication()
35-
{
36-
var directory = new DirectoryInfo(@"..\..\..\..\..\games");
37-
foreach (var file in Directory.EnumerateFiles(directory.FullName).Where(x => !x.EndsWith(".c8")))
38-
{
39-
var application = File.ReadAllBytes(file);
40-
var instructionDecoder = new InstructionDecoder();
41-
42-
var instructions = new List<string>();
43-
for (int i = 0; i < application.Length - 1; i += 2)
44-
{
45-
var instruction = GetInstruction(application[i], application[i + 1], instructionDecoder);
46-
instructions.Add(instruction);
47-
}
48-
49-
// if length of the application is not an even number, that means that the last instruction
50-
// was skipped (in the preceding for loop) because it did not start on an even address
51-
if (application.Length % 2 != 0)
52-
{
53-
var instruction = GetInstruction(application[application.Length - 1], 0x0, instructionDecoder);
54-
instructions.Add(instruction);
55-
}
56-
57-
var codeFilePath = $"{file}.c8";
58-
var alreadyDecompiledApplication = File.ReadAllLines(codeFilePath);
59-
CollectionAssert.AreEqual(alreadyDecompiledApplication, instructions, $"File: {codeFilePath}");
60-
//File.WriteAllLines(codeFilePath, instructions);
61-
}
62-
}
63-
64-
[Test]
65-
[Ignore("Executed manually")]
66-
public void CompiledApplication_IsSameAs_AlreadyCompiledApplication()
67-
{
68-
var directory = new DirectoryInfo(@"..\..\..\..\..\games");
69-
foreach (var file in Directory.EnumerateFiles(directory.FullName).Where(x => x.EndsWith(".c8")))
70-
{
71-
var decompiledApplication = File.ReadAllLines(file);
72-
var instructionEncoder = new InstructionEncoder();
73-
74-
// Convert all lines of code into CPU instructions
75-
var cpuInstructions = new List<CpuInstruction>();
76-
for (int i = 0; i < decompiledApplication.Length; i++)
77-
{
78-
var cpuInstruction = instructionEncoder.GetCpuInstruction(decompiledApplication[i]);
79-
cpuInstructions.Add(cpuInstruction);
80-
}
81-
82-
var application = new List<byte>();
83-
foreach (var cpuInstruction in cpuInstructions)
84-
{
85-
// First add most significant byte
86-
application.Add((byte)((cpuInstruction.Decoded.InstructionCode & 0xFF00) >> 8));
87-
88-
// Then least significant byte
89-
application.Add(cpuInstruction.Decoded.kk);
90-
}
91-
92-
if (application[application.Count - 1] == 0x0)
93-
{
94-
application.RemoveAt(application.Count - 1);
95-
}
96-
97-
var binaryFilePath = file.Substring(0, file.Length - 3);
98-
var alreadyCompiledApplication = File.ReadAllBytes(binaryFilePath);
99-
CollectionAssert.AreEqual(alreadyCompiledApplication, application, $"File: {binaryFilePath}");
100-
//File.WriteAllBytes(binaryFilePath, application.ToArray());
101-
}
102-
}
103-
104-
private string GetInstruction(byte msb, byte lsb, InstructionDecoder instructionDecoder)
105-
{
106-
var decodedInstruction = instructionDecoder.Decode(msb, lsb);
107-
var cpuInstruction = instructionDecoder.GetCpuInstruction(decodedInstruction);
108-
return cpuInstruction.Mnemonic;
109-
}
110-
}
1+
using Chip8.Instructions;
2+
using Moq;
3+
using NUnit.Framework;
4+
using NUnit.Framework.Legacy;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
9+
namespace Chip8.Tests;
10+
11+
public class CompilationAndDecompilationOfSampleApplications
12+
{
13+
[Test]
14+
[Ignore("Executed manually")]
15+
public void LoadingThenRetrievingApplicationInEmulator_ReturnsSameByteArray()
16+
{
17+
var directory = new DirectoryInfo(@"..\..\..\..\..\games");
18+
foreach (var file in Directory.EnumerateFiles(directory.FullName).Where(x => !x.EndsWith(".c8")))
19+
{
20+
var originalGame = File.ReadAllBytes(file);
21+
22+
var emulator = new Emulator(new Cpu(), new Mock<IDisplay>().Object, new Mock<IKeyboard>().Object, new Mock<ISound>().Object);
23+
emulator.LoadApplication(originalGame);
24+
25+
var gameFromEmulator = emulator.GetApplication();
26+
27+
CollectionAssert.AreEqual(originalGame, gameFromEmulator, $"File: {file}");
28+
//File.WriteAllBytes(file, gameFromEmulator);
29+
}
30+
}
31+
32+
[Test]
33+
[Ignore("Executed manually")]
34+
public void DecompiledApplication_IsSameAs_AlreadyDecompiledApplication()
35+
{
36+
var directory = new DirectoryInfo(@"..\..\..\..\..\games");
37+
foreach (var file in Directory.EnumerateFiles(directory.FullName).Where(x => !x.EndsWith(".c8")))
38+
{
39+
var application = File.ReadAllBytes(file);
40+
var instructionDecoder = new InstructionDecoder();
41+
42+
var instructions = new List<string>();
43+
for (int i = 0; i < application.Length - 1; i += 2)
44+
{
45+
var instruction = GetInstruction(application[i], application[i + 1], instructionDecoder);
46+
instructions.Add(instruction);
47+
}
48+
49+
// if length of the application is not an even number, that means that the last instruction
50+
// was skipped (in the preceding for loop) because it did not start on an even address
51+
if (application.Length % 2 != 0)
52+
{
53+
var instruction = GetInstruction(application[application.Length - 1], 0x0, instructionDecoder);
54+
instructions.Add(instruction);
55+
}
56+
57+
var codeFilePath = $"{file}.c8";
58+
var alreadyDecompiledApplication = File.ReadAllLines(codeFilePath);
59+
CollectionAssert.AreEqual(alreadyDecompiledApplication, instructions, $"File: {codeFilePath}");
60+
//File.WriteAllLines(codeFilePath, instructions);
61+
}
62+
}
63+
64+
[Test]
65+
[Ignore("Executed manually")]
66+
public void CompiledApplication_IsSameAs_AlreadyCompiledApplication()
67+
{
68+
var directory = new DirectoryInfo(@"..\..\..\..\..\games");
69+
foreach (var file in Directory.EnumerateFiles(directory.FullName).Where(x => x.EndsWith(".c8")))
70+
{
71+
var decompiledApplication = File.ReadAllLines(file);
72+
var instructionEncoder = new InstructionEncoder();
73+
74+
// Convert all lines of code into CPU instructions
75+
var cpuInstructions = new List<CpuInstruction>();
76+
for (int i = 0; i < decompiledApplication.Length; i++)
77+
{
78+
var cpuInstruction = instructionEncoder.GetCpuInstruction(decompiledApplication[i]);
79+
cpuInstructions.Add(cpuInstruction);
80+
}
81+
82+
var application = new List<byte>();
83+
foreach (var cpuInstruction in cpuInstructions)
84+
{
85+
// First add most significant byte
86+
application.Add((byte)((cpuInstruction.Decoded.InstructionCode & 0xFF00) >> 8));
87+
88+
// Then least significant byte
89+
application.Add(cpuInstruction.Decoded.kk);
90+
}
91+
92+
if (application[application.Count - 1] == 0x0)
93+
{
94+
application.RemoveAt(application.Count - 1);
95+
}
96+
97+
var binaryFilePath = file.Substring(0, file.Length - 3);
98+
var alreadyCompiledApplication = File.ReadAllBytes(binaryFilePath);
99+
CollectionAssert.AreEqual(alreadyCompiledApplication, application, $"File: {binaryFilePath}");
100+
//File.WriteAllBytes(binaryFilePath, application.ToArray());
101+
}
102+
}
103+
104+
private string GetInstruction(byte msb, byte lsb, InstructionDecoder instructionDecoder)
105+
{
106+
var decodedInstruction = instructionDecoder.Decode(msb, lsb);
107+
var cpuInstruction = instructionDecoder.GetCpuInstruction(decodedInstruction);
108+
return cpuInstruction.Mnemonic;
109+
}
110+
}

0 commit comments

Comments
 (0)