GBA rom trimmer for Mac?

Discussion in 'NDS - Flashcarts and Accessories' started by DMPugh, Dec 16, 2008.

Dec 16, 2008

GBA rom trimmer for Mac? by DMPugh at 8:58 AM (1,126 Views / 0 Likes) 2 replies

  1. DMPugh
    OP

    Newcomer DMPugh Advanced Member

    Joined:
    Aug 3, 2008
    Messages:
    86
    Country:
    Canada
    Not sure if this is the right forum for this, but can someone point me to a rom trimmer for Mac for GBA roms? Preferably something like Rominator which can automatically rename the roms. These will be used on a 3-in-1 through an Acekard 2.1. Thanks!
     
  2. enarky

    Member enarky GBAtemp Advanced Fan

    Joined:
    Jul 31, 2003
    Messages:
    997
    Country:
    If you have access to a C Compiler you could take this snippet from Pogoshell to compile your own Max OS X command line trimmer... been using it for years on Windows and Linux, works fine.

    CODE/************************************************************************
    * romtrunc - this programm removes "unnecessary" bytes from the end of *
    * (theoretically any, but in this case) GBA files. *
    * last changed September 9th 2003 *
    ************************************************************************/

    #include
    #include
    #include

    #define BUF_SIZE 65536

    int main(int argc, char *argv[])
    {
    unsigned char buf[BUF_SIZE], c, oldc;
    int l;

    FILE *fpi, *fpo;

    if(argc != 3){
    printf("Truncate similar bytes from end of file\n");
    printf("Usage: ""romtrunc infile.gba outfile.gba"" or\n");
    printf(" ""romtrunc infile.gba""\n");

    exit(0);
    }else{
    if(!(fpo=fopen(argv[2], "wb"))){
    printf("ERROR, either your disk is full or this file does not exist.");
    exit(0);
    }

    if(!(fpi=fopen(argv[1], "rb"))){
    printf("ERROR, either your disk is full or this file does not exist.");
    exit(0);
    }
    }

    // Begin of truncating operation.

    fseek(fpi, -1, SEEK_END);
    fread(&c, 1, 1, fpi);
    oldc = c;

    while((!c || (c == 0xFF) || (c==0x00)) && (oldc == c)){
    fseek(fpi, -2, SEEK_CUR);
    oldc = c;
    fread(&c, 1, 1, fpi);
    }

    l = ftell(fpi);
    fseek(fpi, 0, SEEK_SET);
    printf("Truncating at %d\n", l);

    while(l > BUF_SIZE){
    fread(buf, 1, BUF_SIZE, fpi);
    fwrite(buf, 1, BUF_SIZE, fpo);
    l -= BUF_SIZE;
    }

    fread(buf, 1, l, fpi);
    fwrite(buf,1, l, fpo);
    fclose(fpi);
    fclose(fpo);

    return 0;
    }
    If Mac OS X has gcc installed (what I hope, it's based on BSD, afterall...) just paste this into a text file and call it 'romtrunc.c'. Then compile it with 'gcc -Wall -g romtrunc.c -o romtrunc.
     
  3. Narin

    Former Staff Narin The Cheat Master, kupo!

    Joined:
    Feb 19, 2008
    Messages:
    2,624
    Country:
    United States
    I wouldn't bother really. I took about a gigabyte of GBA ROMs (About a thousand in total) and trimmed them and only saved like 32 megabytes. Most GBA ROMs use up all the space in the ROM so unlike NDS games, you gain very little from trimming them.
     

Share This Page