This commit is contained in:
Fabien Freling 2019-07-14 19:58:58 +02:00
parent 94defc9653
commit 9f9d898fac

View file

@ -94,7 +94,6 @@ let inc mem addr =
Bytes.set m x c; Bytes.set m x c;
overflow overflow
let update_timers mem cycles = let update_timers mem cycles =
let should_inc_div = Timer.update mem.timer_div cycles in let should_inc_div = Timer.update mem.timer_div cycles in
if should_inc_div then ignore (inc mem.map gDIV); if should_inc_div then ignore (inc mem.map gDIV);
@ -109,13 +108,26 @@ let update_timers mem cycles =
end end
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 background_map mem n =
let bg_map = Array2.create Bigarray.int8_unsigned Bigarray.c_layout 8 8 in 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; Array2.fill bg_map 0;
for j = 0 to (Array2.dim2 bg_map) - 1 do for j = 0 to (Array2.dim2 bg_map) - 1 do
for i = 0 to (Array2.dim1 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} <- (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
done; done;
bg_map bg_map