-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPad.hs
43 lines (35 loc) · 760 Bytes
/
Pad.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
module Pad (
Pad(..),
padU, padD, padL, padR, padA, padB,
initialPad,
updatePad,
pressing,
justPressed
) where
import Data.Bits ((.&.), complement, shiftL)
-- Pad
data Pad = Pad {
curr :: Int,
prev :: Int
}
initialPad :: Pad
initialPad = Pad { curr = complement 0, prev = complement 0 }
padU, padD, padL, padR, padA, padB :: Int
padU = 1 `shiftL` 0
padD = 1 `shiftL` 1
padL = 1 `shiftL` 2
padR = 1 `shiftL` 3
padA = 1 `shiftL` 4
padB = 1 `shiftL` 5
updatePad :: Pad -> Int -> Pad
updatePad opad btn =
Pad {
curr = btn,
prev = curr opad
}
pressing :: Pad -> Int -> Bool
pressing pad btn = (curr pad .&. btn) /= 0
justPressed :: Pad -> Int -> Bool
justPressed pad btn = (trg .&. btn) /= 0
where
trg = curr pad .&. complement (prev pad)