An emulator, assembler, and disassembler for the Sega Game Gear
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

107 lignes
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. bool is_label;
  19. struct ASMLine *next;
  20. };
  21. typedef struct ASMLine ASMLine;
  22. struct ASMInclude {
  23. LineBuffer *lines;
  24. struct ASMInclude *next;
  25. };
  26. typedef struct ASMInclude ASMInclude;
  27. typedef struct {
  28. size_t offset;
  29. size_t length;
  30. } ASMLocation;
  31. struct ASMInstruction {
  32. ASMLocation loc;
  33. uint8_t b1, b2, b3, b4;
  34. char *symbol;
  35. const ASMLine *line;
  36. struct ASMInstruction *next;
  37. };
  38. typedef struct ASMInstruction ASMInstruction;
  39. struct ASMData {
  40. ASMLocation loc;
  41. uint8_t *data;
  42. struct ASMData *next;
  43. };
  44. typedef struct ASMData ASMData;
  45. struct ASMSymbol {
  46. uint16_t offset;
  47. char *symbol;
  48. const ASMLine *line;
  49. struct ASMSymbol *next;
  50. };
  51. typedef struct ASMSymbol ASMSymbol;
  52. typedef struct {
  53. ASMSymbol *buckets[SYMBOL_TABLE_BUCKETS];
  54. } ASMSymbolTable;
  55. typedef struct {
  56. size_t offset;
  57. bool checksum;
  58. uint32_t product_code;
  59. uint8_t version;
  60. uint8_t region;
  61. uint8_t rom_size;
  62. } ASMHeaderInfo;
  63. typedef struct {
  64. ASMHeaderInfo header;
  65. bool optimizer;
  66. bool cross_blocks;
  67. size_t rom_size;
  68. ASMLine *lines;
  69. ASMInclude *includes;
  70. ASMInstruction *instructions;
  71. ASMData *data;
  72. ASMSymbolTable *symtable;
  73. } AssemblerState;
  74. /* Functions */
  75. void state_init(AssemblerState*);
  76. void state_free(AssemblerState*);
  77. void asm_symtable_init(ASMSymbolTable**);
  78. void asm_lines_free(ASMLine*);
  79. void asm_includes_free(ASMInclude*);
  80. void asm_instructions_free(ASMInstruction*);
  81. void asm_data_free(ASMData*);
  82. void asm_symtable_free(ASMSymbolTable*);
  83. const ASMSymbol* asm_symtable_find(const ASMSymbolTable*, const char*);
  84. void asm_symtable_insert(ASMSymbolTable*, ASMSymbol*);
  85. #ifdef DEBUG_MODE
  86. void asm_lines_print(const ASMLine*);
  87. #endif