ucon64_misc.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. ucon64_misc.h - miscellaneous functions for uCON64
  3. Copyright (c) 1999 - 2006 NoisyB
  4. Copyright (c) 2001 - 2004 dbjh
  5. Copyright (c) 2001 Caz
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef UCON64_MISC_H
  19. #define UCON64_MISC_H
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h" // USE_DISCMAGE
  22. #endif
  23. #ifdef _MSC_VER
  24. #pragma warning(push)
  25. #pragma warning(disable: 4820) // 'bytes' bytes padding added after construct 'member_name'
  26. #endif
  27. #include <time.h>
  28. #ifdef _MSC_VER
  29. #pragma warning(pop)
  30. #endif
  31. #include "misc/getopt2.h" // st_getopt2_t
  32. #include "misc/itypes.h"
  33. /*
  34. UCON64_DM_VERSION_MAJOR
  35. UCON64_DM_VERSION_MINOR
  36. UCON64_DM_VERSION_STEP min. version of libdiscmage supported by uCON64
  37. ucon64_load_discmage() load libdiscmage
  38. discmage_usage usage for libdiscmage
  39. discmage_gauge gauge wrapper for libdiscmage
  40. */
  41. #ifdef USE_DISCMAGE
  42. #include "libdiscmage/libdiscmage.h" // dm_image_t
  43. #define UCON64_DM_VERSION_MAJOR 0
  44. #define UCON64_DM_VERSION_MINOR 0
  45. #define UCON64_DM_VERSION_STEP 7
  46. extern const st_getopt2_t discmage_usage[];
  47. extern int ucon64_load_discmage (void);
  48. extern int discmage_gauge (int pos, int size);
  49. #endif
  50. /*
  51. usage of miscellaneous options
  52. */
  53. extern const st_getopt2_t ucon64_options_usage[];
  54. extern const st_getopt2_t ucon64_padding_usage[];
  55. /*
  56. uCON64 messages
  57. usage example: fprintf (stdout, ucon64_msg[WROTE], filename);
  58. */
  59. enum
  60. {
  61. PARPORT_ERROR = 0,
  62. CONSOLE_ERROR,
  63. WROTE,
  64. OPEN_READ_ERROR,
  65. OPEN_WRITE_ERROR,
  66. READ_ERROR,
  67. WRITE_ERROR,
  68. BUFFER_ERROR, // not enough memory
  69. ROM_BUFFER_ERROR,
  70. FILE_BUFFER_ERROR,
  71. DAT_NOT_FOUND,
  72. DAT_NOT_ENABLED,
  73. READ_CONFIG_FILE,
  74. NO_LIB
  75. };
  76. extern const char *ucon64_msg[];
  77. /*
  78. ucon64_file_handler() handles backups (before modifying the ROM) and ROMs
  79. inside archives. Read the comment at the header to
  80. see how it and the flags work
  81. remove_temp_file() remove possible temp file created by ucon64_file_handler()
  82. ucon64_output_fname()
  83. ucon64_gauge() wrapper for misc.c/gauge()
  84. ucon64_testpad() test if ROM is padded
  85. ucon64_testsplit() test if ROM is split
  86. optionally a callback function can be used for specific
  87. testing
  88. ucon64_configfile() configfile handling
  89. ucon64_rename() DAT or internal header based rename
  90. ucon64_e() emulator "frontend"
  91. ucon64_pattern() change file based on patterns specified in pattern_fname
  92. */
  93. #define OF_FORCE_BASENAME 1
  94. #define OF_FORCE_SUFFIX 2
  95. extern int ucon64_file_handler (char *dest, char *src, int flags);
  96. extern void remove_temp_file (void);
  97. extern char *ucon64_output_fname (char *requested_fname, int flags);
  98. extern int ucon64_gauge (time_t init_time, int pos, int size);
  99. extern int ucon64_testpad (const char *filename);
  100. extern int ucon64_testsplit (const char *filename, int (*testsplit_cb) (const char *));
  101. extern int ucon64_set_property_array (void);
  102. extern int ucon64_rename (int mode);
  103. extern int ucon64_e (void);
  104. extern int ucon64_pattern (const char *pattern_fname);
  105. /*
  106. Some general file stuff that MUST NOT and WILL NOT be written again and again
  107. ucon64_fread() same as fread but takes start and src is a filename
  108. ucon64_fwrite() same as fwrite but takes start and dest is a filename; mode
  109. is the same as fopen() modes
  110. ucon64_fgetc() same as fgetc but takes filename instead of FILE and a pos
  111. ucon64_fputc() same as fputc but takes filename instead of FILE and a pos
  112. buf,s,bs,b,f,m == buffer,start,blksize,blks,filename,mode
  113. ucon64_bswap16_n() bswap16() n bytes of buffer
  114. ucon64_fbswap16() bswap16() len bytes of file from start
  115. ucon64_fwswap32() wswap32() len bytes of file from start
  116. ucon64_dump() file oriented wrapper for memdump() (uses the same flags)
  117. ucon64_find() file oriented wrapper for memsearch() (uses the same flags)
  118. ucon64_chksum() file oriented wrapper for chksum()
  119. if (!sha1) {sha1 won't be calculated!}
  120. ucon64_filefile() compare two files for similarities or differencies
  121. */
  122. #define ucon64_fgetc(f, p) (quick_io_c(0, p, f, "rb"))
  123. #define ucon64_fputc(f, p, b, m) (quick_io_c(b, p, f, m))
  124. #define ucon64_fread(b, s, l, f) (quick_io(b, s, l, f, "rb"))
  125. #define ucon64_fwrite(b, s, l, f, m) (quick_io((void *) b, s, l, f, m))
  126. extern int ucon64_bswap16_n (void *buffer, int n);
  127. extern void ucon64_fbswap16 (const char *fname, size_t start, size_t len);
  128. extern void ucon64_fwswap32 (const char *fname, size_t start, size_t len);
  129. extern void ucon64_dump (FILE *output, const char *filename, size_t start,
  130. size_t len, uint32_t flags);
  131. // Be sure the following constant doesn't conflict with the MEMCMP2_* constants
  132. #define UCON64_FIND_QUIET (1 << 31)
  133. extern int ucon64_find (const char *filename, size_t start, size_t len,
  134. const char *search, int searchlen, uint32_t flags);
  135. extern int ucon64_chksum (char *sha1, char *md5, unsigned int *crc32, // uint16_t *crc16,
  136. const char *filename, int file_size, size_t start);
  137. extern void ucon64_filefile (const char *filename1, int start1,
  138. const char *filename2, int start2, int similar);
  139. #endif // #ifndef UCON64_MISC_H