From e5eaac83739396898e8064efb373c4b6332f2771 Mon Sep 17 00:00:00 2001 From: matheusanmo Date: Sat, 9 Jun 2018 14:50:27 +0000 Subject: [PATCH] Fixes Int to CInt issue; pixel;clear;draw; --- Makefile | 2 +- QPawn.hs | 23 ++++++++++++++++------- qpawn.c | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c2e5597..815abde 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,4 @@ qpawn.o: qpawn.c gcc -Wall -I/usr/include/SDL2 -lSDL2 -c qpawn.c clean: - rm qpwn *.o *.hi + rm qpwn *.o *.hi *.hc diff --git a/QPawn.hs b/QPawn.hs index 86b052a..6de9d92 100644 --- a/QPawn.hs +++ b/QPawn.hs @@ -16,8 +16,8 @@ foreign import ccall "qpawn.c quit" foreign import ccall "qpawn.c clear" c_clear :: IO () -foreign import ccall "qpawn.c show" - c_show :: IO () +foreign import ccall "qpawn.c draw" + c_draw :: IO () foreign import ccall "qpawn.c pixel" c_pixel :: CInt -> CInt -> IO () @@ -30,26 +30,35 @@ foreign import ccall "qpawn.c sleep" -- | actual code -color :: Int32 -> Int32 -> Int32 -> IO () +-- hide this one from module? +cint :: (Integral a) => a -> CInt +cint n = (fromIntegral n) :: CInt + +color :: Int -> Int -> Int -> IO () color r g b = c_color r' g' b' - where (r', g', b') = fmap CInt (r, g, b) + where (r', g', b') = (cint r, cint g, cint b) pixel :: Int32 -> Int32 -> IO () pixel x y = c_pixel x' y' - where (x', y') = fmap CInt (x,y) + where (x', y') = (cint x, cint y) clear :: IO () clear = c_clear -sleep :: Int32 -> IO () -sleep = c_sleep . CInt +sleep :: Int -> IO () +sleep = c_sleep . cint + +draw :: IO () +draw = c_draw main :: IO () main = do c_init color 0 0 0 clear + draw sleep 2 color 255 255 255 clear + draw sleep 2 c_quit diff --git a/qpawn.c b/qpawn.c index a548e82..104b233 100644 --- a/qpawn.c +++ b/qpawn.c @@ -16,7 +16,7 @@ void quit(); void pixel(int, int); void color(int, int, int); void clear(); -void show(); +void draw(); void sleep(int); struct event* events(); @@ -60,7 +60,7 @@ void pixel(int x, int y) SDL_RenderDrawPoint(renderer, x, y); } -void show() +void draw() { SDL_RenderPresent(renderer); } -- 2.11.4.GIT