User Tools

Site Tools


writing_20console_20mode_20programs_20that_20will_20also_20run_20in_20the_20ide

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

writing_20console_20mode_20programs_20that_20will_20also_20run_20in_20the_20ide [2018/03/31 13:19]
127.0.0.1 external edit
writing_20console_20mode_20programs_20that_20will_20also_20run_20in_20the_20ide [2018/04/15 11:10] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Writing console mode programs that will also run in the IDE===== =====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:\\ \\ +//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: 
 + 
 +<code bb4w>
         IF FNInConsoleMode THEN         IF FNInConsoleMode THEN
           SYS "​GetStdHandle",​-10 TO @hfile%(1):​*INPUT 13           SYS "​GetStdHandle",​-10 TO @hfile%(1):​*INPUT 13
Line 13: Line 15:
  
         IF FNInConsoleMode THEN QUIT         IF FNInConsoleMode THEN QUIT
-\\  ​At the start of the program we [[/​Discovering%20how%20a%20program%20was%20run|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 (**C**ommon **G**ateway **I**nterface) programs in BBC BASIC program that will also run from the IDE:\\ \\ +</​code>​ 
 + 
 +At the start of the program we [[/​Discovering%20how%20a%20program%20was%20run|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 (**C**ommon **G**ateway **I**nterface) programs in BBC BASIC program that will also run from the IDE: 
 + 
 +<code bb4w>
         IF FNInConsoleMode THEN SYS "​GetStdHandle",​-11 TO @hfile%(2):​*OUTPUT 2         IF FNInConsoleMode THEN SYS "​GetStdHandle",​-11 TO @hfile%(2):​*OUTPUT 2
  
Line 21: Line 27:
  
         IF FNInConsoleMode THEN SYS "​SetEndOfFile",​ @hfile%(2):​QUIT         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.\\ \\ +</​code>​ 
 + 
 +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 ==== ==== Routines ====
 +
 +<code bb4w>
         DEF FNInConsoleMode         DEF FNInConsoleMode
         LOCAL base%         LOCAL base%
         SYS "​GetModuleHandle",​ 0 TO base%         SYS "​GetModuleHandle",​ 0 TO base%
         = (base%?​(base%!60+92) = 3)         = (base%?​(base%!60+92) = 3)
 +</​code>​
writing_20console_20mode_20programs_20that_20will_20also_20run_20in_20the_20ide.txt · Last modified: 2018/04/15 11:10 by richardrussell