Simulator

The Meggy Jr RGB is a handheld game system based on the arduino platform, and it is programmed in the C programming language via a limited arduino programming environment. Meggy has available to it a low-level library of system functions, called MeggyJr, and a simpler library on top of that called MeggyJrSimple. Although writing programs for Meggy is a simple task for an experienced C programmer, the arduino programming environment is not very robust, has severely limited debugging capabilities, and requires a fair amount of hassle in uploading and testing Meggy programs on an actual Meggy unit. The Meggy Simulator allows the programmer to write Meggy programs entirely within the Visual C++ environment, taking full advantage of their more robust features, eliminating upload hassles, speeding up development, and ultimately allowing the Meggy program to be compiled, played, and shared with Neanderthals that don't even have a Meggy!

Set against all these advantages are a handful of relatively minor disadvantages. The Visual C++ environments (free download from Microsoft) are massive and take a fair amount of time to download and install. Their usage is less than intuitive, and for those who have never built a Visual C++ project, the experience can cause intense dysphoria.
Finally, the Meggy system is an open source platform (i.e. has the potential to change at any moment), and the library exposes some very low-level access to the hardware, the bulk of which the Simulator won't pretent to support, so the Simulator WON'T contain all Meggy functionality at a given time.

Never fear; we will get through this together. I will explain the structure of a Visual C++ project, and walk you through the simple steps of creating a Siimulator project within Visual C++.

This page describes the installation procedure for the MeggyJr RGB Simulator onto a Windows XP computer with SDL 1.2 and Visual C++ Express Edition 9.0 Free, and the first compile of your project.  If you're installing it on anything other than Windows XP or using a version of Visual C++ other than that suggested below, it's up to you to figure out how to make things work with SDL and your compiler (submission of how you got it to work gladly accepted).  However, since there's no Windows-specific things here other than Visual C++ configuration it should be trivial to port this to work on your favourite platform or compiler.

  1. First things first: download some software.  There's a bunch of it to download, so this will likely take a while.
  2. Install everything
    • SDL & SDL mixer - I copied the contents of SDLmixer directory into the SDL directory so that I only had to add one path to the includes and libraries for Visual C++.
    • Visual C++ - install as normal
    • Java - install as normal
    • Arduino - self contained, so unpack wherever convenient
    • MeggyJr library - must be unpacked into the arduino directory.
    • Directory Structure - I like my directory structure nice and clean, here's what I'd suggest, but you pick what works best for you:
      • c:\projects\sdl
        c:\projects\arduino
        c:\projects\meggyjr
        c:\java
        c:\program...   {wherever Visual C++ installs itself.}
  3. Configure Visual C++ to be able to find the SDL include files and libraries.
    1. Select Tools->Options... from the menu.  You'll see the dialog below.
    2. Make sure the left-hand menu has 'VC++ Directories selected'
    3. Make sure the upper right-hand corner says 'Include files'
    4. Add the path to the SDL include files here.  I put mine in C:\Projects\Meggy\SDL\include
    5. Make sure to do the same thing for the 'Library files' (C:\Projects\Meggy\SDL\lib for me)
    6. modify standard include path
    7. modify standard library path
    8. Click 'OK', and now Visual C++ knows where to find the SDL includes and libraries.
  4. Unpack the Arduino environment into <arduino directory>
  5. Install the MeggyJr directory from the meggy library inside <arduino directory>/hardware/libraries
  6. unpack the simulator code,
    1. copy 'MeggyJrSimple.h' into the SDL "includes" directory.
  7. Run Visual C++ for the first time, and you'll see something like this:
    1. first View of Visual C++
  8. Select File->New->Project... like this:
    1.  file new project...
  9. Enter the name of the project, (in this case Meggy_Blink), and click 'OK':
    1. new project dialog
  10. The Win32 Application Wizard pops up, like below.  click on 'Next >'
    1. Win32 Application Wizard
  11. Application Settings.  Make sure to click the 'Empty project' tickbox.
    1. Application Settings
  12. You'll see theSolution Explorer view of your new project.  There are no files added to it yet, so we'll do that now.
    1. Solution Explorer view
  13. Go to the directory where Visual C++ stored the project.
    1. project directory
  14. Add 'MeggyJrSimple.c.  Copy the file you want in the project 'MeggyJr_Blink.pde' into your project directory, and then rename it to end in '.c'.
    1.  project directory with files
  15. In this case, I'd added the .h file to this directory too.  It doesn't matter, as it won't be picked up by the compiler.  It must be in the SDL 'includes' directory.
    1. SDL includes directory
  16. Add your source files to the project by right clicking on 'Source Files' and selecting Add->Existing Item..., and then browse for the C files you want to include (MeggyJrSimple.c, and your program is a good starting point).  Also do the same thing for the header file, and it's most important that you browse to the MeggyJrSimple.h file in the 'includes' directory inside the SDL directory.  For reasons I don't entirely understand, Visual C won't look in the same directory as your program for header files.  It's likely just the way I've got it set up, but there you go.Your source files are the files ending in .c (originally .pde when built for the arduino environment).
    1. Add existing item
  17. Right Click on the name of the project, and select Properties.
    1. modify project properties
  18. In the Linker Input section, add the strings shown to 'Additional Dependancies'
    1. Additional dependancies
  19. That's it!  You should now be completely configured to compile your meggy program and run it in Visual C's environment.  Press 'F7' to try a compile.  Here's the output from the compile...the best line is at the end where it says "1 succeeded"
    1.  compilation step
  20. Now, try to run the application...press 'F5', and in a moment, you'll see a black simulation window open up:
    1.  Simulation Window

You'll notice that instead of circles, the LED's are represented by squares.  Also, the 8 yellow LEDs are the little squares at the top.

The controls for the Simulator are currently: arrows for left, right, up, and down, and '1' for B and '2' for A.

Sound is not currently supported, nor are editted or custom colours.

Today: Sep 8, 2010