void* calcLoop(void* v)
{
	while(run)
	{
		gol->Step();
		sleepx(300);
	}
	return 0;
}
Пример #2
0
int main () {

	_textcolor (12);
	srand (time (0));
	int cell [2] [80];
	int switcher = 0;
	int line = 1;
	int sum;
	int i;
	char input;

	start:
	_clrscr ();
	switcher = 0;
	line = 1;

	for (i = 0; i < 80; ++i) {
		cell [0] [i] = 0;
		cell [1] [i] = 0;
	}

	_gotoxy (1, line);
	for (i = 0; i < 80; ++i) {
		cell [switcher] [i] = rand () % 2;
		
		if (cell [switcher] [i] == 1) {
			printf ("%c", OUTPUT);
		}
		else {
			printf (" ");
		}
	}

	while (1) {
		sleepx (500);

		switcher = !switcher;
		++line;
		_gotoxy (1, line);



		for (i = 0; i < 80; ++i) {
			sum = cell [!switcher] [(i-2) % 80] + cell [!switcher] [(i-1) % 80] + cell [!switcher] [(i+1) % 80] + cell [!switcher] [(i+2) % 80];

			if (sum == PLUS1 || sum == PLUS2) {
				cell [switcher] [i] = 1;
				printf ("%c", OUTPUT);
			}
			else {
				cell [switcher] [i] = 0;
				printf (" ");
			}
		}


		

		if (_kbhit()) {
			input = _getch ();

			if (input == ' ') 
				_getch ();

			else if (input == 27)
				break;

			else if (input == '\r')
				goto start;
		}
	}

	_getch ();
	return 0;
}
Пример #3
0
s32 nand_copy(const char *source, const char *destination,Nand_Permissions src_perm)
{
    //variables
    u8 *buffer = NULL;
    STACK_ALIGN(fstats,status,sizeof(fstats),32);
    s32 file_handler, ret;
    u32 FileHash_D1[5];
    memset(FileHash_D1,0,5);
    u32 FileHash_D2[5];
    memset(FileHash_D2,0xFF,5); //place different data in D2 so that if something goes wrong later on, the comparison will fail
    SHA1 sha;
    sha.Reset();

    //variables - temp dir & SHA1 check
    char temp_dest[ISFS_MAXPATH];
    memset(temp_dest,0,ISFS_MAXPATH);
    char *ptemp = NULL;
    u8 temp = 0;

    //get temp filename
    ptemp = strstr(destination,"/");
    while(ptemp != NULL && strstr(ptemp+1,"/") != NULL)
    {
        ptemp = strstr(ptemp+1,"/");
    }
    if(ptemp[0] == '/')
    {
        ptemp = ptemp+1;
    }
    memset(temp_dest,0,ISFS_MAXPATH);
    sprintf(temp_dest,"/tmp/%s",ptemp);

    //get data into pointer from original file
    file_handler = ISFS_Open(source,ISFS_OPEN_READ);
    if (file_handler < 0)
    {
        gprintf("failed to open source : %s\n",source);
        return file_handler;
    }

    ret = ISFS_GetFileStats(file_handler,status);
    if (ret < 0)
    {
        printf("\n\nFailed to get information about %s!\n",source);
        sleepx(2);
        ISFS_Close(file_handler);
        return ret;
    }

    buffer = (u8 *)memalign(32,ALIGN32(status->file_length));
    if (buffer == NULL)
    {
        gprintf("buffer failed to align\n");
        sleepx(2);
        ISFS_Close(file_handler);
        return 0;
    }
    memset(buffer,0,status->file_length);
    ret = ISFS_Read(file_handler,buffer,status->file_length);
    if (ret < 0)
    {
        printf("\n\nFailed to Read Data from %s!\n",source);
        sleepx(2);
        ISFS_Close(file_handler);
        free(buffer);
        buffer = NULL;
        return ret;
    }
    ISFS_Close(file_handler);
    //everything read into buffer. generate SHA1 hash of the buffer
    sha.Input(buffer,status->file_length);
    if (!sha.Result(FileHash_D1))
    {
        gprintf("could not compute Hash of D1!\n");
        free(buffer);
        buffer = NULL;
        return -80;
    }
    sha.Reset();
    //done, lets create temp file and write :')

    ISFS_Delete(temp_dest);
    ISFS_CreateFile(temp_dest,src_perm.attributes,src_perm.ownerperm,src_perm.groupperm,src_perm.otherperm);
    //created. opening it...
    file_handler = ISFS_Open(temp_dest,ISFS_OPEN_RW);
    if (file_handler < 0)
    {
        gprintf("failed to open destination : %s\n",temp_dest);
        ISFS_Delete(temp_dest);
        free(buffer);
        buffer = NULL;
        return file_handler;
    }
    ret = ISFS_Write(file_handler,buffer,status->file_length);
    if (ret < 0)
    {
        gprintf("failed to write destination : %s\n",destination);
        ISFS_Close(file_handler);
        ISFS_Delete(temp_dest);
        free(buffer);
        buffer = NULL;
        return ret;
    }
    //write done. reopen file for reading and compare SHA1 hash
    ISFS_Close(file_handler);
    free(buffer);
    buffer = NULL;
    memset(status,0,sizeof(fstats));
    file_handler = ISFS_Open(temp_dest,ISFS_OPEN_READ);
    if(!file_handler)
    {
        temp = -1;
        goto free_and_Return;
    }
    ret = ISFS_GetFileStats(file_handler,status);
    if (ret < 0)
    {
        ISFS_Close(file_handler);
        temp = -2;
        goto free_and_Return;
    }
    buffer = (u8 *)memalign(32,ALIGN32(status->file_length));
    if (buffer == NULL)
    {
        gprintf("buffer failed to align\n");
        ISFS_Close(file_handler);
        temp = -3;
        goto free_and_Return;
    }
    memset(buffer,0,status->file_length);
    if( ISFS_Read(file_handler,buffer,status->file_length) < 0 )
    {
        temp = -4;
        goto free_and_Return;
    }
    ISFS_Close(file_handler);
    sha.Reset();
    sha.Input(buffer,status->file_length);
    free(buffer);
    buffer = NULL;
    if (!sha.Result(FileHash_D2))
    {
        gprintf("could not compute Hash of D2!\n");
        return -80;
    }
    sha.Reset();
    /*gprintf("sha1 original : %x %x %x %x %x\nsha1 written : %x %x %x %x %x\n",
    																	  FileHash_D1[0],FileHash_D1[1],FileHash_D1[2],FileHash_D1[3],FileHash_D1[4],
    																	  FileHash_D2[0],FileHash_D2[1],FileHash_D2[2],FileHash_D2[3],FileHash_D2[4]);*/
    if (!memcmp(FileHash_D1,FileHash_D2,sizeof(FileHash_D1)))
    {
        gprintf("nand_copy : SHA1 hash success\n");
        ISFS_Delete(destination);
        ret = ISFS_Rename(temp_dest,destination);
        gprintf("ISFS_Rename ret %d\n",ret);
        if ( ret < 0)
            temp = -5;
        goto free_and_Return;
    }
    else
    {
        temp = -6;
        goto free_and_Return;
    }
free_and_Return:
    if(buffer)
    {
        free(buffer);
        buffer = NULL;
    }
    if (temp < 0)
    {
        gprintf("nand_copy temp %d fail o.o;\n",temp);
        ISFS_Delete(temp_dest);
        return -80;
    }
    return 1;
}