HOME About NCOT Documentation SineSoft Social Media Support Me


Made from 100% Programmer Art

[Blog] [Prototypes] [Labs]
How to Write Emulator - Intro

How to Write Emulator - Intro


To begin, this isn’t technically an emulator, the system I’m trying to model isn’t real. This is more of a simulator, but that’s less of a catchy search word on the Internet.

What is Core War

“Core War is a 1984 programming game created by D. G. Jones and A. K. Dewdney in which two or more battle programs (called “warriors”) compete for control of a virtual computer. These battle programs are written in an abstract assembly language called Redcode.” Wikipedia

There are some terms that are helpful to know, and which I will probably end up mixing together

  • Core War - This is the programming game itself
  • Warrior - A program written in Redcode
  • Redcode - The assembly language
  • MARS - Memory Array Redcode Simulator. The actual simulator.
  • Core - The memory where the programs run

What I’m Making

I’m making a version of the MARS in C++, which can run and interpret the Redcode programming language. The aim being to create a simulator that can load and execute Redcode programs, displaying the state of the simulator and possibly allow running programs to be debugged.


Redcode is a type of assembly language, modelled after CISC assembly languages of the 1980s. It looks like this:

ADD.AB  #   4, $   3
MOV.F   $   2, @   2
JMP.B   $  -2, $   0
DAT.F   #   0, #   0

Each instruction contains an opcode and two operands. The opcode can have an optional modifier, and the operands can have optional addressing modes. The combination of the simple opcodes with the modifiers and addressing modes allows complex “Warriors” to be created. The aim being to write a warrior that will outlast all the other running warriors in the simulation.

Steps Required

To make this work, I need to create the following sections

  • A simulation of the machine’s RAM (called the “core”). This is 8000 bytes of contiguous memory which is treated as a circular array. The ends wrap around.
  • The MARS itself. A Redcode simulator follows a well defined Fetch-Decode-Execute cycle where each instruction takes one cycle to complete.
  • A file parser for source code. A programmable machine is of no use if there’s no way to get code into it, after all!
  • Visual display. Most CoreWar simulators show the core as a grid of blocks so you can watch the programs running. Some allow programs to be disassembled or stepped through.

Related Content

  • #GitHubGameOff Jam 2019 Day 1
    November 2, 2019
    Day 1 of the #GitHubGameOff jam, where I create a basic platform controller and level builder.

  • Minimum Spanning Tree
    October 29, 2019
    An implementation of the Minimum Spanning Tree algorithm, with some nice motion

  • One Lone Coder Jam 2019
    September 8, 2019
    In this game jam I learn all about the importance of having a decent game idea before even starting to write any code

  • Godot Wild Jam 12
    August 20, 2019
    Between the 9th and 16th August 2019 I took part in the Godot Wild Jam #12. Let’s go through what it was like, and the things I learned this time.

  • GMTK Game Jam 2019
    August 7, 2019
    I enter the GMTK Game Jam 2019 using Pico 8, and make a game in about seven hours.