forked from elastomania/across
-
Notifications
You must be signed in to change notification settings - Fork 0
/
D_K.CPP
267 lines (231 loc) · 4.88 KB
/
D_K.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include "all.h"
#define kb_data 0x060
#define kb_ctl 0x061
#define kb_reset 0x080
#define itc_eoi 32
static volatile int Irtam = 0, Marfut = 0;
void mk_wmkeydown( int kod );
void mk_wmkeyup( int kod );
void mk_wmchar( int kod );
#ifdef DOSX286
REALPTR Old_real;
PIHANDLER Old_prot;
#endif
#ifdef DOS
void interrupt (*cim)(...);
#endif
#ifdef WATCOM
void (__interrupt __far *cim)();
#endif
#ifdef DOSX286
static void interrupt far billkezelo( void ) {
#endif
#ifdef DOS
static void interrupt far billkezelo( ... ) {
#endif
#ifdef WATCOM
static void __interrupt billkezelo() {
#endif
unsigned char al, al2, al3;
al = inp( kb_data );
al2 = inp( kb_ctl );
al3 = char(al2 | kb_reset);
outp( kb_ctl, al3 );
outp( kb_ctl, al2 );
if( al < 128 ) {
Irtam = 1;
mk_wmkeydown( al );
}
else
mk_wmkeyup( al-128 );
outp( 0x020, itc_eoi );
}
void billstart( void ) {
delay( 200 );
if( !Marfut ) {
#ifdef DOSX286
DosSetPassToProtVec( 9,
(PIHANDLER)billkezelo,
&Old_prot,
&Old_real);
#else
cim = _dos_getvect( 9 );
_dos_setvect( 9, billkezelo );
#endif
Marfut = 1;
}
}
void billstop( void ) {
int kesz;
if( Marfut ) {
kesz = 0;
while( !kesz ) {
Irtam = 0;
kesz = 1;
//for( i = 0; i < 128; i++ )
// if( leny[i] )
// kesz = 0;
_disable();
if( kesz && !Irtam ) {
#ifdef DOSX286
DosSetRealProtVec( 9, Old_prot, Old_real,
NULL, NULL);
#else
_dos_setvect( 9, cim );
#endif
Marfut = 0;
}
_enable();
}
}
Marfut = 0;
}
// MK_.H-ban levo fuggvenyek:
#define MAXKOD (126)
static volatile int Tomb[MAXKOD+1];
static volatile int Buffsize = 30;
static volatile int* Buffer = NULL;
static volatile int Charszam = 0;
static volatile char Konvtomb[] = "^^1234567890_^^^qwertyuiop^^^^asdfghjkl^^^^^zxcvbnm^.^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^";
void mk_init( void ) {
Konvtomb[1] = 1; // ESC
Konvtomb[28] = MK_ENTER;
Konvtomb[72] = MK_UP;
Konvtomb[80] = MK_DOWN;
Konvtomb[75] = MK_LEFT;
Konvtomb[77] = MK_RIGHT;
Konvtomb[73] = MK_PGUP;
Konvtomb[81] = MK_PGDOWN;
Konvtomb[83] = MK_DEL;
Konvtomb[14] = MK_BACKSPACE;
Konvtomb[42] = 42; // SHIFT
Konvtomb[54] = 42; // SHIFT
for( int i = 0; i < MAXKOD; i++ )
Tomb[i] = 0;
{ Buffer = NEW(int*) int[Buffsize]; }
if( !Buffer )
hiba( "memory mk_init-ben!" );
Charszam = 0;
}
static int konvtomk( int c ) {
if( c == 331 ) return MK_LEFT;
if( c == 333 ) return MK_RIGHT;
if( c == 336 ) return MK_DOWN;
if( c == 328 ) return MK_UP;
if( c == 13 ) return MK_ENTER;
if( c == 27 ) return MK_ESC;
if( c == 329 ) return MK_PGUP;
if( c == 337 ) return MK_PGDOWN;
if( c == 339 ) return MK_DEL;
if( c == 8 ) return MK_BACKSPACE;
return c;
}
int mk_getextchar( void ) {
if( Billint ) {
while( 1 ) {
if( Charszam > 0 ) {
_disable();
int c = Buffer[0];
for( int i = 0; i < Charszam-1; i++ )
Buffer[i] = Buffer[i+1];
Charszam--;
_enable();
return c;
}
}
}
else {
int c = getch();
if( !c )
c = 256+getch();
c = konvtomk( c );
// torlendo, torol
/*if( c == 'q' ) {
// Kiirjuk kepet lemezre:
if( Editbuffer )
Editbuffer->save( "snap_ed.pcx", Korny->pal_fomenu->tomb );
} */
return c;
}
}
void mk_emptychar( void ) {
if( Billint ) {
_disable();
Charszam = 0;
_enable();
}
else {
while( kbhit() ) {
int c = getch();
if( !c )
c = 256+getch();
}
for( int c = 0; c < MAXKOD; c++ )
Tomb[c] = 0;
}
}
int mk_kbhit( void ) {
if( Billint ) {
if( Charszam > 0 )
return 1;
else
return 0;
}
else {
return kbhit();
}
}
int mk_getstate( int kod ) {
if( kod <= 0 || kod >= MAXKOD )
hiba( "mk_getstate-ben kod nem ismert!" );
if( Billint ) {
return Tomb[kod];
}
else {
// Eloszor is csinal egy kis vizsgalatot:
while( kbhit() ) {
int c = getch();
if( !c )
c = 256+getch();
c = konvtomk( c );
if( c > 0 && c < MAXKOD )
Tomb[c] = 10;
}
if( Tomb[kod] > 0 ) {
Tomb[kod]--;
return 1;
}
return 0;
}
}
// Kovetkezo billentyu fuggvenyek nem publikusak:
void mk_wmkeydown( int kod ) {
if( kod < 0 || kod >= MAXKOD )
return;
int valodikod = Konvtomb[kod];
if( valodikod == '^' )
return;
Tomb[valodikod] = 1;
mk_wmchar( valodikod );
}
void mk_wmkeyup( int kod ) {
if( kod < 0 || kod >= MAXKOD )
return;
int valodikod = Konvtomb[kod];
if( valodikod == '^' )
return;
Tomb[valodikod] = 0;
}
void mk_wmchar( int kod ) {
if( kod == 42 )
return;
if( Charszam < Buffsize ) {
if( Tomb[42] ) {
// Ha SHIFT le van nyomva:
if( kod >= 0x61 && kod <= 0x7a )
kod -= 0x20;
}
Buffer[Charszam] = kod;
Charszam++;
}
}