Wednesday, August 5, 2015

Learning (Ancient) C

Today and yesterday I made efforts to learn C so that I could modify NetKeen, Lemm's competitive multiplayer adaptation of Commander Keen. I would have downloaded Clang or another modern C compiler, but NetKeen requires features only held by very old compilers: the ability to compile inline assembler into the final executable and target real-mode 16-bit DOS. Those requirements led me to use Borland C++ 5.02, an old IDE for C and C++.

Now, Borland C++ 5.02 was built in a time when Windows 2000 was a fancy new OS. That meant that I wasn't going to get far with it on 64-bit Windows 8.1, so I had to make use of a Windows 95 virtual machine that I had sitting around. After some fiddling around with virtual CDs, I had Borland in Windows 95 successfully compile the original NetKeen source. (That virtual machine's resolution is locked at 640x480; there doesn't seem to be a way to change it with VirtualBox as the hypervisor. Oh, and Windows 95 really likes to open new Explorer windows when I navigate to other folders. Thanks to those two facts, using the VM is kind of painful.)

My original means of transferring files between host and guest was to create a FAT-formatted VHD and attach it to the VM as a separate hard drive. To move a file one way or the other, I shut down the VM, mounted the VHD on my real machine, put files on it or copied them off, dismounted the VHD, and rebooted the VM. It was painful, so I was very happy after I remembered how to enable TCP/IP and file sharing in Windows 95. Now I can just navigate to the VM's shared folder from my host's Explorer and copy files as appropriate.

Editing of source files was initially done by working in Notepad++ and then copying the files onto the VHD. When I broke the build (which happened a few times, since I had literally never any non-trivial C before yesterday), I had to tweak files using Borland's IDE in the VM, which was painful for reasons already explained. Oh, and this is a version of C that splits each method into a declaration section and an action section, so no variables can be declared after normal calls have been made. It's like COBOL! Once the file sharing was set up, I just used Notepad++ directly on the shared files and only used Borland to compile.

It was a saga, but I did finally get some modifications done. In my customized NetKeen, many more hits are required to attain a stun, so strategy and tactics are required. Running out of ammo is always a real possibility! I also changed the penalty for getting stunned by non-player sources to award points to others rather than taking them away from the victim. (That change strongly discourages suicide to regain starting health.)

No comments:

Post a Comment