rolandshacks / vs64

C64 Development Environment for Visual Studio Code
Other
102 stars 18 forks source link

Version Installs Build Status

VS64 - The C64 Development Environment

VS64 is an open-source extension for Visual Studio Code.

The VS64 extension makes it easy to develop software for the C64 using Visual Studio Code. It provides in-depth support for 6502 assemblers, C and C++ compilers and the BASIC programming language. It comes with a project and build system, compilers and converters for BASIC and resource files, and it integrates well with all the advanced features of Visual Studio Code, such as the task and launch system, debugging and introspection and language grammar and semantics support.

Features and Supported Languages/Toolkits

Quick and Start (TL;DR)

Getting Started

The quickest start is by opening the command palette and run the "VS64: Getting Started" command.

If you want to do some manual steps or adjustments, these are the individual things to look at:

Creating Projects Quickly

The "Create Project" commands are a great tool to configure and re-configure a code project. Whenever such a command is issued, the current workspace will be scanned and a fresh project configuration file will be generated based on the existing source files. Afterwards, everything should be ready to build and run.

Setup

ACME Cross-Assembler

VS64 supports the ACME Cross-Assembler.

In case you did a manual or custom installation, please make sure you updated the VS64 settings with the correct ACME installation path.

Kick Assembler

VS64 supports Kick Assembler.

Please make sure you check the VS64 settings for the correct KickAssembler installation path.

LLVM-MOS Compiler

VS64 also supports the LLVM-MOS C/C++ Compiler.

Please make sure you update the VS64 settings with the correct LLVM-MOS installation and include paths.

CC65 Compiler

VS64 also supports the CC65 6502 C Compiler.

In case you did a manual or custom installation, please make sure you update the VS64 settings with the correct CC65 installation and include paths.

Oscar64 Compiler

VS64 also supports the Oscar64 C Compiler.

In case you did a customized installation, please make sure you update the VS64 settings with the correct Oscar65 installation and include paths.

BASIC Compiler

VS64 supports compiling BASIC source to binary programs.

In order to use the basic compiler, just add your BASIC source files to the "sources" list of the project file.

Crunching BASIC Code

The basic compiler supports crunching of BASIC code:

To enable this feature, just set the build mode in the project file to "release":

"build": "release"

Upper/Lower Case Character Set

In order to properly use the different ROM character sets in BASIC programs, remapping of upper/lower case character codes is needed. This can be achieved in two different ways:

Info: Use POKE 53272,23 or PRINT "{lower}" to actually switch to the upper/lower case charset, and use POKE 53272,21 or PRINT "{upper}" to switch back to the default charset.

Example of properly using the upper/lower case character set in source code:

#lowercase
10 print "{lower}"
20 rem "* AaBbZz *"
30 print "AaBbZz"

Example of BASIC compiler flags in the project file instead of the #lowercase preprocessor directive:

"args": ["--lower"]

Raw Strings

In order to use characters without upper/lower case conversion, use single quoted raw strings:

#uppercase
10 PRINT "{upper}"
20 PRINT "HELLO"
30 PRINT 'Hello'

Auto-Numbering

The compiler adds line numbers automatically. In case a basic line does not contain a line number, it uses 'last number + 1'. Whenever static line numbers are given in the source code, automatic counters continue from there.

For example:

10 A$="HELLO"
PRINT A$
50 B$="WORLD"
PRINT B$

Will be compiled to:

10 A$="HELLO"
11 PRINT A$
50 B$="WORLD"
51 PRINT B$

Use of Labels

In addition to using line numbers as jump targets, the basic compiler also lets you use labels.

Here's one example:

label1:
    A$="HELLO"
    PRINT A$
    GOTO label1

Will be compiled to:

1 A$="HELLO"
2 PRINT A$
3 GOTO 1

PETSCII Control Characters

The usage of PETSCII control characters is supported via the extended string control character syntax:

PRINT "{clr}HELLO, {green}WORLD{$21}{lightblue}"

A control token within a string is either a {mnemonic}, {number}, {$hex}, {0xhex}, {%binary} or {0bbinary}.

The following mnemonics are available: {space}, {return}, {shift-return}, {clr}, {clear}, {home}, {del}, {inst}, {run/stop}, {cursor right}, {crsr right}, {cursor left}, {crsr left}, {cursor down}, {crsr down}, {cursor up}, {crsr dup}, {uppercase}, {upper}, {cset1}, {lowercase}, {lower}, {cset0}, {black}, {blk}, {white}, {wht}, {red}, {cyan}, {cyn}, {purple}, {pur}, {green}, {grn}, {blue}, {blu}, {yellow}, {yel}, {orange}, {brown}, {pink}, {light-red}, {gray1}, {darkgrey}, {grey}, {lightgreen}, {lightblue}, {grey3}, {lightgrey}, {rvs on}, {rvs off}, {f1}, {f3}, {f5}, {f7}, {f2}, {f4}, {f6}, {f8}, {ctrl-c}, {ctrl-e}, {ctrl-h}, {ctrl-i}, {ctrl-m}, {ctrl-n}, {ctrl-r}, {ctrl-s}, {ctrl-t}, {ctrl-q}, {ctrl-1}, {ctrl-2}, {ctrl-3}, {ctrl-4}, {ctrl-5}, {ctrl-6}, {ctrl-7}, {ctrl-8}, {ctrl-9}, {ctrl-0}, {ctrl-/}, {c=1}, {c=2}, {c=3}, {c=4}, {c=5}, {c=6}, {c=7}, {c=8}

Resource Compilation

VS64 comes with an integrated resource compiler that turns media files into plain source code to be directly referenced by the code and compiled into the binary. Currently, the supported media formats are:

In order to use the resource compiler, just add your resources files to the "sources" list of the project file.

Please notice: The resource compiler requires a Python 3.x interpreter to be used. On Windows, the VS64 extension is providing a minimalistic fallback setup out of the box, while on Linux and MacOS, it is assumed that Python is already installed and running just fine.

VICE Emulator

In addition to the internal 6502 cpu emulator, VS64 also supports debugging using the VICE emulator.

In case you did a manual or custom installation, please make sure you update the VS64 settings with the correct VICE executable.

Please notice: It is recommended to use or upgrade to version 3.7 of VICE as with this version, the binary monitor interface has been declared stable.

Commander X16 Emulator

VS64 provides launch integration for the Commander X16 emulator.

Please make sure you update the VS64 settings with the correct x16emu executable.

General Usage

The VS64 extension provides a convienient editing, build and run environment. This is done by providing syntax highlighting, seamless integration to the task, build and launch system, an embedded 6502 CPU emulator for fast and precise evaluation of 6502 code and integration of the VICE C64 emulator for advanced system debugging. For further analysis, an integrated disassembler and BASIC-decompiler for C64 program files is provided.

For details, please look at the provided example projects for ACME, LLVM-MOS, CC65 or BASIC.

Build System

VS64 provides a meta build system which is based on the Ninja build toolkit. Dependency scanning and the generation of intellisense information is supported.

Syntax Highlighting

Support for ACME assember syntax is provided. Syntax highlighting for KickAssembler is partially implemented. The recommended file extension is .asm.

Project Configuration

The VS64 extension is mainly controlled and configured using a per-workspace project configuration file project-config.json. The project config file needs to reside in the root folder of the project and needs to be in JSON format.

The general structure of the file is like this:

{
    "name": "example",
    "description": "Example project",
    "toolkit": "acme",
    "main": "src/main.asm",
    "build": "release",
    "definitions": [],
    "includes": ["src/includes"]
}

A more extensive project file for CC65 using source and resource files could like like this:

{
    "name": "cexample",
    "description": "Example for the CC65 compiler",
    "toolkit": "cc65",
    "sources": [
        "src/main.c",
        "libc64/src/audio.c",
        "libc64/src/auxiliary.c",
        "libc64/src/system.c",
        "libc64/src/video.c",
        "libc64/src/sprite.c",
        "resources/sprites.spm"
    ],
    "build": "debug",
    "definitions": [],
    "includes": ["libc64/include"]
}

A project file for CC65 could like like this:

{
    "name": "cppexample",
    "description": "Example for the LLVM-MOS sdk",
    "toolkit": "llvm",
    "machine": "c64",
    "sources": [
        "src/assem.asm",
        "src/main.cpp"
    ],
    "build": "debug",
    "definitions": [],
    "includes": [],
    "args": [],
    "assemblerFlags": "",
    "compilerFlags": "",
    "linkerFlags": "",
    "compiler": "",
    "resources: {}
}

To specify resource compiler flags and options, add a section "resources" to the project file using the following syntax:

{
    "name": "example",
    ...
    "resources": {
        "sampleFrequency": 8000,
        "sampleBits": 8
    },
    ...
}

A project file for a BASIC program could look like this:

{
    "name": "basic_example",
    "description": "Example for BASIC",
    "toolkit": "basic",
    "sources": [
        "src/main.bas"
    ],
    "args": ["--lower"]
    ...
}

Example project file to use C++ for the Commander X16:

{
    "name": "x16",
    "description": "Project x16",
    "toolkit": "llvm",
    "sources": [
        "src/main.cpp"
    ],
    "build": "debug",
    "definitions": [],
    "includes": [],
    "args": [],
    "compiler": "",
    "machine": "cx16"
    ...
}

name

Project name, also defines the name of the output program file name.prg.

description

Project description, for information purposes.

sources

Defines all used source and resource files. The build system will keep track of changes of these files. Resources files will be translated to language-specific to binary data declarations.

toolkit

Specifies which build toolkit is used. Currently supported are "acme", "kick", "llvm", "cc65", "oscar64" and "basic".

machine

Specifies the target system which the binaries should be generated for. Default is the C64, possible settings are dependent on the used toolkit.

main

Can be used instead of 'sources' in simple projects. Defines the main source file which is compiled and used as the entry point for recursive dependency scanning.

build

Defines either a "release" or "debug" build. Debug builds are the default if not specified.

definitions

Optional project specific compiler defines. The project defines are added to the global defines as specified in the settings.

includes

Optional project include paths for the compiler. The project specific include paths are added and overlay the global include paths specified in the settings.

args

Optional argument list to be added to the build tool command line arguments. For more fine grained setting, use the 'assemblerFlags', 'compilerFlags' and 'linkerFlags' attributes.

assemblerFlags

Optional arguments to be added to the assembler command.

compilerFlags

Optional arguments to be added to the compiler command.

linkerFlags

Optional arguments to be added to the linker command.

Example to use a specific linker configuration for cc65:

"linkerFlags": [
    "--config", "c64.cfg"
]

compiler

Overrides the path to the compiler executable. The default path is specified in the settings.

resources

Optional parameters for the resource compiler. Currently, the following list of parameters is supported:

Example:

"resources": {
    "sampleFrequency": 8000,
    "sampleBits": 8,
    "sampleLoudness": -9.0,
    "sampleNormalizationMax": 5.0
}

rcFlags

Optional arguments to be added to the resource compiler command. Use this to force the resource compiler to produce a specific output format, where format can be 'cpp', 'cc', 'acme' or 'kick'.

{
    ...
    "rcFlags": "--format cpp"
}

Disassembler and BASIC De-Compiler

VS64 supports on-the-fly disassembly of .prg files containing either machine code or BASIC programs. In order to use it, just open a .prg file in the Visual Studio Code editor.

D64 File System Provider

VS64 allows mounting D64 files as virtual folders of the Visual Studio Code workspace tree.

To add a D64 file to the workspace, simply select a .d64 disk file, then right-click and select "Mount". In case the disk was successfully opened, there should be a new folder at the root level of the project workspace.

In order to unmount a virtual D64 folder, simple select the workspace folder and choose "Remove from workspace".

Supported actions:

Some additional notes:

IntelliSense Support

The VS64 build system supports the IntelliSense editing features of Visual Studio Code. Project settings, include paths and defines are automatically provided to the IntelliSense system.

Further information about IntelliSense can be found here.

Background Compilation

Whenever a referenced source file or the project settings file is modified and saved, it is automatically compiled to a C64 (cbm) .prg program file.

If compilation is successful, that program file can either be run/debugged with the embedded debugger based on a defined launch configuration (see Debugger Launch Configuration), or it can be loaded into a VICE emulator session to run an advanced debugging session.

If compilation fails, the ACME outputs are shown in the problems view as well as in the output terminal view.

Debugging

Debugging Features

The VS64 extension comes with a built-in 6502 CPU emulator that allows very fast edit-build-run cycles. The limitation is important to understand: it is not a full C64 emulation. It executes 6502 machine code as fast as possible - and integrates nicely to the Visual Studio Code debugger interface. But it does not emulate any of the C64 custom chips (the VIC, SID, CIA, etc.). To still run C64 code similar to what would happen on a real C64, the bank switching and handling of ROM memory areas is supported. Also, basic startup behavior is supported in a way that actual C64 program files can be loaded and executed.

As another option for debugging, a VICE emulator session can be launched or attached to perform advanced debugging steps in an acurate C64 system emulation.

Supported debugging features:

Debugging support for the CC65 toolkit

Debugging support for the LLVM Toolkit (Elf/Dwarf):

Debugging support for the BASIC Toolkit:

Please notice: Debugging with a release build can be quite challenging. In order to enable correct behavior, use a "debug" build for debugging sessions (by setting the flag in the project configuration).

Debugger Launch Configuration

In order to debug a compiled C64 program (.prg) you have to create a launch configuration. Here are a few examples:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "6502",
            "request": "launch",
            "name": "Launch 6502",
            "preLaunchTask": "${defaultBuildTask}"
        },
        {
            "type": "vice",
            "request": "launch",
            "name": "Launch Vice",
            "preLaunchTask": "${defaultBuildTask}"
        },
        {
            "type": "vice",
            "request": "attach",
            "name": "Attach Vice",
            "hostname": "localhost",
            "port": 6502,
            "preLaunchTask": "${defaultBuildTask}"
        },
        {
            "type": "x16",
            "request": "launch",
            "name": "Launch X16",
            "preLaunchTask": "${defaultBuildTask}"
        },
    ]
}

type: Launch type

Can be either "6502" to run the integrated 6502 cpu emulator, "vice" to run a VICE emulator based debugging session or "x16" to launch the Commander X16 emulator.

request: Request type

Use "launch" here to run a new emulation session. In case "vice" is selected as debugger type, then a new VICE process is started. Use "attach" to attach to a running VICE process. VICE needs to have the binary monitor interface enabled, or has to be started with the -binarymonitor and -autostartprgmode 1 command line arguments.

name: Launch configuration name

Any name you want to use is fine.

hostname: Host name

Optional name of host running a VICE emulator with enabled binary monitor. If not specified, 'localhost' will be used.

port: Port number

Optional port number of running a VICE emulator with enabled binary monitor. If not specified, the binary monitor default port '6502' will be used.

pc: (6502 only) Optional parameter to overwrite the start address of the C64 program. Default is taken from the first two bytes of the program file.

A 16-bit address in decimal or $hexadecimal form.

preLaunchTask: Task to be executed before launch

Optional task name, can be ${defaultBuildTask} to use the currently configured default build task.

Debugger Watch Expressions

The debugger supports different kinds of watch expressions: registers, constant values and addresses. Here are a few examples for direct, symbolic and indirect watch expressions:

Preferences/Settings Reference

To setup the C64 development environment, go to Preferences>Settings to open the settings window.

Build System Settings

VS64: Acme Install Dir

Path to Acme installation. Example: C:\Tools\c64\acme.

VS64: KickAssembler Install Dir

Path to KickAssembler installation. Example: C:\Tools\c64\kickassembler.

VS64: Cc65 Install Dir

Path to Cc65 installation. Example: C:\Tools\c64\cc65.

VS64: LLVM Install Dir

Path to LLVM-MOS installation. Example: C:\Tools\c64\llvm-mos.

VS64: Build Defines

Global build defines.

VS64: Build Includes

Global build include paths.

VS64: Build Args

Global build command line options.

VS64: Ninja Executable

Path to custom Ninja build executable. Example: C:\Tools\bin\ninja.exe. Leave blank to use the embedded Ninja executable that is distributed with the extension.

VS64: Python Executable

Path to custom Python installation. Example: C:\Tools\python\python.exe. Leave blank to use an installed Python environment or (on Windows) use the minimalistic Python environment distributed with the extension.

VS64: Java Executable

Path to Java executable. Example: C:\Tools\jdk\bin\java. Leave blank to use an installed Java Runtime / JDK environment.

VS64: Basic Compiler

Path to a Python script to be used as a drop-in replacement for the VS64 BASIC compiler (bc.py).

VS64: Resource Compiler

Path to a Python script to be used as a drop-in replacement for the VS64 resource compiler (rc.py).

VS64: Auto Build

Enable auto build before running or debugging.

Emulator Settings

VS64: VICE Executable

Path to Vice emulator executable. Example: C:\Tools\c64\vice\bin\x64sc.exe.

VS64: VICE Arguments

Additional VICE emulator command line options.

VS64: VICE Port

Port number to use to connect to the VICE emulator debug interface (6502 is the default).

VS64: X16 Executable

Path to X16 emulator executable. Example: C:\Tools\x16emu\x16emu.exe.

VS64: X16 Arguments

Additional X16 emulator command line options.

Misc Settings

VS64: Log Level

Set console output verbosity level (error, warn, info, debug, trace).

VS64: BASIC Charset

Set default charset for the BASIC compiler and disassembler ("big/graphics" for character set 1, or "small/big" for character set 2).

VS64: Recursive Label Parsing

Can be used to disable recursive parsing of assembly files. Mostly used for debugging purposes. Default and recommendation is to leave it enabled.

VS64: Show Welcome

Enable the welcome page. This setting is automatically disabled after the welcome page has been shown.

Open Source

This package includes open source from other developers and I would like to thank all of those:

Links