Ejemplo n.º 1
0
Archivo: linux.c Proyecto: zhoukk/pixel
int main(int argc, char *argv[]) {
	XEvent event;
	KeySym keysym;
	char keychar[255];
	uint32_t timestamp = 0;
	uint32_t current;

	init_x();

	pixel_start(WIDTH, HEIGHT, argv[1]);

	for (;;) {
		while(XPending(g_X.display) > 0) {
			XNextEvent(g_X.display, &event);
			if (XFilterEvent(&event, None))
				continue;
			switch (event.type) {
			case Expose:
				if (event.xexpose.count==0) {
					pixel_frame(0.01f);
					glXSwapBuffers(g_X.display, g_X.wnd);
				}
				break;
			case KeyPress:
				XLookupString(&event.xkey, keychar, 255, &keysym, 0);
				pixel_key(KEY_DOWN, keychar[0]);
				break;
			case KeyRelease:
				XLookupString(&event.xkey, keychar, 255, &keysym, 0);
				pixel_key(KEY_UP, keychar[0]);
				break;
			case ButtonPress:
				pixel_touch(0, TOUCH_BEGIN, event.xbutton.x, event.xbutton.y);
				break;
			case ButtonRelease:
				pixel_touch(0, TOUCH_END, event.xbutton.x, event.xbutton.y);
				break;
			case MotionNotify:
				pixel_touch(0, TOUCH_MOVE, event.xbutton.x, event.xbutton.y);
				break;
			case ClientMessage:
				if ((Atom)event.xclient.data.l[0] == wm_delete_window) {
					Display *dis;
					pixel_close();
					glXMakeCurrent(g_X.display, g_X.wnd, NULL);
					dis = g_X.display;
					XFreeGC(dis, gc);
					XDestroyWindow(dis, g_X.wnd);
					XCloseDisplay(dis);
					exit(0);
				}
				break;
			}
		}
		current = _gettime();
		if (current - timestamp >= UPDATE_INTERVAL) {
			float t = (current - timestamp)/100.0f;
			timestamp = current;
			pixel_update(t);
			pixel_frame(t);
			glXSwapBuffers(g_X.display, g_X.wnd);
		} else {
			usleep(1000);
		}
	}
}
Ejemplo n.º 2
0
UINT32 hd44780_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	assert(height*9 <= bitmap.height() && width*6 <= bitmap.width());

	bitmap.fill(0, cliprect);

	if (m_display_on)
		for (int l=0; l<height; l++)
			for (int i=0; i<width; i++)
			{
				UINT8 line_base = l * 0x40;
				UINT8 line_size = (m_num_line) ? 40 : 80;
				INT8 char_pos = line_base + i;

				char_pos += m_disp_shift;

				while (char_pos < 0 || (char_pos - line_base) >= line_size)
				{
					if (char_pos < 0)
						char_pos += line_size;
					else if (char_pos - line_base >= line_size)
						char_pos -= line_size;
				}

				for (int y=0; y<8; y++)
					for (int x=0; x<5; x++)
						if (m_ddram[char_pos] <= 0x10)
						{
							//draw CGRAM characters
							pixel_update(bitmap, l, i, y, x, BIT(m_cgram[(m_ddram[char_pos]&0x07)*8+y], 4-x));
						}
						else
						{
							//draw CGROM characters
							if (region()->bytes() <= 0x800)
							{
								pixel_update(bitmap, l, i, y, x, BIT(region()->u8(m_ddram[char_pos]*8+y), 4-x));
							}
							else
							{
								if(m_ddram[char_pos] < 0xe0)
									pixel_update(bitmap, l, i, y, x, BIT(region()->u8(m_ddram[char_pos]*8+y), 4-x));
								else
									pixel_update(bitmap, l, i, y, x, BIT(region()->u8(0x700+((m_ddram[char_pos]-0xe0)*11)+y), 4-x));
							}
						}

				// if is the correct position draw cursor and blink
				if (char_pos == m_cursor_pos)
				{
					//draw the cursor
					if (m_cursor_on)
						for (int x=0; x<5; x++)
							pixel_update(bitmap, l, i, 7, x, 1);

					if (!m_blink && m_blink_on)
						for (int y=0; y<7; y++)
							for (int x=0; x<5; x++)
								pixel_update(bitmap, l, i, y, x, 1);
				}
			}

	return 0;
}