Basic Interpreter With Shared Variables

I expanded the BASIC script interpreter in to include an example of how you can share variables between your program and the script. For example, you can set a counter in your program, pass that value to the script, and have the script update the value, and then use the new value in your program. Note that since the make file is for Qt, I suggest you compile with g++ *.cpp -o basicscript.

The example ConsoleBasic class now shares two variables with the script, in addition to the CLS command we added in the previous post. An integer variable counter and a string in name$ are now read and modified in the sharedvariable.b sample script.

Continue reading Basic Interpreter With Shared Variables

Basic interpreter with custom command

I expanded the BASIC script interpreter in to include an example of how you can extend the interpreter and add your own commands to it. Sorry about the Makefile depending on Qt. I’ll create a generic Makefile next version I release.

I created a ConsoleBasic object, then added the cls command. You can see I add it in the constructor, then in execAddonCommand I check the token that is passed in to figure out what command I should execute, which in this case can only be one command, then clear the screen via ANSI escape codes.

Next example will show how to make your C++ variables available to BASIC.

class ConsoleBasic : public SmallBasic
    int m_cls;
    ConsoleBasic(const char* pszFilename)
        : SmallBasic(pszFilename),m_cls(0)
        m_cls = addCommand("cls");

    bool execAddonCommand(const int tok)
        if(tok == m_cls)
        return true;

Basic Interpreter for Embedded scripts

I had a few people interested in my BASIC interpreter that I was using as an embedded script interpreter. I had started using it in my MUD but pulled it out and made a stand alone example. It still needs a little cleanup and i still need to create an example of how to add more commands to it. See You can run the script with “basicscript hello.b“. hello.b uses a few commands and shows how you can use labels instead of line numbers. Line numbers are supported as well. Don’t be too hard on the code, I wrote it back in 2001!

6809 CPU Emulator project started

CpuEmulator is a CPU emulator project that aims to emulate a CPU (the 6809 to start with), it’s registers, and system memory. It will allow you to monitor registers, flags and memory as you step through code. Having done SharpiEmu for the Sharp PC–1360 Pocket Computer, the concept seems pretty simple. The 6809 has a number of addressing modes, and different opcodes for the same mnemonic. So I’m expecting it to be somewhat more of a challenge.

Initial version will emulate the CPU, memory, and text video mode.


  • Emulate 6809 instructions
  • Emulate 32×16 & 80×24 text modes
  • Emulate the Coco3’s MMU
  • 4K all the way up to 512KB memory options
  • Debugger that steps through code, shows current state of registers, selected memory block, and source code from a listing file.
  • Break points. They are remembered between runs.
  • Memory watcher. When memory at a certain addresses are modified, a breakpoint is triggered so you can see what modified it.

Continue reading 6809 CPU Emulator project started

CxxTest for unit testing C++ programs

I just discovered CxxTest, and just had to mention it. Fantastic unit test framework for C++ programs. To brush up on my C++ coding, I decided to write a simple 6809 CPU emulator, with the goal of being able to plug-in other CPU’s. This project really lends itself to the idea of unit tests. It’s very easy to test each part of the emulator, and check the results after an instruction has run.

After reading @noel_llopis‘s article¬†Exploring the C++ Unit Testing Framework Jungle I figured I would check out CppUnit first, since I had seen it mentioned it was¬†the standard on, or at least widely used. Not sure how that is possible, given the weak documentation and complicated setup. The docs never once tell you what to include and what to link against. 30 minutes later I decided to move onto CxxTest. Glad I did as CxxTest was very simple, and I had unit tests running within 5 minutes. The true mark of a well setup project. My emulator processed it’s first instruction today, LDX #$1234. And the unit tests were right there to validate the results.