2009-11-23 20:47:01 +01:00
|
|
|
#include <SDL_image.h>
|
|
|
|
#include <SDL_ttf.h>
|
|
|
|
|
2009-12-06 10:11:04 +01:00
|
|
|
#include "gui.hh"
|
2009-11-23 19:52:30 +01:00
|
|
|
#include "utils.hh"
|
2010-01-02 13:41:50 +01:00
|
|
|
#include <C64.h>
|
2009-11-23 19:52:30 +01:00
|
|
|
|
|
|
|
SDL_Surface *screen;
|
2010-01-02 13:41:50 +01:00
|
|
|
C64 *TheC64;
|
2009-11-23 19:52:30 +01:00
|
|
|
|
2010-01-16 09:56:15 +01:00
|
|
|
#define MS_PER_FRAME 28
|
|
|
|
|
2009-11-23 19:52:30 +01:00
|
|
|
static void run(void)
|
|
|
|
{
|
2010-01-16 09:56:15 +01:00
|
|
|
Uint32 last_frame = SDL_GetTicks();
|
|
|
|
|
2009-11-23 19:52:30 +01:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
SDL_Event ev;
|
2010-01-16 09:56:15 +01:00
|
|
|
Uint32 now = SDL_GetTicks();
|
2009-11-25 19:14:48 +01:00
|
|
|
|
2010-01-23 15:55:15 +01:00
|
|
|
if (!Gui::gui->is_active)
|
|
|
|
break;
|
|
|
|
|
2009-11-25 19:14:48 +01:00
|
|
|
while (SDL_PollEvent(&ev)) {
|
2009-11-23 19:52:30 +01:00
|
|
|
if (ev.type == SDL_QUIT)
|
2009-11-23 20:47:01 +01:00
|
|
|
exit(1);
|
2009-11-23 19:52:30 +01:00
|
|
|
|
2009-12-13 09:54:25 +01:00
|
|
|
Gui::gui->pushEvent(&ev);
|
2009-11-23 19:52:30 +01:00
|
|
|
}
|
2009-12-13 09:54:25 +01:00
|
|
|
Gui::gui->runLogic();
|
|
|
|
Gui::gui->draw(screen);
|
2009-11-23 19:52:30 +01:00
|
|
|
|
2009-11-23 20:33:51 +01:00
|
|
|
SDL_Flip(screen);
|
2010-01-16 09:56:15 +01:00
|
|
|
|
|
|
|
if ( (now - last_frame) < MS_PER_FRAME)
|
|
|
|
SDL_Delay( MS_PER_FRAME - (now - last_frame));
|
2009-11-23 19:52:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init(void)
|
|
|
|
{
|
2010-01-02 13:41:50 +01:00
|
|
|
/* Creation of the mocks */
|
|
|
|
TheC64 = new C64();
|
|
|
|
|
2009-11-23 19:52:30 +01:00
|
|
|
screen = SDL_SetVideoMode(640, 480, 16,
|
|
|
|
SDL_DOUBLEBUF);
|
|
|
|
panic_if(!screen, "Cannot initialize video: %s\n", SDL_GetError());
|
|
|
|
TTF_Init();
|
|
|
|
|
2009-12-13 09:54:25 +01:00
|
|
|
Gui::init();
|
|
|
|
Gui::gui->activate();
|
2009-11-23 19:52:30 +01:00
|
|
|
}
|
2009-11-19 18:59:43 +01:00
|
|
|
|
2010-01-23 15:55:15 +01:00
|
|
|
static void fini(void)
|
|
|
|
{
|
|
|
|
delete Gui::gui;
|
|
|
|
}
|
|
|
|
|
2009-11-19 18:59:43 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2009-11-23 19:52:30 +01:00
|
|
|
init();
|
|
|
|
run();
|
2010-01-23 15:55:15 +01:00
|
|
|
fini();
|
|
|
|
|
2010-01-23 16:16:52 +01:00
|
|
|
SDL_Quit();
|
|
|
|
|
2009-11-19 18:59:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|