Esempio n. 1
0
int main(int argc, char* argv[]) {
   clock_t t;
   clock_t delta = CLOCKS_PER_SEC / clock_rate;

   /* accept a file name as an argument */
   char *file = (char*)"roms/Pong [Paul Vervalin, 1990].ch8";
   if (argc == 2)
      file = argv[1];

   /* initialise the emulator */
   chip8_init();

   /* load a rom into memory */
   if(!chip8_load_rom(file))
      goto done;

   /* setup SDL and GL */
   init();

   /* main event loop */
   t = clock();
   do {
      if (clock() > t){
         chip8_cycle();
         if (chip8_refresh_screen())
            render();
         input();
         t += delta;
      }
   } while (!quit);

done:
   close();
   return 0;
}
Esempio n. 2
0
File: main.c Progetto: bogger33/emus
int main(int argc, char *argv[])
{
	/* Check usage */
	if (argc != 2) {
		printf("Usage: %s <rom_path>\n", argv[0]);
		return 1;
	}

	/* Initialize video backend */
	backend_video_init();

	/* Initialize and run machine */
	chip8_init(argv[1]);
	chip8_run();

	return 0;
}
Esempio n. 3
0
int main() {

	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

	video v;
	
  	input in;
	chip8cpu c8cpu;

	init_video(&v);
	chip8_init(&c8cpu);
	chip8_load_resources(&c8cpu, &v, &in);
	
	load_program(&c8cpu);


	for (;;) {
		/*
		parse_instruction(&c8cpu, 0x620A);  // set r2 to 0A
		parse_instruction(&c8cpu, 0x6308);  // set r3 to 09
		parse_instruction(&c8cpu, 0x8235);  // subtract r3 from r2
		parse_instruction(&c8cpu, 0xA003);  // set I to 123
		parse_instruction(&c8cpu, 0xF555);  // move r4 to [I]
		*/

		if (check_for_exit(c8cpu.p_input))
			break;

		SDL_Flip(c8cpu.p_video->screen);
		SDL_Delay(250);
		break;
	}
	print_chip8_state(&c8cpu);
	main_memory_dump(&c8cpu);
	
	SDL_Quit();

	return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("Usage: ./CHIP-SDL rom\n");
        return -1;
    }

    srand(time(NULL));
    printf("Chip-SDL by xerpi\n");
    printf("Loading \"%s\"...", argv[1]);
    struct chip8_context chip8;
    chip8_init(&chip8, 64, 32);
    int ret = chip8_loadrom(&chip8, argv[1]);
    if (ret) printf("OK!\n");
    else {
        printf("ERROR.\n");
        chip8_fini(&chip8);
        return -1;
    }
    printf("Running \"%s\"...\n", argv[1]);
    
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window *window = SDL_CreateWindow("Chip-SDL",
       SDL_WINDOWPOS_CENTERED,
       SDL_WINDOWPOS_CENTERED,
       640,
       320,
       SDL_WINDOW_SHOWN);
    SDL_Surface *screen = SDL_GetWindowSurface(window);
    SDL_Surface *chip8_disp = CreateSurface(SDL_SWSURFACE, 64, 32, screen);
    SDL_Event event;
    int running = 1;
    
    while (running) {
        while (SDL_PollEvent(&event) != 0) {
            switch (event.type) {
            case SDL_QUIT:
                running = 0;
                break;
            case SDL_KEYDOWN:
                switch (event.key.keysym.sym) {
                    case SDLK_q:
                        running = 0;
                        break;
                    case SDLK_r:
                        chip8_reset(&chip8);
                        chip8_loadrom(&chip8, argv[1]);
                        break;
                    case SDLK_w:
                        chip8_key_press(&chip8, 1);
                        break;
                    case SDLK_s:
                        chip8_key_press(&chip8, 4);
                        break;
                    case SDLK_UP:
                        chip8_key_press(&chip8, 0xC);
                        break;
                    case SDLK_DOWN:
                        chip8_key_press(&chip8, 0xD);
                        break;
                }
                break;
            case SDL_KEYUP:
                switch (event.key.keysym.sym) {
                    case SDLK_q:
                        running = 0;
                        break;
                    case SDLK_w:
                        chip8_key_release(&chip8, 1);
                        break;
                    case SDLK_s:
                        chip8_key_release(&chip8, 4);
                        break;
                    case SDLK_UP:
                        chip8_key_release(&chip8, 0xC);
                        break;
                    case SDLK_DOWN:
                        chip8_key_release(&chip8, 0xD);
                        break;
                }
                break;
            }
        }
        
        chip8_step(&chip8);
        /*int x, y;
        for (y = 0; y < 32; y++) {
            for (x = 0; x < 8; x++) {
                int i;
                for (i = 0; i < 8; i++) {
                    printf("%c", (chip8.disp_mem[x+y*8]>>(7-i))&0b1 ? 'X' : 'O');
                }
                printf(" ");
            }
            printf("\n");
        }
        printf("\n\n");
        */
        
        //chip8_core_dump(&chip8);
        //usleep(16667);

        chip8_disp_to_SDL(&chip8, chip8_disp);
        SDL_BlitScaled(chip8_disp, NULL, screen, NULL);
        SDL_UpdateWindowSurface(window);
    }
    
    chip8_fini(&chip8);
    SDL_FreeSurface(chip8_disp);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}