Message ID | 4FF159B2.4010405@siemens.com |
---|---|
State | New |
Headers | show |
On Mon, Jul 2, 2012 at 8:20 AM, Jan Kiszka <jan.kiszka@siemens.com> wrote: > Let the text cursor blink at 5 Hz. No timer is used, instead we rely on > the fact that the display is updated periodically. > > Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> > --- > hw/vga.c | 14 +++++++++++++- > hw/vga_int.h | 2 ++ > 2 files changed, 15 insertions(+), 1 deletions(-) > > diff --git a/hw/vga.c b/hw/vga.c > index acb3f7d..f22c4d9 100644 > --- a/hw/vga.c > +++ b/hw/vga.c > @@ -38,6 +38,8 @@ > > //#define DEBUG_BOCHS_VBE > > +#define VGA_TEXT_CURSOR_PERIOD 200 > + > /* > * Video Graphics Array (VGA) > * > @@ -1300,6 +1302,7 @@ static void vga_draw_text(VGACommonState *s, int full_update) > uint32_t *ch_attr_ptr; > vga_draw_glyph8_func *vga_draw_glyph8; > vga_draw_glyph9_func *vga_draw_glyph9; > + int64_t now = qemu_get_clock_ms(vm_clock); > > /* compute font data address (in plane 2) */ > v = s->sr[VGA_SEQ_CHARACTER_MAP]; > @@ -1370,6 +1373,11 @@ static void vga_draw_text(VGACommonState *s, int full_update) > s->cursor_end = s->cr[VGA_CRTC_CURSOR_END]; > } > cursor_ptr = s->vram_ptr + (s->start_addr + cursor_offset) * 4; > + if (now >= s->cursor_blink_time) { > + s->cursor_blink_time = now + VGA_TEXT_CURSOR_PERIOD; > + s->cursor_blink_state ^= 1; > + full_update = 1; This would force a whole screen refresh at 5Hz. How about moving the check, which you modify below, outside of if (full_update || ch_attr != *ch_attr_ptr) { ... } block? > + } > > depth_index = get_depth_index(s->ds); > if (cw == 16) > @@ -1420,7 +1428,8 @@ static void vga_draw_text(VGACommonState *s, int full_update) > font_ptr, cheight, fgcol, bgcol, dup9); > } > if (src == cursor_ptr && > - !(s->cr[VGA_CRTC_CURSOR_START] & 0x20)) { > + !(s->cr[VGA_CRTC_CURSOR_START] & 0x20) && > + s->cursor_blink_state != 0) { > int line_start, line_last, h; > /* draw the cursor */ > line_start = s->cr[VGA_CRTC_CURSOR_START] & 0x1f; > @@ -1884,6 +1893,9 @@ static void vga_update_display(void *opaque) > } > if (graphic_mode != s->graphic_mode) { > s->graphic_mode = graphic_mode; > + s->cursor_blink_time = > + qemu_get_clock_ms(vm_clock) + VGA_TEXT_CURSOR_PERIOD; > + s->cursor_blink_state = 1; > full_update = 1; > } > switch(graphic_mode) { > diff --git a/hw/vga_int.h b/hw/vga_int.h > index 3b38764..c374474 100644 > --- a/hw/vga_int.h > +++ b/hw/vga_int.h > @@ -156,6 +156,8 @@ typedef struct VGACommonState { > uint32_t last_scr_width, last_scr_height; /* in pixels */ > uint32_t last_depth; /* in bits */ > uint8_t cursor_start, cursor_end; > + int cursor_blink_state; I'd use bool and a name that tells something about the state, like bool cursor_visible; > + int64_t cursor_blink_time; > uint32_t cursor_offset; > unsigned int (*rgb_to_pixel)(unsigned int r, > unsigned int g, unsigned b); > -- > 1.7.3.4 >
diff --git a/hw/vga.c b/hw/vga.c index acb3f7d..f22c4d9 100644 --- a/hw/vga.c +++ b/hw/vga.c @@ -38,6 +38,8 @@ //#define DEBUG_BOCHS_VBE +#define VGA_TEXT_CURSOR_PERIOD 200 + /* * Video Graphics Array (VGA) * @@ -1300,6 +1302,7 @@ static void vga_draw_text(VGACommonState *s, int full_update) uint32_t *ch_attr_ptr; vga_draw_glyph8_func *vga_draw_glyph8; vga_draw_glyph9_func *vga_draw_glyph9; + int64_t now = qemu_get_clock_ms(vm_clock); /* compute font data address (in plane 2) */ v = s->sr[VGA_SEQ_CHARACTER_MAP]; @@ -1370,6 +1373,11 @@ static void vga_draw_text(VGACommonState *s, int full_update) s->cursor_end = s->cr[VGA_CRTC_CURSOR_END]; } cursor_ptr = s->vram_ptr + (s->start_addr + cursor_offset) * 4; + if (now >= s->cursor_blink_time) { + s->cursor_blink_time = now + VGA_TEXT_CURSOR_PERIOD; + s->cursor_blink_state ^= 1; + full_update = 1; + } depth_index = get_depth_index(s->ds); if (cw == 16) @@ -1420,7 +1428,8 @@ static void vga_draw_text(VGACommonState *s, int full_update) font_ptr, cheight, fgcol, bgcol, dup9); } if (src == cursor_ptr && - !(s->cr[VGA_CRTC_CURSOR_START] & 0x20)) { + !(s->cr[VGA_CRTC_CURSOR_START] & 0x20) && + s->cursor_blink_state != 0) { int line_start, line_last, h; /* draw the cursor */ line_start = s->cr[VGA_CRTC_CURSOR_START] & 0x1f; @@ -1884,6 +1893,9 @@ static void vga_update_display(void *opaque) } if (graphic_mode != s->graphic_mode) { s->graphic_mode = graphic_mode; + s->cursor_blink_time = + qemu_get_clock_ms(vm_clock) + VGA_TEXT_CURSOR_PERIOD; + s->cursor_blink_state = 1; full_update = 1; } switch(graphic_mode) { diff --git a/hw/vga_int.h b/hw/vga_int.h index 3b38764..c374474 100644 --- a/hw/vga_int.h +++ b/hw/vga_int.h @@ -156,6 +156,8 @@ typedef struct VGACommonState { uint32_t last_scr_width, last_scr_height; /* in pixels */ uint32_t last_depth; /* in bits */ uint8_t cursor_start, cursor_end; + int cursor_blink_state; + int64_t cursor_blink_time; uint32_t cursor_offset; unsigned int (*rgb_to_pixel)(unsigned int r, unsigned int g, unsigned b);
Let the text cursor blink at 5 Hz. No timer is used, instead we rely on the fact that the display is updated periodically. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> --- hw/vga.c | 14 +++++++++++++- hw/vga_int.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletions(-)