Setting Up SGDK in Visual Studio Code (With Auto-Complete)

Posted February 22, 2018

As I mentioned in part 2 of Adventures in Mega Drive Coding I set up Code::Blocks as my IDE for Mega Drive development. And Code::Blocks is great, but I still had two issues with it. First of all, auto-complete didn’t really work. Considering I’m pretty much poking around the SGDK API blindly, that wasn’t helpful. And secondly…I use VSCode for pretty much anything else coding-related, so it would be nice to also use it for SGDK stuff.

Now VSCode of course “supports” development in SGDK considering it’s just a bunch of C files, but I wanted things like auto-complete and compilation via keyboard shortcuts. Luckily I found a rather easy way to set this up!

Note: These instructions are meant for Windows. However, since Visual Studio Code is cross-platform, you should be able to get this to work on other operating systems with some slight tweaks.

  1. Download and install SGDK (obviously). Follow the steps here.
  2. Download and install Visual Studio Code (also obvious).
  3. Clone this git repo (or download/extract it as a .zip file). It doesn’t matter where you put it. Inside is a folder called .vscode. Open it.
  4. Open the file c_cpp_properties.json with a text editor. Change includePath to point to the inc folder of your SGDK installation (for example "includePath": ["c:/sgdk/inc"])
  5. Copy the .vscode folder into your project directory.
  6. When you open the project in VSCode now, you should be able to compile it via the Command Palette (Ctrl+Shift+P) or directly (Ctrl+Shift+B). Auto-complete should also be working. Sweet!

Bonus: Loading the Rom After Compilation

That’s already pretty cool. But there was one last thing I was missing: I had set up Code::Blocks to automatically load up my compiled rom in an emulator. Luckily this is also possible in VSCode!

First you need to create a .bat file using your favorite text editor. Just call it anything you want, I named mine run.bat. In it we’ll add two lines. The first will make the project, the second will load the rom in our emulator. My .bat file looks like this:

%GDK_WIN%\bin\make -f %GDK_WIN%\makefile.gen
%GDK_WIN%\gensk\gens.exe %cd%/out/rom.bin

If you’ve set up the environment variables as described in the SGDK tutorial, the first line should look the same for you.

The second line depends on what emulator you’re using and where it is. I am using Gens KMod which I’ve put in a gensk subfolder within the main SGDK folder. Just alter the first part of the second line to point to your emulator executable.

With the .bat file done, open up the tasks.json file in your project’s .vscode folder. You can see that two tasks have already been defined: makeand clean. We’re gonna add a third one. Paste the following below the other two tasks (and don’t forget the comma after the closing curling braces of the previous task!):

    "isBuildCommand": false,
    "suppressTaskName": true,
    "echoCommand": true,
    "taskName": "makeAndRun",
    "args": [

You can set taskNameto whatever you want. The string in args should point to the .bat file you created.

And you’re done! When you fire up your project now and open the command palette, your new command should be available. Also, one final pro tip: If you set isBuildCommand to true, that command will be called directly whenever you press Ctrl+Shift+B. Now you can compile and run your game with a single shortcut!

I hope this helped, let me know if you have any questions or comments. And thanks to pleft for the templates!

Join my Discord Server!

Hang out, get news, be excellent!

Come hang out!

Want To Buy Me a Coffee?

Coffee rules, and it keeps me going! I'll take beer too, though.

Related Posts

About the SGDK Tutorials

POST | | #SGDK #Announcement

They’re on hiatus.

Using Shoebox With MonoGame

POST | | #Tutorial #MonoGame

If you’ve worked with spritesheets at any point you might have worked with tools like TexturePacker or Shoebox, which can make creating and managing spritesheets a lot easier. I’ve actually not used them until now, but since I’m experimenting with a new framework (MonoGame) I thought I might as well give them a try! However, while TexturePacker has built-in MonoGame support you can only access it in the paid version. Shoebox is completely free, but doesn’t offer support for MonoGame out of the box…but luckily you can modify the output parameters to enable that support!

HaxeFlixel Tutorial: Single Separation Collisions

POST | | #HaxeFlixel #Speer #Tutorial

Collision detection (and handling) is one of the most fiddly things when it comes to creating games, at least in my experience. There seems to be no shortage of weird bugs and issues that can pop up throughout the entire dev cycle of a game (the weirdest one I’ve encountered so far is this one right here). It’s a good thing then that HaxeFlixel comes with several functions that can take care of it for you.

By using the Disqus service you confirm that you have read and agreed to the privacy policy.

comments powered by Disqus