コード例 #1
0
ファイル: gfx_lzw_enc.c プロジェクト: jasonkfirth/fbc
/*:::::*/
FBCALL int fb_hEncode(const unsigned char *in_buffer, int in_size, unsigned char *out_buffer, int *out_size)
{
	LZW_ENTRY *e;
	unsigned short string_code, next_code = 256;
	unsigned char bit = 0;
	int size;

	size = 0;
	fb_hMemSet(fb_lzw_entry, -1, sizeof(fb_lzw_entry));
	string_code = *in_buffer++;
	in_size--;
	while (in_size) {
		e = find_match(string_code, *in_buffer);
		if (e->code != -1)
			string_code = (unsigned short)e->code;
		else {
			if (next_code < MAX_CODE) {
				e->code = next_code++;
				e->prefix = string_code;
				e->value = *in_buffer;
			}
			OUTPUT_CODE(string_code);
			string_code = *in_buffer;
		}
		in_buffer++;
		in_size--;
	}
	OUTPUT_CODE(string_code);
	OUTPUT_CODE(MAX_CODE);
	if (bit)
		size++;
	*out_size = size;
	return 0;
}
コード例 #2
0
ファイル: gfx_core.c プロジェクト: dkoksal/fbc
/*:::::*/
FB_GFXCTX *fb_hGetContext(void)
{
	FB_GFXCTX *context;
	
	context = (FB_GFXCTX *)fb_TlsGetCtx(FB_TLSKEY_GFX, sizeof(FB_GFXCTX));
	if ((__fb_gfx) && (context->id != __fb_gfx->id)) {
		/* context has to be initialized; default to screen */
		if (context->line)
			free(context->line);
		fb_hMemSet(context, 0, sizeof(FB_GFXCTX));
		context->id = __fb_gfx->id;
		context->old_view_w = __fb_gfx->w;
		context->old_view_h = context->max_h = __fb_gfx->h;
		context->line = (unsigned char **)malloc(__fb_gfx->h * sizeof(unsigned char *));
        if ((__fb_gfx->depth > 4) && (__fb_gfx->depth <= 8))
            context->fg_color = 15;
        else
            context->fg_color = __fb_gfx->color_mask;
        context->bg_color = MASK_A_32 & __fb_gfx->color_mask;
		context->flags = CTX_BUFFER_INIT;
		fb_hPrepareTarget(context, NULL);
		fb_hSetPixelTransfer(context, MASK_A_32);
	}
	
	return context;
}
コード例 #3
0
ファイル: gfx_screen.c プロジェクト: dkoksal/fbc
FBCALL void fb_GfxSetWindowTitle(FBSTRING *title)
{
	fb_hMemSet(window_title_buff, 0, WINDOW_TITLE_SIZE);
	fb_hMemCpy(window_title_buff, title->data, MIN(WINDOW_TITLE_SIZE - 1, FB_STRSIZE(title)));
	__fb_window_title = window_title_buff;

	if ((__fb_gfx) && (__fb_gfx->driver->set_window_title))
		__fb_gfx->driver->set_window_title(__fb_window_title);

	/* del if temp */
	fb_hStrDelTemp( title );
}
コード例 #4
0
ファイル: gfx_circle.c プロジェクト: jasonkfirth/fbc
/*:::::*/
static void draw_ellipse(FB_GFXCTX *ctx, int x, int y, float a, float b, unsigned int color, int fill)
{
	int d, x1, y1, x2, y2;
	long long dx, dy, aq, bq, r, rx, ry;
	char filled[ctx->view_h];

	x1 = x - a;
	x2 = x + a;
	y1 = y2 = y;
	fb_hMemSet(filled, 0, ctx->view_h);
	
	if (!b) {
		draw_scanline(ctx, y, x1, x2, color, TRUE, filled);
		return;
	}
	else
		draw_scanline(ctx, y, x1, x2, color, fill, filled);
	
	aq = a * a;
	bq = b * b;
	dx = aq << 1;
	dy = bq << 1;
	r = a * bq;
	rx = r << 1;
	ry = 0;
	d = a;
	
	while (d > 0) {
		if (r > 0) {
			y1++;
			y2--;
			ry += dx;
			r -= ry;
		}
		if (r <= 0) {
			d--;
			x1++;
			x2--;
			rx -= dy;
			r += rx;
		}
		draw_scanline(ctx, y1, x1, x2, color, fill, filled);
		draw_scanline(ctx, y2, x1, x2, color, fill, filled);
	}
}
コード例 #5
0
ファイル: gfx_joystick.c プロジェクト: denise-amiga/fbc
FBCALL int fb_GfxGetJoystick(int id, ssize_t *buttons, float *a1, float *a2, float *a3, float *a4, float *a5, float *a6, float *a7, float *a8)
{
	const char *device[] = { "/dev/input/js",
							 "/dev/js",
							 NULL };
	/* overallocate device_name[] to prevent a sprintf() warning in GCC */
	char device_name[13 + 11 + 1];
	JOYDATA *joy;
	JS_EVENT event;
	int i, j, k, count = 0;
	int version;

	FB_GRAPHICS_LOCK( );

	if (!inited) {
		fb_hMemSet(joydata, 0, sizeof(JOYDATA) * 16);
		for (i = 0; i < 16; i++)
			joydata[i].fd = -1;
		joy = joydata;
		for (i = 0; device[i] && (count < 16); i++) {
			for (j = 0; (j < 16) && (count < 16); j++) {
				sprintf(device_name, "%s%d", device[i], j);
				joy->fd = open(device_name, O_NONBLOCK);
				if (joy->fd >= 0) {
					ioctl(joy->fd, JSIOCGVERSION, &version);
					if (version < 0x10000) {
						close(joy->fd);
						continue;
					}
					for (k = 0; k < 8; k++)
						joy->axis[k] = -1000.0;
					joy++;
					count++;
				}
			}
		}
		inited = TRUE;
	}

	*buttons = -1;
	*a1 = *a2 = *a3 = *a4 = *a5 = *a6 = *a7 = *a8 = -1000.0;

	if ((id < 0) || (id > 15)) {
		FB_GRAPHICS_UNLOCK( );
		return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
	}

	joy = &joydata[id];
	if (joy->fd < 0) {
		FB_GRAPHICS_UNLOCK( );
		return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
	}

	while (read(joy->fd, &event, sizeof(event)) > 0) {
		switch (event.type & ~JS_EVENT_INIT) {
			case JS_EVENT_AXIS:
				if (event.number < 8)
					joy->axis[event.number] = (float)event.value / 32767.0;
				break;

			case JS_EVENT_BUTTON:
				if (event.number < 32) {
					if (event.value)
						joy->buttons |= (1 << event.number);
					else
						joy->buttons &= ~(1 << event.number);
				}
				break;
		}
	}

	*a1 = joy->axis[0];
	*a2 = joy->axis[1];
	*a3 = joy->axis[2];
	*a4 = joy->axis[3];
	*a5 = joy->axis[4];
	*a6 = joy->axis[5];
	*a7 = joy->axis[6];
	*a8 = joy->axis[7];
	*buttons = joy->buttons;

	FB_GRAPHICS_UNLOCK( );
	return fb_ErrorSetNum( FB_RTERROR_OK );
}
コード例 #6
0
ファイル: gfx_circle.c プロジェクト: VlaBst6/fbc
static void draw_ellipse
	(
		FB_GFXCTX *ctx,
		int x,
		int y,
		float a,
		float b,
		unsigned int color,
		int fill,
		int *top,
		int *bottom
	)
{
	int d, x1, y1, x2, y2;
	long long dx, dy, aq, bq, r, rx, ry;
	char filled[ctx->view_h];

	x1 = x - a;
	x2 = x + a;
	y1 = y2 = y;
	fb_hMemSet(filled, 0, ctx->view_h);

	if (!b) {
		draw_scanline(ctx, y, x1, x2, color, TRUE, filled);
		*top = y;
		*bottom = y;
		return;
	}

	draw_scanline(ctx, y, x1, x2, color, fill, filled);

	aq = a * a;
	bq = b * b;
	dx = aq << 1;
	dy = bq << 1;
	r = a * bq;
	rx = r << 1;
	ry = 0;
	d = a;

	while (d > 0) {
		if (r > 0) {
			y1++;
			y2--;
			ry += dx;
			r -= ry;
		}
		if (r <= 0) {
			d--;
			x1++;
			x2--;
			rx -= dy;
			r += rx;
		}
		draw_scanline(ctx, y1, x1, x2, color, fill, filled);
		draw_scanline(ctx, y2, x1, x2, color, fill, filled);
	}

	/* Tell caller exactly which rows were drawn so the SET_DIRTY() will be
	   correct */
	*top = y2;
	*bottom = y1;
}
コード例 #7
0
ファイル: gfx_paint.c プロジェクト: dkoksal/fbc
/*:::::*/
FBCALL void fb_GfxPaint(void *target, float fx, float fy, unsigned int color, unsigned int border_color, FBSTRING *pattern, int mode, int flags)
{
	FB_GFXCTX *context = fb_hGetContext();
	int size, x, y;
	unsigned char data[256], *dest, *src;
	SPAN **span, *s, *tail, *head;

	if (!__fb_gfx)
		return;

	fb_hPrepareTarget(context, target);

	if (flags & DEFAULT_COLOR_1)
		color = context->fg_color;
	else
		color = fb_hFixColor(context->target_bpp, color);
	if (flags & DEFAULT_COLOR_2)
		border_color = color;
	else
		border_color = fb_hFixColor(context->target_bpp, border_color);

	fb_hSetPixelTransfer(context,color);

	fb_hFixRelative(context, flags, &fx, &fy, NULL, NULL);

	fb_hTranslateCoord(context, fx, fy, &x, &y);

	fb_hMemSet(data, 0, sizeof(data));
	if ((mode == PAINT_TYPE_PATTERN) && (pattern)) {
		fb_hMemCpy(data, pattern->data, MIN(256, FB_STRSIZE(pattern)));
    }
    if (pattern) {
        /* del if temp */
        fb_hStrDelTemp( pattern );
    }

	if ((x < context->view_x) || (x >= context->view_x + context->view_w) ||
	    (y < context->view_y) || (y >= context->view_y + context->view_h))
		return;

	if (context->get_pixel(context, x, y) == border_color)
		return;

	size = sizeof(SPAN *) * (context->view_y + context->view_h);
	span = (SPAN **)malloc(size);
	fb_hMemSet(span, 0, size);

	tail = head = add_span(context, span, &x, y, border_color);

	/* Find all spans to paint */
	while (tail) {
		if (tail->y - 1 >= context->view_y) {
			for (x = tail->x1; x <= tail->x2; x++) {
				if (context->get_pixel(context, x, tail->y - 1) != border_color) {
					s = add_span(context, span, &x, tail->y - 1, border_color);
					if (s) {
						head->next = s;
						head = s;
					}
				}
			}
		}
		if (tail->y + 1 < context->view_y + context->view_h) {
			for (x = tail->x1; x <= tail->x2; x++) {
				if (context->get_pixel(context, x, tail->y + 1) != border_color) {
					s = add_span(context, span, &x, tail->y + 1, border_color);
					if (s) {
						head->next = s;
						head = s;
					}
				}
			}
		}
		tail = tail->next;
	}

	DRIVER_LOCK();

	/* Fill spans */
	for (y = context->view_y; y < context->view_y + context->view_h; y++) {
		for (s = tail = span[y]; s; s = s->row_next, free(tail), tail = s) {

			dest = context->line[s->y] + (s->x1 * context->target_bpp);

			if (mode == PAINT_TYPE_FILL)
				context->pixel_set(dest, color, s->x2 - s->x1 + 1);
			else {
				src = data + (((s->y & 0x7) << 3) * context->target_bpp);
				if (s->x1 & 0x7) {
					if ((s->x1 & ~0x7) == (s->x2 & ~0x7))
						size = s->x2 - s->x1 + 1;
					else
						size = 8 - (s->x1 & 0x7);
					fb_hPixelCpy(dest, src + ((s->x1 & 0x7) * context->target_bpp), size);
					dest += size * context->target_bpp;
				}
				s->x2++;
				for (x = (s->x1 + 7) >> 3; x < (s->x2 & ~0x7) >> 3; x++) {
					fb_hPixelCpy(dest, src, 8);
					dest += 8 * context->target_bpp;
				}
				if ((s->x2 & 0x7) && ((s->x1 & ~0x7) != (s->x2 & ~0x7)))
					fb_hPixelCpy(dest, src, s->x2 & 0x7);
			}

			if (__fb_gfx->framebuffer == context->line[0])
				__fb_gfx->dirty[context->view_y + y] = TRUE;
		}
	}
	free(span);

	DRIVER_UNLOCK();

}
コード例 #8
0
ファイル: gfx_dos.c プロジェクト: jasonkfirth/fbc
static int fb_dos_timer_handler(unsigned irq)
{
	int do_abort;
	int mouse_x = 0, mouse_y = 0;
	int buttons;
	EVENT e;

	fb_dos.timer_ticks += fb_dos.timer_step;
	if( (do_abort = fb_dos.timer_ticks < 65536)==FALSE )
		fb_dos.timer_ticks -= 65536;
		
	__fb_dos_update_ticks++;
	
	if (fb_dos.in_interrupt || fb_dos.locked || __fb_dos_update_ticks < __fb_dos_ticks_per_update)
		return do_abort;

	fb_dos.in_interrupt = TRUE;
	
	__fb_dos_update_ticks -= __fb_dos_ticks_per_update;

#if 0 /* Set to 1 if you want to debug a display driver */
	outportb(0x20, 0x20);
	fb_dos_sti();
#endif

	if( fb_dos.depth <= 8 && fb_dos.set_palette && fb_dos.pal_dirty )
	{
		fb_dos.set_palette( );
		if( fb_dos.mouse_ok ) fb_hSoftCursorPaletteChanged( );
	}
	
	mouse_x = fb_dos_mouse_x;
	mouse_y = fb_dos_mouse_y;
	if ( fb_dos.mouse_ok && fb_dos.mouse_cursor ) {
		fb_hSoftCursorPut(mouse_x, mouse_y);
	}
	
	fb_dos.update();
	fb_hMemSet(__fb_gfx->dirty, FALSE, fb_dos.h);

	if ( fb_dos.mouse_ok && fb_dos.mouse_cursor ) {
		fb_hSoftCursorUnput(mouse_x, mouse_y);
	}
	
	e.type = 0;

	if ( fb_dos.mouse_ok ) {	
	
		if ( (fb_dos.mouse_x_old != mouse_x) || (fb_dos.mouse_y_old != mouse_y) ) {
			e.type = EVENT_MOUSE_MOVE;
			e.x = mouse_x;
			e.y = mouse_y;
			e.dx = mouse_x - fb_dos.mouse_x_old;
			e.dy = mouse_y - fb_dos.mouse_y_old;
			fb_hPostEvent(&e);
		}
		
		if ( fb_dos.mouse_z_old != fb_dos_mouse_z ) {
			e.type = EVENT_MOUSE_WHEEL;
			e.z = fb_dos_mouse_z;
			fb_hPostEvent(&e);
		}

		if (fb_dos_mouse_buttons != fb_dos.mouse_buttons_old) {
			buttons = (fb_dos_mouse_buttons ^ fb_dos.mouse_buttons_old) & 0x7;
			for (e.button = 0x4; e.button; e.button >>= 1) {
				if (buttons & e.button) {
					if (fb_dos_mouse_buttons & e.button)
						e.type = EVENT_MOUSE_BUTTON_PRESS;
					else
						e.type = EVENT_MOUSE_BUTTON_RELEASE;
					fb_hPostEvent(&e);
				}
			}
		}

		fb_dos.mouse_x_old = mouse_x;
		fb_dos.mouse_y_old = mouse_y;
		fb_dos.mouse_z_old = fb_dos_mouse_z;
		fb_dos.mouse_buttons_old = fb_dos_mouse_buttons;
	}
コード例 #9
0
ファイル: joystick_win32.c プロジェクト: jofers/fbc
/*:::::*/
FBCALL int fb_GfxGetJoystick(int id, int *buttons, float *a1, float *a2, float *a3, float *a4, float *a5, float *a6, float *a7, float *a8)
{
	JOYINFOEX info;
	JOYDATA *j;

	*buttons = -1;
	*a1 = *a2 = *a3 = *a4 = *a5 = *a6 = *a7 = *a8 = -1000.0;

	if (!inited) {
		fb_hMemSet(joy, 0, sizeof(JOYDATA) * 16);
		inited = TRUE;
	}

	if ((id < 0) || (id > 15))
		return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
	j = &joy[id];

	if (!j->detected) {
		j->detected = TRUE;
		if (joyGetDevCaps(id + JOYSTICKID1, &j->caps, sizeof(j->caps)) != JOYERR_NOERROR)
			return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
		j->available = TRUE;
	}
	if (!j->available)
		return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);

	info.dwSize = sizeof(info);
	info.dwFlags = JOY_RETURNALL;
	if (joyGetPosEx(id + JOYSTICKID1, &info) != JOYERR_NOERROR)
		return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
	*a1 = CALCPOS(info.dwXpos, j->caps.wXmin, j->caps.wXmax);
	*a2 = CALCPOS(info.dwYpos, j->caps.wYmin, j->caps.wYmax);
	if (j->caps.wCaps & JOYCAPS_HASZ)
		*a3 = CALCPOS(info.dwZpos, j->caps.wZmin, j->caps.wZmax);
	if (j->caps.wCaps & JOYCAPS_HASR)
		*a4 = CALCPOS(info.dwRpos, j->caps.wRmin, j->caps.wRmax);
	if (j->caps.wCaps & JOYCAPS_HASU)
		*a5 = CALCPOS(info.dwUpos, j->caps.wUmin, j->caps.wUmax);
	if (j->caps.wCaps & JOYCAPS_HASV)
		*a6 = CALCPOS(info.dwVpos, j->caps.wVmin, j->caps.wVmax);
	if (j->caps.wCaps & JOYCAPS_HASPOV)
	{
		*a7 = *a8 = 0;

		if(( info.dwPOV > 4500 - POV_LAP ) && ( info.dwPOV < 13500 + POV_LAP ))
			*a7 = 1;
		else if(( info.dwPOV > 22500 - POV_LAP ) && ( info.dwPOV < 31500 + POV_LAP ))
			*a7 = -1;

		if(( info.dwPOV > 13500 - POV_LAP ) && ( info.dwPOV < 22500 + POV_LAP ))
			*a8 = 1;
		else if(( info.dwPOV >= 0 ) && ( info.dwPOV < 4500 + POV_LAP ))
			*a8 = -1;
		else if(( info.dwPOV > 31500 - POV_LAP ) && ( info.dwPOV < 36000 ))
			*a8 = -1;
	}

	*buttons = info.dwButtons;

	return fb_ErrorSetNum( FB_RTERROR_OK );
}