Keith F. Lynch <k...@KeithLynch.net> wrote:
>I remember when my boss got tired of paying for CPU time on a
>mainframe, and had me convert some simulation code to run on his
>new Apple ][. I did so, but there were several problems:
>
>* The 6502 didn't have built-in floating point. That had to be
> emulated in software. That code was already built in, but it
> slowed everything down.
This is true. And, the programming languages most folks used at the
time did not have good features to make fixed-point math easy.
>* The system didn't have a trig library, so I had to write my own.
> And I didn't know what I was doing, so I coded it using the Taylor
> series. Mathematically sound, but painfully slow except for very
> small angles. (What can I say? This was more than 30 years ago.
> I've long since learned better ways of caculating trig functions.)
I gather from the mention of "p-code" that you were using the
Apple Pascal System, which was a port of the UCSD P-code. If this
was the case, you need to use the pragma UNIT TRANSCEND to request
transcendental functions like sine and cosine.
However, the transcendental functions are written in Pascal and compiled
down to p-code so they are not as fast as native versions would be.
>* The compiler compiled into p-code, which then had to be interpreted.
> That slowed things down a lot.
This is true.
>* The 6502 instruction set was impoverished.
>
>* The machine ran at just 1 Mhz.
>
>I'm sure you can see where this is going.
You'd have done much better just to use interpreted BASIC. I did a
satellite tracking system on a Commodore 64... it took about five minutes
to spit out a current position given time and the Keplarian elements,
which was just fine. The BASIC interpreter has the transcendental functions
implemented directly in assembler, and in pretty tightly optimized assembler
too, so in spite of the interpreter overhead it can be a big win if you are
doing something floating-point on an 8-bit micro.
I still do a lot of that today. I am currently calculating air velocity
in three-space given propagation times of an ultrasonic pulse in three
different directions (not parallel to the three axes), using an 8051.
There's plenty of CPU available.
>If at that time, over 30 years ago, I'd started one of the simpler
>simulations, one that took about a minute of CPU time on the CDC
>Cyber, it would probably still be running today.
Well, if you were running it on a Cyber you had a different set of horrible
coding issues there, too.