⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_ipodvideo.c

📁 linux下面的一个开源的多媒体中间件
💻 C
📖 第 1 页 / 共 2 页
字号:
		current->format->palette->colors[i+j].b = 85 * j;	    }	}    }    current->flags = flags & SDL_FULLSCREEN;    this->hidden->w = current->w = width;    this->hidden->h = current->h = height;    current->pitch = current->w * (bpp / 8);    current->pixels = this->hidden->buffer;    return current;}static int iPod_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color *colors){    if (SDL_VideoSurface && SDL_VideoSurface->format && SDL_VideoSurface->format->palette) {	int i, j;	for (i = 0; i < 256; i += 4) {	    for (j = 0; j < 4; j++) {		SDL_VideoSurface->format->palette->colors[i+j].r = 85 * j;		SDL_VideoSurface->format->palette->colors[i+j].g = 85 * j;		SDL_VideoSurface->format->palette->colors[i+j].b = 85 * j;	    }	}    }    return 0;}static void iPod_VideoQuit (_THIS){    ioctl (kbfd, KDSETMODE, KD_TEXT);    tcsetattr (kbfd, TCSAFLUSH, &old_termios);    old_kbmode = -1;    if (oldvt > 0)	ioctl (kbfd, VT_ACTIVATE, oldvt);        if (kbfd > 0)	close (kbfd);    if (dbgout) {	fprintf (dbgout, "<-- Ended SDL -->\n");	fclose (dbgout);    }        kbfd = -1;}static char iPod_SC_keymap[] = {    0,				/* 0 - no key */    '[' - 0x40,			/* ESC (Ctrl+[) */    '1', '2', '3', '4', '5', '6', '7', '8', '9',    '-', '=',    '\b', '\t',			/* Backspace, Tab (Ctrl+H,Ctrl+I) */    'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',    '\n', 0,			/* Enter, Left CTRL */    'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',    0, '\\',			/* left shift, backslash */    'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',    0, '*', 0, ' ', 0,		/* right shift, KP mul, left alt, space, capslock */    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F1-10 */    0, 0,			/* numlock, scrollock */    '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', /* numeric keypad */    0, 0,			/* padding */    0, 0, 0,			/* "less" (?), F11, F12 */    0, 0, 0, 0, 0, 0, 0,	/* padding */    '\n', 0, '/', 0, 0,	/* KP enter, Rctrl, Ctrl, KP div, PrtSc, RAlt */    0, 0, 0, 0, 0, 0, 0, 0, 0,	/* Break, Home, Up, PgUp, Left, Right, End, Down, PgDn */    0, 0,			/* Ins, Del */    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* padding */    0, 0,			/* RWin, LWin */    0				/* no key */};    static void iPod_keyboard() {    unsigned char keybuf[128];    int i, nread;    SDL_keysym keysym;    SDL_Event ev;    keysym.mod = 0;    keysym.scancode = 0xff;    memset (&ev, 0, sizeof(SDL_Event));    nread = read (kbfd, keybuf, 128);    for (i = 0; i < nread; i++) {	char ascii = iPod_SC_keymap[keybuf[i] & 0x7f];	if (dbgout) fprintf (dbgout, "Key! %02x is %c %s", keybuf[i], ascii, (keybuf[i] & 0x80)? "up" : "down");	keysym.sym = keysym.unicode = ascii;	ev.type = (keybuf[i] & 0x80)? SDL_KEYUP : SDL_KEYDOWN;	ev.key.state = 0;	ev.key.keysym = keysym;	SDL_PushEvent (&ev);    }}static void iPod_PumpEvents (_THIS) {    fd_set fdset;    int max_fd = 0;    static struct timeval zero;    int posted;    do {	posted = 0;	FD_ZERO (&fdset);	if (kbfd >= 0) {	    FD_SET (kbfd, &fdset);	    max_fd = kbfd;	}	if (dbgout) fprintf (dbgout, "Selecting");	if (select (max_fd + 1, &fdset, 0, 0, &zero) > 0) {	    if (dbgout) fprintf (dbgout, " -> match!\n");	    iPod_keyboard();	    posted++;	}	if (dbgout) fprintf (dbgout, "\n");    } while (posted);}// enough space for 160x128x2static char ipod_scr[160 * (128/4)];#define outl(datum,addr) (*(volatile unsigned long *)(addr) = (datum))#define inl(addr) (*(volatile unsigned long *)(addr))/*** The following LCD code is taken from Linux kernel uclinux-2.4.24-uc0-ipod2,     file arch/armnommu/mach-ipod/fb.c. A few modifications have been made. ***//* get current usec counter */static int M_timer_get_current(void){	return inl(lcd_rtc);}/* check if number of useconds has past */static int M_timer_check(int clock_start, int usecs){	unsigned long clock;	clock = inl(lcd_rtc);		if ( (clock - clock_start) >= usecs ) {		return 1;	} else {		return 0;	}}/* wait for LCD with timeout */static void M_lcd_wait_write(void){	if ( (inl(lcd_base) & 0x8000) != 0 ) {		int start = M_timer_get_current();					do {			if ( (inl(lcd_base) & (unsigned int)0x8000) == 0 ) 				break;		} while ( M_timer_check(start, 1000) == 0 );	}}/* send LCD data */static void M_lcd_send_data(int data_lo, int data_hi){	M_lcd_wait_write();		outl(data_lo, lcd_base + LCD_DATA);			M_lcd_wait_write();		outl(data_hi, lcd_base + LCD_DATA);}/* send LCD command */static voidM_lcd_prepare_cmd(int cmd){	M_lcd_wait_write();	outl(0x0, lcd_base + LCD_CMD);	M_lcd_wait_write();		outl(cmd, lcd_base + LCD_CMD);	}/* send LCD command and data */static void M_lcd_cmd_and_data(int cmd, int data_lo, int data_hi){	M_lcd_prepare_cmd(cmd);	M_lcd_send_data(data_lo, data_hi);}// Copied from uWstatic void M_update_display(int sx, int sy, int mx, int my){	int y;	unsigned short cursor_pos;	sx >>= 3;	mx >>= 3;	cursor_pos = sx + (sy << 5);	for ( y = sy; y <= my; y++ ) {		unsigned char *img_data;		int x;		/* move the cursor */		M_lcd_cmd_and_data(0x11, cursor_pos >> 8, cursor_pos & 0xff);		/* setup for printing */		M_lcd_prepare_cmd(0x12);		img_data = ipod_scr + (sx << 1) + (y * (lcd_width/4));		/* loops up to 160 times */		for ( x = sx; x <= mx; x++ ) {		        /* display eight pixels */			M_lcd_send_data(*(img_data + 1), *img_data);			img_data += 2;		}		/* update cursor pos counter */		cursor_pos += 0x20;	}}/* get current usec counter */static int C_timer_get_current(void){	return inl(0x60005010);}/* check if number of useconds has past */static int C_timer_check(int clock_start, int usecs){	unsigned long clock;	clock = inl(0x60005010);		if ( (clock - clock_start) >= usecs ) {		return 1;	} else {		return 0;	}}/* wait for LCD with timeout */static void C_lcd_wait_write(void){	if ((inl(0x70008A0C) & 0x80000000) != 0) {		int start = C_timer_get_current();					do {			if ((inl(0x70008A0C) & 0x80000000) == 0) 				break;		} while (C_timer_check(start, 1000) == 0);	}}static void C_lcd_cmd_data(int cmd, int data){	C_lcd_wait_write();	outl(cmd | 0x80000000, 0x70008A0C);	C_lcd_wait_write();	outl(data | 0x80000000, 0x70008A0C);}static void C_update_display(int sx, int sy, int mx, int my){	int height = (my - sy) + 1;	int width = (mx - sx) + 1;	char *addr = SDL_VideoSurface->pixels;	if (width & 1) width++;	/* start X and Y */	C_lcd_cmd_data(0x12, (sy & 0xff));	C_lcd_cmd_data(0x13, (((SDL_VideoSurface->w - 1) - sx) & 0xff));	/* max X and Y */	C_lcd_cmd_data(0x15, (((sy + height) - 1) & 0xff));	C_lcd_cmd_data(0x16, (((((SDL_VideoSurface->w - 1) - sx) - width) + 1) & 0xff));	addr += sx + sy * SDL_VideoSurface->pitch;	while (height > 0) {		int h, x, y, pixels_to_write;		pixels_to_write = (width * height) * 2;		/* calculate how much we can do in one go */		h = height;		if (pixels_to_write > 64000) {			h = (64000/2) / width;			pixels_to_write = (width * h) * 2;		}		outl(0x10000080, 0x70008A20);		outl((pixels_to_write - 1) | 0xC0010000, 0x70008A24);		outl(0x34000000, 0x70008A20);		/* for each row */		for (x = 0; x < h; x++)		{			/* for each column */			for (y = 0; y < width; y += 2) {				unsigned two_pixels;				two_pixels = addr[0] | (addr[1] << 16);				addr += 2;				while ((inl(0x70008A20) & 0x1000000) == 0);				/* output 2 pixels */				outl(two_pixels, 0x70008B00);			}			addr += SDL_VideoSurface->w - width;		}		while ((inl(0x70008A20) & 0x4000000) == 0);		outl(0x0, 0x70008A24);		height = height - h;	}}// Should work with photo. However, I don't have one, so I'm not sure.static void iPod_UpdateRects (_THIS, int nrects, SDL_Rect *rects) {    if (SDL_VideoSurface->format->BitsPerPixel == 16) {	C_update_display (0, 0, lcd_width, lcd_height);    } else {	int i, y, x;	for (i = 0; i < nrects; i++) {	    SDL_Rect *r = rects + i;	    if (!r) {		continue;	    }	    	    for (y = r->y; (y < r->y + r->h) && y < lcd_height; y++) {		for (x = r->x; (x < r->x + r->w) && x < lcd_width; x++) {		    ipod_scr[y*(lcd_width/4) + x/4] &= ~(3 << (2 * (x%4)));		    ipod_scr[y*(lcd_width/4) + x/4] |=			(((Uint8*)(SDL_VideoSurface->pixels))[ y*SDL_VideoSurface->pitch + x ] & 3) << (2 * (x%4));		}	    }	}		M_update_display (0, 0, lcd_width, lcd_height);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -