示例#1
0
/* Set up the next sample */
static int
screen_sample(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_screen_enum *penum = senum;
    gs_point pt;
    int code = gs_screen_currentpoint(penum, &pt);
    ref proc;

    switch (code) {
        default:
            return code;
        case 1:
            /* All done */
            if (real_opproc(esp - 2) != 0)
                code = (*real_opproc(esp - 2)) (i_ctx_p);
            esp -= snumpush;
            screen_cleanup(i_ctx_p);
            return (code < 0 ? code : o_pop_estack);
        case 0:
            ;
    }
    push(2);
    make_real(op - 1, pt.x);
    make_real(op, pt.y);
    proc = sproc;
    push_op_estack(set_screen_continue);
    *++esp = proc;
    return o_push_estack;
}
示例#2
0
/* the code for Type 1 halftones in sethalftone. */
int
zscreen_enum_init(i_ctx_t *i_ctx_p, const gx_ht_order * porder,
                  gs_screen_halftone * psp, ref * pproc, int npop,
                  int (*finish_proc)(i_ctx_t *), int space_index)
{
    gs_screen_enum *penum;
    gs_memory_t * mem = (gs_memory_t *)idmemory->spaces_indexed[space_index];
    int code;

    check_estack(snumpush + 1);
    penum = gs_screen_enum_alloc(mem, "setscreen");
    if (penum == 0)
        return_error(e_VMerror);
    make_struct(esp + snumpush, space_index << r_space_shift, penum);	/* do early for screen_cleanup in case of error */
    code = gs_screen_enum_init_memory(penum, porder, igs, psp, mem);
    if (code < 0) {
        screen_cleanup(i_ctx_p);
        return code;
    }
    /* Push everything on the estack */
    make_mark_estack(esp + 1, es_other, screen_cleanup);
    esp += snumpush;
    make_op_estack(esp - 2, finish_proc);
    sproc = *pproc;
    push_op_estack(screen_sample);
    pop(npop);
    return o_push_estack;
}
示例#3
0
文件: main.c 项目: theta43/tetris
/* We can exit() at any point and still safely cleanup */
static void cleanup(void)
{
	screen_cleanup();
	blocks_cleanup();

	/* Game separator */
	fprintf(stderr, "--\n");

	fclose(stderr);
	printf("Thanks for playing Blocks-%s!\n", VERSION);
}
示例#4
0
文件: main.c 项目: thebirk/ccpu
int main(int argc, char** argv)
{
	int i;
	int window = 1;
	int showhelp = 0;
	int fps = 0;
	int width = 640;
	int height = 360;
	int fullscreen = 0;

	if(argc > 2) {
		for(i = 2; i < argc; i++) {
			char* dup = strdup(argv[i]);
			char* tok = strtok(dup, "=");			

			if(strcmp(argv[i], "-s") == 0) {
				stepping = 1;
			}else if(strcmp(argv[i], "-noscreen") == 0) {
				window = 0;
			}else if(strcmp(argv[i], "-h") == 0) {
				showhelp = 1;
			}else if(strcmp(argv[i], "-fps") == 0) {
				fps = 1;
			}else if(strcmp(tok, "-width") == 0) {
				tok = strtok(NULL, "=");
				width = strtol(tok, NULL, 0);
			}else if(strcmp(tok, "-height") == 0) {
				tok = strtok(NULL, "=");
				height = strtol(tok, NULL, 0);
			}else if(strcmp(argv[i], "-f") == 0) {
				fullscreen = 1;
			}
			else {
				printf("Ignoring unknown argument '%s'. Use '-h' for more information\n", argv[i]);
			}
		}
	}

	if(argc < 2 | showhelp) {
		printf("Usage: ccpu <binary> [options]\n\nOptions:\n\t-s - Stepping mode\n\t-noscreen - No screen/window\n\t-fps - Output fps\n\t-width=w - Set window width\n\t-height=h - Set window height\n\t-f - Fullscreen mode\n");
		return -1;
	}

	FILE* f = fopen(argv[1], "rb");
	if(f == NULL) {
		printf("Failed to open '%s'\n", argv[1]);
		return -1;
	}
	fseek(f, 0, SEEK_END);
	int length = ftell(f);
	rewind(f);
	u8* buffer = (u8*)malloc(sizeof(u8)*length);
	int read = fread(buffer, sizeof(u8), length, f);
	fclose(f);

	if(read != length) {
		printf("Failed to read file '%s'\n", argv[1]);
		return -1;
	}

	f = fopen("rom.bin", "rb");
	if(f == NULL) {
		printf("Could not open 'rom.bin'\n");
		return -1;
	}
	fseek(f, 0, SEEK_END);
	int rom_length = ftell(f);
	if(rom_length > 0x1000) {
		printf("'rom.bin' is %04X bytes long, but can not be longer than 0x100 bytes\n", rom_length);
		return -1;
	}
	rewind(f);
	u8* rom_buffer = (u8*)malloc(sizeof(u8)*rom_length);
	read = fread(rom_buffer, sizeof(u8), rom_length, f);
	if(read != rom_length) {
		printf("Failed to read 'rom.bin'\n");
		return -1;
	}
	fclose(f);

	c = cpu_init(0x1000);

	for(i = 0; i < length; i++) {
		c->mem[c->ip+i] = buffer[i];
	}

	for(i = 0; i < rom_length; i++) {
		c->mem[0xF000+i] = rom_buffer[i];
	}

	c->ip = 0xF000;

	SDL_Thread* ccpu_thread = SDL_CreateThread(cpu_thread_func, "ccpu_thread", NULL);
	
	if(window) {
	Screen* s = screen_init(width, height, 640, 360, 8, 12, 16, 16, fullscreen);

	Uint32 now = SDL_GetTicks();
	Uint32 lastTime = now;
	Uint32 fpsCounterTime = now;
	Uint32 interval = 16;

	int frames = 0;

	while(!screen_closerequested(s)) {
		now = SDL_GetTicks();
		
		if(now - lastTime > interval) {
			screen_update(s, c);
			frames++;
			lastTime = now;	
		}

		if(now - fpsCounterTime > 1000) {
			if(fps) printf("fps %d\n", frames);
			frames = 0;
			fpsCounterTime = now;
		}

		screen_pollevents(s, c);
		if(!cpu_running) break;
	}
	screen_cleanup(s);
	SDL_DetachThread(ccpu_thread);
	}else {
		SDL_WaitThread(ccpu_thread, NULL);
	}
	
	return 0;
}