OSDN Git Service

基本機能完成
[os-dk/osdk-master.git] / src / lib / vga / text.c
1 /*
2  VGA Text Manager
3  (C) 2015 OS-DK.
4  (C) 2015 VOSystems.
5 */
6
7 #include<sysvga.h>
8 #include<types.h>
9
10 static unsigned short *ch_vram;
11 static unsigned short X,Y,pos;
12 static unsigned char attr;
13
14 enum VGA_PORTS{
15                 CRTC_ADDR = 0x3D4,
16                 CRTC_DATA = 0x3D5
17 };
18
19 enum CGTC_REGS{
20                 CRTC_CURSOR_H = 0x0E,
21                 CRTC_CURSOR_L = 0x0F
22 };
23
24 void init_sysvga(void)
25 {
26         ch_vram=(unsigned short*)0xb8000;
27         X=0;    Y=0;    pos=0;
28         DisplayColorChangeChar(White,Black);
29 }
30
31 void ClearScreen(void)
32 {
33         ch_vram=(unsigned short*)0xb8000;
34         X=0;Y=0;
35         while(ch_vram<(unsigned short*)0xc0000)
36         {
37                 *ch_vram++ =NULL;
38         }
39         ch_vram=(unsigned short*)0xb8000;
40         
41         vga_text_update_cursor();
42         
43         return;
44 }
45
46 void vga_text_update_cursor(void)
47 {
48         pos=(Y*80)+X;
49         subset_out8(CRTC_ADDR, CRTC_CURSOR_H);
50         subset_out8(CRTC_DATA, pos >> 8     );
51         subset_out8(CRTC_ADDR, CRTC_CURSOR_L);
52         subset_out8(CRTC_DATA, pos & 0xFF   );
53 }
54
55 void DisplayOutputChar(const char ch)
56 {
57         if(ch=='\n'){
58                 if(Y<25){
59                         ch_vram+=(80-X);
60                         X=0;
61                         Y++;
62                         pos=Y*80;
63                 }else{
64                         ShiftDisplayChar(1);
65                         ch_vram+=(80-X);
66                         pos=Y*80;
67                         X=0;
68                 }
69         }else if(ch=='\r'){
70                 ch_vram-=X;
71                 X=0;
72                 
73         }else if(ch=='\t'){
74                 DisplayOutputChar(' ');
75                 DisplayOutputChar(' ');
76                 
77         }else{
78                 *ch_vram++ = (((attr)<<8) | ch);
79                 
80         }
81 }
82
83 void ShiftDisplayChar(unsigned int len)
84 {
85         unsigned int *sc1,*sc2;
86         sc1=0xb8000;    sc2=0xb8000+(80*2);
87         while(sc2<=0xc0000)*sc1++ = *sc2++;
88         if(len>1){
89                 len--;
90                 ShiftDisplayChar(len);
91         }
92 }
93
94 void DisplayColorChangeChar(Color_t fore, Color_t back)
95 {
96         attr |= (back<<4) | (fore & 0x0f);
97 }