Read RAM size.
This commit is contained in:
parent
bbd75e25f1
commit
f89d34ec14
|
@ -14,8 +14,8 @@ type t = {
|
|||
title : string;
|
||||
(* mem_type : memory_bank_controller; *)
|
||||
rom_size : int;
|
||||
(* ram_size : int;
|
||||
header_checksum : bytes;
|
||||
ram_size : int;
|
||||
(* header_checksum : bytes;
|
||||
global_checksum : bytes; *)
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,15 @@ let get_ROM_size b =
|
|||
| 0x54 -> 1500 (* 96 banks *)
|
||||
| _ -> raise Read_error
|
||||
|
||||
(** RAM size is expressed in KB *)
|
||||
let get_RAM_size b =
|
||||
match Bytes.get b 0 |> int_of_char with
|
||||
| 0x00 -> 0
|
||||
| 0x01 -> 2
|
||||
| 0x02 -> 8
|
||||
| 0x03 -> 32 (* 4 x 8KB banks *)
|
||||
| _ -> raise Read_error
|
||||
|
||||
|
||||
let read_cartridge file =
|
||||
try
|
||||
|
@ -53,25 +62,33 @@ let read_cartridge file =
|
|||
if (lseek fd nin_logo_offset SEEK_SET) != nin_logo_offset
|
||||
then raise Read_error;
|
||||
|
||||
(* Nintendo logo *)
|
||||
let nin_logo_size = 48 in
|
||||
let nintendo_logo = Bytes.create nin_logo_size in
|
||||
if (read fd nintendo_logo 0 nin_logo_size) != nin_logo_size
|
||||
then raise Read_error;
|
||||
|
||||
(* Title *)
|
||||
let title_size = 16 in
|
||||
let title_b = Bytes.create title_size in
|
||||
if (read fd title_b 0 title_size) != title_size
|
||||
then raise Read_error;
|
||||
let title = Bytes.to_string title_b in
|
||||
|
||||
let size_b = Bytes.create 1 in
|
||||
(* ROM size *)
|
||||
let byte = Bytes.create 1 in
|
||||
let _ = lseek fd 4 SEEK_CUR in
|
||||
if (read fd size_b 0 1) != 1
|
||||
if (read fd byte 0 1) != 1
|
||||
then raise Read_error;
|
||||
let rom_size = get_ROM_size size_b in
|
||||
let rom_size = get_ROM_size byte in
|
||||
|
||||
(* RAM size *)
|
||||
if (read fd byte 0 1) != 1
|
||||
then raise Read_error;
|
||||
let ram_size = get_RAM_size byte in
|
||||
|
||||
Unix.close fd;
|
||||
Some { nintendo_logo; title; rom_size }
|
||||
Some { nintendo_logo; title; rom_size; ram_size }
|
||||
|
||||
with Read_error -> Unix.close fd; None
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
open Cartridge
|
||||
open Printf
|
||||
|
||||
(** Power up sequence
|
||||
|
@ -8,7 +9,8 @@ let power_up cartridge =
|
|||
then print_endline "Invalid ROM."
|
||||
else
|
||||
print_endline "Valid ROM.";
|
||||
printf "ROM size: %iKB\n" cartridge.rom_size
|
||||
printf "ROM size: %iKB\n" cartridge.rom_size;
|
||||
printf "RAM size: %iKB\n" cartridge.ram_size
|
||||
|
||||
|
||||
let () =
|
||||
|
|
Loading…
Reference in a new issue