home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / gbe / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-13  |  4.8 KB  |  173 lines

  1. /*
  2.  *  gbe - gameboy emulator
  3.  *  Copyright (C) 1999  Chuck Mason, Steven Fuller
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18.  *
  19.  *
  20.  *  Chuck Mason <chuckjr@sinclair.net>
  21.  *  Steven Fuller <relnev@atdot.org>
  22.  */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <signal.h>
  26. #include <string.h>
  27.  
  28. #include "rom.h"
  29. #include "mem.h"
  30. #include "data.h"
  31. #include "vram.h"
  32. #include "cpu.h"
  33. #include "joypad.h"
  34. #include "debug.h"
  35.  
  36. gameboy_proc_t *current_processor = NULL;
  37. unsigned long cycles_per_hblank   = 451;
  38. unsigned char use_joystick        = 5;
  39. unsigned char gameboy_screen_mul  = 1;
  40. force_type force_system           = NONE;
  41.  
  42. void sigint(int sig);
  43.  
  44. extern int use_pad, use_cgfx, use_req, use_highcolor;
  45.  
  46. /* 
  47.  * TODO: Change -s to -s n where n is graphic mode
  48.  * (and list out available graphic modes in help)
  49.  */
  50.  
  51. void help(char *name)
  52. {
  53.   printf("usage: %s [OPTIONS] ... FILENAME\n\n", name);
  54.   printf("\t-v\tdisplay version and quit\n"
  55.          "\t-c n\tset cycles per hblank to n\n"
  56.          "\t-f [color|regular] force emulation of color or regular gameboy\n\n"
  57.          "\t-p\tCD32 pad instead of keyboard\n"
  58.          "\t-x\tCGFX instead of direct gfxmem access\n"
  59.          "\t-r\tscreenmode requester instead of CGFX BestModeID/PAL Lores\n"
  60.          "\t-h\thighcolor, 15bit, on CGFX systems\n"
  61.   );
  62. }
  63.  
  64. int main(int argc, char *argv[])
  65. {
  66.      char *filename = NULL;
  67.      int i;
  68.      
  69.      printf("gbe v0.0.22: gameboy emulator by\n");
  70.      printf("\tChuck Mason <chuckjr@sinclair.net>\n");
  71.      printf("\tSteven Fuller <relnev@atdot.org>\n");
  72.      printf("\nAmigaPPC version by\n");
  73.      printf("\tMathias Roslund <gbe@amidog.com>\n\n");
  74.  
  75.      if(argc < 2) {
  76.              help(argv[0]);
  77.           return 0;
  78.      }
  79.  
  80.      for (i=1; i<argc; i++)
  81.      {
  82.        if (argv[i][0] != '-')
  83.        {
  84.          filename = strdup(argv[i]);
  85.        }
  86.        else
  87.        {
  88.          switch(argv[i][1]) {
  89.                case 'v':
  90.                     exit(EXIT_SUCCESS);
  91.                     break;
  92.                case 'c':
  93.                     i++;
  94.                     if (i < argc) {
  95.                     cycles_per_hblank = strtoul(argv[i], NULL, 10);
  96.                     printf("Cycles per HBlank set to %ld\n", cycles_per_hblank);
  97.                     }
  98.                     break;
  99.                case 'f':
  100.                     i++;
  101.                     if (i < argc) {
  102.                     if(strcmp(argv[i], "color") == 0)
  103.                          force_system = COLOR;
  104.                     else if(strcmp(argv[i], "regular") == 0)
  105.                          force_system = REGULAR;
  106.                     else {
  107.                          printf("unknown system %s\n", argv[i]);
  108.                          return 0;
  109.                          }
  110.                     }
  111.                     break;
  112.                case 'p':
  113.                     use_pad = 1;
  114.                     break;
  115.                case 'x':
  116.                     use_cgfx = 1;
  117.                     break;
  118.                case 'r':
  119.                     use_req = 1;
  120.                     break;
  121.                case 'h':
  122.                     use_highcolor = 1;
  123.                     break;
  124.                default:
  125.                     printf("unknown argument %s\n", argv[i]);
  126.                     exit(EXIT_FAILURE);
  127.                     break;
  128.          }
  129.        }
  130.      }
  131.  
  132.      if(filename == NULL) {
  133.           fprintf(stderr, "gbe: no gameboy image specified.\n");
  134.           exit(0);
  135.      }
  136.  
  137.      if(initialize_memory() == 0) {
  138.           free_memory(); /* Free everything that was 'actually' allocated.. */
  139.           
  140.           printf("Unable to allocate memory\n");
  141.           return 0;
  142.      }
  143.  
  144.      if(load_rom(filename)) {
  145.           gbe_init_gfx();
  146.           joypad_init();
  147.           
  148.           signal(SIGINT, sigint);
  149.           
  150.           if((current_processor = gameboy_cpu_hardreset())) {
  151.                     gameboy_cpu_run(current_processor);     
  152.           }
  153.           gbe_close_gfx();
  154.      } else {
  155.           fprintf(stderr, "Unable to load '%s'\n", argv[1]);
  156.      }
  157.  
  158.      free_rom();
  159.      free_memory();
  160.  
  161.      if(current_processor) {
  162.           free(current_processor);
  163.      }
  164.  
  165.      return 1;
  166. }
  167.  
  168. void sigint(int sig)
  169. {
  170.      signal(SIGINT, sigint);
  171.      gbz80_debugger(current_processor);
  172. }
  173.