29 lines
610 B
OCaml
29 lines
610 B
OCaml
open Unix
|
|
open Printf
|
|
|
|
(** http://bgb.bircd.org/pandocs.htm#thecartridgeheader *)
|
|
|
|
type memory_bank_controller =
|
|
| ROM_ONLY
|
|
| MBC1
|
|
|
|
type t = {
|
|
nintendo_logo : bytes;
|
|
title : string;
|
|
mem_type : memory_bank_controller;
|
|
rom_size : int;
|
|
ram_size : int;
|
|
header_checksum : bytes;
|
|
global_checksum : bytes;
|
|
}
|
|
|
|
let read_cartridge file =
|
|
print_endline file;
|
|
let fd = openfile file [Unix.O_RDONLY] 0o644 in
|
|
let n_logo = Bytes.create 48 in
|
|
let _ = lseek fd 0x0104 SEEK_SET in
|
|
let _ = read fd n_logo 0 48 in
|
|
print_endline "Nintendo logo:";
|
|
Hexa.print_bytes n_logo ~width:16;
|
|
Unix.close fd
|