Emulator

From Uzebox Wiki
Revision as of 18:13, 11 January 2010 by Filipe (talk | contribs) (→‎Windows)
Jump to navigation Jump to search

Description

Uzebox has its own emulator called Uzem. You can use it for both kernel and games development.

Features:

  • Multi-platform (Linux, Windows and MacOS)
  • Implements the CPU atmega644 used by Uzebox
  • Video and Sound using [www.libsdl.org/ SDL]
  • SNES gamepads and mouse
  • SDCard (for the Gameloader)
  • GDB Server (For debugging)

There is another emulator based on the Softgun simulator. The current version has some issues with the keymap, the mouse is emulate with keys and the monitor is accessed by VNC. For more details, see: http://softgun.sourceforge.net/uzebox.shtml

Building

Pre-requisites

  • GCC compiler and SDL libraries
    • Windows: Download them from http://www.mingw.org/ (Download the installer) and http://www.libsdl.org (Download the libraries, i.e: SDL-devel-1.2.14-mingw32.tar.gz)
    • Linux:
      • Ubuntu: sudo apt-get install build-essential libsdl1.2-dev
      • OpenSuse: sudo zypper install -t pattern devel_C_C++ SDL-devel
      • Fedora: yum install gcc gcc-c++ SDL-devel
    • Mac OS X: Download them from Xcode and http://www.libsdl.org

Install

Windows

  • Install mingw in the default location: c:\MinGW
  • Add C:\MinGW\bin to your system's path
  • Add C:\WinAVR\utils\bin to your system's path (you will need Unix style of mkdir and rm)
  • Create folder C:\MinGW\includes\SDL and copy all SDL include files in there
  • Copy SDL library files to C:\MinGW\lib

Download

Get the last Uzebox version from http://code.google.com/p/uzebox/

Compiling

  • Unpack it
  • Open a command line terminal, go to the tools/emulator/ directory
  • To see the available options, type make help
  • Type make for the default options

This process will create two executables: uzem and uzemdbg.
Important: The uzemdbg is only used for the Emulator development, it generates a lot of debugging messages and is very slow.

Using

Just run the emulator in the command line and pass the game (iHex file) as parameter: uzem path/to/your/game.hex

To see all the options available run: uzem --help

GDB

Uzem implements an internal GDB server (originally based on simulavr) making it an important tool to develop Uzebox games.

Running Uzem in debug mode

The following examples are using the game Arkanoid.
Windows users: Don't forget to use backslash "\"

Execute uzem with the option -d and the game file:

$ uzem -d  ../../demos/Arkanoid/default/Arkanoid.hex

NOTE THIS IS AN EXPERIMENTAL BRANCH OF THE UZEBOX EMULATOR
PLEASE SEE THE FORUM FOR MORE DETAILS:  http://uzebox.org/forums

Loading Hex Image...
Waiting on port 1284 for gdb client to connect...

Uzem will start and wait for the GDB client to connect.

Gdb clients

Now with Uzem running in debug mode, you need the gdb client to debug the game. Following is a list of GDB clients and front-ends you can use.

avr-gdb


Details
Site: http://sourceware.org/gdb/  
OS: Windows, Linux and MacOS  
Type:    Command line  

This is the official gnu gdb client. Windows: It is shipped with WinAvr Linux: Check you distribution.

  • Ubuntu has the avr-gdb package but its version (6.4) has some issues about variables in flash and will crash.

If you want compile the last version visit http://www.nongnu.org/avr-libc/user-manual/install_tools.html for more details.

Build the game and from the same directory run avr-gdb passing the elf file as parameter:

1. $>cd demos/Arkanoid/default/
2. $>make
3. $>avr-gdb Arkanoid.elf

You will get a prompt like this: (gdb)
Then connect to the Uzem:

4. (gdb)target remote localhost:1284

You don't need to use the GDB command "run". You are already with the debugger session started, but still stopped at the first instruction as you can see:

Remote debugging using localhost:1284
0x00000000 in __vectors ()

Go ahead and start debugging your code.

Refer to GDB manual for more information about the available commands.
GDB cheat sheet: http://www.yolinux.com/TUTORIALS/GDB-Commands.html

Gdb supports script files to automate the tedious task. Arkanoid has a simple script (file: Arkanoid/default/gdb-script.cfg) to connect to the target, insert a breakpoint at main() and continue until it reaches main. Gsb script are text files with gdb commands, but can create new commands using an internal language and others GDB commands.

Use the option -x like: avr-gsb -x gdb-script.cfg Arkanoid.elf

avr-insight


Details
Site: http://sourceware.org/insight/  
OS: Windows, Linux and MacOS  
Type:    Gui  

avr-insight is a GUI with avr-gdb embedded. For windows users, it is distributed in the WinAVR tool suite and can be started and connected to an already running Uzem like so:

avr-insight -x gdb-script.cfg Arkanoid.elf

KDbg


Details
Site: http://www.kdbg.org/  
OS: Linux  
Type:    Gui  

KDbg is a graphical user interface to gdb. It provides an intuitive interface for setting breakpoints, inspecting variables, and stepping through code.

Note: It is a front-end to avr-gdb, so you still need avr-gdb.

To install, user your package manager.

  • Ubuntu: sudo apt-get install kdbg

As you are going to debug an AVR target, you need first configure KDbg to use an avr-gdb:
1. Start KDbg and go to the menu option Settings/Global Options...
2. From the tab Debugger change the option in the box How to invke GDB: from the default gdb to avr-gdb.

  • Make sure your avr-gdb is in the PATH or just use the full path.

There is no option to connect a remote target from KDbg using the GUI interface, so you will need to close it and open from the shell with the option -r:
1. Start uzem with -d
2. Open a new shell
3. $>cd demos/Arkanoid/default/
4. Build if necessary
5. $>kdbg -r localhost:1284 Arkanoid.elf

The KDbg is running and connected. It is very intuitive, on the bottom you have Stack and Breakpoints and on the right variables and expressions to inspect data. From the menu option View you see Registers and Memory.

Gdb Problems

Starting a debug session with 'steps'.

If you connect to your target and try to step, you may get some errors or gdb will even crash. This happens because gdb client is trying to read an invalid address from SRAM. To avoid this, use a breakpoint into main() (or other function you want) and give a 'continue'.
Filipe's note: It looks like an GDB bug, but I'm getting more details before submit a bug report.

Variables in flash (PROGMEM)

The debugger says a variable defined with PROGMEM is 'out of bounds' and will shows it with a SRAM address (over 0x800000). Gdb can get the variable value, so it knows the variable is in flash, but if you get the variable address and try to overwrite it, GDB thinks it is in SRAM. If you want the real flash address, just subtract 0x800000. If you want overwrite a value, use the gdb command set {type} addr = value.
Example using the global variable const char strEnd2[] PROGMEM = "THAT WAS THE LAST LEVEL" declared in Arkanoid.c:

(gdb) print strEnd2
$3 = "THAT WAS THE LAST LEVEL"
(gdb) print strEnd2[0]=64
Cannot access memory at address 0x80a003
(gdb) print &strEnd2
$4 = (char (*)[24]) 0x80a003
(gdb) set {char}0xa003 = 64
(gdb) print strEnd2
$5 = "@HAT WAS THE LAST LEVEL"

Filipe's note: Again this looks like a GDB bug. I tried change types like 'char *' to 'prog_char *' but gdb still get crazy. I will send a bug report as soon I get finished more tests.

FAQ