-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.c
832 lines (734 loc) · 20 KB
/
lib.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
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
/* lib.c - Some basic library functions (printf, strlen, etc.)
* vim:ts=4 noexpandtab
*/
#include "lib.h"
#define VIDEO 0xB8000
#define NUM_COLS 80
#define NUM_ROWS 25
#define ATTRIB 0x7
#define screen_width 79
#include "task.h"
extern volatile uint32_t cur_terminal;
extern volatile uint32_t alt_terminal;
extern volatile uint32_t system_init_flag;
int screen_x[NUM_TERMINAL];
int screen_y[NUM_TERMINAL];
static char* video_mem = (char *)VIDEO;
/*dir
* Description: update the position by direction
* Input: --dd: scanned value for direction
* Output: N/A
* Return value: N/A
* Side effect: update the screen coordinates
*/
void dir(unsigned char dd)
{
switch(dd)
{
// up
case 0x48: if(screen_y[cur_terminal]!=0) screen_y[cur_terminal]--; break;
// left
case 0x4B: if(screen_x[cur_terminal]!=0) screen_x[cur_terminal]--; update_cursor(screen_y[alt_terminal], screen_x[alt_terminal]);break;
// down
case 0x50: screen_y[cur_terminal]++; break;
// right
case 0x4D: if(screen_x[cur_terminal]<screen_width) screen_x[cur_terminal]++;
else {screen_x[cur_terminal]=0;screen_y[cur_terminal]++;}
update_cursor(screen_y[alt_terminal], screen_x[alt_terminal]);
break;
}
}
/*up_screen
* Description: update the screen
* Input: N/A
* Output: N/A
* Return value: N/A
* Side effect: update the screen coordinates
*/
void up_screen(void)
{
// if it reaches the right most
if(screen_x[cur_terminal]>=79)
{
// set it to 0
screen_x[cur_terminal]=0;
// update the y coordinate
screen_y[cur_terminal]++;
}
}
/*scroll
* Description: scroll the screen
* Input: N/A
* Output: N/A
* Return value: N/A
* Side effect: update the video mem
*/
void scroll(void)
{
int32_t i;
video_mem=(char *)VIDEO;
for(i=NUM_COLS; i< (NUM_ROWS*NUM_COLS-NUM_COLS); i++) {
// if it does not reach the bottom line, shift the video mem
*(uint8_t *)(video_mem + (i << 1)) = *(uint8_t *)(video_mem + ((i+NUM_COLS)<< 1));
// also the content of color
*(uint8_t *)(video_mem + (i << 1) + 1) = *(uint8_t *)(video_mem + ((i+NUM_COLS)<< 1)+1);;
}
//if it reaches the bottom line
for(i=(NUM_ROWS*NUM_COLS-NUM_COLS); i< (NUM_ROWS*NUM_COLS); i++) {
// replace with space
*(uint8_t *)(video_mem + (i << 1)) = ' ';
// as well as the color
*(uint8_t *)(video_mem + (i << 1) + 1) = ATTRIB;;
}
screen_x[cur_terminal] = 0;
screen_y[cur_terminal]= NUM_ROWS - 1;
}
/*clear
* Description: clear the screen
* Input: N/A
* Output: N/A
* Return value: N/A
* Side effect: update the video mem
*/
void
clear(void)
{
int32_t i;
video_mem=(char *)VIDEO;
// fill every pixel in the terminal with space
for(i=NUM_COLS; i<NUM_ROWS*NUM_COLS; i++) {
*(uint8_t *)(video_mem + (i << 1)) = ' ';
*(uint8_t *)(video_mem + (i << 1) + 1) = ATTRIB;;
}
if(system_init_flag) {
// mapping the video mem
video_mem=(char *)VIDEO+(alt_terminal+1)*size_of_vmem;
// then clear the screen
for(i=NUM_COLS; i<NUM_ROWS*NUM_COLS; i++) {
*(uint8_t *)(video_mem + (i << 1)) = ' ';
*(uint8_t *)(video_mem + (i << 1) + 1) = ATTRIB;;
}
}
screen_x[cur_terminal]=0;
screen_y[cur_terminal]=1;
}
/* Standard printf().
* Only supports the following format strings:
* %% - print a literal '%' character
* %x - print a number in hexadecimal
* %u - print a number as an unsigned integer
* %d - print a number as a signed integer
* %c - print a character
* %s - print a string
* %#x - print a number in 32-bit aligned hexadecimal, i.e.
* print 8 hexadecimal digits, zero-padded on the left.
* For example, the hex number "E" would be printed as
* "0000000E".
* Note: This is slightly different than the libc specification
* for the "#" modifier (this implementation doesn't add a "0x" at
* the beginning), but I think it's more flexible this way.
* Also note: %x is the only conversion specifier that can use
* the "#" modifier to alter output.
* */
int32_t
printf(int8_t *format, ...)
{
/* Pointer to the format string */
int8_t* buf = format;
/* Stack pointer for the other parameters */
int32_t* esp = (void *)&format;
esp++;
while(*buf != '\0') {
switch(*buf) {
case '%':
{
int32_t alternate = 0;
buf++;
format_char_switch:
/* Conversion specifiers */
switch(*buf) {
/* Print a literal '%' character */
case '%':
putc('%');
break;
/* Use alternate formatting */
case '#':
alternate = 1;
buf++;
/* Yes, I know gotos are bad. This is the
* most elegant and general way to do this,
* IMHO. */
goto format_char_switch;
/* Print a number in hexadecimal form */
case 'x':
{
int8_t conv_buf[64];
if(alternate == 0) {
itoa(*((uint32_t *)esp), conv_buf, 16);
if(alt_terminal == cur_terminal)
printscur(conv_buf);
else
puts(conv_buf);
} else {
int32_t starting_index;
int32_t i;
itoa(*((uint32_t *)esp), &conv_buf[8], 16);
i = starting_index = strlen(&conv_buf[8]);
while(i < 8) {
conv_buf[i] = '0';
i++;
}
if(alt_terminal == cur_terminal)
printscur(&conv_buf[starting_index]);
else
puts(&conv_buf[starting_index]);
}
esp++;
}
break;
/* Print a number in unsigned int form */
case 'u':
{
int8_t conv_buf[36];
itoa(*((uint32_t *)esp), conv_buf, 10);
if(alt_terminal == cur_terminal)
printscur(conv_buf);
else
puts(conv_buf);
esp++;
}
break;
/* Print a number in signed int form */
case 'd':
{
int8_t conv_buf[36];
int32_t value = *((int32_t *)esp);
if(value < 0) {
conv_buf[0] = '-';
itoa(-value, &conv_buf[1], 10);
} else {
itoa(value, conv_buf, 10);
}
if(alt_terminal == cur_terminal)
printscur(conv_buf);
else
puts(conv_buf);
esp++;
}
break;
/* Print a single character */
case 'c':
putc( (uint8_t) *((int32_t *)esp) );
esp++;
break;
/* Print a NULL-terminated string */
case 's':
if(alt_terminal == cur_terminal)
printscur(*((int8_t **)esp) );
else
puts( *((int8_t **)esp) );
esp++;
break;
default:
break;
}
}
break;
default:
putc(*buf);
break;
}
buf++;
}
return (buf - format);
}
/* Output a string to the console */
int32_t
puts(int8_t* s)
{
register int32_t index = 0;
while(s[index] != '\0') {
putc(s[index]);
index++;
}
return index;
}
void
putc(uint8_t c)
{
uint32_t i;
video_mem=(char *)VIDEO;
if(c == '\n' || c == '\r') {
screen_y[cur_terminal]++;
screen_x[cur_terminal]=0;
if(screen_y[cur_terminal] >= 24)
{
for(i=NUM_COLS; i< (NUM_ROWS*NUM_COLS-NUM_COLS); i++) {
*(uint8_t *)(VIDEO + (i << 1)) = *(uint8_t *)(VIDEO+ ((i+NUM_COLS)<< 1));
*(uint8_t *)(VIDEO+ (i << 1) + 1) = *(uint8_t *)(VIDEO+ ((i+NUM_COLS)<< 1)+1);;
}
for(i=(NUM_ROWS*NUM_COLS-NUM_COLS); i< (NUM_ROWS*NUM_COLS); i++) {
*(uint8_t *)(VIDEO+ (i << 1)) = ' ';
*(uint8_t *)(VIDEO + (i << 1) + 1) = ATTRIB;
}
screen_x[cur_terminal] =0;
screen_y[cur_terminal] =23;
}
}
else
{
if(screen_x[cur_terminal]>=79)
{
screen_x[cur_terminal]=0;
screen_y[cur_terminal]++;
}
*(uint8_t *)(video_mem + ((NUM_COLS*screen_y[cur_terminal] + screen_x[cur_terminal]) << 1)) = c;
*(uint8_t *)(video_mem + ((NUM_COLS*screen_y[cur_terminal] + screen_x[cur_terminal]) << 1) + 1) = ATTRIB;
screen_x[cur_terminal]++;
screen_x[cur_terminal] %= NUM_COLS;
if(screen_y[cur_terminal] >= 24)
{
for(i=NUM_COLS; i< (NUM_ROWS*NUM_COLS-NUM_COLS); i++) {
*(uint8_t *)(VIDEO + (i << 1)) = *(uint8_t *)(VIDEO+ ((i+NUM_COLS)<< 1));
*(uint8_t *)(VIDEO+ (i << 1) + 1) = *(uint8_t *)(VIDEO+ ((i+NUM_COLS)<< 1)+1);;
}
for(i=(NUM_ROWS*NUM_COLS-NUM_COLS); i< (NUM_ROWS*NUM_COLS); i++) {
*(uint8_t *)(VIDEO+ (i << 1)) = ' ';
*(uint8_t *)(VIDEO + (i << 1) + 1) = ATTRIB;
}
screen_x[cur_terminal] =0;
screen_y[cur_terminal] =23;
}
}
if(system_init_flag)
if(cur_terminal == alt_terminal)
{
// *(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((NUM_COLS*screen_y[cur_terminal] + screen_x[cur_terminal]) << 1)) = c;
// *(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((NUM_COLS*screen_y[cur_terminal] + screen_x[cur_terminal]) << 1) + 1) = ATTRIB;
memcpy((char *)VIDEO+(alt_terminal+1)*size_of_vmem ,(char *)VIDEO, size_of_vmem);
update_cursor(screen_y[alt_terminal], screen_x[alt_terminal]);
}
}
/* Convert a number to its ASCII representation, with base "radix" */
int8_t*
itoa(uint32_t value, int8_t* buf, int32_t radix)
{
static int8_t lookup[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int8_t *newbuf = buf;
int32_t i;
uint32_t newval = value;
/* Special case for zero */
if(value == 0) {
buf[0]='0';
buf[1]='\0';
return buf;
}
/* Go through the number one place value at a time, and add the
* correct digit to "newbuf". We actually add characters to the
* ASCII string from lowest place value to highest, which is the
* opposite of how the number should be printed. We'll reverse the
* characters later. */
while(newval > 0) {
i = newval % radix;
*newbuf = lookup[i];
newbuf++;
newval /= radix;
}
/* Add a terminating NULL */
*newbuf = '\0';
/* Reverse the string and return */
return strrev(buf);
}
/* In-place string reversal */
int8_t*
strrev(int8_t* s)
{
register int8_t tmp;
register int32_t beg=0;
register int32_t end=strlen(s) - 1;
while(beg < end) {
tmp = s[end];
s[end] = s[beg];
s[beg] = tmp;
beg++;
end--;
}
return s;
}
/* String length */
uint32_t
strlen(const int8_t* s)
{
register uint32_t len = 0;
while(s[len] != '\0')
len++;
return len;
}
/* Optimized memset */
void*
memset(void* s, int32_t c, uint32_t n)
{
c &= 0xFF;
asm volatile(" \n\
.memset_top: \n\
testl %%ecx, %%ecx \n\
jz .memset_done \n\
testl $0x3, %%edi \n\
jz .memset_aligned \n\
movb %%al, (%%edi) \n\
addl $1, %%edi \n\
subl $1, %%ecx \n\
jmp .memset_top \n\
.memset_aligned: \n\
movw %%ds, %%dx \n\
movw %%dx, %%es \n\
movl %%ecx, %%edx \n\
shrl $2, %%ecx \n\
andl $0x3, %%edx \n\
cld \n\
rep stosl \n\
.memset_bottom: \n\
testl %%edx, %%edx \n\
jz .memset_done \n\
movb %%al, (%%edi) \n\
addl $1, %%edi \n\
subl $1, %%edx \n\
jmp .memset_bottom \n\
.memset_done: \n\
"
:
: "a"(c << 24 | c << 16 | c << 8 | c), "D"(s), "c"(n)
: "edx", "memory", "cc"
);
return s;
}
/* Optimized memset_word */
void*
memset_word(void* s, int32_t c, uint32_t n)
{
asm volatile(" \n\
movw %%ds, %%dx \n\
movw %%dx, %%es \n\
cld \n\
rep stosw \n\
"
:
: "a"(c), "D"(s), "c"(n)
: "edx", "memory", "cc"
);
return s;
}
/* Optimized memset_dword */
void*
memset_dword(void* s, int32_t c, uint32_t n)
{
asm volatile(" \n\
movw %%ds, %%dx \n\
movw %%dx, %%es \n\
cld \n\
rep stosl \n\
"
:
: "a"(c), "D"(s), "c"(n)
: "edx", "memory", "cc"
);
return s;
}
/* Optimized memcpy */
void*
memcpy(void* dest, const void* src, uint32_t n)
{
asm volatile(" \n\
.memcpy_top: \n\
testl %%ecx, %%ecx \n\
jz .memcpy_done \n\
testl $0x3, %%edi \n\
jz .memcpy_aligned \n\
movb (%%esi), %%al \n\
movb %%al, (%%edi) \n\
addl $1, %%edi \n\
addl $1, %%esi \n\
subl $1, %%ecx \n\
jmp .memcpy_top \n\
.memcpy_aligned: \n\
movw %%ds, %%dx \n\
movw %%dx, %%es \n\
movl %%ecx, %%edx \n\
shrl $2, %%ecx \n\
andl $0x3, %%edx \n\
cld \n\
rep movsl \n\
.memcpy_bottom: \n\
testl %%edx, %%edx \n\
jz .memcpy_done \n\
movb (%%esi), %%al \n\
movb %%al, (%%edi) \n\
addl $1, %%edi \n\
addl $1, %%esi \n\
subl $1, %%edx \n\
jmp .memcpy_bottom \n\
.memcpy_done: \n\
"
:
: "S"(src), "D"(dest), "c"(n)
: "eax", "edx", "memory", "cc"
);
return dest;
}
/* Optimized memmove (used for overlapping memory areas) */
void*
memmove(void* dest, const void* src, uint32_t n)
{
asm volatile(" \n\
movw %%ds, %%dx \n\
movw %%dx, %%es \n\
cld \n\
cmp %%edi, %%esi \n\
jae .memmove_go \n\
leal -1(%%esi, %%ecx), %%esi \n\
leal -1(%%edi, %%ecx), %%edi \n\
std \n\
.memmove_go: \n\
rep movsb \n\
"
:
: "D"(dest), "S"(src), "c"(n)
: "edx", "memory", "cc"
);
return dest;
}
/* Standard strncmp */
int32_t
strncmp(const int8_t* s1, const int8_t* s2, uint32_t n)
{
int32_t i;
for(i=0; i<n; i++) {
if( (s1[i] != s2[i]) ||
(s1[i] == '\0') /* || s2[i] == '\0' */ ) {
/* The s2[i] == '\0' is unnecessary because of the short-circuit
* semantics of 'if' expressions in C. If the first expression
* (s1[i] != s2[i]) evaluates to false, that is, if s1[i] ==
* s2[i], then we only need to test either s1[i] or s2[i] for
* '\0', since we know they are equal. */
return s1[i] - s2[i];
}
}
return 0;
}
/* Standard strcpy */
int8_t*
strcpy(int8_t* dest, const int8_t* src)
{
int32_t i=0;
while(src[i] != '\0') {
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return dest;
}
/* Standard strncpy */
int8_t*
strncpy(int8_t* dest, const int8_t* src, uint32_t n)
{
int32_t i=0;
while(src[i] != '\0' && i < n) {
dest[i] = src[i];
i++;
}
while(i < n) {
dest[i] = '\0';
i++;
}
return dest;
}
void
test_interrupts(void)
{
int32_t i;
video_mem=(char *)VIDEO;
for (i=0; i < NUM_ROWS*NUM_COLS; i++) {
video_mem[i<<1]++;
}
if(system_init_flag) {
video_mem=(char *)VIDEO+(alt_terminal+1)*size_of_vmem;
for (i=0; i < NUM_ROWS*NUM_COLS; i++) {
video_mem[i<<1]++;
}
}
}
void
screen_ptr(int x, int y)
{
screen_x[alt_terminal]=x;
screen_y[alt_terminal]=y;
update_cursor(y, x);
}
int gety()
{
return screen_y[cur_terminal];
}
int getx()
{
return screen_x[cur_terminal];
}
/*bksp
* Description: back space function
* Input: N/A
* Output: N/A
* Return value: N/A
* Side effect: update the screen coordinate
*/
void bksp(void)
{
// if not from the starting point, update position and replace with space
if(screen_x[alt_terminal]!=0)
{
screen_x[alt_terminal]--;
printf(" ");
screen_x[alt_terminal]--;
//make sure not delete the status bar
}
else if(screen_y[alt_terminal]!=0)
{
screen_y[alt_terminal]--;
screen_x[alt_terminal] = 79;
}
// update the cursor
update_cursor(screen_y[alt_terminal], screen_x[alt_terminal]);
}
/*bksp_t
* Description: delete the keyboard input
* Input: N/A
* Output: N/A
* Return value: N/A
* Side effect: modify the video mem
*/
void
bksp_t(void)
{
// move the actal cursor
screen_x[alt_terminal]--;
// replace the present value with space
*(uint8_t *)(VIDEO + ((NUM_COLS*screen_y[alt_terminal] + screen_x[alt_terminal]) << 1)) = ' ';
// update the foreground color.
*(uint8_t *)(VIDEO + ((NUM_COLS*screen_y[alt_terminal] + screen_x[alt_terminal]) << 1) + 1) = ATTRIB;
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((NUM_COLS*screen_y[alt_terminal] + screen_x[alt_terminal]) << 1)) = ' ';
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((NUM_COLS*screen_y[alt_terminal] + screen_x[alt_terminal]) << 1) + 1) = ATTRIB;
update_cursor(screen_y[alt_terminal], screen_x[alt_terminal]);
}
void update_cursor(int row, int col)
{
unsigned short position=(row*80) + col;
// cursor LOW port to vga INDEX register
outb(0x0F, 0x3D4);
outb((unsigned char)(position&0xFF), 0x3D5);
// cursor HIGH port to vga INDEX register
outb(0x0E, 0x3D4);
outb((unsigned char )((position>>8)&0xFF), 0x3D5);
}
/*statusbar
* Description: display status
* Input: N/A
* Output: N/A
* Return value: N/A
* Side effect: modify the video mem
*/
void statusbar(void)
{
int i,j;
uint8_t text[] = "terminal IOTA OS ";
text[9] = (uint8_t) 49;
//mapping the video mem from text
video_mem=(char *)VIDEO;
for(i=0; i< 80 ; i++) {
*(uint8_t *)(video_mem + (i << 1)) = text[i];
*(uint8_t *)(video_mem + (i << 1) + 1) = 0x3 | 0x80;
}
for(j =0; j< NUM_TERMINAL; j++)
{
// text[9] indicating the terminal number
text[9] = (uint8_t) j + 49;
video_mem=(char *)VIDEO+(j+1)*size_of_vmem;
for(i=0; i< 80 ; i++) {
// the video mem will never interact with alt_terminal.
*(uint8_t *)(video_mem + (i << 1)) = text[i];
*(uint8_t *)(video_mem + (i << 1) + 1) = 0x3 | (0x80 + 0x10*j);
}
screen_x[j]=0;
screen_y[j]=1;
}
}
/*putcur
* Description: print current terminal to the screen
* Input: --c: command
* Output: N/A
* Return value: N/A
* Side effect: N/A
*/
void putcur(char c)
{
int32_t i;
if(c == '\n' || c == '\r') {//change line
screen_y[alt_terminal]++;
screen_x[alt_terminal]=0;
if(screen_y[alt_terminal] >= 24)//scolling
{
for(i=NUM_COLS; i< (NUM_ROWS*NUM_COLS-NUM_COLS); i++) {
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1)) = *(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((i+NUM_COLS)<< 1));
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1) + 1) = *(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((i+NUM_COLS)<< 1)+1);;
}
for(i=(NUM_ROWS*NUM_COLS-NUM_COLS); i< (NUM_ROWS*NUM_COLS); i++) {
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1)) = ' ';
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1) + 1) = ATTRIB;
}
screen_x[alt_terminal] =0;
screen_y[alt_terminal] =23;
}
}
else
{
if(screen_x[alt_terminal]>=79)
{
screen_x[alt_terminal]=0;
screen_y[alt_terminal]++;
}
//put to alt video memeory
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((NUM_COLS*screen_y[alt_terminal] + screen_x[alt_terminal]) << 1)) = c;
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((NUM_COLS*screen_y[alt_terminal] + screen_x[alt_terminal]) << 1) + 1) = ATTRIB;
screen_x[alt_terminal] ++;
screen_x[alt_terminal] %= NUM_COLS;
if(screen_y[alt_terminal] >= 24)//scolling
{
for(i=NUM_COLS; i< (NUM_ROWS*NUM_COLS-NUM_COLS); i++) {
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1)) = *(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((i+NUM_COLS)<< 1));
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1) + 1) = *(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + ((i+NUM_COLS)<< 1)+1);;
}
for(i=(NUM_ROWS*NUM_COLS-NUM_COLS); i< (NUM_ROWS*NUM_COLS); i++) {
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1)) = ' ';
*(uint8_t *)(VIDEO+(alt_terminal+1)*size_of_vmem + (i << 1) + 1) = ATTRIB;
}
screen_x[alt_terminal] =0;
screen_y[alt_terminal] =23;
}
}
update_cursor(screen_y[alt_terminal], screen_x[alt_terminal]);
}
/*putcur
* Description: put a string to the alt_terminal
* Input: --buff: buffer stored the string
* Output: increment index
* Return value: N/A
* Side effect: N/A
*/
void
printscur( char * buff)
{
register int32_t index = 0;
while(buff[index] != '\0') {
//if not reach the end, print the char.
putcur(buff[index]);
// increment the index
index++;
}
}