main index FIRST OF ALL, did you read all of my Sony Ericsson P900 notes?

Quick notes:

software:Zx Spectrum emulator
release:0.91 beta release (29 October 2004)
platforms: SonyEricsson P900 and... read below!!!
license: GPL license (except for the Z80 engine)
purpose: emulator of the Sinclair Zx Spectrum computer
home site:my site!
latest news: preliminary P800 and P910 support; see below
C++ source:click here to download p900zxspectrum_0.91.tar.bz2 (109 kbytes);
it needs P900 UIQ SDK for Linux to compile
download:click here to download ZxSpectrum_0.91.sis (88 kbytes, ready to install)
BEWARE!!! you have to manually create the directory D:\Media files\Document\ZxSpectrum - if you don't do it, the emulator will panic with a Kern-Exec-3 (I will fix it in next release). I got tons of emails about this "Kern-Exec" error: it seems that no one likes to read documentation in this page!

YEAH, I DID IT! This is an almost decent Spectrum emulator to carry in the pocket... Oops! in the P900's gunnysack - because it's a P900 gun! And if you still don't know what's a Spectrum, have a look to my Sinclair Spectrum pages! (for other P900 downloads, click here)

WARNING:

This Spectrum emulator:

Currently stable features:

Currently unstable features (not always working):

Unsupported things (work in progress):

SOME Spectrum games reported as "runs correctly": (I report here only a few titles; I do not have much time to test thousands of games and programs!)

The alpha-tester team is currently limited to one person only:

  1. Martina (eight years old girl)

Atic Atac first screen How to use the Zx Spectrum emulator

When you start it, the emulator shows shortly the original Sinclair Zx Spectrum, initializes all data, and then begins the Spectrum emulation, clearing memory and screen and starting the Basic interpreter.

This is not a "simulator": this is an "emulator"! It interpretes every single Z80A processor instruction, applying correct timings, checking for memory and I/O ports accesses, and consequently emulating every Spectrum hardware unit ("floating bus", ULA, pixel-by-pixel screen image generation, etc). This means that virtually any Spectrum program can run in the emulator - old programs like new programs. You could even write your own Spectrum programs and have them run into the emulator before you test it on a real Spectrum! (this also suggests why a 156MHz machine is needed to correctly emulate a 3.5MHz computer).

Comparison between the emulated machine and the host machine:

manufacturer: Sinclair Research Ltd (England, April 1982) Sony Ericsson (summer 2003)
computer name: Zx Spectrum P900
processor: Zilog Z80A (8-bit), clocked at 3.5 MHz ARM/9 class (32-bit), clocked at 156 MHz
firmware: 16 kbyte ROM (Spectrum Basic interpreter) 64 Mbyte (phone firmware, Symbian 7.0, UIQ 2.1)
memory: 48 kbyte RAM (~7k video, ~1k vars/work area, 40k+ user programs) 16 Mbyte RAM (130k video, about 8 Mb for user programs)
graphics: 256×192 pixels (768 8×8 pixel areas), 16 colors with flashing 208×320 independent pixels, 65536 colors
keyboard: 40 keys, with Basic keywords printed on 16 keys (phone flip), 5-way jog-dial, three external keys (Power, Camera, Browser)
mass storage: any tape player/recorder; default throughput (normal mode): about 150 bytes per second internal 16 Mbyte solid-state disk (up to 13 Mb available for user data), 32 to 128 Mbyte memory stick (30.7 Mb available for user data in a 32Mb stick); throughput: more than 250k per second

More information about the Spectrum, links to Spectrum sites, links to Spectrum programs download sites, etc, on my Spectrum pages.

Emulation on the P900

First, the emulator works in "landscape" mode (320×208 instead of the 208×320 mode of the UIQ environment). Thus, the "lower part" of the emulated screen means "the rightmost part" if you look at the P900 in "portrait" mode (as normally in the Symbian/UIQ environment). The central 256×192 area contains the Spectrum screen graphic area, and the surrounding area contains the Spectrum border. Codename MAT loading... As in the original Spectrum, programs changing quickly the border colour will show a "striped" border (for example when loading programs from tape).

The P900 (like the P800) does not have a "qwerty" keyboard. This means that you won't be able to use with great fun some softwares like Spectrum wordprocessors, text adventures, and such things. The P910 has an integrated "qwerty" keyboard, but its orientation is in "portrait" mode instead of the "landscape" screen mode used by the emulator.

Also, the jog-dial is only vaguely resembling a joystick.

So I had to choose a decent compromise, at least to play games.

Most games require five keys or less. You can easily use the P900 jog-dial, touchscreen and external keys to emulate the useful combinations of keys and joystick.

On-screen keyboard

Pressing the P900 "Browser" button or tapping in the lowest part of the screen will open the on-screen keyboard. The on-screen keyboard (two keys pressed) The screen will show as here on the right: you can change the state of any key by tapping on it with the stylus. When a key is pressed (in the example on the right, the "Caps Shift" on the lower left and "P" on the upper right) the keys are drawn in different color.

Notice: not every key combination is considered useful by the Spectrum programs. Also, the keys are valid for next frame only; once read, they will be reset to "unclicked" state. This will make typing possible.

Keyboard/joystick emulation

The keyboard/joystick combinations of the Spectrum are emulated using jog-dial, keys, and touchscreen of the P900.

Jog-dial. On the P900 you will use the jog-dial for forward/backward/left/right movement: "forward" means pressing the jog-dial outwards, and "backward" means pressing jog-dial backwards; "left" means rolling the jog dial in anticlockwise, and "right" means clockwise. The standard P900 jog-dial pressure (select-function in UIQ environment) will be here called "special".

Flip-keyboard. If the flip is present, the flip keys will emulate these Spectrum keys:

I chose this combination because:

The emulator main menu

Pressing the P900 "Power" button will open the main menu, as shown in the screenshot here on the right. Rolling the jog-dial will move up and down the cursor.

Select keyboard/joystick modes

The configuration menu allows to choose:

For example, if you select a Q-A-O-P combination, then when you will press or move the stylus in the upper-right part of the screen, then the keys for "up" and "right" ("Q" and "P") will be emulated, and the emulated Kempston interface will report "up" and "right" directions. The center of the screen will act as a "fire" button.

Note that the P900 Camera button will always act as a "fire" button

The five-way jog-dial will always act as a joystick, emulating the Kempston interface and/or an up/down/left/right/fire key set.

Load snapshot or tape file

There is a huge collection of Spectrum programs around (go search for Spectrum-related sites). Lots of them will run on this emulator, some other maybe won't because snapshot/tapeloading is still work-in-progress!

Roll the jog-dial up/down to select the program to load in the emulator, then press the jog-dial to select or press outwards the jog-dial to exit the menu.

The emulator can read .TAP and .TZX tape-dump files, and the .Z80 and .SNA snapshot files. Programs in different formats should be converted to one of these formats using utilities found on Spectrum sites.

Remember that you need to place your TAP/TZX/Z80/SNA files in the D:\Media files\document\ZxSpectrum directory... yes: while the program can be installed in internal memory or external card, you always need to place your Spectrum program collection in the memorystickduo card!

Reset Spectrum

This will reset the Zx Spectrum like powering off and on again (like "Ye Olde Times" reset). The Spectrum Basic interpreter will run again from the ROM.

Reload original ROM

This will reload the Spectrum ROM image in memory. This option is here because the memory monitor allows you (not in the current beta release) to patch even the ROM area (this is impossible on the original Spectrum). Future versions of this emulator will allow you to load different ROM files.

Hardware mode

This option allows to select "issue 2" or "issue 3" Spectrum hardware; it actually only moves a bit in the I/O port 254, but is needed for a few old programs who cannot correctly read the keyboard on the "issue 3" hardware. By default the emulator starts in "issue 3" mode, which is the most common.

Machine monitor

This view shows the Z80A processor and memory status.
First, the number of screen frames since the last reset, then the time in minutes, seconds and hundredths (on the Spectrum machines there are about 50 frames per second). Note: these are the only decimal values shown here. Sample screen of the machine monitor

Then, the ULA (Uncommitted Logic Array) last port value. Below, the Z80 registers: AF (accumulator, flags), BC/DE/HL (other common registers), of the main set and alternate set; then 16-bit index registers (IX, IY), the stack pointer, and program counter; then the special registers for memory refresh and interrupts, and the interrupt mode. On the rightmost part, the bit-by-bit alternate-flags and main-flags register values (you can distinguish them by their color).

In the following two lines, the program being executed (the first four bytes are the "already executed", and then the "next to execute") and the stack contents (next words to be popped).

Below, the memory dump from current program counter on. If you rotate the jog-dial you can go up/down in the memory (use "browser" and "camera" buttons for larger skips).

About this software

This only shows a short about screen. If you press on the email/site area, you will get redirected to the P900 browser on a local HTML page with links to outside world (but it will not start any internet connection).

Exit the emulator

Exits to Symbian/UIQ environment. The "exit" command is anyways triggered by one or more of these conditions:


Snapshots and tape-dump

The emulator can load Spectrum programs from:

The tape-dump loading will show some alternating color stripes on the border, reproducing exactly the loading behaviour of the original Spectrum.


Some implementation notes

The overall performance of the emulation loop is faster than the normal Spectrum, so that sometimes (at the end of a screen frame draw) a little pause is needed to keep the emulated machine speed to about 100% Spectrum speed.

Since the P900 screen is memory-mapped, I don't need to maintain a list of "dirty" screen areas (as in the FUSE emulator): I simply redraw the entire screen 25 times every second. If the system seems slow, the frame-rate drops down for a while to 16.6, 12.5 or 10 frames per second.

Every screen redraw means 320×208 16-bit values written in a non-linear fashion: the "next pixel" means "208 words before" because the screen memory is oriented in "portrait" mode; this program uses it in "landscape" mode, so that the left-top P900 pixel becomes the right-top Zx Spectrum pixel.


Other notes

If you compile the sources using make x11 you will get the program compiled for X11. I did it for testing, and it still works... :-) (duh, it's only slow! I emulated everything pixel-by-pixel, and filling 16 bits of P900 memory is stunningly faster than calling a "write a dot on the current window" on the Linux/X11 system because the latter involves socket operations and other things).

Yes, the .SIS packaging system is safe. A bad .SIS won't install (or, at least, will give out an error while installing).

The Symbian OS has a memory protection scheme (unlike previous versions of Epoc), so you will get "kernel" errors for badly written applications (for example, writing out of the memory areas and stacks allocated by the process). The first common bug of my emulator was a missing "NULL" check on the existence of the snapshots directory, and the emulator just exited with "kernel" error.


More technical notes

Some time ago I released this P900 Zx Spectrum emulator (full source included).

The main source has to #include a "p900.h" header file: if the compiler is targeted to ARM processor, then it will include a "p900base.h" header, else it will include "p900x11.h" (with same functions but targeted to X11 and Linux).

Also, the functions contained in the p900base.h will give you a "full CPU" environment instead of the common "event driven" structure. As you may already know, in every windowed environment programming library (Mac OS X, Windows, QT, Symbian/UIQ, etc) your program has only to answer to events: the system, not your program, has the control of all resources.

For example, given a button, you define an event "button clicked", and your procedure will be called only when the button is actually clicked: you have then to quickly execute your (short) code and then release control to the system (because other events may be waiting: keypresses, timing, etc).

The most notable exception is bare X11 programming, where you must initialize all windows and stuff, and then create a for-loop to ask for events and then respond to them. You have the control, not the windowing management library of the system: you can write programs that can use all available CPU power and which still appear in "windowed" mode.

To write the Zx Spectrum emulator I needed full control, not "event style" control. So I had to split the main P900 .APP program in two threads soon after initialization phase: the first is a classic event-driven program, which keeps a linked-list (big, circular) filled with the events that it got from the system; the second thread simply runs at full speed, reading from the shared list the events (keyboard, touchscreen) when needed, and can use all available CPU power without interfering with the rest of Symbian applications already running.

This said, I was finally able to create the P900 Zx Spectrum emulator which:

1) uses all available CPU power, thus getting a realistic screen refresh (25 fps: 25 times per second the 320×208 screen gets a full redraw) without freezing the P900 (alarms, messaging, etc won't stop); a commercial Spectrum emulator, using the standard event/timers driven version, can barely get more than 12-15 frames per second.

2) same P900-Spectrum source is cross-compilable to the Linux+X11 platform (have a look at the Makefile: "make x11" will compile it for your Linux box), where it will perform in the same mode but a little slower (due to X11 calls: in the P900 to set a pixel you simply need to write two bytes in memory; in X11 you need to call a library function which will perform window controls, color depth control, visibility controls, etc, before actually telling the X11 engine to recolor it: a dramatic speed-up was obtained by keeping an fake screen matrix, in order to call the set pixel color function only when the color was changed)

3) I had to stop development for a number of reasons, and didn't explore the sound section (which, in event-driven mode, could still use the 5-8% of CPU power left from the P900 Spectrum emulator and still be in sync with everything).

This entire introduction means that:

a) you can build and develop on X11 and do minimal tests on a real P900;

b) you can experiment almost everything available on both platforms (for example: did you know that the free ZLIB is available both on Symbian and Mac OS X and Linux?)

c) by using P900X11 library you can quickly convert some old MS/DOS & VGA game to the P900 (remember that classic VGA games always used 320×200 resolution at 256 colors, while P900 can do 320×208 at 65536); as you may already see in the P900 Zx Spectrum emulator sources, I got an already existing C++ source for Linux (FBZX) and only had to do some rearrangements.

My intention, from the P900 Zx Spectrum emulator up to date, is to convince all that the P900/P910 platform can be used as a classic computer.

First, it has a true 32-bit processor running at 156MHz. You have 32-bit operations (arithmetics and pointers) at native speed (it's not emulating 32-bit operations on an 8- or 16-bit machine: the ARM9 is a true 32-bit machine).

Second, it has a good resolution display with fast access: write two bytes to lit up a pixel, like in the old-style VESA modes, without page-flipping (no 16-bit limitations). You can use it as 208×320 or 320×208, as if you had two real screen resolutions (I won't discuss using the 208×208 mode in "flip-closed (and no touchscreen function)" mode).

Third, it has a true filesystem, where you can open/read/write/close and copy/remove/rename files. Yes, your program resides its own directory, and can write there or access some other directory.

Fourth, it has some sort of keyboard and mouse: the jog-dial (cursor keys), the flip (common keys), the camera/internet keys (function keys); and also the touchscreen (mouse, except for "mouse move" functions).

Fifth, an application can have decent memory usage (it's not impossible to have an executable of up to 1Mb code which uses up to 1Mb data; may be even more on the P900; surely more on the P910; there are some extra limits on the available stack for common functions, but you can allocate on the heap instead of the stack, as I did in the P900 Zx Spectrum emulator).

Finally, it has an operating system (that will close your files at exit, free memory, etc) with memory protection (that is: your program will be stopped if tries to access other tasks memory). While you can use all of the remaining available CPU, the Symbian operating system will continue to run (your program will be interrupted every 1/64sec, the system will check for incoming calls, SMS messages, calendar, alarm, etc).



Legal notes

This package includes the Spectrum ROM file: Amstrad, who owns the copyright for the Spectrum ROMs, allows free distribution of them for emulation purposes.

This package is released under GNU GPL license with only one exception: the Z80 engine by Marat Fayzullin, which is freeware but not released as GPL. I got from Marat explicit permission to use it in my Zx Spectrum emulator but I clearly state here again that the z80.h and z80extra.h source files are not covered by the GPL license.


Credits:

Anyways, if you want to see a real Spectrum roaring on your computer, you have to download the absolutely best Spectrum emulator around: RealSpectrum/RealX.


History



Frequently Asked Questions

Woah! Some people discussed this program in forums related to Sony Ericsson phones or Symbian operating system. Sadly, I cannot track down every comment about this program, but I am very happy that lots of people enjoyed it!!!


Porting this emulator to P990

An UIQ3 expert asked me about porting this emulator to P990. Here is my answer.

Working on this Spectrum emulator doesn't require UIQ programming skills (if you see the startup section you will find my UIQ skills very poor). It's basically a small APP that starts two threads:

1) accumulation of input events (keys, touch, jogdial) in a shared FIFO queue (an event array).

2) run actual emulation, fetching events when simulating Spectrum hardware and 50Hz interrupt.

There are other Spectrum emulators around, based on clean UIQ programming, but achieve no more than 10-12 fps. And they are not GPL source.

My emulator uses direct screen access (that is, write 16 bit into a memory location and have exactly that pixel colored), achieving full 25 fps (TV-quality) even on a 156MHz ARM925T (the P900/P910). To get maximum performance I "unrolled" the loop in the drawvisible function so that the ptr -= offset; *ptr = colour were reduced to single ARM instructions (no jumps/loops).

I don't think you can easily compile it in a Windows environment. I created my own "P900 UIQ SDK" to have the same source compiled for Linux/X11 and Linux (in fact you can do make x11 instead of make to get a Linux/X11 graphical executable, slow but functionally identical).

I used BZ2 compression, so you need to use tar xjvf p900zxspectrum*.tar.bz2 to extract it.

A port to the P990 would require:

  1. working on screen section (P900/P910 was 320×208@16, P990 is 320×240 but don't know if it's 16-bit-per-pixel with 5-6-5 mapping); surely this is not simple.
  2. cleaning startup section (in p900.h header file), but I don't think this will be hard.

I stopped developing because of some hysterical GPL cops. I do not have much time to develop now; Ìm very busy with a lot of other things and I swear my next smartphone will be a Linux-based one.


Google
 
Web www.alfonsomartone.itb.it

Below: the Spectrum emulator running Manic Miner on the Sony Ericsson P900; above the P900 you can see the Spectrum emulator running in a Linux X/Free window of my Thinkpad notebook. The notebook TFT display has an 82dpi resolution (this is the reason why its window appears bigger) while the P900 screen has 132dpi resolution. I always use Linux as base system for development of P900 programs; the Spectrum emulator C++ source is cross-compilable (P900 and Linux).

Zx Spectrum emulator running on the Sony Ericsson P900 and in a Linux/XFree window. YAY! - if you cant see this image, click here!

Sony Ericsson P900 index - send e-mail - home page