Slimelite BBS

Help! Wizard needed!

Back to EMULATE

From Jerry Coffin · 1996-04-05 05:47 · #73630 in EMULATE

In reply to Help! Wizard needed! by Chris Neale

On (29 Mar 96) Chris Neale wrote to Jerry Coffin...

 JC>Yes and no.  My day job is mostly reverse engineering other
 JC> people's

 CN> Who for? Yourself or a company? It must be bl00dy difficult, I would
 CN> presume.

Oh, it depends - some of it is pretty easy.  OTOH, at times I end up
with large, bloody bald spots from ripping my hair out.

 CN> I've always assumed it to be very hard, requring a lot of
 CN> knowledge of assembly and a hell of a lot of time. Or is it easier
 CN> than it appears.

Yes, it requires a fair amount of knowledge of assemly, and yes it can
take quite a bit of time.  I also spend a fair amount of time using C++
becuase I frequently have to write my own tools.  These include things
like disassemblers and occassionally simulators, though most of the time
commercial circuit simulators work just fine.

 CN> Is there a lot to be yeilded from it for the programmer
 CN> when it comes to seeing how they've done it, and of faster ways of
 CN> doing things. I know very little about dis-assembly, so can only
 CN> guess. It's not a very publicised thing so it appears.

I learn lots of interesting tid-bits, but much has limited direct
usefulness outside its original application.  OTOH, I hope it's
broadened my viewpoint a bit.

 CN> Thanks again for the help with my program. About the int/void main
 CN> argument; how do you return an error level from function main(). And
 CN> as an integer it can be from -32k to +32k, yes? And how can, say a
 CN> batch file or another program see it.

The value you return from main becomes the errorlevel returned to the
calling program.  For instance, one of the most used batch utilities
ever is one to get a single key press and return its value as the error
level.  With C under DOS this looks like:

#include <conio.h>

int main() {
    return getch();
}

With a program this small and simple, there's little C++ can add to C,
so at least technically further discussion is off-topic.  The one main
difference between C and C++ in this area, is that you can call exit to
return a value to the OS as well, but in C++ this is almost always a
poor idea - exit() doesn't guarantee calling destructors of all objects
before exiting, so important cleanup can be missed.

As far as the range of values goes: under DOS, the value that's returned
to the OS is broken into two parts.  With a normal return, the value you
specify gets masked and only the low byte is actually returned, with the
high byte always set to 0.  With a return by other means such as
pressing `a' when an `Abort/Retry/Ignore' prompt is displayed, the high
byte is set to another value to signify the method of exiting the
program.

Under most other OSes you can return the full range of integers.

 CN> The book I'm using to teach me to use it goes into deep detail about
 CN> some things but doesn't touch on these discrete features. Nor does
 CN> it mention anything about DOS/BIOS interrupts at all. As I have
 CN> written several program which use them it is a bit of a pain. The
 CN> objects system makes this sort of thing a lot easier to use IMO.

Many of the books on C++ that I'd consider the best in quality try to
stick to relatively portable constructs rather than being written
specifically for DOS on a PC, where direct access to BIOS interrupts and
such are available.  Even when you're writing for a PC under DOS, it's
often handy to know what's portable and what isn't, so you'll be able to
use portable code when possible, and restrict things like direct use of
the BIOS to small, well defined sections of code.  As it happens, this
generally results in better organized and structured code as well.
    Later,
    Jerry.

... The Universe is a figment of its own imagination.

--- PPoint 1.90
 * Origin: Point Pointedly Pointless (1:128/77.3)