IPC@CHIP DK41 / DK51
Getting Started V2.2
© 2000-2004 Beck IPC GmbH Page 56 of 61
#include <dos.h>
#include <stdio.h>
#define RTOS_INTERRUPT (0xAD)
#define @CHIP-RTOS_INTERRUPT_A0 (0xA0)
#define @CHIP-RTOS_INTERRUPT_10 (0x10)
#define SHELL_FOCUS (1)
#define APPLICATION_FOCUS (2)
static void Set_Stdio_Focus (int to_whom)
{
_AL = to_whom ;
_AH = 0x11 ; // Service index
asm { int @CHIP-RTOS_INTERRUPT_A0 }
}
static unsigned int Key_Pressed (void)
{
_AH = 0x01 ; // Service index
asm { int @CHIP-RTOS_INTERRUPT_10 }
return _AX; //Register AX contains the result
}
static void Sleep (int how_long)
{
_BX = how_long ; // [ms]
_AH = 0x0 ; // Service index
asm { int RTOS_INTERRUPT }
}
int main (void)
{
Set_Stdio_Focus (APPLICATION_FOCUS) ;
printf ("Hello World\n") ;
do
{
Sleep (100) ;
} while (!Key_Pressed()) ;
printf ("Good Bye\n") ;
Set_Stdio_Focus (SHELL_FOCUS) ;
return 0 ;
}
The program first transfers the stdio focus to the application so that the printf output can be seen on
the terminal. Use of the RTOS Sleep is a good practice for DOS programs which dwell for any
significant amount of time, so that lower priority system tasks such as the Web server or FTP server
can still operate
15
. This hello program spins in the loop until a key on the console is touched and then
it exits with the “Good Bye” message.
A:\>hello
Hello World
Good Bye
15
This also allows multiple DOS programs to execute concurrently with a co-operative multitasking.