Fixes Int to CInt issue; pixel;clear;draw;
[qpawn.git] / QPawn.hs
blob6de9d922be5c2949c56ebbc310d4951f9afee290
1 {-# LANGUAGE ForeignFunctionInterface #-}
3 module Main where
5 import Foreign
6 import Foreign.C.Types
7 import Data.Int
9 -- | foreign imports
10 foreign import ccall "qpawn.c init"
11 c_init :: IO ()
13 foreign import ccall "qpawn.c quit"
14 c_quit :: IO ()
16 foreign import ccall "qpawn.c clear"
17 c_clear :: IO ()
19 foreign import ccall "qpawn.c draw"
20 c_draw :: IO ()
22 foreign import ccall "qpawn.c pixel"
23 c_pixel :: CInt -> CInt -> IO ()
25 foreign import ccall "qpawn.c color"
26 c_color :: CInt -> CInt -> CInt -> IO ()
28 foreign import ccall "qpawn.c sleep"
29 c_sleep :: CInt -> IO ()
32 -- | actual code
33 -- hide this one from module?
34 cint :: (Integral a) => a -> CInt
35 cint n = (fromIntegral n) :: CInt
37 color :: Int -> Int -> Int -> IO ()
38 color r g b = c_color r' g' b'
39 where (r', g', b') = (cint r, cint g, cint b)
41 pixel :: Int32 -> Int32 -> IO ()
42 pixel x y = c_pixel x' y'
43 where (x', y') = (cint x, cint y)
45 clear :: IO ()
46 clear = c_clear
48 sleep :: Int -> IO ()
49 sleep = c_sleep . cint
51 draw :: IO ()
52 draw = c_draw
54 main :: IO ()
55 main = do c_init
56 color 0 0 0
57 clear
58 draw
59 sleep 2
60 color 255 255 255
61 clear
62 draw
63 sleep 2
64 c_quit