Commit 77f7c7be authored by Fabien Freling's avatar Fabien Freling

Replace begin .. end with ( .. )

parent 033f63ec
......@@ -189,38 +189,36 @@ let run cpu (mem: Memory.map) =
| '\x20' -> let n = read_pc_byte cpu mem in
let s = Bit.signed_byte n in
let inst = sprintf "JR \tNZ, 0x%02X (%d)" n s in
if cpu.flag.z = false then
begin
if cpu.flag.z = false then (
inc_pc cpu (s - 2); (* we read 2 bytes from PC, opcode and n *)
inst, 12
end else begin
) else (
inst, 8
end
)
| '\xC9' -> let inst = sprintf "RET" in
cpu.reg.pc <- pop_stack cpu mem;
inst, 16
| '\xC0' -> let inst = sprintf "RET \tNZ" in
if cpu.flag.z = false then
begin
if cpu.flag.z = false then (
cpu.reg.pc <- pop_stack cpu mem;
inst, 20
end else begin
) else (
inst, 8
end
)
| '\x03' -> let inst = sprintf "INC \tBC" in
inc_BC cpu;
inst, 8
| '\x05' -> let inst = sprintf "DEC \tB" in
let dec = int_of_char(cpu.reg.b) - 1 in
cpu.flag.z <- dec = 0;
cpu.flag.n <- true;
cpu.flag.h <- dec < 0;
cpu.flag.h <- dec < 0;
cpu.reg.b <- char_of_int @@ if dec >= 0 then dec else 0;
inst, 4
......@@ -252,13 +250,12 @@ let run cpu (mem: Memory.map) =
| '\x28' -> let n = read_pc_byte cpu mem in
let inst = sprintf "JR \tZ, 0x%02X" n in
if cpu.flag.z = true then
begin
if cpu.flag.z = true then (
inc_pc cpu (n - 1);
inst, 12
end else begin
) else (
inst, 8
end
)
| '\x34' -> let inst = sprintf "INC \t(HL)" 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_ =
if not !Interrupt.ime then
() (* Interrupt Master Enable flag set to false, nothing to do *)
else
begin
else (
(* N.B.: flags are precomputed once but an interrupt could be requested
during that time *)
let interrupts = ie land if_ in
......@@ -359,4 +355,4 @@ let handle_interrupts cpu mem ie if_ =
match flags with
| [] -> () (* No interrupt *)
| _ -> List.iter (fun x -> handle_interrupt cpu mem x) flags
end
)
......@@ -13,10 +13,10 @@ open Printf
@see http://imrannazar.com/GameBoy-Emulation-in-JavaScript:-Memory *)
(** Common addresses *)
let gDIV = 0xFF04 (** divider register *)
let gDIV = 0xFF04 (** divider register *)
let gTIMA = 0xFF05 (** timer counter *)
let gTMA = 0xFF06 (** timer modulo *)
let gTAC = 0xFF07 (** timer control *)
let gTMA = 0xFF06 (** timer modulo *)
let gTAC = 0xFF07 (** timer control *)
type map = {
rom_bank_00 : bytes; (* cartridge, 16KB *)
......@@ -99,11 +99,11 @@ let update_timers mem cycles =
if should_inc_div then ignore (inc mem.map gDIV);
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
if overflow then begin
if overflow then (
let tma = get mem.map gTMA in
set mem.map gTIMA tma
(* TODO: INT 50 - Timer interupt *)
end
end
)
)
......@@ -16,16 +16,15 @@ let rec run (cpu: Cpu.t) (mem: Memory.t) (screen: Screen.t) =
printf "start %f\n" start;
let rec run_for cpu (mem: Memory.t) cycles_remaining =
if cycles_remaining > 0 then
begin
if cycles_remaining > 0 then (
printf "\n";
let inst, cycles = Cpu.run cpu mem.map in
printf "[Instruction] %s\n" inst;
Memory.update_timers mem cycles;
run_for cpu mem (cycles_remaining - cycles)
end
)
in
run_for cpu mem cycles_per_frame;
......@@ -60,12 +59,11 @@ let power_up cartridge =
let () =
if Array.length Sys.argv < 2 then
begin
if Array.length Sys.argv < 2 then (
prerr_endline "Please specify a ROM.";
eprintf "Usage: %s path/to/rom\n" Sys.argv.(0);
exit 1;
end;
);
let cartridge = Cartridge.read_cartridge Sys.argv.(1) in
match cartridge with
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment