From 14da0fb7e81cc5f46903201563f8d3302d25a88c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 14 Feb 2010 17:25:52 +0100 Subject: [PATCH] 2010-02-14 Samuel Thibault * 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. --- ChangeLog | 7 +++++++ commands/i386/pc/play.c | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03388c7f3..950a26f3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-02-14 Samuel Thibault + + * 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 * commands/i386/pc/play.c (BASE_TEMPO): Set to 60 * diff --git a/commands/i386/pc/play.c b/commands/i386/pc/play.c index 04bf8625d..84819b551 100644 --- a/commands/i386/pc/play.c +++ b/commands/i386/pc/play.c @@ -101,13 +101,13 @@ #define PIT_CTRL_COUNT_BINARY 0x00 /* 16-bit binary counter. */ #define PIT_CTRL_COUNT_BCD 0x01 /* 4-decade BCD counter. */ -#define T_REST ((short) 0) -#define T_FINE ((short) -1) +#define T_REST ((grub_uint16_t) 0) +#define T_FINE ((grub_uint16_t) -1) struct note { - short pitch; - short duration; + grub_uint16_t pitch; + grub_uint16_t duration; }; static void @@ -120,7 +120,7 @@ beep_off (void) } static void -beep_on (short pitch) +beep_on (grub_uint16_t pitch) { unsigned char status; unsigned int counter; @@ -149,7 +149,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), { grub_file_t file; struct note buf; - int tempo; + grub_uint32_t tempo; unsigned int to; 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"); } + tempo = grub_le_to_cpu32(tempo); + grub_dprintf ("play","tempo = %d\n", tempo); while (grub_file_read (file, &buf, - sizeof (struct note)) == sizeof (struct note) - && buf.pitch != T_FINE && grub_checkkey () < 0) + sizeof (struct note)) == sizeof (struct note)) { + 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, buf.duration);