User Tools

Site Tools


writing_20console_20mode_20programs_20that_20will_20also_20run_20in_20the_20ide

Writing console mode programs that will also run in the IDE

by Jon Ripley, January 2007, April 2007

The following code demonstrates how to write a console mode BBC BASIC program that will also run from the IDE:

        IF FNInConsoleMode THEN
          SYS "GetStdHandle",-10 TO @hfile%(1):*INPUT 13
          SYS "GetStdHandle",-11 TO @hfile%(2):*OUTPUT 14
          SYS "SetConsoleMode",@hfile%(1),0
        ENDIF
 
        PRINT "Hello world!"'
        INPUT "What is your name ",name$
        PRINT '"Hello ";name$"."
 
        IF FNInConsoleMode THEN QUIT

At the start of the program we check the current environment the program is running in and only redirect I/O to the console if the program has been compiled - assuming that the program will be compiled with the 'Console mode' option set. When running in console mode you must end your program using QUIT. The code for FNInConsoleMode is at the end of this article.

Similar code is used to write CGI (Common Gateway Interface) programs in BBC BASIC program that will also run from the IDE:

        IF FNInConsoleMode THEN SYS "GetStdHandle",-11 TO @hfile%(2):*OUTPUT 2
 
        PRINT "Content-type: text/plain"
        PRINT
        PRINT "Hello world!"
 
        IF FNInConsoleMode THEN SYS "SetEndOfFile", @hfile%(2):QUIT

The differences here are that we do not need to redirect program input and CGI programs must close the output file handle before quitting.

Routines

        DEF FNInConsoleMode
        LOCAL base%
        SYS "GetModuleHandle", 0 TO base%
        = (base%?(base%!60+92) = 3)
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
writing_20console_20mode_20programs_20that_20will_20also_20run_20in_20the_20ide.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1