utils.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _UTILS_H_
  4. #define _UTILS_H_
  5. #ifndef _CBASETYPES_H_
  6. #include "../common/cbasetypes.h"
  7. #endif
  8. #include <stdio.h> // FILE*
  9. // generate a hex dump of the first 'length' bytes of 'buffer'
  10. void WriteDump(FILE* fp, const void* buffer, size_t length);
  11. void ShowDump(const void* buffer, size_t length);
  12. void findfile(const char *p, const char *pat, void (func)(const char*));
  13. bool exists(const char* filename);
  14. //Caps values to min/max
  15. #define cap_value(a, min, max) ((a >= max) ? max : (a <= min) ? min : a)
  16. /// calculates the value of A / B, in percent (rounded down)
  17. unsigned int get_percentage(const unsigned int A, const unsigned int B);
  18. //////////////////////////////////////////////////////////////////////////
  19. // byte word dword access [Shinomori]
  20. //////////////////////////////////////////////////////////////////////////
  21. extern uint8 GetByte(uint32 val, int idx);
  22. extern uint16 GetWord(uint32 val, int idx);
  23. extern uint16 MakeWord(uint8 byte0, uint8 byte1);
  24. extern uint32 MakeDWord(uint16 word0, uint16 word1);
  25. #endif /* _UTILS_H_ */