I'm trying out OS development and have been following a book that goes on explaining the process well, but I have come into a roadblock as the example shown doesn't work for me. The function accesses video memory 0xb8000
and gets an offset to where it stores an ascii value of a letter, followed by an attribute byte that can change it's style.
VIDEO_ADDRESS
is set as #define VIDEO_ADDRESS 0xb8000
in screen.h
, while the function is in screen.c
int print_char(char character, int col, int row, char attribute_byte){ unsigned char *vidmem = (unsigned char *) VIDEO_ADDRESS; if(!attribute_byte){ attribute_byte = WHITE_ON_BLACK; } int offset; if(col >= 0 && row >= 0){ offset = get_offset(col, row); }else{ offset = get_cursor_offset(); } if(character == '\n'){ row = get_offset_row(offset); offset = get_offset(0, row+1); }else{ vidmem[offset] = character; vidmem[offset+1] = attribute_byte; } offset += 2; set_cursor_offset(offset); return offset;}
I tried another method which was combining the video address with an offset as follows:
// vidmem[offset] = character; // vidmem[offset+1] = attribute_byte; char* mem = vidmem + offset; *mem = character; mem++; *mem = attribute_byte;
But that leaves the top-left cell of the screen blank (calling a clear_screen()
function)
get_offset() function
int get_offset(int col, int row){ return 2 * (row * MAX_COLS + col);}
clear_screen() function
void clear_screen(){ int row = 0; int col = 0; for(row = 0; row < MAX_ROWS; row++){ for(col = 0; col < MAX_COLS; col++){ print_char('', col, row, WHITE_ON_BLACK); } } set_cursor_offset(get_offset(0, 0));}
How could I go about accessing the video memory with the offset to store the ascii value and offset?