Skip to content

Commit

Permalink
Add > and <=
Browse files Browse the repository at this point in the history
Found out by Tobias Bäumer.
  • Loading branch information
nomeata committed Jan 12, 2015
1 parent 472f3cf commit 7c01b09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
14 changes: 8 additions & 6 deletions GME-Format.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ The conditionals are of the format `t1 aaaa cccc t2 bbbb`
* `t1` & `t2` (uint8) type of `a` and `b` resp. (0 == register, 1 == value)
* `a` & `b` (uint16) value or id of register
* `c` (uint16) is the comparison operator
The rest of the line is only considered when the comparison between the
register and the value or other register holds.

Known comparison operators are:
* `FFF9` equal == (written `$r==m?` in decode's output): Only continue with this line if register `$r` has value `m`.
* `FFFB` lesser < (written `$r<m?` in decode's output): Only continue with this line if register `$r` has a value lower than `m`.
* `FFFD` greater or equal >= (written `$r>=m?` in decode's output): Only continue with this line if register `$r` has a value greater or equal `m`.
* `FFFF` not equal != (written `$r!=m?` in decode's output): Only continue with this line if register `$r` has not value `m`.

Currently unknown comparison operators are `FFFA` & `FFFE`.
* `FFF9` (written `$r==m?` in decode's output and the yaml files): Equality
* `FFFA` (written `$r>m?` in decode's output): Greather than
* `FFFB` (written `$r<m?` in decode's output): Less than
* `FFFD` (written `$r>=m?` in decode's output): Greater or equal
* `FFFE` (written `$r<=?` in decode's output): Less or equal
* `FFFF` (written `$r!=m?` in decode's output): Not equal

The actions are of the format `rrrr cccc tt mmmm`
* `r` (uint16) id of register
Expand Down
22 changes: 15 additions & 7 deletions tttool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ data Conditional r = Cond (TVal r) CondOp (TVal r)

data CondOp
= Eq
| NEq
| Gt
| Lt
| GEq
| LEq
| NEq
| Unknowncond B.ByteString
deriving (Eq)

Expand Down Expand Up @@ -288,8 +290,10 @@ putTVal (Const n) = do

putCondOp :: CondOp -> SPut
putCondOp Eq = mapM_ putWord8 [0xF9, 0xFF]
putCondOp Gt = mapM_ putWord8 [0xFA, 0xFF]
putCondOp Lt = mapM_ putWord8 [0xFB, 0xFF]
putCondOp GEq = mapM_ putWord8 [0xFD, 0xFF]
putCondOp LEq = mapM_ putWord8 [0xFE, 0xFF]
putCondOp NEq = mapM_ putWord8 [0xFF, 0xFF]
putCondOp (Unknowncond b) = putBS b

Expand Down Expand Up @@ -503,10 +507,12 @@ lineParser = begin
fail $ printf "At position 0x%08X, expected %d/%02X, got %d/%02X" (b-1) n n n' n'

conditionals =
[ (B.pack [0xF9,0xFF], Eq )
, (B.pack [0xFF,0xFF], NEq )
, (B.pack [0xFB,0xFF], Lt )
, (B.pack [0xFD,0xFF], GEq )
[ (B.pack [0xF9,0xFF], Eq)
, (B.pack [0xFA,0xFF], Gt)
, (B.pack [0xFB,0xFF], Lt)
, (B.pack [0xFD,0xFF], GEq)
, (B.pack [0xFE,0xFF], LEq)
, (B.pack [0xFF,0xFF], NEq)
]

actions =
Expand Down Expand Up @@ -1401,10 +1407,12 @@ parseTVal = (Reg <$> parseReg <|> Const <$> parseWord16) <?> "Value"
parseCondOp :: Parser CondOp
parseCondOp = choice
[ P.reservedOp lexer "==" >> return Eq
, P.reservedOp lexer "/=" >> return NEq
, P.reservedOp lexer "!=" >> return NEq
, P.reservedOp lexer "<" >> return Lt
, P.reservedOp lexer ">" >> return Gt
, P.reservedOp lexer ">=" >> return GEq
, P.reservedOp lexer "<=" >> return LEq
, P.reservedOp lexer "/=" >> return NEq
, P.reservedOp lexer "!=" >> return NEq
]

parseInitRegs :: Parser [(Register, Word16)]
Expand Down

0 comments on commit 7c01b09

Please sign in to comment.