Turbo C++ Video Example

Programming, for all ages and all languages.
Post Reply
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Turbo C++ Video Example

Post 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;
}
Matías Beretta
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

IIRC Turbo C provided peek and poke functions by itself
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

I remember those good old days when I though printing text on the screen was as hard as it would get :P
My OS is Perception.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Re: Turbo C++ Video Example

Post 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.
Author of COBOS
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

reply

Post by matias_beretta »

ok
Matías Beretta
elfenix
Member
Member
Posts: 50
Joined: Sun Dec 02, 2007 1:24 pm
Libera.chat IRC: elfenix
Location: United States
Contact:

Re: Turbo C++ Video Example

Post 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...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Turbo C++ Video Example

Post 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.
Every good solution is obvious once you've found it.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post 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
Author of COBOS
Post Reply