From 9f9d898faceb7e3ba9f88ae8cf28468fdcefc691 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 14 Jul 2019 19:58:58 +0200 Subject: [PATCH] wip --- src/core/memory.ml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/memory.ml b/src/core/memory.ml index 54343d7..3f8e443 100644 --- a/src/core/memory.ml +++ b/src/core/memory.ml @@ -94,7 +94,6 @@ let inc mem addr = Bytes.set m x c; overflow - let update_timers mem cycles = let should_inc_div = Timer.update mem.timer_div cycles in if should_inc_div then ignore (inc mem.map gDIV); @@ -109,13 +108,26 @@ let update_timers mem cycles = end end +(* A tile is 8x8, with each pixel encoded in 2 bits: + * - the whole tile takes 16 bytes + * - each line takes 2 bytes + * - the first byte contains the least significant bit for the row + * - the second byte contains the upper bit + * - 8th bit is the leftmost + * - 1st bit is the rigthmost *) let background_map mem n = let bg_map = Array2.create Bigarray.int8_unsigned Bigarray.c_layout 8 8 in + let offset = match n with + | 0 -> 0x1800 (* VRAM starts at 0x8000 *) + | 1 -> 0x1C00 + | _ -> failwith "Invalid background map index" in Array2.fill bg_map 0; for j = 0 to (Array2.dim2 bg_map) - 1 do for i = 0 to (Array2.dim1 bg_map) - 1 do (* bg_map.{i, j} <- (i + j * Array2.dim1 bg_map) mod 4 *) - bg_map.{i, j} <- n + let mem_addr = i + j * Array2.dim1 bg_map in + let tile_index = Bytes.get mem.map.vram mem_addr |> int_of_char in + bg_map.{i, j} <- tile_index mod 4 done done; bg_map