コード例 #1
0
ファイル: memory.c プロジェクト: tonymagro/stroids3d
/* computes the hashed value of pointer */
static void hash_insert( void * ptr, unsigned int size, unsigned int line, const char * fname ) {

    hashnode_t * h;
    unsigned int hashpos;

    if( ptr == NULL ) {
        OS_Error( 1, "tried to hash null pointer\n" );
    }

    hashpos = HASH_PTR(ptr);

    // first time?
    if( MemHash[hashpos] == NULL ) {
        MemHash[hashpos] = malloc( sizeof( hashnode_t ) );
        if( MemHash[hashpos] == NULL  ) {
            OS_Error( 1, "out of memory!\n" );
        }
        MemHash[hashpos]->next = NULL;
        h = MemHash[hashpos];
    } else {

        h = MemHash[hashpos];

        /* collision */
        ++Collisions;

        // march down the linked list until the end.
        while( h->next != NULL ) {
            h = h->next;
        }

        // allocate a new node on the end.
        h->next = malloc( sizeof( hashnode_t ) );
        if( h->next == NULL ) {
            OS_Error( 1, "out of memory!\n" );
        }

        // move to node we just created
        h = h->next;

        // make sure this terminates the list.
        h->next = NULL;
    }

    h->pointer = (unsigned long long)ptr;
    h->line = line;
    h->size = size;
    strncpy( h->file, fname, MAX_MEM_FILE );

    TotalBytes += size;
    ++TotalAllocs;

}
コード例 #2
0
ファイル: memory.c プロジェクト: tonymagro/stroids3d
/* computes the hashed value of pointer */
static void hash_remove( void * ptr ) {

    int hashpos;
    hashnode_t *h, *prev = NULL;

    if( ptr == NULL ) {
        OS_Error( 1, "tried to free a null pointer\n" );
    }

    hashpos = HASH_PTR(ptr);

    h = MemHash[hashpos];

    if( h == NULL ) {
        // this is wrong -- trying to free a pointer that was
        // never hashed.
        OS_Error( 1, "tried to a free an unallocated pointer\n" );
        return;
    }

    while( h->pointer != (unsigned long long)ptr ) {
        if( h->next == NULL ) {
            // wrong again -- freeing a pointer never hashed
            OS_Error( 1, "tried to a free an unallocated pointer\n" );
            return;
        }
        prev = h;
        h = h->next;
    }

    // guaranteed to have the right one now.

    TotalBytes -= h->size;
    --TotalAllocs;

    free( (void *)(h->pointer) );

    // if was first in list..
    if( prev == NULL ) {
        prev = h;
        MemHash[hashpos] = h->next;
        free( h );
    } else {
        // works even in end case
        prev->next = h->next;
        free( h );
    }

}
コード例 #3
0
ファイル: rfu_uart.c プロジェクト: ShurfireSoftware/Simple
/*******************************************************************************
* Procedure:    tx_task
* Purpose:      Task that processes serial output for Nordic RF chip.
* Passed:
*   
* Returned:     nothing
* Globals:      none
*
* Date:         Author:             Comments:
*   2014-09-19  Neal Shurmantine    initial revision
*******************************************************************************/
void *tx_task(void * param)
{
    void *event_handle;
    uint32_t wait_time = WAIT_TIME_INFINITE;
    uint16_t event_mask = RF_SERIAL_TX_EVENT_BIT;
    uint16_t event_active;

//#define SERIAL_PORT_NAME  "/dev/ttyAMA0"
    if (setup_serial_port() == false) {
        OS_Error(OS_ERR_SERIAL_PORT);
    }
    
    event_handle = OS_EventCreate(0,false);
    TxMailbox = OS_MboxCreate(event_handle,RF_SERIAL_TX_EVENT_BIT);
printf("tx_task\n");
    while(1) {
        event_active = OS_TaskWaitEvents(event_handle, event_mask, wait_time);
        if (event_active == RF_SERIAL_TX_EVENT_BIT) {
            tx_msg_to_uart();
            //give a little space between stacked up messages
            event_mask = 0;
            wait_time = 20;
        }
        else {
            event_mask = RF_SERIAL_TX_EVENT_BIT;
            wait_time = WAIT_TIME_INFINITE;
       }
   }
}
コード例 #4
0
ファイル: memory.c プロジェクト: tonymagro/stroids3d
void * mem_allocate( unsigned int size, unsigned int line, const char * file ) {

    void * ret;

    ret = malloc( size );
    if( ret == NULL ) {
        OS_Error( 1, "out of memory in mem_malloc()\n" );
    }

    hash_insert( ret, size, line, file );

    return( ret );

}
コード例 #5
0
ファイル: buffer.c プロジェクト: tonymagro/stroids3d
void* Buf_GetSpace( buffer_t* buf, int length )
{
	void*	data;

	// See if buffers current size plus added data is too large for the buffer
	if( buf->currentsize + length > buf->maxsize )
	{
		if( !buf->allowoverflow )
			OS_Error( 1, "Buf_GetSpace - Fatal Buffer Overflow\n" );
		if( length > buf->maxsize )
			OS_Error( 1, "Buf_GetSpace - Length is Greater then Buffer Size\n" );

		printf( "Buf_GetSpace - Non-Fatal Buffer Overflow" );

		Buf_Clear( buf );

		buf->overflow = True;
	}

	data = buf->data + buf->currentsize;
	buf->currentsize += length;

	return data;
}
コード例 #6
0
ファイル: memory.c プロジェクト: tonymagro/stroids3d
void * mem_reallocate( void * ptr, unsigned int size, unsigned int line, const char * file ) {

    hashnode_t * h;
    void * ret;

    if( (h = hash_lookup( ptr )) == NULL ) {
        OS_Error( 1, "mem_realloc() with unallocated pointer" );
    }

    ret = mem_allocate( size, line, file );

    memcpy( ret, ptr, size <= h->size ? size : h->size );
    mem_free( ptr );

    return( ret );

}
コード例 #7
0
ファイル: os_sdl.c プロジェクト: tonymagro/stroids3d
/* Main Entry into program */
int main( int argc, char **argv )
{
	int				time, oldtime, newtime;

	/* whether or not the window is active */
    int isActive = True;
	/* main loop variable */
    int done = False;
	/* used to collect events */
    SDL_Event event;
	/* Flags to pass to SDL_SetVideoMode */
	int initFlags;

	/* Timing */
	int thisframe = 0;
	static int lastframe = 0;

	/* check endian */
    if( Swap_SysBigEndian() )
		printf( "System Byte Order: Big Endian\n" );
    else
		printf( "System Byte Order: Little Endian\n" );

	

	window_created = False;

	vidinfo.height		=  DEFAULT_VIEWPORT_WIDTH;
	vidinfo.width		=  DEFAULT_VIEWPORT_HEIGHT;
	vidinfo.bpp			=  DEFAULT_VIEWPORT_BPP;

	
	vidinfo.fullscreen	=  DEFAULT_VIEWPORT_FULLSCREEN;
	vidinfo.mode		=  DEFAULT_VIDMODE;

	initFlags = SDL_INIT_VIDEO;

	if( JOYSTICK_SUPPORT )
		initFlags |= SDL_INIT_JOYSTICK;

    /* initialize SDL */
    if ( SDL_Init( initFlags ) < 0 )
	{
	    fprintf( stderr, "Video initialization failed: %s\n",
		     SDL_GetError( ) );
	    OS_Error( 1, va("Video initialization failed: %s\n",
		     SDL_GetError()) );
	}

	OS_SetVidMode( vidinfo.mode, vidinfo.fullscreen );

	/* Name our Window */
	SDL_WM_SetCaption( S_VERSION, 0 );

		/* set up keyboard delay */
	//SDL_EnableKeyRepeat( 0, 0 );


	/* Hide cursor and grab input */
	SDL_ShowCursor(0);
	SDL_WM_GrabInput(SDL_GRAB_ON);
	SDL_WarpMouse( (unsigned short)(vidinfo.width/2), (unsigned short)(vidinfo.height/2) );
	
	Main_Init();

	oldtime = OS_Milliseconds ();

    /* wait for events */
    while ( !done )
	{
		thisframe = OS_Milliseconds();

	    /* handle the events in the queue */
	    while ( SDL_PollEvent( &event ) )
		{
		    switch( event.type )
			{
			case SDL_ACTIVEEVENT:
			    /* Something's happend with our focus
			     * If we lost focus or we are iconified, we
			     * shouldn't draw the screen
			     */
/*			    if ( event.active.gain == 0 )
				isActive = FALSE;
			    else
				isActive = True;
*/			    break;
				/*
			case SDL_VIDEORESIZE:
			    // handle resize event 
			    surface = SDL_SetVideoMode( event.resize.w,
							event.resize.h,
							VIEWPORT_BPP, videoFlags );
			    if ( !surface )
				{
				    fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) );
					G_Shutdown();
				    OS_Quit( 1 );
				}
			    Ren_WindowSize( event.resize.w, event.resize.h );
			    break;
				*/
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				OS_HandleKeyEvent( &event.key );
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				OS_HandleMouseButton( &event.button );
				break;
		//	case SDL_JOYAXISMOTION:
		//		OS_HandleJoyMotion( &event.jaxis );
		//		break;
			case SDL_JOYBUTTONDOWN:
			case SDL_JOYBUTTONUP:
				OS_HandleJoyButton( &event.jbutton );
				break;
			case SDL_QUIT:
			    /* handle quit requests */
			    done = True;
			    break;
			default:
			    break;
			}
		}

		do
		{
			newtime = OS_Milliseconds ();
			time = newtime - oldtime;
		} while (time < 1);

		Main_Frame(time);
		
	}

    /* clean ourselves up and exit */
    OS_Quit( 0 );

    /* Should never get here */
    return( 0 );

}
コード例 #8
0
ファイル: os_sdl.c プロジェクト: tonymagro/stroids3d
sboolean OS_CreateWindow( int width, int height, int bpp, sboolean fullscreen )
{
	// Video Init Flags
	int videoFlags;
    /* this holds some info about our display */
    const SDL_VideoInfo *videoInfo;

	if( window_created )
	{
		//SDL_QuitSubSystem( SDL_INIT_VIDEO );
		//SDL_FreeSurface( surface );
		//surface = NULL;
		//SDL_InitSubSystem( SDL_INIT_VIDEO );
	}


    /* Fetch the video info */
    videoInfo = SDL_GetVideoInfo( );

    if ( !videoInfo )
    {
        fprintf( stderr, "Video query failed: %s\n",
		     SDL_GetError( ) );
        OS_Error( 1, va("Video query failed: %s\n",
		     SDL_GetError()) );
    }

    /* the flags to pass to SDL_SetVideoMode */
    videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
    videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
    videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
    //videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */

    if( fullscreen )
        videoFlags |= SDL_FULLSCREEN;

    /* This checks to see if surfaces can be stored in memory */
    if ( videoInfo->hw_available )
	videoFlags |= SDL_HWSURFACE;
    else
	videoFlags |= SDL_SWSURFACE;

    /* This checks if hardware blits can be done */
    if ( videoInfo->blit_hw )
	videoFlags |= SDL_HWACCEL;

    /* Sets up OpenGL double buffering */
    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

    /* get a SDL surface */
    surface = SDL_SetVideoMode( width, height, bpp, videoFlags );

    /* Verify there is a surface */
    if ( !surface )
	{
	    fprintf( stderr,  "Video mode set failed: %s\n", SDL_GetError( ) );
		if( window_created )
			return False;
		else
			OS_Error( 1 , va("Video mode set failed: %s\n", SDL_GetError()));
	}
	
	
	Ren_WindowSize( width, height );

    window_created = True;

    return True;

}