Pierre Surply avatar Pierre Surply committed 4ef57d6

Added sound

Comments (0)

Files changed (4)

Binary file added.

 ## <pierre.surply@gmail.com>
 ## 
 ## Started on  Sat Aug  4 20:55:40 2012 Pierre Surply
-## Last update Sun Aug  5 18:31:52 2012 Pierre Surply
+## Last update Mon Aug  6 11:15:50 2012 Pierre Surply
 ##
 
 EXECDIR = ..
 RESULT  = $(EXECDIR)/ocaml-chip8
 SOURCES = option.ml display.ml events.ml opcode.ml chip8.ml font.ml interpreter.ml main.ml
-LIBS    = bigarray sdl sdlloader
+LIBS    = bigarray sdl sdlloader sdlmixer
 INCDIRS = +sdl
 
 include OCamlMakefile
 ** <pierre.surply@gmail.com>
 ** 
 ** Started on  Sat Aug  4 21:06:50 2012 Pierre Surply
-** Last update Sun Aug  5 18:11:13 2012 Pierre Surply
+** Last update Mon Aug  6 10:57:18 2012 Pierre Surply
 *)
 
 open Opcode
   chip8.v.(x) <- (Random.int 256) land kk
 
 let drw_vx_vy_nibble x y n = 
-  (*chip8.v.(0xF) <- 0;
-  for k = 0 to n-1 do
-    let code = chip8.mem.(chip8.i+k) in
-    let py = (chip8.v.(y)+k) mod h in
-    for j = 0 to 7 do
-      let px = (chip8.v.(x)+j) mod w in
-      let b = code land (1 lsl (7-j)) != 0 in
-      let lp = display.pixels.(px + py*w) in
-      display.pixels.(px + py*w) <- b;
-      if display.pixels.(px + py*w) != lp then
-	chip8.v.(0xF) <- 1
-    done
-  done*)
   chip8.v.(0xF) <- 0;
   for k = 0 to n-1 do
     let code = chip8.mem.(chip8.i+k) in
 ** <pierre.surply@gmail.com>
 ** 
 ** Started on  Sat Aug  4 20:56:34 2012 Pierre Surply
-** Last update Sun Aug  5 23:45:00 2012 Pierre Surply
+** Last update Mon Aug  6 11:15:20 2012 Pierre Surply
 *)
 
 open Chip8
 let debug = false
 
 let init_sdl () = 
-  Sdl.init [`VIDEO]
+  Sdl.init [`VIDEO; `AUDIO];
+  Sdlmixer.open_audio ()
 
 let quit_sdl () = 
-  Sdl.quit ()
+  Sdl.quit ();
+  Sdlmixer.close_audio
 
 let main () = 
   init_sdl ();
     load_game Sys.argv.(1)
   else
     failwith "Usage : ./ocaml-chip8 ROM";
+
+  let beep = Sdlmixer.loadWAV "res/beep.wav" in
   
   while not(events.quit) do
     update_events ();
       print_debug ();
     update_screen ();
     Sdltimer.delay(fps);
+
+    if chip8.st > 0 then
+      Sdlmixer.play_sound beep;
     count ();
   done;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.