vaseboot/VasEBoot-core/commands/videoinfo.c

263 lines
7.6 KiB
C

/* videoinfo.c - command to list video modes. */
/*
* VasEBoot -- GRand Unified Bootloader
* Copyright (C) 2005,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* VasEBoot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VasEBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VasEBoot. If not, see <http://www.gnu.org/licenses/>.
*/
#include <VasEBoot/video.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/env.h>
#include <VasEBoot/misc.h>
#include <VasEBoot/mm.h>
#include <VasEBoot/command.h>
#include <VasEBoot/i18n.h>
VasEBoot_MOD_LICENSE ("GPLv3+");
struct hook_ctx
{
unsigned height, width, depth;
struct VasEBoot_video_mode_info *current_mode;
};
static int
hook (const struct VasEBoot_video_mode_info *info, void *hook_arg)
{
struct hook_ctx *ctx = hook_arg;
if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height))
return 0;
if (ctx->depth && info->bpp != ctx->depth)
return 0;
if (info->mode_number == VasEBoot_VIDEO_MODE_NUMBER_INVALID)
VasEBoot_printf (" ");
else
{
if (ctx->current_mode && info->mode_number == ctx->current_mode->mode_number)
VasEBoot_printf ("*");
else
VasEBoot_printf (" ");
VasEBoot_printf (" 0x%03x ", info->mode_number);
}
VasEBoot_printf ("%4d x %4d x %2d (%4d) ", info->width, info->height, info->bpp,
info->pitch);
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_PURE_TEXT)
VasEBoot_xputs (_("Text-only "));
/* Show mask and position details for direct color modes. */
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_RGB)
/* TRANSLATORS: "Direct color" is a mode when the color components
are written dirrectly into memory. */
VasEBoot_printf_ (N_("Direct color, mask: %d/%d/%d/%d pos: %d/%d/%d/%d"),
info->red_mask_size,
info->green_mask_size,
info->blue_mask_size,
info->reserved_mask_size,
info->red_field_pos,
info->green_field_pos,
info->blue_field_pos,
info->reserved_field_pos);
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_INDEX_COLOR)
/* TRANSLATORS: In "paletted color" mode you write the index of the color
in the palette. Synonyms include "packed pixel". */
VasEBoot_xputs (_("Paletted "));
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_YUV)
VasEBoot_xputs (_("YUV "));
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_PLANAR)
/* TRANSLATORS: "Planar" is the video memory where you have to write
in several different banks "plans" to control the different color
components of the same pixel. */
VasEBoot_xputs (_("Planar "));
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_HERCULES)
VasEBoot_xputs (_("Hercules "));
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_CGA)
VasEBoot_xputs (_("CGA "));
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_NONCHAIN4)
/* TRANSLATORS: Non-chain 4 is a 256-color planar
(unchained) video memory mode. */
VasEBoot_xputs (_("Non-chain 4 "));
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_1BIT_BITMAP)
VasEBoot_xputs (_("Monochrome "));
if (info->mode_type & VasEBoot_VIDEO_MODE_TYPE_UNKNOWN)
VasEBoot_xputs (_("Unknown video mode "));
VasEBoot_xputs ("\n");
return 0;
}
static void
print_edid (struct VasEBoot_video_edid_info *edid_info)
{
unsigned int edid_width, edid_height;
if (VasEBoot_video_edid_checksum (edid_info))
{
VasEBoot_puts_ (N_(" EDID checksum invalid"));
VasEBoot_errno = VasEBoot_ERR_NONE;
return;
}
VasEBoot_printf_ (N_(" EDID version: %u.%u\n"),
edid_info->version, edid_info->revision);
if (VasEBoot_video_edid_preferred_mode (edid_info, &edid_width, &edid_height)
== VasEBoot_ERR_NONE)
VasEBoot_printf_ (N_(" Preferred mode: %ux%u\n"), edid_width, edid_height);
else
{
VasEBoot_printf_ (N_(" No preferred mode available\n"));
VasEBoot_errno = VasEBoot_ERR_NONE;
}
}
static VasEBoot_err_t
VasEBoot_cmd_videoinfo (VasEBoot_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
VasEBoot_video_adapter_t adapter;
VasEBoot_video_driver_id_t id;
struct hook_ctx ctx;
ctx.height = ctx.width = ctx.depth = 0;
if (argc)
{
char *ptr;
ptr = args[0];
ctx.width = VasEBoot_strtoul (ptr, &ptr, 0);
if (VasEBoot_errno)
return VasEBoot_errno;
if (*ptr != 'x')
return VasEBoot_error (VasEBoot_ERR_BAD_ARGUMENT,
N_("invalid video mode specification `%s'"),
args[0]);
ptr++;
ctx.height = VasEBoot_strtoul (ptr, &ptr, 0);
if (VasEBoot_errno)
return VasEBoot_errno;
if (*ptr == 'x')
{
ptr++;
ctx.depth = VasEBoot_strtoul (ptr, &ptr, 0);
if (VasEBoot_errno)
return VasEBoot_errno;
}
}
#ifdef VasEBoot_MACHINE_PCBIOS
if (VasEBoot_strcmp (cmd->name, "vbeinfo") == 0)
VasEBoot_dl_load ("vbe");
#endif
id = VasEBoot_video_get_driver_id ();
VasEBoot_puts_ (N_("List of supported video modes:"));
VasEBoot_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
FOR_VIDEO_ADAPTERS (adapter)
{
struct VasEBoot_video_mode_info info;
struct VasEBoot_video_edid_info edid_info;
VasEBoot_printf_ (N_("Adapter `%s':\n"), adapter->name);
if (!adapter->iterate)
{
VasEBoot_puts_ (N_(" No info available"));
continue;
}
ctx.current_mode = NULL;
if (adapter->id == id)
{
if (VasEBoot_video_get_info (&info) == VasEBoot_ERR_NONE)
ctx.current_mode = &info;
else
/* Don't worry about errors. */
VasEBoot_errno = VasEBoot_ERR_NONE;
}
else
{
if (adapter->init ())
{
VasEBoot_puts_ (N_(" Failed to initialize video adapter"));
VasEBoot_errno = VasEBoot_ERR_NONE;
continue;
}
}
if (adapter->print_adapter_specific_info)
adapter->print_adapter_specific_info ();
adapter->iterate (hook, &ctx);
if (adapter->get_edid && adapter->get_edid (&edid_info) == VasEBoot_ERR_NONE)
print_edid (&edid_info);
else
VasEBoot_errno = VasEBoot_ERR_NONE;
ctx.current_mode = NULL;
if (adapter->id != id)
{
if (adapter->fini ())
{
VasEBoot_errno = VasEBoot_ERR_NONE;
continue;
}
}
}
return VasEBoot_ERR_NONE;
}
static VasEBoot_command_t cmd;
#ifdef VasEBoot_MACHINE_PCBIOS
static VasEBoot_command_t cmd_vbe;
#endif
VasEBoot_MOD_INIT(videoinfo)
{
cmd = VasEBoot_register_command ("videoinfo", VasEBoot_cmd_videoinfo,
/* TRANSLATORS: "x" has to be entered in,
like an identifier, so please don't
use better Unicode codepoints. */
N_("[WxH[xD]]"),
N_("List available video modes. If "
"resolution is given show only modes"
" matching it."));
#ifdef VasEBoot_MACHINE_PCBIOS
cmd_vbe = VasEBoot_register_command ("vbeinfo", VasEBoot_cmd_videoinfo,
/* TRANSLATORS: "x" has to be entered in,
like an identifier, so please don't
use better Unicode codepoints. */
N_("[WxH[xD]]"),
N_("List available video modes. If "
"resolution is given show only modes"
" matching it."));
#endif
}
VasEBoot_MOD_FINI(videoinfo)
{
VasEBoot_unregister_command (cmd);
#ifdef VasEBoot_MACHINE_PCBIOS
VasEBoot_unregister_command (cmd_vbe);
#endif
}