Add-in development tools for fx-9860G and fx-CG 50, to use with GCC and gint.
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.

fxg1a.h 5.8KB

  1. //---
  2. // fxg1a:fxg1a - Main interfaces
  3. //---
  4. #ifndef FX_FXG1A
  5. #define FX_FXG1A
  6. #include <stdlib.h>
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. #include <g1a.h>
  10. /*
  11. ** Header dumping (dump.c)
  12. */
  13. /* dump(): Print the detailed header fields of a g1a file
  14. This function takes as argument the full file loaded into memory and the
  15. size of the file. It does various printing to stdout as main job.
  16. @g1a Full file data
  17. @size Size of g1a file */
  18. void dump(struct g1a const *g1a, size_t size);
  19. /*
  20. ** Header manipulation (edit.c)
  21. */
  22. /* sign(): Sign header by filling fixed fields and checksums
  23. This function fills the fixed fields and various checksums of a g1a file. To
  24. do this it accesses some of the binary data. To set the user-customizable
  25. field, use the edit_*() functions. (The value of the customizable fields
  26. does not influence the checksums so it's okay to not call this function
  27. afterwards.)
  28. @g1a Header to sign
  29. @size Size of raw file data */
  30. void sign(struct g1a *g1a, size_t size);
  31. /* edit_*(): Set various fields of a g1a header */
  32. void edit_name (struct g1a *g1a, const char *name);
  33. void edit_internal (struct g1a *g1a, const char *internal);
  34. void edit_version (struct g1a *g1a, const char *version);
  35. void edit_date (struct g1a *g1a, const char *date);
  36. /* edit_icon(): Set monochrome icon of a g1a header
  37. The icon parameter must be loaded in 1-bit bitmap format. */
  38. void edit_icon(struct g1a *header, uint8_t const *mono);
  39. /*
  40. ** Utility functions (util.c)
  41. */
  42. /* checksum(): Sum of 8 big-endian shorts at 0x300
  43. Computes the third checksum by summing bytes from the data part of the file.
  44. @g1a Add-in file whose checksum is requested
  45. @size Size of file */
  46. uint16_t checksum(struct g1a const *g1a, size_t size);
  47. /* default_output(): Calculate default output file name
  48. This function computes a default file name by replacing the extension of
  49. @name (if it exists) or adding one. The extension is specified as a suffix,
  50. usually in the form ".ext".
  51. The resulting string might be as long as the length of @name plus that of
  52. @suffix (plus one NUL byte); the provided buffer must point to a suitably-
  53. large allocated space.
  54. @name Input file name
  55. @suffix Suffix to add or replace @name's extension with
  56. @output Output file name */
  57. void default_output(const char *name, const char *suffix, char *output);
  58. /*
  59. ** File manipulation (file.c)
  60. */
  61. /* load_g1a(): Load a g1a file into memory
  62. This function loads @filename into a dynamically-allocated buffer and
  63. returns the address of that buffer; it must be free()'d after use. When
  64. loading the file, if @size is not NULL, it receives the size of the file.
  65. On error, load() prints a message an stderr and returns NULL. The header
  66. is inverted before this function returns.
  67. @filename File to load
  68. @size If non-NULL, receives the file size
  69. Returns a pointer to a buffer with loaded data, or NULL on error. */
  70. struct g1a *load_g1a(const char *filename, size_t *size);
  71. /* load_binary(): Load a binary file into memory
  72. This function operates like load_g1a() but reserves space for an empty
  73. header. The header is initialized with all zeros.
  74. @filename File to load
  75. @size If non-NULL, receives the file size
  76. Returns a pointer to a buffer with loaded data, or NULL on error. */
  77. struct g1a *load_binary(const char *filename, size_t *size);
  78. /* save_g1a(): Save a g1a file to disk
  79. This functions creates @filename, then writes a g1a header and a chunk of
  80. raw data to it. Since it temporarily inverts the header to comply with
  81. Casio's obfuscated format, it needs write access to @g1a. Returns non-zero
  82. on error.
  83. @filename File to write (it will be overridden if it exists)
  84. @g1a G1A data to write
  85. @size Size of data
  86. Returns zero on success and a nonzero error code otherwise. */
  87. int save_g1a(const char *filename, struct g1a *g1a, size_t size);
  88. /*
  89. ** Icon management (icon.c)
  90. */
  91. /* icon_print(): Show a monochrome 30*17 icon on stdout
  92. The buffer should point to a 68-byte array. */
  93. void icon_print(uint8_t const *icon);
  94. /* icon_load(): Load a monochrome PNG image into an array
  95. This function loads a PNG image into a 1-bit buffer; each row is represented
  96. by a fixed number of bytes, each byte being 8 pixels. Rows are loaded from
  97. top to bottom, and from left to right.
  98. If the image is not a PNG image or a reading error occurs, this functions
  99. prints an error message on stderr and returns NULL.
  100. @filename PNG file to load
  101. @width If non-NULL, receives image width
  102. @height If non-NULL, receives image height
  103. Returns a pointer to a free()able buffer with loaded data, NULL on error. */
  104. uint8_t *icon_load(const char *filename, size_t *width, size_t *height);
  105. /* icon_save(): Save an 8-bit array to a PNG image
  106. Assumes 8-bit GRAY format.
  107. @filename Target filename
  108. @input An 8-bit GRAY image
  109. @width Width of input, should be equal to stride
  110. @height Height of input
  111. Returns non-zero on error. */
  112. int icon_save(const char *filename, uint8_t *input, size_t width,
  113. size_t height);
  114. /* icon_conv_8to1(): Convert an 8-bit icon to 1-bit
  115. The returned 1-bit icon is always of size 30*17, if the input size does not
  116. match it is adjusted.
  117. @input 8-bi data
  118. @width Width of input image
  119. @height Height of input image
  120. Returns a free()able buffer with a 1-bit icon on success, NULL on error. */
  121. uint8_t *icon_conv_8to1(uint8_t const *input, size_t width, size_t height);
  122. /* icon_conv_1to8(): Convert an 1-bit icon to 8-bit
  123. Input 1-bit is assumed to be 30*17 in size, this function returns an 8-bit
  124. buffer with the same dimensions.
  125. @mono Input monochrome icon (from a g1a header, for instance)
  126. Returns a free()able buffer, or NULL on error. */
  127. uint8_t *icon_conv_1to8(uint8_t const *mono);
  128. #endif /* FX_FXG1A */