gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/examples/megaduck/laptop_speech/src/main.c
1 #include <gbdk/platform.h>
2 #include <gbdk/console.h>
3 #include <gb/isr.h>
4
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include <stdio.h>
8
9 #include <duck/laptop_io.h>
10
11
12 // Send a request for the Laptop Hardware to play one of 6 pre-recorded Speech Phrases
13 //
14 // The input range is 1-6 (DUCK_IO_SPEECH_CMD_MIN - DUCK_IO_SPEECH_CMD_MAX)
15 // Playback of one sample can be interrupted by request for playback of another sample
16 //
17 //
18 // # Spanish Model Phrases
19 // - 1. "Genial" (brilliant)
20 // - 2. "Estupendo" (great)
21 // - 3. "Fantástico" (fantastic)
22 // - 4. "No, inténtalo otra vez." (no, try it again)
23 // - 5. "No, prueba una vez más" (no, try once again)
24 // - 6. "Vuelve a intentarlo" (try again)
25 //
26 // # German Model Phrases
27 // - 1. "Ja, sehr gut" (yes, very good)
28 // - 2. "Gut gemacht" (well done)
29 // - 3. "Super" (great, awesome)
30 // - 4. "Uh uh, probier's noch mal" (uh oh, try again)
31 // - 5. "Uh uh, versuch's noch einmal" (give it another try)
32 // - 6. "Oooh, schade" (ohh, what a pity)
33 //
34 // Returns success or failure
35 bool duck_io_send_speech_cmd(uint8_t speech_sample_num) {
36
37 duck_io_tx_buf[0] = speech_sample_num;
38 duck_io_tx_buf_len = DUCK_IO_LEN_PLAY_SPEECH;
39
40 if (duck_io_send_cmd_and_buffer(DUCK_IO_CMD_PLAY_SPEECH)) {
41 return true;
42 } else {
43 return false;
44 }
45 }
46
47
48
49 void main(void) {
50
51 uint8_t gamepad;
52 uint8_t speech_num = 1u;
53
54 bool megaduck_laptop_init_ok = duck_io_laptop_init();
55
56 SPRITES_8x8;
57 SHOW_SPRITES;
58 SHOW_BKG;
59 printf("Initializing..\n");
60
61 if (!megaduck_laptop_init_ok) {
62 // If laptop hardware is not present then there isn't anything
63 // for this program to do, so just idle in a loop
64 printf("Laptop not detected\n"
65 "or Failed to Initialize");
66 while(1) {
67 vsync();
68 }
69 }
70
71 // Otherwise laptop init succeeded
72 printf("Laptop Detected!\n");
73
74 printf("\n"
75 "Play built-in speech\n"
76 "\n"
77 "*START:start speech\n"
78 "*UP/DOWN change num\n");
79
80 gotoxy(0,10); printf("Play Num:%d ", speech_num);
81
82 while(1) {
83 vsync();
84 gamepad = joypad();
85
86 // It is not necessary to turn on audio to play the pre-recorded Speech Phrases
87
88 // Laptop serial command intervals below 20 msec may cause laptop hardware lockup
89 // Poll for RTC every other frame (~32 msec)
90 if (sys_time & 0x01u) {
91
92 if (gamepad) {
93
94 switch (gamepad) {
95 case J_UP:
96 if (speech_num < DUCK_IO_SPEECH_CMD_MAX) speech_num++;
97 gotoxy(0,10); printf("Play Num:%d ", speech_num);
98 break;
99
100 case J_DOWN:
101 if (speech_num > DUCK_IO_SPEECH_CMD_MIN) speech_num--;
102 gotoxy(0,10); printf("Play Num:%d ", speech_num);
103 break;
104
105 case J_START:
106 if (duck_io_send_speech_cmd(speech_num)) {
107 gotoxy(0,11);
108 printf("Speech OK \n");
109 } else {
110 gotoxy(0,11);
111 printf("Speech FAIL\n");
112 }
113 break;
114 }
115
116 // Wait for all buttons to be released before continuing
117 waitpadup();
118 }
119 }
120 }
121 }
122
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.