An emulator, assembler, and disassembler for the Sega Game Gear
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

102 satır
2.1 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. const ASMLine *line;
  46. struct ASMSymbol *next;
  47. };
  48. typedef struct ASMSymbol ASMSymbol;
  49. typedef struct {
  50. ASMSymbol *buckets[SYMBOL_TABLE_BUCKETS];
  51. } ASMSymbolTable;
  52. typedef struct {
  53. size_t offset;
  54. bool checksum;
  55. uint32_t product_code;
  56. uint8_t version;
  57. uint8_t region;
  58. uint8_t rom_size;
  59. } ASMHeaderInfo;
  60. typedef struct {
  61. ASMHeaderInfo header;
  62. bool optimizer;
  63. size_t rom_size;
  64. ASMLine *lines;
  65. ASMInclude *includes;
  66. ASMInstruction *instructions;
  67. ASMData *data;
  68. ASMSymbolTable *symtable;
  69. } AssemblerState;
  70. /* Functions */
  71. void state_init(AssemblerState*);
  72. void state_free(AssemblerState*);
  73. void asm_symtable_init(ASMSymbolTable**);
  74. void asm_lines_free(ASMLine*);
  75. void asm_includes_free(ASMInclude*);
  76. void asm_instructions_free(ASMInstruction*);
  77. void asm_data_free(ASMData*);
  78. void asm_symtable_free(ASMSymbolTable*);
  79. const ASMSymbol* asm_symtable_find(const ASMSymbolTable*, const char*);
  80. void asm_symtable_insert(ASMSymbolTable*, ASMSymbol*);
  81. #ifdef DEBUG_MODE
  82. void asm_lines_print(const ASMLine*);
  83. #endif