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.

edit.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <fxg1a.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <endianness.h>
  5. /* sign(): Sign header by filling fixed fields and checksums */
  6. void sign(struct g1a *g1a, size_t size)
  7. {
  8. struct header *header = &g1a->header;
  9. /* Fixed elements */
  10. memcpy(header->magic, "USBPower", 8);
  11. header->mcs_type = 0xf3;
  12. memcpy(header->seq1, "\x00\x10\x00\x10\x00", 5);
  13. header->seq2 = 0x01;
  14. header->filesize_be1 = htobe32(size);
  15. header->filesize_be2 = htobe32(size);
  16. /* Control bytes and checksums */
  17. header->control1 = size + 0x41;
  18. header->control2 = size + 0xb8;
  19. header->checksum = htobe16(checksum(g1a, size));
  20. }
  21. /* edit_name(): Set application name */
  22. void edit_name(struct g1a *g1a, const char *name)
  23. {
  24. memset(g1a->header.name, 0, 8);
  25. if(!name) return;
  26. for(int i = 0; name[i] && i < 8; i++)
  27. g1a->header.name[i] = name[i];
  28. }
  29. /* edit_internal(): Set internal name */
  30. void edit_internal(struct g1a *g1a, const char *internal)
  31. {
  32. memset(g1a->header.internal, 0, 8);
  33. if(!internal) return;
  34. for(int i = 0; internal[i] && i < 8; i++)
  35. g1a->header.internal[i] = internal[i];
  36. }
  37. /* edit_version(): Set version string */
  38. void edit_version(struct g1a *g1a, const char *version)
  39. {
  40. memset(g1a->header.version, 0, 10);
  41. if(!version) return;
  42. for(int i = 0; version[i] && i < 10; i++)
  43. g1a->header.version[i] = version[i];
  44. }
  45. /* edit_date(): Set build date */
  46. void edit_date(struct g1a *g1a, const char *date)
  47. {
  48. memset(g1a->header.date, 0, 14);
  49. if(!date) return;
  50. for(int i = 0; date[i] && i < 14; i++)
  51. g1a->header.date[i] = date[i];
  52. }
  53. /* edit_icon(): Set icon from monochrome bitmap */
  54. void edit_icon(struct g1a *g1a, uint8_t const *mono)
  55. {
  56. memcpy(g1a->header.icon, mono, 68);
  57. }