It is currently Wed Oct 18, 2017 6:01 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: yy-chr: set file size
PostPosted: Wed Jul 13, 2016 11:22 am 
Offline

Joined: Sat Jul 09, 2016 10:16 am
Posts: 9
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?


Top
 Profile  
 
PostPosted: Wed Jul 13, 2016 11:50 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2961
Location: Tampere, Finland
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: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Wed Jul 13, 2016 12:28 pm 
Offline

Joined: Sat Jul 09, 2016 10:16 am
Posts: 9
That works, thanks!


Top
 Profile  
 
PostPosted: Fri Aug 12, 2016 11:54 am 
Offline
User avatar

Joined: Sun Dec 08, 2013 9:53 pm
Posts: 54
Location: Canada
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:

Code:
#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;
}


It takes two command line args, the chr file and then the output file.


Top
 Profile  
 
PostPosted: Fri Aug 12, 2016 1:46 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
You can't be serious with that getFileSize() routine, are you? You don't need the while/fgetc at all. Try:

Code:
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;
}

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. :-)


Top
 Profile  
 
PostPosted: Fri Aug 12, 2016 2:56 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2961
Location: Tampere, Finland
Python is quite a bit more practical for tasks like that:
Code:
import sys; open( sys.argv[2], "wb" ).write( open( sys.argv[1], "rb" ).read( 1024 ) )
(That's the whole program.)

On *nix you could achieve the same thing with dd.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Sat Aug 13, 2016 12:32 pm 
Offline
User avatar

Joined: Sun Dec 08, 2013 9:53 pm
Posts: 54
Location: Canada
koitsu wrote:
You can't be serious with that getFileSize() routine, are you? You don't need the while/fgetc at all. Try:

Code:
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;
}

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. :-)


That's okay, critique is welcome. I'm certainly not the Da Vinci of C code :lol: (slapped it together on the way home from work).


Top
 Profile  
 
PostPosted: Sat Aug 13, 2016 12:42 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
thefox wrote:
On *nix you could achieve the same thing with dd.

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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group