2010-02-14 Samuel Thibault <samuel.thibault@ens-lyon.org>

* commands/i386/pc/play.c (T_REST, T_FINE, struct note, beep_on): Use
	grub_uint16_t instead of short.
	(grub_cmd_play): Use grub_uint32_t instead of int, convert data from
	disk from little endian to cpu endianness.
This commit is contained in:
Samuel Thibault 2010-02-14 17:25:52 +01:00
parent 04459e70a3
commit 14da0fb7e8
2 changed files with 21 additions and 8 deletions

View file

@ -1,3 +1,10 @@
2010-02-14 Samuel Thibault <samuel.thibault@ens-lyon.org>
* commands/i386/pc/play.c (T_REST, T_FINE, struct note, beep_on): Use
grub_uint16_t instead of short.
(grub_cmd_play): Use grub_uint32_t instead of int, convert data from
disk from little endian to cpu endianness.
2010-02-07 Samuel Thibault <samuel.thibault@ens-lyon.org> 2010-02-07 Samuel Thibault <samuel.thibault@ens-lyon.org>
* commands/i386/pc/play.c (BASE_TEMPO): Set to 60 * * commands/i386/pc/play.c (BASE_TEMPO): Set to 60 *

View file

@ -101,13 +101,13 @@
#define PIT_CTRL_COUNT_BINARY 0x00 /* 16-bit binary counter. */ #define PIT_CTRL_COUNT_BINARY 0x00 /* 16-bit binary counter. */
#define PIT_CTRL_COUNT_BCD 0x01 /* 4-decade BCD counter. */ #define PIT_CTRL_COUNT_BCD 0x01 /* 4-decade BCD counter. */
#define T_REST ((short) 0) #define T_REST ((grub_uint16_t) 0)
#define T_FINE ((short) -1) #define T_FINE ((grub_uint16_t) -1)
struct note struct note
{ {
short pitch; grub_uint16_t pitch;
short duration; grub_uint16_t duration;
}; };
static void static void
@ -120,7 +120,7 @@ beep_off (void)
} }
static void static void
beep_on (short pitch) beep_on (grub_uint16_t pitch)
{ {
unsigned char status; unsigned char status;
unsigned int counter; unsigned int counter;
@ -149,7 +149,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
{ {
grub_file_t file; grub_file_t file;
struct note buf; struct note buf;
int tempo; grub_uint32_t tempo;
unsigned int to; unsigned int to;
if (argc != 1) if (argc != 1)
@ -166,12 +166,18 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
"file doesn't even contains a full tempo record"); "file doesn't even contains a full tempo record");
} }
tempo = grub_le_to_cpu32(tempo);
grub_dprintf ("play","tempo = %d\n", tempo); grub_dprintf ("play","tempo = %d\n", tempo);
while (grub_file_read (file, &buf, while (grub_file_read (file, &buf,
sizeof (struct note)) == sizeof (struct note) sizeof (struct note)) == sizeof (struct note))
&& buf.pitch != T_FINE && grub_checkkey () < 0)
{ {
buf.pitch = grub_le_to_cpu16(buf.pitch);
buf.duration = grub_le_to_cpu16(buf.duration);
if (buf.pitch == T_FINE || grub_checkkey () >= 0)
break;
grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch, grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch,
buf.duration); buf.duration);