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.

state.h 1.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_symtable_init(ASMSymbolTable**);
  61. void asm_lines_free(ASMLine*);
  62. void asm_includes_free(ASMInclude*);
  63. void asm_instructions_free(ASMInstruction*);
  64. void asm_symtable_free(ASMSymbolTable*);