Printing To Screen: Difference between revisions

→‎Printing Strings: Added a more advanced C function
[unchecked revision][unchecked revision]
m (→‎Printing Strings: Aesthetics)
(→‎Printing Strings: Added a more advanced C function)
Line 42:
 
This simply cycles through each character in the string, and copies it to the appropriate place in video memory.
 
Here is a more advanced set of functions (C code compatible with C++):
<source lang="c">
//User:bellezzasolo: excerpt from my OS. In my OS this is C++
//This will work in both C and C++
//MODE 3 printing text
#include "stdio.h" //Put definitons of these functions here
#define UCHAR unsigned char
int x = 0;
int y = 0;
unsigned short* vidmem = (unsigned short*)0xb8000;
UCHAR color = (UCHAR)0x3f; //Avoid compiler error. This produces white on light blue. You can change this if you want
void setColor(UCHAR foreground, UCHAR background)
{
color = (background<<4 | foreground);
}
void putc(char c) //Prints a character
{
unsigned short temp = (unsigned short)((color << 8)|c);
unsigned short* vid = (unsigned short*)(vidmem + y*80 +x);
*vid = c;
x++;
if(x>80)
{
y++;
x=0;
if(y>25)
{
scroll();
}
}
}
void Puts(char* string)
{
if(!string)
return;
char* stream = string;
while(*stream != 0)
{
putc(*stream);
stream++;
}
}
</source>
 
==Printing Integers==
Anonymous user