Files
V2TMUMemTester/Utils.h
chacha 1ff171316b .
2026-02-27 22:04:00 +00:00

97 lines
2.3 KiB
C

/* V2MemTest - A CLI Tool to test & fix Voodoo² TMU System
* Copyright (C) 2026 ChaCha
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _DEF_UTILS_H_
#define _DEF_UTILS_H_
#include <stdint.h>
#include "V2MemTest.h"
#define ErrorCheck() \
do{ \
if(Status < 0) \
{ \
if(Status <= E_INVALID_ERROR_CODE) \
fprintf(stderr,"Error detected at %s:%d\t%s", \
__FILE__,__LINE__,szErrorMsg[DEF_UNKNOWN_ERROR_IDX]); \
else \
fprintf(stderr,"Error detected at %s:%d\t%s", \
__FILE__,__LINE__, \
szErrorMsg[DEF_GET_ERROR_IDX(Status)]); \
return Status; \
} \
}while(0)
#define ErrorCheck_gotoCleanUp() \
do{ \
if(Status < 0) \
{ \
if(Status <= E_INVALID_ERROR_CODE) \
fprintf(stderr,"Error detected at %s:%d\t%s", \
__FILE__,__LINE__,szErrorMsg[DEF_UNKNOWN_ERROR_IDX]); \
else \
fprintf(stderr,"Error detected at %s:%d\t%s", \
__FILE__,__LINE__, \
szErrorMsg[DEF_GET_ERROR_IDX(Status)]); \
goto CleanUp; \
} \
}while(0)
static inline unsigned char
count_bit32(const uint32_t ulVal)
{
unsigned char cpt = 0;
for(uint32_t idxBit = 1<<31;idxBit>0;idxBit>>=1)
if(ulVal & idxBit)
cpt++;
return cpt;
}
static inline unsigned char
count_bit8(const uint8_t ulVal)
{
unsigned char cpt = 0;
for(uint8_t idxBit = 1<<7;idxBit>0;idxBit>>=1)
if(ulVal & idxBit)
cpt++;
return cpt;
}
void
printbin32( const uint32_t ulVal,
const unsigned char bGroupByBytes);
void
printbin32Info( const uint32_t ulVal,
const unsigned short uhb,
const unsigned short ulb);
uint32_t
get_notnull_random();
uint32_t
get_notnull_random_balanced();
uint8_t
get_notnull8_random_balanced();
uint32_t
get_notnull_random_balanced_mByte();
#endif //_DEF_UTILS_H_