* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / libc / bios / vt52.c
blob4574c1243bcf699bbf50e403862d647cb4502840
1 /* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
2 * This file is part of the Linux-8086 C library and is distributed
3 * under the GNU Library General Public License.
4 */
6 #if !__FIRST_ARG_IN_AX__
7 #ifdef __AS386_16__
8 #ifdef __STANDALONE__
10 #include <bios.h>
11 #include <errno.h>
12 int errno;
14 extern void (*__smart_putch)();
16 #define CTRL(x) ((x)&0x1F)
17 static int last_attr = 0x07;
18 static int con_mode;
19 static unsigned char con_height = 24, con_width = 79;
21 static int con_colour = 0;
22 static unsigned char con_row, con_col;
24 vt52_putch(c)
25 int c;
27 static int ctrl = 0;
28 int new_attr;
29 __smart_putch = vt52_putch();
31 if( con_mode==0 ) asm_coninit();
33 switch( ctrl )
35 case 1:
36 ctrl=0;
37 switch(c)
39 case 'A': if( con_row ) con_row--; asm_cpos(con_row, con_col); break;
40 case 'B': if( con_row != con_height ) con_row++;
41 asm_cpos(con_row, con_col); break;
42 case 'C': if( con_col != con_height ) con_col++;
43 asm_cpos(con_row, con_col); break;
44 case 'D': if( con_col ) con_col--; asm_cpos(con_row, con_col); break;
45 case 'E': last_attr = 0x07; asm_cls();
46 case 'H': asm_cpos(0,0); break;
47 case 'J': asm_cls(); break;
48 case 'K': break;
49 case 'R': ctrl = 2; break; /* Foreground */
50 case 'S': ctrl = 3; break; /* Background */
51 case 'Y': ctrl = 4; break; /* ttypos */
53 break;
54 case 2: ctrl=0; new_attr = (last_attr & 0xF0) + (c&0xF);
55 if(0) {
56 case 3: ctrl=0; new_attr = (last_attr & 0x0F) + (c<<4);
58 switch(c)
60 case '_': if( !con_colour ) last_attr = (last_attr&0x88) + 1;
61 break;
62 case '!': last_attr = (last_attr&0x88) + 0x70; break;
63 case ' ': last_attr = 0x07; break;
64 case '+': last_attr |= 0x08; break;
65 case '*': last_attr |= 0x80; break;
67 default: if( con_colour )
68 last_attr = new_attr;
70 break;
71 case 4: ctrl=5; con_col = c-' '; break;
72 case 5: ctrl=0; con_row = c-' '; asm_cpos(con_row, con_col); break;
73 break;
75 default:
76 if( c & 0xE0 )
77 { asm_colour(last_attr) ; asm_putc(c); }
78 else switch(c)
80 default:
81 asm_putc(c);
82 break;
83 case CTRL('I'):
84 asm_gpos();
85 con_col = ((con_col+8)& -8);
86 asm_cpos(con_row, con_col);
87 break;
88 case CTRL('L'):
89 asm_cpos(0,0);
90 asm_cls();
91 break;
92 case CTRL('['):
93 ctrl = 1;
94 asm_gpos();
95 break;
97 break;
101 static asm_coninit()
103 #asm
104 mov ax,#$0F00
105 int $10
106 mov _con_mode,ax
107 #endasm
108 if( (con_mode &0xFF) > 39 ) con_width = (con_mode>>8);
109 if( (con_mode&0xFF) != 0x7)
110 con_colour = 1;
113 static asm_putc(c)
115 #asm
116 #if !__FIRST_ARG_IN_AX__
117 mov bx,sp
118 mov ax,[bx+2]
119 #endif
120 cmp al,#$0A
121 jne not_nl
122 mov ax,#$0E0D
123 mov bx,#7
124 int $10
125 mov al,#$0A
126 not_nl:
127 mov ah,#$0E
128 mov bx,#7
129 int $10
130 #endasm
133 static asm_cls()
135 #asm
136 push bp ! Bug in some old BIOS`s
137 !mov ax,#$0500
138 !int $10
139 mov ax,#$0600
140 mov bh,_last_attr
141 mov cx,#$0000
142 mov dl,_con_width
143 mov dh,_con_height
144 int $10
145 pop bp
146 #endasm
149 static asm_cpos(r,c)
151 #asm
152 #if __FIRST_ARG_IN_AX__
153 mov bx,sp
154 mov dh,al
155 mov ax,[bx+2]
156 mov dl,al
157 #else
158 mov bx,sp
159 mov ax,[bx+2]
160 mov dh,al
161 mov ax,[bx+4]
162 mov dl,al
163 #endif
164 mov ah,#$02
165 mov bx,#7
166 int $10
167 #endasm
170 static asm_colour(c)
172 #asm
173 #if __FIRST_ARG_IN_AX__
174 mov bx,ax
175 #else
176 mov bx,sp
177 mov bx,[bx+2]
178 #endif
179 mov ah,#$08
180 int $10
181 mov ah,#$09
182 mov cx,#1
183 int $10
184 #endasm
187 static asm_gpos()
189 #asm
190 mov ah,#$03
191 mov bx,#7
192 int $10
193 mov [_con_row],dh
194 mov [_con_col],dl
195 mov ax,cx
196 #endasm
199 #endif
200 #endif
201 #endif