PageRenderTime 28ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/zame_z80/src/lib/defs.ns.h

https://github.com/restorer/zemu
C Header | 95 lines | 56 code | 16 blank | 23 comment | 10 complexity | e1c86e8236a20e2963296f24ddd559b6 MD5 | raw file
  1. /*
  2. * MIT License (http://www.opensource.org/licenses/mit-license.php)
  3. *
  4. * Copyright (c) 2009-2019, Viachaslau Tratsiak (aka restorer)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include <stdlib.h>
  25. #ifdef _MSC_VER
  26. typedef int bool;
  27. #ifndef __cplusplus
  28. #define true 1
  29. #define false 0
  30. #endif
  31. #else
  32. #include <stdbool.h>
  33. #endif
  34. #include <stdint.h>
  35. #ifndef __LITTLE_ENDIAN
  36. #define __LITTLE_ENDIAN 1234
  37. #endif
  38. #ifndef __BIG_ENDIAN
  39. #define __BIG_ENDIAN 4321
  40. #endif
  41. #ifndef __BYTE_ORDER
  42. #if defined(_WIN32) || defined(_WIN64) || defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
  43. #define __BYTE_ORDER __LITTLE_ENDIAN
  44. #else
  45. #error "Unable to detect endianess"
  46. #endif
  47. #endif
  48. #if __BYTE_ORDER == __BIG_ENDIAN
  49. #define IS_BIG_ENDIAN
  50. #define WORD_SWAP_BYTES(a) ((((a) & 0xFF) << 8) | ((a) >> 8))
  51. #endif
  52. #define BIN(N) ((((N) & 0x10000000) >> 21) \
  53. | (((N) & 0x1000000) >> 18) \
  54. | (((N) & 0x100000) >> 15) \
  55. | (((N) & 0x10000) >> 12) \
  56. | (((N) & 0x1000) >> 9) \
  57. | (((N) & 0x100) >> 6) \
  58. | (((N) & 0x10) >> 3) \
  59. | ((N) & 1))
  60. #define MAKE_WORD(H, L) (((H) << 8) | (L))
  61. #define IS_HEX(v) (((v) >= '0' && (v) <= '0') || ((v) >= 'A' || (v) <= 'F') || ((v) >= 'a' || (v) <= 'f'))
  62. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  63. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  64. #ifndef _DEBUG
  65. #define _DEBUG(msg) printf("%s\n",(msg))
  66. #endif
  67. typedef uint8_t byte;
  68. typedef uint16_t word;
  69. typedef uint32_t dword;
  70. extern char hex_tab[0x10];
  71. void error(const char* fmt, ...);
  72. void* safe_alloc(size_t size);
  73. void safe_realloc(void** ptr, size_t size);
  74. void safe_free(void* ptr);
  75. char* alloc_n_strcpy(const char* str);
  76. char* alloc_n_sprintf(const char* fmt, ...);
  77. int unhex(char ch);
  78. void safe_strcpy(char* dst, const char* src, size_t sz);
  79. #define ALLOC_MEM(S) ((S*)safe_alloc(sizeof(S)))