Refactor "try" block in read_cartridge.
Remove custom exception Read_error in favor of standard Failure.
This commit is contained in:
parent
1a978d6814
commit
91ad537af9
|
@ -3,7 +3,6 @@ open Printf
|
||||||
|
|
||||||
(** http://bgb.bircd.org/pandocs.htm#thecartridgeheader *)
|
(** http://bgb.bircd.org/pandocs.htm#thecartridgeheader *)
|
||||||
|
|
||||||
exception Read_error
|
|
||||||
|
|
||||||
type memory_bank_controller =
|
type memory_bank_controller =
|
||||||
| ROM_ONLY
|
| ROM_ONLY
|
||||||
|
@ -41,7 +40,7 @@ let get_ROM_size = function
|
||||||
| 0x52 -> 1100 (* 72 banks *)
|
| 0x52 -> 1100 (* 72 banks *)
|
||||||
| 0x53 -> 1200 (* 80 banks *)
|
| 0x53 -> 1200 (* 80 banks *)
|
||||||
| 0x54 -> 1500 (* 96 banks *)
|
| 0x54 -> 1500 (* 96 banks *)
|
||||||
| _ -> raise Read_error
|
| _ -> failwith "Invalid ROM size code."
|
||||||
|
|
||||||
(** RAM size is expressed in KB *)
|
(** RAM size is expressed in KB *)
|
||||||
let get_RAM_size = function
|
let get_RAM_size = function
|
||||||
|
@ -49,7 +48,7 @@ let get_RAM_size = function
|
||||||
| 0x01 -> 2
|
| 0x01 -> 2
|
||||||
| 0x02 -> 8
|
| 0x02 -> 8
|
||||||
| 0x03 -> 32 (* 4 x 8KB banks *)
|
| 0x03 -> 32 (* 4 x 8KB banks *)
|
||||||
| _ -> raise Read_error
|
| _ -> failwith "Invalid RAM size code."
|
||||||
|
|
||||||
|
|
||||||
let read_cartridge file =
|
let read_cartridge file =
|
||||||
|
@ -62,8 +61,6 @@ let read_cartridge file =
|
||||||
really_input ic full_rom 0 file_size;
|
really_input ic full_rom 0 file_size;
|
||||||
close_in ic;
|
close_in ic;
|
||||||
|
|
||||||
try
|
|
||||||
|
|
||||||
(* Nintendo logo *)
|
(* Nintendo logo *)
|
||||||
let nin_logo_offset = 0x0104 in
|
let nin_logo_offset = 0x0104 in
|
||||||
let nin_logo_size = 48 in
|
let nin_logo_size = 48 in
|
||||||
|
@ -85,8 +82,7 @@ let read_cartridge file =
|
||||||
|
|
||||||
Some { full_rom; nintendo_logo; title; rom_size; ram_size }
|
Some { full_rom; nintendo_logo; title; rom_size; ram_size }
|
||||||
|
|
||||||
with
|
with
|
||||||
| Invalid_argument(msg) -> None (* This is triggered by Bytes.sub *)
|
| Sys_error msg
|
||||||
| Read_error -> None
|
| Invalid_argument msg (* This is triggered by Bytes.sub *)
|
||||||
|
| Failure msg -> prerr_endline msg; None
|
||||||
with Sys_error(msg) -> None
|
|
||||||
|
|
Loading…
Reference in a new issue