home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / v2600 / source.lha / source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-06  |  1.9 KB  |  100 lines

  1. /*****************************************************************************
  2.  
  3.    This file is part of x2600, the Atari 2600 Emulator
  4.    ===================================================
  5.    
  6.    Copyright 1996 Alex Hornby. For contributions see the file CREDITS.
  7.  
  8.    This software is distributed under the terms of the GNU General Public
  9.    License. This is free software with ABSOLUTELY NO WARRANTY.
  10.    
  11.    See the file COPYING for Details.
  12.    
  13.    $Id: main.c,v 1.19 1996/11/24 16:55:40 ahornby Exp $
  14. ******************************************************************************/
  15.  
  16. /* 
  17.    The main program body.
  18.  */
  19. #include "config.h"
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. #include "types.h"
  24. #include "display.h"
  25. #include "keyboard.h"
  26. #include "realjoy.h"
  27. #include "files.h"
  28. #include "config.h"
  29. #include "vmachine.h"
  30. #include "profile.h"
  31. #include "options.h"
  32. #include "dbg_mess.h"
  33.  
  34. #include "sound.h"
  35.  
  36. /* The mainloop from cpu.c */
  37. extern void mainloop (void);
  38.  
  39. /* Make sure any exit() calls free up shared memory */
  40. void
  41. cleanup (void)
  42. {
  43.   /* Close the raw keyboard */
  44.   close_keyboard ();
  45.  
  46.   /* Close the PC joystick */
  47.   close_realjoy ();
  48.  
  49.   /* Close down display */
  50.   tv_off ();
  51.  
  52.   /* Turn off the sound */
  53.   sound_close ();
  54.  
  55. }
  56.  
  57. /* The main entry point */
  58. /* argc: number of command line arguments */
  59. /* argv: the argument text */
  60. int
  61. main (int argc, char **argv)
  62. {
  63.  
  64.   /* Parse options */
  65.   parse_options (argc, argv);
  66.  
  67.   /* Set up the cleanup code */
  68.   atexit (cleanup);
  69.  
  70.   /* Initialise the 2600 hardware */
  71.   init_hardware ();
  72.  
  73.   /* Turn the virtual TV on. */
  74.   tv_on (argc, argv);
  75.  
  76.   /* Turn on sound */
  77.   sound_init ();
  78.  
  79.   init_realjoy ();
  80.  
  81.   /* load cartridge image */
  82.   if (loadCart ())
  83.     {
  84.       fprintf (stderr, "Error loading cartridge image.\n");
  85.       exit (-1);
  86.     }
  87.  
  88.   /* Cannot be done until file is loaded */
  89.   init_banking();
  90.  
  91.   if (Verbose)
  92.     printf ("OK\n");
  93.  
  94.   /* start cpu */
  95.   mainloop ();
  96.  
  97.   /* Thats it folks */
  98.   exit (0);
  99. }
  100.