Qbasicnews.com

Full Version: Somebody tell me this would be impossible
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A program written in C++ that would read and execute QBasic code just like a scripting program. Different versions or packets you could download to emulate libraries (but each would use the allegro, just translate from DQBput() to drawsprite(), etc...). Here would be a really crappy example:

QB code:
DIM i AS INTEGER
SCREEN 13
LINE (0, 0)-(319, 199), 15
SLEEP
END

C++ interpreter (haven't made a parser or anything) the basic idea would be:
DIM i AS INTEGER would make any references to i in the basic code refer to an integer in a huge array for integers. This would also apply to floats, strings, etc..
SCREEN 13 would tell allegro you want to make a 320x200 resolution with 8bit color depth.
LINE would be converted to allegro's line()
SLEEP would be converted to readkey() (when it has no value)
END would signify the end of the file and quit the program.

This is probably impossible, or at least so that you couldn't emulate all the commands of QBasic in C++. Someone like me who just started C++ doesn't need to be making this, but someone with lots of experience does.

Some of the problems that would have to be addressed would be: how do you handle EMS and XMS calls (maybe just allocate them in system memory and emulate them accordingly), DOS calls like interrupt probably wouldn't work, File inputting/writing because QB uses commas to tell the compiler that there is a newline in the text file while C++ uses a space, types, multidimensional arrays, etc, etc, etc...

Somebody tell me this is impossible OR push me in the right direction and hook me up with a parsing function or tutorial.
Nope, of course its possible. Heck the qb ide was probally coded in C and asm. You can code your own compiler in C as well. The easiest way to do it is not what youve mentioned, but rather port qb code to c++, and have it be compiled. The problem with this is that libs no longer function that well, but you can always code wrappers for famous qb libs.

And there is an example of it at at sourceforge.net, got through http://qbcm.hybd.net/issues/ and look for a qbcc project, it should have a link and source code

And google PARSER on the internet youll find lots..

And finally http://lua.org is a very popular script engine, it's open source so take a look.

[edit]
Well if you wanted to make a perfect qb emulator, than hah, thats a joke. No chance qb has hundreds of routines etc etc itll take you years!!!!!!!!!! why not just write qb2 ? a protected mode qb compiler/c translator with a large amount of compatibilty.
and
http://qbcc.sf.net

there i found it for you
translate QB source code to machine code and execute it. BC.EXE and LINK.EXE are just figments of your imagination.

(Well, you told somebody to tell you it was impossible.)

(Wait a minute. I'm a nobody. Nevermind.)
there are over 1400 routines in bcom45.lib and hundreds listed in the index of qb's help. It might be a doable project if the entire community wrote classes and routines and converter stuff, but for now your best bet is to port it yourself.
Wouldn't there likely be *some* routines in the libraries for whatever C++ compiler he's using that would fulfill some of those functions?
1400 routines... Ok forget that idea. I was thinking that 100 or so was close to impossible, but 1400? I was just thinking how cool it would be to have a QB emulator for all windows platforms, just like a snes emulator or something, you would just load it and play. I don't think I'd be the guy for the task anyways.
Toshi's doing one in Java...
1400 is an exaggeration, that' just the number of routines in the lib file. but there are a couple hundred routines, and it wouldnt be terrible to convert to c. quite a few people have used classes to shape c's syntax to something closer to qb, and many of the routines (on trapping, PLAY) are archaic and rarely used, so they can be done as afterthought.
does anybody have QBCC? I couldn't download it from the site, and the email addresses don't work.