Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / commands / videoinfo.c
blob4be8107d553a1e2fa582fd292ba58e36312c2372
1 /* videoinfo.c - command to list video modes. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2007,2008,2009,2010 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/video.h>
21 #include <grub/dl.h>
22 #include <grub/env.h>
23 #include <grub/misc.h>
24 #include <grub/mm.h>
25 #include <grub/command.h>
26 #include <grub/i18n.h>
28 GRUB_MOD_LICENSE ("GPLv3+");
30 struct hook_ctx
32 unsigned height, width, depth;
33 struct grub_video_mode_info *current_mode;
36 static int
37 hook (const struct grub_video_mode_info *info, void *hook_arg)
39 struct hook_ctx *ctx = hook_arg;
41 if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height))
42 return 0;
44 if (ctx->depth && info->bpp != ctx->depth)
45 return 0;
47 if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
48 grub_printf (" ");
49 else
51 if (ctx->current_mode && info->mode_number == ctx->current_mode->mode_number)
52 grub_printf ("*");
53 else
54 grub_printf (" ");
55 grub_printf (" 0x%03x ", info->mode_number);
57 grub_printf ("%4d x %4d x %2d (%4d) ", info->width, info->height, info->bpp,
58 info->pitch);
60 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT)
61 grub_xputs (_("Text-only "));
62 /* Show mask and position details for direct color modes. */
63 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_RGB)
64 /* TRANSLATORS: "Direct color" is a mode when the color components
65 are written dirrectly into memory. */
66 grub_printf_ (N_("Direct color, mask: %d/%d/%d/%d pos: %d/%d/%d/%d"),
67 info->red_mask_size,
68 info->green_mask_size,
69 info->blue_mask_size,
70 info->reserved_mask_size,
71 info->red_field_pos,
72 info->green_field_pos,
73 info->blue_field_pos,
74 info->reserved_field_pos);
75 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
76 /* TRANSLATORS: In "paletted color" mode you write the index of the color
77 in the palette. Synonyms include "packed pixel". */
78 grub_xputs (_("Paletted "));
79 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_YUV)
80 grub_xputs (_("YUV "));
81 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PLANAR)
82 /* TRANSLATORS: "Planar" is the video memory where you have to write
83 in several different banks "plans" to control the different color
84 components of the same pixel. */
85 grub_xputs (_("Planar "));
86 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_HERCULES)
87 grub_xputs (_("Hercules "));
88 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_CGA)
89 grub_xputs (_("CGA "));
90 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_NONCHAIN4)
91 /* TRANSLATORS: Non-chain 4 is a 256-color planar
92 (unchained) video memory mode. */
93 grub_xputs (_("Non-chain 4 "));
94 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP)
95 grub_xputs (_("Monochrome "));
96 if (info->mode_type & GRUB_VIDEO_MODE_TYPE_UNKNOWN)
97 grub_xputs (_("Unknown video mode "));
99 grub_xputs ("\n");
101 return 0;
104 static void
105 print_edid (struct grub_video_edid_info *edid_info)
107 unsigned int edid_width, edid_height;
109 if (grub_video_edid_checksum (edid_info))
111 grub_puts_ (N_(" EDID checksum invalid"));
112 grub_errno = GRUB_ERR_NONE;
113 return;
116 grub_printf_ (N_(" EDID version: %u.%u\n"),
117 edid_info->version, edid_info->revision);
118 if (grub_video_edid_preferred_mode (edid_info, &edid_width, &edid_height)
119 == GRUB_ERR_NONE)
120 grub_printf_ (N_(" Preferred mode: %ux%u\n"), edid_width, edid_height);
121 else
123 grub_printf_ (N_(" No preferred mode available\n"));
124 grub_errno = GRUB_ERR_NONE;
128 static grub_err_t
129 grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
130 int argc, char **args)
132 grub_video_adapter_t adapter;
133 grub_video_driver_id_t id;
134 struct hook_ctx ctx;
136 ctx.height = ctx.width = ctx.depth = 0;
137 if (argc)
139 char *ptr;
140 ptr = args[0];
141 ctx.width = grub_strtoul (ptr, &ptr, 0);
142 if (grub_errno)
143 return grub_errno;
144 if (*ptr != 'x')
145 return grub_error (GRUB_ERR_BAD_ARGUMENT,
146 N_("invalid video mode specification `%s'"),
147 args[0]);
148 ptr++;
149 ctx.height = grub_strtoul (ptr, &ptr, 0);
150 if (grub_errno)
151 return grub_errno;
152 if (*ptr == 'x')
154 ptr++;
155 ctx.depth = grub_strtoul (ptr, &ptr, 0);
156 if (grub_errno)
157 return grub_errno;
161 #ifdef GRUB_MACHINE_PCBIOS
162 if (grub_strcmp (cmd->name, "vbeinfo") == 0)
163 grub_dl_load ("vbe");
164 #endif
166 id = grub_video_get_driver_id ();
168 grub_puts_ (N_("List of supported video modes:"));
169 grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
171 FOR_VIDEO_ADAPTERS (adapter)
173 struct grub_video_mode_info info;
174 struct grub_video_edid_info edid_info;
176 grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
178 if (!adapter->iterate)
180 grub_puts_ (N_(" No info available"));
181 continue;
184 ctx.current_mode = NULL;
186 if (adapter->id == id)
188 if (grub_video_get_info (&info) == GRUB_ERR_NONE)
189 ctx.current_mode = &info;
190 else
191 /* Don't worry about errors. */
192 grub_errno = GRUB_ERR_NONE;
194 else
196 if (adapter->init ())
198 grub_puts_ (N_(" Failed to initialize video adapter"));
199 grub_errno = GRUB_ERR_NONE;
200 continue;
204 if (adapter->print_adapter_specific_info)
205 adapter->print_adapter_specific_info ();
207 adapter->iterate (hook, &ctx);
209 if (adapter->get_edid && adapter->get_edid (&edid_info) == GRUB_ERR_NONE)
210 print_edid (&edid_info);
211 else
212 grub_errno = GRUB_ERR_NONE;
214 ctx.current_mode = NULL;
216 if (adapter->id != id)
218 if (adapter->fini ())
220 grub_errno = GRUB_ERR_NONE;
221 continue;
225 return GRUB_ERR_NONE;
228 static grub_command_t cmd;
229 #ifdef GRUB_MACHINE_PCBIOS
230 static grub_command_t cmd_vbe;
231 #endif
233 GRUB_MOD_INIT(videoinfo)
235 cmd = grub_register_command ("videoinfo", grub_cmd_videoinfo,
236 /* TRANSLATORS: "x" has to be entered in,
237 like an identifier, so please don't
238 use better Unicode codepoints. */
239 N_("[WxH[xD]]"),
240 N_("List available video modes. If "
241 "resolution is given show only modes"
242 " matching it."));
243 #ifdef GRUB_MACHINE_PCBIOS
244 cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
245 /* TRANSLATORS: "x" has to be entered in,
246 like an identifier, so please don't
247 use better Unicode codepoints. */
248 N_("[WxH[xD]]"),
249 N_("List available video modes. If "
250 "resolution is given show only modes"
251 " matching it."));
252 #endif
255 GRUB_MOD_FINI(videoinfo)
257 grub_unregister_command (cmd);
258 #ifdef GRUB_MACHINE_PCBIOS
259 grub_unregister_command (cmd_vbe);
260 #endif