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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
|
/*
** SCCS ID: @(#)cio.c 2.10 1/22/25
**
** @file cio.c
**
** @author Warren R. Carithers
**
** Based on: c_io.c 1.13 (Ken Reek, Jon Coles, Warren R. Carithers)
**
** Console I/O routines
**
** This module implements a simple set of input and output routines
** for the console screen and keyboard on the machines in the DSL.
** Refer to the header file comments for complete details.
**
** Naming conventions:
**
** Externally-visible functions have names beginning with the
** characters "cio_".
**
*/
#include <cio.h>
#include <lib.h>
#include <support.h>
#include <x86/arch.h>
#include <x86/pic.h>
#include <x86/ops.h>
/*
** Bit masks for the lower five and eight bits of a value
*/
#define BMASK5 0x1f
#define BMASK8 0xff
/*
** Video parameters
*/
#define SCREEN_MIN_X 0
#define SCREEN_MIN_Y 0
#define SCREEN_X_SIZE 80
#define SCREEN_Y_SIZE 25
#define SCREEN_MAX_X (SCREEN_X_SIZE - 1)
#define SCREEN_MAX_Y (SCREEN_Y_SIZE - 1)
/*
** Video state
*/
static unsigned int scroll_min_x, scroll_min_y;
static unsigned int scroll_max_x, scroll_max_y;
static unsigned int curr_x, curr_y;
static unsigned int min_x, min_y;
static unsigned int max_x, max_y;
// pointer to input notification function
static void (*notify)(int);
#ifdef SA_DEBUG
#include <stdio.h>
#define cio_putchar putchar
#define cio_puts(x) fputs(x, stdout)
#endif
/*
** VGA definitions.
*/
// calculate the memory address of a specific character position
// within VGA memory
#define VIDEO_ADDR(x, y) \
(unsigned short *)(VID_BASE_ADDR + 2 * ((y) * SCREEN_X_SIZE + (x)))
// port addresses
#define VGA_CTRL_IX_ADDR 0x3d4
#define VGA_CTRL_CUR_HIGH 0x0e // cursor location, high byte
#define VGA_CTRL_CUR_LOW 0x0f // cursor location, low byte
#define VGA_CTRL_IX_DATA 0x3d5
// attribute bits
#define VGA_ATT_BBI 0x80 // blink, or background intensity
#define VGA_ATT_BGC 0x70 // background color
#define VGA_ATT_FICS 0x80 // foreground intensity or char font select
#define VGA_ATT_FGC 0x70 // foreground color
// color selections
#define VGA_BG_BLACK 0x0000 // background colors
#define VGA_BG_BLUE 0x1000
#define VGA_BG_GREEN 0x2000
#define VGA_BG_CYAN 0x3000
#define VGA_BG_RED 0x4000
#define VGA_BG_MAGENTA 0x5000
#define VGA_BG_BROWN 0x6000
#define VGA_BG_WHITE 0x7000
#define VGA_FG_BLACK 0x0000 // foreground colors
#define VGA_FG_BLUE 0x0100
#define VGA_FG_GREEN 0x0200
#define VGA_FG_CYAN 0x0300
#define VGA_FG_RED 0x0400
#define VGA_FG_MAGENTA 0x0500
#define VGA_FG_BROWN 0x0600
#define VGA_FG_WHITE 0x0700
// color combinations
#define VGA_WHITE_ON_BLACK (VGA_FG_WHITE | VGA_BG_BLACK)
#define VGA_BLACK_ON_WHITE (VGA_FG_BLACK | VGA_BG_WHITE)
/*
** Internal support routines.
*/
/*
** setcursor: set the cursor location (screen coordinates)
*/
static void setcursor(void)
{
unsigned addr;
unsigned int y = curr_y;
if (y > scroll_max_y) {
y = scroll_max_y;
}
addr = (unsigned)(y * SCREEN_X_SIZE + curr_x);
outb(VGA_CTRL_IX_ADDR, VGA_CTRL_CUR_HIGH);
outb(VGA_CTRL_IX_DATA, (addr >> 8) & BMASK8);
outb(VGA_CTRL_IX_ADDR, VGA_CTRL_CUR_LOW);
outb(VGA_CTRL_IX_DATA, addr & BMASK8);
}
/*
** putchar_at: physical output to the video memory
*/
static void putchar_at(unsigned int x, unsigned int y, unsigned int c)
{
/*
** If x or y is too big or small, don't do any output.
*/
if (x <= max_x && y <= max_y) {
unsigned short *addr = VIDEO_ADDR(x, y);
/*
** The character may have attributes associated with it; if
** so, use those, otherwise use white on black.
*/
c &= 0xffff; // keep only the lower bytes
if (c > BMASK8) {
*addr = (unsigned short)c;
} else {
*addr = (unsigned short)c | VGA_WHITE_ON_BLACK;
}
}
}
/*
** Globally-visible support routines.
*/
/*
** Set the scrolling region
*/
void cio_setscroll(unsigned int s_min_x, unsigned int s_min_y,
unsigned int s_max_x, unsigned int s_max_y)
{
scroll_min_x = bound(min_x, s_min_x, max_x);
scroll_min_y = bound(min_y, s_min_y, max_y);
scroll_max_x = bound(scroll_min_x, s_max_x, max_x);
scroll_max_y = bound(scroll_min_y, s_max_y, max_y);
curr_x = scroll_min_x;
curr_y = scroll_min_y;
setcursor();
}
/*
** Cursor movement in the scroll region
*/
void cio_moveto(unsigned int x, unsigned int y)
{
curr_x = bound(scroll_min_x, x + scroll_min_x, scroll_max_x);
curr_y = bound(scroll_min_y, y + scroll_min_y, scroll_max_y);
setcursor();
}
/*
** The putchar family
*/
void cio_putchar_at(unsigned int x, unsigned int y, unsigned int c)
{
if ((c & 0x7f) == '\n') {
unsigned int limit;
/*
** If we're in the scroll region, don't let this loop
** leave it. If we're not in the scroll region, don't
** let this loop enter it.
*/
if (x > scroll_max_x) {
limit = max_x;
} else if (x >= scroll_min_x) {
limit = scroll_max_x;
} else {
limit = scroll_min_x - 1;
}
while (x <= limit) {
putchar_at(x, y, ' ');
x += 1;
}
} else {
putchar_at(x, y, c);
}
}
#ifndef SA_DEBUG
void cio_putchar(unsigned int c)
{
/*
** If we're off the bottom of the screen, scroll the window.
*/
if (curr_y > scroll_max_y) {
cio_scroll(curr_y - scroll_max_y);
curr_y = scroll_max_y;
}
switch (c & BMASK8) {
case '\n':
/*
** Erase to the end of the line, then move to new line
** (actual scroll is delayed until next output appears).
*/
while (curr_x <= scroll_max_x) {
putchar_at(curr_x, curr_y, ' ');
curr_x += 1;
}
curr_x = scroll_min_x;
curr_y += 1;
break;
case '\r':
curr_x = scroll_min_x;
break;
default:
putchar_at(curr_x, curr_y, c);
curr_x += 1;
if (curr_x > scroll_max_x) {
curr_x = scroll_min_x;
curr_y += 1;
}
break;
}
setcursor();
}
#endif
/*
** The puts family
*/
void cio_puts_at(unsigned int x, unsigned int y, const char *str)
{
unsigned int ch;
while ((ch = *str++) != '\0' && x <= max_x) {
cio_putchar_at(x, y, ch);
x += 1;
}
}
#ifndef SA_DEBUG
void cio_puts(const char *str)
{
unsigned int ch;
while ((ch = *str++) != '\0') {
cio_putchar(ch);
}
}
#endif
/*
** Write a "sized" buffer (like cio_puts(), but no NUL)
*/
void cio_write(const char *buf, int length)
{
for (int i = 0; i < length; ++i) {
cio_putchar(buf[i]);
}
}
void cio_clearscroll(void)
{
unsigned int nchars = scroll_max_x - scroll_min_x + 1;
unsigned int l;
unsigned int c;
for (l = scroll_min_y; l <= scroll_max_y; l += 1) {
unsigned short *to = VIDEO_ADDR(scroll_min_x, l);
for (c = 0; c < nchars; c += 1) {
*to++ = ' ' | 0x0700;
}
}
}
void cio_clearscreen(void)
{
unsigned short *to = VIDEO_ADDR(min_x, min_y);
unsigned int nchars = (max_y - min_y + 1) * (max_x - min_x + 1);
while (nchars > 0) {
*to++ = ' ' | 0x0700;
nchars -= 1;
}
}
void cio_scroll(unsigned int lines)
{
unsigned short *from;
unsigned short *to;
int nchars = scroll_max_x - scroll_min_x + 1;
int line, c;
/*
** If # of lines is the whole scrolling region or more, just clear.
*/
if (lines > scroll_max_y - scroll_min_y) {
cio_clearscroll();
curr_x = scroll_min_x;
curr_y = scroll_min_y;
setcursor();
return;
}
/*
** Must copy it line by line.
*/
for (line = scroll_min_y; line <= scroll_max_y - lines; line += 1) {
from = VIDEO_ADDR(scroll_min_x, line + lines);
to = VIDEO_ADDR(scroll_min_x, line);
for (c = 0; c < nchars; c += 1) {
*to++ = *from++;
}
}
for (; line <= scroll_max_y; line += 1) {
to = VIDEO_ADDR(scroll_min_x, line);
for (c = 0; c < nchars; c += 1) {
*to++ = ' ' | 0x0700;
}
}
}
static int mypad(int x, int y, int extra, int padchar)
{
while (extra > 0) {
if (x != -1 || y != -1) {
cio_putchar_at(x, y, padchar);
x += 1;
} else {
cio_putchar(padchar);
}
extra -= 1;
}
return x;
}
static int mypadstr(int x, int y, char *str, int len, int width, int leftadjust,
int padchar)
{
int extra;
if (len < 0) {
len = strlen(str);
}
extra = width - len;
if (extra > 0 && !leftadjust) {
x = mypad(x, y, extra, padchar);
}
if (x != -1 || y != -1) {
cio_puts_at(x, y, str);
x += len;
} else {
cio_puts(str);
}
if (extra > 0 && leftadjust) {
x = mypad(x, y, extra, padchar);
}
return x;
}
static void do_printf(int x, int y, char **f)
{
char *fmt = *f;
int *ap;
char buf[12];
char ch;
char *str;
int leftadjust;
int width;
int len;
int padchar;
/*
** Get characters from the format string and process them
*/
ap = (int *)(f + 1);
while ((ch = *fmt++) != '\0') {
/*
** Is it the start of a format code?
*/
if (ch == '%') {
/*
** Yes, get the padding and width options (if there).
** Alignment must come at the beginning, then fill,
** then width.
*/
leftadjust = 0;
padchar = ' ';
width = 0;
ch = *fmt++;
if (ch == '-') {
leftadjust = 1;
ch = *fmt++;
}
if (ch == '0') {
padchar = '0';
ch = *fmt++;
}
while (ch >= '0' && ch <= '9') {
width *= 10;
width += ch - '0';
ch = *fmt++;
}
/*
** What data type do we have?
*/
switch (ch) {
case 'c':
// ch = *( (int *)ap )++;
ch = *ap++;
buf[0] = ch;
buf[1] = '\0';
x = mypadstr(x, y, buf, 1, width, leftadjust, padchar);
break;
case 'd':
// len = cvtdec( buf, *( (int *)ap )++ );
len = cvtdec(buf, *ap++);
x = mypadstr(x, y, buf, len, width, leftadjust, padchar);
break;
case 's':
// str = *( (char **)ap )++;
str = (char *)(*ap++);
x = mypadstr(x, y, str, -1, width, leftadjust, padchar);
break;
case 'x':
// len = cvthex( buf, *( (int *)ap )++ );
len = cvthex(buf, *ap++);
x = mypadstr(x, y, buf, len, width, leftadjust, padchar);
break;
case 'o':
// len = cvtoct( buf, *( (int *)ap )++ );
len = cvtoct(buf, *ap++);
x = mypadstr(x, y, buf, len, width, leftadjust, padchar);
break;
case 'u':
len = cvtuns(buf, *ap++);
x = mypadstr(x, y, buf, len, width, leftadjust, padchar);
break;
}
} else {
/*
** No - just print it normally.
*/
if (x != -1 || y != -1) {
cio_putchar_at(x, y, ch);
switch (ch) {
case '\n':
y += 1;
/* FALL THRU */
case '\r':
x = scroll_min_x;
break;
default:
x += 1;
}
} else {
cio_putchar(ch);
}
}
}
}
void cio_printf_at(unsigned int x, unsigned int y, char *fmt, ...)
{
do_printf(x, y, &fmt);
}
void cio_printf(char *fmt, ...)
{
do_printf(-1, -1, &fmt);
}
/*
** These are the "standard" IBM AT "Set 1" keycodes.
*/
static unsigned char scan_code[2][128] = { { // unshifted characters
/* 00-07 */ '\377',
'\033',
'1',
'2',
'3',
'4',
'5',
'6',
/* 08-0f */ '7',
'8',
'9',
'0',
'-',
'=',
'\b',
'\t',
/* 10-17 */ 'q',
'w',
'e',
'r',
't',
'y',
'u',
'i',
/* 18-1f */ 'o',
'p',
'[',
']',
'\n',
'\377',
'a',
's',
/* 20-27 */ 'd',
'f',
'g',
'h',
'j',
'k',
'l',
';',
/* 28-2f */ '\'',
'`',
'\377',
'\\',
'z',
'x',
'c',
'v',
/* 30-37 */ 'b',
'n',
'm',
',',
'.',
'/',
'\377',
'*',
/* 38-3f */ '\377',
' ',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 40-47 */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'7',
/* 48-4f */ '8',
'9',
'-',
'4',
'5',
'6',
'+',
'1',
/* 50-57 */ '2',
'3',
'0',
'.',
'\377',
'\377',
'\377',
'\377',
/* 58-5f */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 60-67 */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 68-6f */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 70-77 */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 78-7f */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377' },
{ // shifted characters
/* 00-07 */ '\377',
'\033',
'!',
'@',
'#',
'$',
'%',
'^',
/* 08-0f */ '&',
'*',
'(',
')',
'_',
'+',
'\b',
'\t',
/* 10-17 */ 'Q',
'W',
'E',
'R',
'T',
'Y',
'U',
'I',
/* 18-1f */ 'O',
'P',
'{',
'}',
'\n',
'\377',
'A',
'S',
/* 20-27 */ 'D',
'F',
'G',
'H',
'J',
'K',
'L',
':',
/* 28-2f */ '"',
'~',
'\377',
'|',
'Z',
'X',
'C',
'V',
/* 30-37 */ 'B',
'N',
'M',
'<',
'>',
'?',
'\377',
'*',
/* 38-3f */ '\377',
' ',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 40-47 */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'7',
/* 48-4f */ '8',
'9',
'-',
'4',
'5',
'6',
'+',
'1',
/* 50-57 */ '2',
'3',
'0',
'.',
'\377',
'\377',
'\377',
'\377',
/* 58-5f */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 60-67 */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 68-6f */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 70-77 */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
/* 78-7f */ '\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377',
'\377' } };
/*
** Scan code masks
*/
// 'release' bit
#define REL_BIT 0x80
#define CODE_BITS 0x7f
#define IS_PRESS(c) (((c) & REL_BIT) == 0)
#define IS_RELEASE(c) (((c) & REL_BIT) != 0)
/*
** Scan codes for some special characters
*/
// escape code - followed by another code byte
#define SCAN_ESC 0xe0
// shift keys: press, release
#define L_SHIFT_DN 0x2a
#define R_SHIFT_DN 0x36
#define L_SHIFT_UP 0xaa
#define R_SHIFT_UP 0xb6
// control keys
#define L_CTRL_DN 0x1d
#define L_CTRL_UP 0x9d
/*
** I/O communication constants
*/
#define KBD_DATA 0x60
#define KBD_STATUS 0x64
#define READY 0x1
/*
** Circular buffer for input characters. Characters are inserted at
** next_space, and are removed at next_char. Buffer is empty if
** these are equal.
*/
#define C_BUFSIZE 200
static char input_buffer[C_BUFSIZE];
static volatile char *next_char = input_buffer;
static volatile char *next_space = input_buffer;
static volatile char *increment(volatile char *pointer)
{
if (++pointer >= input_buffer + C_BUFSIZE) {
pointer = input_buffer;
}
return pointer;
}
static int input_scan_code(int code)
{
static int shift = 0;
static int ctrl_mask = BMASK8;
int rval = -1;
/*
** Do the shift processing
*/
code &= BMASK8;
switch (code) {
case L_SHIFT_DN:
case R_SHIFT_DN:
shift = 1;
break;
case L_SHIFT_UP:
case R_SHIFT_UP:
shift = 0;
break;
case L_CTRL_DN:
ctrl_mask = BMASK5;
break;
case L_CTRL_UP:
ctrl_mask = BMASK8;
break;
default:
/*
** Process ordinary characters only on the press (to handle
** autorepeat). Ignore undefined scan codes.
*/
if (IS_PRESS(code)) {
code = scan_code[shift][(int)code];
if (code != '\377') {
volatile char *next = increment(next_space);
/*
** Store character only if there's room
*/
rval = code & ctrl_mask;
if (next != next_char) {
*next_space = code & ctrl_mask;
next_space = next;
}
}
}
}
return (rval);
}
static void keyboard_isr(int vector, int code)
{
int data = inb(KBD_DATA);
int val = input_scan_code(data);
// if there is a notification function, call it
if (val != -1 && notify)
notify(val);
outb(PIC1_CMD, PIC_EOI);
}
int cio_getchar(void)
{
char c;
int interrupts_enabled = r_eflags() & EFL_IF;
while (next_char == next_space) {
if (!interrupts_enabled) {
/*
** Must read the next keystroke ourselves.
*/
while ((inb(KBD_STATUS) & READY) == 0) {
;
}
(void)input_scan_code(inb(KBD_DATA));
}
}
c = *next_char & BMASK8;
next_char = increment(next_char);
if (c != EOT) {
cio_putchar(c);
}
return c;
}
int cio_gets(char *buffer, unsigned int size)
{
char ch;
int count = 0;
while (size > 1) {
ch = cio_getchar();
if (ch == EOT) {
break;
}
*buffer++ = ch;
count += 1;
size -= 1;
if (ch == '\n') {
break;
}
}
*buffer = '\0';
return count;
}
int cio_input_queue(void)
{
int n_chars = next_space - next_char;
if (n_chars < 0) {
n_chars += C_BUFSIZE;
}
return n_chars;
}
/*
** Initialization routines
*/
void cio_init(void (*fcn)(int))
{
/*
** Screen dimensions
*/
min_x = SCREEN_MIN_X;
min_y = SCREEN_MIN_Y;
max_x = SCREEN_MAX_X;
max_y = SCREEN_MAX_Y;
/*
** Scrolling region
*/
scroll_min_x = SCREEN_MIN_X;
scroll_min_y = SCREEN_MIN_Y;
scroll_max_x = SCREEN_MAX_X;
scroll_max_y = SCREEN_MAX_Y;
/*
** Initial cursor location
*/
curr_y = min_y;
curr_x = min_x;
setcursor();
/*
** Notification function (or NULL)
*/
notify = fcn;
/*
** Set up the interrupt handler for the keyboard
*/
install_isr(VEC_KBD, keyboard_isr);
}
#ifdef SA_DEBUG
int main()
{
cio_printf("%d\n", 123);
cio_printf("%d\n", -123);
cio_printf("%d\n", 0x7fffffff);
cio_printf("%d\n", 0x80000001);
cio_printf("%d\n", 0x80000000);
cio_printf("x%14dy\n", 0x80000000);
cio_printf("x%-14dy\n", 0x80000000);
cio_printf("x%014dy\n", 0x80000000);
cio_printf("x%-014dy\n", 0x80000000);
cio_printf("%s\n", "xyz");
cio_printf("|%10s|\n", "xyz");
cio_printf("|%-10s|\n", "xyz");
cio_printf("%c\n", 'x');
cio_printf("|%4c|\n", 'y');
cio_printf("|%-4c|\n", 'y');
cio_printf("|%04c|\n", 'y');
cio_printf("|%-04c|\n", 'y');
cio_printf("|%3d|\n", 5);
cio_printf("|%3d|\n", 54321);
cio_printf("%x\n", 0x123abc);
cio_printf("|%04x|\n", 20);
cio_printf("|%012x|\n", 0xfedcba98);
cio_printf("|%-012x|\n", 0x76543210);
}
int curr_x, curr_y, max_x, max_y;
#endif
|