ttinfo.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /******************************************************************************
  2. *
  3. * project name: TI-68k Developer Utilities
  4. * file name: ttchecksum.c
  5. * initial date: 21/08/2000
  6. * author: thomas.nussbaumer@gmx.net
  7. * description: prints infos about 89s/89y/9xs/9xy files
  8. *
  9. ******************************************************************************/
  10. /*
  11. This file is part of TI-68k Developer Utilities.
  12. This file is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU Lesser General Public
  14. License as published by the Free Software Foundation; either
  15. version 2.1 of the License, or (at your option) any later version.
  16. As a special exception, UNMODIFIED copies of ttinfo may also be
  17. redistributed or sold without source code, for any purpose. (The Lesser
  18. General Public License restrictions do apply in other respects; for example,
  19. they cover modification of the program.) This exception notice must be
  20. removed on modified copies of this file.
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Lesser General Public License for more details.
  25. You should have received a copy of the GNU Lesser General Public
  26. License along with this library; if not, write to the Free Software
  27. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include "ttversion.h"
  33. #include "revtools.h"
  34. #include "tt.h"
  35. #include "strhead.h"
  36. #ifdef FILE_REVISION
  37. #undef FILE_REVISION
  38. #endif
  39. #define FILE_REVISION "1.6"
  40. //=============================================================================
  41. // outputs usage information of this tool
  42. //=============================================================================
  43. void PrintUsage() {
  44. fprintf(USAGE_OUT, "Usage: ttinfo <infile>\n\n" \
  45. " prints infos about a 89z/89s/89y/9xz/9xs/9xy file\n");
  46. }
  47. //=============================================================================
  48. // ... it gets boring ...
  49. //=============================================================================
  50. int main(int argc,char *argv[]) {
  51. FILE* fp;
  52. long len;
  53. unsigned char ftype;
  54. unsigned char chk1;
  55. unsigned char chk2;
  56. unsigned int checksum;
  57. char tmp[100];
  58. unsigned long calcvar;
  59. StrHeader sh;
  60. PRINT_ID("TTInfo");
  61. if (argc !=2) {
  62. PrintUsage();
  63. return 1;
  64. }
  65. if (!(fp = fopen(argv[1],"rb"))) {
  66. fprintf(stderr,"ERROR: cannot open inputfile %s\n",argv[1]);
  67. return 1;
  68. }
  69. if (fread(&sh,sizeof(StrHeader),1,fp) != 1) {
  70. fprintf(stderr,"ERROR: file is too short\n");
  71. fclose(fp);
  72. return 1;
  73. }
  74. if (strncmp(sh.signature,"**TI",4)) {
  75. fprintf(stderr,"ERROR: file doesn't start with '**TI'\n");
  76. fclose(fp);
  77. return 1;
  78. }
  79. if (fseek(fp,-3,SEEK_END)) {
  80. fprintf(stderr,"ERROR: cannot seek to filetype\n");
  81. fclose(fp);
  82. return 1;
  83. }
  84. ftype = fgetc(fp);
  85. chk1 = fgetc(fp);
  86. chk2 = fgetc(fp);
  87. len = ftell(fp);
  88. checksum = (chk2 << 8) + chk1;
  89. if (ftype != 0x2d && ftype != 0xf8 && ftype != 0xf3) {
  90. fprintf(stderr,"ERROR: file neither of STR nor of OTH type\n");
  91. fclose(fp);
  92. return 1;
  93. }
  94. printf("filename: %s\n",argv[1]);
  95. printf("filesize: %ld bytes\n",len);
  96. printf("filetype: %s (0x%02x)\n",(ftype == 0x2D) ? "STR" : (ftype == 0xf8) ? "OTH" : "ASM",ftype);
  97. if (ftype == 0xf8) {
  98. int c1,c2,c3;
  99. fseek(fp,-7,SEEK_END);
  100. c1 = fgetc(fp);
  101. c2 = fgetc(fp);
  102. c3 = fgetc(fp);
  103. printf("extension: %c%c%c\n",c1,c2,c3);
  104. }
  105. strncpy(tmp,sh.signature,8);
  106. tmp[8] = 0;
  107. printf("signature: %s\n",tmp);
  108. strncpy(tmp,sh.folder,8);
  109. printf("folder: %s\n",tmp);
  110. strncpy(tmp,sh.name,8);
  111. printf("varname: %s\n",tmp);
  112. strncpy(tmp,sh.desc,40);
  113. tmp[40] = 0;
  114. printf("desc: %s\n",tmp);
  115. calcvar = sh.size[0];
  116. calcvar += (((unsigned long)sh.size[1]) << 8);
  117. calcvar += (((unsigned long)sh.size[2]) << 16);
  118. calcvar += (((unsigned long)sh.size[3]) << 24);
  119. printf("size: %lu (0x%02x%02x%02x%02x)\n",calcvar,sh.size[0],sh.size[1],sh.size[2],sh.size[3]);
  120. calcvar = sh.datasize[0] << 8;
  121. calcvar+= sh.datasize[1];
  122. printf("datasize: %lu (0x%02x%02x)\n",calcvar,sh.datasize[0],sh.datasize[1]);
  123. printf("checksum: %u (0x%02x%02x)\n\n",checksum,chk1,chk2);
  124. return 0;
  125. }
  126. //#############################################################################
  127. //###################### NO MORE FAKES BEYOND THIS LINE #######################
  128. //#############################################################################
  129. //
  130. //=============================================================================
  131. // Revision History
  132. //=============================================================================
  133. //
  134. // Revision 1.6 2009/01/25 Lionel Debroux
  135. // Changes by Romain Liévin and/or me for 64-bit compatibility.
  136. // Adapt to new version display (revtools.h).
  137. //
  138. // Revision 1.5 2002/02/07 09:49:37 tnussb
  139. // all local includes changed, because header files are now located in pctools folder
  140. //
  141. // Revision 1.4 2001/01/13 20:43:17 Thomas Nussbaumer
  142. // can operate now on 89z and 9xz files, too
  143. //
  144. // Revision 1.3 2000/11/28 00:06:33 Thomas Nussbaumer
  145. // using now USAGE_OUT stream for usage info
  146. //
  147. // Revision 1.2 2000/08/23 20:02:22 Thomas Nussbaumer
  148. // adapted to automatic version display (revtools.h)
  149. //
  150. // Revision 1.1 2000/08/21 17:12:27 Thomas Nussbaumer
  151. // initial version
  152. //
  153. //
  154. //
  155. //