Others explained to you how to get a string, which was your question. However, this is not your problem. You use the x86 and want to write to the text buffer at 0xB8000
to show a text on the screen. This is not normal, since most other program on x86 run inside an OS.
To get what you want, you have to set every second byte to the character you want and every other byte to the color you want. A string will not work for your problem.
Means you will need something like this:
#define COLOR 0x04 //red text on black background
vidmem[0] = 'A';
vidmem[1] = COLOR;
vidmem[2] = 'B';
vidmem[3] = COLOR;
vidmem[4] = 'C';
vidmem[5] = COLOR;
Of course it would make more sense to do this in a for
or while
loop and don't do it by hand, but i want to explain what you need to do in order to print some text.
Indexing Positions
You can directly accessing individual positions on the screens. vidmem
is an array of 25 lines, each line is an array of positions, each position has a byte for the symbol and one for the color. You can change your vidmem
declaration so you see at a glance what you access.
#define COLOR 0x04
void kmain(void) //also, use a proper declaration, with return type.
{
//vidmem is a pointer to an array with 50 elements of an array of 2 elements with type char
//The array [50][2] is exaclty the same as an array of [100], but
//with [50][2] we tell the compiler how to access it.
//The memory pointed to by vidmem has a special hardware function, so it should be volatile.
volatile char (*vidmem)[50][2]=(void*)0xb8000;
// ^----- 50 columns per line
// ^- 2 bytes per character
// V--------------- Line
// V------------ Column
// V--------- Symbol (0) or color (1)
vidmem[0][0][0] = 'A'; //symbol at position 0,0 is a 'A'
vidmem[0][0][1] = COLOR; //Set color for position 0,0
vidmem[0][1][0] = 'B'; //symbol at position 0,1 is a 'B'
vidmem[0][1][1] = COLOR; //Set color for position 0,1
//you can also directly access any other position
vidmem[1][0][0] = 'C'; //symbol at position 1,0 (second line) is a 'C'
vidmem[1][0][1] = COLOR; //Set color for position 1,0
}