Merge mainline into cleanbuild
This commit is contained in:
commit
016a671b51
89 changed files with 1402 additions and 929 deletions
|
@ -41,7 +41,7 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
|
|||
|
||||
file = grub_gzfile_open (args[0], 1);
|
||||
if (! file)
|
||||
return 0;
|
||||
return grub_errno;
|
||||
|
||||
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0
|
||||
&& key != GRUB_TERM_ESC)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#define BASE_TEMPO 120
|
||||
#define BASE_TEMPO (60 * GRUB_TICKS_PER_SECOND)
|
||||
|
||||
/* The speaker port. */
|
||||
#define SPEAKER 0x61
|
||||
|
@ -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;
|
||||
|
@ -143,60 +143,111 @@ beep_on (short pitch)
|
|||
grub_outb (status | SPEAKER_TMR2 | SPEAKER_DATA, SPEAKER);
|
||||
}
|
||||
|
||||
/* Returns whether playing should continue. */
|
||||
static int
|
||||
play (unsigned tempo, struct note *note)
|
||||
{
|
||||
unsigned int to;
|
||||
|
||||
if (note->pitch == T_FINE || grub_checkkey () >= 0)
|
||||
return 1;
|
||||
|
||||
grub_dprintf ("play", "pitch = %d, duration = %d\n", note->pitch,
|
||||
note->duration);
|
||||
|
||||
switch (note->pitch)
|
||||
{
|
||||
case T_REST:
|
||||
beep_off ();
|
||||
break;
|
||||
|
||||
default:
|
||||
beep_on (note->pitch);
|
||||
break;
|
||||
}
|
||||
|
||||
to = grub_get_rtc () + BASE_TEMPO * note->duration / tempo;
|
||||
while (((unsigned int) grub_get_rtc () <= to) && (grub_checkkey () < 0))
|
||||
;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
{
|
||||
grub_file_t file;
|
||||
struct note buf;
|
||||
int tempo;
|
||||
unsigned int to;
|
||||
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name or tempo and notes required");
|
||||
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
|
||||
if (grub_file_read (file, &tempo, sizeof(tempo)) != sizeof(tempo))
|
||||
if (file)
|
||||
{
|
||||
grub_file_close (file);
|
||||
return grub_error (GRUB_ERR_FILE_READ_ERROR,
|
||||
"file doesn't even contains a full tempo record");
|
||||
}
|
||||
struct note buf;
|
||||
grub_uint32_t 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)
|
||||
{
|
||||
|
||||
grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch,
|
||||
buf.duration);
|
||||
|
||||
switch (buf.pitch)
|
||||
if (grub_file_read (file, &tempo, sizeof (tempo)) != sizeof (tempo))
|
||||
{
|
||||
case T_REST:
|
||||
beep_off ();
|
||||
break;
|
||||
grub_file_close (file);
|
||||
return grub_error (GRUB_ERR_FILE_READ_ERROR,
|
||||
"file doesn't even contains a full tempo record");
|
||||
}
|
||||
|
||||
default:
|
||||
beep_on (buf.pitch);
|
||||
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 = grub_le_to_cpu16 (buf.pitch);
|
||||
buf.duration = grub_le_to_cpu16 (buf.duration);
|
||||
|
||||
if (play (tempo, &buf))
|
||||
break;
|
||||
}
|
||||
|
||||
to = grub_get_rtc () + BASE_TEMPO * buf.duration / tempo;
|
||||
while (((unsigned int) grub_get_rtc () <= to) && (grub_checkkey () < 0))
|
||||
;
|
||||
grub_file_close (file);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *end;
|
||||
unsigned tempo;
|
||||
struct note note;
|
||||
int i;
|
||||
|
||||
tempo = grub_strtoul (args[0], &end, 0);
|
||||
|
||||
if (*end)
|
||||
/* Was not a number either, assume it was supposed to be a file name. */
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
|
||||
grub_dprintf ("play","tempo = %d\n", tempo);
|
||||
|
||||
for (i = 1; i + 1 < argc; i += 2)
|
||||
{
|
||||
note.pitch = grub_strtoul (args[i], &end, 0);
|
||||
if (*end)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_NUMBER, "bogus pitch number");
|
||||
break;
|
||||
}
|
||||
|
||||
note.duration = grub_strtoul (args[i + 1], &end, 0);
|
||||
if (*end)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_NUMBER, "bogus duration number");
|
||||
break;
|
||||
}
|
||||
|
||||
if (play (tempo, ¬e))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
beep_off ();
|
||||
|
||||
grub_file_close (file);
|
||||
|
||||
while (grub_checkkey () > 0)
|
||||
grub_getkey ();
|
||||
|
||||
|
@ -208,7 +259,8 @@ static grub_command_t cmd;
|
|||
GRUB_MOD_INIT(play)
|
||||
{
|
||||
cmd = grub_register_command ("play", grub_cmd_play,
|
||||
N_("FILE"), N_("Play a tune."));
|
||||
N_("FILE | TEMPO [PITCH1 DURATION1] [PITCH2 DURATION2] ... "),
|
||||
N_("Play a tune."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(play)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <grub/term.h>
|
||||
#include <grub/machine/init.h>
|
||||
#include <grub/machine/vbe.h>
|
||||
#include <grub/video.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
|
|
|
@ -69,9 +69,9 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
|
|||
color = grub_video_map_rgb (0, 255, 255);
|
||||
grub_video_fill_rect (color, 100, 100, 100, 100);
|
||||
|
||||
sansbig = grub_font_get ("Helvetica Bold 24");
|
||||
sans = grub_font_get ("Helvetica Bold 14");
|
||||
sanssmall = grub_font_get ("Helvetica 8");
|
||||
sansbig = grub_font_get ("Unknown Regular 16");
|
||||
sans = grub_font_get ("Unknown Regular 16");
|
||||
sanssmall = grub_font_get ("Unknown Regular 16");
|
||||
fixed = grub_font_get ("Fixed 20");
|
||||
if (! sansbig || ! sans || ! sanssmall || ! fixed)
|
||||
return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
|
||||
|
@ -126,11 +126,6 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
|
|||
grub_font_draw_string (str, fixed, color, 16, texty);
|
||||
texty += grub_font_get_descent (fixed) + grub_font_get_leading (fixed);
|
||||
|
||||
/* Some character don't exist in the Helvetica font, so the font engine
|
||||
will fall back to using glyphs from another font that does contain them.
|
||||
TODO The font engine should be smart about selecting a replacement font
|
||||
and prioritize fonts with similar sizes. */
|
||||
|
||||
texty += grub_font_get_ascent(sansbig);
|
||||
grub_font_draw_string (str, sansbig, color, 16, texty);
|
||||
texty += grub_font_get_descent (sansbig) + grub_font_get_leading (sansbig);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue