Archive for the ‘Astronomy’ Category

Blasting from the past

Tuesday, August 5th, 2008

Someone with far too much time on their hands has ported the original BASIC version of StarTrek to C#

May God have mercy on us all.

Ah, good old line-numbered BASIC. It’s all coming back to me now. Those line numbers were there to provide targets for GOTO and GOSUB statements. But, line numbers made editing a tad difficult. It was convention to enter in line numbers that were multiples of 10. That way, as you developed the program, you could go back and insert up to 9 additional statements in between existing lines without reworking all the GOTO/GOSUB references.

Oh bloody hell, I remember that, in fact I was thinking about it the other day, and not in a nostalgic way. Now machine code, thats nostalgia, though I guess line numbers were a natural successor in a way, like flexible addressing, hmmmm … I better stop or I’ll make it sound good.

due to the caps, I feel like the code is screaming at me

Ha ha, yeah …. things sure have changed …

Next, I had to decide what language to port it to. Staring at that BASIC code reminded me that C# brought goto back into the mainstream.

So it’s C#’s fault, eh ? I better move swiftly on before I start quoting Dijkstra, may God have mercy on us all.

Would it be possible to do an exact line-by-line port from BASIC to C#? Apparently so… and the result is some of the sickest code I’ve ever keyed into a computer. Want a comparison? Here’s a segment of BASIC code:


2950 PRINT "TORPEDO TRACK:"
2960 LET X=X+X[1]
2970 LET Y=Y+X[2]
2980 IF X<.5 OR X >= 8.5 OR Y<.5 OR Y >= 8.5 THEN 3420
2990 LET V[4]=X
2991 LET V[5]=Y
2992 GOSUB 9000
2993 PRINT
3020 IF A[INT(X+.5),INT(Y+.5)]#0 THEN 3080
3060 GOTO 2960
3080 IF A[INT(X+.5),INT(Y+.5)]#2 THEN 3230
3120 PRINT “*** KLINGON DESTROYED ***”
3130 LET P[1]=P[1]-1
3140 LET P[3]=P[3]-1
3150 IF P[3] <= 0 THEN 4040
3160 FOR I=1 TO 3
3170 IF INT(X+.5)#K[I,1] THEN 3190
3180 IF INT(Y+.5)=K[I,2] THEN 3200
3190 NEXT I
3200 LET K[I,3]=0
3210 GOTO 3370
3230 IF A[INT(X+.5),INT(Y+.5)]#4 THEN 3290
3270 PRINT "YOU CAN'T DESTROY STARS SILLY"
3280 GOTO 3420

And the C# version:


_2950: Console.WriteLine("TORPEDO TRACK:");
_2960: X = X + _X[1];
_2970: Y = Y + _X[2];
_2980: if (X < .5 || X >= 8.5 || Y < .5 || Y >= 8.5) goto _3420;
_2990: _V[4] = X;
_2991: _V[5] = Y;
_2992: _9000();
_2993: Console.WriteLine();
_3020: if (_A[(int)(X + .5), (int)(Y + .5)] != 0) goto _3080;
_3060: goto _2960;
_3080: if (_A[(int)(X + .5), (int)(Y + .5)] != 2) goto _3230;
_3120: Console.WriteLine(”*** KLINGON DESTROYED ***”);
_3130: _P[1] = _P[1] - 1;
_3140: _P[3] = _P[3] - 1;
_3150: if (_P[3] <= 0) goto _4040;
_3160: for(I = 1; I <= 3; I += 1) {
_3170: if ((int)(X + .5) != _K[(int)I, 1]) goto _3190;
_3180: if ((int)(Y + .5) == _K[(int)I, 2]) goto _3200;
_3190: ;} I = 3;
_3200: _K[(int)I, 3] = 0;
_3210: goto _3370;
_3230: if (_A[(int)(X + .5), (int)(Y + .5)] != 4) goto _3290;
_3270: Console.WriteLine("YOU CAN'T DESTROY STARS SILLY");
_3280: goto _3420;

To simulate line numbers, each line starts with a label consisting of an underscore followed by a number. That works fine for GOTO, but what about GOSUB? Examine line 2992. Subroutines were replaced with methods. That almost worked. In BASIC, you’re not forced to RETURN from subroutines. You can leave them via GOTO. That was used only in the case that the player is destroyed to send them back to the beginning of the program to start over. I replaced that GOTO with a return statement that passes a flag back to the caller. The caller inspects the flag and jumps back to the program start if need be. I also discovered that at one point, there is a GOTO that jumps into a FOR loop. C# won’t let you jump to a label in a sub-block of code. I transformed the FOR loop into a GOTO loop to make C# happy.

All the variables in the BASIC program, including the arrays, are real number type. However, in BASIC, an array and a scalar can share the same name; the interpreter is able to sort it all out. But, C# is less kind. To solve the problem, I prefixed array names with underscores. Also, arrays in BASIC are indexed from 1 instead of 0. To compensate, I increased the length of all arrays by 1. Index 0 is never used.

Well, BASIC to C# using labels is a fairly neat hack, but …. it is still painful. Notice the use of reals to compensate for the typing conversion. Whenever anyone goes on about the superiority of dynamic typing I always think of them as BASIC programmers.

Anyway pain aside, here comes the real gem and the reason for posting the article ….

Rewriting the game brought up an interesting aspect of the BASIC version. Targeting is done using polar coordinates, but you won’t find any trigonometric functions in the BASIC code. I assume the functions were unavailable. Instead, the angle is converted into a direction vector using different ratios that approximate the trigonometric functions. That means even if you worked out perfect targeting using trigonometry, when you entered in the angle, the actual trajectory will be slightly off. Nonetheless, it’s a pretty clever math trick. As for me, I took advantage of Math.Sin() and Math.Cos().

Now that is nostalgia, using math hacks because there wasn’t any support for things like trigonometry, not that from time to time in certain situations these old hacks don’t resurface, for example I remember coming across a pretty slick circle drawing algorythm a few years ago using ints and no trig at all, or having to provide your own divide route for chips without a divide instruction.

Jaaniõhtu

Monday, June 23rd, 2008

If you are Estonian you may be celebrating Jaaniõhtu tonight, or there again maybe not, it’s up to you.

From Wikipedia

The short summer seasons with long days and brief nights hold special significance for the people of Estonia. Jaanipäev is celebrated in the night between 23rd and 24th of June, a few days after the summer solstice, when night seems to be non-existent.

The best-known Jaanik, or midsummer, ritual is the lighting of the bonfire and the jumping over it. This is seen as a way of guaranteeing prosperity and avoiding bad luck. Likewise, to not light the fire is to invite the destruction of your house by fire. The fire also frightened away mischievous spirits who avoided it at all costs, thus ensuring a good harvest. So, the bigger the fire, the further the mischievous spirits stayed away.

Midsummer’s eve is important for lovers. Among Estonian fairy tales and literature there is the tale of two lovers, Koit (dawn) and Hämarik (dusk). These two lovers see each other only once a year and exchange the briefest of kisses on the shortest night of the year. Earth-bound lovers go into the forest looking for the flower of the fern which is said to bloom only on that night. Also on this night, single people can follow a detailed set of instructions to see whom they are going to marry.

Former President Lennart Meri has provided another perspective on Jaanipäev in his work Hõbevalge (Silverwhite, 1976). Meri suggests that the Jaanipäev traditions re-enact the fall of the Kaali meteorite in Saaremaa. The meteorite’s fall is also said to be the inspiration for Nordic and Baltic mythological stories about the sun falling onto the earth. This idea suggests that the present day bonfires and celebrations actually symbolise Estonia’s connection with its ancient past.

During their occupation of Estonia, the Soviets made no attempt to stop Jaanipäev celebrations. For Estonians, however, Jaanipäev remained tied to Estonia’s victory during the War of Independence and the securing of a free and independent state. Jaanipäev, therefore, always reminded Estonians of their independence in the past, despite Soviet attempts to eliminate such ideas.

The tradition before the Soviet occupation, which has now been restored, was for a fire to be lit by the Estonian President on the morning of Võidupüha (June 23). From this fire, the flame of independence was carried across the country to light the many bonfires.

make install

Thursday, April 3rd, 2008

SCUBA-2 installation video ( .gif )

Google maps for sky

Monday, March 17th, 2008

http://www.google.com/sky/ or http://sky.google.com/ and not to be confused with Google Earth with Sky.

Scooby Doo in the news

Monday, February 25th, 2008

From the press release

“Submillimetre astronomy is a relatively new science and one where the UK has led the world over the past two decades. Our latest camera is the most powerful yet: SCUBA-2 on the JCMT should detect the equivalent of the heat from a candle on the surface of the Moon.”

Bring it on !

STFC petition

Monday, February 11th, 2008

Another online petition

Due to cost overruns the UK’s funding agency for particle physics and astronomy, STFC, is recouping £80M with deep cuts to UK physics operations in these areas. These include ending the UK’s involvement in the International Linear Collider - the next generation of particle physics experiment. This risks relegating the UK to second tier involvement in future research and critically damaging the country’s standing within the community. Furthermore UK Astronomy will be seriously hit with up to a 25% cut in grants. This is incompatible with the government’s stated aim of making Britain a world leader in science. A review of this decision has recently been announced and we urge the Prime Minister to press for another solution to this problem before UK physics is set back by decades.

Once again I reiterate my point on online petitions, not worth the paper they are printed on, Government ones doubly so, or prove me wrong.

If you want to get the issue raised in Parliament you need to contact your local representative. I recommend using writetothem.com, which used to be FaxYourMP.

http://www.writetothem.com/

Chimps in spaaaaace !

Thursday, January 31st, 2008

On this day in 1961, a four year old Chimpanzee named Ham was sent into space by the US. Ham was the first known hominid to travel into outer space.

What the … Mars Shun

Wednesday, January 23rd, 2008

According to Aunty, people the world over are going ape-poopy over this image ( click to enlarge … no, on the image, ) claiming it to be proof of extra-terrestrial life.

They are quite correct, the figure on the left of the picture is obviously a Tuskan Raider from Star Wars and on the right you can plainly see there is a Jawa Sand Crawler

Of course I’m eating humble-crumble after mocking peoples half-baked beliefs.

UPDATE : How to take pictures on Mars … coool.

Hotel Mauna Kea

Wednesday, December 5th, 2007

http://www.youtube.com/watch?v=XPdTlHK1h_0

Paul forwarded this, as apparently it is doing the rounds of the telescopes. When the weather is poor, as it is at the moment, it appears visiting observers hang around at Hale Pohaku writing parodies of well-known songs and their careers.

Disk crashes ending careers ? not on my watch !

I swear it never happens

Monday, November 19th, 2007

http://seemikedraw.files.wordpress.com/2007/11/giant-telescope.gif

From SeeMikeDrawOf course they’ve discovered life on other planets. They just don’t want to share the telescope.

Thanks to the Binary Ape, who appears to be convinced this practice goes on.