CGI Programming Tutorial
Graphic Counter Language NEW
If you are interested in assembly language programming for Windows 95, download crc32.zip from here. It illustrates how to write a dynamic link library in assembly language. (Unix version also available.)
Or download clockwise.zip which contains a DLL (and ASM code) to determine whether a polygon is being drawn clockwise or counter-clockwise (quite important when interpreting PostScript fonts).
With just slight modifications to the above DLL, we have convex.zip with a DLL to determine whether a polygon is convex or concave. As usual, ASM source is included.
Examine the source code in polyarea.zip to see how to calculate the area of a polygon with just a few math coprocessor instructions.
To get sample code for a full Windows 95 program in assembly language, download rand.zip. It contains the code and executables for two similar but different programs, now in version 126.96.36.199. This code teaches how to use the timer, process mouse input, create a memory bitmap, and copy a bitmap to Windows clipboard.
Talking of copying a bitmap to the clipboard... Windows 95 comes with no utility to empty the clipboard. This wastes precious memory! Luckily, you can download ClipWipe, a powerful assembly language program to wipe the clipboard clean, i.e., to empty it and free the memory it uses. And, of course, the source code is included.
Do you know how to open the default web browser from your program and send it to a web page of your choice? If not, download whizkid.zip to see how simple it is! This very simple program does nothing but sends your browser to this site. I have it on my Windows 95 desktop so I can get here anytime I want. Do the same, or modify it to get you to other sites. And, of course, incorporate it into your own programs as needed.
I have posted several random rectangles sample programs here, using a rather primitive random number generator. I have now written the Whiz Kid Technomagic Random Number Generator which produces a sequence of 32-bit pseudo-random numbers. The sequence is very long. In fact, you would have to have it generate more than half a trillion pseudo-random numbers before the sequence starts repeating. This is a DLL, and, of course, the source code is included.
Verithmetics, version 1.00, consists of two modules, VeriAdd and VeriSub. These modules produce Verilog source code for adders and subtractors of any size. Version 1.00 is very simple, version 2.00 (still in the making) will have numerous optimization options, and will contain additional modules.
Nothing requires the power of assembly language more than computer graphics. After all, when applying filters to an image that is 1,000 pixels wide and 1,000 pixels tall, you may need to run the filter routines million times. And since assembly language programs are considerably faster than programs written in other languages, the difference in speed of image filtering is mind boggling.
Yet, the common trend in graphics programming is to use not just high-level languages, such as C, but very high-level languages, such as C++ and Visual Basic.
Why? Is it because that kind of programming is hard in assembly language? Certainly not!
I have written a number of Photoshop plug-ins, each and every one in assembly language, so I know it is no harder than doing it in any other language.
I posted these plug-ins in Red Prince Atelier, many with the full assembly language source code. Feel free to visit there and download them.
One of them, Red Prince Noise Generator, is an example of the use of my random number generator you read about earlier on this page.
Another one, Red Prince Whitewash is a functional equivalent of Etsuro Endo’s Eliminate White filter, which he wrote in Filter Factory. I needed it, but it would not work on anything but small images on mu system with its 8 Meg of RAM. So, I wrote one in assembly language, and it works on images of any size.
Then there is Red Prince Flips ’n Rolls, which, well, flips and rolls different color channels. This is probably a prime example of how assembly language is better than anything else. This, by the way, was the first Photoshop plug-in I made available for download.
And if computer graphics are what you love, don’t miss my Red Prince Pixie Dust, a large collection of many Photoshop filters, entirely in assembly language. This one is a major project, result of several years of work, so it does not include the source code. But it shows you how much functionality you can pack into a small program if, and only if, you use assembly language.
Oh, and, by the way, I now have a section called Photoshop Plug-In of the Week. Every week I post a new plug-in (yes, of course it is in assembly language). And delete the one from the week before. So if you miss a week, well, it’s gone...
I have mentioned in e-mail to several people that my next project was to show how to program OLE/COM in assembly language. When I first started working on it, I was quite excited: The idea behind OLE/COM is good. But the more I worked on it, the clearer it became that Microsoft’s implementation of the idea was an abysmal failure. It is BAAAD!!! Now I believe OLE/COM stands for Obviously Lacking Expertise/Criminally Obnoxious Mind. It is extremely complex, and introduces so much overhead that if you really want to go for it, you may as well write it in Visual Basic!
The sample code I wrote was to convert RGB colors to what I call RBY colors (short for r-y, b-y, y), a very straightforward thing to do in assembly language. But just adding the OLE/COM overhead increased the size of every procedure 4-5 times. That is simply ridiculous. I then decided to actively axe OLE/COM and stick with straight DLLs. I suggest you do the same.
Indeed, the more I think of OLE/COM, the more clearly I see it as an attempt to defy a fundemental law of nature: Panta Rei! Even Microsoft cannot do that. Some time ago, I developed my own programming system which I named Device Oriented Programming Environment (or DOPE for short). When I first looked at OLE/COM, I was under the impression it was implementing similar ideas as DOPE, which is why I was so excited about it. But no, the two stand at the opposite ends of the spectrum. OLE/COM uses a hard macho approach, while DOPE is soft and flexible.
I am quite busy these days, but as soon as I can get to it, I will create a separate page explaining how DOPE works and, of course, I will include sample source code. I will add a guestbook to this site, so anyone can comment on DOPE, and anyone can read the comments as well.
I wish I could keep posting new things on the web all the time, but it is a hassle. So, I decided to start The Whizzine instead. It is a weekly ezine which I send to anyone who wants it. You can subscribe here. And, if you don't care for it, you can unsubscribe here as well.
If you do not have an assembler, try Netwide Assembler (NASM) 0.93. It will not assemble the sample code above (that was written for MASM), but it will get you started. And, unlike MASM, it will let you assemble your code for various platforms, including Windows and Linux. (Note: I did not write NASM, I am just making it available for download.)
Another free assembler is Specific Assembler (SpAsm). It assembles your source code directly to Windows PE executables. That is, it requires no linker. Also, I have seen a Usenet message according to which MASM is now available for free download as part of the Win98 DDK. According to this message, MASM will be in 98ddk\bin\win98\ml.exe after install. I have not verified this information since I do not feel like downloading an 18.5 MB file and since I do not have or want Windows 98...
Finally, if you want MASM with printed documentation, or you would rather have Borland Turbo Assembler, you can buy it online or from your favorite software store.
2,500 years ago, the Buddha suggested we should not accept something because everyone says it is true. Indeed, good memory is not cheap. And not everyone has the latest and the fastest microprocessor inside their computer.
Even if they did, Windows 95 is a multitasking system. Running several programs at the same time fills up available memory very fast. Whenever that happens (and it does happen a lot), Windows 95 starts swapping data between the memory and the hard disk. This process brings the system to a crawl. And it stays in a crawl even after the bulky programs finish executing. The only solution is to restart the computer.
Well, actually, there is another solution, a better one at that. But that solution is not in the hands of the user but of the programmer. The solution is assembly language programming.
It is a common myth that assembly language for Windows is an impossible task. And, to be honest, before Windows 95 it was not quite a myth: Programming for Windows 3.x in assembly language is indeed confusing and hard (albeit not impossible).
However, Windows 95 has changed it. Not only is assembly language easier in Windows 95 than it was in Windows 3.x, it is, in my opinion, even easier than it was under MS DOS.
No longer needs the assembly language programmer be concerned with various interrupts, memory segments, writing directly to the screen, or accessing extended memory. Windows 95 is a 32-bit system which uses a flat memory model.
Indeed, writing assembly language programs for Windows 95 is as easy as writing C programs, and easier than writing C++ programs. After all, the various dynamic link libraries that come with every copy of Windows 95 contain code for string formatting, input, output, various graphic routines, file handling, and much more. And they are easy to use: Just push the parameters on the stack and call the routine.
Yes, you may say, but what about object-oriented programming? Simple: OOP is not the language you use, it is an attitude. It is just as easy to write object-oriented programs in assembly language as in C++. Correction: It is easier. For starters, the assembly language programmer can encapsulate various routines in a number of dynamic link libraries much better than a C or C++ programmer. Writing too many DLL in C or C++ will link all the C start-up code to each and every one of them. And if the C/C++ programmer does not have any sense and links the C libraries with every DLL instead of using the DLL provided with his compiler, he can bring the system down to its knees with a single program.
But assembly language has no overhead. Not with dynamic link libraries, not with the main executable.
To see how easy it is to write small and fast, yet extremely powerful, dynamic link libraries in assembly language, download crc32.zip. The code is highly commented, so even a beginner can understand it. Besides, it will offer you a useful DLL for any time you need to use CRC-32 routines, whether from your assembly language or C/C++ programs.
It also illustrates how to write routines that can pass parameters in registers for speed when called from assembly language programs, while making it possible to use the same routines with C/C++ and its convention of passing parameters on the stack.
Those of you who are not comfortable writing the WinMain and WinProc procedures in assembly language can still write those in C, and code everything else in assembly language dynamic link libraries. The crc32.zip contains two sample programs, one in assembly language and one in C, to illustrate how to do it.
In conclusion: If you are a Windows 95 programmer, you owe to yourself and to your custommers to learn the art of assembly language programming. I can only hope that my sample code will help you get started.
Clicking on any of these books will get you to an online bookstore. I am not trying to sell you these books, nor do I try to tell you where you should buy them if you want to. I am just offering the links as a convenience should you want to take advantage of it. I chose these links because they offer good discounts, and ship anywhere, not just the US.
Teach Yourself SQL in 24 Hours, by Ronald R. Plew and Ryan K. Stephens. I have decided to put a database of shareware programs on my web site. I know there are many such databases available, but I want to try a different approach, where a shareware author can enter the information, and it is immediately visible on the site. It may not work if people abuse it, but I decided to give it a try. (I'll let you know when it is ready, and where.)
Now, I know the theory of databases, but I have never really used them. Generally, I create my own file format. After all, I’m a speed freak. But for a project of this magnitude, I decided to look into available database software. It turns out that my web host offers MySQL at no extra charge, and the data in it does not count against my disk usage. Not bad! Except... I have never used SQL in my life. I’ve heard about it, mind you, but never used it.
So, off to the bookstore I went. I live in a small town, and the only bookstore in town had nothing about SQL or any other database. Luckily, the book seller on duty was a computer science student at the local technical college. He suggested the local music store, of all places.
He was right! They had one and only one book on SQL, but a what a book it was! It promised to teach me SQL in 24 hours, but it took less. The book is clearly written, uses a good order of presenting information, and has practical examples for everything. Now, I’m ready to start building my database.
Windows Annoyances, by David A. Karp. This book is the ultimate problem solver for Windows 95 and NT. I found it in a bookstore by mere coincidence. At the time, my copy of Windows would not allow me to save my Internet access password (the option was grayed out). The manufacturer of the computer could not fix it; the biggest computer company in my town could not fix it. After I bought this book, I fixed it in two minutes. And, of course, I was able to fix many other annoyances.
Note: If you use Windows 98, you may prefer Windows 98 Annoyances.
Computer Graphics Handbook, by Michael E. Mortenson. This is a letter-sized book of pure math and geometry pertaining to computer graphics. I stumbled on it several years ago at Carnegie Library in Pittsburgh. I do not know how I could have lived without it. It does not go into much theory: Each page offers a solution to a specific problem, ranging from vector addition, through Bézier curves, polygons and polyhedra, hidden surfaces, to reflection and light. If you work with computer graphics, you will also find his Geometric Transformations a sine qua non.
Application-Specific Integrated Circuits, by Michael John Sebastian Smith. Since you are reading this web page, chances are you are a programmer concerned with speeding up your programs by using assembly language. But what do you do when even assembly language is not fast enough? Only one thing is faster than a well written assembly language program: dedicated hardware.
Of course, if you specialize in designing software, you may think trying to design an ASIC (application-specific integrated circuit) is way out of your league. Until now, you only had two realistic options: Going back to school for an electronics engineering degree or hiring a hardware expert. Either option is very expensive (and the first one would take several years). Luckily, now you have an alternative: Read Dr. Smith’s book and learn how to do it yourself!
I have to confess one thing: When reading most books on this topic, I have the impression they are written in a foreign tongue (my degree is not in electronics—I have a master’s degree in psychology). But Dr. Smith’s book reads like a novel. I can understand everything he has written, even though the book is more than 1000 pages long! Dr. Smith teaches at the University of Hawaii, and quite obviously is a very good teacher. He used to work for IBM, at its T.J. Watson Research Center. So he also knows what he is talking about.
But more important than the author’s credentials is the fact that he has written a book you need to read. Once you have read it, you will understand how to design ASIC on your own. And you will have a valuable reference book you will be coming back to over and over, for the rest of your life. Even if you do not want to turn your software into hardware, this book will make you a better programmer.
Have I made myself clear? This is a book everyone who deals with any aspect of computing needs to read. Unfortunately, I do have to caution you about one thing: If your friends see this book in your hands, they will want to borrow it. And they will not want to return it. It is that good.
Make Your Site Sell, by Ken Evoy MD. Unlike the rest of the books reviewed here, this one is an e-book. That is, it is not printed on paper but comes as a series of PDF files. I generally do not review e-books. I have good reasons for it: They tend to be overpriced to start with. Since anyone can put an e-book together, they tend to be poorly edited, or rather not edited at all. They tend to be typeset like traditional books, and that makes them very hard to read on computer screen. Most importantly, when I read them, I tend to say over and over: “Tell me something I do not know!”
It was very refreshing when I stumbled on this one. At $25 Canadian (about $17 US), this book is underpriced. It is packed with useful information for webmasters, and for everyone who wants to run a business on the Internet successfully. It is about the only e-book I have seen that allows you to download sample chapters so you can “browse” through it as you would in a bookstore. For example, one such sample chapter tells you how to get listed on Yahoo!
Anyway, to make a long story short, the author discusses three steps any web business has to take to succeed. It is clear that the author has not just read similar books and rewritten them. On the contrary, he has run a successful web business and is now describing all the mistakes he made at first, and all the right moves he has made later. Just his insights on how to get top listing in search engines is worth reading his book.
This is one e-book I have to take seriously. Take a look at it, and you will too.
Acting Professionally, by Robert Cohen. (Well, I told you I had varied interests.) Written by the Chairman of the drama department at the University of California, Irvine, this is a no-nonsense guide to becoming a professional actor on Broadway, in Hollywood, or anywhere else in the US. It is a small book, but if you want to become a professional actor, it is worth its weight in gold. Don’t leave home without it!
One of the best kept secrets in the world of computers is 4DOS, an excellent shareware replacement for COMMAND.COM by JP Software. Although it has been around for years, I usually meet with a blank face when I mention it to most computer professionals.
4DOS works equally well on the older DOS systems and the latest Windows systems. It does everything COMMAND.COM does, plus everything COMMAND.COM should do but does not do.
One of its many features is built-in LIST command. Not only does it display any file (binary or text), it can also be used to pipe output of other programs as its input.
For example, instead of typing “dir/p” you can enter “dir|list”. Rather than seeing one screenful of directory listing at a time, you will get the entire listing in a scrollable window, so you can page-up and page-down through it.
If you are a programmer, you will find this feature quite useful when compiling or assembling programs. How often does it happen that you type “nmake” just to watch a list of error messages scrolling on the screen so fast you cannot possibly read any of them?
With COMMAND.COM your best bet is to redirect the output of nmake to a file, then examine it with a text editor, and then delete it. With 4DOS, you just enter “nmake|&list” and, voilà, you page up and down through all the error messages at your own pace and convenience. (The “&” part of the command will make sure you pipe both stdin and stderr to LIST.)
So, where do you get this treasure? Directly form the JP Software web site.
Positively, the best disk drive utility is SpinRite, now in version 5.0, from Gibson Research Corporation. Written entirely in assembly language by Steve Gibson, this program will repair your disk drives (hard disk, floppy disk, Zip drive, you name it!). Most likely it will also recover lost data.
But you do not have to wait till your drive crashes or you lose some data. SpinRite is also perfect for the prevention of disk problems. It works on several levels: The simplest one will just test your drive for possible future problems. The highest one will reformat your disk while keeping your data intact, it will recover data from bad sectors and move it to good ones. It can even restore formally bad sectors and return them to good use.
If you think I am not serious, consider this: Two days after I bought my copy of SpinRite and used it to refresh my hard disk, my system was victimized by an electric surge which destroyed my modem, my serial ports, my sound card, and did other damage to my system. But my hard disk survived without a glitch! Thank you, Steve!!!
In the last few years the Internet has grown to such proportions it is virtually impossible to get your own point across. Unless you have developed your writing skills, chances are even if people find your web site or subscribe to your ezine or any other form of ecommunication, they will spend very little time reading what you have written but will move on quickly.
The “big” sites hire expensive professional writers to get their point through fast. Small guys like you and me have hard time competing with them. What can we do?
Luckily, some of us have a way with words. Others are not so lucky. Certainly, each and every one of us can improve our own writing skills. I have recently discovered a nice 5-day course called The Netwriting Masters. The course is free, with no strings attached, and available by email to anyone who wants it. To receive the course, all you have to do is send a blank email to firstname.lastname@example.org. The first lesson is delivered immediately, the rest of them one each day for five days.
If you run your own web site on a budget, have Web Site Garage tune it up for you. While they are hoping you will sign up with them as a paying custommer, this web site will automatically and thoroughly analyze any individual web page for free. It will check your HTML syntax, your spelling, your META tags, and rate your page on the scale from excellent to poor,
It will also offer suggestions on how you can improve your web page. In addition, it will register (if you want) your web page with eight web search engines. All that for free.
Links to other sites on the Web:
BFM Computing, run by a Zen Buddhist monk
Don Lancaster’s Guru’s Lair
History of computers
Paul Bourke's site, packed with algorithms and other information
Jason Galanter’s page. Contains lots of interesting information and links.
Microsoft Developers Network. Offers free information and SDK downloads. A must for every programmer!
Art of Assembly Language. A thorough textbook/reference on assembly language available for free download.
Broken Bone Playhouse. My theatre page.
Windows 95 shareware
This page brought to you by G. Adam Stanislav, independent computer consultant and programmer, located in Rhinelander, Wisconsin.For comments send me e-mail: email@example.com
© 1997 G. Adam Stanislav
For best enjoyment of this web site, download and install the Augie font, either in TrueType or Postscript. It is the font I used to design the Whiz Kid Technomagic logo above.