yy-chr: set file size
Moderator: Moderators
-
- Posts: 9
- Joined: Sat Jul 09, 2016 10:16 am
yy-chr: set file size
I noticed that some chr files are different sizes (some are 8kb, some are 2kb...) and I need mine to be 1kb in size, but whenever I create a new file in YY-CHR it's 8KB large by default. How can I change this?
Re: yy-chr: set file size
AFAIK it's not possible. You can edit smaller files though (you can use a hex editor like HxD to create a file full of zeros). Caution: If you make changes in areas that don't fall within the original size of the file, the changes won't be saved.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
-
- Posts: 9
- Joined: Sat Jul 09, 2016 10:16 am
Re: yy-chr: set file size
That works, thanks!
- Light-Dark
- Posts: 53
- Joined: Sun Dec 08, 2013 9:53 pm
- Location: Canada
Re: yy-chr: set file size
Because Tokumaru's tile compressor takes a max of 4kb of tile data I wrote a simple C program that carves up the standard 8kb chr file for myself. Here's an example program for you that fits your needs:
It takes two command line args, the chr file and then the output file.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
char* extractKB(char* indata,int size){
char* cut = malloc(size);
memcpy(cut,indata,size); //copy first kb
return cut;
}
int getFileSize(FILE* fp){
int count = 0;
while(fgetc(fp)!=EOF)
count++;
fseek(fp,0,0);
return count;
}
int main(int argc,char** argv) {
if(argc < 3)
return 1;
FILE* fp = fopen(argv[1],"rb");
int size = getFileSize(fp);
char* buffer= malloc(size);
fread(buffer,1,size,fp);
fclose(fp);
fp = fopen(argv[2],"wb");
char* extracted = extractKB(buffer,1024);
fwrite(extracted,1,1024,fp);
fclose(fp);
free(buffer);
free(extracted);
return 0;
}
Re: yy-chr: set file size
You can't be serious with that getFileSize() routine, are you? You don't need the while/fgetc at all. Try:
Note that ftell() returns long, not int, so other portions of the program will need to be updated. Also, fread() takes a size_t for its size and member counts, so you might have to force-cast (no guarantee size_t is a long on every arch).
I'm intentionally choosing not to comment on the rest. :-)
Code: Select all
long getFileSize(FILE *fp) {
long count;
fseek(fp, 0, SEEK_END);
/* TODO handle when ftell() returns -1 (error; errno is set) */
count = ftell(fp);
fseek(fp, 0, SEEK_SET);
return count;
}
I'm intentionally choosing not to comment on the rest. :-)
Re: yy-chr: set file size
Python is quite a bit more practical for tasks like that:
(That's the whole program.)
On *nix you could achieve the same thing with dd.
Code: Select all
import sys; open( sys.argv[2], "wb" ).write( open( sys.argv[1], "rb" ).read( 1024 ) )
On *nix you could achieve the same thing with dd.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
- Light-Dark
- Posts: 53
- Joined: Sun Dec 08, 2013 9:53 pm
- Location: Canada
Re: yy-chr: set file size
That's okay, critique is welcome. I'm certainly not the Da Vinci of C code (slapped it together on the way home from work).koitsu wrote:You can't be serious with that getFileSize() routine, are you? You don't need the while/fgetc at all. Try:
Note that ftell() returns long, not int, so other portions of the program will need to be updated. Also, fread() takes a size_t for its size and member counts, so you might have to force-cast (no guarantee size_t is a long on every arch).Code: Select all
long getFileSize(FILE *fp) { long count; fseek(fp, 0, SEEK_END); /* TODO handle when ftell() returns -1 (error; errno is set) */ count = ftell(fp); fseek(fp, 0, SEEK_SET); return count; }
I'm intentionally choosing not to comment on the rest.
Re: yy-chr: set file size
There is dd for Windows (which also implements /dev/null, /dev/zero, and /dev/random "devices" for convenience). I've used this for a long time with great success.thefox wrote:On *nix you could achieve the same thing with dd.