Wednesday, 13 July 2016

Monkey2 development setup

Today's post will be a bit different. It will not be about retro computing per se, but about my development setup and the tools  I use to create retro styled games. You know, the ones you can download from the My Games page.

This post is by request, but also for myself to remind me later on how I did things. :)

I am using Linux to develop but the idea is the same on all major platforms (Linux, Windows, MacOS)

Development Setup

Monkey2 is the new language by Amiga veteran Mark Sibly. It evolved from the Blitz Basic language and from the multi-platform Monkey language.  Monkey2 code is translated to C++ code and then compiled, and it uses SDL2 for graphics, input, audio, etc so it's perfect to create games!!

Monkey2 is in development, but the 1.0 version is very capable and a lot of fun to use!

The things I make with Monkey2 are located on my Github page, in a new area called mutated monkey. Here you can find my code examples, game framework, sublime text configurations, code snippets and more...

Here's an overview of my development system setup:

  • Operating System: Linux Mint 17.3
  • IDE/Editor: Sublime Text 3
  • Builder: Gradle
  • SmartGit: source repository client
  • Monkey2: language translator
  • Java: to run SmartGit and Gradle


I downloaded the archive from this page and unpacked it in my home folder. I am not going to explain how to set this up, but after starting SmartGit you can clone repositories from Github easily.

Sublime Text 3

ST3 can be downloaded from its website, or you can use the software manager. The website has the newer version, almost all of the time. Install it using the downloaded .deb package. 

Monkey2 Language Definition

I've made a Monkey2 language definition file and handy snippets. This file needs to go into your ST3 Packages/User/ folder.  For Linux, this is under ~/.config/sublime-text3/. This path will differ on other OS types.

Simplest thing to do is to make a monkey2 sub-folder in the User folder and put the contents of the repository in there. Now, when you restart ST3, you can select Monkey2 under View/Syntax/


Monkey2 is free to use and you can download it from the Monkey2 web site. A smarter thing to do is to use SmartGit to clone the github repository to your local drive. I cloned the repository to my home directory, and then ran monkey2/scripts/ to build the modules, editor (TED2) and docs. You may have to set the execution bit on the scripts to make them executable.


The build system used is Gradle ( Gradle is free and requires Java. Install Java and Gradle according to the installation guide, and make sure you can start Gradle from the command line, from anywhere on the system (meaning: add the Gradle path to the system path variable)


Now we have all the tools in place, lets get to work. Here's now to setup a ST3 project which will use Gradle to build your application or module.

To achieve this, we need to create 3 files in a project folder:
  • <projectname>.sublime-project
  • build.gradle
  • main source file

sublime-project file

I always work with projects, it makes life so much easier inside ST3. ST3 makes it simple to move between projects and each project can have its own build systems.

To use Gradle for building we use a build system from the Sublime Text Tools menu We create these by adding a build system (or more than one) to a Sublime Text project file.

You create a new project by selecting Add folder to Project from the Project pull down menu. So first create a folder, then use this menu item. Save the project by using Project/Save Project As. I advise you to put the sublime-project file in the project folder.

Now, choose Project/Edit Project and paste the following template in it:

"folders": [
"path": ".",
"file_exclude_patterns": [ ".git*", "*.i", "*.sublime-workspace"],
"folder_exclude_patterns": [".gradle"]
    "build_systems": [
            "name": "Gradle: Build and run TEST debug",
            "cmd": "gradle --daemon build_project_debug",
            "working_dir": "${project_path}",
            "shell": "true"
            "name": "Gradle: Build and run TEST debug CLEAN",
            "cmd": "gradle --daemon build_project_debug_clean",
            "working_dir": "${project_path}",
            "shell": "true"
            "name": "Gradle: Build and run TEST release",
            "cmd": "gradle --daemon build_project_release",
            "working_dir": "${project_path}",
            "shell": "true"



This project template has three build systems. The first will create a debug build. The second will also create a debug build, but it will clean the build folder beforehand. The third build system will create a release build.

As you can see, the command to run for each build system is a shell command; each will start Gradle with the required parameters. First --deamon, which will keep Gradle running in the background for faster builds, and then the task to execute, which is defined in the build.gradle file in the same folder. These build systems do NOT call mx2cc! We will let Gradle do that.

Save the project and the build systems will appear in Sublime Text's Tools/Build System menu. You need to select one and then you can use CTRL-B to build.

build.gradle file

Now we need to create the build.gradle file. This file will hold the definitions of the build tasks we want to execute, mainly the entry source file and the command line to build. Create a new file in the project folder and edit it by pasting this text into it:

def PROJECT_NAME = "asteroids.monkey2"

task build_project_debug << {
        println "Building project DEBUG...\n"

        def command = "/home/wiebo/Monkey2/bin/mx2cc_linux makeapp -run -target=desktop -config=debug $PROJECT_NAME"
        print "Running command: '$command'\n"

        def proc = command.execute()  {line -> println line}
        proc.err.eachLine {line -> println 'ERROR: ' + line}

        def exitValue = proc.exitValue()
        if (exitValue != 0) {
                throw new GradleException ("Build project failed with exit code: $exitValue")

This is an example build.gradle file, showing only one task, but you'll get the idea, you can add more tasks. Make sure you can call them from the build systems definitions in the ST3 project file.

The PROJECT_NAME variable is set to the main file to build, in this case it is asteroids.monkey2. This file needs to be in the same location as the .gradle file, so make sure to put it there.

A task is then defined called build_project_debug. You saw this definition in the ST3 project file.

I used a hard coded path to my monkey folder inside my Linux home directory to call mx2cc_linux. If you're on windows, you need to change this to your own monkey2 bin folder and use mx2cc_windows.exe. For OSX this is mx2cc_macos. The -config=debug option is used to create a debug build.


That's it. Once you create the main monkey2 file in the project folder, and add some code to it you should be able to build. Don't forget the select the correct build system!

Happy coding!

1541 Ultimate II Guide 6 : D71 and D81 images

When you want to use your 1571 or 1581 drive with your C64 or C128 it's nice to be able to use the hardware to the fullest. That means ...