forked from entropia/tip-toi-reveng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.hs
109 lines (86 loc) · 2.69 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{-# LANGUAGE DeriveFunctor, DeriveFoldable #-}
module Types
( module Types, Word8, Word16, Word32 )
where
import qualified Data.ByteString.Lazy as B
import Data.Word
import qualified Data.Map as M
import Data.Foldable (Foldable)
-- Main data types
type Offset = Word32
type Segment = (Offset, Word32, [String])
type Segments = [Segment]
data Register = RegPos Word16 | RegName String
deriving (Show, Eq, Ord)
type ResReg = Word16
data TVal r
= Reg r
| Const Word16
deriving (Eq, Functor, Foldable)
data Conditional r = Cond (TVal r) CondOp (TVal r)
deriving (Eq, Functor, Foldable)
data CondOp
= Eq
| Gt
| Lt
| GEq
| LEq
| NEq
| Unknowncond B.ByteString
deriving (Eq)
data ArithOp
= Inc | Dec | Mult | Div | Mod | And | Or | XOr | Set
deriving (Eq, Bounded, Enum)
data Command r
= Play Word16
| Random Word8 Word8
| Cancel
| Game Word16
| ArithOp ArithOp r (TVal r)
| Neg r
| Unknown B.ByteString r (TVal r)
| Jump (TVal r)
| NamedJump String -- Only in YAML files, never read from GMEs
deriving (Eq, Functor, Foldable)
type PlayList = [Word16]
data Line r = Line Offset [Conditional r] [Command r] PlayList
deriving (Functor, Foldable)
type ProductID = Word32
data TipToiFile = TipToiFile
{ ttProductId :: ProductID
, ttRawXor :: Word32
, ttComment :: B.ByteString
, ttDate :: B.ByteString
, ttInitialRegs :: [Word16]
, ttWelcome :: [PlayList]
, ttScripts :: [(Word16, Maybe [Line ResReg])]
, ttGames :: [Game]
, ttAudioFiles :: [B.ByteString]
, ttAudioFilesDoubles :: Bool
, ttAudioXor :: Word8
, ttBinaries1 :: [(B.ByteString, B.ByteString)]
, ttBinaries2 :: [(B.ByteString, B.ByteString)]
, ttBinaries3 :: [(B.ByteString, B.ByteString)]
, ttBinaries4 :: [(B.ByteString, B.ByteString)]
, ttSpecialOIDs :: Maybe (Word16, Word16)
, ttChecksum :: Word32
, ttChecksumCalc :: Word32
}
type PlayListList = [PlayList]
type GameId = Word16
data Game
= Game6 Word16 B.ByteString [PlayListList] [SubGame] [SubGame] B.ByteString [PlayListList] PlayList
| Game7 Word16 Word16 B.ByteString [PlayListList] [SubGame] B.ByteString [PlayListList] PlayListList
| Game8 Word16 Word16 B.ByteString [PlayListList] [SubGame] B.ByteString [PlayListList] [OID] [GameId] PlayListList PlayListList
| Game9
| Game10
| Game16
| Game253
| UnknownGame Word16 Word16 Word16 B.ByteString [PlayListList] [SubGame] B.ByteString [PlayListList]
deriving Show
type OID = Word16
data SubGame
= SubGame B.ByteString [OID] [OID] [OID] [PlayListList]
deriving Show
type Transscript = M.Map Word16 String
type CodeMap = M.Map String Word16