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 }
@@ -77,28 +89,27 @@ void ClearScreen()
7789// Scrolls the screen, when we have used more than 25 rows
7890void Scroll ()
7991{
80- // Get a space character with the default colour attributes.
81- unsigned char attributeByte = (0 /*black*/ << 4 ) | (15 /*white*/ & 0x0F );
82- unsigned short blank = 0x20 /* space */ | (attributeByte << 8 );
83- 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 ;
8495
85- // Row 25 is the end, this means we need to scroll up
86- 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 )
8799 {
88- int i ;
89- for (i = 0 ; i < COLS * 2 * (ROWS - 1 ); i ++ )
100+ for (i = 0 ; i < NumberOfColumns * 2 * (NumberOfRows - 1 ); i ++ )
90101 {
91- video_memory [i ] = video_memory [i + (COLS * 2 )];
102+ video_memory [i ] = video_memory [i + (NumberOfColumns * 2 )];
92103 }
93104
94105 // Blank the last line
95- 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 )
96107 {
97- video_memory [i ] = blank ;
108+ video_memory [i ] = BLANK ;
98109 video_memory [i + 1 ] = attributeByte ;
99110 }
100111
101- screenLocation .Row = 25 ;
112+ screenLocation .Row = NumberOfRows ;
102113 }
103114}
104115
@@ -112,10 +123,28 @@ void printf(char *string)
112123 }
113124}
114125
126+ // Prints out the status line string
127+ void PrintStatusLine (char * string )
128+ {
129+ unsigned char color = (COLOR_GREEN << 4 ) | (COLOR_BLACK & 0x0F );
130+ char * video_memory = (char * )VIDEO_MEMORY ;
131+ int colStatusLine = 1 ;
132+
133+ while (* string != '\0' )
134+ {
135+ int offset = (25 - 1 ) * NumberOfColumns * 2 + (colStatusLine - 1 ) * 2 ;
136+ video_memory [offset ] = * string ;
137+ video_memory [offset + 1 ] = color ;
138+ colStatusLine ++ ;
139+
140+ string ++ ;
141+ }
142+ }
143+
115144// Prints a single character on the screen
116145void print_char (char character )
117146{
118- char * video_memory = (char * )VIDEO_MEMORY ;
147+ char * video_memory = (char * )VIDEO_MEMORY ;
119148
120149 switch (character )
121150 {
@@ -135,7 +164,7 @@ void print_char(char character)
135164 }
136165 default :
137166 {
138- int offset = (screenLocation .Row - 1 ) * COLS * 2 + (screenLocation .Col - 1 ) * 2 ;
167+ int offset = (screenLocation .Row - 1 ) * NumberOfColumns * 2 + (screenLocation .Col - 1 ) * 2 ;
139168 video_memory [offset ] = character ;
140169 video_memory [offset + 1 ] = screenLocation .Attributes ;
141170 screenLocation .Col ++ ;
0 commit comments