Add LCD control structure.
Also add the Bin module to easily deal with binary.
This commit is contained in:
parent
52e5afa344
commit
644a1356a8
4
src/bit.ml
Normal file
4
src/bit.ml
Normal file
|
@ -0,0 +1,4 @@
|
|||
let is_set num i =
|
||||
if i < 0 then failwith "Invalid bit index."
|
||||
(num lsr i) land 0b00000001 <> 0
|
||||
|
|
@ -11,6 +11,40 @@ type t = {
|
|||
data : pixel array;
|
||||
}
|
||||
|
||||
type control = {
|
||||
lcd_display_enable : bool;
|
||||
tile_map_select : int;
|
||||
window_display_enable : bool;
|
||||
tile_data_select : int;
|
||||
bg_tile_map_select : int;
|
||||
sprite_size : int;
|
||||
sprite_enable : bool;
|
||||
bg_display : bool;
|
||||
}
|
||||
|
||||
let get_lcd_control mem =
|
||||
let b = Memory.get mem 0xFF40 |> int_of_char in
|
||||
|
||||
let lcd_display_enable = Bit.is_set b 7 in
|
||||
let tile_map_select = if not (Bit.is_set b 6) then 0x9800 else 0x9c00 in
|
||||
let window_display_enable = Bit.is_set b 5 in
|
||||
let tile_data_select = if not (Bit.is_set b 4) then 0x8800 else 0x8000 in
|
||||
let bg_tile_map_select = if not (Bit.is_set b 3) then 0x9800 else 0x9c00 in
|
||||
let sprite_size = if not (Bit.is_set b 2) then 8 else 16 in
|
||||
let sprite_enable = Bit.is_set b 1 in
|
||||
let bg_display = Bit.is_set b 0 in
|
||||
|
||||
{
|
||||
lcd_display_enable;
|
||||
tile_map_select;
|
||||
window_display_enable;
|
||||
tile_data_select;
|
||||
bg_tile_map_select;
|
||||
sprite_size;
|
||||
sprite_enable;
|
||||
bg_display;
|
||||
}
|
||||
|
||||
let init_screen w h =
|
||||
{
|
||||
width = w;
|
||||
|
|
Loading…
Reference in a new issue