Commit 3c24ade3 authored by Fabien Freling's avatar Fabien Freling

Blit tiles to map.

parent c464ca69
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
......@@ -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
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