Skip to content

Commit

Permalink
Handle and store arguments to FFE1 and FFE0
Browse files Browse the repository at this point in the history
but still hard-code the first (register) argument to $0. This fixes #130
and #131.
  • Loading branch information
nomeata committed Apr 14, 2016
1 parent 07874c7 commit ff40f93
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/GMEParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ lineParser = begin
actions =
[ (B.pack [0xE0,0xFF], \r -> do
unless (r == 0) $ fail "Non-zero register for RandomVariant command"
Const 0x0000 <- getTVal
return RandomVariant)
v <- getTVal
return (RandomVariant v))
, (B.pack [0xE1,0xFF], \r -> do
unless (r == 0) $ fail "Non-zero register for PlayAllVariant command"
Const 0x0000 <- getTVal
return PlayAllVariant)
v <- getTVal
return (PlayAllVariant v))
, (B.pack [0xE8,0xFF], \r -> do
unless (r == 0) $ fail "Non-zero register for Play command"
Const n <- getTVal
Expand Down
8 changes: 4 additions & 4 deletions src/GMEWriter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ putCommand (Neg r) = do
putWord16 r
mapM_ putWord8 [0xF8, 0xFF]
putTVal (Const 0)
putCommand RandomVariant = do
putCommand (RandomVariant v) = do
putWord16 0
mapM_ putWord8 [0xE0, 0xFF]
putTVal (Const 0)
putCommand PlayAllVariant = do
putTVal v
putCommand (PlayAllVariant v) = do
putWord16 0
mapM_ putWord8 [0xE1, 0xFF]
putTVal (Const 0)
putTVal v
putCommand (Play n) = do
putWord16 0
mapM_ putWord8 [0xE8, 0xFF]
Expand Down
8 changes: 5 additions & 3 deletions src/PrettyPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ groupRuns l = go
r -> Right [x] : r

ppPlayList :: Transscript -> PlayList -> String
ppPlayList t xs = "[" ++ commas (map go (groupRuns (flip M.lookup t) xs)) ++ "]"
ppPlayList t xs = "[" ++ commas (map go (groupRuns (`M.lookup` t) xs)) ++ "]"
where go (Left s) = quote s
go (Right []) = error "Empty list in groupRuns result"
go (Right l) | length l > 3 = show (head l) ++ ".." ++ show (last l)
Expand Down Expand Up @@ -111,8 +111,10 @@ ppCommand True t xs p
ppCommand _ t xs (Play n) = printf "P(%s)" $ ppPlayIndex t xs (fromIntegral n)
ppCommand _ t xs (Random a b) = printf "P(%s)" $ ppPlayRange t xs [b..a]
ppCommand _ t xs (PlayAll a b) = printf "PA(%s)" $ ppPlayRange t xs [b..a]
ppCommand _ t xs PlayAllVariant = printf "PA*(%s)" $ ppPlayAll t xs
ppCommand _ t xs RandomVariant = printf "P*(%s)" $ ppPlayAll t xs
ppCommand _ t xs (PlayAllVariant (Const 0)) = printf "PA*(%s)" (ppPlayAll t xs)
ppCommand _ t xs (PlayAllVariant v) = printf "PA*(%s)(%s)" (ppPlayAll t xs) (ppTVal v)
ppCommand _ t xs (RandomVariant (Const 0)) = printf "P*(%s)" (ppPlayAll t xs)
ppCommand _ t xs (RandomVariant v) = printf "P*(%s)(%s)" (ppPlayAll t xs) (ppTVal v)
ppCommand _ t xs Cancel = printf "C"
ppCommand _ t xs (Jump v) = printf "J(%s)" (ppTVal v)
ppCommand _ t xs (Timer r v) = printf "T(%s,%s)" (ppReg r) (ppTVal v)
Expand Down
5 changes: 3 additions & 2 deletions src/TipToiYaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -963,13 +963,14 @@ parseCommands i =
withStar <- optionBool (char '*')
return (withA, withStar)
fns <- P.parens lexer $ P.commaSep1 lexer parseAudioRef
playAllUnknownArgument <- option (Const 0) $ P.parens lexer $ parseTVal
let n = length fns
let c = case (withA, withStar, fns) of
(False, False, [fn]) -> Play (fromIntegral i)
(False, False, _) -> Random (fromIntegral (i + n - 1)) (fromIntegral i)
(True, False, _) -> PlayAll (fromIntegral (i + n - 1)) (fromIntegral i)
(False, True, _) -> RandomVariant
(True, True, _) -> PlayAllVariant
(False, True, _) -> RandomVariant playAllUnknownArgument
(True, True, _) -> PlayAllVariant playAllUnknownArgument
(cmds, filenames) <- parseCommands (i+n)
return (c : cmds, fns ++ filenames)
, descP "Cancel" $
Expand Down
4 changes: 2 additions & 2 deletions src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ data Command r
= Play Word16
| Random Word8 Word8
| PlayAll Word8 Word8
| PlayAllVariant
| RandomVariant
| PlayAllVariant (TVal r)
| RandomVariant (TVal r)
| Cancel
| Game Word16
| ArithOp ArithOp r (TVal r)
Expand Down

0 comments on commit ff40f93

Please sign in to comment.