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
					
				
					 1 changed files with 6 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -3,7 +3,6 @@ open Printf
 | 
			
		|||
 | 
			
		||||
(** http://bgb.bircd.org/pandocs.htm#thecartridgeheader *)
 | 
			
		||||
 | 
			
		||||
exception Read_error
 | 
			
		||||
 | 
			
		||||
type memory_bank_controller =
 | 
			
		||||
  | ROM_ONLY
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +40,7 @@ let get_ROM_size = function
 | 
			
		|||
  | 0x52 -> 1100 (* 72 banks *)
 | 
			
		||||
  | 0x53 -> 1200 (* 80 banks *)
 | 
			
		||||
  | 0x54 -> 1500 (* 96 banks *)
 | 
			
		||||
  | _ -> raise Read_error
 | 
			
		||||
  | _ -> failwith "Invalid ROM size code."
 | 
			
		||||
 | 
			
		||||
(** RAM size is expressed in KB *)
 | 
			
		||||
let get_RAM_size = function
 | 
			
		||||
| 
						 | 
				
			
			@ -49,7 +48,7 @@ let get_RAM_size = function
 | 
			
		|||
  | 0x01 -> 2
 | 
			
		||||
  | 0x02 -> 8
 | 
			
		||||
  | 0x03 -> 32 (* 4 x 8KB banks *)
 | 
			
		||||
  | _ -> raise Read_error
 | 
			
		||||
  | _ -> failwith "Invalid RAM size code."
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
let read_cartridge file =
 | 
			
		||||
| 
						 | 
				
			
			@ -62,8 +61,6 @@ let read_cartridge file =
 | 
			
		|||
    really_input ic full_rom 0 file_size;
 | 
			
		||||
    close_in ic;
 | 
			
		||||
 | 
			
		||||
    try
 | 
			
		||||
 | 
			
		||||
      (* Nintendo logo *)
 | 
			
		||||
      let nin_logo_offset = 0x0104 in
 | 
			
		||||
      let nin_logo_size = 48 in
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +83,6 @@ let read_cartridge file =
 | 
			
		|||
      Some { full_rom; nintendo_logo; title; rom_size; ram_size }
 | 
			
		||||
 | 
			
		||||
  with
 | 
			
		||||
    | Invalid_argument(msg) -> None (* This is triggered by Bytes.sub *)
 | 
			
		||||
    | Read_error -> None
 | 
			
		||||
 | 
			
		||||
  with Sys_error(msg) -> None
 | 
			
		||||
  | Sys_error msg
 | 
			
		||||
  | Invalid_argument msg (* This is triggered by Bytes.sub *)
 | 
			
		||||
  | Failure msg -> prerr_endline msg; None
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue