Page 1 of 1

Turbo C++ Video Example

Posted: Sun Dec 16, 2007 9:06 am
by matias_beretta
Hello, I made some functions and I want to share them with you. Feel free to use it in your OS.

Code: Select all

int _di_ = 0;

void pokeb(int a, int b, char c)
{
    asm mov ax, [a];
    asm mov es, ax;
    asm mov di, [b];
    asm mov al, [c];
    asm mov [es:di], al;
}

char peekb(int a, int b)
{
    char c;
    asm mov ax, [a];
    asm mov es, ax;
    asm mov di, [b];
    asm mov al, [es:di];
    asm mov [c], al;
    return c;
}

void outp(int a, char b)
{
    asm mov dx, [a];
    asm mov al, [b];
    asm out dx, al;
}

char inp(int a)
{
    char b;
    asm mov dx, [a];
    asm in al, dx;
    asm mov [b], al;
    return b;
}

void gotoxy(int a)
{
    char b;
    char c;
    _di_ = a * 2;
    asm mov ax, [a];
    asm mov [b], al;
    asm mov [c], ah;
    outp(0x3d4, 0xf);
    outp(0x3d5, b);
    outp(0x3d4, 0xe);
    outp(0x3d5, c);
}

void clrscr()
{
    int a;
    for (a = 0x0; a <= 0xf00;)
    {
	pokeb(0xb800, a, ' ');
	a++;
	pokeb(0xb800, a, 0x1f);
	a++;
    }
    gotoxy(_di_ / 2);

}

void putch(char a)
{
    int b;
    if (_di_ == 0xfa0)
    {
	for (b = 0x0; b <= 0xf00; b++)
	{
	    pokeb(0xb800, b, peekb(0xb800, b + 0xa0));
	}
	for (b = 0xf00; b <= 0xfa0;)
	{
	    pokeb(0xb800, b, 0x20);
	    b++;
	    pokeb(0xb800, b, 0x1f);
	    b++;
	}
	_di_ = 0xf00;
    }
    if (a == '\n')
    {
	_di_ = _di_ - _di_ % 0xa0 + 0xa0;
    }
    else if ((a >= 0x20) && (a <= 0x7e))
    {
	pokeb(0xb800, _di_, a);
	_di_++;
	pokeb(0xb800, _di_, 0x1f);
	_di_++;
    }
    gotoxy(_di_ / 2);
}

void puts(char *a)
{
    while (*a != 0)
    {
	putch(*a);
	a++;
    }
}

void main(void)
{
    clrscr();
    gotoxy(988);
    puts("Matias Sebastian Beretta");

    asm mov ah, 0x0;
    asm int 0x16;
}

Posted: Sun Dec 16, 2007 3:37 pm
by Combuster
IIRC Turbo C provided peek and poke functions by itself

Posted: Sun Dec 16, 2007 4:36 pm
by AndrewAPrice
I remember those good old days when I though printing text on the screen was as hard as it would get :P

Re: Turbo C++ Video Example

Posted: Mon Dec 17, 2007 2:09 am
by os64dev
matias_beretta wrote:Hello, I made some functions and I want to share them with you. Feel free to use it in your OS.

Code: Select all

*SNIP*
As most of us is writing 32 protected mode or 64 long-mode nowadays. Your code is pretty useless to them. Furthermore your code is very compiler specific enhancing the uselessness. In short thanks for the code but it does not help me and i doubt others.

If you wish to contribute, you could write tutorials and code examples and post them on your (OS) website. JamesM is a very good example of how it should be done.

reply

Posted: Mon Dec 17, 2007 7:37 am
by matias_beretta
ok

Re: Turbo C++ Video Example

Posted: Mon Dec 17, 2007 9:43 pm
by elfenix
os64dev wrote:
matias_beretta wrote:Hello, I made some functions and I want to share them with you. Feel free to use it in your OS.

Code: Select all

*SNIP*
As most of us is writing 32 protected mode or 64 long-mode nowadays. Your code is pretty useless to them. Furthermore your code is very compiler specific enhancing the uselessness. In short thanks for the code but it does not help me and i doubt others.

If you wish to contribute, you could write tutorials and code examples and post them on your (OS) website. JamesM is a very good example of how it should be done.
Harsh...

Re: Turbo C++ Video Example

Posted: Tue Dec 18, 2007 1:37 am
by Solar
Fate wrote:Harsh...
A bit, yes.

Marias had code written for his compiler of choice, which worked, and perhaps took him quite some time to get right. And he wanted to share that info - laudable, for sure.

But consider it from the "other side". His code is specific to a compiler used by only a few people, and if Combuster is right, quite inefficient too. And it's limited to Real Mode, which most people leave behind as early as in the bootloader.

Well-intentioned, yes. Actually useful, not really.

And some of the "old farts" here have developed an allergy towards "newbie" symptoms, which sometimes leads to reactions more harsh than strictly necessary.

Posted: Tue Dec 18, 2007 2:35 am
by os64dev
Ok, i apologize if it sounded harsh.. it was not my intention to do so. :oops:

I should have written it a little nicer as Solar did, but sometimes i type before i think. My apologies again