LB Booster
General >> Suggestion Box >> Additional support for console programs
http://lbb.conforums.com/index.cgi?board=suggestions&action=display&num=1500347707

Additional support for console programs
Post by CirothUngol on Jul 18th, 2017, 03:15am

I was playing around with MAINWIN functions compiled into console programs (PRINT, INPUT, LOCATE, TAB(n), CLS) and they all seem to work as expected. LBB even compiled and ran the MiniMax Chess Engine in a console window without a hitch (except for the 24 line default), which was a lot of fun. My testing wasn't extensive, but I think all of the MAINWIN functions worked except for MAINWIN itself. "MAINWIN columns [rows]" is directly analogous to "MODE columns,lines" in the Windows console. Would it be difficult to integrate this when compiling for console executables? Also, are LBB apps capable if interacting closely with the console, such as sending to/receiving from other console apps via stdIn/stdOut/stdErr, reading/writing environment variables, or sending commands to/executing apps in the current console (eg MODE, COLOR, DIR, etc) ...or does LBB use the windows console as a sort of 'dummy terminal'?

I've used a tiny but indispensable console app called BG.EXE for years (written by Carlos Aguilera). It provides mouse input, keyboard scanning, and advanced text output, including the ability to manipulate foreground/background colors (it was originally written to provide the ability to write batch games for the windows console, and I have both a very playable Snake-clone and rather addictive Sokuban puzzler to show what a fine job it does). He actually provided me with a custom stripped down version 3.0a of his utility along with his publicly available source code. Looking at the source for its Print, Color, Font, and Cursor functions it mostly just seems to be API calls to read a current value then write an altered value. If possible, it would be really nice to create some functions in LB Booster to replicate this functionality, but I'm only barely versed in either C or LB's API/DLL and I'm unsure if it's even possible.

Would it be improper to post his C language code here to see if anyone could recognize the likelihood of doing this in LBB? If not the whole thing then perhaps a function or three, such as the function to set the fore/back color for all subsequent writes to the console: C language Code:
void color()
{
    if (3 == argc) {
	WORD color;

	CONSOLE_SCREEN_BUFFER_INFO csbi;
	HANDLE hOut;

	hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	GetConsoleScreenBufferInfo(hOut, &csbi);


	color = (WORD) wcstoul(argv[2], (wchar_t **) NULL, 16);
	SetConsoleTextAttribute(hOut, color);
    }
} 
Looks like it sets up variables (2 numbers and a STRUCT?), grabs a handle (for the current console?), makes an API call (to fill a variable with screen buffer info?), gets the new settings from the commandline (as 1 or 2 single digit hex numbers), and makes another API call with the new settings (again to the current console?). Simple, right? ^_^
Is this even doable? Would this actually manipulate the console window that LBB is running in? With just a little more functionality, I think LBB could be a great resource for producing console applications.

Well, whaddaya know? You can check it all out via TextUploader:
Source and docs for BG.EXE v3.0a
HexNuts v1.3.0 batch game using BG.EXE v2.2
Worm v1.2.1 batch game using BG.EXE v2.2
Re: Additional support for console programs
Post by Richard Russell on Jul 18th, 2017, 08:38am

on Jul 18th, 2017, 03:15am, CirothUngol wrote:
"MAINWIN columns [rows]" is directly analogous to "MODE columns,lines" in the Windows console. Would it be difficult to integrate this when compiling for console executables?

Probably not difficult. I'll add it to the 'wishlist'.

Quote:
Also, are LBB apps capable if interacting closely with the console...

As you will have gathered already, I'm not an expert in console programming. If the things you are asking about can be achieved using straightforward API calls I can see no obvious reason why they should not be done from LBB using CALLDLL just as would be the case for a GUI program. Try it!

Quote:
Is this even doable? Would this actually manipulate the console window that LBB is running in? With just a little more functionality, I think LBB could be a great resource for producing console applications.

Again, the way to find out is to try it! The C code you listed is easily convertible to LB and no obvious 'gotchas' jump out at me. Give it a go and let us know how you get on.

Richard.