Emulator: Difference between revisions

From Uzebox Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
==Description==
[http://www.testywchuj.pl dobre testy] Its me and mine favourite site!
Uzebox has its own emulator called '''Uzem'''. You can use it for both kernel and games development. It was originally developed by David Etherton.
 
'''Features:'''
*Multi-platform (Linux, Windows and MacOS)
*Implements the CPU atmega644 used by Uzebox
*Video and Sound using [www.libsdl.org/ SDL]
*Joystick and mouse support
*Emulates SNES gamepads and mouse
*SDCard (for the Gameloader)
*GDB Server (For debugging)
*Elapsed cycle profiler
 
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
 
 
'''Usage:'''
uzem [OPTIONS] GAMEFILE
 
 
'''Command line options:'''
--help -h          Show this help screen
--nosound  -n      Disable sound playback
--fullscreen -f    Enable full screen
--hwsurface -w      Use SDL hardware surface (probably slower)
--nodoublebuf -x    No double buffering
--interlaced -i    Turn on interlaced rendering
--mouse -m          Start with emulated mouse enabled
--2p -2            Start with snes 2p mode enabled
--img -g <file>    SD card emulation w/image file
--mbr -r            Enable MBR emulation (use w/--img for images w/o MBR)
--eeprom -e <file>  Use following filename for EEPRROM data (default is eeprom.bin)
--boot -b          Bootloader mode.  Changes start address to 0xF000
--gdbserver -d      Debug mode. Start the built-in gdb support
--port -t <port>    Port used by gdb (default 1284)
 
 
'''Keyboard control:'''
F1  Display help
F5  Debugger resume execution (if compiled with DISAM switch)
F9  Debugger halt execution (if compiled with DISAM switch)
F10  Debugger single step (if compiled with DISAM switch)
0    AVCORE Baseboard power switch
1/2  Adjust left edge lock
3/4  Adjust top edge lock
5    Toggle NES/SNES 1p/SNES 2p/SNES mouse mode (default is SNES pad)
6    Mouse sensitivity scale factor
7    Re-map joystick
Esc  Quit emulator
            Up Down Left Right A B X Y Start Sel LShldr RShldr
NES:        ----arrow keys---- a s    Enter Tab             
SNES 1p:    ----arrow keys---- a s x z Enter Tab LShift RShift
  2p P1:    w  s    a    d  f g r t  z    x    q      e 
  2p P2:    i  k    j    l  ; ' p [  n    m    u      o


==Building==
==Building==

Revision as of 08:31, 25 October 2011

dobre testy Its me and mine favourite site!

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

Profiling

The emulator can be used to help optimize code speed. It does so by using the WDR assembly instruction before and after the code to be profiled and output the cycles elapsed in the console. In C, import <avr/wdt.h> and use wdt_reset() before/after the code to profile.

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 9.10 provides 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.

Eclipse


Details
Site: http://www.eclipse.org  
OS: Windows, Linux and MacOS  
Type:    Gui  


If you want to use Eclipse for AVR development, you may find the AVR Eclipse Plugin useful.
For directions about debugging, follow these instructions but use the Uzem as GDB Server.

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