An emulator, assembler, and disassembler for the Sega Game Gear
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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