Implementing AntSnes with Qt part 4: using special keys

Support for green, red, menu, and camera keys:
Current S60 v. 5.0 phones really don’t have that much keys, so I decided to add support for all keys that I can find from the phone. This will require the SwEvent capability. The downside is that SwEvent requires signing by user. The signing can be made at Symbian signed website.

Here’s a trick how to catch these special button events from the phone.

CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
TRAPD(error,
    if (appUi) {
     // disable other green key functionality to be able to use it
     appUi->SetKeyEventFlags(CAknAppUi::EDisableSendKeyShort|CAknAppUi::EDisableSendKeyLong);
    }

//capturing menukeys, redkey (no), and camera keys
iMenuKeyHandle = CEikonEnv::Static()->RootWin().CaptureKeyUpAndDowns(EStdKeyApplication0, 0,0);
iNoKeyHandle = CEikonEnv::Static()->RootWin().CaptureKeyUpAndDowns(EStdKeyNo, 0, 0);
iNoKeyHandle2 = CEikonEnv::Static()->RootWin().CaptureKey( EKeyNo, 0, 0 );
iCameraKeyHandle = CEikonEnv::Static()->RootWin().CaptureKey( EKeyDevice7, 0, 0 );

There are limitations in these keys also. The green and red button are sending the  KeyUp events, even if I would hold the button down. So these keys shouldn’t be mapped into keys that require long key presses.

Adding support for multimedia buttons:
There’s are very good forum.nokia article about how to utilize multimedia keys: http://wiki.forum.nokia.com/index.php/TSS000432_-_Utilising_media_keys. I utilized the multimedia keys in similar ways, and after that I’ll make a KeyEvent with Qt’s Event:
Continue reading ‘Implementing AntSnes with Qt part 4: using special keys’ »

Implementing AntSnes with Qt part 3: Running the emulation in worker thread

I decided to build a two threaded application.  The main thread is for the UI, and the worker thread if for the emulator. This makes all porting easier in general, since now we can have a UI thread to handle all rendering, key I/O etc, and run the emulator thread as worker thread, which can emit the new processed frames to the UI thread etc.

The Qt makes the threading extra easy:
In my application I just inherited the emulator controller class from QThread,  then I just call start() to start the thread. The QThread will guarantee that  all slots will be executed in the context of that QThread after start has been called.
Another nice trick is to use Qt::BlockingQueuedConnection as connection type when the signal must be prosessed before the emitting thread can continue.

I’m really excited that all this communication between threads was so easy. No mutexes, or semaphores were required this time  at all :)

Here’s some code snippets how the threading was actually implemented.

//starting the thread
void <code>QSnesController::</code>Start()
{
   start( QThread::LowPriority );
}

//after the start() the thread will execute in the run()
void QSnesController::run()
 {
 connect(this, SIGNAL(frameblit()), blitter, SLOT(render()),
 Qt::BlockingQueuedConnection );

 gameloop();
 disconnect(this, SIGNAL(frameblit()), blitter, SLOT(render()) );
 }

//in render frame callback function
emit( frameblit() );

Implementing AntSnes with Qt part 2: Creating Settings View

I’m using the Qt now, so I wanted to make a new fresh clean look to the UI.  Therefore I dumped the old S60 UI style, which really wasn’t good design for touch devices.

You can see my settings view in the picture below. The empty space on top of the view is for the Main/settings widget. The main widget which is empty in the picture will have a  AntSnes logo, and maybe a screencapture from the currently selected saved state, which could be shown on top of the savestate box.  When user click some settings button such as controls/video/audio the main widget will change to show  selected settings.

AntSnes settings view

AtnSnes Settings view

On upper panel there’s obious selections for “Load ROM”, reset, and continue. On application startup, you can just press continue to continue playing the previous game you were playing on last time.

Continue reading ‘Implementing AntSnes with Qt part 2: Creating Settings View’ »

Implementing AntSnes with Qt part 1: Creating Views

This is first post on Qt App development series on Symbian. In this series I will describe how I made a new user interface with Qt for AntSnes. The same Ui will be later be used with gpsp and psx4all.

The mobile UI should be pretty much different, than the desktop UI, so there are some challenges ahed. I’m still sure that the UI will be a lot cooler than the old AntSnes UI with Symbian Avkon layer.

The UI will made with two separate views. The emulation view, and the settings view. The are both inherited from the QMainWidget, and they both are controlled by viewcontroller-class.  The ViewController is only responsible to call hide() and show() functions to widgets, so there’s allways the correct view shown on the screen.

Here’s an example how the app is started with the viewcontroller class.

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ViewController* vc = new ViewController();
    return a.exec();
}

Continue reading ‘Implementing AntSnes with Qt part 1: Creating Views’ »

I’ll be using Qt with gpsp and psx4all ports

Currently I have the dynamic recompilation running without the trampoline pattern (thanks to hinkka’s tips), so there’s no deoptimizations in the dynarec side anymore. However the speed is not nearly as good as it should be. It seems that the main issue is somewhere in the Symbian SDL port. Therefore I decided to dump the SDL port, and make my own port with Qt.

The Qt will be the UI system for Symbian^4 and for future Maemo platforms, so they can easily be supported after this change. So basically I’ll be getting much better compatibility too. Actually the Qt is already working on the Current Maemo 5 and N900! The dynarecs were originally written for linux, so there really shouldn’t be any issues compiling and running the same SW with Maemo devices too.

Using Qt with S60 versions from 3.1 to 5.0 is a bit more challenging. I doubt that the Qt’s blit is fast enough, so I’ll have to make old S60 blit-functions for them, but it’s OK, I’ll switch to the Qt blit later on.

I’ll be using the Qt 4.6 which was released a while ago.