40 lines
810 B
OCaml
40 lines
810 B
OCaml
(**
|
|
* Copyright (c) 2016, Fabien Freling
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD 2-clause license found in the
|
|
* LICENSE file at the top level directory of this source tree.
|
|
*)
|
|
|
|
(* let IME = ref false;; *)
|
|
|
|
type t =
|
|
| V_Blank
|
|
| LCD_Stat
|
|
| Timer
|
|
| Serial
|
|
| Joypad
|
|
|
|
let get_flags byte =
|
|
|
|
let nth_interrupt i =
|
|
match i with
|
|
| 0 -> V_Blank
|
|
| 1 -> LCD_Stat
|
|
| 2 -> Timer
|
|
| 3 -> Serial
|
|
| 4 -> Joypad
|
|
| _ -> failwith "Invalid interrupt index." in
|
|
|
|
let rec get_flag byte i accu =
|
|
match i with
|
|
| 0 | 1 | 2 | 3 | 4 ->
|
|
if Bit.is_set byte i then
|
|
let interrupt = nth_interrupt i in
|
|
get_flag byte (i + 1) (interrupt :: accu)
|
|
else
|
|
get_flag byte (i + 1) accu
|
|
| _ -> accu in
|
|
|
|
get_flag byte 0 []
|