An emulator, assembler, and disassembler for the Sega Game Gear
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

39 lines
1.5 KiB

  1. /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. Released under the terms of the MIT License. See LICENSE for details. */
  3. #pragma once
  4. #include <errno.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. /* Internal usage only */
  9. #define LOG_MSG(level, extra, after, ...) { \
  10. fprintf(stderr, level ": " __VA_ARGS__); \
  11. extra; \
  12. fprintf(stderr, "\n"); \
  13. after; \
  14. }
  15. #define PRINT_ERRNO() fprintf(stderr, ": %s", strerror(errno))
  16. /* Public logging macros */
  17. #define FATAL(...) LOG_MSG("Error", {}, exit(EXIT_FAILURE), __VA_ARGS__)
  18. #define FATAL_ERRNO(...) LOG_MSG("Error", PRINT_ERRNO(), exit(EXIT_FAILURE), __VA_ARGS__)
  19. #define ERROR(...) LOG_MSG("Error", {}, {}, __VA_ARGS__)
  20. #define ERROR_ERRNO(...) LOG_MSG("Error", PRINT_ERRNO(), {}, __VA_ARGS__)
  21. #define WARN(...) LOG_MSG("Warning", {}, {}, __VA_ARGS__)
  22. #define WARN_ERRNO(...) LOG_MSG("Warning", PRINT_ERRNO(), {}, __VA_ARGS__)
  23. #ifdef DEBUG_MODE
  24. #define DEBUG(...) LOG_MSG("[DEBUG]", {}, {}, __VA_ARGS__)
  25. #define DEBUG_ERRNO(...) LOG_MSG("[DEBUG]", PRINT_ERRNO(), {}, __VA_ARGS__)
  26. #else
  27. #define DEBUG(...) {}
  28. #define DEBUG_ERRNO(...) {}
  29. #endif
  30. #define OUT_OF_MEMORY() FATAL("couldn't allocate enough memory")