Blit tiles to map.

This commit is contained in:
Fabien Freling 2015-04-19 19:18:20 +02:00
parent c464ca697a
commit 3c24ade366
2 changed files with 42 additions and 2 deletions

View file

@ -1,4 +1,6 @@
let is_set num i = let is_set num i =
if i < 0 then failwith "Invalid bit index." if i < 0 then
(num lsr i) land 0b00000001 <> 0 failwith "Invalid bit index."
else
(num lsr i) land 0b00000001 <> 0

View file

@ -51,3 +51,41 @@ let init_screen w h =
height = h; height = h;
data = Array.make_matrix h w { r = 255; g = 255; b = 255; a = 255 } 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