Files
SyncHome/trunk/AVRProjects/sd2iec/src-1.0.0alpha0-98/src/utils.h
2023-03-13 09:01:12 +00:00

56 lines
1.7 KiB
C

/* sd2iec - SD/MMC to Commodore serial bus interface/controller
Copyright (C) 2007-2016 Ingo Korb <ingo@akana.de>
Inspired by MMC2IEC by Lars Pontoppidan et al.
FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
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; version 2 of the License only.
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
utils.c: Misc. utility functions that didn't fit elsewhere
*/
#ifndef UTILS_H
#define UTILS_H
/* Side-effect safe min/max */
#define max(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })
#define min(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a < _b ? _a : _b; })
/* Write a number to a string as ASCII */
uint8_t *appendnumber(uint8_t *msg, uint8_t value);
/* Convert between integer and BCD */
uint8_t bcd2int(uint8_t value);
uint8_t int2bcd(uint8_t value);
/* Tokenize a string like strtok_r, but with a single delimiter character only */
uint8_t *ustr1tok(uint8_t *str, const uint8_t delim, uint8_t **saveptr);
/* ASCII to PETSCII string conversion */
void asc2pet(uint8_t *buf);
// note: not moving pet2asc out of fatops saves 6 bytes on AVR
#endif