Skip to main content
gamedev.net
🔒 Locked

Trick Question

Started by TEUTON 8 replies 650+ views
Original Post
TEUTON
TEUTON
Please don't kill me for this... I was just wondering if we could print some text like Hello GameDev on screen without using any headers or libraries... I don't know how to design my own print functions??? Is it possible to do it in some simpler way?
Falken42
Falken42
In DOS, sure. Get a pointer to video memory (0x000B8000) and write away to your heart's content. No header files or libraries required.

Under Windows, no. To output to a console window, you need to at least call WriteConsole to show _something_ on the screen. Under GDI, you have to do a lot more work with creating a window and selecting a font. With DirectDraw, you can at least get a pointer to video memory, but you still have to link to some kind of library.

If you're just trying to write text output code, use the console routines to display text to the screen.
TEUTON
TEUTON
I tired using this
long int * ptr=(long int *)0x000B8000;
but this caused an error that cannot convert from long to long*

Falken42
Falken42
There is nothing wrong with that single line of code. Something else is causing the problem. However, it is usually easier to access video memory in char units rather than "long int".

You _are_ using a DOS compiler, right? Visual Studio cannot generate DOS .EXEs. If you got something compiled and tried to run it, it would crash because the application is not allowed direct memory access.
TEUTON
TEUTON
First i tried it in VC but it crashed as you said...
Then I tried in Dos based compiler with this cod

char * ptr=(char*)0x000B8000;
*&ptr="Hello bpoint";

But there was no output??
Falken42
Falken42
Try:
void writeString(char *addr, char *str){    while (*str != 0)    {        *addr = *str++;        addr += 2;    }}int main(){    char *addr = (char *)0x000B8000;    writeString(addr, "Hello bpoint");}


The text mode frame buffer is layed out in memory such that two bytes compromise a single character. One byte is the character itself, the next byte is the color attribute. Use google, you should be able to find tons of pages about how it works.

Is this 32-bit protected mode, by the way? If not, 16-bit mode requires a far pointer into B800:0000 instead.
TEUTON
TEUTON
Cool Man!!!
It worked..Thanks a alot...and yes it was old crappy 16-bit compiler..I don't use it but for this question I had to use it.
TEUTON
TEUTON
Can't we do that in assembly in windows based compiler??
Falken42
Falken42
Whether you do it in assembly or in C, it makes no difference. Windows does not allow direct access to the hardware from user mode.

Even if you coded it in assembly, your application would still crash just like the C version did.
TEUTON
TEUTON
Alright!! Thanks Again :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.