Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - VisualStudio Code for SMS Development

Reply to topic
Author Message
  • Joined: 23 Aug 2009
  • Posts: 223
  • Location: Seattle, WA
Reply with quote
VisualStudio Code for SMS Development
Post Posted: Sat Dec 28, 2019 6:21 pm
Here is how I have been able to setup VS Code as a development environment for SMS work. I don't claim it to be the best, or that I've explored it thoroughly, but I have something in place that works and maybe that'll help you out.

I've split my work into two blobs of code:

    * A reusable framework workspace, acting as a sort of library: SMSFramework
    * An application workspace that lets me focus on the game. An example application can be found here: SMSSampleApp


You can follow that pattern or go your own way, but what's nice about VS Code is that it lets me have both workspaces loaded at the same time, and I can do source control of them independently via the IDE.

You might want to peek into those packages, as I've stored things in the .vscode/ directories that may prove useful.

Let's get started.

1. Download Visual Studio Code. N.B.: VS Code is NOT the same as Visual Studio. VS Code is lighter-weight and free.

2. Install it.

3. As part of the install process, or by clicking the little gear in the lower left of the IDE, you can select Extensions to install. I've chosen "Z80 Assembly" to do code highlighting. It's not perfect but comments are comments and instructions I've just made up out of thin air get called out appropriately. The author's GitHub can be found here: Z80 Assembly Extension.

4. [Optional] Setup Git connectivity within the IDE. You can do more than just connecting it to GitHub. For example, one game I'm working on uses an AWS CodeCommit repo for the application layer, and GitHub for the SMSFramework.

5. Creating your first workspace is kind of wonky. I save a dummy file (main.asm or whatever) in the base directory for my project, and then do File -> Add Folder to Workspace and indicate the directory. Whatever.

6. Prep the IDE to assemble and launch your game from within VS Code by creating a directory called ".vscode". Note the leading period.

7. Create a file called "tasks.json" inside the .vscode/ directory. Here's what mine looks like:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Link SMS",
            "type": "shell",
            "command": "wlalink -d -r -v -s linkfile release/YOURGAME.sms",

            "group": {
                "kind": "build",
                "isDefault": true
            },

            "dependsOn": "Assemble SMS"
        },
        {
            "label": "Assemble SMS",
            "type": "shell",
            "command": "wla-z80 -v -o ../obj/main.o main.asm",
            "options": { "cwd": "./src/" },
       
            "group": "build"
        },
        {
            "label": "Build & Run in MEKA",
            "type": "shell",
            "command": "${env:MEKA_PATH}/mekaw release/YOURGAME.sms -DEBUG",

            "group": {
                "kind": "test",
                "isDefault": true
            },

            "dependsOn": "Link SMS"
        },
        {
            "label": "Build & Run in Emulicious",
            "type": "shell",
            "command": "${env:EMULICIOUS_PATH}/emulicious.bat",
            "options": { "cwd": "${env:EMULICIOUS_PATH}/" },

            "group": {
                "kind": "test",
                "isDefault": true
            },

            "dependsOn": "Link SMS"
        }
    ]
}


...This let's me assemble and link my game by hitting CTRL+SHIFT+B in the editor. You can also open a "command palette" by pressing CTRL+P and typing "task " to see the list of tasks available. As you can see, I can launch MEKA or Emulicious from the IDE.

8. Here's an easy pitfall: make sure WLA-DX and any other programs you're using are in the environment variables. I have WLA-DX in my global PATH. I have an environment variable called "MEKA_PATH" for MEKA, and an environment variable called "EMULICIOUS_PATH" for Emulicious. You can edit these in Windows by going to System Properties -> Advanced -> Environment Variables. Those of you on a *nix environment already know how to do this.

9. WLA-DX needs to know what to assemble and link, so create a file named "linkfile" in the root of your project. Here's what mine looks like:


[objects]
./obj/main.o


And that's really all there is to it. Or at least I think that's it. I've probably forgotten something in there.
  View user's profile Send private message
  • Joined: 23 Aug 2009
  • Posts: 223
  • Location: Seattle, WA
Reply with quote
Post Posted: Tue Dec 31, 2019 6:07 pm
I've updated the instructions (and SMSSampleApp) for a better structure, as well as given an example for how to include Emulicious as a launch target from the IDE. A big thanks to Calindro for his help in making this a smoother experience!
  View user's profile Send private message
  • Joined: 23 Aug 2005
  • Posts: 37
  • Location: Manchester, UK
Reply with quote
Post Posted: Wed Jan 08, 2020 1:02 am
I am doing exactly the same thing except I'm using C compilation. I just set up a C development environment after chatting with the devkitSMS team on GitHub. I'm about to migrate this to VS Code also and wondered why you didn't call a batch script? Is there something that I should know before attempting that?

Cheers

[Edit] I will make my tests here: https://github.com/gpaluk/sms-testing
Capture.PNG (75.42 KB)
Capture.PNG

  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14968
  • Location: London
Reply with quote
Post Posted: Wed Jan 08, 2020 8:20 am
It’s more conventional to use build scripts like makefiles or cmake for C development - although this can also be used for assembly development. Batch files are considered rather more fragile, and less extensible for more complex projects; build systems are also more designed for detecting which steps are unnecessary and skipping them.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Aug 2005
  • Posts: 37
  • Location: Manchester, UK
Reply with quote
Build success
Post Posted: Mon Jan 13, 2020 8:46 pm
Indeed. And I was simply able to add the relevant programs onto my environment vars paths and run that batch file to build and launch the ROM. Excellent stuff !! :)
build.PNG (112.98 KB)
build.PNG

  View user's profile Send private message Visit poster's website
  • Joined: 08 Dec 2013
  • Posts: 200
Reply with quote
Post Posted: Tue Jan 21, 2020 3:58 pm
That reminded me that I was working on a VSCode extension for WLA-DX syntax colouring; I need to finish that up.


[Extension Development Host] - sonic_the_hedgehog.asm - Sonic1-Z80-ASM 21_1_20 3_55_32 PM.png (83.5 KB)
Screenshot of VSCode with WLA-DX syntax colouring
[Extension Development Host] - sonic_the_hedgehog.asm - Sonic1-Z80-ASM 21_1_20 3_55_32 PM.png

  View user's profile Send private message Visit poster's website
  • Joined: 12 Oct 2015
  • Posts: 194
  • Location: Ireland
Reply with quote
Inspired
Post Posted: Sun Mar 21, 2021 4:55 pm
Inspired from this forum topic, I have also setup Visual Studio Code for SMS Development for both Z80 and C source code with build scripts hooked up to Ctrl + Shift + B too plus the ability to debug step thru source code using the VS Code Emulicious Debugger extension.. All of which is documented here: https://steveproxna.blogspot.com/2021/02/z80-programming-setup.html
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!