Switch decoding over to a Monad for portability
At some point this may run on BizHawk so that I can draw information instead of having the very limited Dolphin text. I should really start working on my own Amulet prelude... There's lots of stuff from cats that I miss here.
This commit is contained in:
parent
723fe69684
commit
73c1a485fb
10 changed files with 255 additions and 107 deletions
|
@ -1,5 +1,40 @@
|
|||
open import "prelude.ml"
|
||||
open import "./int.ml"
|
||||
open import "../reader.ml"
|
||||
|
||||
type decoding_context = DecodingContext of {
|
||||
read_u8 : int -> u8,
|
||||
read_s8 : int -> s8,
|
||||
read_u16 : int -> u16,
|
||||
read_s16 : int -> s16,
|
||||
read_u32 : int -> u32,
|
||||
read_s32 : int -> s32
|
||||
}
|
||||
|
||||
class decode 'a begin
|
||||
val decode : int -> 'a
|
||||
val decode : int -> reader decoding_context 'a
|
||||
end
|
||||
|
||||
instance decode u8 begin
|
||||
let decode addr = Reader (fun (DecodingContext c) -> c.read_u8 addr)
|
||||
end
|
||||
|
||||
instance decode s8 begin
|
||||
let decode addr = Reader (fun (DecodingContext c) -> c.read_s8 addr)
|
||||
end
|
||||
|
||||
instance decode u16 begin
|
||||
let decode addr = Reader (fun (DecodingContext c) -> c.read_u16 addr)
|
||||
end
|
||||
|
||||
instance decode s16 begin
|
||||
let decode addr = Reader (fun (DecodingContext c) -> c.read_s16 addr)
|
||||
end
|
||||
|
||||
instance decode u32 begin
|
||||
let decode addr = Reader (fun (DecodingContext c) -> c.read_u32 addr)
|
||||
end
|
||||
|
||||
instance decode s32 begin
|
||||
let decode addr = Reader (fun (DecodingContext c) -> c.read_s32 addr)
|
||||
end
|
||||
|
|
63
mem/int.ml
63
mem/int.ml
|
@ -1,6 +1,4 @@
|
|||
open import "prelude.ml"
|
||||
open import "./decode.ml"
|
||||
open import "../dolphin.ml"
|
||||
|
||||
type u8 =
|
||||
U8 of int
|
||||
|
@ -9,10 +7,6 @@ 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
|
||||
|
||||
|
@ -20,17 +14,6 @@ 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 > 0xFF then
|
||||
negate (0x100 - u8)
|
||||
else
|
||||
u8
|
||||
S8 signfix
|
||||
end
|
||||
|
||||
type u16 =
|
||||
U16 of int
|
||||
|
||||
|
@ -38,10 +21,6 @@ instance show u16 begin
|
|||
let show (U16 x) = (show x) ^ "_u16"
|
||||
end
|
||||
|
||||
instance decode u16 begin
|
||||
let decode addr = U16 (Dolphin.read_value_16 addr)
|
||||
end
|
||||
|
||||
type s16 =
|
||||
S16 of int
|
||||
|
||||
|
@ -49,17 +28,6 @@ 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 > 0xFFFF then
|
||||
negate (0x10000 - u16)
|
||||
else
|
||||
u16
|
||||
S16 signfix
|
||||
end
|
||||
|
||||
type u32 =
|
||||
U32 of int
|
||||
|
||||
|
@ -67,10 +35,6 @@ instance show u32 begin
|
|||
let show (U32 x) = (show x) ^ "_u32"
|
||||
end
|
||||
|
||||
instance decode u32 begin
|
||||
let decode addr = U32 (Dolphin.read_value_32 addr)
|
||||
end
|
||||
|
||||
type s32 =
|
||||
S32 of int
|
||||
|
||||
|
@ -78,13 +42,20 @@ instance show s32 begin
|
|||
let show (S32 x) = (show x) ^ "_s32"
|
||||
end
|
||||
|
||||
instance decode s32 begin
|
||||
let decode addr =
|
||||
let u32 = Dolphin.read_value_32 addr
|
||||
let signfix =
|
||||
if u32 > 0xFFFFFFFF then
|
||||
negate (0x100000000 - u32)
|
||||
else
|
||||
u32
|
||||
S32 signfix
|
||||
end
|
||||
let u8_to_s8 (U8 u8) =
|
||||
if u8 > 0x7F then
|
||||
S8 (0x100 - u8)
|
||||
else
|
||||
S8 u8
|
||||
|
||||
let u16_to_s16 (U16 u16) =
|
||||
if u16 > 0x7FFF then
|
||||
S16 (0x10000 - u16)
|
||||
else
|
||||
S16 u16
|
||||
|
||||
let u32_to_s32 (U32 u32) =
|
||||
if u32 > 0x7FFFFFFF then
|
||||
S32 (0x100000000 - u32)
|
||||
else
|
||||
S32 u32
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue