Replace begin .. end with ( .. )

master
Fabien Freling 2016-02-29 23:58:29 +01:00
parent 033f63ec42
commit 77f7c7bef3
3 changed files with 25 additions and 31 deletions

View File

@ -189,26 +189,24 @@ let run cpu (mem: Memory.map) =
| '\x20' -> let n = read_pc_byte cpu mem in | '\x20' -> let n = read_pc_byte cpu mem in
let s = Bit.signed_byte n in let s = Bit.signed_byte n in
let inst = sprintf "JR \tNZ, 0x%02X (%d)" n s in let inst = sprintf "JR \tNZ, 0x%02X (%d)" n s in
if cpu.flag.z = false then if cpu.flag.z = false then (
begin
inc_pc cpu (s - 2); (* we read 2 bytes from PC, opcode and n *) inc_pc cpu (s - 2); (* we read 2 bytes from PC, opcode and n *)
inst, 12 inst, 12
end else begin ) else (
inst, 8 inst, 8
end )
| '\xC9' -> let inst = sprintf "RET" in | '\xC9' -> let inst = sprintf "RET" in
cpu.reg.pc <- pop_stack cpu mem; cpu.reg.pc <- pop_stack cpu mem;
inst, 16 inst, 16
| '\xC0' -> let inst = sprintf "RET \tNZ" in | '\xC0' -> let inst = sprintf "RET \tNZ" in
if cpu.flag.z = false then if cpu.flag.z = false then (
begin
cpu.reg.pc <- pop_stack cpu mem; cpu.reg.pc <- pop_stack cpu mem;
inst, 20 inst, 20
end else begin ) else (
inst, 8 inst, 8
end )
@ -252,13 +250,12 @@ let run cpu (mem: Memory.map) =
| '\x28' -> let n = read_pc_byte cpu mem in | '\x28' -> let n = read_pc_byte cpu mem in
let inst = sprintf "JR \tZ, 0x%02X" n in let inst = sprintf "JR \tZ, 0x%02X" n in
if cpu.flag.z = true then if cpu.flag.z = true then (
begin
inc_pc cpu (n - 1); inc_pc cpu (n - 1);
inst, 12 inst, 12
end else begin ) else (
inst, 8 inst, 8
end )
| '\x34' -> let inst = sprintf "INC \t(HL)" in | '\x34' -> let inst = sprintf "INC \t(HL)" in
let hl = merge_bytes cpu.reg.l cpu.reg.h in let hl = merge_bytes cpu.reg.l cpu.reg.h in
@ -350,8 +347,7 @@ let handle_interrupt cpu mem flag =
let handle_interrupts cpu mem ie if_ = let handle_interrupts cpu mem ie if_ =
if not !Interrupt.ime then if not !Interrupt.ime then
() (* Interrupt Master Enable flag set to false, nothing to do *) () (* Interrupt Master Enable flag set to false, nothing to do *)
else else (
begin
(* N.B.: flags are precomputed once but an interrupt could be requested (* N.B.: flags are precomputed once but an interrupt could be requested
during that time *) during that time *)
let interrupts = ie land if_ in let interrupts = ie land if_ in
@ -359,4 +355,4 @@ let handle_interrupts cpu mem ie if_ =
match flags with match flags with
| [] -> () (* No interrupt *) | [] -> () (* No interrupt *)
| _ -> List.iter (fun x -> handle_interrupt cpu mem x) flags | _ -> List.iter (fun x -> handle_interrupt cpu mem x) flags
end )

View File

@ -99,11 +99,11 @@ let update_timers mem cycles =
if should_inc_div then ignore (inc mem.map gDIV); if should_inc_div then ignore (inc mem.map gDIV);
let should_inc_tima = Timer.update mem.tima cycles in let should_inc_tima = Timer.update mem.tima cycles in
if should_inc_tima then begin if should_inc_tima then (
let overflow = inc mem.map gTIMA in let overflow = inc mem.map gTIMA in
if overflow then begin if overflow then (
let tma = get mem.map gTMA in let tma = get mem.map gTMA in
set mem.map gTIMA tma set mem.map gTIMA tma
(* TODO: INT 50 - Timer interupt *) (* TODO: INT 50 - Timer interupt *)
end )
end )

View File

@ -16,8 +16,7 @@ let rec run (cpu: Cpu.t) (mem: Memory.t) (screen: Screen.t) =
printf "start %f\n" start; printf "start %f\n" start;
let rec run_for cpu (mem: Memory.t) cycles_remaining = let rec run_for cpu (mem: Memory.t) cycles_remaining =
if cycles_remaining > 0 then if cycles_remaining > 0 then (
begin
printf "\n"; printf "\n";
let inst, cycles = Cpu.run cpu mem.map in let inst, cycles = Cpu.run cpu mem.map in
printf "[Instruction] %s\n" inst; printf "[Instruction] %s\n" inst;
@ -25,7 +24,7 @@ let rec run (cpu: Cpu.t) (mem: Memory.t) (screen: Screen.t) =
Memory.update_timers mem cycles; Memory.update_timers mem cycles;
run_for cpu mem (cycles_remaining - cycles) run_for cpu mem (cycles_remaining - cycles)
end )
in in
run_for cpu mem cycles_per_frame; run_for cpu mem cycles_per_frame;
@ -60,12 +59,11 @@ let power_up cartridge =
let () = let () =
if Array.length Sys.argv < 2 then if Array.length Sys.argv < 2 then (
begin
prerr_endline "Please specify a ROM."; prerr_endline "Please specify a ROM.";
eprintf "Usage: %s path/to/rom\n" Sys.argv.(0); eprintf "Usage: %s path/to/rom\n" Sys.argv.(0);
exit 1; exit 1;
end; );
let cartridge = Cartridge.read_cartridge Sys.argv.(1) in let cartridge = Cartridge.read_cartridge Sys.argv.(1) in
match cartridge with match cartridge with