/[grub]/grub/stage2/hercules.c
ViewVC logotype

Diff of /grub/stage2/hercules.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by okuji, Tue Feb 27 12:59:00 2001 UTC revision 1.2 by okuji, Tue Jun 11 16:36:54 2002 UTC
# Line 1  Line 1 
1  /* hercules.c - hercules console interface */  /* hercules.c - hercules console interface */
2  /*  /*
3   *  GRUB  --  GRand Unified Bootloader   *  GRUB  --  GRand Unified Bootloader
4   *  Copyright (C) 2001  Free Software Foundation, Inc.   *  Copyright (C) 2001,2002  Free Software Foundation, Inc.
5   *   *
6   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 22  Line 22 
22    
23  #include <shared.h>  #include <shared.h>
24  #include <hercules.h>  #include <hercules.h>
25    #include <term.h>
26    
27  /* The position of the cursor.  */  /* The position of the cursor.  */
28  static unsigned hercx, hercy;  static int herc_x;
29    static int herc_y;
30    
31    static int herc_normal_color = A_NORMAL;
32    static int herc_highlight_color = A_REVERSE;
33    static int herc_current_color = A_NORMAL;
34    static int herc_highlight_state = 0;
35    
36  /* Write a byte to a port.  */  /* Write a byte to a port.  */
37  static inline void  static inline void
# Line 36  outb (unsigned short port, unsigned char Line 43  outb (unsigned short port, unsigned char
43  static void  static void
44  herc_set_cursor (void)  herc_set_cursor (void)
45  {  {
46    unsigned offset = hercy * HERCULES_WIDTH + hercx;    unsigned offset = herc_y * HERCULES_WIDTH + herc_x;
47        
48    outb (HERCULES_INDEX_REG, 0x0f);    outb (HERCULES_INDEX_REG, 0x0f);
49    outb (0x80, 0x0f);    outb (0x80, 0);
50    outb (HERCULES_DATA_REG, offset & 0xFF);    outb (HERCULES_DATA_REG, offset & 0xFF);
51    outb (0x80, offset & 0xFF);    outb (0x80, 0);
52        
53    outb (HERCULES_INDEX_REG, 0x0e);    outb (HERCULES_INDEX_REG, 0x0e);
54    outb (0x80, 0x0e);    outb (0x80, 0);
55    outb (HERCULES_DATA_REG, offset >> 8);    outb (HERCULES_DATA_REG, offset >> 8);
56    outb (0x80, offset >> 8);    outb (0x80, 0);
57    }
58    
59    static void
60    herc_turn_cursor (int state)
61    {
62      outb (HERCULES_INDEX_REG, 0x0a);
63      outb (0x80, 0);
64      outb (HERCULES_DATA_REG, state ? 0 : (1 << 5));
65      outb (0x80, 0);
66  }  }
67    
68  void  void
69  herc_putchar (int c)  hercules_putchar (int c)
70  {  {
     
71    switch (c)    switch (c)
72      {      {
73      case '\b':      case '\b':
74        if (hercx)        if (herc_x > 0)
75          hercx--;          herc_x--;
76        break;        break;
77                
78      case '\n':      case '\n':
79        hercy++;        herc_y++;
80        break;        break;
81                
82      case '\r':      case '\r':
83        hercx = 0;        herc_x = 0;
84          break;
85    
86        case '\a':
87        break;        break;
88    
89      default:      default:
# Line 73  herc_putchar (int c) Line 91  herc_putchar (int c)
91          volatile unsigned short *video          volatile unsigned short *video
92            = (unsigned short *) HERCULES_VIDEO_ADDR;            = (unsigned short *) HERCULES_VIDEO_ADDR;
93                    
94          video[hercy * HERCULES_WIDTH + hercx] = 0x0700 | c;          video[herc_y * HERCULES_WIDTH + herc_x]
95          hercx++;            = (herc_current_color << 8) | c;
96          if (hercx >= HERCULES_WIDTH)          herc_x++;
97            if (herc_x >= HERCULES_WIDTH)
98            {            {
99              hercx = 0;              herc_x = 0;
100              hercy++;              herc_y++;
101            }            }
102        }        }
103        break;        break;
104      }      }
105    
106    if (hercy >= HERCULES_HEIGHT)    if (herc_y >= HERCULES_HEIGHT)
107      {      {
       int i;  
108        volatile unsigned long *video = (unsigned long *) HERCULES_VIDEO_ADDR;        volatile unsigned long *video = (unsigned long *) HERCULES_VIDEO_ADDR;
109          int i;
110                
111        hercy = HERCULES_HEIGHT - 1;        herc_y = HERCULES_HEIGHT - 1;
112        grub_memmove ((char *) HERCULES_VIDEO_ADDR,        grub_memmove ((char *) HERCULES_VIDEO_ADDR,
113                      (char *) HERCULES_VIDEO_ADDR + HERCULES_WIDTH * 2,                      (char *) HERCULES_VIDEO_ADDR + HERCULES_WIDTH * 2,
114                      HERCULES_WIDTH * (HERCULES_HEIGHT - 1) * 2);                      HERCULES_WIDTH * (HERCULES_HEIGHT - 1) * 2);
# Line 101  herc_putchar (int c) Line 120  herc_putchar (int c)
120  }  }
121    
122  void  void
123  herc_cls (void)  hercules_cls (void)
124  {  {
125    int i;    int i;
126    volatile unsigned long *video = (unsigned long *) HERCULES_VIDEO_ADDR;    volatile unsigned long *video = (unsigned long *) HERCULES_VIDEO_ADDR;
# Line 109  herc_cls (void) Line 128  herc_cls (void)
128    for (i = 0; i < HERCULES_WIDTH * HERCULES_HEIGHT / 2; i++)    for (i = 0; i < HERCULES_WIDTH * HERCULES_HEIGHT / 2; i++)
129      video[i] = 0x07200720;      video[i] = 0x07200720;
130    
131    hercx = hercy = 0;    herc_x = herc_y = 0;
132    herc_set_cursor ();    herc_set_cursor ();
133      herc_turn_cursor (1);
134  }  }
135    
136  int  int
137  herc_getxy (void)  hercules_getxy (void)
138  {  {
139    return (hercx << 8) | hercy;    return (herc_x << 8) | herc_y;
140  }  }
141    
142  void  void
143  herc_gotoxy (int x, int y)  hercules_gotoxy (int x, int y)
144  {  {
145    hercx = x;    herc_x = x;
146    hercy = y;    herc_y = y;
147    herc_set_cursor ();    herc_set_cursor ();
148  }  }
149    
150  void  void
151  herc_set_attrib (int attr)  hercules_highlight (int state)
152    {
153      herc_current_color = state ? herc_highlight_color : herc_normal_color;
154      herc_highlight_state = state;
155    }
156    
157    void
158    hercules_setcolor (int normal_color, int highlight_color)
159  {  {
160    volatile unsigned char *video = (unsigned char *) HERCULES_VIDEO_ADDR;    herc_normal_color = normal_color;
161      herc_highlight_color = highlight_color;
162        
163    if (attr & 0xF0)    hercules_highlight (herc_highlight_state);
164      attr = 0x70;  }
   else  
     attr = 0x07;  
165    
166    video[((hercy * HERCULES_WIDTH + hercx) << 1) + 1] = attr;  void
167    hercules_nocursor (void)
168    {
169      herc_turn_cursor (0);
170  }  }
171    
172  #endif /* SUPPORT_HERCULES */  #endif /* SUPPORT_HERCULES */

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26