macros.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Hey EMACS -*- linux-c -*- */
  2. /* $Id: macros.h 2450 2006-06-07 20:03:00Z roms $ */
  3. /* libtifiles - Ti File Format library, a part of the TiLP project
  4. * Copyright (C) 1999-2006 Romain Liévin
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #ifndef __TIEMU_MACROS__
  21. #define __TIEMU_MACROS__
  22. #include <stdint.h>
  23. // extract a word from a longword
  24. # define LSW(l) (uint16_t) ((l) & 0x0000FFFF)
  25. # define MSW(l) (uint16_t)(((l) & 0xFFFF0000) >> 16)
  26. // extract a byte from a word
  27. # define LSB(w) (uint8_t) ((w) & 0x00FF)
  28. # define MSB(w) (uint8_t)(((w) & 0xFF00) >> 8)
  29. // extract a nibble from a byte
  30. # define LSN(b) ((b) & 0x0F)
  31. # define MSN(b) (((b) & 0xF0) >> 4)
  32. // convert 2 nibbles into a BCD byte
  33. # define BCD(b) (10*MSN(b)+LSN(b))
  34. #endif