Forum Archive

Go Back   3D Realms Forums > General Topics > Programming Forum
Blogs FAQ Community Calendar

Notices

 
 
Thread Tools
Old 06-25-2011, 10: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 (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 06-25-2011, 11:53 PM   #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  
Old 06-27-2011, 03: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  
Old 06-27-2011, 05: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  
Old 06-27-2011, 07: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 (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 06-27-2011, 09: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  
 

Bookmarks


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 -6. The time now is 06:41 AM.

Page generated in 0.08822203 seconds (100.00% PHP - 0% MySQL) with 16 queries

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

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