Annotation of frontvm/src/main.c, revision 1.1.1.1

1.1       root        1: /*
                      2:   Hatari - main.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: 
                      7:   Main initialization and event handling routines.
                      8: */
                      9: 
                     10: #include <time.h>
                     11: #include <signal.h>
                     12: #include <sys/time.h>
                     13: #include <unistd.h>
                     14: #include <signal.h>
                     15: 
                     16: #include <SDL.h>
                     17: 
                     18: #include "main.h"
                     19: #include "audio.h"
                     20: #include "../m68000.h"
                     21: #include "hostcall.h"
                     22: #include "input.h"
                     23: #include "keymap.h"
                     24: #include "screen.h"
                     25: #include "shortcut.h"
                     26: 
                     27: 
                     28: #define FORCE_WORKING_DIR                 /* Set default directory to cwd */
                     29: 
                     30: 
                     31: BOOL bQuitProgram=FALSE;                  /* Flag to quit program cleanly */
                     32: BOOL bUseFullscreen=FALSE;
                     33: BOOL bEmulationActive=TRUE;               /* Run emulation when started */
                     34: BOOL bAppActive = FALSE;
                     35: char szBootDiscImage[MAX_FILENAME_LENGTH] = { "" };
                     36: 
                     37: char szWorkingDir[MAX_FILENAME_LENGTH] = { "" };
                     38: char szCurrentDir[MAX_FILENAME_LENGTH] = { "" };
                     39: 
                     40: /*-----------------------------------------------------------------------*/
                     41: /*
                     42:   Error handler
                     43: */
                     44: void Main_SysError(char *Error,char *Title)
                     45: {
                     46:   fprintf(stderr,"%s : %s\n",Title,Error);
                     47: }
                     48: 
                     49: 
                     50: /*-----------------------------------------------------------------------*/
                     51: /*
                     52:   Bring up message(handles full-screen as well as Window)
                     53: */
                     54: int Main_Message(char *lpText, char *lpCaption/*,unsigned int uType*/)
                     55: {
                     56:   int Ret=0;
                     57: 
                     58:   /* Show message */
                     59:   fprintf(stderr,"%s: %s\n", lpCaption, lpText);
                     60: 
                     61:   return(Ret);
                     62: }
                     63: 
                     64: 
                     65: /*-----------------------------------------------------------------------*/
                     66: /*
                     67:   Pause emulation, stop sound
                     68: */
                     69: void Main_PauseEmulation(void)
                     70: {
                     71:   if( bEmulationActive )
                     72:   {
                     73:     Audio_EnableAudio(FALSE);
                     74:     bEmulationActive = FALSE;
                     75:   }
                     76: }
                     77: 
                     78: /*-----------------------------------------------------------------------*/
                     79: /*
                     80:   Start emulation
                     81: */
                     82: void Main_UnPauseEmulation(void)
                     83: {
                     84:   if( !bEmulationActive )
                     85:   {
                     86:     Audio_EnableAudio(1);
                     87:     bEmulationActive = TRUE;
                     88:   }
                     89: }
                     90: 
                     91: /* ----------------------------------------------------------------------- */
                     92: /*
                     93:   Message handler
                     94:   Here we process the SDL events (keyboard, mouse, ...) and map it to
                     95:   Atari IKBD events.
                     96: */
                     97: void Main_EventHandler()
                     98: {
                     99:   SDL_Event event;
                    100: 
                    101:   while (SDL_PollEvent (&event))
                    102:    switch( event.type )
                    103:    {
                    104:     case SDL_QUIT:
                    105:        bQuitProgram = TRUE;
                    106:        SDL_Quit ();
                    107:        exit (0);
                    108:        break;
                    109:     case SDL_MOUSEMOTION:               /* Read/Update internal mouse position */
                    110:        input.motion_x += event.motion.xrel;
                    111:        input.motion_y += event.motion.yrel;
                    112:        input.abs_x = event.motion.x;
                    113:        input.abs_y = event.motion.y;
                    114:        break;
                    115:     case SDL_MOUSEBUTTONDOWN:
                    116:        Input_MousePress (event.button.button);
                    117:        break;
                    118:     case SDL_MOUSEBUTTONUP:
                    119:        Input_MouseRelease (event.button.button);
                    120:        break;
                    121:     case SDL_KEYDOWN:
                    122:        Keymap_KeyDown(&event.key.keysym);
                    123:        break;
                    124:     case SDL_KEYUP:
                    125:        Keymap_KeyUp(&event.key.keysym);
                    126:        break;
                    127:    }
                    128:   Input_Update ();
                    129: }
                    130: 
                    131: 
                    132: /*-----------------------------------------------------------------------*/
                    133: /*
                    134:   Check for any passed parameters
                    135: */
                    136: void Main_ReadParameters(int argc, char *argv[])
                    137: {
                    138:   int i;
                    139: 
                    140:   /* Scan for any which we can use */
                    141:   for(i=1; i<argc; i++)
                    142:   {
                    143:     if (strlen(argv[i])>0)
                    144:     {
                    145:       if (!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h"))
                    146:       {
                    147:         printf("Usage:\n frontier [options]\n"
                    148:                "Where options are:\n"
                    149:                "  --help or -h          Print this help text and exit.\n"
                    150:                "  --fullscreen or -f    Try to use fullscreen mode.\n"
                    151:                "  --nosound             Disable sound (faster!).\n"
                    152:                "  --size w h            Start at specified window size.\n"
                    153:               );
                    154:         exit(0);
                    155:       }
                    156:       else if (!strcmp(argv[i],"--fullscreen") || !strcmp(argv[i],"-f"))
                    157:       {
                    158:         bUseFullscreen=TRUE;
                    159:       }
                    160:       else if ( !strcmp(argv[i],"--nosound") )
                    161:       {
                    162:         bDisableSound=TRUE;
                    163:       }
                    164:       else if ( !strcmp(argv[i],"--size") )
                    165:       {
                    166:        screen_h = 0;
                    167:        if (++i < argc) screen_w = atoi (argv[i]);
                    168:        if (++i < argc) screen_h = atoi (argv[i]);
                    169:        /* fe2 likes 1.6 aspect ratio until i fix the mouse position
                    170:         * to 3d object position code... */
                    171:        if (screen_h == 0) screen_h = 5*screen_w/8;
                    172:       }
                    173:       else
                    174:       {
                    175:              /* some time make it possible to read alternative
                    176:               * names for fe2.bin from command line */
                    177:              fprintf(stderr,"Illegal parameter: %s\n",argv[i]);
                    178:       }
                    179:     }
                    180:   }
                    181: }
                    182: 
                    183: 
                    184: /*-----------------------------------------------------------------------*/
                    185: /*
                    186:   Initialise emulation
                    187: */
                    188: void Main_Init(void)
                    189: {
                    190:   /* Init SDL's video subsystem. Note: Audio and joystick subsystems
                    191:      will be initialized later (failures there are not fatal). */
                    192:   if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
                    193:   {
                    194:     fprintf(stderr, "Could not initialize the SDL library:\n %s\n", SDL_GetError() );
                    195:     exit(-1);
                    196:   }
                    197:   
                    198:   Screen_Init();
                    199:   Init680x0();                  /* Init CPU emulation */
                    200:   Audio_Init();
                    201:   Keymap_Init();
                    202: 
                    203:   if(bQuitProgram)
                    204:   {
                    205:     SDL_Quit();
                    206:     exit(-2);
                    207:   }
                    208: }
                    209: 
                    210: 
                    211: /*-----------------------------------------------------------------------*/
                    212: /*
                    213:   Un-Initialise emulation
                    214: */
                    215: void Main_UnInit(void)
                    216: {
                    217:   Audio_UnInit();
                    218:   Screen_UnInit();
                    219: 
                    220:   /* SDL uninit: */
                    221:   SDL_Quit();
                    222: }
                    223: 
                    224: static Uint32 vbl_callback ()
                    225: {
                    226:        FlagException (0);
                    227:        return 20;
                    228: }
                    229: 
                    230: void sig_handler (int signum)
                    231: {
                    232:        if (signum == SIGSEGV) {
                    233:                printf ("Segfault! All is lost! Abandon ship!\n");
                    234:                Call_DumpDebug ();
                    235:                abort ();
                    236:        }
                    237: }
                    238: 
                    239: /*-----------------------------------------------------------------------*/
                    240: /*
                    241:   Main
                    242: */
                    243: int main(int argc, char *argv[])
                    244: {
                    245:   signal (SIGSEGV, sig_handler);
                    246:        
                    247:   /* Generate random seed */
                    248:   srand( time(NULL) );
                    249: 
                    250:   /* Check for any passed parameters */
                    251:   Main_ReadParameters(argc, argv);
                    252: 
                    253:   /* Init emulator system */
                    254:   Main_Init();
                    255: 
                    256:   /* Switch immediately to fullscreen if user wants to */
                    257:   if( bUseFullscreen )
                    258:     Screen_ToggleFullScreen();
                    259: 
                    260:   SDL_AddTimer (20, &vbl_callback, NULL);
                    261:   
                    262:   /* Run emulation */
                    263:   Main_UnPauseEmulation();
                    264:   Start680x0();                 /* Start emulation */
                    265: 
                    266:   /* Un-init emulation system */
                    267:   Main_UnInit();
                    268: 
                    269:   return(0);
                    270: }
                    271: 
                    272: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.