initial import

This commit is contained in:
Lobo 2025-11-27 16:39:54 -03:00
commit ad589d2894
26 changed files with 2241 additions and 0 deletions

17
lib/Util.ml Normal file
View file

@ -0,0 +1,17 @@
let uint8_to_int8 i = (i lsl (Sys.int_size - 8)) asr (Sys.int_size - 8)
let uint16_to_int16 i = (i lsl (Sys.int_size - 16)) asr (Sys.int_size - 16)
let get_uint16_wrap ?(wrap = 0xff) (bytes : bytes) (position : int) : int =
let i0 = position land wrap in
let hi = Bytes.get_uint8 bytes i0 in
let lo = Bytes.get_uint8 bytes ((i0 + 1) land wrap) in
(hi lsl 8) lor lo
let get_int16_wrap ?(wrap = 0xff) (bytes : bytes) (position : int) : int =
get_uint16_wrap ~wrap bytes position |> uint16_to_int16
let set_uint16_wrap ?(wrap = 0xff) (bytes : bytes) (position : int)
(value : int) : unit =
let i0 = position land wrap in
Bytes.set_uint8 bytes i0 ((value lsr 8) land 0xff);
Bytes.set_uint8 bytes ((i0 + 1) land wrap) (value land 0xff)