Beispiel #1
0
void
reset(Mach *m)
{
	loadrom(m);
	m->ac = m->io = m->ov = m->halt = 0;
	m->pc                           = 4;
	memset(m->flag, 0, sizeof(m->flag));
	memset(m->sense, 0, sizeof(m->sense));
	m->frametime = SDL_GetTicks();
}
Beispiel #2
0
static int cbfs_print(int argc, char **argv)
{
    char *romname = argv[1];
    char *cmd = argv[2];
    void *rom = loadrom(romname);

    if (rom == NULL) {
        printf("Could not load ROM image '%s'.\n", romname);
        return 1;
    }

    print_cbfs_directory(romname);
    return 0;
}
Beispiel #3
0
static int cbfs_add_stage(int argc, char **argv)
{
    char *romname = argv[1];
    char *cmd = argv[2];
    void *rom = loadrom(romname);

    if (rom == NULL) {
        printf("Could not load ROM image '%s'.\n", romname);
        return 1;
    }

    if (argc < 5) {
        printf("not enough arguments to '%s'.\n", cmd);
        return 1;
    }

    char *filename = argv[3];
    char *cbfsname = argv[4];

    uint32_t filesize = 0;
    void *filedata = loadfile(filename, &filesize, 0, SEEK_SET);
    if (filedata == NULL) {
        printf("Could not load file '%s'.\n", filename);
        return 1;
    }

    uint32_t base = 0;
    void *cbfsfile = NULL;

    comp_algo algo = CBFS_COMPRESS_NONE;
    if (argc > 5) {
        if (argv[5][0] == 'l')
            algo = CBFS_COMPRESS_LZMA;
    }
    if (argc > 6) {
        base = strtoul(argv[6], NULL, 0);
    }
    unsigned char *stage;
    filesize = parse_elf_to_stage(filedata, &stage, algo, &base);
    cbfsfile =
        create_cbfs_file(cbfsname, stage, &filesize,
                         CBFS_COMPONENT_STAGE, &base);

    if (add_file_to_cbfs(cbfsfile, filesize, base))
        return 1;
    if (writerom(romname, rom, romsize))
        return 1;
    return 0;
}
Beispiel #4
0
static int cbfs_add(int argc, char **argv)
{
    char *romname = argv[1];
    char *cmd = argv[2];
    void *rom = loadrom(romname);

    if (rom == NULL) {
        printf("Could not load ROM image '%s'.\n", romname);
        return 1;
    }

    if (argc < 5) {
        printf("not enough arguments to '%s'.\n", cmd);
        return 1;
    }

    char *filename = argv[3];
    char *cbfsname = argv[4];

    uint32_t filesize = 0;
    void *filedata = loadfile(filename, &filesize, 0, SEEK_SET);
    if (filedata == NULL) {
        printf("Could not load file '%s'.\n", filename);
        return 1;
    }

    uint32_t base = 0;
    void *cbfsfile = NULL;

    if (argc < 6) {
        printf("not enough arguments to 'add'.\n");
        return 1;
    }
    uint32_t type;
    if (intfiletype(argv[5]) != ((uint64_t) - 1))
        type = intfiletype(argv[5]);
    else
        type = strtoul(argv[5], NULL, 0);
    if (argc > 6) {
        base = strtoul(argv[6], NULL, 0);
    }
    cbfsfile = create_cbfs_file(cbfsname, filedata, &filesize, type, &base);
    if (add_file_to_cbfs(cbfsfile, filesize, base))
        return 1;
    if (writerom(romname, rom, romsize))
        return 1;
    return 0;
}
Beispiel #5
0
int main(int argc, char *argv[]) {

  if (argc < 2) {
    printf("Usage: ./chipemu romfile\n");
    return 0;
  }

  char* filename;
  
  if (argc == 3 && (int)argv[1][0] == '-' && (int)argv[1][1] == 'h') {
    HARNESS = 1;
    filename = argv[2];
  }
  else {
    HARNESS = 0;
    filename = argv[1];
  }

  int filesize = loadrom(filename, &romdata);
  display_width = WIDTH*MODIFIER;
  display_height = HEIGHT*MODIFIER;

  initialize(&p, filesize);

  if (DEBUGMODE) step(&p);

  if (HARNESS) while(1) run(&p);

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);

  glutInitWindowSize(display_width, display_height);
  glutInitWindowPosition(320, 160);
  glutCreateWindow("Chip-8 Emulator");

  glutDisplayFunc(emulationLoop);
  glutIdleFunc(emulationLoop);
  glutReshapeFunc(reshapeWindow);
  glutKeyboardFunc(keyboardDown);
  glutKeyboardUpFunc(keyboardUp);
  glutTimerFunc(2, decTimers, 0);

  glutMainLoop();

  return 0;
}
Beispiel #6
0
static void file_open(HWND hWnd)
{
    char buffer[1024];
    static char filter[] =
        "NES ROMs (*.nes, *.unf, *.unif *.fds *.nsf)\0*.nes;*.unf;*.unif;*.fds;*.nsf\0"
        "iNES ROMs (*.nes)\0*.nes\0"
        "UNIF ROMs (*.unf, *.unif)\0*.unf;*.unif\0"
        "FDS Images (*.fds)\0*.fds\0"
        "NSF Files (*.nsf)\0*.nsf\0"
        "All Files (*.*)\0*.*\0";

    memset(buffer,0,1024);
    if(filedialog(hWnd,0,buffer,"Open NES ROM...",filter,0) != 0)
        return;
    log_printf("WndProc:  loading file '%s'\n",buffer);
    loadrom(buffer);
}
Beispiel #7
0
//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static char dest[1024];
    int i,wmId,wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    HMENU hMenu;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case ID_FILE_OPEN:
            file_open(hWnd);
            break;
        case ID_FILE_LOADPATCH:
            file_open_patch(hWnd);
            break;
        case ID_FILE_UNLOAD:
            emu_event(E_UNLOAD,0);
            break;
        case ID_NES_PAUSE:
            emu_event(E_TOGGLERUNNING,0);
            break;
        case ID_NES_SOFTRESET:
            emu_event(E_SOFTRESET,0);
            break;
        case ID_NES_HARDRESET:
            emu_event(E_HARDRESET,0);
            break;
        case ID_NES_LOADSTATE:
            emu_event(E_LOADSTATE,0);
            break;
        case ID_NES_SAVESTATE:
            emu_event(E_SAVESTATE,0);
            break;
        case ID_MOVIE_LOAD:
            load_movie(hWnd);
            break;
        case ID_MOVIE_SAVE:
            save_movie(hWnd);
            break;
        case ID_MOVIE_PLAY:
            emu_event(E_PLAYMOVIE,0);
            break;
        case ID_MOVIE_RECORD:
            emu_event(E_RECORDMOVIE,0);
            break;
        case ID_MOVIE_STOP:
            emu_event(E_STOPMOVIE,0);
            break;
        case ID_FDS_FLIPDISK:
            emu_event(E_FLIPDISK,0);
            break;
        case ID_VIEW_CONFIGURATION:
            ConfigurationPropertySheet(hWnd);
            break;
        case ID_VIEW_DEBUGGER:
            DialogBox(hInst,(LPCTSTR)IDD_DEBUGGER,hWnd,(DLGPROC)DebuggerDlg);
            break;
        case ID_VIEW_SEARCH:
            DialogBox(hInst,(LPCTSTR)IDD_CHEATSEARCH,hWnd,(DLGPROC)CheatSearchDlg);
            break;
        case ID_VIEW_CONSOLE:
            hMenu = GetMenu(hWnd);
            if(GetWindowLong(hConsole,GWL_USERDATA) == 0) {
                CheckMenuItem(hMenu,ID_VIEW_CONSOLE,MF_CHECKED);
                ShowWindow(hConsole,SW_SHOW);
                SetWindowLong(hConsole,GWL_USERDATA,1);
            }
            else {
                CheckMenuItem(hMenu,ID_VIEW_CONSOLE,MF_UNCHECKED);
                ShowWindow(hConsole,SW_HIDE);
                SetWindowLong(hConsole,GWL_USERDATA,0);
            }
            break;
        case IDM_ABOUT:
            DialogBox(hInst,(LPCTSTR)IDD_ABOUT,hWnd,(DLGPROC)AboutDlg);
            break;
        case ID_HELP_SUPPORTEDMAPPERS:
            DialogBox(hInst,(LPCTSTR)IDD_MAPPERS,hWnd,(DLGPROC)MappersDlg);
            break;
        case IDM_EXIT:
            if(config_get_bool("video.fullscreen") != 0)
                emu_event(E_WINDOWED,0);
            else
                DestroyWindow(hWnd);
            break;
        case ID_VIEW_FULLSCREEN:
            emu_event(E_TOGGLEFULLSCREEN,0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_ENTERMENULOOP:
        sound_pause();
        for(i=0; nesids[i] != -1; i++) {
            EnableMenuItem(GetMenu(hWnd),nesids[i],nes->cart ? MF_ENABLED : MF_GRAYED);
        }
        break;
    case WM_EXITMENULOOP:
        sound_play();
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        quit++;
        if(hConsole)
            DestroyWindow(hConsole);
        PostQuitMessage(0);
        break;
    case WM_SIZE:
//		video_resize();
        break;
    case WM_DROPFILES:
        DragQueryFile((HDROP)wParam,0,dest,1024);
        DragFinish((HDROP)wParam);
        loadrom(dest);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Beispiel #8
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	int ret;
	char *p,*p2,*cmdline;

	memset(configfilename,0,1024);
	MyRegisterClass(hInstance);
	if(InitInstance(hInstance,nCmdShow) == 0) {
		return(FALSE);
	}

	log_sethook(console_loghook);

	//make the exe path variable
	GetModuleFileName(hInstance,exepath,1024);
	if((p = strrchr(exepath,PATH_SEPERATOR)) != 0) {
		*p = 0;
	}

	if(emu_init() != 0)
		return(FALSE);

   ShowWindow(hWnd,nCmdShow);
   UpdateWindow(hWnd);

	p = cmdline = mem_strdup(lpCmdLine);
	if(*p == '\"') {
		p++;
		if((p2 = strchr(p,'\"')) != 0)
			*p2 = 0;
	}

	if(strcmp(p,"") != 0) {
		char *filename;

		//it is a relative path, make full path name
		if(p[1] != ':') {
			char *cwd = system_getcwd();
			int len = strlen(p) + strlen(cwd) + 2;

			filename = (char*)mem_alloc(len);
			sprintf(filename,"%s\\%s",cwd,p);
		}

		//already full path name
		else {
			filename = mem_strdup(p);
		}

		log_printf("trying lpcmdline as filename (%s)...\n",filename);
		loadrom(filename);
		mem_free(filename);
	}

	mem_free(cmdline);

	ret = (emu_mainloop() == 0) ? TRUE : FALSE;

	emu_kill();

	return(emu_exit(ret));
}
Beispiel #9
0
static void loadrecent(int n)
{
	loadrom(config.recent[n]);
}