Tuesday, April 10, 2012

Programming from Commodore to Intel


In the beginning there was 1 KB...

Computers came to life in a world of innocence and innocent they were - at least in the first years... In the early computer systems you had to access memory directly in order to program, there was no operating system that you could blame for all your mistakes, you had to enter text programming commands in order to do the simplest tasks as loading a small game, loading was conducted from an analog tape recorder and not a fancy cd-rom, there were no colour displays, there were many-page manuals of computers which taught you how to program. In simple words: computers were more tools than simple 'black box' gadgets. Anyone who lived in that times knows how to use computers and is not afraid of experimenting. If you haven't lived in that era you should know and understand it, in order to be able to be a successful programmer.

Commodore 64

Any programmer who doesn't know the computer history is condemned to ignorance. Knowledge is power. Learn how to program for a Commodore computer and you will be able to program for any machine possible. Learn how to use 128 KB of memory for your programs and you will never feel limited by the 2 GB of todays computers' memory...

Computers' structure

Computers are consisted of electronic parts. These parts can only understand two basic states: the existence of current (state called ‘1’) and the absence of current (state called ‘0’). When we talk about 0’s (or 1’s) we actually talk about current passing (or not passing) through a pipe in the processor during a calculation it performs or about charge existing (or not existing) in a specific area of a storage device used by the computer (i.e. its RAM chip) capable of retaining such a charge. We program the computers so that we can tell them how to handle specific inputs. The input to a computer is the current passing through the pipes of the processor. The processor then processes that input according to what it is programmed to do and generated an output (again a ‘collection’ of 0’s and 1’s).

Programming at a basic level


Commodore 128 initial screen

The processor of a computer is firstly programmed by its manufacturer. In particular, the manufacturer designs the circuits of the processor in such a way that the processor already "knows" how to act when given certain inputs. In that way, every processor has some commands he can obey to, already embedded in it. For example, consider the simple imaginary case of a processor which has 2 input current "pipes" and one output "pipe" that they are designed in such a way that the current in each one of the input pipes is added to the other and then the resulting total current (in Ampere) is sent in the output pipe. That processor is a processor which is already "programmed" (from its manufacturer) to apply the ‘add’ command to its input and send it to the output. It sounds simple and trivial, but that is how it all started...
The second level of programming a processor is by having direct access to its circuits after it is build and store the commands you want in its permanent memory. Intel and AMD provide big software vendors (mainly the ones which develop Operating Systems that must interact at a more low level with the processor) with access to the processors memory (via developers’ kits – including specific hardware and electronic equipment to facilitate the writing to the memory where commands can be stored to the processor), so that they can write the programs they want. For example Bill Gates and Paul Allen wrote the operating system of Altair computer in the ‘70s by toggling switches up (the 1’s) and down (the 0’s). This computer had no keyboard, just switches in its front, with which one could store programs in its memory. The output of that computer was lights flashing (the 1’s) or not flashing (the 0’s).However no operating system is written entirely in 0’s and 1’s in that way. It is more usual for developers to write directly into the processor’s memory a program (called an ‘Assembler’) that will facilitate the developing of other programs in a more easy way: the Assembler can accept as input commands in a structured language (e.g. ‘mov ah, al’ to move the contents of the al register to the ah memory register) instead of the tedious 0’s and 1’s. This Assembler, once stored into the processors memory, can help other software developers enter their programs via the normal keyboard and store them appropriately. The conversion of the commands in the structured language the Assembler accepts as input to 0’s and 1’s which the processor can understand, is done by the Assembler without the programmer having to worry about anything. How can you write in machine language in the first place?

Intel 386 processor

How can you load a program into a blank processor? Simple: talk to the processor’s manufacturer, get access (via specific hardware the manufacturer has constructed so that his processor can be programmed) to the processor and…type in your program!Once an assembler is loaded into the processor, anyone can write…Assembly into that chip! Assembly language is a low level language that allows the programmer to do anything he wants via direct memory manipulation. With the proper commands you can store data into already specified [by whom? Don’t ask again! The answer is: by the chip manufacturer! Intel, AMD, etc…] memory segments (called ‘registers’) or into memory addresses you specify and make things work. Examples of registers are ‘ah’ or ‘al’. A direct memory address can be written in a format of AAA:DDD, where AAA is the main memory piece in which we look and DDD the displacement into that piece that leads us to the specific memory place we try to reach. The data used by an assembly program is stored into the Data Segment, whose beginning memory address is stored into the ‘ds’ register. If you want to go ‘5’ places (i.e. bits) into the data segment, just write ds:5, for example. Remember that things are highly dependable on the assembly language you use, which in turn has been developed for a very specific processor. So again: read the manual! It will solve many of your questions! Most 8088-based processors have some commands (called ‘interrupts’ because when they are executed, they interrupt the normal operation of the processor to do something else) already stored in them, which the assembly programmer can utilize by using the ‘int’ command. Please read the manual on how to do that…The purpose of this text is to show you the main underlying logic of programming so that you are not intimidated by it and not teach you programming techniques.

High Level Language programming

If you want to program in a high level language (HLL) that is object-oriented, then things are much simpler: just read the language manual, learn how you can create and use objects in that language and then…develop! Developing programs in a high level language means that you can write your source code into more elegant style, using more simple and intuitive sentences, while taking advantage of already existing power of the language itself. When you write a program into an HLL you write one command and the language takes care of the 100 steps required to execute that command into the processor. This gives the programmers more freedom to concentrate on what is really important in programming: the program’s underlying logic, its structure its algorithm. The first thing one developer has to do is think about how the program’s algorithm will work. If the design phase is perfect, then the program has a high chance of satisfying its purpose: cover the needs of its users – nothing more, nothing less. If you fail in the design, then – no matter how good your programming skills are – your program will certainly fail! Remember that.

Object-Oriented programming

But how do you create and use objects? First, you have to declare the class of the object. For example, if you want to create an object called ‘Blue Calculator’, you must first create and declare a class of objects called Calculator. Define the parameters of that class: the variables it will be using (i.e. the color of the calculator, the numbers which the user will enter in the calculator by pressing the buttons + the result that the calculator will print on its screen) and the methods (or functions) that the calculator will utilize in order to reach the result (i.e. functions for adding numbers, subtracting number etc).The definition of that class will have the following scheme (independent of what the programming language you use may be):
class Calculator
{
// Variables
Number_type number1;
Number_type number2;
Number_type Result;
Color_Type Calculator_Color;
// Methods
Function Add(number1, number2)
{
Print “The result is:”, (number1 + number2);
}
Function Sutract(number1, number2)
{
Print “The result is:”, (number1 – number2);
}
} // End of class definition
Generic sample code of class declaration (refer to the programming language manual for specific instructions on how to do that)
After you have properly declared your class of objects, you can create as many objects of that class you like and use them in your program.
For example you can create a new blue color calculator by writing a command that could look something like that:
Calculator my_calculator = new Calculator(Blue);
You can then use the member-variables and member-functions of the calculator with commands like:
Integer no1 = 2;
Integer no2 = 7;
Print “Result = ”, my_calculator(Add(no1, no2));
// this should print ‘9’ in the screen
my_calculator.number1 = 20;
Print “Result = ”, my_calculator(Add(my_calculator.number1, no2));
// this should print ‘27’ in the screen
The specific commands again depend on the programming language you use, but you get the meaning. It is all too easy:Declare class => Create new object of that class => Manipulate / define parameters of the new object => Use member functions of that object to generate the result they are designed to generate.It may be difficult for you to grasp, but ALL programming in ANY language (C++, C#, Visual Basic, Java etc) are based on that logic. What is more, the languages themselves have some ready-made classes that you can use to develop your programs! For example, Visual C++ in the new Microsoft Visual Studio has a stored class for Buttons. To add a button to your application, you just write:
Button my_button = new Button();
my_button.color = Blue;
You don’t have to reinvent the wheel! That simple (and I think you understand what the second command does, without telling you…)! I keep repeating myself, in order for you to stop fearing the unknown realm of programming and just…start programming! The ready-made classes (or even simple functions) are usually stored in packets called ‘libraries’. Add the library you want in your program and them just use any class / function it contains.

Things to remember

This is the main underlying logic of all programming languages nowadays, in the year 2008. And probably for the years to come. Some languages are different than others, without any significant impact on the way you have to program. For example the programming language C is more primitive that HLLs (it stands somewhere in the middle between Assembly and HLLs) and uses mainly functions, not classes. Just open the manual of the language you prefer, read where and with which commands you declare classes in that language and do it! There may be differences from language to language (eg. ‘packages’ in Java, ‘namespaces’ in C++ 8.0 denoting large collections of ready-made classed you can add to your program etc), but the meaning is the same! EXACTLY THE SAME!That was the programming part. The EASY part.The MOST IMPORTANT however part of programming is also the difficult one: the part of designing the program to function properly, to serve the user’s needs. You must FIRST design the algorithm and the user interface of your program in plain paper, before you even open the computer! Only properly designed programs with good working algorithms behind them can be successful! Remember that!
Go out there, THINK of your program, DESIGN it in simple graphs and words on paper and then do the easy part! No matter how much the languages change, the fact that cleverly designed programs prevail will remain the same…

Why do people still use old computers

The software and computer community has relied on the increasing computing strength of the new processors for more than it should to. As a result software developers did not care about writing efficient code – they just wrote programs, then added new features, then added some more new features without checking how they interacted with the previous ones, then added some new features again, without never trying to optimize the whole program again, without caring about memory leaks, performance problems… After all, why care, since the new Intel or AMD processor could handle the new bigger (and slower) program? As a result many programs nowadays have become huge collections of code lines with 50-70% redundant and useless (or even just error-generating) code.

Commodore 64 initial screen
There was a time when computer owners trying to write programs had to use small variables in order to save memory space. There was a time when developers had to optimize their code in order to use every bit available. Microchess developed for Commodore machines is a perfect example of efficient programming. Getting the computer to play chess with a program just some bytes long, when compared to chess programs today many MEGAbytes long, seems like plain magic for people who are used to just drag-and-drop buttons to create monster programs doing nothing.
That is why every serious software developer should buy a Commodore 128 (or any other old machine that can be programmed in BASIC, assembly, machine language or any other language), use it, develop programs for it, learn how to write correct, working, efficient and simple code!
When one understands that 3 GHz computers are on principle 1 MHz Commodore 128 computers with enhanced GEOS (graphics based operating system developed for C128), then he would have made a giant leap (for him, not for mankind).
He who forgets where he came from, he is lost and cannot go anywhere. No one should forget from where software development started…

Is an old computer really "old"?

This is a weird question. Why should we care at all? Well, we should care if we are to understand the true nature of computers. If we know what are the "true" changes that took place from Commodore to Pentium, wouldn't we be in a better place to understand computers?
The answer to that question is even weirder: A computer like Commodore is NOT really "old"!! But how can that be the case? Don't we now have Graphical User Interface OS? Don't we now have multitasking systems? Don't we now have computers with the ability to connect to high speed Internet via Ethernet cables? What does Commodore has to do with that at all?!?!? Well, the answer is: it simply can do all of the above!!!
There are multitasking OS for Commodore with GUI (yes, including windows and mouse support). Today a Commodore user CAN connect to the Internet via Ethernet! Today a Commodore user can set up a server based on his 64 KB decades-old computer!!! The illustrations below are characteristic.

How to create a web server out of your Commodore

Setting up a web server with your Commodore is not so impossible as you might think it would be. The basic steps are listed below, along with respective photos.
1. Get a Commodore computer.
I own two (2) Commodore 128 and one (1) Commodore 16 computers. For the web server I used one of the two Commodore 128 (however a Commodore 64 is most common in similar servers on the net).

One of the Commodore systems I use. The joystic is used as mouse in the Contiki OS. [Click on the image to enlarge]
2. Buy the hardware required to connect Commodore to the Internet.
A standard C64/128 modem will do the trick, but if you want to connect to your ADSL line then you should buy something like the RR-Net add-on (which sits on the MMC Replay add-on).


The MMC Replay device with the RR-Net add-on for connection to the Internet via Ethernet. [Click on the image to enlarge]
You can have a look at the "Stores to buy new hardware for your Commodore" at the end of the article for indicative stores to buy the abovementioned hardware.
3. Get the Contiki OS and configure RR-Net
You can download the Contiki Commodore version for free from the Internet. Put that OS into a flash card and into MMC Replay. Then create a disk image of the OS in a good old one 5 1/4'' diskette. Re-boot the computer and LOAD "*",8,1 the Contiki OS from the diskette.
After you do that, configure the internal IP of the RR-Net device (I have configured it to 192.168.2.64).

The portal of Kakos as shown in the web browser of the Contiki OS in the Commodore 128. [Click on the image to enlarge]
4. Enable the web server
Go into the Directory of Contiki and enable the Web Server by clicking on the icon shown below.

Some of the programs a Commodore user can use in the Contiki OS. Notice the Web Server... [Click on the image to enlarge]
5. Set the virtual server and you are ready!
All you now have to do is to configure your ADSL router so as to make the server visible from the public Internet! Just go to the administrator's console and set the IP you have selected for your Commodore as virtual server. Loo at your router's manual for instructions on how to do that.
Set up your ADSL router for making your Commodore 64 server visible in the Internet [Click on the image to enlarge]

Haven't you wondered how hackers that are in jail for years with no access to any computer, can catch up and get back into "business" almost the minute they enter their house again? It is not because they are super-brains. It is because the technology of computers does not actually change radically, if at all! The same 010101 logic still applies and if you know that underlying logic it is easy to do anything with some reading and experimenting. As long as you have enough time, willingness to experiment and lack of "fear not to break something" literally everything is possible...

Links for further searching

There are many links out there that contain lots of data ready to be read. Ba patient, look for what you search for through all possible channels, ask the older ones, backup your data and experiment on your computer. Knowledge is out there for you to discover!
Tools to develop new programs in Commodore BASIC
Stores to buy new hardware for your Commodore:
News 2010-11: Commodore USA company has resolved the issues with Commodore brand licensing and will soon release the new Commodore computer! A Commodore for the new era!
Happy coding!
And do not forget: he who doesn't experiment, doesn't learn!

Related Posts Plugin for WordPress, Blogger...