Subversion Repositories freemyipod

Rev

Rev 717 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
714 user890104 1
//
2
//
3
//    Copyright 2011 TheSeven, user890104
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "emcoreapp.h"
25
#include "beep.h"
26
 
716 user890104 27
struct note
28
{
29
    unsigned int cycles;
30
    unsigned int length;
31
};
714 user890104 32
 
33
static void main()
34
{
35
    if (0x47324e49 != get_platform_id()) // IN2G
36
    {
37
        cputs(3, "Your device is not supported!\n");
38
        return;
39
    }
40
 
41
    size_t size;
42
    int fd;
716 user890104 43
    struct note *buf;
44
    unsigned int i, count;
714 user890104 45
 
753 user890104 46
    fd = file_open("/.apps/beeper/song.dat", O_RDONLY);
714 user890104 47
 
48
    if (fd <= 0)
49
    {
753 user890104 50
        cputs(3, "Unable to open /.apps/beeper/song.dat!\n");
714 user890104 51
        return;
52
    }
53
 
54
    cputs(3, "File opened\n");
55
    size = filesize(fd);
56
 
716 user890104 57
    if (0 == size)
714 user890104 58
    {
59
        close(fd);
60
        cputs(3, "Unable to get file size or file is empty!\n");
61
        return;
62
    }
63
 
64
    cprintf(3, "File size: %d bytes\n", size);
65
 
66
    if (0 != size % 8)
67
    {
68
        close(fd);
69
        cputs(3, "Invalid file, unable to continue!\n");
70
        return;
71
    }
72
 
73
    buf = memalign(0x10, size);
716 user890104 74
 
714 user890104 75
    if (!buf)
76
    {
77
        close(fd);
78
        cputs(3, "Memory allocation failed!\n");
79
        return;
80
    }
81
 
82
    if (size != read(fd, buf, size))
83
    {
84
        free(buf);
85
        close(fd);
86
        cputs(3, "Read error!\n");
87
        return;
88
    }
89
 
90
    cputs(3, "Read successful\n");
91
    close(fd);
92
    cputs(3, "File closed\n");
93
 
715 user890104 94
    count = size / 8;
95
 
96
    for (i = 0; i < count; ++i)
714 user890104 97
    {
717 user890104 98
        if (0 == buf[i].cycles)
714 user890104 99
        {
716 user890104 100
            sleep(buf[i].length);
714 user890104 101
            continue;
102
        }
103
 
716 user890104 104
        singlebeep(buf[i].cycles, buf[i].length);
714 user890104 105
    }
715 user890104 106
 
716 user890104 107
    free(buf);
714 user890104 108
}
109
 
110
EMCORE_APP_HEADER("Beeper", main, 127)