Go Back   3D Realms Forums > General Topics > Programming / HTML Forum

Reply
 
Thread Tools
Old 06-25-2011, 11:05 AM   #1
8IronBob

8IronBob's Avatar
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.
__________________
PC Specs: Antec 900 ATX Case, Gigabyte 790GX Mobo, AMD Phenom II x4 955, EVGA 2GB GTX 680, Corsair Vengeance 16GB DDR3-1600, 160GB X25-M SSD, 500GB+640GB WD Caviar Blacks, 8x LG Blu-ray burner, 3D Vision 2 Kit/3DTV Play, Toshiba TL32515U, Logitech Z-2300 Speakers, DAS Pro K/B, Logitech MX518 Mouse, Win 7 Pro x64, Wacom Bamboo Fun Tablet.
8IronBob is offline   Reply With Quote
Old 06-26-2011, 12:53 AM   #2
Dopefish7590

Dopefish7590's Avatar
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,
Dopefish7590 is offline   Reply With Quote
Old 06-27-2011, 04:35 AM   #3
Altered Reality

Altered Reality's Avatar
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.
__________________
[...] We view customers as complete morons that will never catch on and [...] we're lying to them all the time. (Gabe Newell, Valve)
I'm the worst enemy in film-making and a completely talentless idiot. (Uwe Boll)
Faith is why you are wrong. (Crosma)
Altered Reality is offline   Reply With Quote
Old 06-27-2011, 06:46 PM   #4
Dopefish7590

Dopefish7590's Avatar
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"...
Dopefish7590 is offline   Reply With Quote
Old 06-27-2011, 08:42 PM   #5
8IronBob

8IronBob's Avatar
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.
__________________
PC Specs: Antec 900 ATX Case, Gigabyte 790GX Mobo, AMD Phenom II x4 955, EVGA 2GB GTX 680, Corsair Vengeance 16GB DDR3-1600, 160GB X25-M SSD, 500GB+640GB WD Caviar Blacks, 8x LG Blu-ray burner, 3D Vision 2 Kit/3DTV Play, Toshiba TL32515U, Logitech Z-2300 Speakers, DAS Pro K/B, Logitech MX518 Mouse, Win 7 Pro x64, Wacom Bamboo Fun Tablet.
8IronBob is offline   Reply With Quote
Old 06-27-2011, 10:48 PM   #6
Jiminator

Jiminator's Avatar
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.
__________________
big badass nasty weapons here....
Jiminator is offline   Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:29 PM.

Page generated in 0.09405088 seconds (100.00% PHP - 0% MySQL) with 17 queries

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

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