1 /* Public Domain Curses */
2
3 #include "pdcdos.h"
4
5 /* ACS definitions originally by jshumate@wrdis01.robins.af.mil -- these
6 match code page 437 and compatible pages (CP850, CP852, etc.) */
7
8 #ifdef CHTYPE_LONG
9
10 # define A(x) ((chtype)x | A_ALTCHARSET)
11
12 chtype acs_map[128] =
13 {
14 A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), A(10),
15 A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19),
16 A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27), A(28),
17 A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&', '\'', '(',
18 ')', '*',
19
20 A(0x1a), A(0x1b), A(0x18), A(0x19),
21
22 '/',
23
24 0xdb,
25
26 '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
27 '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
28 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
29 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
30
31 A(0x04), 0xb1,
32
33 'b', 'c', 'd', 'e',
34
35 0xf8, 0xf1, 0xb0, A(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d, 0x2d,
36 0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3, 0xf2, 0xe3,
37 0xd8, 0x9c, 0xf9,
38
39 A(127)
40 };
41
42 # undef A
43
44 #endif
45
46 #ifdef __PACIFIC__
movedata(unsigned sseg,unsigned soff,unsigned dseg,unsigned doff,unsigned n)47 void movedata(unsigned sseg, unsigned soff, unsigned dseg,
48 unsigned doff, unsigned n)
49 {
50 far char *src = MK_FP(sseg, soff);
51 far char *dst = MK_FP(dseg, doff);
52
53 while (n--)
54 *dst++ = *src++;
55 }
56 #endif
57
58 /* position hardware cursor at (y, x) */
59
PDC_gotoyx(int row,int col)60 void PDC_gotoyx(int row, int col)
61 {
62 PDCREGS regs;
63
64 PDC_LOG(("PDC_gotoyx() - called: row %d col %d\n", row, col));
65
66 regs.h.ah = 0x02;
67 regs.h.bh = 0;
68 regs.h.dh = (unsigned char) row;
69 regs.h.dl = (unsigned char) col;
70 PDCINT(0x10, regs);
71 }
72
73 /* update the given physical line to look like the corresponding line in
74 curscr */
75
PDC_transform_line(int lineno,int x,int len,const chtype * srcp)76 void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
77 {
78 int j;
79
80 PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno));
81
82 if (pdc_direct_video)
83 {
84 #if SMALL || MEDIUM
85 # ifndef __PACIFIC__
86 struct SREGS segregs;
87 # endif
88 int ds;
89 #endif
90 /* this should be enough for the maximum width of a screen */
91
92 struct {unsigned char text, attr;} temp_line[256];
93
94 /* replace the attribute part of the chtype with the actual
95 color value for each chtype in the line */
96
97 for (j = 0; j < len; j++)
98 {
99 chtype ch = srcp[j];
100
101 temp_line[j].attr = pdc_atrtab[ch >> PDC_ATTR_SHIFT];
102 #ifdef CHTYPE_LONG
103 if (ch & A_ALTCHARSET && !(ch & 0xff80))
104 ch = acs_map[ch & 0x7f];
105 #endif
106 temp_line[j].text = ch & 0xff;
107 }
108
109 #ifdef __DJGPP__
110 dosmemput(temp_line, len * 2,
111 (unsigned long)_FAR_POINTER(pdc_video_seg,
112 pdc_video_ofs + (lineno * curscr->_maxx + x) * 2));
113 #else
114 # if SMALL || MEDIUM
115 # ifdef __PACIFIC__
116 ds = FP_SEG((void far *) temp_line);
117 # else
118 segread(&segregs);
119 ds = segregs.ds;
120 # endif
121 movedata(ds, (int)temp_line, pdc_video_seg,
122 pdc_video_ofs + (lineno * curscr->_maxx + x) * 2, len * 2);
123 # else
124 memcpy((void *)_FAR_POINTER(pdc_video_seg,
125 pdc_video_ofs + (lineno * curscr->_maxx + x) * 2),
126 temp_line, len * 2);
127 # endif
128 #endif
129
130 }
131 else
132 for (j = 0; j < len;)
133 {
134 PDCREGS regs;
135 unsigned short count = 1;
136 chtype ch = srcp[j];
137
138 while ((j + count < len) && (ch == srcp[j + count]))
139 count++;
140
141 PDC_gotoyx(lineno, j + x);
142
143 regs.h.ah = 0x09;
144 regs.W.bx = pdc_atrtab[ch >> PDC_ATTR_SHIFT];
145 regs.W.cx = count;
146 #ifdef CHTYPE_LONG
147 if (ch & A_ALTCHARSET && !(ch & 0xff80))
148 ch = acs_map[ch & 0x7f];
149 #endif
150 regs.h.al = (unsigned char) (ch & 0xff);
151
152 PDCINT(0x10, regs);
153
154 j += count;
155 }
156 }
157