Replace begin .. end with ( .. )
This commit is contained in:
		
							parent
							
								
									033f63ec42
								
							
						
					
					
						commit
						77f7c7bef3
					
				
					 3 changed files with 25 additions and 31 deletions
				
			
		
							
								
								
									
										26
									
								
								src/cpu.ml
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								src/cpu.ml
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -189,26 +189,24 @@ 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
 | 
			
		||||
              )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
  )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
    )
 | 
			
		||||
  )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								src/oboy.ml
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/oboy.ml
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -16,8 +16,7 @@ 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;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,7 +24,7 @@ let rec run (cpu: Cpu.t) (mem: Memory.t) (screen: Screen.t) =
 | 
			
		|||
      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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue