diff options
author | Jörg Hohensohn <hohensoh@rockbox.org> | 2004-01-30 22:43:37 +0000 |
---|---|---|
committer | Jörg Hohensohn <hohensoh@rockbox.org> | 2004-01-30 22:43:37 +0000 |
commit | 25a1add8cf8486b2297f2e62aaf1e0d4adca013e (patch) | |
tree | 077e15267954fbb02a5857e9a82f12142db7576d /apps/plugins | |
parent | 95298a955846d59a7758076a56df12f9996fc0bd (diff) | |
download | rockbox-25a1add8cf8486b2297f2e62aaf1e0d4adca013e.tar.gz rockbox-25a1add8cf8486b2297f2e62aaf1e0d4adca013e.zip |
first game with sound: chip8 makes noise
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4286 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/chip8.c | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/apps/plugins/chip8.c b/apps/plugins/chip8.c index d19e03d762..c08079584e 100644 --- a/apps/plugins/chip8.c +++ b/apps/plugins/chip8.c | |||
@@ -61,15 +61,46 @@ static byte chip8_running; /* Flag for End-of-Emulation */ | |||
61 | typedef void (*opcode_fn) (word opcode); | 61 | typedef void (*opcode_fn) (word opcode); |
62 | typedef void (*math_fn) (byte *reg1,byte reg2); | 62 | typedef void (*math_fn) (byte *reg1,byte reg2); |
63 | 63 | ||
64 | static bool is_playing; | ||
65 | |||
66 | /* one frame of bitswapped mp3 data */ | ||
67 | static unsigned char beep[]={255, | ||
68 | 223, 28, 35, 0,192,210, 35,226, 72,188,242, 1,128,166, 16, 68,146,252,151, 19, | ||
69 | 10,180,245,127, 96,184, 3,184, 30, 0,118, 59,128,121,102, 6,212, 0, 97, 6, | ||
70 | 42, 65, 28,134,192,145, 57, 38,136, 73, 29, 38,132, 15, 21, 70, 91,185, 99,198, | ||
71 | 15,192, 83, 6, 33,129, 20, 6, 97, 33, 4, 6,245,128, 92, 6, 24, 0, 86, 6, | ||
72 | 56,129, 44, 24,224, 25, 13, 48, 50, 82,180, 11,251,106,249, 59, 24, 82,175,223, | ||
73 | 252,119, 76,134,120,236,149,250,247,115,254,145,173,174,168,180,255,107,195, 89, | ||
74 | 24, 25, 48,131,192, 61, 48, 64, 10,176, 49, 64, 1,152, 50, 32, 8,140, 48, 16, | ||
75 | 5,129, 51,196,187, 41,177, 23,138, 70, 50, 8, 10,242, 48,192, 3,248,226, 0, | ||
76 | 20,100, 18, 96, 41, 96, 78,102, 7,201,122, 76,119, 20,137, 37,177, 15,132,224, | ||
77 | 20, 17,191, 67,147,187,116,211, 41,169, 63,172,182,186,217,155,111,140,104,254, | ||
78 | 111,181,184,144, 17,148, 21,101,166,227,100, 86, 85, 85, 85}; | ||
79 | |||
80 | /* callback to request more mp3 data */ | ||
81 | void callback(unsigned char** start, int* size) | ||
82 | { | ||
83 | *start = beep; /* give it the same frame again */ | ||
84 | *size = sizeof(beep); | ||
85 | } | ||
86 | |||
64 | /****************************************************************************/ | 87 | /****************************************************************************/ |
65 | /* Turn sound on */ | 88 | /* Turn sound on */ |
66 | /****************************************************************************/ | 89 | /****************************************************************************/ |
67 | static void chip8_sound_on (void) { } | 90 | static void chip8_sound_on (void) |
91 | { | ||
92 | if (!is_playing) | ||
93 | rb->mp3_play_pause(true); /* kickoff audio */ | ||
94 | } | ||
68 | 95 | ||
69 | /****************************************************************************/ | 96 | /****************************************************************************/ |
70 | /* Turn sound off */ | 97 | /* Turn sound off */ |
71 | /****************************************************************************/ | 98 | /****************************************************************************/ |
72 | static void chip8_sound_off (void) { } | 99 | static void chip8_sound_off (void) |
100 | { | ||
101 | if (!is_playing) | ||
102 | rb->mp3_play_pause(false); /* pause audio */ | ||
103 | } | ||
73 | 104 | ||
74 | static void op_call (word opcode) | 105 | static void op_call (word opcode) |
75 | { | 106 | { |
@@ -430,8 +461,9 @@ static void chip8_execute(void) | |||
430 | --chip8_regs.delay; | 461 | --chip8_regs.delay; |
431 | 462 | ||
432 | if (chip8_regs.sound) | 463 | if (chip8_regs.sound) |
433 | --chip8_regs.sound; /* How could we make sound on the archos? */ | 464 | if (--chip8_regs.sound == 0) /* Update the machine status */ |
434 | /* Update the machine status */ | 465 | chip8_sound_off(); |
466 | |||
435 | chip8_update_display(); | 467 | chip8_update_display(); |
436 | chip8_keyboard(); | 468 | chip8_keyboard(); |
437 | rb->yield(); /* we should regulate the speed by timer query, sleep/yield */ | 469 | rb->yield(); /* we should regulate the speed by timer query, sleep/yield */ |
@@ -517,9 +549,24 @@ bool chip8_run(char* file) | |||
517 | rb->lcd_clear_display(); | 549 | rb->lcd_clear_display(); |
518 | rb->lcd_drawrect(23,0,66,64); | 550 | rb->lcd_drawrect(23,0,66,64); |
519 | rb->lcd_update(); | 551 | rb->lcd_update(); |
552 | |||
553 | /* init sound */ | ||
554 | is_playing = rb->mp3_is_playing(); /* would we disturb playback? */ | ||
555 | if (!is_playing) /* no? then we can make sound */ | ||
556 | { /* prepare */ | ||
557 | rb->mp3_play_init(); | ||
558 | rb->mp3_play_data(beep, sizeof(beep), callback); | ||
559 | rb->mpeg_sound_set(SOUND_VOLUME, rb->global_settings->volume); | ||
560 | } | ||
561 | |||
520 | chip8_reset(); | 562 | chip8_reset(); |
521 | while (chip8_running) chip8_execute(); | 563 | while (chip8_running) chip8_execute(); |
522 | 564 | ||
565 | if (!is_playing) | ||
566 | { /* stop it if we used audio */ | ||
567 | rb->mp3_play_stop(); // stop audio ISR | ||
568 | } | ||
569 | |||
523 | return true; | 570 | return true; |
524 | } | 571 | } |
525 | 572 | ||