78 lines
1.2 KiB
OCaml
78 lines
1.2 KiB
OCaml
|
open import "prelude.ml"
|
||
|
open import "./decode.ml"
|
||
|
open import "../dolphin.ml"
|
||
|
|
||
|
type u8 =
|
||
|
U8 of int
|
||
|
|
||
|
instance show u8 begin
|
||
|
let show (U8 x) = (show x) ^ "_u8"
|
||
|
end
|
||
|
|
||
|
instance decode u8 begin
|
||
|
let decode addr = U8 (Dolphin.read_value_8 addr)
|
||
|
end
|
||
|
|
||
|
type s8 =
|
||
|
S8 of int
|
||
|
|
||
|
instance show s8 begin
|
||
|
let show (S8 x) = (show x) ^ "_s8"
|
||
|
end
|
||
|
|
||
|
instance decode s8 begin
|
||
|
let decode addr =
|
||
|
let u8 = Dolphin.read_value_8 addr
|
||
|
let signfix =
|
||
|
if u8 > 127 then
|
||
|
negate (256 - u8)
|
||
|
else
|
||
|
u8
|
||
|
S8 signfix
|
||
|
end
|
||
|
|
||
|
type u16 =
|
||
|
U16 of int
|
||
|
|
||
|
instance show u16 begin
|
||
|
let show (U16 x) = (show x) ^ "_u16"
|
||
|
end
|
||
|
|
||
|
type s16 =
|
||
|
S16 of int
|
||
|
|
||
|
instance show s16 begin
|
||
|
let show (S16 x) = (show x) ^ "_s16"
|
||
|
end
|
||
|
|
||
|
instance decode s16 begin
|
||
|
let decode addr =
|
||
|
let u16 = Dolphin.read_value_16 addr
|
||
|
let signfix =
|
||
|
if u16 > 32767 then
|
||
|
negate (65536 - u16)
|
||
|
else
|
||
|
u16
|
||
|
S16 signfix
|
||
|
end
|
||
|
|
||
|
type u32 =
|
||
|
U32 of int
|
||
|
|
||
|
instance show u32 begin
|
||
|
let show (U32 x) = (show x) ^ "_u32"
|
||
|
end
|
||
|
|
||
|
type s32 =
|
||
|
S32 of int
|
||
|
|
||
|
instance show s32 begin
|
||
|
let show (S32 x) =
|
||
|
let signfix =
|
||
|
if x > 2147483647 then
|
||
|
negate (4294967296 - x)
|
||
|
else
|
||
|
x
|
||
|
(show signfix) ^ "_s32"
|
||
|
end
|