104 lines
2.1 KiB
OCaml
104 lines
2.1 KiB
OCaml
|
open import "prelude.ml"
|
||
|
|
||
|
type u8 =
|
||
|
U8 of int
|
||
|
|
||
|
instance show u8 begin
|
||
|
let show (U8 x) = (show x) ^ "_u8"
|
||
|
end
|
||
|
|
||
|
type s8 =
|
||
|
S8 of int
|
||
|
|
||
|
instance show s8 begin
|
||
|
let show (S8 x) =
|
||
|
let signfix =
|
||
|
if x > 127 then
|
||
|
negate (256 - x)
|
||
|
else
|
||
|
x
|
||
|
(show signfix) ^ "_s8"
|
||
|
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) =
|
||
|
let signfix =
|
||
|
if x > 32767 then
|
||
|
negate (65536 - x)
|
||
|
else
|
||
|
x
|
||
|
(show signfix) ^ "_s16"
|
||
|
end
|
||
|
|
||
|
type u32 =
|
||
|
U32 of int
|
||
|
|
||
|
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
|
||
|
|
||
|
module Dolphin = struct
|
||
|
external val read_value_8 : int -> () -> int =
|
||
|
"function(addr, n) return ReadValue8(addr) end"
|
||
|
external val read_value_16 : int -> () -> int =
|
||
|
"function(addr, n) return ReadValue16(addr) end"
|
||
|
external val read_value_32 : int -> () -> int =
|
||
|
"function(addr, n) return ReadValue32(addr) end"
|
||
|
external val read_value_float : int -> () -> float =
|
||
|
"function(addr, n) return ReadValueFloat(addr) end"
|
||
|
external val read_value_string : int -> int -> () -> string =
|
||
|
"function(addr, len, n) return ReadValueString(addr, len) end"
|
||
|
|
||
|
external val msg_box : string -> int -> () -> () =
|
||
|
"function(message, delay, n) MsgBox(message, delay) end"
|
||
|
external val set_screen_text : string -> () -> () =
|
||
|
"function(message, n) SetScreenText(message) end"
|
||
|
end
|
||
|
|
||
|
class decode 'a begin
|
||
|
val decode : int -> () -> 'a
|
||
|
end
|
||
|
|
||
|
instance decode u8 begin
|
||
|
let decode addr x = U8 (Dolphin.read_value_8 addr x)
|
||
|
end
|
||
|
|
||
|
instance decode s8 begin
|
||
|
let decode addr x = S8 (Dolphin.read_value_8 addr x)
|
||
|
end
|
||
|
|
||
|
instance decode u16 begin
|
||
|
let decode addr x = U16 (Dolphin.read_value_16 addr x)
|
||
|
end
|
||
|
|
||
|
instance decode s16 begin
|
||
|
let decode addr x = S16 (Dolphin.read_value_16 addr x)
|
||
|
end
|
||
|
|
||
|
instance decode u32 begin
|
||
|
let decode addr x = U32 (Dolphin.read_value_32 addr x)
|
||
|
end
|
||
|
|
||
|
instance decode s32 begin
|
||
|
let decode addr x = S32 (Dolphin.read_value_32 addr x)
|
||
|
end
|