utils.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* sd2snes - SD card based universal cartridge for the SNES
  2. Copyright (C) 2009-2010 Maximilian Rehkopf <otakon@gmx.net>
  3. This file was adapted from sd2iec, written by Ingo Korb.
  4. Original copyright header follows:
  5. */
  6. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  7. Copyright (C) 2007-2009 Ingo Korb <ingo@akana.de>
  8. Inspiration and low-level SD/MMC access based on code from MMC2IEC
  9. by Lars Pontoppidan et al., see sdcard.c|h and config.h.
  10. FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; version 2 of the License only.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. utils.c: Misc. utility functions that didn't fit elsewhere
  22. */
  23. #ifndef UTILS_H
  24. #define UTILS_H
  25. /* Side-effect safe min/max */
  26. #define max(a,b) \
  27. ({ typeof (a) _a = (a); \
  28. typeof (b) _b = (b); \
  29. _a > _b ? _a : _b; })
  30. #define min(a,b) \
  31. ({ typeof (a) _a = (a); \
  32. typeof (b) _b = (b); \
  33. _a < _b ? _a : _b; })
  34. /* Write a number to a string as ASCII */
  35. uint8_t *appendnumber(uint8_t *msg, uint8_t value);
  36. /* Convert between integer and BCD */
  37. uint8_t bcd2int(uint8_t value);
  38. uint8_t int2bcd(uint8_t value);
  39. /* Tokenize a string like strtok_r, but with a single delimiter character only */
  40. uint8_t *ustr1tok(uint8_t *str, const uint8_t delim, uint8_t **saveptr);
  41. #endif