Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Base - Type [File] [Data].c
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgCM_File_Output_Header ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgCM_File_Output_Header( P_STg2_Output psOUT, CPC_STg2_File_Block psFileBlock )
{
    TgUINT32                            uiIndex;
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Section                ps;
    }                                   psSection;

    TgPARAM_CHECK(psOUT && psFileBlock);

    tgIO_PrintF( psOUT, TgT("File Header\n") );
    tgIO_PrintF( psOUT, TgT(" - FourCC: %d\n"), psFileBlock->m_uiFourCC );
    tgIO_PrintF( psOUT, TgT(" - Version: %d\n"), psFileBlock ->m_uiVersion );
    tgIO_PrintF( psOUT, TgT(" - Machine: %d\n"), psFileBlock ->m_uiMachine );
    tgIO_PrintF( psOUT, TgT(" - Flags: %d\n"), psFileBlock ->m_uiFlags );
    tgIO_PrintF( psOUT, TgT(" - Tools Version: %d\n"), psFileBlock ->m_uiTool_Version );
    tgIO_PrintF( psOUT, TgT(" - Tool Id: %d\n"), psFileBlock ->m_uiTool_ID );
    tgIO_PrintF( psOUT, TgT(" - Section Version: %d\n"), psFileBlock ->m_uiSection_Version );
    tgIO_PrintF( psOUT, TgT(" - Section Count: %d\n"), psFileBlock ->m_uiSection_Count );
    tgIO_PrintF( psOUT, TgT(" - Section Size: %d\n"), psFileBlock ->m_uiSection_Size );

    psSection.pui = (CP_TgUINT08)psFileBlock->m_asSection;
    for (uiIndex = 0; uiIndex < psFileBlock->m_uiSection_Count; ++uiIndex)
    {
        tgIO_PrintF( psOUT, TgT(" - Section (% 4d) FourCC: %d\n"), uiIndex, psSection.ps->m_uiFourCC );
        tgIO_PrintF( psOUT, TgT(" - Section (% 4d) Offset: %d\n"), uiIndex, psSection.ps->m_uiOffset );
        psSection.pui += psFileBlock->m_uiSection_Size;
    };
}


/* ---- tgCM_File_Output_Data_Headers ----------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgCM_File_Output_Data_Headers( P_STg2_Output psOUT, CPC_STg2_File_Block psFileBlock )
{
    TgUINT32                            uiIndex;
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Section                ps;
    }                                   psSection;
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Data                   ps;
    }                                   psData;

    TgPARAM_CHECK(psOUT && psFileBlock);

    psSection.pui = (CP_TgUINT08)psFileBlock->m_asSection;
    for (uiIndex = 0; uiIndex < psFileBlock->m_uiSection_Count; ++uiIndex)
    {
        psData.pui = (CP_TgUINT08)psFileBlock + psSection.ps->m_uiOffset;
        tgIO_PrintF( psOUT, TgT(" - Section Data (% 4d) FourCC: %d\n"), uiIndex, psData.ps->m_uiFourCC );
        tgIO_PrintF( psOUT, TgT(" - Section Data (% 4d) Offset: %d\n"), uiIndex, psData.ps->m_iOffset );
        tgIO_PrintF( psOUT, TgT(" - Section Data (% 4d) Size: %d\n"), uiIndex, psData.ps->m_uiSize );
        tgIO_PrintF( psOUT, TgT(" - Section Data (% 4d) Version: %d\n"), uiIndex, psData.ps->m_uiVersion );
        psSection.pui += psFileBlock->m_uiSection_Size;
    };
}


/* ---- tgCM_File_Query_Data -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL tgCM_File_Query_Data( TgVOID const **ppRet, CPC_STg2_File_Block psFileBlock, C_TgUINT32 uiBlockIndex )
{
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Section                ps;
    }                                   psSection;
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Data                   ps;
    }                                   psData;

    TgPARAM_CHECK(ppRet && psFileBlock);

    if (uiBlockIndex >= psFileBlock->m_uiSection_Count)
        return (TgFALSE);

    psSection.pui = (CP_TgUINT08)psFileBlock->m_asSection + uiBlockIndex * psFileBlock->m_uiSection_Size;
    psData.pui = (CP_TgUINT08)psFileBlock + psSection.ps->m_uiOffset;

    *ppRet = (CP_TgVOID)(psData.pui + psData.ps->m_iOffset);
    return (TgTRUE);
}


/* ---- tgCM_File_Query_Data_Size --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL tgCM_File_Query_Data_Size( P_TgSIZE puiSize, CPC_STg2_File_Block psFileBlock, C_TgUINT32 uiBlockIndex )
{
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Section                ps;
    }                                   psSection;
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Data                   ps;
    }                                   psData;

    TgPARAM_CHECK(puiSize && psFileBlock);

    if (uiBlockIndex >= psFileBlock->m_uiSection_Count)
        return (TgFALSE);

    psSection.pui = (CP_TgUINT08)psFileBlock->m_asSection + uiBlockIndex * psFileBlock->m_uiSection_Size;
    psData.pui = (CP_TgUINT08)psFileBlock + psSection.ps->m_uiOffset;

    *puiSize = psData.ps->m_uiSize;
    return (TgTRUE);
}


/* ---- tgCM_File_Query_Data_Count -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSIZE tgCM_File_Query_Data_Count( CPC_STg2_File_Block psFileBlock )
{
    TgPARAM_CHECK(psFileBlock);
    return (psFileBlock->m_uiSection_Count);
}


/* ---- tgCM_File_Check_Block_With_Assert ------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgCM_File_Check_Block_With_Assert( CPCU_STg2_File_Block psFileBlock )
{
    TgUINT32                            uiIndex;
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Section                ps;
    }                                   psSection;
    union
    {
        CP_TgUINT08                         pui;
        CP_STg2_File_Data                   ps;
    }                                   psData;

    TgPARAM_CHECK(psFileBlock);

    TgERROR(psFileBlock->m_uiSize == sizeof( STg2_File_Block ));
    TgERROR(psFileBlock->m_uiVersion > 0);
    TgERROR(psFileBlock->m_uiTool_Version > 0);
    TgERROR(psFileBlock->m_uiSection_Version > 0);
    TgERROR(psFileBlock->m_uiSection_Count > 0);
    TgERROR(psFileBlock->m_uiSection_Size == sizeof( STg2_File_Section ));

    psSection.pui = (CP_TgUINT08)psFileBlock->m_asSection;
    for (uiIndex = 0; uiIndex < psFileBlock->m_uiSection_Count; ++uiIndex)
    {
        psData.pui = (CP_TgUINT08)psFileBlock + psSection.ps->m_uiOffset;
        TgERROR(psSection.ps->m_uiFourCC == psData.ps->m_uiFourCC);
        TgERROR(psData.ps->m_iOffset > 0);
        TgERROR(psData.ps->m_uiSize > 0);
        TgERROR(psData.ps->m_uiVersion > 0);
        psSection.pui += psFileBlock->m_uiSection_Size;
    };
}