Text output for any system [code]

Started by
9 comments, last by Khaos 20 years, 6 months ago
In DOS I know I can write: cout << "hello"; and have it print to my screen. However, am I correct to assume this won''t work for Linux? Or does it? What about MacOSX, or something else? How am I to know what functions work on any system and what work on a specific system? How can I write a text output routine (with no assembly obviously, just pure C++) that will output a given string to the monitor? A simple as possible method to doing this would be appreciated. Theory too, not just code samples. I''d like to know how this works. Can the same method, or any method, be applied to a pixel plotting routine? Sound output? Etc? Can I use simply C++ and nothing else to write a routine that will place a colored pixel on any monitor on any system? I''m sorry for the fact I generally write thoughts as questions. Please point me in the right direction. Thank you all.
Advertisement
cout is standard C++ so it will work on any system that has a C++ compiler.

As for plotting pixels or sound, it may be very different from a system to another so you can use a cross-platform library like SDL (http://www.libsdl.org) or write your own functions for every systems you want to support (i suggest the prior)

Hope that helps
Matt
Matt
Thank you. However, I was not thinking of a commercial library. I would like some help or ideas on rolling my own routine to stick characters in the display memory, that will work on any system or OS.

And also, what''s the difference in binary of the letter "F" displayed on the screen, and a particular red pixel at (17,39)? How can I do similar and place pixels on the screen?

Thanks again.
You can''t stick characters in memory on most OSes, because they protect memory (''Protected Mode''). You''ll need to write OS-specific functions and use conditional compilation or something like that to have a different library on each OS that has the same interface.
How you set the display mode and write pixels or text will depend entire on the OS and platform.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
std::cout is part of the c++ standard library, which is implemented in most new compilers, so that code will work on any OS with a c++ compiler (btw you have to recompile it on the other OS for it to work with that OS). Plotting graphics is much harder to do in an OS independant way, which is why OpenGL and other cross-platform libraries are there.
So it''s not possible? You HAVE to have a library per system? In protected mode OSes you cannot simply stick anything in the video display RAM? Is video RAM not accessible or what?
quote:Original post by Khaos
So it''s not possible? You HAVE to have a library per system? In protected mode OSes you cannot simply stick anything in the video display RAM? Is video RAM not accessible or what?


There are higher level access routines for a reason.

If you could get true direct access to lower level hardware functions instead of letting the OS and drivers handle it for you, you would have to write a different set of code for pretty much every piece of hardware there is.

Go with a standard libary.


Or am I reading you wrong?


Far too much time has passed
For us to lament that we were in love.
"I want to make a simple MMORPG first" - Fenryl
quote:Original post by Khaos
So it''s not possible? You HAVE to have a library per system? In protected mode OSes you cannot simply stick anything in the video display RAM? Is video RAM not accessible or what?

Precisely. For this reason, languages that do not have standard graphics packages - Java does; C++ does not - are forced to rely on third-party libraries. If you do not wish to use one, then yes, you will have to write different routines for each platform you wish to support.
Is the term "platform" used to represent the _processor_, the _operating system_, or both? Is there a generic term for one or the other? If you are writing platform independent code, does that run on any OS or any processor, or both, in other words. What would you call code that could run on 8 bit, 16 bit, 32 bit, or 64 bit processors, from any company (Z80, PIC, x86, etc) on any given OS (if any)? If it could run on ANYTHING, would it be platform independent, or system independent, or what?

I''m sorry to ask stupid questions, but I''d like to have accurate terminology. Thank you.
Platform usually refers to the operating system / environment.
e.g. Java Virtual Machines are implemented on an operating system basis, not for different processors.

I think assembler code is different because it is intertwined with the processor, there is no level of abstraction beyong direct opcode translation.

C++ compilers are also written per operating system.

Wizza Wuzza?

This topic is closed to new replies.

Advertisement