Skip to content

Commit bbad042

Browse files
committed
Opentk 4 and first release
1 parent ecbbc43 commit bbad042

31 files changed

+451
-453
lines changed

Build.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dotnet publish "Monoboy/Monoboy.csproj" -o "Builds/Monoboy Win-x64" -c Release -r win10-x64 --no-self-contained -p:PublishSingleFile=true
2+
dotnet publish "Monoboy/Monoboy.csproj" -o "Builds/Monoboy Win-x86" -c Release -r win10-x86 --no-self-contained -p:PublishSingleFile=true
3+
dotnet publish "Monoboy/Monoboy.csproj" -o "Builds/Monoboy Linux-x64" -c Release -r linux-x64 --no-self-contained -p:PublishSingleFile=true
4+
dotnet publish "Monoboy/Monoboy.csproj" -o "Builds/Monoboy MacOS-x64" -c Release -r osx.10.14-x64 --no-self-contained -p:PublishSingleFile=true

Monoboy.Tests/Monoboy.Tests.csproj

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp3.1</TargetFramework>
44

5-
<IsPackable>false</IsPackable>
5+
<IsPackable>false</IsPackable>
66

7-
<Platforms>x64;x86</Platforms>
8-
</PropertyGroup>
7+
<Platforms>x64;x86</Platforms>
8+
</PropertyGroup>
99

10-
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
12-
<PackageReference Include="xunit" Version="2.4.1" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
14-
<PrivateAssets>all</PrivateAssets>
15-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16-
</PackageReference>
17-
<PackageReference Include="coverlet.collector" Version="1.3.0">
18-
<PrivateAssets>all</PrivateAssets>
19-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20-
</PackageReference>
21-
</ItemGroup>
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
12+
<PackageReference Include="xunit" Version="2.4.1" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
17+
<PackageReference Include="coverlet.collector" Version="1.3.0">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
</ItemGroup>
2222

23-
<ItemGroup>
24-
<ProjectReference Include="..\Monoboy\Monoboy.csproj" />
25-
</ItemGroup>
23+
<ItemGroup>
24+
<ProjectReference Include="..\Monoboy\Monoboy.csproj" />
25+
</ItemGroup>
2626

2727
</Project>

Monoboy.Tests/Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public class Tests
88
public void BootRom()
99
{
1010
Emulator emulator = new Emulator();
11-
emulator.LoadRom("Tetris.gb");
11+
emulator.Open("Tetris.gb");
1212

13-
while(emulator.bus.register.PC != 0x100)
13+
while (emulator.bus.register.PC != 0x100)
1414
{
1515
emulator.Step();
1616
}

Monoboy.sln

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monoboy", "Monoboy\Monoboy.
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Monoboy.Tests", "Monoboy.Tests\Monoboy.Tests.csproj", "{FE49472D-CE2E-4648-BF4F-9CE179BE0878}"
99
EndProject
10-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D2FF5988-1772-429D-A924-77F4185072B8}"
11-
EndProject
1210
Global
1311
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14-
Debug|Any CPU = Debug|Any CPU
1512
Debug|x64 = Debug|x64
1613
Debug|x86 = Debug|x86
17-
Release|Any CPU = Release|Any CPU
1814
Release|x64 = Release|x64
1915
Release|x86 = Release|x86
2016
EndGlobalSection
2117
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22-
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Debug|Any CPU.ActiveCfg = Debug|x86
23-
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Debug|x64.ActiveCfg = Debug|x64
24-
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Debug|x64.Build.0 = Debug|x64
18+
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Debug|x64.ActiveCfg = Release|x64
19+
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Debug|x64.Build.0 = Release|x64
2520
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Debug|x86.ActiveCfg = Debug|x86
2621
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Debug|x86.Build.0 = Debug|x86
27-
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Release|Any CPU.ActiveCfg = Release|x86
2822
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Release|x64.ActiveCfg = Release|x64
2923
{BFF040CB-D225-4205-8C3B-238F4F7553E1}.Release|x86.ActiveCfg = Release|x86
30-
{FE49472D-CE2E-4648-BF4F-9CE179BE0878}.Debug|Any CPU.ActiveCfg = Debug|x86
3124
{FE49472D-CE2E-4648-BF4F-9CE179BE0878}.Debug|x64.ActiveCfg = Debug|x64
3225
{FE49472D-CE2E-4648-BF4F-9CE179BE0878}.Debug|x64.Build.0 = Debug|x64
3326
{FE49472D-CE2E-4648-BF4F-9CE179BE0878}.Debug|x86.ActiveCfg = Debug|x86
34-
{FE49472D-CE2E-4648-BF4F-9CE179BE0878}.Release|Any CPU.ActiveCfg = Release|x86
3527
{FE49472D-CE2E-4648-BF4F-9CE179BE0878}.Release|x64.ActiveCfg = Release|x64
3628
{FE49472D-CE2E-4648-BF4F-9CE179BE0878}.Release|x86.ActiveCfg = Release|x86
3729
EndGlobalSection

Monoboy/Application/Application.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
using System.Numerics;
33

44
using ImGuiNET;
5-
6-
using ImGuiOpenTK;
5+
using ImGuiNET.OpenTK;
76

87
using Monoboy.Constants;
98
using Monoboy.Utility;
109

1110
using OpenTK.Graphics.OpenGL;
1211
using OpenTK.Windowing.Common;
13-
using OpenTK.Windowing.Common.Input;
1412
using OpenTK.Windowing.Desktop;
13+
using OpenTK.Windowing.GraphicsLibraryFramework;
1514

1615
namespace Monoboy.Application
1716
{
@@ -38,10 +37,8 @@ public class Application : Window
3837

3938
public Application(GameWindowSettings gameWindow, NativeWindowSettings nativeWindow) : base(gameWindow, nativeWindow)
4039
{
41-
4240
emulator = new Emulator();
4341

44-
// opentk 4.0 bug!
4542
MakeCurrent();
4643

4744
framebufferTexture = new Texture("FrameBuffer", Constant.WindowWidth, Constant.WindowHeight, emulator.bus.gpu.framebuffer.Pixels);
@@ -76,14 +73,14 @@ protected override void OnUpdateFrame(FrameEventArgs args)
7673

7774
void UpdateJoypad()
7875
{
79-
emulator.bus.joypad.SetButton(Joypad.Button.A, KeyboardState.IsKeyDown(Key.Space));
80-
emulator.bus.joypad.SetButton(Joypad.Button.B, KeyboardState.IsKeyDown(Key.ShiftLeft));
81-
emulator.bus.joypad.SetButton(Joypad.Button.Select, KeyboardState.IsKeyDown(Key.Escape));
82-
emulator.bus.joypad.SetButton(Joypad.Button.Start, KeyboardState.IsKeyDown(Key.Enter));
83-
emulator.bus.joypad.SetButton(Joypad.Button.Up, KeyboardState.IsKeyDown(Key.W));
84-
emulator.bus.joypad.SetButton(Joypad.Button.Down, KeyboardState.IsKeyDown(Key.S));
85-
emulator.bus.joypad.SetButton(Joypad.Button.Left, KeyboardState.IsKeyDown(Key.A));
86-
emulator.bus.joypad.SetButton(Joypad.Button.Right, KeyboardState.IsKeyDown(Key.D));
76+
emulator.bus.joypad.SetButton(Joypad.Button.A, KeyboardState.IsKeyDown(Keys.Space));
77+
emulator.bus.joypad.SetButton(Joypad.Button.B, KeyboardState.IsKeyDown(Keys.LeftShift));
78+
emulator.bus.joypad.SetButton(Joypad.Button.Select, KeyboardState.IsKeyDown(Keys.Escape));
79+
emulator.bus.joypad.SetButton(Joypad.Button.Start, KeyboardState.IsKeyDown(Keys.Enter));
80+
emulator.bus.joypad.SetButton(Joypad.Button.Up, KeyboardState.IsKeyDown(Keys.W));
81+
emulator.bus.joypad.SetButton(Joypad.Button.Down, KeyboardState.IsKeyDown(Keys.S));
82+
emulator.bus.joypad.SetButton(Joypad.Button.Left, KeyboardState.IsKeyDown(Keys.A));
83+
emulator.bus.joypad.SetButton(Joypad.Button.Right, KeyboardState.IsKeyDown(Keys.D));
8784
}
8885

8986
void DrawFrame()
@@ -242,7 +239,7 @@ private void TilemapWindow()
242239
byte data1 = emulator.bus.gpu.VideoRam[tileGraphicAddress + line];
243240
byte data2 = emulator.bus.gpu.VideoRam[tileGraphicAddress + line + 1];
244241

245-
byte bit = (byte)(0b00000001 << ((((int)x % 8) - 7) * 0xff));
242+
byte bit = (byte)(0b00000001 << (((x % 8) - 7) * 0xff));
246243
byte palletIndex = (byte)(((data2.GetBit(bit) ? 1 : 0) << 1) | (data1.GetBit(bit) ? 1 : 0));
247244
byte colorIndex = (byte)((emulator.bus.gpu.BGP >> palletIndex * 2) & 0b11);
248245
tilemapBuffer.SetPixel(x, y, palette[colorIndex]);

Monoboy/Application/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void Main()
2121
NativeWindowSettings settings = new NativeWindowSettings
2222
{
2323
API = OpenTK.Windowing.Common.ContextAPI.OpenGL,
24-
APIVersion = new Version(3, 2),
24+
APIVersion = new Version(3, 3),
2525
Size = new OpenTK.Mathematics.Vector2i(1280, 720)
2626
};
2727

Monoboy/Application/Window.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using System;
2-
using ImGuiNET;
3-
using ImGuiOpenTK;
1+
using ImGuiNET.OpenTK;
2+
43
using OpenTK.Graphics.OpenGL4;
54
using OpenTK.Mathematics;
65
using OpenTK.Windowing.Common;
@@ -12,16 +11,12 @@ public class Window : GameWindow
1211
{
1312
ImGuiController _controller;
1413

15-
public Window(GameWindowSettings gameWindow, NativeWindowSettings nativeWindow) : base(gameWindow, nativeWindow)
16-
{ }
14+
public Window(GameWindowSettings gameWindow, NativeWindowSettings nativeWindow) : base(gameWindow, nativeWindow) { }
1715

1816
protected override void OnLoad()
1917
{
2018
base.OnLoad();
2119

22-
// OpenTK-pre9.4 doesn't make the context current when loading so we do that here.
23-
MakeCurrent();
24-
2520
Title = "Monoboy";
2621

2722
_controller = new ImGuiController(ClientSize.X, ClientSize.Y);

Monoboy/Emulator/Bus.cs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections.Generic;
2-
3-
namespace Monoboy
1+
namespace Monoboy
42
{
53
public class Bus
64
{
@@ -53,7 +51,7 @@ public ushort ReadShort(ushort address)
5351

5452
public void Write(ushort address, byte data)
5553
{
56-
switch(address)
54+
switch (address)
5755
{
5856
case ushort _ when address <= 0x7FFF: memoryBankController.WriteBank(address, data); break; // 16KB ROM Bank > 00 (in cartridge, every other bank)
5957
case ushort _ when address <= 0x9FFF: memory.vram[address - 0x8000] = data; break; // 8KB Video RAM (VRAM) (switchable bank 0-1 in CGB Mode)
@@ -75,61 +73,61 @@ public void WriteShort(ushort address, ushort data)
7573

7674
private byte ReadIO(ushort address)
7775
{
78-
switch(address)
76+
switch (address)
7977
{
8078
case 0xFF00:// JOYP
81-
{
82-
return joypad.JOYP;
83-
}
79+
{
80+
return joypad.JOYP;
81+
}
8482

8583
default:
86-
{
87-
return memory.io[address - 0xFF00];
88-
}
84+
{
85+
return memory.io[address - 0xFF00];
86+
}
8987
}
9088

9189
}
9290

9391
private void WriteIO(ushort address, byte data)
9492
{
95-
switch(address)
93+
switch (address)
9694
{
9795
case 0xFF00:// JOYP
98-
{
99-
joypad.JOYP = data;
100-
}
101-
break;
96+
{
97+
joypad.JOYP = data;
98+
}
99+
break;
102100

103101
case 0xFF04:// DIV
104-
{
105-
data = 0;
106-
}
107-
break;
102+
{
103+
data = 0;
104+
}
105+
break;
108106

109107
case 0xFF44:// LY
110-
{
111-
data = 0;
112-
}
113-
break;
108+
{
109+
data = 0;
110+
}
111+
break;
114112

115113
case 0xFF46:
116-
{
117-
ushort offset = (ushort)(data << 8);
118-
for(byte i = 0; i < memory.oam.Length; i++)
119114
{
120-
memory.oam[i] = Read((ushort)(offset + i));
115+
ushort offset = (ushort)(data << 8);
116+
for (byte i = 0; i < memory.oam.Length; i++)
117+
{
118+
memory.oam[i] = Read((ushort)(offset + i));
119+
}
121120
}
122-
}
123-
break;
124-
125-
//case 0xFF02:
126-
//{
127-
// if(data == 0x81)
128-
// {
129-
// Debug.Write(Convert.ToChar(Read(0xFF01)));
130-
// }
131-
//}
132-
//break;
121+
break;
122+
123+
//case 0xFF02:
124+
//{
125+
// if(data == 0x81)
126+
// {
127+
// Debug.Write(Convert.ToChar(Read(0xFF01)));
128+
// }
129+
//}
130+
//break;
133131
}
134132

135133
memory.io[address - 0xFF00] = data;

0 commit comments

Comments
 (0)