Example #1
0
int draw_xpm(char* buf, int xi, int yi, char* xpm[])
{
	int width, height;
	char* pix = NULL;
	if((pix = (char*) read_xpm(xpm, &width, &height)) == NULL)
		return 1;
	coord_t pos;
	pos.x = xi;
	pos.y = yi;
	unsigned short i = 0;
	unsigned short j = 0;
	for(; i < height; i++)
	{
		for(; j < width; j++)
		{
			if(*pix != 0)
			write_pixel(buf,pos,*pix);
			pix++;
			pos.x++;
		}
		j = 0;
		pos.y++;
		pos.x = xi;
	}
	return 0;
}
Example #2
0
char vg_draw_xpm(unsigned short xi, unsigned short yi, char *xpm[]) {
	int width, height;
	char *pixmap;

	if ((pixmap = read_xpm(xpm, &width, &height)) == NULL)
		return 1;

	char ret = vg_draw_pixmap(xi, yi, (unsigned short) width,
			(unsigned short) height, pixmap);
	free(pixmap);
	return ret;
}
Example #3
0
Sprite *create_sprite(char *pic[]) {
//allocate space for the "object"
	Sprite *sp = (Sprite *) malloc(sizeof(Sprite));
	if (sp == NULL)
		return NULL;
// read the sprite pixmap
	sp->map = read_xpm(pic, &(sp->width), &(sp->height));
	if (sp->map == NULL) {
		free(sp);
		return NULL;
	}
	return sp;
}
Example #4
0
Sprite * create_sprite(char *pic[], int xi, int yi){
	Sprite *sp = (Sprite *) malloc ( sizeof(Sprite));
	if( sp == NULL )
		return NULL;
	// read the sprite pixmap
	sp->map = read_xpm(pic, &(sp->width), &(sp->height));
	if( sp->map == NULL ) {
		free(sp);
		return NULL;
	}
	sp->x = xi;
	sp->y = yi;
	return sp;
}
Example #5
0
int vg_draw_xpm(unsigned short xi,unsigned short yi, char *map[]){
	int wd;
	int ht;
	char *pic;
	pic = read_xpm(map,&wd,&ht);
	unsigned int i,j;
	for(i = 0; i < ht; i++) {
		for(j = 0; j < wd; j++){
			vg_draw_pixel(xi+j,yi+i,*pic);
			pic++;
		}
	}
	return 0;
}
Example #6
0
Sprite *create_sprite(char * pic[], unsigned short xi, unsigned short yi) {
	Sprite * sp = (Sprite *) malloc(sizeof(Sprite));
	if (sp == NULL)
		return NULL;
	sp->map = read_xpm(pic, &(sp->width), &(sp->height), get_h_res(),
			get_v_res());
	if (sp->map == NULL) {
		free(sp);
		return NULL;
	}
	sp->x = xi;
	sp->y = yi;
	sp->xspeed = 0;
	sp->yspeed = 0;
	return sp;
}
Example #7
0
Sprite * create_sprite(char *pic[], char *base)
{
	//allocate space for the "object"
	Sprite *sp = (Sprite *) malloc ( sizeof(Sprite));
	if( sp == NULL )
		return NULL;

	sscanf(pic[0],"%d %d", &(sp->width), &(sp->height));

	// read the sprite pixmap
	sp->map = read_xpm(pic, &(sp->width), &(sp->height));
	if( sp->map == NULL ) {
		free(sp);
		return NULL;
	}

	//generic values for now
	sp->x=100;
	sp->y=100;
	sp->xspeed = 0;
	sp->yspeed = 0;

return sp;
}
Example #8
0
int test_move(unsigned short xi, unsigned short yi, char *xpm[],
		unsigned short hor, short delta, unsigned short time) {
	int width, height;
	char* pixmap;
	int ipc_status;
	message msg;
	int irq_set_timer = timer_subscribe_int();
	int irq_set_keyboard = kb_subscribe_int();
	int r;
	unsigned short counter = 0;
	long character;
	float pixmap_speed, next_position;

	if (vg_init(VBE_VIDEO_MODE) == NULL)
		return 1;

	if ((pixmap = (char*) read_xpm(xpm, &width, &height)) == NULL)
		return 1;

	pixmap_speed = (float) (delta) / (time * 60); //TODO encontrar TICKS_PER_SEC; nao existe

	if (irq_set_timer >= 0)
		irq_set_timer = BIT(irq_set_timer);
	else
		irq_set_timer = 0;

	if (irq_set_keyboard >= 0)
		irq_set_keyboard = BIT(irq_set_keyboard);
	else
		irq_set_keyboard = 0;

	next_position = 0;

	while (counter < time && character != ESC_BREAKCODE) { /* You may want to use a different condition */
		/* Get a request message. */
		if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
			printf("driver_receive failed with: %d", r);
			continue;
		}
		if (is_ipc_notify(ipc_status)) { /* received notification */
			switch (_ENDPOINT_P(msg.m_source)) {
			case HARDWARE: /* hardware interrupt notification */
				if (msg.NOTIFY_ARG & irq_set_timer) { /* subscribed interrupt */
					timed_scan_int_handler(&counter);
					vg_move_pixmap(xi, yi, width, height, pixmap, hor, next_position);
					vg_update_screen();
					next_position += pixmap_speed;
				}
				if (msg.NOTIFY_ARG & irq_set_keyboard) { /* subscribed interrupt */
					character = kb_int_handler();
				}
				break;
			default:
				break; /* no other notifications expected: do nothing */
			}
		} else { /* received a standard message, not a notification */
			/* no standard messages expected: do nothing */
		}
	}

	free(pixmap);
	return vg_exit();
}
Example #9
0
int test_move(unsigned short xi, unsigned short yi, char *xpm[], 
				unsigned short hor, short delta, unsigned short time1)
{
	if(xpm == NULL)
		return 1;
	char* video_mem = NULL;
	int failure =0;
	int width, height;
	char* pix = NULL;
	if((pix = (char*) read_xpm(xpm, &width, &height)) == NULL)
		return 1;
	if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL)
	{
		printf("test_move(): vg_init() failed");
		return 1;
	}
	int kbd_irq_set = 0;
	int timer_irq_set=0;
	if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts
		printf("test_move(): kbd_subscribe_int() failed \n");
		failure = 1;
	}
	if((timer_irq_set = timer_subscribe_int()) < 0){//subscribe timer 0 interrupts
		printf("test_move(): timer_subscribe_int() failed \n");
		failure = 1;
	}
	int ipc_status;
	message msg;
	int r;
	double step = (double)delta/(time1*60);
	double xfp = xi;
	double yfp = yi;
	if(!failure){
		do{
			/* Get a request message. */
			if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
				printf("driver_receive failed with: %d", r);
				continue;
			}
			if (is_ipc_notify(ipc_status)) { /* received notification */
				switch (_ENDPOINT_P(msg.m_source)) {
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & kbd_irq_set)  /* subscribed kbd interrupt */
						if(kbd_int_handler())
							failure = 1;
					if(msg.NOTIFY_ARG & timer_irq_set){
						if(get_ticks() < time1 * 60){//enquanto tempo desjado nao passou
							timer_int_handler();
							blank_secondary_buf();//clear buffer
							draw_pixmap(get_secondary_buf(),(int) xfp, (int) yfp, height, width, pix);
							commit_to_video_mem();
							if(hor)
								xfp += step;//se movimento horizontal incrementar x
							else yfp +=step;//senao incrementar y
						}
					}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {/* received a standard message, not a notification */
				/* no standard messages expected: do nothing */
			}
		} while(get_scancode() != ESC_BREAK && !failure);
	}
	if(timer_unsubscribe_int()){//unsubscribe interrupts
		printf("test_move(): timer_unsubscribe_int() failed\n");
		failure = 1;
	}
	if(kbd_unsubscribe_int()){//unsubscribe interrupts
		printf("test_move(): kbd_unsubscribe_int() failed\n");
		failure = 1;
	}
	printf("Done\n");
	if(vg_exit()){
		printf("test_move(): vg_exit() failed");
		return 1;
	}
	return failure;
}