Skip to contentSkip to conversation

Widening terminal coordinates, and reading terminal size.

PATCH In review Timothy Baldwin 3 participants 10 messages Oct 6, 2004 – Jan 8, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Widening terminal coordinates, and reading terminal size.

Here is a patch to widen terminal coordinates from grub_uint8_t to unsigned, change grub_getxy to return values via pointers. I have also added grub_getsizexy to read the terminal size. The PPC implementation is a dummy function, an the PC version assumes a height of 25. Improvements would be welcome.

2004-10-03 Timothy Baldwin <[email protected]>

* include/grub/term.h
(grub_getsizexy, grub_term::grub_getsizexy): New prototypes. (grub_getxy, grub_term::grub_getxy): Returns via pointers to unsigned, instead of packed into a 16-bit value, all callers
and implementations updated.
(grub_gotoxy, grub_term::grub_gotoxy): Arguements are now unsigned.
* term/i386/pc/console.c kern/i386/pc/startup.S include/grub/i386/pc/console.h (grub_console_getsizexy): New function
* term/powerpc/ieee1275/ofconsole.c (grub_ofconsole_getsizexy): New function, needs implementing.
* util/console.c (grub_ncurses_getsizexy): New function

Signature · 2 lines
Member AFFS, WYLUG, SWP (UK), ANL, RESPECT, Leeds SA, Leeds Anti-war coalition
No to software patents!    No to DRM/EUCD - hands off our computers!

Index: include/grub/term.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/term.h,v retrieving revision 1.6

grub/term.h +9 -5
diff -u -r1.6 term.h
@@ -75,11 +75,14 @@
   /* Get a character.  */
   int (*getkey) (void);
   
-  /* Get the cursor position. The return value is ((X << 8) | Y).  */
-  grub_uint16_t (*getxy) (void);
+  /* Get the window size. */
+  void (*getsizexy) (unsigned *x, unsigned *y);
+  
+  /* Get the cursor position. */
+  void (*getxy) (unsigned *x, unsigned *y);
   
   /* Go to the position (X, Y).  */
-  void (*gotoxy) (grub_uint8_t x, grub_uint8_t y);
+  void (*gotoxy) (unsigned x, unsigned y);
   
   /* Clear the screen.  */
   void (*cls) (void);
@@ -116,8 +119,9 @@
 void EXPORT_FUNC(grub_putcode) (grub_uint32_t code);
 int EXPORT_FUNC(grub_getkey) (void);
 int EXPORT_FUNC(grub_checkkey) (void);
-grub_uint16_t EXPORT_FUNC(grub_getxy) (void);
-void EXPORT_FUNC(grub_gotoxy) (grub_uint8_t x, grub_uint8_t y);
+void EXPORT_FUNC(grub_getsizexy) (unsigned *x, unsigned *y);
+void EXPORT_FUNC(grub_getxy) (unsigned *x, unsigned *y);
+void EXPORT_FUNC(grub_gotoxy) (unsigned x, unsigned y);
 void EXPORT_FUNC(grub_cls) (void);
 void EXPORT_FUNC(grub_setcolorstate) (grub_term_color_state state);
 void EXPORT_FUNC(grub_setcolor) (grub_uint8_t normal_color,

Index: include/grub/i386/pc/console.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/i386/pc/console.h,v retrieving revision 1.4

grub/i386/pc/console.h +3 -2
diff -u -r1.4 console.h
@@ -43,8 +43,9 @@
 void grub_console_real_putchar (int c);
 int EXPORT_FUNC(grub_console_checkkey) (void);
 int EXPORT_FUNC(grub_console_getkey) (void);
-grub_uint16_t grub_console_getxy (void);
-void grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y);
+void grub_console_getsizexy (unsigned *x, unsigned *y);
+void grub_console_getxy (unsigned *x, unsigned *y);
+void grub_console_gotoxy (unsigned x, unsigned y);
 void grub_console_cls (void);
 void grub_console_setcursor (int on);
 

Index: kern/term.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/term.c,v
retrieving revision 1.7

term.c +16 -8
diff -u -r1.7 term.c
@@ -92,9 +92,10 @@
 {
   if (code == '\t' && grub_cur_term->getxy)
     {
-      int n;
+      unsigned n;
       
-      n = 8 - ((grub_getxy () >> 8) & 7);
+      grub_getxy(&n, 0);
+      n = 8 - (n & 7);
       while (n--)
 	grub_putcode (' ');
 
@@ -112,7 +113,8 @@
       if (grub_more && grub_more_lines == 24 - 1)
 	{
 	  char key;
-	  int pos = grub_getxy ();
+	  unsigned x, y;
+	  grub_getxy (&x, &y);
 
 	  /* Show --MORE-- on the lower left side of the screen.  */
 	  grub_gotoxy (1, 24 - 1);
@@ -125,7 +127,7 @@
 	  /* Remove the message.  */
 	  grub_gotoxy (1, 24 -1);
 	  grub_printf ("        ");
-	  grub_gotoxy (pos >> 8, pos & 0xFF);
+	  grub_gotoxy (x, y);
 	  
 	  /* Scroll one lines or an entire page, depending on the key.  */
 	  if (key == '\r' || key =='\n')
@@ -212,14 +214,20 @@
   return (grub_cur_term->checkkey) ();
 }
 
-grub_uint16_t
-grub_getxy (void)
+void
+grub_getsizexy (unsigned *x, unsigned *y)
+{
+  (grub_cur_term->getxy) (x, y);
+}
+
+void
+grub_getxy (unsigned *x, unsigned *y)
 {
-  return (grub_cur_term->getxy) ();
+  (grub_cur_term->getxy) (x, y);
 }
 
 void
-grub_gotoxy (grub_uint8_t x, grub_uint8_t y)
+grub_gotoxy (unsigned x, unsigned y)
 {
   (grub_cur_term->gotoxy) (x, y);
 }

Index: kern/i386/pc/startup.S
===================================================================
RCS file: /cvsroot/grub/grub2/kern/i386/pc/startup.S,v retrieving revision 1.13

i386/pc/startup.S +56 -6

85 lines not on this page · raw message

Index: normal/cmdline.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/cmdline.c,v
retrieving revision 1.8

cmdline.c +9 -4
diff -u -r1.8 cmdline.c
@@ -491,10 +491,12 @@
 	{
 	  if (xpos++ > 78)
 	    {
+	      unsigned ytemp;
 	      grub_putchar ('\n');
 	      
 	      xpos = 1;
-	      if (ypos == (unsigned) (grub_getxy () & 0xFF))
+	      grub_getxy(0, &ytemp);
+	      if (ypos == ytemp)
 		ystart--;
 	      else
 		ypos++;
@@ -546,13 +548,15 @@
   lpos = llen = 0;
   buf[0] = '\0';
 
-  if ((grub_getxy () >> 8) != 0)
+  grub_getxy (&xpos, 0);
+  if (xpos != 0)
     grub_putchar ('\n');
   
   grub_printf (prompt);
   
   xpos = plen;
-  ystart = ypos = (grub_getxy () & 0xFF);
+  grub_getxy (0, &ypos);
+  ystart = ypos;
   
   cl_insert (cmdline);
 
@@ -610,7 +614,8 @@
 		    /* Restore the prompt.  */
 		    grub_printf ("\n%s%s", prompt, buf);
 		    xpos = plen;
-		    ystart = ypos = (grub_getxy () & 0xFF);
+		    grub_getxy (0, &ypos);
+		    ystart = ypos;
 		  }
 
 		if (insert)

Index: normal/menu.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/menu.c,v
retrieving revision 1.8

menu.c +3 -3
diff -u -r1.8 menu.c
@@ -37,9 +37,8 @@
 #define DISP_LL		0x2517
 #define DISP_LR		0x251B
 
-/* FIXME: These should be dynamically obtained from a terminal.  */
-#define TERM_WIDTH	(80 - 1)
-#define TERM_HEIGHT	25
+static unsigned TERM_WIDTH =	(80 - 1);
+static unsigned TERM_HEIGHT =	25;
 
 /* The number of lines of "GRUB version..." at the top.  */
 #define TERM_INFO_HEIGHT	1
@@ -228,6 +227,7 @@
 init_page (int nested, int edit)
 {
   grub_normal_init_page ();
+  grub_getsizexy(&TERM_WIDTH, &TERM_HEIGHT);
   draw_border ();
   print_message (nested, edit);
 }

Index: term/i386/pc/console.c
===================================================================
RCS file: /cvsroot/grub/grub2/term/i386/pc/console.c,v retrieving revision 1.4

i386/pc/console.c +1 -0
diff -u -r1.4 console.c
@@ -107,6 +107,7 @@
     .putchar = grub_console_putchar,
     .checkkey = grub_console_checkkey,
     .getkey = grub_console_getkey,
+    .getsizexy = grub_console_getsizexy,
     .getxy = grub_console_getxy,
     .gotoxy = grub_console_gotoxy,
     .cls = grub_console_cls,

Index: term/powerpc/ieee1275/ofconsole.c
===================================================================
RCS file: /cvsroot/grub/grub2/term/powerpc/ieee1275/ofconsole.c,v retrieving revision 1.3

powerpc/ieee1275/ofconsole.c +17 -4
diff -u -r1.3 ofconsole.c
@@ -201,14 +201,26 @@
   return key;
 }
 
-static grub_uint16_t
-grub_ofconsole_getxy (void)
+static void
+grub_ofconsole_getsizexy (unsigned *x, unsigned *y)
+{
+  if (x)
+    *x = 80;
+  if (y)
+    *y = 25;
+}
+
+static void
+grub_ofconsole_getxy (unsigned *x, unsigned *y)
 {
-  return ((grub_curr_x - 1) << 8) | grub_curr_y;
+  if (x)
+    *x = grub_curr_x - 1;
+  if (y)
+    *y = grub_curr_y;
 }
 
 static void
-grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y)
+grub_ofconsole_gotoxy (unsigned x, unsigned y)
 {
   char s[11]; /* 5 + 3 + 3.  */
   grub_curr_x = x;
@@ -289,6 +301,7 @@
     .putchar = grub_ofconsole_putchar,
     .checkkey = grub_ofconsole_checkkey,
     .getkey = grub_ofconsole_getkey,
+    .getsizexy = grub_ofconsole_getsizexy,
     .getxy = grub_ofconsole_getxy,
     .gotoxy = grub_ofconsole_gotoxy,
     .cls = grub_ofconsole_cls,

Index: util/console.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/console.c,v
retrieving revision 1.5

console.c +22 -8
diff -u -r1.5 console.c
@@ -121,19 +121,32 @@
   return c;
 }
 
-static grub_uint16_t
-grub_ncurses_getxy (void)
+static void
+grub_ncurses_getsizexy (unsigned *x, unsigned *y)
 {
-  int x;
-  int y;
-
-  getyx (stdscr, y, x);
+  unsigned p, q;
+  
+  if (!x)
+    x = &p;
+  if (!y)
+    y = &q;
+  getmaxyx (stdscr, *y, *x);
+}
 
-  return (x << 8) | y;
+static void
+grub_ncurses_getxy (unsigned *x, unsigned *y)
+{
+  unsigned p, q;
+  
+  if (!x)
+    x = &p;
+  if (!y)
+    y = &q;
+  getyx (stdscr, *y, *x);
 }
 
 static void
-grub_ncurses_gotoxy (grub_uint8_t x, grub_uint8_t y)
+grub_ncurses_gotoxy (unsigned x, unsigned y)
 {
   move (y, x);
 }
@@ -189,6 +202,7 @@
     .putchar = grub_ncurses_putchar,
     .checkkey = grub_ncurses_checkkey,
     .getkey = grub_ncurses_getkey,
+    .getsizexy = grub_ncurses_getsizexy,
     .getxy = grub_ncurses_getxy,
     .gotoxy = grub_ncurses_gotoxy,
     .cls = grub_ncurses_cls,
#1 lore raw
Quoted 5 lines · Timothy Baldwin

Here is a patch to widen terminal coordinates from grub_uint8_t to unsigned, change grub_getxy to return values via pointers. I have also added grub_getsizexy to read the terminal size. The PPC implementation is a dummy function, an the PC version assumes a height of 25. Improvements would be welcome.

I agree with your idea, but the name `getsizexy' is not very good, since the return values are not coordinates. getsize or getgeometry might be better. What do you think?

Quoted 2 lines

* include/grub/term.h
(grub_getsizexy, grub_term::grub_getsizexy): New prototypes.

This does not follow the convention. First, you should not specify multiple functions in an entry. Please split it.

Also, grub_term::grub_getsizexy is not good. It should be:

(struct grub_term): Added a new member `grub_getsizexy'.

Quoted 3 lines

(grub_getxy, grub_term::grub_getxy): Returns via pointers to unsigned, instead of packed into a 16-bit value, all callers and implementations updated.

Likewise.

Quoted 1 line

(grub_gotoxy, grub_term::grub_gotoxy): Arguements are now unsigned.

Likewise.

Quoted 3 lines

* term/i386/pc/console.c kern/i386/pc/startup.S include/grub/i386/pc/console.h (grub_console_getsizexy): New
function

You should not mention multiple files at a time. Please split it.

And, you don't describe your change of grub_console_getxy.

Quoted 1 line

* util/console.c (grub_ncurses_getsizexy): New function

Please append a period.

Okuji

#2 lore raw
Quoted 10 lines · Yoshinori K. Okuji
Quoted 5 lines · Timothy Baldwin

Here is a patch to widen terminal coordinates from grub_uint8_t to unsigned, change grub_getxy to return values via pointers. I have also added grub_getsizexy to read the terminal size. The PPC implementation is a dummy function, an the PC version assumes a height of 25. Improvements would be welcome.

I agree with your idea, but the name `getsizexy' is not very good, since the return values are not coordinates. getsize or getgeometry might be better. What do you think?

grub_getsize is ambiguous (size of what?) and grub_getgeometry suggests a function to get the geometry of a GUI window, grub_get_term_size is better. What do you think?

Would it be better for grub_getxy and grub_getsizexy (or whatever it is called) to handle the case of null pointers, rather than the terminal drivers?

I also noticed I omitted to change term/i386/pc/vga.c. I will fix this.

2004-10-03 Timothy Baldwin <[email protected]>

* include/grub/term.h
(grub_getsizexy): New prototype.
(grub_gotoxy): Arguments changed to unsigned.
(grub_getxy): Returns via pointers to unsigned, instead of packed into a 16-bit value, all callers updated.
(struct grub_term): Added a new member grub_getsizexy', arguments to grub_gotoxy' changed to unsigned, `grub_getxy' returns values via pointers to unsigned as above.
* kern/term.c (grub_getsizexy): New function.
(grub_getxy): Changed arguments as above.
* kern/i386/pc/startup.S (grub_console_getsizexy): New function. (grub_console_getxy): Changed arguments as above.
* include/grub/i386/pc/console.h (grub_console_getsizexy): New prototype (grub_console_getxy): Changed arguments as above.
* term/i386/pc/console.c: (grub_console_term): Added grub_console_getsizexy.
* term/powerpc/ieee1275/ofconsole.c (grub_ofconsole_getsizexy): New function. (grub_ofconsole_getxy): Changed arguments as above. (grub_ofconsole_term): Added grub_ofconsole_getsizexy.
* util/console.c (grub_ncurses_getsizexy): New function. (grub_ncurses_getxy): Changed arguments as above. (grub_ncurses_term): Added grub_ncurses_getsizexy.

#3 lore raw
Quoted 7 lines · Timothy Baldwin
Quoted 3 lines

I agree with your idea, but the name `getsizexy' is not very good, since the return values are not coordinates. getsize or getgeometry might be better. What do you think?

grub_getsize is ambiguous (size of what?) and grub_getgeometry suggests a function to get the geometry of a GUI window, grub_get_term_size is better. What do you think?

How about getdimensions? That is the term that is used in the Hurd.

Quoted 3 lines

Would it be better for grub_getxy and grub_getsizexy (or whatever it is called) to handle the case of null pointers, rather than the terminal drivers?

The case of null pointers? I think when you have a nullpointer this is a bug, no?

Quoted 5 lines

(grub_getxy): Returns via pointers to unsigned, instead of packed into a 16-bit value, all callers updated.
(struct grub_term): Added a new member grub_getsizexy', arguments to grub_gotoxy' changed to unsigned, `grub_getxy' returns values via pointers to unsigned as above.

As above is very confusing. In that case I would do:

(grub_getxy): Returns via pointers to unsigned, instead of packed into a 16-bit value, all callers updated.
(grub_getxy): Likewise.
(struct grub_term): Likewise for grub_getxy'. Added a new member grub_getsizexy', arguments to grub_gotoxy' changed to unsigned, grub_getxy'.

So you can better reorder things or duplicate the text IMHO.

--
Marco

#4 lore raw
Quoted 1 line · Marco Gerards

How about getdimensions? That is the term that is used in the Hurd.

Perfect.

Quoted 7 lines
Quoted 4 lines

Would it be better for grub_getxy and grub_getsizexy (or whatever it is called) to handle the case of null pointers, rather than the terminal drivers?

The case of null pointers? I think when you have a nullpointer this is a bug, no?

As it stands, when a result is not wanted, a null pointer may be passed and will not be dereferneced. In light of you comments the feture will be removed.

[snip]

Quoted 1 line

As above is very confusing. In that case I would do:

I will change it.

Signature · 2 lines
Member AFFS, WYLUG, SWP (UK), ANL, RESPECT, Leeds SA, Leeds Anti-war coalition
No to software patents!    No to DRM/EUCD - hands off our computers!
#5 lore raw
Quoted 10 lines · Timothy Baldwin
Quoted 6 lines
Quoted 3 lines

Would it be better for grub_getxy and grub_getsizexy (or whatever it is called) to handle the case of null pointers, rather than the terminal drivers?

The case of null pointers? I think when you have a nullpointer this is a bug, no?

As it stands, when a result is not wanted, a null pointer may be passed and will not be dereferneced. In light of you comments the feture will be removed.

It might be useful. Do you think it is useful? Don't remove it just because I am asking for it. ;)

Thanks,
Marco

#6 lore raw
In reply to Marco Gerards
Quoted 5 lines · Marco Gerards
Quoted 3 lines

grub_getsize is ambiguous (size of what?) and grub_getgeometry suggests a function to get the geometry of a GUI window, grub_get_term_size is better. What do you think?

How about getdimensions? That is the term that is used in the Hurd.

I don't like getdimensions, since dimensions can be read as the number of axes. I vote for grub_getgeometry. Since GRUB does not have a window system, I don't think it is ambiguous.

Okuji

#7 lore raw
Quoted 3 lines · Yoshinori K. Okuji

I don't like getdimensions, since dimensions can be read as the number of axes. I vote for grub_getgeometry. Since GRUB does not have a window system, I don't think it is ambiguous.

I've changed it to grub_getgeometry. A new patch is attached, and here is the changelog:

2004-10-03 Timothy Baldwin <[email protected]>

* include/grub/term.h
(grub_getsizexy): New prototype.
(grub_gotoxy): Arguments changed to unsigned.
(grub_getxy): Returns via pointers to unsigned, instead of packed into a 16-bit value, all callers updated.
(struct grub_term): Likewise for grub_getxy'. Added a new member grub_getsizexy', arguments to grub_gotoxy' changed to unsigned, grub_getxy'.
* kern/term.c (grub_getsizexy): New function.
(grub_getxy): Changed arguments as above.
* kern/i386/pc/startup.S (grub_console_getsizexy): New function. (grub_console_getxy): Changed arguments as above.
* include/grub/i386/pc/console.h (grub_console_getsizexy): New prototype (grub_console_getxy): Changed arguments as above.
* term/i386/pc/console.c (grub_console_term): Added grub_console_getsizexy.
* term/powerpc/ieee1275/ofconsole.c (grub_ofconsole_getsizexy): New function. (grub_ofconsole_getxy): Changed arguments as above. (grub_ofconsole_term): Added grub_ofconsole_getsizexy.
* util/console.c (grub_ncurses_getsizexy): New function. (grub_ncurses_getxy): Changed arguments as above. (grub_ncurses_term): Added grub_ncurses_getsizexy.
* term/i386/pc/console.c (grub_vga_getsizexy): New function. (grub_vga_getxy): Changed arguments as above.
(grub_vga_term): Added grub_ncurses_getsizexy.

PS. I haven't signed any copyright forms.

Signature · 2 lines
Member AFFS, WYLUG, SWP (UK), ANL, RESPECT, Leeds SA, Leeds Anti-war coalition
No to software patents!    No to DRM/EUCD - hands off our computers!

Index: include/grub/term.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/term.h,v retrieving revision 1.6

grub/term.h +9 -5
diff -u -r1.6 term.h
@@ -75,11 +75,14 @@
   /* Get a character.  */
   int (*getkey) (void);
   
-  /* Get the cursor position. The return value is ((X << 8) | Y).  */
-  grub_uint16_t (*getxy) (void);
+  /* Get the window size. */
+  void (*getgeometry) (int *x, int *y);
+  
+  /* Get the cursor position. */
+  void (*getxy) (int *x, int *y);
   
   /* Go to the position (X, Y).  */
-  void (*gotoxy) (grub_uint8_t x, grub_uint8_t y);
+  void (*gotoxy) (int x, int y);
   
   /* Clear the screen.  */
   void (*cls) (void);
@@ -116,8 +119,9 @@
 void EXPORT_FUNC(grub_putcode) (grub_uint32_t code);
 int EXPORT_FUNC(grub_getkey) (void);
 int EXPORT_FUNC(grub_checkkey) (void);
-grub_uint16_t EXPORT_FUNC(grub_getxy) (void);
-void EXPORT_FUNC(grub_gotoxy) (grub_uint8_t x, grub_uint8_t y);
+void EXPORT_FUNC(grub_getgeometry) (int *x, int *y);
+void EXPORT_FUNC(grub_getxy) (int *x, int *y);
+void EXPORT_FUNC(grub_gotoxy) (int x, int y);
 void EXPORT_FUNC(grub_cls) (void);
 void EXPORT_FUNC(grub_setcolorstate) (grub_term_color_state state);
 void EXPORT_FUNC(grub_setcolor) (grub_uint8_t normal_color,

Index: include/grub/i386/pc/console.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/i386/pc/console.h,v retrieving revision 1.4

grub/i386/pc/console.h +3 -2
diff -u -r1.4 console.h
@@ -43,8 +43,9 @@
 void grub_console_real_putchar (int c);
 int EXPORT_FUNC(grub_console_checkkey) (void);
 int EXPORT_FUNC(grub_console_getkey) (void);
-grub_uint16_t grub_console_getxy (void);
-void grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y);
+void grub_console_getgeometry (int *x, int *y);
+void grub_console_getxy (int *x, int *y);
+void grub_console_gotoxy (int x, int y);
 void grub_console_cls (void);
 void grub_console_setcursor (int on);
 

Index: kern/term.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/term.c,v
retrieving revision 1.7

term.c +16 -8
diff -u -r1.7 term.c
@@ -92,9 +92,10 @@
 {
   if (code == '\t' && grub_cur_term->getxy)
     {
-      int n;
+      int n, dummy;
       
-      n = 8 - ((grub_getxy () >> 8) & 7);
+      grub_getxy(&n, &dummy);
+      n = 8 - (n & 7);
       while (n--)
 	grub_putcode (' ');
 
@@ -112,7 +113,8 @@
       if (grub_more && grub_more_lines == 24 - 1)
 	{
 	  char key;
-	  int pos = grub_getxy ();
+	  int x, y;
+	  grub_getxy (&x, &y);
 
 	  /* Show --MORE-- on the lower left side of the screen.  */
 	  grub_gotoxy (1, 24 - 1);
@@ -125,7 +127,7 @@
 	  /* Remove the message.  */
 	  grub_gotoxy (1, 24 -1);
 	  grub_printf ("        ");
-	  grub_gotoxy (pos >> 8, pos & 0xFF);
+	  grub_gotoxy (x, y);
 	  
 	  /* Scroll one lines or an entire page, depending on the key.  */
 	  if (key == '\r' || key =='\n')
@@ -212,14 +214,20 @@
   return (grub_cur_term->checkkey) ();
 }
 
-grub_uint16_t
-grub_getxy (void)
+void
+grub_getgeometry (int *x, int *y)
+{
+  (grub_cur_term->getgeometry) (x, y);
+}
+
+void
+grub_getxy (int *x, int *y)
 {
-  return (grub_cur_term->getxy) ();
+  (grub_cur_term->getxy) (x, y);
 }
 
 void
-grub_gotoxy (grub_uint8_t x, grub_uint8_t y)
+grub_gotoxy (int x, int y)
 {
   (grub_cur_term->gotoxy) (x, y);
 }

Index: kern/i386/pc/startup.S
===================================================================
RCS file: /cvsroot/grub/grub2/kern/i386/pc/startup.S,v retrieving revision 1.13

i386/pc/startup.S +45 -4

74 lines not on this page · raw message

Index: normal/cmdline.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/cmdline.c,v
retrieving revision 1.8

cmdline.c +10 -5
diff -u -r1.8 cmdline.c
@@ -465,7 +465,7 @@
 grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
 		  int echo_char, int readline)
 {
-  unsigned xpos, ypos, ystart;
+  unsigned xpos, ypos, ystart, dummy;
   grub_size_t lpos, llen;
   grub_size_t plen;
   char buf[max_len];
@@ -491,10 +491,12 @@
 	{
 	  if (xpos++ > 78)
 	    {
+	      int xtemp, ytemp;
 	      grub_putchar ('\n');
 	      
 	      xpos = 1;
-	      if (ypos == (unsigned) (grub_getxy () & 0xFF))
+	      grub_getxy(&xtemp, &ytemp);
+	      if (ypos == ytemp)
 		ystart--;
 	      else
 		ypos++;
@@ -546,13 +548,15 @@
   lpos = llen = 0;
   buf[0] = '\0';
 
-  if ((grub_getxy () >> 8) != 0)
+  grub_getxy (&xpos, &dummy);
+  if (xpos != 0)
     grub_putchar ('\n');
   
   grub_printf (prompt);
   
   xpos = plen;
-  ystart = ypos = (grub_getxy () & 0xFF);
+  grub_getxy (&dummy, &ypos);
+  ystart = ypos;
   
   cl_insert (cmdline);
 
@@ -610,7 +614,8 @@
 		    /* Restore the prompt.  */
 		    grub_printf ("\n%s%s", prompt, buf);
 		    xpos = plen;
-		    ystart = ypos = (grub_getxy () & 0xFF);
+		    grub_getxy (&dummy, &ypos);
+		    ystart = ypos;
 		  }
 
 		if (insert)

Index: normal/menu.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/menu.c,v
retrieving revision 1.8

menu.c +3 -3
diff -u -r1.8 menu.c
@@ -37,9 +37,8 @@
 #define DISP_LL		0x2517
 #define DISP_LR		0x251B
 
-/* FIXME: These should be dynamically obtained from a terminal.  */
-#define TERM_WIDTH	(80 - 1)
-#define TERM_HEIGHT	25
+static int TERM_WIDTH =	(80 - 1);
+static int TERM_HEIGHT =	25;
 
 /* The number of lines of "GRUB version..." at the top.  */
 #define TERM_INFO_HEIGHT	1
@@ -228,6 +227,7 @@
 init_page (int nested, int edit)
 {
   grub_normal_init_page ();
+  grub_getgeometry(&TERM_WIDTH, &TERM_HEIGHT);
   draw_border ();
   print_message (nested, edit);
 }

Index: term/i386/pc/console.c
===================================================================
RCS file: /cvsroot/grub/grub2/term/i386/pc/console.c,v retrieving revision 1.4

i386/pc/console.c +1 -0
diff -u -r1.4 console.c
@@ -107,6 +107,7 @@
     .putchar = grub_console_putchar,
     .checkkey = grub_console_checkkey,
     .getkey = grub_console_getkey,
+    .getgeometry = grub_console_getgeometry,
     .getxy = grub_console_getxy,
     .gotoxy = grub_console_gotoxy,
     .cls = grub_console_cls,

Index: term/i386/pc/vga.c
===================================================================
RCS file: /cvsroot/grub/grub2/term/i386/pc/vga.c,v retrieving revision 1.5

i386/pc/vga.c +17 -7
diff -u -r1.5 vga.c
@@ -396,25 +396,34 @@
 #if DEBUG_VGA
   if (show)
     {
-      grub_uint16_t pos = grub_getxy ();
+      int xpos, ypos;
+      grub_getxy (&xpos, &ypos);
 
       show = 0;
       grub_gotoxy (0, 0);
-      grub_printf ("[%u:%u]", (unsigned) (pos >> 8), (unsigned) (pos & 0xff));
-      grub_gotoxy (pos >> 8, pos & 0xff);
+      grub_printf ("[%u:%u]", (unsigned) xpos, (unsigned) ypos);
+      grub_gotoxy (xpos, ypos);
       show = 1;
     }
 #endif
 }
 
-static grub_uint16_t
-grub_vga_getxy (void)
+static void
+grub_vga_getgeometry (int *x, int *y)
+{
+  *x = TEXT_WIDTH;
+  *y = TEXT_HEIGHT;
+}
+
+static void
+grub_vga_getxy (int *x, int *y)
 {
-  return ((xpos << 8) | ypos);
+  *x = xpos;
+  *y = ypos;
 }
 
 static void
-grub_vga_gotoxy (grub_uint8_t x, grub_uint8_t y)
+grub_vga_gotoxy (int x, int y)
 {
   if (x >= TEXT_WIDTH || y >= TEXT_HEIGHT)
     {
@@ -500,6 +509,7 @@
     .putchar = grub_vga_putchar,
     .checkkey = grub_console_checkkey,
     .getkey = grub_console_getkey,
+    .getgeometry = grub_vga_getgeometry,
     .getxy = grub_vga_getxy,
     .gotoxy = grub_vga_gotoxy,
     .cls = grub_vga_cls,

Index: term/powerpc/ieee1275/ofconsole.c
===================================================================
RCS file: /cvsroot/grub/grub2/term/powerpc/ieee1275/ofconsole.c,v retrieving revision 1.3

powerpc/ieee1275/ofconsole.c +13 -4
diff -u -r1.3 ofconsole.c
@@ -201,14 +201,22 @@
   return key;
 }
 
-static grub_uint16_t
-grub_ofconsole_getxy (void)
+static void
+grub_ofconsole_getgeometry (int *x, int *y)
+{
+  *x = 80;
+  *y = 25;
+}
+
+static void
+grub_ofconsole_getxy (int *x, int *y)
 {
-  return ((grub_curr_x - 1) << 8) | grub_curr_y;
+  *x = grub_curr_x - 1;
+  *y = grub_curr_y;
 }
 
 static void
-grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y)
+grub_ofconsole_gotoxy (int x, int y)
 {
   char s[11]; /* 5 + 3 + 3.  */
   grub_curr_x = x;
@@ -289,6 +297,7 @@
     .putchar = grub_ofconsole_putchar,
     .checkkey = grub_ofconsole_checkkey,
     .getkey = grub_ofconsole_getkey,
+    .getgeometry = grub_ofconsole_getgeometry,
     .getxy = grub_ofconsole_getxy,
     .gotoxy = grub_ofconsole_gotoxy,
     .cls = grub_ofconsole_cls,

Index: util/console.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/console.c,v
retrieving revision 1.5

console.c +10 -8
diff -u -r1.5 console.c
@@ -121,19 +121,20 @@
   return c;
 }
 
-static grub_uint16_t
-grub_ncurses_getxy (void)
+static void
+grub_ncurses_getgeometry (int *x, int *y)
 {
-  int x;
-  int y;
-
-  getyx (stdscr, y, x);
+  getmaxyx (stdscr, *y, *x);
+}
 
-  return (x << 8) | y;
+static void
+grub_ncurses_getxy (int *x, int *y)
+{
+  getyx (stdscr, *y, *x);
 }
 
 static void
-grub_ncurses_gotoxy (grub_uint8_t x, grub_uint8_t y)
+grub_ncurses_gotoxy (int x, int y)
 {
   move (y, x);
 }
@@ -189,6 +190,7 @@
     .putchar = grub_ncurses_putchar,
     .checkkey = grub_ncurses_checkkey,
     .getkey = grub_ncurses_getkey,
+    .getgeometry = grub_ncurses_getgeometry,
     .getxy = grub_ncurses_getxy,
     .gotoxy = grub_ncurses_gotoxy,
     .cls = grub_ncurses_cls,
#8 lore raw
Quoted 2 lines · Timothy Baldwin

(grub_getxy): Returns via pointers to unsigned, instead of packed into a 16-bit value, all callers updated.

Although you say unsigned here, you use int in your patch.

Quoted 1 line

PS. I haven't signed any copyright forms.

Oh, I forgot it! Thank you for pointing it out. I'll send a template of the request form later.

Okuji

#9 lore raw
Quoted 4 lines · Yoshinori K. Okuji
Quoted 1 line

PS. I haven't signed any copyright forms.

Oh, I forgot it! Thank you for pointing it out. I'll send a template of the request form later.

Are the copyrights assigned now? I would like to integrate this patch in CVS after I read it one more time.

Thanks,
Marco