diff --git a/src/bit.ml b/src/bit.ml index a3bf5ff..d6e50cc 100644 --- a/src/bit.ml +++ b/src/bit.ml @@ -1,4 +1,6 @@ let is_set num i = - if i < 0 then failwith "Invalid bit index." - (num lsr i) land 0b00000001 <> 0 + if i < 0 then + failwith "Invalid bit index." + else + (num lsr i) land 0b00000001 <> 0 diff --git a/src/screen.ml b/src/screen.ml index a1f27ed..43005a6 100644 --- a/src/screen.ml +++ b/src/screen.ml @@ -51,3 +51,41 @@ let init_screen w h = height = h; data = Array.make_matrix h w { r = 255; g = 255; b = 255; a = 255 } } + + +let render_map mem map_addr = + let tile_size = 16 in + let map = Bytes.create (32 * 32 * tile_size) in + for y = 0 to (32 - 1) do + for x = 0 to (32 - 1) do + let tile_number = Memory.get mem (map_addr + (y * 32 + x)) |> int_of_char in + let src_offset = map_addr + tile_number * tile_size in + let tile_line_size = 2 in + let tile_height = 8 in + + for line_index = 0 to (tile_height - 1) do + let line_offset = src_offset + (line_index * tile_line_size) in + let dst_y = y * tile_height + line_index in + let dst_offset = (dst_y * 32 + x) * tile_line_size in + Bytes.blit mem.vram line_offset map dst_offset tile_line_size + done + done + done + + +let render mem = + let + { + lcd_display_enable; + tile_map_select; + window_display_enable; + tile_data_select; + bg_tile_map_select; + sprite_size; + sprite_enable; + bg_display; + } = get_lcd_control mem in + let scy = Memory.get mem 0xFF42 |> int_of_char in + let scx = Memory.get mem 0xFF43 |> int_of_char in + scx + scy +