An emulator, assembler, and disassembler for the Sega Game Gear
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

105 行
2.2 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 <stdbool.h>
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include "../assembler.h"
  8. #define DEFAULT_HEADER_OFFSET 0x7FF0
  9. #define DEFAULT_REGION 6 // GG Export
  10. #define DEFAULT_DECLSIZE 0xC // 32 KB
  11. #define SYMBOL_TABLE_BUCKETS 128
  12. /* Structs */
  13. struct ASMLine {
  14. char *data;
  15. size_t length;
  16. const Line *original;
  17. const char *filename;
  18. struct ASMLine *next;
  19. };
  20. typedef struct ASMLine ASMLine;
  21. struct ASMInclude {
  22. LineBuffer *lines;
  23. struct ASMInclude *next;
  24. };
  25. typedef struct ASMInclude ASMInclude;
  26. typedef struct {
  27. size_t offset;
  28. size_t length;
  29. } ASMLocation;
  30. struct ASMInstruction {
  31. ASMLocation loc;
  32. uint8_t b1, b2, b3, b4;
  33. uint8_t virtual_byte;
  34. char *symbol;
  35. struct ASMInstruction *next;
  36. };
  37. typedef struct ASMInstruction ASMInstruction;
  38. struct ASMData {
  39. ASMLocation loc;
  40. uint8_t *data;
  41. struct ASMData *next;
  42. };
  43. typedef struct ASMData ASMData;
  44. struct ASMSymbol {
  45. size_t offset;
  46. char *symbol;
  47. const ASMLine *line;
  48. struct ASMSymbol *next;
  49. };
  50. typedef struct ASMSymbol ASMSymbol;
  51. typedef struct {
  52. ASMSymbol *buckets[SYMBOL_TABLE_BUCKETS];
  53. } ASMSymbolTable;
  54. typedef struct {
  55. size_t offset;
  56. bool checksum;
  57. uint32_t product_code;
  58. uint8_t version;
  59. uint8_t region;
  60. uint8_t rom_size;
  61. } ASMHeaderInfo;
  62. typedef struct {
  63. ASMHeaderInfo header;
  64. bool optimizer;
  65. size_t rom_size;
  66. ASMLine *lines;
  67. ASMInclude *includes;
  68. ASMInstruction *instructions;
  69. ASMData *data;
  70. ASMSymbolTable *symtable;
  71. } AssemblerState;
  72. /* Functions */
  73. void state_init(AssemblerState*);
  74. void state_free(AssemblerState*);
  75. void asm_symtable_init(ASMSymbolTable**);
  76. void asm_lines_free(ASMLine*);
  77. void asm_includes_free(ASMInclude*);
  78. void asm_instructions_free(ASMInstruction*);
  79. void asm_data_free(ASMData*);
  80. void asm_symtable_free(ASMSymbolTable*);
  81. const ASMSymbol* asm_symtable_find(const ASMSymbolTable*, const char*);
  82. void asm_symtable_insert(ASMSymbolTable*, ASMSymbol*);
  83. #ifdef DEBUG_MODE
  84. void asm_lines_print(const ASMLine*);
  85. #endif