Read Nintendo checksum in cartridge header.
This first commit parses the ROM to extract the Nintendo Logo and display it on stdout.
This commit is contained in:
commit
09f1ffb488
7 changed files with 80 additions and 0 deletions
28
src/cartridge.ml
Normal file
28
src/cartridge.ml
Normal file
|
@ -0,0 +1,28 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue