diff --git a/dos/pdcdisp.c b/dos/pdcdisp.c index ac2b719e..d27d3894 100644 --- a/dos/pdcdisp.c +++ b/dos/pdcdisp.c @@ -70,15 +70,41 @@ void PDC_gotoyx(int row, int col) PDCINT(0x10, regs); } -/* update the given physical line to look like the corresponding line in - curscr */ - -void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) +void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp) { + attr_t sysattrs; int j; + short fore, back; + unsigned char mapped_attr; PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno)); + sysattrs = SP->termattrs; + PDC_pair_content(PAIR_NUMBER(attr), &fore, &back); + + if (attr & A_BOLD) + fore |= 8; + if (attr & A_BLINK) + back |= 8; + + fore = pdc_curstoreal[fore]; + back = pdc_curstoreal[back]; + + if (attr & A_REVERSE) + { + if (sysattrs & A_BLINK) + mapped_attr = (back & 7) | (((fore & 7) | (back & 8)) << 4); + else + mapped_attr = back | (fore << 4); + } + else + { + if ((attr & A_UNDERLINE) && (sysattrs & A_UNDERLINE)) + fore = (fore & 8) | 1; + + mapped_attr = fore | (back << 4); + } + if (pdc_direct_video) { #if SMALL || MEDIUM @@ -98,7 +124,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) { chtype ch = srcp[j]; - temp_line[j].attr = pdc_atrtab[ch >> PDC_ATTR_SHIFT]; + temp_line[j].attr = mapped_attr; #ifdef CHTYPE_LONG if (ch & A_ALTCHARSET && !(ch & 0xff80)) ch = acs_map[ch & 0x7f]; @@ -141,7 +167,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) PDC_gotoyx(lineno, j + x); regs.h.ah = 0x09; - regs.W.bx = pdc_atrtab[ch >> PDC_ATTR_SHIFT]; + regs.W.bx = mapped_attr; regs.W.cx = count; #ifdef CHTYPE_LONG if (ch & A_ALTCHARSET && !(ch & 0xff80)) @@ -154,3 +180,32 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) j += count; } } + +/* update the given physical line to look like the corresponding line in + curscr */ + +void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) +{ + attr_t old_attr, attr; + int i, j; + + PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno)); + + old_attr = *srcp & (A_ATTRIBUTES ^ A_ALTCHARSET); + + for (i = 1, j = 1; j < len; i++, j++) + { + attr = srcp[i] & (A_ATTRIBUTES ^ A_ALTCHARSET); + + if (attr != old_attr) + { + _new_packet(old_attr, lineno, x, i, srcp); + old_attr = attr; + srcp += i; + x += i; + i = 0; + } + } + + _new_packet(old_attr, lineno, x, i, srcp); +} diff --git a/dos/pdcdos.h b/dos/pdcdos.h index 18d6608e..02be07aa 100644 --- a/dos/pdcdos.h +++ b/dos/pdcdos.h @@ -3,12 +3,6 @@ #include #include -#ifdef CHTYPE_LONG -# define PDC_ATTR_SHIFT 19 -#else -# define PDC_ATTR_SHIFT 8 -#endif - #if defined(_MSC_VER) || defined(_QC) # define MSC 1 #endif @@ -54,7 +48,7 @@ #include -extern unsigned char *pdc_atrtab; +extern short pdc_curstoreal[16]; extern int pdc_adapter; extern int pdc_scrnmode; extern int pdc_font; diff --git a/dos/pdcscrn.c b/dos/pdcscrn.c index ccb9c6e0..fcb5a3b9 100644 --- a/dos/pdcscrn.c +++ b/dos/pdcscrn.c @@ -4,15 +4,9 @@ #include -#ifdef CHTYPE_LONG -# define PDC_OFFSET 32 -#else -# define PDC_OFFSET 8 -#endif - /* COLOR_PAIR to attribute encoding table. */ -unsigned char *pdc_atrtab = (unsigned char *)NULL; +static struct {short f, b;} atrtab[PDC_COLOR_PAIRS]; int pdc_adapter; /* screen type */ int pdc_scrnmode; /* default screen mode */ @@ -22,7 +16,7 @@ bool pdc_bogus_adapter; /* TRUE if adapter has insane values */ unsigned pdc_video_seg; /* video base segment */ unsigned pdc_video_ofs; /* video base offset */ -static short curstoreal[16], realtocurs[16] = +static short realtocurs[16] = { COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE, COLOR_BLACK + 8, @@ -30,6 +24,8 @@ static short curstoreal[16], realtocurs[16] = COLOR_MAGENTA + 8, COLOR_YELLOW + 8, COLOR_WHITE + 8 }; +short pdc_curstoreal[16]; + static bool sizeable = FALSE; /* TRUE if adapter is resizeable */ static unsigned short *saved_screen = NULL; @@ -495,10 +491,6 @@ void PDC_scr_free(void) { if (SP) free(SP); - if (pdc_atrtab) - free(pdc_atrtab); - - pdc_atrtab = (unsigned char *)NULL; } /* open the physical screen -- allocate SP, miscellaneous intialization, @@ -517,13 +509,12 @@ int PDC_scr_open(int argc, char **argv) PDC_LOG(("PDC_scr_open() - called\n")); SP = calloc(1, sizeof(SCREEN)); - pdc_atrtab = calloc(PDC_COLOR_PAIRS * PDC_OFFSET, 1); - if (!SP || !pdc_atrtab) + if (!SP) return ERR; for (i = 0; i < 16; i++) - curstoreal[realtocurs[i]] = i; + pdc_curstoreal[realtocurs[i]] = i; SP->orig_attr = FALSE; @@ -658,33 +649,14 @@ void PDC_save_screen_mode(int i) void PDC_init_pair(short pair, short fg, short bg) { - unsigned char att; - chtype i; - - fg = curstoreal[fg]; - bg = curstoreal[bg]; - - for (i = 0; i < PDC_OFFSET; i++) - { - att = fg | (bg << 4); - - if (i & (A_REVERSE >> PDC_ATTR_SHIFT)) - att = bg | (fg << 4); - if (i & (A_UNDERLINE >> PDC_ATTR_SHIFT)) - att = 1; - if (i & (A_BOLD >> PDC_ATTR_SHIFT)) - att |= 8; - if (i & (A_BLINK >> PDC_ATTR_SHIFT)) - att |= 128; - - pdc_atrtab[pair * PDC_OFFSET + i] = att; - } + atrtab[pair].f = fg; + atrtab[pair].b = bg; } int PDC_pair_content(short pair, short *fg, short *bg) { - *fg = realtocurs[pdc_atrtab[pair * PDC_OFFSET] & 0x0F]; - *bg = realtocurs[(pdc_atrtab[pair * PDC_OFFSET] & 0xF0) >> 4]; + *fg = atrtab[pair].f; + *bg = atrtab[pair].b; return OK; } @@ -697,7 +669,7 @@ static short _egapal(short color) PDCREGS regs; regs.W.ax = 0x1007; - regs.h.bl = curstoreal[color]; + regs.h.bl = pdc_curstoreal[color]; PDCINT(0x10, regs);