Copyright (c) Hyperion Entertainment and contributors.
AmiWest Lesson 3
Contents
AmiWest Lesson 3: Input and Output
Debug Output
One of the first things you will need is some way to output text for debugging purposes. Exec has a simple function which is provided for this purpose and it is used as follows:
IExec->DebugPrintF("my debug message\n");
The text may go to the default serial port, a debug buffer or even a console window via a tool called Sashimi.
More information about this debugging facility can be found at Debug Logging and Redirecting Debug Output.
Console Input and Output
There are many options when it comes to choosing an API for console input and output. This can really confuse beginnners so I thought I would try and briefly explain the fundamentals.
All console input and output is done via DOS streams. That means whatever fancy interface is on the surface it all boils down to working with DOS streams. Three different streams are available for every Process:
- Input
- Output
- ErrorOutput
Usually, Output and ErrorOutput will share the same stream but this is not a requirement.
The ISO C standard also defines input and output streams:
- stdin
- stdout
- stderr
The C startup code will auto-magically create these standard streams for you and assign them to the DOS-provided streams mentioned above.
Whether you use printf() or IDOS->Printf() they will both ultimately end up using the DOS Output stream. However, this doesn't mean you can just mix and match to taste. The reason is that each of these calls are buffered. The C library could use its own buffering or it could depend on DOS buffering. Programmers should not assume one or the other and instead should be consistent in their choice of API.
File Input and Output
File input and output has many APIs to choose from. At the most basic level you have IDOS->Read() and IDOS->Write().