News — source-code sizes of VideoStudio, VSMP, QHTV and QHTE

Tagan News #02

News

Well, what can happen in less than a week? The mail has only just started arriving, and everyone has the same question: “Have you recovered from New Year yet?” And what am I supposed to tell them? I didn’t even start... Our New Year’s crew was a light-drinking bunch (not in the sense of “however much they drink, it’s never enough” :), so over the course of the night we polished off a mere two bottles of champagne and four bottles of soda :) In the morning, they were hair-of-the-dogging with Cahors, which I heroically refused—I’d gone to bed at 5 a.m., and now they wanted me drinking at 9! I wasn’t even properly awake yet, and they were already pouring me a glass. So I treated myself with some tea :] I got home, and there it was—the banquet continued. By then, having recovered, I joined the ranks of my relatives in full.

All right, enough about drinking; time to talk about the Speccy. Recently I was looking through some source code and discovered an interesting fact:

VideoStudio’s source code is 7,500 lines long.
VSMP’s source code is 5,250 lines long.
QHTV’s source code is 10,850 lines long.
QHTE’s source code is 7,650 lines long.

If you take into account that about 4,500 lines in all these programs are shared (the standard shell, which I wrote back in 1999), we can rank these programs by how “fancy” they are. VideoStudio is nowhere near the top, despite what you might expect...

Another fact: the source code for a more or less functional ChAOS prototype is 13,550 lines long. And it shares no more than 500 lines with the programs mentioned above—various mathematical routines that I carry over from one program to another.

From this, we can conclude that a program’s source-code size depends on its complexity. Specifically, the working version of ChAOS will weigh in at around 100,000 lines (one hundred thousand).

Poking around in such a gigantic source file is Bill Gates’ job in programmer hell :] So I made a decision, one I’d borrowed from the PC: split the program into modules, each of which is debugged and tested for every possible situation. To implement this idea, I wrote an assembler file consisting of a set of macros and code to generate everything necessary. To create a module, we do the following:

INCLUDE "MODULE";contains all the macros

...;here we configure the macros, their addresses, etc.
MODULESTART;start of module

PUBLIC "Procedure1",FUNCTION;declare an entry point
Procedure1

PUBLIC "Procedure2",FUNCTION;another one
Procedure2

MODULEEND;module finished

MAKEHEADER;the cool thing

Here’s the trick. Three data blocks are created in memory: a block containing the symbolic names of entry points and variables (which are also declared using the PUBLIC directive), a block containing the address-configuration table, and the actual code block. When the program starts, the code generated by the macro links all these blocks together, adds a header, and writes the whole thing to disk.

So how do we use this? Fair question. Let’s say we have a set of modules for our program. We need to turn them into a single code block. The linker loads their code blocks one after another, and adjusts all the addresses to match their current locations as it goes. It gets the information it needs from the address-configuration table. Another question comes up: what if the modules call each other’s functions? Well, that’s a real pain in the ass, of course, but it can be done. The macro commented as “the cool thing” creates a source file in a page (during compilation (!)) containing lines like these:

Procedure1=ModuleStart+#0000
Procedure2=ModuleStart+#0123
...

News

That is, all the entry points. Now, hopefully, it’s clear what the table of symbolic names for entry points is for?

If anyone’s interested in all this crap, I can send you the file with the macros and an example, or publish it in the paper.

Share your thoughts about the article