/****************************************************************************** Title: Timpy - Remote - MakeRomImageSum Comment: Tiny MP3 Player [ Timpy ] Rev4.x リモート用ツール EEPROMバイナリイメージのチェックサム生成 File Name: mkimgsum.c Version: 1.0 ( Oct 30, 2005 イニシャルリリース) Last Update: Oct. 30, 2005 Copyright(C) Chiaki Nakajima ******************************************************************************/ /* Include File(s) ***********************************************************/ #include #include /* Declaration(s) ************************************************************/ #ifndef NULL #define NULL ((void *)0) #endif /* Main **********************************************************************/ int main(int argc, char *argv[]) { unsigned char Sum; int Dat, CharCtr; long ImageByteCtr; FILE *fImage, *fSum; if (argc != 3) { fprintf(stderr, "Invalid arguments."); return EXIT_FAILURE; } if ((fSum = fopen(argv[2], "w")) == NULL) return EXIT_FAILURE; if ((fImage = fopen(argv[1], "rb")) == NULL) return EXIT_FAILURE; Sum = 0; CharCtr = 0; ImageByteCtr = 0L; while (EOF != (Dat = fgetc(fImage))) { Sum += (unsigned char)(Dat & 0xff); ++ImageByteCtr; if (0 == (ImageByteCtr % 256)) { fprintf(fSum, "%02X", Sum); Sum = 0; ++CharCtr; if (40 == CharCtr) { fprintf(fSum, "\n"); CharCtr = 0; } } } fprintf(stdout, "ImageByteCtr = %d", ImageByteCtr); fclose(fSum); fclose(fImage); return EXIT_SUCCESS; } /* End ***********************************************************************/