Skip to content

Commit ac0c945

Browse files
committed
DOSVGA now uses the common/blink.c code for cursor and blink handling. This enables 'real' blinking and some cursor styles (caret, half-block, underscore, full-block).
1 parent f485b76 commit ac0c945

6 files changed

Lines changed: 55 additions & 87 deletions

File tree

common/dosutil.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
/* Common pieces between DOS, DOSVGA, and VT built for DOS
44
'pdcutil' functions */
55

6+
#ifdef CHECK_FOR_BLINKING
7+
void PDC_check_for_blinking( void);
8+
#endif
9+
610
void PDC_beep(void)
711
{
812
PDCREGS regs;
@@ -49,6 +53,10 @@ void PDC_napmsl( long ms)
4953
long ticks_elapsed = getdosmemdword(0x46c) - tick0;
5054
PDCREGS regs;
5155

56+
#ifdef CHECK_FOR_BLINKING
57+
if( SP)
58+
PDC_check_for_blinking( );
59+
#endif
5260
if( ticks_elapsed < 0L) /* midnight rollover */
5361
ticks_elapsed += MAX_TICK;
5462
if (ticks_elapsed >= ticks_to_wait)

dosvga/pdcdisp.c

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "../common/acs_defs.h"
1212
#include "../common/pdccolor.h"
13+
#include "../common/blink.c"
1314

1415
#ifdef __DJGPP__
1516
#include <go32.h>
@@ -41,15 +42,6 @@ static void _video_read(void *data, unsigned long addr, size_t size);
4142
static void _video_write(unsigned long addr, const void *data, size_t size);
4243
static unsigned _set_window(unsigned window, unsigned long addr);
4344

44-
/* position hardware cursor at (y, x) */
45-
46-
void PDC_gotoyx(int row, int col)
47-
{
48-
if (PDC_state.cursor_visible)
49-
PDC_private_cursor_off();
50-
PDC_private_cursor_on(row, col);
51-
}
52-
5345
/* Draw a run of characters with the same colors */
5446
/* Used with 4 bit pixels only */
5547

@@ -76,6 +68,21 @@ static void _new_packet(unsigned long colors, int lineno, int x, int len, const
7668

7769
/* Which plane we're writing */
7870
unsigned plane;
71+
unsigned cursor_line = PDC_state.font_height;
72+
73+
if( 1 == SP->drawing_cursor) /* cursor is bottom quarter of glyph */
74+
cursor_line -= cursor_line / 4;
75+
else if( 2 == SP->drawing_cursor) /* cursor is full block */
76+
cursor_line = 0;
77+
else if( 5 == SP->drawing_cursor) /* cursor is bottom half of glyph */
78+
cursor_line /= 2;
79+
80+
if( (*srcp & A_BLINK) && SP->blink_state && (SP->termattrs & A_BLINK))
81+
{
82+
fore ^= back;
83+
back ^= fore;
84+
fore ^= back;
85+
}
7986

8087
/* Compute these just once */
8188
for (i = 0; i < len; ++i)
@@ -125,6 +132,8 @@ static void _new_packet(unsigned long colors, int lineno, int x, int len, const
125132
unsigned num_bytes = 0;
126133
int col;
127134

135+
if( line == cursor_line)
136+
invert ^= 0xff;
128137
/* Loop once per column */
129138
cp = addr;
130139
for (col = 0; col < len; ++col)
@@ -378,7 +387,7 @@ we need to swap bits 0-7 with those in 16-23. */
378387

379388
/* PDC_transform_line for 8, 15, 16, 24 and 32 bit pixels */
380389

381-
static void _transform_line_8(int lineno, int x, int len, const chtype *srcp)
390+
static void _transform_line_8( const int lineno, const int x, const int len, const chtype *srcp)
382391
{
383392
unsigned char bytes[1024];
384393
unsigned long addr = _address_8(lineno, x);
@@ -399,7 +408,14 @@ static void _transform_line_8(int lineno, int x, int len, const chtype *srcp)
399408
unsigned char r_mask = 0x80 >> ((PDC_state.font_width - 1) % 8);
400409

401410
int col;
402-
unsigned line;
411+
unsigned line, cursor_line = PDC_state.font_height;
412+
413+
if( 1 == SP->drawing_cursor) /* cursor is bottom quarter of glyph */
414+
cursor_line -= cursor_line / 4;
415+
else if( 2 == SP->drawing_cursor) /* cursor is full block */
416+
cursor_line = 0;
417+
else if( 5 == SP->drawing_cursor) /* cursor is bottom half of glyph */
418+
cursor_line /= 2;
403419

404420
/* Compute basic glyph data only once per character */
405421
for (col = 0; col < len; col++)
@@ -472,10 +488,7 @@ static void _transform_line_8(int lineno, int x, int len, const chtype *srcp)
472488
byte |= r_mask;
473489
if (line == PDC_state.underline)
474490
byte |= glyphs[col].ul_mask;
475-
if (PDC_state.cursor_visible
476-
&& lineno == PDC_state.cursor_row
477-
&& col + x == PDC_state.cursor_col
478-
&& PDC_state.cursor_start <= line && line <= PDC_state.cursor_end)
491+
if( line > cursor_line)
479492
byte ^= 0xFF;
480493

481494
/* Number of pixels to render on this pass */
@@ -544,7 +557,7 @@ static unsigned long _get_colors(chtype glyph)
544557

545558
if ((attr & A_BOLD) != 0 && fore < 16)
546559
fore |= 8;
547-
if ((attr & A_BLINK) != 0 && back < 16)
560+
if ((attr & A_BLINK) != 0 && back < 16 && !(SP->termattrs & A_BLINK))
548561
back |= 8;
549562

550563
if (attr & A_REVERSE)
@@ -558,41 +571,6 @@ static unsigned long _get_colors(chtype glyph)
558571
return ((unsigned long)back << 16) | fore;
559572
}
560573

561-
void PDC_private_cursor_off(void)
562-
{
563-
/* This gets called before atrtab is set up; avoid a null dereference */
564-
if (!SP || !SP->pairs)
565-
return;
566-
567-
PDC_state.cursor_visible = FALSE;
568-
if (PDC_state.cursor_row < LINES
569-
&& PDC_state.cursor_col < COLS)
570-
{
571-
static const chtype space = ' ';
572-
573-
PDC_transform_line(PDC_state.cursor_row, PDC_state.cursor_col, 1,
574-
(curscr && curscr->_y)
575-
? &curscr->_y[PDC_state.cursor_row][PDC_state.cursor_col]
576-
: &space);
577-
}
578-
}
579-
580-
void PDC_private_cursor_on(int row, int col)
581-
{
582-
PDC_state.cursor_visible = TRUE;
583-
PDC_state.cursor_row = row;
584-
PDC_state.cursor_col = col;
585-
if (row < LINES && col < COLS)
586-
{
587-
static const chtype space = ' ';
588-
589-
PDC_transform_line(PDC_state.cursor_row, PDC_state.cursor_col, 1,
590-
(curscr && curscr->_y)
591-
? &curscr->_y[PDC_state.cursor_row][PDC_state.cursor_col]
592-
: &space);
593-
}
594-
}
595-
596574
static unsigned long _address_4(int row, int col)
597575
{
598576
return (unsigned long)row * PDC_state.bytes_per_line * PDC_state.font_height + col;

dosvga/pdcdos.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,9 @@ struct PDC_video_state
7878
unsigned font_width; /* Width of font in pixels */
7979
unsigned font_height; /* Height of font in pixels */
8080
unsigned underline; /* Where to draw the underline */
81-
82-
/* Cursor state */
83-
bool cursor_visible;
84-
int cursor_row;
85-
int cursor_col;
86-
unsigned char cursor_start;
87-
unsigned char cursor_end;
8881
};
8982
extern struct PDC_video_state PDC_state;
9083

91-
extern void PDC_private_cursor_off(void);
92-
extern void PDC_private_cursor_on(int row, int col);
93-
9484
#ifdef __DJGPP__ /* Note: works only in plain DOS... */
9585
# define PDC_FLAT 1
9686
# if DJGPP == 2

dosvga/pdcscrn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ int PDC_scr_open(void)
184184
SP->audible = TRUE;
185185

186186
SP->mono = FALSE;
187-
SP->termattrs = A_COLOR | A_REVERSE | A_UNDERLINE;
187+
SP->termattrs = A_COLOR | A_REVERSE | A_UNDERLINE | A_BLINK;
188188

189189
SP->_preserve = FALSE;
190190

dosvga/pdcsetsc.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,11 @@ pdcsetsc
4040

4141
int PDC_curs_set(int visibility)
4242
{
43-
int ret_vis, start, end;
43+
const int ret_vis = SP->visibility;
4444

4545
PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility));
4646

47-
ret_vis = SP->visibility;
4847
SP->visibility = visibility;
49-
50-
switch (visibility)
51-
{
52-
case 0: /* invisible */
53-
start = 1;
54-
end = 0;
55-
break;
56-
case 2: /* highly visible */
57-
start = 0; /* full-height block */
58-
end = PDC_state.font_height - 1;
59-
break;
60-
default: /* normal visibility */
61-
start = SP->orig_cursor >> 8;
62-
end = SP->orig_cursor & 0xFF;
63-
}
64-
65-
PDC_private_cursor_off();
66-
PDC_state.cursor_start = start;
67-
PDC_state.cursor_end = end;
68-
if (visibility != 0)
69-
PDC_private_cursor_on(PDC_state.cursor_row, PDC_state.cursor_col);
70-
7148
return ret_vis;
7249
}
7350

@@ -79,7 +56,20 @@ void PDC_set_title(const char *title)
7956

8057
int PDC_set_blink(bool blinkon)
8158
{
82-
return blinkon ? ERR : OK;
59+
if (!SP)
60+
return ERR;
61+
else
62+
{
63+
const attr_t prev_termattrs = SP->termattrs;
64+
65+
if( blinkon)
66+
SP->termattrs |= A_BLINK;
67+
else
68+
SP->termattrs &= ~A_BLINK;
69+
if( prev_termattrs != SP->termattrs)
70+
curscr->_clear = TRUE;
71+
return OK;
72+
}
8373
}
8474

8575
int PDC_set_bold(bool boldon)

dosvga/pdcutil.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* PDCurses */
22

3+
#define CHECK_FOR_BLINKING
4+
35
#include "pdcdos.h"
46
#include "../common/dosutil.c"
57

0 commit comments

Comments
 (0)