Esempio n. 1
0
int processCOMD(char *comd, sockaddr_in addr, char *user_name)
{
	char cmd[strlen(comd)];
	strcpy(cmd,comd);
	strtok(cmd,":");
	char arg[strlen(comd)-strlen(cmd)];
	strcpy(arg,"");
	if(strlen(cmd)+1<strlen(comd))
	{
		strcpy(arg,substr(comd,strlen(cmd)+1,strlen(comd)));
	}
	if(strcmp(cmd,CONFIRM_COMD)==0)
	{
		if(strlen(arg)>0)
		{
			char confirm[strlen(arg)];
			strcpy(confirm,arg);
			if(strchr(confirm,':'))
			{
				strtok(confirm,":");
				char obj[strlen(arg)-strlen(confirm)-1];
				strcpy(obj,substr(arg,strlen(confirm)+1,strlen(arg)));
				if(strcmp(confirm,"file")==0)
				{
					sprintf(logC,"File \"%s\" sent\n",obj);
					consoleLog(logC);
					memset(&logC,0,strlen(logC));
				}
			}
		}
		return 0;
	}
	else if(strcmp(cmd,ASK_PASSWORD)==0)
	{
		consoleLog("Sending password...\n");
		return -1;
	}
	else if(strcmp(cmd,KICK_COMD)==0)
	{
		sprintf(logC,"You have been kicked: %s\n",arg);
		consoleLog(logC);
		memset(&logC,0,strlen(logC));
		close(socket_descriptor);
		STATE=False;
	}
	else if(strcmp(cmd,PING_COMD)==0)
	{
		return 0;
	}
	else if(strcmp(cmd,REFUSE_COMD)==0)
	{
		consoleErrorLog(atoi(arg));
		return atoi(arg);
	}
}
Esempio n. 2
0
void* send_fold(void *params)
{
	char *tmp=params;
	if(strlen(tmp)<1)
	{
		/* Error 7: Worng parameters */
		consoleErrorLog(7);
		consoleUsageCmd(&SEND_FOLD_CMD);
		return;
	}
	packet p;
	p.IP_src=client_address.sin_addr;
	p.IP_dst=server_address.sin_addr;
	strcpy(p.login_src,user_login);
	strcpy(p.login_dst,SERVER_ADMIN_NAME);
	strcpy(p.data_type,FILE_TYPE);
	
	char fold[strlen(tmp)+1];
	strcpy(fold,tmp);
	strcat(fold,"/");
	
	path_content path;
	getListFolder(fold,&path);
	int i;
	for(i=0;i<path.nb_elmt;i++)
	{
		if(strcmp(path.content[i],"..")==0)
		{
			continue;
		}
		FILE *f=NULL;
		char file_path[strlen(fold)+strlen(path.content[i])];
		strcpy(file_path,fold);
		strcat(file_path,path.content[i]);
		f=fopen(file_path,"r");
		if(f!=NULL)
		{
			fclose(f);
			packet *packet_file;
			packet_file=calloc(1,sizeof(packet));
			memcpy(packet_file,&p,sizeof(packet));
			send_file_packet(file_path,socket_descriptor,packet_file);
			free(packet_file);
		}
		else
		{
			char sub_fold[strlen(path.content[i])];
			strcpy(sub_fold,path.content[i]);
			strcpy(sub_fold,substr(sub_fold,1,strlen(sub_fold)));
			strtok(sub_fold,"]");
			char new_path[strlen(fold)+1+strlen(sub_fold)];
			strcpy(new_path,fold);
			strcat(new_path,sub_fold);
			send_fold(new_path);
		}
	}
	sprintf(logC,"Folder \"%s\" sent\n",fold);
	consoleLog(logC);
	memset(&logC,0,strlen(logC));
}
char * parseSpaceString(const char * text)
{
	if (text == NULL)
	{
		crashViewer("0x10000002", "接收数据时侦测到空指针错误");
		return "";
	}
	char *space = __SPACE__FILE_READ__;
	size_t i = 0, len = strlen(text),offset = 0;
	char *str = (char *) calloc(__BUFFSIZE__*strlen(__SPACE__FILE_READ__)+1,sizeof(char));
	if (str == NULL)
	{
		consoleLog("在转化空格时出现了无法申请内存的现象");
		return NULL;
	}
	for (i = 0; i < len; i++)
	{
		if (text[i] <= 32 && text[i] >= 0 )
		{
			size_t ts = strlen(__SPACE__FILE_READ__),p=0;
			while (p<ts)
			{
				str[offset++] = space[p++];
			}
		}
		else
		{
			str[offset++] = text[i];
		}
	}
	return str;
}
/*
	int数字转换为字符串
*/
extern char *integerToString(int num)
{
	char *str = (char *)calloc(12, sizeof(char));
	if (str == NULL)
	{
		consoleLog("在转化为字符串时出现了无法申请内存的现象");
		return NULL;
	}
	int flag = 0;
	int count = 0;
	if (num < 0)
	{
		num *= -1;
		flag = 1;
	}
	do {
		str[count++] = num % 10 + 48;
		num /= 10;
	} while (num != 0);
	if (flag)
	{
		str[count++] = '-';
	}
	str[count] = '\0';
	return _strrev(str);
}
Esempio n. 5
0
bool UIConsole::executeCommand(const std::string& command_string) {

    consoleLog(command_string.c_str());

    size_t s = command_string.find(" ");

    std::string command_name;
    std::string command_args;

    if(s != std::string::npos) {
        command_name = command_string.substr(0, s);
        if(s != command_string.size()-1) {
            command_args = command_string.substr(s+1);
        }
   } else {
        command_name = command_string;
    }

    UIConsoleCommand* command = getCommand(command_name);

    if(!command) {
        errorLog("no such console command '%s'", command_name.c_str());
        return false;
    }

    return command->execute(command_args);
}
Esempio n. 6
0
void* quit(void* null)
{
	consoleLog("Disconnecting from server...\n");
	int cancel=pthread_cancel(ping_thread);
	packet p;
	p.IP_src=client_address.sin_addr;
	p.IP_dst=server_address.sin_addr;
	strcpy(p.login_src,user_login);
	strcpy(p.login_dst,SERVER_ADMIN_NAME);
	strcpy(p.data_type,CMD_TYPE);
	strcpy(p.data,QUIT_COMD);
	strcat(p.data,":");
	int sd=send_packet(socket_descriptor,&p);
	memset(&p,0,sizeof(packet));
	close(socket_descriptor);
	consoleLog("Client disconnected\n");
	STATE=False;
}
Esempio n. 7
0
void* get_clients_list(void* null)
{
	packet p;
	p.IP_src=client_address.sin_addr;
	p.IP_dst=server_address.sin_addr;
	strcpy(p.login_src,user_login);
	strcpy(p.login_dst,SERVER_ADMIN_NAME);
	strcpy(p.data_type,CMD_TYPE);
	strcpy(p.data,ASK_CLIENTS_LIST);
	strcat(p.data,":");
	int sd=send_packet(socket_descriptor,&p);
	memset(&p,0,sizeof(packet));
	if(!sd)
	{
		consoleLog("Getting clients list...\n");
	}
}
/*
	去掉字符串中的空格
*/
char * delspace(const char * text)
{
	size_t offset=0,i=0,len = strlen(text);
	char *newstr = (char *)calloc(len + 1, sizeof(char));
	if (newstr == NULL)
	{
		consoleLog("在清除空格时出现了无法申请内存的现象");
		return NULL;
	}
	for (i = 0; i < len; i++)
	{
		if (text[i]>=0 && text[i]<=32)
		{
			continue;
		}
		newstr[offset++] = text[i];
	}
	newstr[offset] = '\0';
	
	return newstr;
}
char * parseStringSpace(const char * text)
{
	if (text == NULL)
	{
		crashViewer("0x10000002", "接收数据时侦测到空指针错误");
		return NULL;
	}
	char *space = __SPACE__FILE_READ__;
	char *str = (char *)calloc(__BUFFSIZE__, sizeof(char));
	if (str == NULL)
	{
		consoleLog("在空格转化时出现了无法申请内存的现象");
		return NULL;
	}
	size_t i = 0;//text循环
	size_t j = 0;//str循环
	size_t lens = strlen(space), len = strlen(text);
	for (i = 0; i < len; i++)
	{
		size_t offset = 0, ioffset = i, joffset = j;
		while (text[ioffset++] == space[offset++] && offset<lens)
		{
			if (offset == lens - 1)
			{
				str[j++] = ' ';
				i += lens-1;
			}
		}
		if (offset != lens)
		{
			str[j++] = text[i];
		}
	}
	str[i] = '\0';
	return str;
}
Esempio n. 10
0
File: main.c Progetto: gocario/tvds
int main(void)
{
	gfxInitDefault();
	consoleInitDefault();

	Result ret;
	state = STATE_START;

	ret = FS_Init();
	if (R_FAILED(ret))
	{
		consoleLog("\nCouldn't initialize the FS module!\n");
		consoleLog("Have you selected a title?\n");
		consoleLog("Error code: 0x%lx\n", ret);
		// state = STATE_ERROR; // TODO: Remove out of Citra
	}

	ret = saveInit();
	if (R_FAILED(ret))
	{
		consoleLog("\nCouldn't initialize the Save module!\n");
		consoleLog("Error code: 0x%lx\n", ret);
		// state = STATE_ERROR; // TODO: Remove out of Citra
	}

	ret = saveGetTitleId(&titleid);
	if (R_FAILED(ret))
	{
		consoleLog("\nCouldn't get the title id of the game!\n");
		consoleLog("Error code: 0x%lx\n", ret);
		// state = STATE_ERROR; // TODO: Remove out of Citra
	}

	fsDirInit();
	fsBackInit(titleid);
	switchState(&state);
	consoleSelectNew(&consoleLog);

	drawHelp();

	u64 heldUp = 0;
	u64 heldDown = 0;
	u32 kDown, kHeld;
	while (aptMainLoop())
	{
		gspWaitForVBlank();
		hidScanInput();

		kDown = hidKeysDown();
		kHeld = hidKeysHeld();

		switch (state)
		{
			case STATE_BROWSE:
			{
				if (kDown & (KEY_LEFT | KEY_RIGHT))
				{
					fsDirSwitch(NULL);
					fsDirPrintSave();
					fsDirPrintSdmc();
				}

				if (kDown & KEY_ZL)
				{
					fsDirSwitch(&saveDir);
					fsDirPrintSave();
					fsDirPrintSdmc();
				}

				if (kDown & KEY_ZR)
				{
					fsDirSwitch(&sdmcDir);
					fsDirPrintSave();
					fsDirPrintSdmc();
				}

				if (kDown & KEY_UP)
				{
					fsDirMove(-1);
					fsDirPrintCurrent();
					heldUp = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_UP)
				{
					if (heldUp + HELD_TICK < svcGetSystemTick())
					{
						fsDirMove(-1);
						fsDirPrintCurrent();
						heldUp = svcGetSystemTick();
					}
				}
#endif

				if (kDown & KEY_DOWN)
				{
					fsDirMove(+1);
					fsDirPrintCurrent();
					heldDown = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_DOWN)
				{
					if (heldDown + HELD_TICK < svcGetSystemTick())
					{
						fsDirMove(+1);
						fsDirPrintCurrent();
						heldDown = svcGetSystemTick();
					}
				}
#endif

				if (kDown & KEY_A)
				{
					ret = fsDirGotoSubDir();
					consoleLog("   > fsDirGotoSubDir: %lx\n", ret);
					fsDirPrintCurrent();
				}

				if (kDown & KEY_B)
				{
					ret = fsDirGotoParentDir();
					consoleLog("   > fsDirGotoParentDir: %lx\n", ret);
					fsDirPrintCurrent();
				}

				if (kDown & KEY_X)
				{
					ret = fsDirDeleteCurrentEntry();
					consoleLog("   > fsDirDeleteCurrentEntry: %lx\n", ret);
					fsDirPrintCurrent();
				}

				if (kDown & KEY_Y)
				{
					ret = fsDirCopyCurrentEntry(false);
					consoleLog("   > fsDirCopyCurrentEntry: %lx\n", ret);
					fsDirPrintDick();
				}

				break;
			}
			case STATE_BACKUP:
			{
				if (kDown & KEY_A)
				{
					ret = fsBackImport();
					consoleLog("  > fsBackImport: %lx\n", ret);
					fsBackPrintSave();
				}

				if (kDown & KEY_B)
				{
					state = STATE_BACKUP_KEY;

					// TODO: setKeyboardString

					consoleSelectNew(&logConsole);
				}

				if (kDown & KEY_X)
				{
					ret = fsBackDelete();
					consoleLog("  > fsBackDelete: %lx\n", ret);
					fsBackPrintBackup();
				}

				if (kDown & KEY_Y)
				{
					ret = fsBackExport();
					consoleLog("  > fsBackExport: %lx\n", ret);
					fsBackPrintBackup();
				}

				if (kDown & KEY_UP)
				{
					fsBackMove(-1);
					fsBackPrintBackup();
					heldUp = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_UP)
				{
					if (heldUp + HELD_TICK < svcGetSystemTick())
					{
						fsBackMove(-1);
						fsBackPrintBackup();
						heldUp = svcGetSystemTick();
					}
				}
#endif

				if (kDown & KEY_DOWN)
				{
					fsBackMove(+1);
					fsBackPrintBackup();
					heldDown = svcGetSystemTick() + HELD_TICK * 2;
				}
#ifndef NO_HELD_TICK
				else if (kHeld & KEY_DOWN)
				{
					if (heldDown + HELD_TICK < svcGetSystemTick())
					{
						fsBackMove(+1);
						fsBackPrintBackup();
						heldDown = svcGetSystemTick();
					}
				}
#endif

				break;
			}
			case STATE_BACKUP_KEY:
			{
				// TODO: updateKeyboard

				if (kDown & KEY_A)
				{
					state = STATE_BACKUP;

					// TODO: getKeyboardString

					drawBackup();
				}

				if (kDown & KEY_B)
				{
					state = STATE_BACKUP;
					drawBackup();
				}

				break;
			}
			case STATE_ERROR:
			{
				consoleLog("\nAn error has occured...\n");
				consoleLog("Please check previous logs!\n");
				consoleLog("\nPress start to exit.\n");
				state = STATE_EOF;
				break;
			}
			default: break;
		}

		{
			if (kDown & KEY_L)
			{
				// TODO: Prev
				switchState(&state);
			}

			if (kDown & KEY_R)
			{
				// TODO: Next
				switchState(&state);
			}

			if (kDown & KEY_SELECT)
			{
				drawHelp();
			}
		}

		if (kDown & KEY_START)
			break;

		gfxFlushBuffers();
		gfxSwapBuffers();
	}

	fsDirExit();
	fsBackExit();
	FS_Exit();
	{
		hidScanInput();
		if (!(hidKeysHeld() & KEY_L) && !(hidKeysHeld() & KEY_R))
		{
			u8 out = 0;
			FS_MediaType mediaType = 3;
			FSUSER_GetMediaType(&mediaType);
			Result ret = saveRemoveSecureValue(titleid, mediaType, &out);
			if (R_FAILED(ret))
			{
				consoleSelect(&logConsole);
				printf("\nSecure value not removed.\n");
				printf("It might already be unitialized.\n");
				printf("Error code: 0x%lx (%i)\n", ret, out);
				printf("\n\nPress any key to exit.\n");
				waitKey(KEY_ANY);
			}
		}
	}
	gfxExit();
	return 0;
}
Esempio n. 11
0
int main(int argc, char* argv[])
{
	mos6502 cpu(MemoryRead, MemoryWrite);
	disasm dasm;
	int SPEED = 100; // %
	int CPUFREQ = 1000000; // Hz - CPU clock frequency
	bool HALT = false;
	// Todo optimize this string buffer size?
	char str[400];

	if (argc < 2)
	{
		std::cout << "Filename required!" << std::endl;
		return 0;
	}

	if (rom.loadFromFile(argv[1]) == 0)
	{
		std::cout << "Rom invalid!" << std::endl;
	}

	std::string caption("CBS6000 Emulator - (C)2015 Koen van Vliet");
	sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), caption);
	sf::RenderWindow dbgwindow(sf::VideoMode(DBGWINDOW_WIDTH, DBGWINDOW_HEIGHT), caption);
	sf::RenderWindow zpwindow(sf::VideoMode(ZPWINDOW_WIDTH, ZPWINDOW_HEIGHT), caption);
	window.setFramerateLimit(FPS);
	dbgwindow.setFramerateLimit(FPS);
	zpwindow.setFramerateLimit(FPS);

	if (!term.load("terminal8x16.png",8,16))
	{
		std::cout << "Failed to open bitmap font file!" << std::endl;
		return 0;
	}

	if (!dbgterm.load("terminal8x16.png",8,16))
	{
		std::cout << "Failed to open bitmap font file!" << std::endl;
		return 0;
	}

	if (!dasmterm.load("terminal8x16.png",8,16))
	{
		std::cout << "Failed to open bitmap font file!" << std::endl;
		return 0;
	}

	if (!regterm.load("terminal8x16.png",8,16))
	{
		std::cout << "Failed to open bitmap font file!" << std::endl;
		return 0;
	}

	if (!zpterm.load("terminal8x16.png",8,16))
	{
		std::cout << "Failed to open bitmap font file!" << std::endl;
		return 0;
	}

	int ctile = 177;
	term.setCursorTile(ctile);
	dbgterm.setCursorTile(ctile);
	dbgterm.enableCursor(false);
	dbgterm.setTextColor(sf::Color::Green);
	dasmterm.enableCursor(false);
	dasmterm.setTextColor(sf::Color::Cyan);
	regterm.enableCursor(false);
	regterm.setTextColor(sf::Color::White);
	zpterm.enableCursor(false);
	zpterm.setTextColor(sf::Color::White);

	consoleLog("---[Debug console]---");
	consoleLog(versionInfo);
	net.init();
	consoleLog("Starting CPU emulation");

	// Reset Cpu and internal IO port for the 6510
	Direction = 0x00;
	PortOut = 0x00;
	cpu.Reset();

	bool SHOWDASM = false;

	while(window.isOpen())
	{
		if (SPEED <= 20)
		{
			SHOWDASM = true;
		}

		sf::Event event;
		while (window.pollEvent(event))
		{
			switch (event.type) {
				case sf::Event::Closed :
					window.close();
					break;
				case sf::Event::TextEntered:
					if (event.text.unicode < 128)
					{
						char c = (char)event.text.unicode;
						term.feedChar(c);
					}
					break;
				case sf::Event::KeyPressed :
					// Increase and decrease the CPU speed
					if (event.key.code == sf::Keyboard::PageUp)
					{
						if (SPEED < 500)
						{
							SPEED += 5;
						}

						sprintf(str, "%d%% speed", SPEED);
						consoleLog(str);
					}
					if (event.key.code == sf::Keyboard::PageDown)
					{
						if (SPEED)
						{
							SPEED -= 5;
							if (SPEED < 0)
							{
								SPEED = 0;
							}
							sprintf(str, "%d%% speed", SPEED);
							consoleLog(str);
						}
					}

					// Stop execution
					if (event.key.code == sf::Keyboard::Delete)
					{
						HALT = true;
						SHOWDASM = true;
						consoleLog("F8 to continue, F5 to step");
					}

					// Stop/Resume execution
					if (event.key.code == sf::Keyboard::F8)
					{
						if (HALT)
						{
							HALT = false;
							consoleLog("Resumed execution...");
						}
						else
						{
							HALT = true;
							SHOWDASM = true;
							consoleLog("F8 to continue, F5 to step");
						}
					}
					// Execute single instruction
					if (event.key.code == sf::Keyboard::F5)
					{
						if (HALT)
						{
							cpu.Run(1);
							SHOWDASM = true;
						}
					}


					if (event.key.code == sf::Keyboard::End)
					{
						// Reset Cpu and internal IO port for the 6510
						Direction = 0x00;
						PortOut = 0x00;
						cpu.Reset();
						HALT = false;
						consoleLog("Reset CPU");
					}

					break;
				default:
					break;
			}
		}

		// Run a bunch of instructions
		if(!HALT)
		{
			int IPF = (CPUFREQ * SPEED) /(FPS * AVG_INSTRUCTION_CYCLES * 100); 			// Instructions per frame
			cpu.Run(IPF);
		}

		if (SHOWDASM)
		{
			// Show live disassembly of the memory
			SHOWDASM = false;
			// Todo fix pc
			uint16_t state[6];
			uint8_t buff[3];
			uint16_t pc;
			cpu.GetState(state);
			pc = state[3];
			for(int i = 0; i< 9; i++)
			{
				uint pc_prev = pc;
				dasmterm.printString("\r\n");
				buff[0] = MemoryRead(pc);
				buff[1] = MemoryRead(pc+1);
				buff[2] = MemoryRead(pc+2);
				pc += 1 + dasm.getDisassembly((char*)str, buff, 1, pc_prev);
				if(i ==0)
					dasmterm.printString(">");
				else
					dasmterm.printString(" ");
				dasmterm.printString(str);
			}

			// Display CPU register contents
			char charA = state[0], charX = state[1], charY = state[2];

			if (charA < ' ')
			{
				charA = ' ';
			}
			if (charX < ' ')
			{
				charX = ' ';
			}
			if (charY < ' ')
			{
				charY = ' ';
			}

			sprintf(str,"\r\n"
						"A:  $%02X  %03d \'%c\'\r\n"
						"X:  $%02X  %03d \'%c\'\r\n"
						"Y:  $%02X  %03d \'%c\'\r\n"
						"PC: $%04X\r\n"
						"SP: $%02X  %03d\r\n"
						"SR: $%02X, Z: %d, C: %d",
						state[0],
						state[0],
						charA,
						state[1],
						state[1],
						charX,
						state[2],
						state[2],
						charY,
						state[3],
						state[4],
						state[4],
						state[5],
						(state[5]>>1) & 1,
						state[5] & 1);
			regterm.printString(str);

			// Show zero page contents
			zpterm.setTextColor(sf::Color::Cyan);
			zpterm.printString("\r\n----: -0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F");
			zpterm.setTextColor(sf::Color::White);
			for(int i = 0; i < 16; i++)
			{
				uint8_t d;
				zpterm.printString("\r\n");
				sprintf(str, "%04X: ", (uint16_t)(i * 16));
				zpterm.printString(str);
				for(int j = 0; j < 16; j++)
				{
					d = MemoryRead(i*16 + j);
					if (j == 15)
						sprintf(str,"%02X",d);
					else
						sprintf(str,"%02X,",d);
					if(i*16 + j >= 0x5C && i*16+j < 0x5C+ 0x27)
						zpterm.setTextColor(sf::Color::Green);
					zpterm.printString(str);
					zpterm.setTextColor(sf::Color::White);
				}
				for(int j = 0; j < 16; j++)
				{
					d = MemoryRead(i*16 + j);
					if (d < ' ')
					{
						d = ' ';
					}
					if(i*16 + j >= 0x5C && i*16+j < 0x5C+ 0x27)
						zpterm.setTextColor(sf::Color::Green);
					zpterm.Write(d);
					zpterm.setTextColor(sf::Color::Blue);
					zpterm.Write(ctile);
					zpterm.setTextColor(sf::Color::White);
				}
				zpterm.setTextColor(sf::Color::Blue);
				for(int i = 0; i< 86; i++)
					zpterm.Write(177);
				zpterm.setTextColor(sf::Color::White);
			}
		}

		// Update the screen
		window.clear();
		dbgwindow.clear();
		zpwindow.clear();
		net.update();
		term.update();
		dbgterm.update();
		dasmterm.update();
		zpterm.update();
		regterm.update();
		window.draw(term);
		dbgwindow.draw(dbgterm);
		zpwindow.draw(zpterm);
		//if(HALT)
		//{
			dbgwindow.draw(dasmterm);
			dbgwindow.draw(regterm);
		//}
		window.display();
		dbgwindow.display();
		zpwindow.display();
	}
	return 0;
}
Esempio n. 12
0
 void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) {
   emit consoleLog(message, lineNumber, sourceID);
 }
Esempio n. 13
0
int processINFO(packet *p)
{
	consoleLog(p->data);
}
Esempio n. 14
0
void Blur_init(){
	blur=Blur_basic;
	sw=larger_pow2(screen->w);
	sh=larger_pow2(screen->h);
	
	GLint mx;
	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mx);
	
	consoleLog("Blur_init: required texture size is %dx%d\n", sw, sh);
	
	if(sw>mx || sh>mx){
		consoleLog("Blur_init: too big texture, disabling blur\n");
		blur=Blur_none;
		return;
	}
	
	consoleLog("Blur_init: allocating screen buffer\n");
	
	glGenTextures(1, &tex_screen);
	glBindTexture(GL_TEXTURE_2D, tex_screen);
#if GL_EXT_framebuffer_object
	if(use_hdr){
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, 
					 sw,sh, 0,
					 GL_RGB, GL_HALF_FLOAT_ARB, NULL);
	}else{
#endif
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 
					 sw,sh, 0,
					 GL_RGB, GL_UNSIGNED_BYTE, NULL);
#if GL_EXT_framebuffer_object
	}
#endif
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glClearColor(0.f, 0.f, 0.0f, 1.f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen->w, screen->h);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	clearTexture(sw, sh);
	
#if GL_ARB_shader_objects
#if GL_ARB_depth_texture
	
	if(cap_glsl){
		
		consoleLog("Blur_init: allocating depth buffer\n");
		
		glGenTextures(1, &tex_depth);
		glBindTexture(GL_TEXTURE_2D, tex_depth);
		int comp;
		GLint i;
		glGetIntegerv(GL_DEPTH_BITS, &i);
		switch(i){
			case 16:
				comp=GL_DEPTH_COMPONENT16_ARB;
				break;
			case 24:
				comp=GL_DEPTH_COMPONENT24_ARB;
				break;
			case 32:
				comp=GL_DEPTH_COMPONENT32_ARB;
				break;
			default:
				comp=GL_DEPTH_COMPONENT;
				break;
		}
		comp=GL_DEPTH_COMPONENT;
		if(use_hdr)
			comp=GL_DEPTH_COMPONENT24_ARB;
		
		glTexImage2D(GL_TEXTURE_2D, 0, comp, 
					 sw,sh, 0,
					 GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		
	}
#endif
#endif
	
#if GL_ARB_shader_objects
	
	if(cap_glsl){
	
		prg_blurSimple=create_program("res/shaders/blur1.vs", "res/shaders/blur1.fs");
		if(prg_blurSimple)
			consoleLog("Blur_init: compiled program \"blur1\"\n");
		else
			consoleLog("Blur_init: couldn't compile program \"blur1\"\n");
	
#if GL_ARB_depth_texture
		prg_blurDepth=create_program("res/shaders/blur2.vs", "res/shaders/blur2.fs");
		if(prg_blurDepth)
			consoleLog("Blur_init: compiled program \"blur2\"\n");
		else
			consoleLog("Blur_init: couldn't compile program \"blur2\"\n");
	
#endif
		
	}else{
		
#endif
	
		consoleLog("Blur_init: no programs to compile\n");
		
#if GL_ARB_shader_objects

	}
		
#endif
	
#if GL_ARB_shader_objects
	if(cap_glsl){
		blur=Blur_glsl_simple;
#if GL_ARB_depth_texture
		blur=Blur_glsl_depth;
#endif
	}
#endif

}
Esempio n. 15
0
void
H19::processCharacter(char ch)
{
    // mask off the high bit just in case, the real H19 would not have it set.
    ch &= 0x7f;

    if (mode_m == Normal)
    {
        switch (ch)
        {
            case ascii::NUL:
            case ascii::SOH:
            case ascii::STX:
            case ascii::ETX:
            case ascii::EOT:
            case ascii::ENQ:
            case ascii::ACK:
            case ascii::VT:
            case ascii::FF:
            case ascii::SO:
            case ascii::SI:
            case ascii::DLE:
            case ascii::DC1:
            case ascii::DC2:
            case ascii::DC3:
            case ascii::DC4:
            case ascii::NAK:
            case ascii::SYN:
            case ascii::ETB:
            case ascii::EM:
            case ascii::SUB:
            case ascii::FS:
            case ascii::GS:
            case ascii::RS:
            case ascii::US:
            case ascii::DEL:
                // From manual, these characters are not processed by the terminal
                break;

            case ascii::BEL: // Rings the bell.
                /// \todo - implement ringing bell.
                consoleLog("<BEL>");
                break;

            case ascii::BS: // Backspace
                consoleLog("<BS>");
                processBS();
                break;

            case ascii::HT: // Horizontal Tab
                consoleLog("<TAB>");
                processTAB();
                break;

            case ascii::LF: // Line Feed
                processLF();

                if (autoCR_m)
                {
                    processCR();
                }

                consoleLog("\n");
                break;

            case ascii::CR: // Carriage Return
                processCR();

                if (autoLF_m)
                {
                    processLF();
                }

                break;

            case ascii::CAN: // Cancel.
                break;

            case ascii::ESC: // Escape
                mode_m = Escape;
                consoleLog("<ESC>");
                break;

            default:
                // if Printable character display it.
#if CONSOLE_LOG
                fprintf(console_out, "%c", ch);
#endif
                displayCharacter(ch);
                break;
        }
    }
    else if (mode_m == Escape)
    {
        // Assume we go back to Normal, so only the few that don't need to set the mode.
        mode_m = Normal;

        switch (ch)
        {
            case ascii::CAN: // CAN - Cancel
                // return to Normal mode, already set.
                break;

            case ascii::ESC: // Escape
                // From the ROM listing, stay in this mode.
                mode_m = Escape;
                break;

            // Cursor Functions

            case 'H': // Cursor Home
                posX_m    = posY_m = 0;
                updated_m = true;
                break;

            case 'C': // Cursor Forward
                cursorForward();
                break;

            case 'D':        // Cursor Backward
                processBS(); // same processing as cursor backward
                break;

            case 'B': // Cursor Down
                cursorDown();
                break;

            case 'A': // Cursor Up
                cursorUp();
                break;

            case 'I': // Reverse Index
                reverseIndex();
                break;

            case 'n': // Cursor Position Report
                cursorPositionReport();
                break;

            case 'j': // Save cursor position
                saveCursorPosition();
                break;

            case 'k': // Restore cursor position
                restoreCursorPosition();
                break;

            case 'Y': // Direct Cursor Addressing
                mode_m = DCA_1;
                break;

            // Erase and Editing

            case 'E': // Clear Display
                clearDisplay();
                break;

            case 'b': // Erase Beginning of Display
                eraseBOD();
                break;

            case 'J': // Erase to End of Page
                eraseEOP();
                break;

            case 'l': // Erase entire Line
                eraseEL();
                break;

            case 'o': // Erase Beginning Of Line
                eraseBOL();
                break;

            case 'K': // Erase To End Of Line
                eraseEOL();
                break;

            case 'L': // Insert Line
                insertLine();
                break;

            case 'M': // Delete Line
                deleteLine();
                break;

            case 'N': // Delete Character
                deleteChar();
                break;

            case '@': // Enter Insert Character Mode
                insertMode_m = true;
                break;

            case 'O': // Exit Insert Character Mode
                insertMode_m = false;
                break;

            // Configuration

            case 'z': // Reset To Power-Up Configuration
                reset();
                break;

            case 'r': // Modify the Baud Rate
                /// \todo - determine if we should support this.
                debugss(ssH19, ERROR, "Error Unimplemented Modify Baud\n");
                break;

            case 'x': // Set Mode
                mode_m = SetMode;
                break;

            case 'y': // Reset Mode
                mode_m = ResetMode;
                break;

            case '<': // Enter ANSI Mode
                /// \todo - implement ANSI mode.
                // ROM - just sets the mode
                debugss(ssH19, ERROR, "Error Entering ANSI mode - unsupported\n");
                break;

            // Modes of operation

            case '[': // Enter Hold Screen Mode
                holdScreen_m = true;
                break;

            case '\\': // Exit Hold Screen Mode
                holdScreen_m = false;
                break;

            case 'p': // Enter Reverse Video Mode
                reverseVideo_m = true;
                break;

            case 'q': // Exit Reverse Video Mode
                reverseVideo_m = false;
                break;

            case 'F': // Enter Graphics Mode
                graphicMode_m = true;
                break;

            case 'G': // Exit Graphics Mode
                graphicMode_m = false;
                break;

            case 't': // Enter Keypad Shifted Mode
                keypadShifted_m = true;
                break;

            case 'u': // Exit Keypad Shifted Mode
                // ROM - just sets the mode
                keypadShifted_m = false;
                break;

            case '=': // Enter Alternate Keypad Mode
                // ROM - just sets the mode
                keypadShifted_m = true;
                break;

            case '>': // Exit Alternate Keypad Mode
                // ROM - just sets the mode
                keypadShifted_m = false;
                break;

            // Additional Functions

            case '}': // Keyboard Disable
                /// \todo - determine whether to do this.
                keyboardEnabled_m = false;
                break;

            case '{': // Keyboard Enable
                keyboardEnabled_m = true;
                break;

            case 'v': // Wrap Around at End Of Line
                wrapEOL_m = true;
                break;

            case 'w': // Discard At End Of Line
                wrapEOL_m = false;
                break;

            case 'Z': // Identify as VT52 (Data: ESC / K)
                debugss(ssH19, ERROR, "Identify request\n");
                sendData(ascii::ESC);
                sendData('/');
                sendData('K');
                break;

            case ']': // Transmit 25th Line
                transmitLine25();
                break;

            case '#': // Transmit Page
                transmitPage();
                break;

            default:
                debugss(ssH19, WARNING, "Unhandled ESC: %d\n", ch);
                /// \todo - verify this is how the H19 ROM does it.
                break;
        }
    }
    else if (mode_m == SetMode)
    {
        mode_m = Normal;

        switch (ch)
        {
            case '1': // Enable 25th line
                // From the ROM, it erases line 25 on the enable, but here we erase on the disable.
                line25_m = true;
                break;

            case '2': // No key click
                keyClick_m = true;
                break;

            case '3': // Hold screen mode
                holdScreen_m = true;
                break;

            case '4': // Block Cursor
                cursorBlock_m = true;
                updated_m     = true;
                break;

            case '5': // Cursor Off
                cursorOff_m = true;
                updated_m   = true;
                break;

            case '6': // Keypad Shifted
                keypadShifted_m = true;
                break;

            case '7': // Alternate Keypad mode
                altKeypadMode_m = true;
                break;

            case '8': // Auto LF
                autoLF_m = true;
                break;

            case '9': // Auto CR
                autoCR_m = true;
                break;

            default:
                /// \todo Need to process ch as if none of this happened...
                debugss(ssH19, WARNING, "Invalid set Mode: %c\n", ch);
                break;
        }
    }
    else if (mode_m == ResetMode)
    {
        mode_m = Normal;

        switch (ch)
        {
            case '1': // Disable 25th line
                eraseLine(rowsMain_c);
                line25_m  = false;
                updated_m = true;
                break;

            case '2': // key click
                keyClick_m = false;
                break;

            case '3': // Hold screen mode
                holdScreen_m = false;
                break;

            case '4': // Block Cursor
                cursorBlock_m = false;
                updated_m     = true;
                break;

            case '5': // Cursor On
                cursorOff_m = false;
                updated_m   = true;
                break;

            case '6': // Keypad Unshifted
                keypadShifted_m = false;
                break;

            case '7': // Exit Alternate Keypad mode
                altKeypadMode_m = false;
                break;

            case '8': // No Auto LF
                autoLF_m = false;
                break;

            case '9': // No Auto CR
                autoCR_m = false;
                break;

            default:
                /// \todo Need to process ch as if none of this happened...
                debugss(ssH19, WARNING, "Invalid reset Mode: %c\n", ch);
                break;
        }
    }
    else if (mode_m == DCA_1)
    {
        // From actual H19, once the line is specified, the cursor
        // immediately moves to that line, so no need to save the
        // position and wait for the entire command.
        /// \todo verify that this is the same on newer H19s.
        if (ch == ascii::CAN)
        {
            // cancel
            mode_m = Normal;
        }
        else
        {
            // \todo handle error conditions

            int pos = ch - 31;

            // verify valid Position
            if (((pos > 0) && (pos < (signed) rows_c)) || ((pos == (signed) rows_c) && (line25_m)))
            {
                posY_m = pos - 1;
            }
            else
            {
                /// \todo check to see how a real h19 handles this.
                debugss(ssH19, INFO, "DCA invalid Y: %d\n", pos);
            }

            mode_m = DCA_2;
        }
    }
    else if (mode_m == DCA_2)
    {
        if (ch == ascii::CAN)
        {
            // cancel
            mode_m = Normal;
        }
        else
        {
            int pos = ch - 31;

            if ((pos > 0) && (pos < 81))
            {
                posX_m = pos - 1;
            }
            else
            {
                posX_m = (cols_c - 1);
            }

            updated_m = true;
            mode_m    = Normal;
        }
    }
}
Esempio n. 16
0
int clientConnect(int argc, char **argv)
{
	hostent 	*ptr_client;			/* Client infos */
	hostent 	*ptr_host;				/* Host infos */
	char 		*prog;					/* Program Name */
	const char 	*hostc;					/* Server address char* */
	in_addr		host;					/* Server address */
	char 		login[LOGIN_SIZE];		/* User name */
	char 		pass[PASSWORD_MAX];		/* User password */
	int 		port;					/* Port of the remote machine */
	bool linked =		False;			/* If the linbk with server is etablished */
	int try =			1;				/* Number of connecting try */
	int try_Max =		MAX_CONNECTION_TRY;	/* Maximum of try to connect */
	int askCo =			0;				/* Result of the connection try */
	STATE =				False;			/* Set client status to disconnected */
	int errorN =		0;				/* Error numlber */
	struct timeval timeout;				/* Timeout for read and write */
	timeout.tv_sec =	RS_TIMEOUT;
	timeout.tv_usec =	0;
	
	if (argc < 5)
	{
		if(argc>0)
		{
			prog = argv[0];
		}
		else
		{
			prog = "client";
		}
		sprintf(logC,"%s <server_address> <server_port> <user_name> <user_password>\n",prog);
		consoleUsage(logC);
		memset(&logC,0,strlen(logC));
		exit(1);
	}
	
	prog = argv[0];
	hostc = argv[1];
	inet_aton(hostc, &host);
	
	port = atoi(argv[2]);
	strcpy(login,argv[3]);

	if (strlen(login) > (LOGIN_SIZE-1)){   // 'Cause of '\0'
		/* Error 13: Login size too long (17 char max) */
		consoleErrorLog(13);
		exit(1);
	}
	
	strcpy(pass,argv[4]);
	
	if (strlen(pass) > (PASSWORD_MAX-1) || strlen(pass) < (PASSWORD_MIN)){   // 'Cause of '\0'
  		/* Error 14: Password size incorrect (Between 7 and 19) */
		consoleErrorLog(14);
		exit(1);
	}

	int argN = 5;
	/* while(argN<argc)
	{
		char tmp[strlen(msg)+strlen(argv[argN])+1];
		strcpy(tmp,msg);
		strcat(tmp," ");
		strcat(tmp,argv[argN]);
		strcpy(msg,tmp);
		argN++;
	} */
	
	char machine[NAME_SIZE+1];
	
	gethostname(machine,NAME_SIZE);
	if((ptr_client = gethostbyname(machine)) == NULL)
	{
		consoleError("Can not find the machine address");
		return errno;
	}
	
	/* character by character copy of ptr_client informations to client address */
	bcopy((char*)ptr_client->h_addr, (char*)&client_address.sin_addr,ptr_client->h_length);
	client_address.sin_family = AF_INET;
	
	/* Use a new port number */
	client_address.sin_port = htons(port);
	
	if((ptr_host = gethostbyname(hostc)) == NULL)
	{
		consoleError("Can not find the server from its address");
		return errno;
	}
	
	/* character by character copy of ptr_host informations to local address */
	bcopy((char*)ptr_host->h_addr, (char*)&server_address.sin_addr,ptr_host->h_length);
	server_address.sin_family = AF_INET;
	
	/* Use a new port number */
	server_address.sin_port = htons(port);
	
	/* Creation of the socket */
	if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) <0){
		consoleError("Unable to create socket connection with the server");
		return errno;
	}
	
	if (setsockopt (socket_descriptor, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
				sizeof(timeout)) < 0)
	{
		consoleWarn("Set socket receive options failed\n");
	}

	if (setsockopt (socket_descriptor, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout,
				sizeof(timeout)) < 0)
	{
		consoleWarn("Set socket send options failed\n");
	}
	
	while(!STATE&&try<=try_Max)
	{
		/* Try to connect to the server with infos in server_address */
		if(!linked&&(connect(socket_descriptor, (sockaddr*)(&server_address), sizeof(sockaddr_in))) < 0)
		{
			consoleError("Unable to connect to server");
			errorN=errno;
		}
		else
		{
			if(!linked)
			{
				consoleLog("Connection established with the server\n");
				errorN=0;
			}
			linked=True;
			askCo=askConnection(server_address.sin_addr,login,pass,SERVER_ADMIN_NAME);
			if(askCo==0&&STATE)
			{
				try=0;
			}
			else
			{
				/* Server is full, we can try until someone disconnect */
				if(askCo==0)
				{
					try_Max=100;
				}
				else
				{
					// Wrong password || Login not allowed || Login already used
					if(askCo==3||askCo==2||askCo==1)
					{
						exit(0);
					}
					try_Max=MAX_CONNECTION_TRY;
				}
			}
		}
		if(!STATE)
		{
			sprintf(errorC,"Attempt (#%d) to connect to server failed [with error #%d]\n",try++,askCo);
			consoleError(errorC);
			memset(&errorC,0,strlen(errorC));
			if(askCo==14||askCo==22)
			{
				errorN=askCo;
				close(socket_descriptor);
				return clientConnect(argc,argv);
			}
			if(try<try_Max)
			{
				consoleLog("Retry to connect in 3 seconds...\n");
				sleep(3);
			}
		}
Esempio n. 17
0
int askConnection(in_addr host, char *login, char *pass, char *dst)
{
	packet 		p;						/* Packet */
	
	current_path.nb_elmt=0;				/* Size of path elmt */
	
	char msg[strlen(ASK_CONNECT)+1];
	strcpy(msg,ASK_CONNECT);
	strcpy(user_login,login);
	strcat(msg,":");
	consoleLog("Asking for connection in progress...\n");
	int sd=send_packet_to(host,login,dst,CMD_TYPE,msg);
	if(!sd)
	{
		consoleLog("Request sent to server\n");
	}
	else
	{
		consoleError("Request not sent to server");
	}
	int rd=read_packet(socket_descriptor,&p,False);
	if(rd!=0)
	{
		/* Connection reset by peer */
		if(rd==22||rd==14)
		{
			return rd;
		}
	}
	
	if(strcmp(p.data_type,CMD_TYPE))
	{
		return askConnection(host,login,pass,dst);
	}
	while(!STATE)
	{
		int comd=processCOMD(p.data,server_address,login);
		memset(&p,0,sizeof(packet));
		if(comd==0)
		{
			STATE=1;
			consoleLog("You are now connected to server\n");
			break;
		}
		else if(comd==-1)
		{
			// Send password
			char pw[strlen(SEND_PASSWORD)+2+strlen(pass)];
			strcpy(pw,SEND_PASSWORD);
			strcat(pw,":");
			strcat(pw,pass);
			sd=send_packet_to(host,login,dst,CMD_TYPE,pw);
			if(!sd)
			{
				consoleLog("Request sent to server\n");
			}
			else
			{
				consoleError("Request not sent to server");
			}
		}
		else
		{
			return comd;
		}
		int rd=read_packet(socket_descriptor,&p,False);
		if(rd!=0)
		{
			/* Connection reset by peer */
			if(rd==22||rd==14)
			{
				return rd;
			}
		}
	}
	return 0;
}
Esempio n. 18
0
void consoleLogN(int n) {
    char c[20];
    memset(c, 0, 20 * sizeof(char));
    sprintf(c, "%d", n);
    consoleLog(c);
}
Esempio n. 19
0
void Blur_apply(){
	
	if(multiSamples!=1 && blur==Blur_glsl_depth){
		consoleLog("Blur_apply: Blur_glsl_depth can't be used with multisample, disabling\n");
		blur=Blur_glsl_simple;
	}
	
	if(blur==Blur_none)
		return;
	
	float lastMatrix[16];
	glGetFloatv(GL_MODELVIEW_MATRIX, lastMatrix);
	
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glScalef(2.f/screen->w, -2.f/screen->h, 1.f);
	glTranslatef(-screen->w*.5f, -screen->h*.5f, 0.f);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_FOG);
	glDisable(GL_LIGHTING);
	glDepthMask(GL_FALSE);
	
	if(blur==Blur_basic){
		
		glColor4f(1.f, 1.f, 1.f, powf(.3f, blurdt*60.f));
		glBindTexture(GL_TEXTURE_2D, tex_screen);
		glBegin(GL_QUADS);
		glTexCoord2f(0.f, (float)screen->h/sh);
		glVertex2i(0, 0);
		glTexCoord2f(0.f, 0.f);
		glVertex2i(0, screen->h);
		glTexCoord2f((float)screen->w/sw, 0.f);
		glVertex2i(screen->w, screen->h);
		glTexCoord2f((float)screen->w/sw, (float)screen->h/sh);
		glVertex2i(screen->w, 0);
		glEnd();
		
		totalPolys+=2;
		
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen->w, screen->h);
	}
#if GL_ARB_shader_objects
	else if(blur==Blur_glsl_simple){
		glUseProgramObjectARB(prg_blurSimple);
		glUniform1iARB(glGetUniformLocationARB(prg_blurSimple, "screen"),
					   0);
		glUniform2fARB(glGetUniformLocationARB(prg_blurSimple, "texSize"),
					   (float)screen->w/sw, (float)screen->h/sh);
		float imat[16];
		float mat2[16];
		memcpy(imat, mx_old, sizeof(imat));
		inverseMatrix4(imat);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurSimple, "curMatrix"),
							  1, GL_FALSE, lastMatrix);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurSimple, "oldMatrix"),
							  1, GL_FALSE, mx_old);
		inverseMatrix4(lastMatrix);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurSimple, "oldMatrixInverse"),
					   1, GL_FALSE, imat);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurSimple, "curMatrixInverse"),
							  1, GL_FALSE, lastMatrix);
		glColor4f(1,1,1,1);
		glBindTexture(GL_TEXTURE_2D, tex_screen);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen->w, screen->h);
		glBegin(GL_QUADS);
		glTexCoord2f(-1.f, 1.f);
		glVertex2i(0, 0);
		glTexCoord2f(-1.f, -1.f);
		glVertex2i(0, screen->h);
		glTexCoord2f(1.f, -1.f);
		glVertex2i(screen->w, screen->h);
		glTexCoord2f(1.f, 1.f);
		glVertex2i(screen->w, 0);
		glEnd();
		totalPolys+=2;
		glUseProgramObjectARB(0);
	}
#if GL_ARB_depth_texture
	else if(blur==Blur_glsl_depth){
		
		glActiveTexture(GL_TEXTURE1_ARB);
		glBindTexture(GL_TEXTURE_2D, tex_depth);
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen->w, screen->h);
		glActiveTexture(GL_TEXTURE0_ARB);
		
		glUseProgramObjectARB(prg_blurDepth);
		glUniform1iARB(glGetUniformLocationARB(prg_blurDepth, "screen"),
					   0);
		glUniform1iARB(glGetUniformLocationARB(prg_blurDepth, "depthTex"),
					   1);
		glUniform2fARB(glGetUniformLocationARB(prg_blurDepth, "texSize"),
					   (float)screen->w/sw, (float)screen->h/sh);
		float imat[16];
		float mat2[16];
		memcpy(imat, mx_old, sizeof(imat));
		inverseMatrix4(imat);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurDepth, "curMatrix"),
							  1, GL_FALSE, lastMatrix);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurDepth, "oldMatrix"),
							  1, GL_FALSE, mx_old);
		inverseMatrix4(lastMatrix);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurDepth, "oldMatrixInverse"),
							  1, GL_FALSE, imat);
		glUniformMatrix4fvARB(glGetUniformLocationARB(prg_blurDepth, "curMatrixInverse"),
							  1, GL_FALSE, lastMatrix);
		glColor4f(1,1,1,1);
		glBindTexture(GL_TEXTURE_2D, tex_screen);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screen->w, screen->h);
		glBegin(GL_QUADS);
		glTexCoord2f(-1.f, 1.f);
		glVertex2i(0, 0);
		glTexCoord2f(-1.f, -1.f);
		glVertex2i(0, screen->h);
		glTexCoord2f(1.f, -1.f);
		glVertex2i(screen->w, screen->h);
		glTexCoord2f(1.f, 1.f);
		glVertex2i(screen->w, 0);
		glEnd();
		totalPolys+=2;
		glUseProgramObjectARB(0);
	}
#endif
#endif
	
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_LIGHTING);
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_FOG);
	glDepthMask(GL_TRUE);
	
}