-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuserpc.c
578 lines (497 loc) · 15.9 KB
/
userpc.c
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
/* ****************************************** */
/* Emu41: HP-41C software emulator for PC */
/* */
/* userpc.c user interface for emu41 */
/* system dependant (PC version) */
/* */
/* Version 2.5, J-F Garnier 1997-2007 */
/* ****************************************** */
/* Conditional compilation:
none
*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
/* DISPLAY variables */
static int curx, cury; /* cursor position */
static int nlines=24; /* number of lines */
static int ncols=80; /* number of cols (not used) */
static char fready; /* display ready */
static char fesc=0; /* ESC sequence on going */
static char fcur=0; /* cursor active */
static char fctyp=1; /* cursor type */
static char fupdate=0; /* last screen operation (1:LCD, 2:video display)
/* Welcome strings */
extern char *Welcome1;
extern char *Welcome2;
extern char *Welcome3;
extern char *Welcome4;
/* ********* utilities ********** */
/* specific for Borland Turbo C 2.0 */
#if __TURBOC__ < 0x200
#define _NOCURSOR 0x2000
#define _NORMALCURSOR 0x607
#define _SOLIDCURSOR 0x007
void _setcursortype(int n)
{
_AX=0x0100;
_CX=n;
geninterrupt(0x10);
}
#endif
/* ****************************************** */
/* restore_cursor() */
/* */
/* restore the normal cursor */
/* ****************************************** */
void restore_cursor(void)
{
_setcursortype(_NORMALCURSOR);
}
/* ****************************************** */
/* cursor_off() */
/* */
/* hide the cursor */
/* ****************************************** */
void cursor_off(void)
{
_setcursortype(_NOCURSOR);
}
/* ********* keyboard support ********** */
/* ****************************************** */
/* tstkey() */
/* */
/* Test if one PC key available */
/* returns 1 if yes */
/* ****************************************** */
int tstkey(void)
{
return(kbhit());
}
/* ****************************************** */
/* readkey() */
/* */
/* Read one PC key available */
/* returns -1 if none */
/* ****************************************** */
int readkey(void)
{
if (kbhit())
return(getch());
else
return(-1);
}
/* ****************************************** */
/* waitforkey() */
/* */
/* Wait for one PC key available */
/* returns the keycode */
/* ****************************************** */
int waitforkey(void)
{
return(getch());
}
/* ********* screen functions ********** */
/* ****************************************** */
/* fen_aide() */
/* */
/* Draw the help window */
/* ****************************************** */
void fen_aide(int mode_printer)
{
window(1,1,80,nlines);
textattr(WHITE);
clrscr();
/* draw the welcome strings */
textbackground(BLUE);
textcolor(WHITE);
gotoxy(1,1);
cputs(Welcome1);
gotoxy(3,3);
cputs(Welcome2);
gotoxy(3,4);
cputs(Welcome3);
gotoxy(3,5);
cputs(Welcome4);
/* bottom help line */
gotoxy(1,nlines);
/* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */
cputs(" TAB:speed End:R/S PageUp:BST PageDown:SST <-:CLX ->:X<>Y ^:SHIFT v:RDN ");
/* right window with keyboard mapping */
window(42,2,80,nlines-4);
gotoxy(1,2);
textbackground(BLUE);
/* 1234567890123456789012345678901234567890 */
textcolor(WHITE);
cputs(" K E Y M A P P I N G \n\r");
cputs(" \n\r");
textcolor(YELLOW);
cputs(" S- Y^X X^2 10^X e^X \n\r");
textcolor(WHITE);
cputs(" A:S+ B:1/X C:SQRT D:LOG E:LN \n\r");
cputs(" \n\r");
textcolor(YELLOW);
cputs(" CLS % ASIN ACOS ATAN \n\r");
textcolor(WHITE);
cputs(" F:X<>Y G:RDN H:SIN I:COS J:TAN \n\r");
cputs(" \n\r");
textcolor(YELLOW);
cputs(" ASN LBL GTO \n\r");
textcolor(WHITE);
cputs(" K:XEQ L:STO M:RCL \n\r");
cputs(" \n\r");
textcolor(YELLOW);
cputs(" CATALOG ISG RTN \n\r");
textcolor(WHITE);
cputs(" N:ENTER O:CHS P:EEX \n\r");
cputs(" \n\r");
textcolor(YELLOW);
cputs(" -:X=Y? 7:SF 8:CF 9:FS? | \n\r");
if (nlines>25)
cputs(" \n\r");
cputs(" +:X<=Y? 4:BEEP 5:P-R 6:R-P |with\n\r");
if (nlines>25)
cputs(" \n\r");
cputs(" *:X>Y? 1:FIX 2:SCI 3:ENG |SHIFT\n\r");
if (nlines>25)
cputs(" \n\r");
cputs(" /:X=0? 0:PI .:LASTX | \n\r");
if (nlines>25)
cputs(" ");
textcolor(WHITE);
if (nlines>25) {
gotoxy(2,16); cputs("-:"); gotoxy(10,16); cputs("7:");
gotoxy(18,16); cputs("8:"); gotoxy(27,16); cputs("9:");
gotoxy(2,18); cputs("+:"); gotoxy(10,18); cputs("4:");
gotoxy(18,18); cputs("5:"); gotoxy(27,18); cputs("6:");
gotoxy(2,20); cputs("*:"); gotoxy(10,20); cputs("1:");
gotoxy(18,20); cputs("2:"); gotoxy(27,20); cputs("3:");
gotoxy(2,22); cputs("/:"); gotoxy(10,22); cputs("0:");
gotoxy(18,22); cputs(".:");
}
/* function key labels */
window(1,nlines-2,80,nlines-1);
textattr(WHITE);
clrscr();
window(1,1,80,nlines);
textattr(LIGHTGRAY<<4);
gotoxy( 2,nlines-2); cputs(" f1 ");
gotoxy( 8,nlines-2); cputs(" f2 ");
gotoxy(14,nlines-2); cputs(" f3 ");
gotoxy(20,nlines-2); cputs(" f4 ");
gotoxy(29,nlines-2); cputs(" f5 ");
gotoxy(35,nlines-2); cputs(" f6 ");
gotoxy(41,nlines-2); cputs(" f7 ");
gotoxy(47,nlines-2); cputs(" f8 ");
gotoxy(56,nlines-2); cputs(" f9 ");
gotoxy(62,nlines-2); cputs(" f10 ");
gotoxy(68,nlines-2); cputs(" f11 ");
gotoxy(74,nlines-2); cputs(" f12 ");
gotoxy( 2,nlines-1); cputs(" ON ");
gotoxy( 8,nlines-1); cputs("USER ");
gotoxy(14,nlines-1); cputs("PRGM ");
gotoxy(20,nlines-1); cputs("ALPHA");
gotoxy(29,nlines-1); cputs("SHIFT");
gotoxy(35,nlines-1); cputs(" SST ");
gotoxy(41,nlines-1); cputs(" R/S ");
gotoxy(47,nlines-1); cputs(" XEQ ");
if (mode_printer>=0) {
/* if HP82143 printer emulation installed, then ... */
gotoxy(56,nlines-1); cputs("MODE ");
gotoxy(62,nlines-1); cputs(" PRX ");
gotoxy(68,nlines-1); cputs(" ADV ");
}
else {
gotoxy(56,nlines-1); cputs(" ");
gotoxy(62,nlines-1); cputs(" ");
gotoxy(68,nlines-1); cputs(" ");
}
/* F12 is a reset key */
gotoxy(74,nlines-1); cputs("reset");
/* f5 is the SHIFT key to be drawn in yellow ... */
textattr((LIGHTGRAY<<4)+YELLOW);
gotoxy(29,nlines-2); cputs(" f5 ");
gotoxy(29,nlines-1); cputs("SHIFT");
window(1,1,80,nlines);
textattr(WHITE);
_setcursortype(_NORMALCURSOR);
gotoxy(1,nlines-4);
/* 12345678901234567890123456789012345678 */
cputs(" "); /* clear LCD line */
if (mode_printer>=0) {
/* if HP82143 printer emulation installed, display printer mode */
gotoxy(32,nlines-4);
cputs("PRT:MAN");
}
gotoxy(1,nlines-3);
cputs(" "); /* clear announciator line */
/* init display cursor position on bottom of screen */
curx=1;
cury=nlines-6;
}
/* ****************************************** */
/* prepa_ecran() */
/* */
/* Prepare the screen (ecran in french) */
/* mode _printer is a flag set if HP82143 */
/* printer emulation is installed */
/* ****************************************** */
void prepa_ecran(int mode_printer)
{
int i;
/* find out the number of lines in present display mode */
gotoxy(1,24); /* go to line 24 */
cputs("\n\n\n\n");
nlines=wherey();
if (nlines>25) {
for (i=0;i<8;i++) cputs("\n\n\n\n");
nlines=wherey(); /* should be 43 or 50 ... */
}
/* drax the help window */
fen_aide(mode_printer);
fready=1; /* emulated video display ready */
fesc=0; /* no on going esc sequence */
fupdate=0; /* display update done */
}
/* ****************************************** */
/* fin_ecran() */
/* */
/* End the emulated video display */
/* ****************************************** */
void fin_ecran(void)
{
window(1,1,80,nlines);
textattr(WHITE);
gotoxy(1,nlines);
_setcursortype(_NORMALCURSOR);
cputs(" \r\n");
fready=0; /* emulated video display not ready */
}
/* ****************************************** */
/* update_cursor() */
/* */
/* update the cursor type in emulated video */
/* display */
/* ****************************************** */
void update_cursor(void)
{
if (fcur==0) {
_setcursortype(_NOCURSOR); /* cursor off */
}
else {
if (fctyp==2)
_setcursortype(_NORMALCURSOR); /* insert cursor */
else
_setcursortype(_SOLIDCURSOR); /* replace cursor */
}
}
/* ********* LCD emulation support ********** */
/* ****************************************** */
/* update_display() */
/* */
/* update the LCD */
/* with display (buf1) and */
/* announciator (buf2) data */
/* ****************************************** */
void update_display(char *buf1, char *buf2)
{
if (fupdate!=1) {
/* if previous access was not for LCD data, init window */
window(1,1,80,nlines);
textattr(WHITE);
_setcursortype(_NOCURSOR);
gotoxy(1,nlines-4);
fupdate=1;
}
if (buf1!=NULL) {
gotoxy(2,nlines-4);
cputs(buf1);
}
if (buf2!=NULL) {
gotoxy(1,nlines-3);
cputs(buf2);
}
if (fcur) {
/* if cursor active in video screen window, restore it */
window(1,2,40,nlines-5);
textattr(BLACK*16+LIGHTGREEN);
gotoxy(curx,cury);
update_cursor();
fupdate=2;
}
}
/* ****************************************** */
/* aff_mode_printer() */
/* */
/* display the printer mode */
/* ****************************************** */
void aff_mode_printer(int mode)
{
gotoxy(36,nlines-4);
switch (mode) {
case 0: cputs("MAN"); break;
case 1: cputs("NOR"); break;
case 2: cputs("TRA"); break;
case 3: cputs("OFF"); break;
default:cputs(" ");
}
}
/* ****************************************** */
/* aff_mode_emu() */
/* */
/* display the emulator state */
/* ****************************************** */
void aff_mode_emu(char c)
{
gotoxy(30,nlines-4);
putch(c);
}
/* ********* display emulation support ********** */
/* ****************************************** */
/* clrdsp() */
/* */
/* clear the display area,and init state */
/* ****************************************** */
void clrdsp(void)
{
window(1,2,40,nlines-5);
textattr(BLACK*16+LIGHTGREEN);
clrscr();
curx=1;
cury=1;
gotoxy(curx,cury);
fesc=0;
fctyp=1;
fcur=0;
fupdate=2;
update_cursor();
}
/* ****************************************** */
/* disp_string() */
/* */
/* display a string in the display area */
/* if display area not initialized, */
/* do a simple printf (startup/end msgs) */
/* ****************************************** */
void disp_string(char *s)
{
if (!fready)
printf("%s",s);
else {
if (fupdate!=2) {
/* if previous access was not for display data, init window */
window(1,2,40,nlines-5);
textattr(BLACK*16+LIGHTGREEN);
gotoxy(curx,cury);
update_cursor();
fupdate=2;
}
cputs(s);
curx=wherex();
cury=wherey();
}
}
/* ****************************************** */
/* disp_char() */
/* */
/* send a character to the display area */
/* manage the ESC sequences */
/* (HP82163 compatible) */
/* convert special HP41 characters */
/* ****************************************** */
void disp_char(int n)
{
int i;
if (fupdate!=2) {
/* if previous access was not for display data, init window */
window(1,2,40,nlines-5);
textattr(BLACK*16+LIGHTGREEN);
gotoxy(curx,cury);
update_cursor();
fupdate=2;
}
switch (fesc) {
case 0:
if (n==8) {
/* for Paname compatibility */
if (curx>1) curx--;
else {
if (cury>1) {
cury--;
curx=40;
}
}
gotoxy(curx, cury);
}
else if (n==27)
fesc=1; /* ESC sequence */
else {
switch (n) {
/* convert special HP41 characters to regular ASCII */
case 0: n='*'; break;
case 12: n='u'; break;
case 28: n='s'; break;
case 29: n='#'; break;
case 124: n='a'; break;
case 127: n='`'; break;
case 10:
case 13: break;
default:
if ((n<32)||(n>127)) n='.'; /* non-printable characters */
}
gotoxy(curx, cury);
putch(n);
curx=wherex();
cury=wherey();
}
break;
case 1:
fesc=0;
switch (n) {
case 'A': if (cury>1) cury--; break; /* csrup */
case 'B': if (cury<(nlines-5)) cury++; break; /* csrdn */
case 'C':
if (curx<40) curx++;
else {
if (cury<(nlines-5)) {
cury++;
curx=1;
}
}
break; /* csrr */
case 'D':
if (curx>1) curx--;
else {
if (cury>1) {
cury--;
curx=40;
}
}
break; /* csrl */
case 'E': clrdsp(); break; /* clrdsp */
case 'H': curx=1; cury=1; break; /* home */
case 'J': /* clrend */
gotoxy(curx,cury);
for (i=curx;i<=40;i++) cputs(" ");
break;
case 'Q': fctyp=2; break; /* csrins */
case 'R': fctyp=1; break; /* csrrep */
case '<': fcur=0; break; /* csroff */
case '>': fcur=1; break; /* csron */
case '%': fesc=2; break; /* csrpos */
}
gotoxy(curx,cury);
update_cursor();
break;
case 2: /* curpos, x value modulo 64*/
curx=(n&63)+1;
fesc=3;
break;
case 3: /* curpos, y value modulo 64 (not compatible with HP82163) */
cury=(n&63)+1;
gotoxy(curx,cury);
update_cursor();
fesc=0;
break;
}
}