Skip to content

Commit

Permalink
Updated Readme; Deployment on release
Browse files Browse the repository at this point in the history
  • Loading branch information
qkmaxware committed Jul 17, 2024
1 parent 8876b7f commit d20bec8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Deploy Github Pages
on:
push:
branches:
- "root"
release:
types: [ published, edited ]
jobs:
deploy:
name: Deploy Github Pages
Expand Down
15 changes: 9 additions & 6 deletions Gameboy.Player.Cli/CliPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class CliPlayer {

private bool CpuTrace;
private bool Benchmark;
private float Scale = 1;
private float ScaleX = 1;
private float ScaleY = 1;

private Gameboy gb;

Expand All @@ -22,17 +23,19 @@ public CliPlayer() {


/// <summary>
/// Main entrypoint for the program
/// Run a GB file in your terminal.
/// </summary>
/// <param name="rom">Path to a rom file</param>
/// <param name="width">Width of the screen on the terminal (default is usually too large for default font)</param>
/// <param name="width">Width of the screen on the terminal</param>
/// <param name="height">Height of the screen on the terminal (default is usually too large for default font)</param>
/// <param name="cpuTrace">Print out a log of executed CPU instructions</param>
/// <param name="benchmark">Record timing metrics for instructions and hardware components</param>
static void Main(string? rom = null, int width = 160, bool cpuTrace = false, bool benchmark = false) {
static void Main(string? rom = null, int width = 160, int height = 144, bool cpuTrace = false, bool benchmark = false) {
CliPlayer player = new CliPlayer() {
CpuTrace = cpuTrace,
Benchmark = benchmark,
Scale = (float)width / (float)Gpu.LCD_WIDTH
ScaleX = (float)width / (float)Gpu.LCD_WIDTH,
ScaleY = (float)height / (float)Gpu.LCD_HEIGHT
};
player.Start(rom);
}
Expand Down Expand Up @@ -99,7 +102,7 @@ public void Start(string? rom) {
});

Console.Title = cart.Info.title;
var renderer = new CliRenderer(CliRendererCharacterSet.Ascii, Scale);
var renderer = new CliRenderer(CliRendererCharacterSet.Ascii, ScaleX, ScaleY);
while (running) {
// Run CPU until flush
gb.DispatchUntilBufferFlush();
Expand Down
19 changes: 11 additions & 8 deletions Gameboy.Player.Cli/CliRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,20 @@ public Rectangle(short left, short top, short right, short bottom) {
/// Create a new renderer with the given characters
/// </summary>
/// <param name="characters">drawing character set</param>
/// <param name="scale">scale of the renderer relative to normal dimensions</param>
public CliRenderer(CliRendererCharacterSet characters, float scale = 1) {
/// <param name="scaleX">scale of the renderer relative to normal width</param>
/// <param name="scaleY">scale of the renderer relative to normal hight</param>
public CliRenderer(CliRendererCharacterSet characters, float scaleX = 1, float scaleY = 1) {
this.CharacterSet = characters;
Console.Clear();
Console.SetCursorPosition(0, 0);
Console.CursorVisible = false;
var position = Console.GetCursorPosition();
this.WindowX = (short)position.Left;
this.WindowY = (short)position.Top;
this.scale = scale;
this.charsWidth = (short)(Gpu.LCD_WIDTH * scale);
this.charsHeight = (short)(Gpu.LCD_HEIGHT * scale);
this.scaleX = scaleX;
this.scaleY = scaleY;
this.charsWidth = (short)(Gpu.LCD_WIDTH * this.scaleX);
this.charsHeight = (short)(Gpu.LCD_HEIGHT * this.scaleY);
chars = new CharInfo[charsHeight * charsWidth];
changed = new bool[chars.Length];
for (var i = 0; i < chars.Length; i++) {
Expand All @@ -128,7 +130,8 @@ public void ToConsole(Bitmap bmp) {
ToConsoleAsConsoleWrite(bmp);
}

private float scale;
private float scaleX;
private float scaleY;
private short charsWidth;
private short charsHeight;
private CharInfo[] chars;
Expand All @@ -145,8 +148,8 @@ private char getChar(short x, short y) {
return (char)chars[addr].Char;
}
private void setChar(short x, short y, char new_value) {
var xOnWindow = (short)MathF.Round(x * scale);
var yOnWindow = (short)MathF.Round(y * scale);
var xOnWindow = (short)MathF.Round(x * scaleX);
var yOnWindow = (short)MathF.Round(y * scaleY);
var addr = charsWidth * yOnWindow + xOnWindow;
if (addr < 0 || addr >= chars.Length)
return;
Expand Down
36 changes: 26 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,39 @@
# BlazorBoy
A simple (and buggy) Nintendo Game Boy emulator written in C# using Blazor as a front-end for rendering the game.

Total conversion from my original pure Java version [here](https://github.com/qkmaxware/GBemu).
Total conversion from my original pure Java version [here](https://github.com/qkmaxware/GBemu). Hopefully it's a little better organized, optimized, and accurate compared to the original.

## Folder Structure
### Qkmaxware.Vm.LR35902
Emulation of the CPU for the Sharp LR35902 processor. Kept separately from the rest of the project in case it gets used somewhere else in the future.
## Front-Ends
Front-ends are applications that implement the rendering/io for BlazorBoy. Front-ends support different environments such as for desktop, mobile, or the web. Additionally, each front-end will have differing levels of performance and may or may not support all console features. These restictions are often dictated by the restrictions of the environment the front-end is designed to run on (eg. the CLI rendering being slow given how slow writing large chunks of text to the console can be).

The following table shows each front-end inluded in this repository and the hardware features that they support.

| Front-End | Download | Speed | Display | Input | Sound | Serial |
|-----------|----------|-------|---------|-------|-------|--------|
| CLI | [nuget](https://github.com/qkmaxware/BlazorBoy/pkgs/nuget/Gameboy.Player.Cli) | SLOW | Mono/Symbolic ASCII | Keyboard<sup>(1)</sup> | -- | -- |
| Blazor | [link](https://qkmaxware.github.io/BlazorBoy/) | MEDIUM | Mono | Touch/Keyboard | -- | -- |
| Godot | [exe](https://github.com/qkmaxware/BlazorBoy/releases/latest) | FAST | Colour | Touch/Keyboard/Gamepad | -- | -- |

- <small>(1) Can only press 1 button at a time.</small>

## Folder Structure
### Gameboy
The actual code for the hardware emulation of the console. Doesn't include any rendering/drawing to the screen.
The actual code for the hardware emulation of the console. Doesn't include any hardware implementations. Console features like the screen, input, sounds, and more are specific to the run-time environment and as such are left without some implementation details that front-ends need to map to features from the rum-time environment. IE this won't just work out of the box as nothing will be drawn, heard, or interacted with.

### Gameboy.Test
Automated unit tests for the emulated hardware.
### Gameboy.Database
A small database of metadata for some popular Game Boy games.

### Gameboy.Player.Blazor
The main renderer for the emulated hardware. A Blazor app which runs the emulated console and displays the graphics as well as handles user input. Runs entirely in the browser thanks to WebAssembly.
A Blazor Web Assembly app front-end for BlazorBoy (the namesake front-end). Glue code is included to map emulated hardware features to HTML events and Canvas elements.

### Gameboy.Player.Cli
An example renderer that prints the images to the terminal's console. Does technically have input, but I wouldn't recommend playing anything in this (rendering is too slow and input is inconsistent).
A CLI application that serves as a front-end for BlazorBoy. Simple example of how to create your own front-end for BlazorBoy. Glue code is included to map emulated hardware features to CLI key events and character printing.

### Gameboy.Player.Godot
A simple Godot 4 project running the emulated hardware.
A Godot 4 front-end for BlazorBoy. Glue code is inlcuded to map emulated hardware features from the emulated console to Godot Nodes/Features.

### Gameboy.Test
Automated unit tests for the emulated hardware.

### Qkmaxware.Vm.LR35902
Emulation of the CPU for the Sharp LR35902 processor. Kept separately from the rest of the project in case it gets used somewhere else in the future.

0 comments on commit d20bec8

Please sign in to comment.