Compare commits

..

No commits in common. "wip" and "master" have entirely different histories.
wip ... master

1 changed files with 2 additions and 14 deletions

View File

@ -94,6 +94,7 @@ 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);
@ -108,26 +109,13 @@ 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 *)
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
bg_map.{i, j} <- n
done
done;
bg_map