xboxscene.org forums

Author Topic: Fstream Problem  (Read 64 times)

razorrifh

  • Archived User
  • Sr. Member
  • *
  • Posts: 329
Fstream Problem
« on: February 24, 2004, 08:01:00 PM »

smile.gif


this is my program
CODE
// gba_namer.cpp : Defines the entry point for the console application.
//

/*
from http://www.work.de/nocash/gbatek.htm#cartridgeheader
Header Overview
 Address Bytes Expl.
 000h    4     ROM Entry Point  (32bit ARM branch opcode, eg. "B rom_start")
 004h    156   Nintendo Logo    (compressed bitmap, required!)
 *****0A0h    12    Game Title       (uppercase ascii, max 12 characters)*****
 0ACh    4     Game Code        (uppercase ascii, 4 characters)
 0B0h    2     Maker Code       (uppercase ascii, 2 characters)
 0B2h    1     Fixed value      (must be 96h, required!)
 0B3h    1     Main unit code   (00h for current GBA models)
 0B4h    1     Device type      (huh ???)
 0B5h    7     Reserved Area    (should be zero filled)
 0BCh    1     Software version (usually 00h)
 0BDh    1     Complement check (header checksum, required!)
 0BEh    2     Reserved Area    (should be zero filled)
 --- Additional Multiboot Header Entries ---
 0C0h    4     RAM Entry Point  (32bit ARM branch opcode, eg. "B ram_start")
 0C4h    1     Boot mode        (init as 00h - BIOS overwrites this value!)
 0C5h    1     Slace ID Number  (init as 00h - BIOS overwrites this value!)
 0C6h    26    Not used         (seems to be unused)
 0E4h    4     JOYBUS Entry Pt. (32bit ARM branch opcode, eg. "B joy_start")


Note: With all entry points, the CPU is initially set into system mode.
*/

#include "stdafx.h"
#include "iostream"
#include "fstream"
using namespace std;

void read_rom_name();
void write_rom_name(char[]);

int _tmain(int argc, _TCHAR* argv[])
{
   read_rom_name();
return 0;
}

void read_rom_name()
{
   fstream romfile;
   char romname[12];

   romfile.open ("rom.bin", fstream::in | fstream::out | fstream::binary);
   romfile.seekp(160);
   romfile.read(romname, 12);
   cout << "the rom\'s name is \"" << romname << "\"\n";
   romfile.close();
}

void write_rom_name(char name[])
{
   fstream romfile;
   
   romfile.open ("rom.bin", fstream::in | fstream::out | fstream::binary);
   romfile.seekp(160);
   romfile.write(name,0);
   cout << "write done! reading out name...\n";
   romfile.close();

   read_rom_name();
}


i deleted the user interface part to get to the part thats the problem. this program goes to the 160th byte of a file and reads the next 12 bytes. this is the game's name stored in the gba rom. it works perfectly on most roms but some of them it shows between 13 and 17 bytes extra. its strange. i cant figure it out!  

if anyone can help please let me know. its driving me crazy.



EDIT: i think it might have something to do with an array starting at 0 and counting starts from 1, but i dont see why it would work on some roms (wrestlemania 18) and not others (mario and luigi superstar saga).
Logged

razorrifh

  • Archived User
  • Sr. Member
  • *
  • Posts: 329
Fstream Problem
« Reply #1 on: February 25, 2004, 02:39:00 AM »

tongue.gif) i'll try that smile.gif
Logged

Dgege

  • Archived User
  • Newbie
  • *
  • Posts: 8
Fstream Problem
« Reply #2 on: February 25, 2004, 10:48:00 AM »

What I meant is that it doesn't specify the name's format
It says : uppercase ascii, max 12 characters, but we don't know if it's null terminated or not. My guess it's not, which explains the problem.
I'm pretty sure the roms which work are one with name under 12 characters, whereas the ones which screw up have names the lenght of 12 characters ? But I may be wrong.

Dgege
Logged

razorrifh

  • Archived User
  • Sr. Member
  • *
  • Posts: 329
Fstream Problem
« Reply #3 on: February 25, 2004, 05:33:00 PM »

smile.gif it just happened that the roms that work were null terminated by chance. the others werent and they were showing garbage until it came across a 0x00.

thanks for all your help smile.gif
Logged

Dgege

  • Archived User
  • Newbie
  • *
  • Posts: 8
Fstream Problem
« Reply #4 on: February 26, 2004, 04:06:00 AM »

smile.gif

Dgege
Logged