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.
 
 
 
 
 

78 lines
1.5 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 SYMBOL_TABLE_BUCKETS 128
  9. /* Structs */
  10. struct ASMLine {
  11. char *data;
  12. size_t length;
  13. const Line *original;
  14. const char *filename;
  15. struct ASMLine *next;
  16. };
  17. typedef struct ASMLine ASMLine;
  18. struct ASMInclude {
  19. LineBuffer *lines;
  20. struct ASMInclude *next;
  21. };
  22. typedef struct ASMInclude ASMInclude;
  23. struct ASMInstruction {
  24. size_t offset;
  25. uint8_t length;
  26. uint8_t b1, b2, b3, b4;
  27. uint8_t virtual_byte;
  28. char *symbol;
  29. struct ASMInstruction *next;
  30. };
  31. typedef struct ASMInstruction ASMInstruction;
  32. struct ASMSymbol {
  33. size_t offset;
  34. char *symbol;
  35. struct ASMSymbol *next;
  36. };
  37. typedef struct ASMSymbol ASMSymbol;
  38. typedef struct {
  39. ASMSymbol *buckets[SYMBOL_TABLE_BUCKETS];
  40. } ASMSymbolTable;
  41. typedef struct {
  42. size_t offset;
  43. bool checksum;
  44. uint32_t product_code;
  45. uint8_t version;
  46. uint8_t region;
  47. uint8_t rom_size;
  48. } ASMHeaderInfo;
  49. typedef struct {
  50. ASMHeaderInfo header;
  51. bool optimizer;
  52. size_t rom_size;
  53. ASMLine *lines;
  54. ASMInclude *includes;
  55. ASMInstruction *instructions;
  56. ASMSymbolTable *symtable;
  57. } AssemblerState;
  58. /* Functions */
  59. void state_init(AssemblerState*);
  60. void asm_lines_free(ASMLine*);
  61. void asm_includes_free(ASMInclude*);
  62. void asm_instructions_free(ASMInstruction*);
  63. void asm_symtable_free(ASMSymbolTable*);