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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 <string.h>
  5. #define DIRECTIVE_MARKER '.'
  6. #define NUM_DIRECTIVES 18
  7. #define DIR_INCLUDE ".include"
  8. #define DIR_ROM_SIZE ".rom_size"
  9. #define DIR_ROM_HEADER ".rom_header"
  10. #define DIR_ROM_CHECKSUM ".rom_checksum"
  11. #define DIR_ROM_PRODUCT ".rom_product"
  12. #define DIR_ROM_VERSION ".rom_version"
  13. #define DIR_ROM_REGION ".rom_region"
  14. #define DIR_ROM_DECLSIZE ".rom_declsize"
  15. #define DIR_CROSS_BLOCKS ".cross_blocks"
  16. #define DIR_DEFINE ".define"
  17. #define DIR_UNDEF ".undef"
  18. #define DIR_ORIGIN ".org"
  19. #define DIR_BLOCK ".block"
  20. #define DIR_BYTE ".byte"
  21. #define DIR_SPACE ".space"
  22. #define DIR_ASCII ".ascii"
  23. #define DIR_ASCIZ ".asciz"
  24. #define DIR_ASCIIZ ".asciiz"
  25. #define DIRECTIVE_HAS_ARG(line, d) ((line)->length > strlen(d))
  26. #define IS_DIRECTIVE(line, d) \
  27. (((line)->length >= strlen(d)) && \
  28. !strncmp((line)->data, d, strlen(d)) && \
  29. (!DIRECTIVE_HAS_ARG(line, d) || (line)->data[strlen(d)] == ' '))
  30. #define IS_LOCAL_DIRECTIVE(line) \
  31. (IS_DIRECTIVE(line, DIR_DEFINE) || IS_DIRECTIVE(line, DIR_UNDEF) || \
  32. IS_DIRECTIVE(line, DIR_ORIGIN) || IS_DIRECTIVE(line, DIR_BLOCK) || \
  33. IS_DIRECTIVE(line, DIR_BYTE) || IS_DIRECTIVE(line, DIR_SPACE) || \
  34. IS_DIRECTIVE(line, DIR_ASCII) || IS_DIRECTIVE(line, DIR_ASCIZ) || \
  35. IS_DIRECTIVE(line, DIR_ASCIIZ))
  36. #define DIRECTIVE_OFFSET(line, d) \
  37. (DIRECTIVE_HAS_ARG(line, d) ? strlen(d) : 0)
  38. #define DIRECTIVE_IS_AUTO(line, d) \
  39. (line->length - (DIRECTIVE_OFFSET(line, d) + 1) == 4 && \
  40. !strncmp(line->data + (DIRECTIVE_OFFSET(line, d) + 1), "auto", 4))