Print cartridge info when loaded

This commit is contained in:
Fabien Freling 2019-06-07 14:25:10 +02:00
parent f0cab3f1c6
commit e260011665
2 changed files with 22 additions and 21 deletions

View file

@ -78,30 +78,30 @@ 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;
(* 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
let nintendo_logo = Bytes.sub full_rom nin_logo_offset nin_logo_size in let nintendo_logo = Bytes.sub full_rom nin_logo_offset nin_logo_size in
(* Title *) (* Title *)
let title_offset = 0x0134 in let title_offset = 0x0134 in
let title_size = 16 in let title_size = 16 in
let title_b = Bytes.sub full_rom title_offset title_size in let title_b = Bytes.sub full_rom title_offset title_size in
let title = Bytes.to_string title_b in let title = Bytes.to_string title_b in
(* Cartridge type - memory bank *) (* Cartridge type - memory bank *)
let mem_type_code = Bytes.get full_rom 0x0147 |> int_of_char in let mem_type_code = Bytes.get full_rom 0x0147 |> int_of_char in
let mem_type = get_cartridge_type mem_type_code in let mem_type = get_cartridge_type mem_type_code in
(* ROM size *) (* ROM size *)
let rom_size_code = Bytes.get full_rom 0x0148 |> int_of_char in let rom_size_code = Bytes.get full_rom 0x0148 |> int_of_char in
let rom_size = get_ROM_size rom_size_code in let rom_size = get_ROM_size rom_size_code in
(* RAM size *) (* RAM size *)
let ram_size_code = Bytes.get full_rom 0x0149 |> int_of_char in let ram_size_code = Bytes.get full_rom 0x0149 |> int_of_char in
let ram_size = get_RAM_size ram_size_code in let ram_size = get_RAM_size ram_size_code in
Some { full_rom; nintendo_logo; title; mem_type; rom_size; ram_size } Some { full_rom; nintendo_logo; title; mem_type; rom_size; ram_size }
with with
| Sys_error msg | Sys_error msg
@ -114,4 +114,5 @@ let print_info cartridge =
printf "Title: %s\n" cartridge.title; printf "Title: %s\n" cartridge.title;
printf "Mem. type: %s\n" (cartridge.mem_type |> mem_type_name); printf "Mem. type: %s\n" (cartridge.mem_type |> mem_type_name);
printf "ROM size: %iKB\n" cartridge.rom_size; printf "ROM size: %iKB\n" cartridge.rom_size;
printf "RAM size: %iKB\n" cartridge.ram_size printf "RAM size: %iKB\n" cartridge.ram_size;
print_newline ()

View file

@ -12,5 +12,5 @@ let load_cartridge file =
let cartridge = Cartridge.read_cartridge file in let cartridge = Cartridge.read_cartridge file in
!state.cartridge <- cartridge; !state.cartridge <- cartridge;
match cartridge with match cartridge with
| Some _ -> true | Some c -> Cartridge.print_info c; true
| None -> false | None -> false