File: id.cxx

package info (click to toggle)
stella 0.7-2
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 864 kB
  • ctags: 1,158
  • sloc: cpp: 6,615; ansic: 492; makefile: 224; asm: 31
file content (47 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//============================================================================
//
//    SSSS    tt          lll  lll              
//   SS  SS   tt           ll   ll                
//   SS     tttttt  eeee   ll   ll   aaaa    "An Atari 2600 VCS Emulator"
//    SSSS    tt   ee  ee  ll   ll      aa      
//       SS   tt   eeeeee  ll   ll   aaaaa   Copyright (c) 1995,1996,1997
//   SS  SS   tt   ee      ll   ll  aa  aa         Bradford W. Mott
//    SSSS     ttt  eeeee llll llll  aaaaa    
//
//============================================================================

/**
  Program to compute the Cartridge ID for a ROM image.

  @author  Bradford W. Mott
  @version $Id: id.cxx,v 1.1 1997/05/17 19:08:10 bwmott Exp $
*/

#include <stdio.h>
#include <fstream.h>

main(int argc, char* argv[])
{
  ifstream in;
  in.open(argv[1], ios::in | ios::nocreate);

  if(in.fail())
  {
    cerr << "Couldn't open " << argv[1] << endl;
    exit(1);
  } 

  // Read ROM from the input stream and see how big it is
  unsigned char rom[32768];
  in.read(rom, 32768);

  // Calculate Cartridge ID
  unsigned long cartId = 0;
  for(int i = 1024; i < 2048; i++)
  {
    cartId += (((unsigned long)rom[i]) << ((i & 0x0003) * 8));
  }

  printf("%08x\n", cartId);
}