You are browsing as a guest. Sign up (or log in) to start making projects!

GBWeb

  • 2 Devlogs
  • 7 Total hours

A Gameboy emulator in the web via WASM

Open comments for this post

3h 34m 45s logged

Devlog 2 - SDL3 and File Loading

  • After setting up the project basics, I spent some time on another project, also using SDL, but a desktop app. This used SDL3 instead of SDL2, which is default for Emscripten. I decided to switch this project to SDL3 as well, since I feel more comfortable with it and it has some features like main callbacks that should help with Emscripten. Instead of using the SDL library bundled with Emscripten, I instead added the SDL3 repo as a submodule, so I should be able to make a desktop version of the program later relatively easily.
  • After switching to SDL3, I researched how to load a file from the user in the web browser into the webasm program. I found a StackOverflow thread that helped a lot, which included a link to a more developed header library, however I opted not to use this, as it was C++ based, and I wanted to remain using C. Instead I just implemented the bits I needed from the thread in C, which wasn’t too hard, although included some JS, which I’ve never used and some pointers which I made a few stupid mistakes with, causing me to think it didn’t work for a while.
  • Finally, I also added a keybind to open the file dialog, which currently is tab, and also made sure that the keys only register on the down press, and not the up as well.
0
0
7
Open comments for this post

3h 38m 31s logged

Devlog 1 - Setup and basic input

I took a while to find a toolchain that I liked, but I’ve settled on using Emscripten, and it’s built in version of SDL2. Emscripten is a library and compiler for CXX that allows direct compilation to web assembly and JavaScript, also allowing graphics and input with SDL. This makes it a lot easier for me to write the program, as I don’t really need to know as much JS or find multiple different libraries to use.

Originally I wanted to use SDL3, but I couldn’t get the input to work automatically with Emscripten, and with this being my first major C and web project, I decided to take the easier path and simply use the fully supported SDL2.

I also spent some time setting up a simple CMake system and some scripts for building and running, which took me a while to figure out, especially as I was also learning Emscripten for the first time, however it will hopefully save me time in the long run.

Just to test my implementation, I set up some keybinds for the eventual emulator to come. I just used SDL scancodes to check for the key press, and they printed the corresponding Gameboy button to the output. You can see this in the video below. For simplicity, I decided to just set keys in code, with WASD being the dpad, J being A, K being B, Return being Start and Backspace being select.

0
0
1

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…