Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://stackoverflow.com/questions/16479006/can-i-use-fgetc-or-fputc-in-a-binary-file
- //Tue May 5 11:39:35 NZST 2020. Now want to chop 1802 bin file into lower and upper parts. 0-$400 and $4000-endoffile
- //Wed May 6 15:55:34 NZST 2020. Looking at command linelist of files.
- #include<stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void ttest1(void);
- int fileIsReal(char* );
- int exists(const char *fname);
- int k;
- char str1[32] ;
- int main( int argc, char *argv[])
- { k=argc;
- strcpy(str1, argv[1]); //copies argv[1] into str1. May be useful.
- printf("Argc is %d.\n",argc);
- if( argc == 3 ) {
- printf("The first argument supplied is file %s. ", argv[1]);
- printf(" Its length is %d, ",strlen(argv[1]));
- char c1 = argv[1][strlen(argv[1])-1];
- printf("and the last character is '%c'. \n" , c1) ; //argv[1][strlen(argv[1])-1]);
- //if(c1!='x') system ("Notepad.exe");
- printf("The second argument supplied is file %s. ", argv[2]);
- printf(" Its length is %d, ",strlen(argv[2]));
- char c2 = argv[2][strlen(argv[2])-1];
- printf("and the last character is '%c'. \n" , c2) ; //argv[1][strlen(argv[1])-1]);
- }
- else if( argc > 3 ) {
- printf("Too many arguments supplied.\n");
- exit(4);
- }
- else {
- printf("Two arguments expected.\n");
- exit(5);
- }
- /*printf("Argc is %d, ",argc);
- printf("argv[1] is %s, ",argv[1]);
- printf("argv[2] is %s.\n ",argv[2]); */
- //FILE * fptr = fopen("BlinkNew3.ino.bin", "rb"); // open existingblink file for nano
- //FILE * fptr = fopen("CDP1802e91.ino.bin", "rb"); // open existingblink file for nano
- //FILE * fptr = fopen("CDP1802e93.ino.bin", "rb"); // open existingblink file for nano
- //printf("Result of exists() function for %s is %d\n",argv[1],exists(argv[1]));
- if(exists(argv[1] )) printf("File %s can be used. ",argv[1]);
- else {
- printf(" Can't find file %s.",argv[1]);
- exit(3);
- }
- if(exists(argv[2] )) printf(" File %s can be used.\n",argv[2]);
- else {
- printf(" Can't find file %s.",argv[2]);
- exit(3);
- }
- FILE * fptr = fopen(argv[1], "rb"); // open existingblink file for nano
- FILE * fptr1 = fopen( argv[2], "rb"); // open long file with 1802 code above $4000 and $0 to 1K
- //char buffer[10000] = {0}; // the pic is 6kb or so, so 10k bytes will hold it
- FILE * fptr2 = fopen("combinedFile0.bin", "wb"); // open a new binary file to be sent to mega
- FILE * fptr3 = fopen("low1802.bin", "wb"); // open a new binary file for vRAM[] insertion via terminal
- unsigned long fileLen, fileLen1;
- unsigned long counter;
- fseek(fptr, 0, SEEK_END);
- fileLen=ftell(fptr); // get the exact size of the blink file
- fseek(fptr, 0, SEEK_SET);
- printf("The size of argv[1], %s, is %d bytes. ",argv[1],fileLen);
- fseek(fptr1, 0, SEEK_END);
- fileLen1=ftell(fptr1); // get the exact size of the blink file
- fseek(fptr1, 0, SEEK_SET);
- printf("The size of argv[2], %s, is %d bytes.\n ",argv[2],fileLen1);
- for(counter=0; counter<fileLen; counter++)
- fputc(fgetc(fptr),fptr2); // read each byte of the arduino file. Put into combinedFile0
- for(counter=fileLen; counter<0x4000; counter++) //fill in the gap between arduino file and 1802asm.bin
- fputc(0x00,fptr2);
- fseek(fptr1,0x4000,SEEK_SET);
- for(counter=0x4000; counter<fileLen1; counter++)
- fputc(fgetc(fptr1),fptr2); //Put bytes from 1802.asm file that are above $4000 into combinedFile0
- fseek(fptr1,0,SEEK_SET);
- for(counter=0; counter<0x400; counter++)
- fputc(fgetc(fptr1),fptr3); //Put bytes from 1802.asm file that are below $400 into low1802.bin .
- fclose(fptr);
- fclose(fptr1);
- fclose(fptr2);
- fclose(fptr3);
- return 0;
- }
- void ttest1(void) {
- printf("The fttttirst argument supplied is %d", k);
- }
- /*int fileIsReal(char* filename) {
- int j;
- FILE * fptr = fopen(argv[1], "rb");
- }*/
- int exists(const char *fname)
- {
- FILE *file;
- if ((file = fopen(fname, "r")))
- {
- fclose(file);
- return 1;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment