Commits

Brian McKenna committed 48be470

Change to a keyboard example

  • Participants
  • Parent commits a2936e3

Comments (0)

Files changed (3)

 		-ffast-math \
 		$(ARCH)
 
-CFLAGS	+=	$(INCLUDE) -DARM9 -DNDS -D__BYTE_ORDER=__LITTLE_ENDIAN -std=gnu99 -marm -D_JHC_GC=_JHC_GC_JGC
+CFLAGS	+=	$(INCLUDE) -DARM9 -D__BYTE_ORDER=__LITTLE_ENDIAN -std=gnu99 -marm -D_JHC_GC=_JHC_GC_JGC
 CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions
 
 ASFLAGS	:=	-g $(ARCH)

File source/Keyboard.hs

+import Foreign.Ptr
+
+foreign import ccall "nds.h consoleDemoInit" consoleDemoInit :: IO ()
+foreign import ccall "nds.h swiWaitForVBlank" swiWaitForVBlank :: IO ()
+
+foreign import ccall "nds.h keyboardDemoInit" keyboardDemoInit :: IO ()
+foreign import ccall "nds.h keyboardShow" keyboardShow :: IO ()
+foreign import ccall "nds.h keyboardUpdate" keyboardUpdate :: IO Int
+
+foreign import ccall "nds.h soundEnable" soundEnable :: IO ()
+foreign import ccall "nds.h soundPlayPSG" soundPlayPSG :: Int -> Int -> Int -> Int -> IO Int
+foreign import ccall "nds.h soundSetFreq" soundSetFreq :: Int -> Int -> IO ()
+
+foreign import primitive "const.DutyCycle_50" dutyCycle_50 :: Int
+
+keyLoop sound = do
+  x <- keyboardUpdate
+  if x > 0 then do
+    soundSetFreq sound $ x * 142
+    putChar $ chr x
+  else
+    return ()
+  swiWaitForVBlank
+  keyLoop sound
+
+main = do
+  consoleDemoInit
+  keyboardDemoInit
+  keyboardShow
+  soundEnable
+  sound <- soundPlayPSG dutyCycle_50 10000 127 64
+  keyLoop sound

File source/Print.hs

-foreign import ccall "nds.h consoleDemoInit" consoleDemoInit :: IO ()
-foreign import ccall "nds.h swiWaitForVBlank" swiWaitForVBlank :: IO ()
-
-memoized_fib =
-  let fib 0 = 0
-      fib 1 = 1
-      fib n = memoized_fib (n-2) + memoized_fib (n-1)
-  in  (map fib [0..] !!)
-
-printFib n = do
-  putStr "fib "
-  putStr $ show n
-  putStr " = "
-  putStr $ show $ memoized_fib n
-  putStrLn ""
-
-main = do
-  consoleDemoInit
-  mapM_ printFib [0..22]
-  swiWaitForVBlank