-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (96 loc) · 4.88 KB
/
Copy pathProgram.cs
File metadata and controls
111 lines (96 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using AutoMapper;
using Highbyte.DotNet6502.App.SilkNetNative;
using Highbyte.DotNet6502.App.SilkNetNative.SystemSetup;
using Highbyte.DotNet6502.Impl.NAudio;
using Highbyte.DotNet6502.Impl.SilkNet;
using Highbyte.DotNet6502.Impl.SilkNet.Commodore64.Video;
using Highbyte.DotNet6502.Logging;
using Highbyte.DotNet6502.Logging.InMem;
using Highbyte.DotNet6502.Monitor;
using Highbyte.DotNet6502.Systems;
using Highbyte.DotNet6502.Systems.Commodore64;
using Highbyte.DotNet6502.Systems.Generic;
using Microsoft.Extensions.Logging;
// Fix for starting in debug mode from VS Code. By default the OS current directory is set to the project folder, not the folder containing the built .exe file...
var currentAppDir = AppDomain.CurrentDomain.BaseDirectory;
Environment.CurrentDirectory = currentAppDir;
DotNet6502InMemLogStore logStore = new();
var logConfig = new DotNet6502InMemLoggerConfiguration(logStore);
var loggerFactory = LoggerFactory.Create(builder =>
{
logConfig.LogLevel = LogLevel.Information;
builder.AddInMem(logConfig);
builder.SetMinimumLevel(LogLevel.Trace);
});
// ----------
// Systems
// ----------
var systemList = new SystemList<SilkNetRenderContextContainer, SilkNetInputHandlerContext, NAudioAudioHandlerContext>();
var c64HostConfig = new C64HostConfig
{
Renderer = C64HostRenderer.SilkNetOpenGl,
SilkNetOpenGlRendererConfig = new C64SilkNetOpenGlRendererConfig()
{
UseFineScrollPerRasterLine = false, // Setting to true may work, depending on how code is written. Full screen scroll may not work (actual screen memory is not rendered in sync with raster line).
ShaderEmbeddedResourceType = typeof(C64SilkNetOpenGlRendererConfig),
VertexShaderPath = "Highbyte.DotNet6502.Impl.SilkNet.Commodore64.Video.C64shader_es.vert",
FragmentShaderPath = "Highbyte.DotNet6502.Impl.SilkNet.Commodore64.Video.C64shader_es.frag",
//UseTestShader = true // Set to true to use a test fragment shader instead of the C64 fragment shader.
}
};
var c64Setup = new C64Setup(loggerFactory, c64HostConfig);
systemList.AddSystem(c64Setup);
var genericComputerHostConfig = new GenericComputerHostConfig { };
var genericComputerSetup = new GenericComputerSetup(loggerFactory, genericComputerHostConfig);
systemList.AddSystem(genericComputerSetup);
// TODO: Read options from appsettings.json
var emulatorConfig = new EmulatorConfig
{
DefaultEmulator = c64Setup.SystemName,
//DefaultEmulator = genericComputerSetup.SystemName,
DefaultDrawScale = 3.0f,
Monitor = new MonitorConfig
{
MaxLineLength = 100,
//DefaultDirectory = "../../../../../../samples/Assembler/C64/Build"
//DefaultDirectory = "../../../../../../samples/Assembler/Generic/Build"
//DefaultDirectory = "%USERPROFILE%/source/repos/dotnet-6502/samples/Assembler/Generic/Build"
//DefaultDirectory = "%HOME%/source/repos/dotnet-6502/samples/Assembler/Generic/Build"
},
HostSystemConfigs = new Dictionary<string, IHostSystemConfig>
{
{ C64.SystemName, c64HostConfig },
{ GenericComputer.SystemName, genericComputerHostConfig}
}
};
emulatorConfig.Validate(systemList);
// TODO: Make Automapper configuration more generic, incorporate in classes that need it?
var mapperConfiguration = new MapperConfiguration(
cfg =>
{
cfg.CreateMap<C64HostConfig, C64HostConfig>();
}
);
var mapper = mapperConfiguration.CreateMapper();
// ----------
// Silk.NET Window
// ----------
int windowWidth = SilkNetWindow.DEFAULT_WIDTH;
int windowHeight = SilkNetWindow.DEFAULT_HEIGHT;
var windowOptions = WindowOptions.Default;
// Update frequency, in hertz.
windowOptions.UpdatesPerSecond = SilkNetWindow.DEFAULT_RENDER_HZ;
// Render frequency, in hertz.
windowOptions.FramesPerSecond = 60.0f; // TODO: With Vsync=false the FramesPerSecond settings does not seem to matter. Measured in OnRender method it'll be same as UpdatesPerSecond setting.
windowOptions.VSync = false; // TODO: With Vsync=true Silk.NET seem to use incorrect UpdatePerSecond. The actual FPS its called is 10 lower than it should be (measured in the OnUpdate method)
windowOptions.WindowState = WindowState.Normal;
windowOptions.Title = "DotNet 6502 emulator hosted in native Silk.NET window using SkiaSharp, OpenGL, and NAudio";
windowOptions.Size = new Vector2D<int>(windowWidth, windowHeight);
windowOptions.WindowBorder = WindowBorder.Fixed;
windowOptions.API = GraphicsAPI.Default; // = Default = OpenGL 3.3 with forward compatibility
windowOptions.ShouldSwapAutomatically = true;
//windowOptions.TransparentFramebuffer = false;
//windowOptions.PreferredDepthBufferBits = 24; // Depth buffer bits must be set explicitly on MacOS (tested on M1), otherwise there will be be no depth buffer (for OpenGL 3d).
IWindow window = Window.Create(windowOptions);
var silkNetWindow = new SilkNetWindow(emulatorConfig, window, systemList, logStore, logConfig, loggerFactory, mapper);
silkNetWindow.Run();