Skip to content

Commit 93e7b59

Browse files
committed
Overall improvements
See the changelog
1 parent 9a1bab0 commit 93e7b59

40 files changed

+1300
-2255
lines changed

.gitignore

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# Precompiled Headers
1111
*.gch
1212
*.pch
13+
precomp/
1314

1415
# Compiled Dynamic libraries
1516
*.so
@@ -34,11 +35,6 @@
3435
# Ignore compiled executable
3536
geebly
3637

37-
# Ignore external libraries
38-
src/lgw/
39-
src/imgui/
40-
src/sfml/
41-
4238
# Ignore test suites
4339
tests/
4440
tearoom/
@@ -49,6 +45,7 @@ res/
4945

5046
# Ignore debug build scripts
5147
build-win-debug.bat
48+
build-win-debug.ps1
5249

5350
# Ignore all BIOSes/ROMs
5451
*.gb
@@ -67,3 +64,18 @@ build-win-debug.bat
6764
# Settings files
6865
*.json
6966
build-win-debug.ps1
67+
build-win-debug.bat
68+
69+
# Temporarily ignore the Linux Makefile
70+
Makefile
71+
72+
# Etc
73+
*.sna
74+
*.asm
75+
src/memory_editor.h
76+
src/devices/ppu/naive_ppu.h
77+
imgui.ini
78+
.vscode/
79+
build-win.bat
80+
.vscode/settings.json
81+
src/devices/ppu/naive_ppu.hpp

.vscode/settings.json

Lines changed: 0 additions & 71 deletions
This file was deleted.

CHANGELOG

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Geebly 0.8.0-dev Changelog
2+
Ok, I just finished polishing some details over this last version of Geebly, its been a while since the last release!
3+
4+
I do plan on using this version as an absolute baseline for a functioning emulator, as I've implemented almost all the details I've refrained from working on since development started, and as such, I'm really happy with the state of the emulator right now, code and functionality wise.
5+
6+
Everything is looking clearer, the PPU has been rewritten from scratch (literally!), the SPU is now properly implemented, etc.
7+
8+
Below is a (non-exhaustive) list of important changes:
9+
10+
### Changes
11+
#### CPU
12+
- Bit operations (and other instructions that used `bus::ref`) now properly cause side effects on MMIO
13+
14+
#### PPU
15+
The PPU has been rewritten from scratch. Now it runs on a much more accurate FIFO-based sub-scanline renderer, compared to the more naive scanline only renderer that was in place before.
16+
17+
- Sub-scanline renderer implemented
18+
- Greatly improved timings
19+
- Implemented sprite/background/window priorities (also for CGB mode)
20+
- Fixed DMA-related issues (see DMA for more info)
21+
22+
#### SPU/APU
23+
I've ditched the initial SPU implementation that relied on `SDL_QueueAudio`. The SPU now outputs samples at the Game Boy's real sample rate (2 MHz) and resamples them on-demand (`audio_update_cb`).
24+
25+
- Ditched `SDL_QueueAudio`, SPU is now callback based, this allowed the fixes below:
26+
- Fixed "race conditions" between channels where one channel would empty the buffer for a new sound to play, while another channel might have been pushing samples to the buffer, resulting in the second channel's audio being cut prematurely
27+
- The wave channel's pitch will no longer drift
28+
- Correctly implemented SPU control registers
29+
- Implemented stereo audio + stereo/mono setting
30+
- Implemented a master volume setting
31+
32+
#### DMA/HDMA (CGB DMA)
33+
- Fixed an issue where WRAM addresses wouldn't have been correctly translated (CGB mode)
34+
- `ff55` will always be set to `ff`, this fixes HDMA-related wait loop hanging. Its a hotfix though, I plan on correctly implementing HDMA so it isn't the same as GDMA
35+
36+
#### Codebase
37+
There have been a lot of improvements to the codebase overall, this looks insignificant to the outside world, but a cleaner, simpler and more concise codebase directly impacts the performance of a project as a whole
38+
39+
### To-do
40+
I plan on completely rewriting the debugger from the ground up, its already possible to see some advancements on the debug.hpp file. There are many more things to work on, but for now this is the one I'm going to be focusing on! Check the sources for more "To-do"s.

Makefile

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
<p align="center">
2-
<img src="https://user-images.githubusercontent.com/15825466/97769482-3c496d00-1b0a-11eb-8930-72a60e210d15.png">
2+
<img width="75%" height="75%" src="https://user-images.githubusercontent.com/15825466/117024784-b1bc1300-acd0-11eb-9656-c4f6e1cc391c.png" alt="Geebly">
33
</p>
44

5+
<div align="center">
6+
7+
#### A Game Boy/Color (DMG/GBC) emulator written in C++
8+
59
![workflow badge](https://github.com/Lycoder/Geebly/actions/workflows/windows-workflow.yml/badge.svg)
610
![workflow badge](https://github.com/Lycoder/Geebly/actions/workflows/ubuntu-workflow.yml/badge.svg)
7-
# Geebly
8-
A Gameboy/Color emulator written in C++, currently under development.
9-
<p align="center">
10-
<img src="https://user-images.githubusercontent.com/15825466/105384568-258a5200-5bf1-11eb-949c-8c274d88229e.gif" alt="Running Super Mario Bros. Deluxe (GBC)")
11-
</p>
11+
12+
![Geebly running Dangan GB](https://user-images.githubusercontent.com/15825466/117328287-dac3db80-ae69-11eb-9ef2-1e9ebf8e199e.gif)![Geebly running the Gejmbåj demo](https://user-images.githubusercontent.com/15825466/117328294-dd263580-ae69-11eb-87a2-942136e2e204.gif)![Geebly running Super Mario Bros. Deluxe](https://user-images.githubusercontent.com/15825466/117328291-dbf50880-ae69-11eb-9e9f-6388101d57ce.gif)![Geebly running Donkey Kong Country](https://user-images.githubusercontent.com/15825466/117328298-ddbecc00-ae69-11eb-8976-ec459c9ea3bb.gif)
13+
14+
</div>
1215

1316
## Usage
1417
### Linux
1518
`geebly <settings> <file>`
1619

17-
### Windows (Powershell)
18-
`./geebly <settings> <file>`
20+
### Windows
21+
`./geebly <settings> <file>` or `geebly <settings> <file>`
1922

2023
### Settings
2124
There are different settings for every part of the emulation engine, Boot ROM/BIOS related settings are prefixed with a `B`, general emulation settings are prefixed with a `E`, etc. Common settings' shorthands usually are just one letter long though.
2225

2326
Here's all the settings currently present in the CLI:
2427
|Setting|Shorthand|Description|Default|
2528
|--|--|--|--|
29+
|`--master-volume`|`-v`|Set the master volume (`float` or `int`) <ul><li>`0.0` = Silence</li><li>`1.0` = Max</li><li>`> 1.0` = Clipping</li></ul>|`1.0`
30+
|`--mono`|`-m`|Disable stereo sound|No
2631
|`--debug`|`-d`|Enable the Geebly Debugger|Disabled
2732
|`--boot`|`-b`|Specify a boot ROM|`"dmg_boot.bin"`
2833
|`--scale`|`-s`|Set the display scale|1
@@ -32,52 +37,9 @@ Here's all the settings currently present in the CLI:
3237
|`--cgb-mode`|`-Ecgb`|Switches to CGB (Game Boy Color) mode|Disabled
3338
|`--enable-joyp-irq-delay/--disable-joyp-irq-delay`|`-Ejoyp-irq-delay/-Eno-joyp-irq-delay`|Enable/disable JOYP IRQ delay|Enabled
3439

35-
## Current state
36-
### Game Boy Color Emulation
37-
Out of nowhere, there's now Game Boy Color emulation! This mostly comprises additional PPU registers and logic, and the CPU's double speed mode, that doesn't really affect the emulated CPU itself, but more the way devices do timing-based stuff based off the CPU clock.
38-
39-
#### Implemented (or mostly implemented) CGB-specific registers:
40-
- `KEY1`
41-
- `SVBK`
42-
- `VBK`
43-
- `BCPS/BGPI`
44-
- `BCPD/BGPD`
45-
46-
### CPU
47-
The CPU is fully implemented.
48-
49-
Almost all IRQs are supported, with the exception of `SC` (no Serial support yet), plus `STAT` might be broken, but testing points to it being close to perfectly emulated.
50-
51-
### Mapper/cartridge type support
52-
Most common mappers are fully implemented, that is:
53-
- `ROM only`
54-
- `MBC1`
55-
- `MBC2`
56-
- `MBC3`
57-
- `MBC5`
58-
59-
All of them with full ROM/SRAM banking support!
60-
61-
RTC and Rumble functions are not supported.
62-
63-
### Graphics (PPU/GPU)
64-
Color is supported! in CGB mode, there's two switchable VRAM banks, but the second one should contain a Background Tile Attribute Map that enables selecting CGB palettes in a per-tile basis, among other things like X/Y flipping tiles, etc.
65-
66-
All three layers are implemented, with full scrolling support for both background and window.
67-
68-
The OAM DMA controller is also implemented, it will log warnings when invalid transfers are attempted. The HDMA/GDMA CGB controllers are not yet supported, but short-term planned.
69-
70-
### Sound (SPU/APU)
71-
Sound emulation is finally supported, but only on Windows, as I don't really have a separate Linux machine to test things on, I'm relying in WSL2 only, which doesn't really have good sound support, I could maybe mess around with `pulseaudio`, but it didn't seem like a straightforward process to me, so that's why I decided to not support sound emulation on Linux for now.
72-
73-
Its not an accurate emulation, nor all features are supported, only channels 1, 2 and 4 are supported, that's the two square channels and a noise channel.
74-
75-
Both square channels support volume envelope, trigger, sound length, but not sweep.
76-
77-
The noise channel's sound is completely off, the documented frequency calculation formula gave out really high frequencies that were inaudible, and so I had to workaround scaling them so something could be heard, this resulted in a high pitched sound being audible alongside the noise, which is undesirable, but at least we get to hear noise stabs or percussion-like sounds.
78-
79-
### Timers
80-
`DIV` and `TIMA` (`TAC` and `TMA` aswell) are accurately emulated.
40+
## Tests
41+
- `cpu_instrs.gb` passes all tests
42+
- `dmg-acid2.gb` passes both DMG and CGB tests
8143

82-
### Blargg's tests
83-
`cpu_instrs.gb` passes all 11 tests!
44+
## Building
45+
So many things have changed in this last version that the build process is just not the same anymore, I'll fix that in upcoming commits

build-win.bat

Lines changed: 0 additions & 13 deletions
This file was deleted.

build-win.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
$SDL2_INCLUDE_DIR = $args[0]
22
$SDL2_LIB_DIR = $args[1]
33
$LGW_INCLUDE_DIR = $args[2]
4+
$IMGUI_SDL_DIR = $args[3]
5+
$IMGUI_DIR = $args[4]
6+
$IMPLOT_DIR = $args[5]
47
$VERSION_TAG = git describe --always --tags --abbrev=0
58
$COMMIT_HASH = git rev-parse --short HEAD
69

710
md -Force -Path build > $null
811

9-
c++ -c src/geebly.cpp -o build/geebly.o -I"`"$($SDL2_INCLUDE_DIR)`"" -I"`"$($LGW_INCLUDE_DIR)`"" -std=c++2a -m64 -Ofast -Wno-format -Wno-narrowing -D GEEBLY_VERSION_TAG=$VERSION_TAG -D GEEBLY_COMMIT_HASH=$COMMIT_HASH
12+
c++ -c src/geebly.cpp -o build/geebly.o -I"`"$($SDL2_INCLUDE_DIR)`"" -I"`"$($LGW_INCLUDE_DIR)`"" -I"`"$($IMGUI_DIR)`"" -I"`"$($IMGUI_SDL_DIR)`"" -I"`"$($IMPLOT_DIR)`"" -std=c++2a -m64 -mbmi2 -Ofast -Wno-format -Wno-narrowing -D GEEBLY_VERSION_TAG=$VERSION_TAG -D GEEBLY_COMMIT_HASH=$COMMIT_HASH -Wunused
1013

11-
c++ build/geebly.o -o build/geebly.exe -L"`"$($SDL2_LIB_DIR)`"" -m64 -lmingw32 -lSDL2main -lSDL2
14+
c++ precomp/implot.o precomp/implot_items.o precomp/implot_demo.o precomp/imgui.o precomp/imgui_demo.o precomp/imgui_draw.o precomp/imgui_tables.o precomp/imgui_widgets.o precomp/imgui_sdl.o build/geebly.o -o build/geebly.exe -L"`"$($SDL2_LIB_DIR)`"" -limm32 -m64 -lSDL2main -lSDL2
1215

13-
del "build\geebly.o"
16+
del "build\geebly.o"

src/bus.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
#include "devices/cart.hpp"
66
#include "devices/wram.hpp"
77
#include "devices/hram.hpp"
8-
9-
108
#include "devices/ppu/ppu.hpp"
11-
12-
9+
#include "devices/joypad.hpp"
1310
#include "devices/ic.hpp"
1411
#include "devices/dma/dma.hpp"
1512
#include "devices/dma/hdma.hpp"
@@ -18,21 +15,21 @@
1815

1916
// Sound emulation is not yet supported on Linux platforms
2017
#ifdef _WIN32
21-
#ifndef GEEBLY_NO_SOUND
2218
#include "devices/spu/spu.hpp"
2319
#endif
24-
#endif
2520

2621
// Clean this whole file up
27-
2822
#define MMIO_DISABLE_BOOTROM 0xff50
2923

3024
namespace gameboy {
3125
namespace bus {
3226
bool bootrom_enabled = true;
27+
3328
u8 ro_sink = 0;
3429

3530
void init() {
31+
bootrom_enabled = true;
32+
3633
if (settings::skip_bootrom) {
3734
bootrom_enabled = false;
3835
}
@@ -63,10 +60,12 @@ namespace gameboy {
6360
// Handle an OAM read
6461
if (addr >= OAM_BEGIN && addr <= OAM_END) { return ppu::read(addr, size); }
6562

66-
if (addr == MMIO_JOYP) { return ppu::read(addr, size); }
63+
if (addr == MMIO_JOYP) { return joypad::read(); }
6764

6865
if (addr >= TIMER_BEGIN && addr <= TIMER_END) { return timer::read(addr, size); }
6966

67+
if (addr >= SPU_BEGIN && addr <= SPU_END) { return spu::read(addr, size); }
68+
7069
if (addr == MMIO_DMA_TRANSFER) { return dma::read(addr, size); }
7170
if (addr >= HDMA_BEGIN && addr <= HDMA_END) { return hdma::read(addr, size); }
7271
if (addr == MMIO_KEY1) { return clock::read(addr, size); }
@@ -134,8 +133,12 @@ namespace gameboy {
134133
// Handle an OAM read
135134
if (addr >= OAM_BEGIN && addr <= OAM_END) { ppu::write(addr, value, size); return; }
136135

136+
#ifdef GEEBLY_OLD_PPU
137137
if (addr == MMIO_JOYP) { ppu::write(addr, value, size); return; }
138-
138+
#else
139+
if (addr == MMIO_JOYP) { joypad::write(value); return; }
140+
#endif
141+
139142
if (addr >= TIMER_BEGIN && addr <= TIMER_END) { timer::write(addr, value, size); return; }
140143

141144
#ifdef _WIN32

0 commit comments

Comments
 (0)