Sunday, September 16, 2012

MS-DOS Explorer

Year 2003 was the last year of my masters in computers. I was very excited because after so many theory papers, finally we were suppose to develop something as our final year projects. MICI, our study center, had posted a list of commonly developed projects such as XYZ Management System, writing some kinda shell scripts for UNIX or making a simple user interface in Oracle forms. It was a long list with all sorts of conventional projects. Visual Basic 6.0 with Oracle back-end was so popular among students. Nobody cared whether an enterprise database like Oracle is actually required for the kind of application they are building. Even I was part of this herd behavior in the final year of my bachelor degree, I made 'Store Management System' in Visual Basic 6.0 and Oracle 8 Personal Edition, though I made it a little more complex to make it stand out from other projects. 2-tier 3-layered using an in-process and an out-process component. It became quite popular and students kept submitting it for years (with little modifications of course) as their final year project, until the combination became obsolete and Visual Basic 6.0 was no longer a preferred development language. .NET era had started. There were some of my friends who had developed or purchased Java projects. Java projects were hard to configure and run and even more harder to make changes to them basically because an IDE (Integrated Development Environment) such as Visual Studio was missing. There were a few I was familiar with such as Borland Java Builder and Tek-Tool's Kawa but these were no match for Visual Studio's speed and features.

I wanted to do something different this time, something nobody had thought of before. One day while I was in the computer lab, managing my files using the DIR, COPY and MOVE dos commands, I felt the need of having a Windows Explorer like application for MS-DOS. 'browser' I named it and my project was decided. It was a purely different idea than the rest of the class. Nobody had ever thought of making a user-interface for MS-DOS. Turbo-C IDE was an example of user-interface in MS-DOS and who can forget popular programs such as 'Nash Format' which could even format a *bad* floppy and make it usable. A user-interface in C, sounded scary. "Are you going to use windows api?", "Which database are you going to use?", "Will there be mouse support" were some of the questions my fellow students would ask. I did not have satisfactory answers to their questions, all I knew was that it is possible and I will do it. Why I was so confident about completing it was because of a book that I bought purely by chance. When I was in Lucknow couple of years back, I asked my father if he could get me a book on Internet on his way home from office (I told him the author and book name). I got it in the evening but it wasn't as good as I expected so I thought I'll return it back and get another one. I went to the Bhoothnath market in the evening itself and started searching for something I could buy in replacement for the Internet book. Strange enough, I could not find even a single book worth buying. It was getting late and the shop had to close so my father asked me to hurry and select something. Just then a book with the word "MSDOS" caught my eye. It was Ray Duncan's Advanced MSDOS Programming. I turned a few pages and it seemed all Greek to me but because I was familiar with MSDOS I decided to buy it anyway. And that's how I got introduced to the magical world of interrupts, TSRs (Terminate and Stay Resident programs) and assembly language programming.


I started MSDOS Explorer by designing the application and soon the whole structure became gigantic with more than thirty different classes. There were classes for each and every user-interface element, from menu, status bar to dialog boxes. I wrote my own classes to handle graphics - yes the 80x25 blocks by directly writing to the video memory buffer (working around the magical video memory address 0xB0008000L). The best thing about this project apart from the UI stuff was that it did multi-processing. Even though the support was fragile (because of all the MSDOS Interrupt Handling) it worked flawlessly if the provided function did simple tasks such as updating the clock or running a ticker. Multi-processing in this context was to schedule multiple functions to run simultaneously along with our main program loop. The support was added by chaining the Clock Tick Interrupt (0x1C) to call our function whenever an interrupt is generated. The function in turn would call other methods such as to update the clock on screen or advance the trigger from it's function list. The downside was that these scheduled functions needs to be very simple and if any one of these failed, it would take the whole application down and there was no way to recover from it. MSDOS Explorer had two scheduled functions, one to update the clock at bottom right corner of screen and the other to run the ticker on top right (which would scroll my name).


The whole class hierarchy was *inspired* by the MFC (Microsoft Foundation Classes) model. A CObject was at the top and then CWnd, CView, CListView, CMenu and classes for different controls, dialogs and utility functions. It took me six months to get the first version out. I wanted to see all my C++ knowledge in action, all the OOP stuff and data structures. For the file list, I used a doubly linked-list of structures and used insertion sort to sort the list. Sorting was required on every column (file name, size, modified etc) and its this sort feature that made me publish my first article in Developer IQ magazine. It was called Using trees with custom data types


One of the feature of MSDOS Explorer that I personally liked very much was the Snake screensaver. If you've worked on Novell Netware systems you probably know what I am talking about. The Novell Netware snake was a little different from the one I implemented in the way that it would always move on an empty black screen and it kept growing as the server load increased. Its tail would grow longer and longer. Mine (see screenshot below) would take a memory screenshot of the current screen, black out the whole screen and would reveal the area underneath it as it moved. After the snake was popular, I added Garbage and Bars screensavers to the application. Unfortunately, I do not have the new executable which had these new screensavers, the "About MSDOS Explorer" screen and in particular the "About Developer" screen. I do have the source code which I wish to re-compile someday and update this post with some more screen shots. I say "someday" because the source code is in pieces and not directly compilable.



When I thought of writing about MSDOS Explorer my only concern was how to run it and take screenshots of different features. One option was to boot MSDOS on my old laptop, run MSDOS Explorer on it and take pictures using a camera. The other option was to run MSDOS as a virtual machine using tools like VMWare Player and take snapshot of the window. This seemed better as I can avoid switching between systems and also because I wanted to restart on this project and do a little programming in TurboC++ 3.0. I have fond memories of that MSDOS based IDE which also supported mouse operations (only a few people used it though) apart from great looking windows, menus and dialog boxes. I won't be wrong in saying that the inspiration for developing a user interface in MSDOS came from this IDE. So ya, I choose the second option to run MSDOS as a virtual machine.

Luckily, MSDOS 6.22 was available in subscriber downloads section inside my MSDN account. I downloaded the executable but it was of no use (though later I learned that files can be packed into an ISO archive using programs such as MagicISO) as VMWare needed an ISO file that it can read as CD to install the operating system. After a couple of minutes of Googling, I found MSDOS 6.22 ISO on AllBootDisks site. Downloaded it and created a new virtual machine from within VMWare Player specifying the path to the ISO file.




Here's a really interesting video while I was searching for different stuff related to this article. The video dates back to 1980s and is a promotional video for MSDOS 5.0.



So that was it. I enjoyed writing this one, it took me back to the old golden memories of FAR and NEAR pointers when even hundred MBs of memory was luxury. It feels so good to think about that period of life. In my next one, I'll talk about the Store Management System project. Till then - keep experimenting.


No comments:

We are Robots

I've always been fascinated by UFOs ( Unidentified Flying Objects ) and stories related to these alien objects. The first story that I ...