44// Define a variable for the screen location information
55ScreenLocation screenLocation ;
66
7+ // The number of rows of the video memory
8+ int NumberOfRows ;
9+
10+ // The number of columns of the video memory
11+ int NumberOfColumns ;
12+
13+ // The blank character
14+ unsigned char BLANK = 0x20 ;
15+
716// Initializes the screen
8- void InitializeScreen ()
17+ void InitializeScreen (int Cols , int Rows )
918{
19+ NumberOfColumns = Cols ;
20+ NumberOfRows = Rows ;
21+
1022 screenLocation .Row = 1 ;
1123 screenLocation .Col = 1 ;
1224 screenLocation .Attributes = COLOR_WHITE ;
@@ -41,7 +53,7 @@ void SetCursorPosition(int Row, int Col)
4153void MoveCursor ()
4254{
4355 // Calculate the linear offset of the cursor
44- short cursorLocation = (screenLocation .Row - 1 ) * COLS + (screenLocation .Col - 1 );
56+ short cursorLocation = (screenLocation .Row - 1 ) * NumberOfColumns + (screenLocation .Col - 1 );
4557
4658 // Setting the cursor's high byte
4759 outb (0x3D4 , 14 );
@@ -58,12 +70,12 @@ void ClearScreen()
5870 char * video_memory = (char * )VIDEO_MEMORY ;
5971 int row , col ;
6072
61- for (row = 0 ; row < ROWS ; row ++ )
73+ for (row = 0 ; row < NumberOfRows ; row ++ )
6274 {
63- for (col = 0 ; col < COLS ; col ++ )
75+ for (col = 0 ; col < NumberOfColumns ; col ++ )
6476 {
65- int offset = row * COLS * 2 + col * 2 ;
66- video_memory [offset ] = 0x20 ; // Blank
77+ int offset = row * NumberOfColumns * 2 + col * 2 ;
78+ video_memory [offset ] = BLANK ;
6779 video_memory [offset + 1 ] = screenLocation .Attributes ;
6880 }
6981 }
@@ -74,40 +86,30 @@ void ClearScreen()
7486 MoveCursor ();
7587}
7688
77- int SetScreenRow (int Row )
78- {
79- int currentRow = screenLocation .Row ;
80- screenLocation .Row = Row ;
81- screenLocation .Col = 1 ;
82-
83- return currentRow ;
84- }
85-
8689// Scrolls the screen, when we have used more than 25 rows
8790void Scroll ()
8891{
89- // Get a space character with the default colour attributes.
90- unsigned char attributeByte = (0 /*black*/ << 4 ) | (15 /*white*/ & 0x0F );
91- unsigned short blank = 0x20 /* space */ | (attributeByte << 8 );
92- char * video_memory = (char * )VIDEO_MEMORY ;
92+ unsigned char attributeByte = (COLOR_BLACK << 4 ) | (COLOR_WHITE & 0x0F );
93+ char * video_memory = (char * )VIDEO_MEMORY ;
94+ int i ;
9395
94- // Row 25 is the end, this means we need to scroll up
95- if (screenLocation .Row > ROWS )
96+ // Check if we have reached the last row of the screen.
97+ // This means we need to scroll up
98+ if (screenLocation .Row > NumberOfRows )
9699 {
97- int i ;
98- for (i = 0 ; i < COLS * 2 * (ROWS - 1 ); i ++ )
100+ for (i = 0 ; i < NumberOfColumns * 2 * (NumberOfRows - 1 ); i ++ )
99101 {
100- video_memory [i ] = video_memory [i + (COLS * 2 )];
102+ video_memory [i ] = video_memory [i + (NumberOfColumns * 2 )];
101103 }
102104
103105 // Blank the last line
104- for (i = (ROWS - 1 ) * COLS * 2 ; i < ROWS * COLS * 2 ; i += 2 )
106+ for (i = (NumberOfRows - 1 ) * NumberOfColumns * 2 ; i < NumberOfRows * NumberOfColumns * 2 ; i += 2 )
105107 {
106- video_memory [i ] = blank ;
108+ video_memory [i ] = BLANK ;
107109 video_memory [i + 1 ] = attributeByte ;
108110 }
109111
110- screenLocation .Row = ROWS ;
112+ screenLocation .Row = NumberOfRows ;
111113 }
112114}
113115
@@ -116,26 +118,33 @@ void printf(char *string)
116118{
117119 while (* string != '\0' )
118120 {
119- print_char (* string , 1 );
121+ print_char (* string );
120122 string ++ ;
121123 }
122124}
123125
124- // Prints out a null-terminated string, without scrolling
125- // the terminal window.
126- void printf_noscrolling (char * string )
126+ // Prints out the status line string
127+ void PrintStatusLine (char * string )
127128{
129+ unsigned char color = (COLOR_GREEN << 4 ) | (COLOR_BLACK & 0x0F );
130+ char * video_memory = (char * )VIDEO_MEMORY ;
131+ int colStatusLine = 1 ;
132+
128133 while (* string != '\0' )
129134 {
130- print_char (* string , 0 );
135+ int offset = (25 - 1 ) * NumberOfColumns * 2 + (colStatusLine - 1 ) * 2 ;
136+ video_memory [offset ] = * string ;
137+ video_memory [offset + 1 ] = color ;
138+ colStatusLine ++ ;
139+
131140 string ++ ;
132141 }
133142}
134143
135144// Prints a single character on the screen
136- void print_char (char character , int scrolling )
145+ void print_char (char character )
137146{
138- char * video_memory = (char * )VIDEO_MEMORY ;
147+ char * video_memory = (char * )VIDEO_MEMORY ;
139148
140149 switch (character )
141150 {
@@ -155,7 +164,7 @@ void print_char(char character, int scrolling)
155164 }
156165 default :
157166 {
158- int offset = (screenLocation .Row - 1 ) * COLS * 2 + (screenLocation .Col - 1 ) * 2 ;
167+ int offset = (screenLocation .Row - 1 ) * NumberOfColumns * 2 + (screenLocation .Col - 1 ) * 2 ;
159168 video_memory [offset ] = character ;
160169 video_memory [offset + 1 ] = screenLocation .Attributes ;
161170 screenLocation .Col ++ ;
@@ -164,11 +173,8 @@ void print_char(char character, int scrolling)
164173 }
165174 }
166175
167- if (scrolling )
168- {
169- Scroll ();
170- MoveCursor ();
171- }
176+ Scroll ();
177+ MoveCursor ();
172178}
173179
174180// Prints out an integer value
0 commit comments