3D Realms Forums

3D Realms Forums (https://forums.3drealms.com/vb/index.php)
-   Programming Forum (https://forums.3drealms.com/vb/forumdisplay.php?f=24)
-   -   Fun with converting old TI-99/4A BASIC to C# (https://forums.3drealms.com/vb/showthread.php?t=38531)

8IronBob 06-25-2011 10:05 AM

Fun with converting old TI-99/4A BASIC to C#
 
Here is a link to a tutorial that I typed up where you could convert an old Hello World application from a 30 year old toy computer into a real console application written in C#, this is a fun example, and I look forward to cracking open even more possibilities from days of old:

Here is the old TI-99/4A BASIC code:

Quote:

10 CALL CLEAR
20 PRINT "HELLO WORLD!!"
30 FOR X = 1 TO 10
40 INPUT "PRESS <ENTER> TO END PROGRAM: ", Q$
50 END
And here is what that same program would look like within C#:

Code:

using System;

namespace HelloWorldExample
{
    class InitializeScreen
    {
          public static void Main()
          {
              ClearScreen();
          }

          private static void ClearScreen();
          {
              Console.BackgroundColor = ConsoleColor.Green;
              Console.ForegroundColor = ConsoleColor.Black;
              Console.Clear();
              HelloWorld.PrintHelloWorld();
          }

    }
}

Code:

using System;

namespace HelloWorldExample
{
    class HelloWorld
    {
          public static void PrintHelloWorld()
          {
              Console.WriteLine("HELLO WORLD!!");
              ScrollScreen();
          }

          private static void ScrollScreen()
          {
              for (int x = 0; x < 10; x++)
              {
                    Console.WriteLine(Environment.NewLine);
              }
               
              EndProgram();
          }

          private static void EndProgram()
          {
              Console.WriteLine("PRESS <ENTER> TO END PROGRAM:  ");
              Console.ReadKey();
          }
    }
}

Cool, huh? Now let's see how well a C# console application would look the other way around... Just thought this would be a cool experiment, see how well your knowledge is of old, old line numeric code would compare to object-oriented coding of today.

Dopefish7590 06-25-2011 11:53 PM

Re: Fun with converting old TI-99/4A BASIC to C#
 
Interesting... A fair amount of BASIC I imagine could be easily abstracted if you wanted to do some rather easy conversion... It would be horribly inefficient though.

There are a lot of things that one must consider when porting from one language to another,

Altered Reality 06-27-2011 03:35 AM

Re: Fun with converting old TI-99/4A BASIC to C#
 
What would be cool IMO would be a modern program that loads old BASIC files and interprets them.

Dopefish7590 06-27-2011 05:46 PM

Re: Fun with converting old TI-99/4A BASIC to C#
 
I suppose you could use DOSBox and QBASIC... But I would hardly call QBASIC "Modern"...

8IronBob 06-27-2011 07:42 PM

Re: Fun with converting old TI-99/4A BASIC to C#
 
That's true...but I was just showing how line numbered programming can be converted to OOP through more modern languages like C# and/or Java. Let's see if I can come up with another example that'll be fancier than Hello World...that was just too easy.

All right, here's a program called "Marching Numbers." Now let's see how well we can convert this one:

Original TI BASIC Code:

Code:

10 CALL CLEAR
20 X=0
30 X=X+1
40 IF X>9 THEN 20
50 PRINT X;
60 GOTO 30

Now let's convert this into C# code in OOP fashion, shall we?

Code:

using System;

namespace MarchingNumbers
{
    class Program
    {
          public static void Main()
          {
              InitializeScreen(); 
          }

          private static void InitializeScreen()
          {
              Console.BackgroundColor = Console.Color = Green;
              Console.ForegroundColor = Console.Color = Black;
              Console.Cls();
              NumberMarch.MarchNumbers();
          }
    }

    class NumberMarch
    {
          public static void MarchNumbers()
          {
              int x = 0;
              x += 1;

              Console.WriteLine(x);

              if (x >= 9)
              {
                    x == 0;
              }
          }
    }
}

Now I'm not certain that this conversion would exactly be 100%, but it does show how important it is to be able to determine, based on line number references, where to either create a new class and/or method, and if you need to make an if or a for statement, associate the line numbers, and develop a code block with all the involved lines of code. It's a weird science, I do admit, but there are key elements in older code to look for when attempting to convert it to a newer language. Just throwing that out there.

Jiminator 06-27-2011 09:48 PM

Re: Fun with converting old TI-99/4A BASIC to C#
 
your examples make no practical sense. In the real world you probably have thousands of these programs. Doing conversions on that scale will likely be error prone and problematic. A better solution would be to write hooks to say an enterprise service bus. That would allow the old programs to pass data back and forth with modern programs. Then the next step will be to get a replacement of the old programs and make the same hooks to the service bus. Then voila, swap out the old with the new.


All times are GMT -6. The time now is 11:26 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.

Website is 1987-2014 Apogee Software, Ltd.
Ideas and messages posted here become property of Apogee Software Ltd.