gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Writing a Perl rom trimmer: pbs with seek() and read()

#23184 - Vince - Tue Jul 06, 2004 7:38 pm

Hiya to you all,

Since I am not so experienced in GBA devel, I post here despite the fact that my request does not directly address GBA programming but managing ROMS instead.
I want to write utilities to be able to manage ROMs under Linux/free OSes. One of them is a ROM trimmer. I use Perl as a language.

Basically, what I wanted to do is the following :
1. Use the seek() function to go to the end of the ROM file.
2. Iterate on bytes reading backwards with read() as long as the byte read is a 00 or an FF. Stop when different. I would get a certain location (let's name it $offset) from the end of the ROM
3. Now go to the beginning of the ROM
4. Copy ROM contents from start to (size-$offset) into new file : ROM_trimmed.gba

However, I have problems with read() which, along reading a byte, advances the "seek cursor" position by one byte. Instead of having to, before doing a new read, going backwards two bytes, I wanted to know if there is a possibility to read backwards in an easier manner.

Thank you for your attention, I hope I was clear enough

Vince

#23188 - tepples - Wed Jul 07, 2004 1:12 am

Try seeking and reading 32 KB at a time.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#23200 - Vince - Wed Jul 07, 2004 9:35 am

Hi tepples,

Thank you for your answer.
Quote:
Try seeking and reading 32 KB at a time

While I can understand that GBA code need to be aligned on 32 bits boundaries (thus allowing me to read 4 bytes at a time, an improvement over the 1 byte read), I still not understand your answer.
IMHO, 32KB (you were talking about bytes weren't you?) is too much to read at a time.

Could you elaborate on this?

Thank you for your time.

#23222 - tepples - Wed Jul 07, 2004 8:31 pm

32768 bytes is the granularity of many flash cartridges' bankswitch registers. Therefore, when size-stripping a ROM, it's best to size-strip in 32 KB increments.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#23411 - Vince - Mon Jul 12, 2004 9:24 am

Hi back tepples,

Thanks for your answer, I got it now.
I will also look deeper into the bankswitching mechanisms involved with flash carts to get a thorough understanding of the underlying principles.

Thanks again,

Vince