home *** CD-ROM | disk | FTP | other *** search
- /*
- * gbe - gameboy emulator
- * Copyright (C) 1999 Chuck Mason, Steven Fuller
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *
- * Chuck Mason <chuckjr@sinclair.net>
- * Steven Fuller <relnev@atdot.org>
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <string.h>
-
- #include "rom.h"
- #include "mem.h"
- #include "data.h"
- #include "vram.h"
- #include "cpu.h"
- #include "joypad.h"
- #include "debug.h"
-
- gameboy_proc_t *current_processor = NULL;
- unsigned long cycles_per_hblank = 451;
- unsigned char use_joystick = 5;
- unsigned char gameboy_screen_mul = 1;
- force_type force_system = NONE;
-
- void sigint(int sig);
-
- extern int use_pad, use_cgfx, use_req, use_highcolor;
-
- /*
- * TODO: Change -s to -s n where n is graphic mode
- * (and list out available graphic modes in help)
- */
-
- void help(char *name)
- {
- printf("usage: %s [OPTIONS] ... FILENAME\n\n", name);
- printf("\t-v\tdisplay version and quit\n"
- "\t-c n\tset cycles per hblank to n\n"
- "\t-f [color|regular] force emulation of color or regular gameboy\n\n"
- "\t-p\tCD32 pad instead of keyboard\n"
- "\t-x\tCGFX instead of direct gfxmem access\n"
- "\t-r\tscreenmode requester instead of CGFX BestModeID/PAL Lores\n"
- "\t-h\thighcolor, 15bit, on CGFX systems\n"
- );
- }
-
- int main(int argc, char *argv[])
- {
- char *filename = NULL;
- int i;
-
- printf("gbe v0.0.22: gameboy emulator by\n");
- printf("\tChuck Mason <chuckjr@sinclair.net>\n");
- printf("\tSteven Fuller <relnev@atdot.org>\n");
- printf("\nAmigaPPC version by\n");
- printf("\tMathias Roslund <gbe@amidog.com>\n\n");
-
- if(argc < 2) {
- help(argv[0]);
- return 0;
- }
-
- for (i=1; i<argc; i++)
- {
- if (argv[i][0] != '-')
- {
- filename = strdup(argv[i]);
- }
- else
- {
- switch(argv[i][1]) {
- case 'v':
- exit(EXIT_SUCCESS);
- break;
- case 'c':
- i++;
- if (i < argc) {
- cycles_per_hblank = strtoul(argv[i], NULL, 10);
- printf("Cycles per HBlank set to %ld\n", cycles_per_hblank);
- }
- break;
- case 'f':
- i++;
- if (i < argc) {
- if(strcmp(argv[i], "color") == 0)
- force_system = COLOR;
- else if(strcmp(argv[i], "regular") == 0)
- force_system = REGULAR;
- else {
- printf("unknown system %s\n", argv[i]);
- return 0;
- }
- }
- break;
- case 'p':
- use_pad = 1;
- break;
- case 'x':
- use_cgfx = 1;
- break;
- case 'r':
- use_req = 1;
- break;
- case 'h':
- use_highcolor = 1;
- break;
- default:
- printf("unknown argument %s\n", argv[i]);
- exit(EXIT_FAILURE);
- break;
- }
- }
- }
-
- if(filename == NULL) {
- fprintf(stderr, "gbe: no gameboy image specified.\n");
- exit(0);
- }
-
- if(initialize_memory() == 0) {
- free_memory(); /* Free everything that was 'actually' allocated.. */
-
- printf("Unable to allocate memory\n");
- return 0;
- }
-
- if(load_rom(filename)) {
- gbe_init_gfx();
- joypad_init();
-
- signal(SIGINT, sigint);
-
- if((current_processor = gameboy_cpu_hardreset())) {
- gameboy_cpu_run(current_processor);
- }
- gbe_close_gfx();
- } else {
- fprintf(stderr, "Unable to load '%s'\n", argv[1]);
- }
-
- free_rom();
- free_memory();
-
- if(current_processor) {
- free(current_processor);
- }
-
- return 1;
- }
-
- void sigint(int sig)
- {
- signal(SIGINT, sigint);
- gbz80_debugger(current_processor);
- }
-