11 Mar

Software Improvements That Made Hardware Better

Here is a 100% subjective list of remarkable software that made existing hardware better, more useful or simply extended its shelf life without any hardware modifications, purchases or upgrades.

The Playstation 3 Supercomputer

As already reported by millions of blogs since 2006, a Playstation 3 seems to find use in a scientific project than in a living room. A cluster of a dozen or so PS3’s provides more computational prowess for scientific research than is available by the usual means for the same amount of money. In fact, there are resellers specialized in selling PS3 clusters. As a collective supercomputer, Playstation 3 users dominate the Folding@home project.

Basically, this means even if the PS3 finally bombed as a video game console, the unsold units could find purposeful life as a cheap supercomputer. This easily meets the criteria for making existing hardware more useful via software.

C64 fast loaders

Back in the 1980s, having a quick few minutes game of, say, Pitstop 2 (OK, I know any respectable player would not settle for a few minutes game of this gem) on the Commodore 64 was a relatively impossible task thanks to long loading times. You could have to wait minutes for a game to load — when loading from a cassette or from a floppy. Some loader routines even had a tiny game built-in to waste your time with while the game loaded in the background. To experience this ritual, watch the below video before proceeding to the next paragraph. Do not skip forward. It’ll make you respect fast loaders more.

Then, someone realized that the original routines for transferring data from the disk drive were in fact crap and wrote much more efficient routines. Thus, fast loaders were born. For example, the disk turbo on Action Replay VI reduced loading times tenfold (while the mentioned turbo was delivered on a cartridge, it was still purely a software affair — in fact the loader could be saved on disk from the cartridge). A game would load in a few seconds.

Subpixel rendering

With the advent of LCD screens, subpixel rendering has become commonplace. This is mostly thanks to ClearType, Microsoft’s implementation of subpixel rendering shipped with Windows XP. This technique implementable purely by software triples the vertical screen resolution. Kind of.

Subpixel rendering exploits the fact most displays have each screen pixel represented as set of a red, a green and a blue pixel (as you can remember from school, white consists of those three base colors). By slightly changing the color of neighboring RGB triplets, the human eye can be fooled to think a pixel is slightly towards the neighboring pixels (thanks to the fact our eyes sense color intensity much better than the actual shade of the color). Think of it as something similar to anti-aliasing.

This works best — or rather is more easily implemented by lazy programmers — on most LCD screens, thanks to the fact the triplet is usually arranged horizontally. A typical CRT screen doesn’t have a similar symmetric pixel geometry.

Alternative keyboard layouts

The QWERTY layout is the most common arrangement of keys on a keyboard. There are alternative layouts that are much faster for typing, as QWERTY was developed to slow down typists who were faster than the technology was back in the stone age. By ordering the keys in a different order, typing can be sped up because the fingers are closer to the keys that are used the most often.

A popular alternative layout is the Dvorak layout. A Dvorak keyboard can look intimidating a first (it looks like someone has vandalized a perfectly good keyboard) but in theory, it should be faster to type. It even takes into account that most people are right-handed — therefore the right hand should do most of the typing. Since it is the most common non-QWERTY layout, it is well supported. For example, Windows has shipped with it since Windows 95.

There is no single layout that was as good for any language as QWERTY is bad. The Dvorak layout has a downside that it is mainly for English — other languages have slightly different typing profile and thus have modified Dvorak layouts. For programmers and other people who frequently need special characters, there also exists a version of Dvorak.

The best potential feature of non-QWERTY layouts is the fact it is less likely you’ll injure yourself. Although, this is subject to debate considering a serious wrist injure comes from quite bad typing habits. People do however mention increased comfort when using e.g. Dvorak.

Turning a $60 router into a $600 router

Something comparable to the PS3 upgrade above, the hardware of some cheap routers can be better harnessed by changing the firmware. This is mostly because companies love to overprice their products (after all, a higher price is the only factor making some things “professional” — *cough* Vista). They simply sell a software downgraded version of a router with a lower price. Lifehacker explains in detail how to upgrade your router, in case it is suitable for the operation.

Also of note is that many wireless routers are capable of more transmitting power than they are allowed to. To put it short, the wireless connection does not work as reliably as it could. Even if the above firmware upgrade was not available for your router, it is very possible that there exists ways to increase the transmitting power. However, the legality of it is a gray area — the power is usually limited for a reason.

09 Mar

Dev Stories from the Past

A bit of nostalgy can never hurt anyone. To me, weird tales about old software are a source of inspiration — they are essentially war stories for nerds. Here are some cool software stories from the past told by the developers themselves.

Donkey Kong and Me

The aptly named DadHacker writes about his past at Atari Corp. and more specifically about his experiences on porting the Donkey Kong coin-op on Atari. Includes gory descriptions of 8-bit graphics modes.

… most of the game sources I saw in the consumer division were crap, just absolute garbage: almost no comments, no insight as to what was going on, just pages of LDA/STA/ADD and alphabet soup, and maybe the occasional label that was meaningful. But otherwise, totally unmaintainable code.

Sounds familiar…

Tim Follin Interview about Video Game Music

Here is a great video interview with Tim Follin, a composer of game music on the Commodore 64, Atari ST and many other platforms. Wikipedia has a surprisingly extensive biography but the below video has the same information told much better.

Be sure to watch the second part as well.

Macintosh Stories

The development of the Apple Macintosh is the source of many mythical stories. This site dedicated to Macintosh folklore contains probably most of them. I like the fact there is a lot of stories about both the people and the inner workings of the Mac.

Llamasoft

Jeff Minter is a legendary character with the distinctive style of his games. Personally, Minter is in my all time Top 5. One of my first memories about computers is not understanding Colourspace at all back when I was about 8. Below is a really interesting and funny presentation by the man itself including game footage from his old games (I think the presentation is promotion for his latest effort, Space Giraffe). He has written an extensive history of his company Llamasoft.

An Interview with Rob Northen

Rob Northen was responsible for copy protecting many games on the Amiga and Atari ST platforms. Considering publisher giants like Ocean, Microprose and US Gold used his services, I’d say a majority of games used a version of his protection. This interview gives some insight into how he came up with his software Copylock and how it worked.

09 Mar

Pointers? Pointers.

This is my attempt at demystifying pointers, a very useful concept available in C, C++ and other programming languages that do not lack balls. Java and PHP have references, a similar feature (C++ also has this) but pointers pretty much are the same thing and for some reason pointers seem ancient, complex or downright frightening to some (or, most).

Why I’m writing this is because I feel a lot of tutorials do not explain pointers as well as I’d like them to explain, considering they are useful and not some archaic curiosity from the 1970s. I originally expressed the concern over here. This tutorial, or introduction, is aimed at C and C++ people because Java doesn’t have pointers and because other languages are generally for wussies.

Note: This is a living tutorial, i.e. you can suggest things and I’ll make it better. I’m all for a good pointer tutorial.

What are pointers?

At first, let’s think about computers. A very basic computer has memory for the data and the code. In a programming language, a variable refers to a location in the memory. The location, referred by address, is something like a page number in a book. At the very least, a programming language automatically assigns these memory locations and acts as a directory for the book, allowing you to refer to the locations by the variable name instead of the page number.

In a programming language, pointer is a variable that contains the address. Simple as that. In most cases, a pointer contains an address of another variable. The pointer can then be used to read or change the contents of the referred variable.

How do I use pointers?

In C, using pointers is easy. To make a variable as a pointer to another variable of type A, you define the pointer to be of type A*.

A variable=42;
A* pointer_to_a_variable=&variable;
*pointer_to_a_variable=0;

& can be read as “address of”. * can be read as “contents of”. Try reading the above example like that and you should figure out what it does.

Here is the answer:

A variable=42;
A* pointer_to_a_variable=&variable; // a pointer to the above variable
*pointer_to_a_variable=0; // the contents of the variable referred are zeroed

When should I use pointers?

A pointer can be very useful in a variety of situations. The simplest use would be something like passing a reference to a variable as a function parameter and the function then changes the variable. This is impossible without either references or pointers. At the very far end of the same spectrum, pointers are the only way to implement polymorphism in C++, which is an important and useful concept in object oriented programming.

Using pointers is natural when in a function you need to use the contents of an object given as a parameter and change them. If you don’t pass a pointer or a reference to the object, you will only change the data in the copied object. For example, see the C++ function below.

void func(Object obj) {
  obj.data=0;
}

This bit of code would be quite useless, considering the object obj is discarded after the function exits. The data member of the object passed as a parameter will not be modified because the object is duplicated for use in the function. The below function does the same but with the exact same object that was passed as a parameter.

void func(Object& obj) {
  obj.data=0;
}

Now the object is not duplicated but obj is a direct reference to the original object. data will be zeroed. Below is yet another version of the same functionality, this time with a pointer.

void func(Object* obj) {
  obj->data=0;
}

This does the same thing, only that obj is a pointer to the object. The above examples show how pointers indeed can be avoided by using references or other more modern concepts (and in some languages you are forced do it with references).

However, in C++, the above example (the one with the pointer) would also allow you to pass an object as a parameter that was inherited from the class Object. By using C++ references this is not possible. Now, if the function called a member function, it would call different bits of code depending on the object! This can be a very, very powerful and nice feature. And you can’t do it without pointers (in C++).

Show me more examples.

In C and C++, the line between arrays and pointers is a bit blurred. For example, you can use a pointer as an array, in that you can use an index with an array and a pointer. Below is an example:

int a[2]={123,456};
int* b=a;
a[0]=0;
b[1]=0;

The array a is now full of zeros. Note that b only refers to the array, it doesn’t have its own data. Also note that specifying an index eliminates the asterisk in front of b. This is because in effect b[1] is the same as *(b+1).

Continuing from the above:

int a[2]={123,456};
int* b=a;
a[0]=0;
b=b+1;
*b=0;

This also zeros the array, because the pointer b is incremented. A pointer is simply a variable with an address and you of course can change that value. This is called pointer arithmetic. It can be very helpful and actually will often allow faster code: using an index needs a multiplication while smartly incrementing pointers only needs an addition (your mileage may vary — compilers are getting better and better). See the below example:

int a[100];
int i;
for (i=0;i<100;i++) a[i]=0;

The below modification should be marginally faster.

int a[100];
int *ptr=a;
int i;
for (i=0;i<100;i++) { *ptr=0; ++ptr; }

This is because in effect, the below example only increments the pointer while the above calculates the address using index.

Note: Many younger coders suffer of premature optimization. This is not a permanent condition and will reduce with some experience. The above is not a good place to optimize (what computer can’t do that fast enough for 100 times?) but do keep that trick in mind. At the very least, it can make code a bit shorter.

Afterword

This is it for now, I can’t think of anything more about basic pointer use. Honestly, it is a bit hard to imagine things from the perspective of an absolute beginner. Any ideas are welcome.

01 Mar

Use Macross to automate common WordPress post content

Here’s a macro plugin for WordPress I made. It features useful features for advertising, e.g. limiting the maximum amount of displayed ads.

macro view

What are macros?

A macro is a bit of text inside a post that, when displayed, will be substituted with other text. It simplifies editing of post and also provides a convenient way to insert repeating content.

Macros are useful for various uses:

  • Adding common content shared by multiple posts/pages
    • Post headers, footers and navigation between a series of posts
    • License disclaimers
    • Advertising inside post content (much more effective than leaving the ads outside the content)
  • Simplifying complex layout by hiding unnecessary formatting, e.g. adding an image with a caption using only a short macro
  • Quickly changing information on multiple pages, e.g. disclaimers, important notifications

Features

  • Configurable via the WordPress control panel system
  • Automatically limits the number of injected macros (useful for e.g. Adsense whose TOS states you can only have three instances per page)
  • Can be extensively controlled depending of page type (archive page, home page, single post etc.)

How it works

The macros are used by inserting text inside HTML comments when writing the post. Below is an example of a macro:

<!--adsense_inside_post-->

The macro looks like the above code when editing the post but when viewing the post (or page) it will be substituted with a Google Adsense advert (given that you have defined the macro).

Parameters can be used inside macros as follows. The first example is the text inside a post and the second is the macro defined on the Macross options page (with the name “image_with_caption”).

<--image_with_caption "image.jpg" "A photo I took last summer"-->
<p><img src="$1" alt="$2" /><br/>$2</p>

This macro will insert the text “A photo I took last summer” as the alt attribute for the tag and add it as a caption below the image.

You can use macros in a page template by using the expand_macro($name,$echo=true) function. This will also increment the counters. Here is the above example reinterpreted using expand_macro:

<?php expand_macro('image "image.jpg" "A photo I took last summer"'); ?>

By cleverly using macro priority (a lower priority macro gets injected first) you can use macros inside other macros. In combination with macro display options (i.e. if the macro is enabled for content, excerpts or feeds) you can use the same macro to expand into different text depending on where it is used.

Installation and configuration

Unzip the contents of macross.zip in your WordPress plugin directory and activate the plugin from Options > Plugins. Go to Options > Macross to create a macros. Counters work so that each successive macro injection increments the counter. If any of the specified counters for a macro exceeds the maximum value, the macro simply will not epand (also, none of the counters will be incremented).

The checkboxes next to a macro specify on which pages the macro will work. The first colum (Hook) tells Macross whether to expand the macro when actions the_content() or the_excerpt() is called. The third option enables the macro for the expand_macro() function. The rest of the checkboxes specify a page type, as returned by is_page(), is_single() and other conditional WordPress tags.

Download

Yes, the following is done with a macro, too. ;)

Links

  • Another macro plugin Originally, I wanted to use this, but found it cumbersome to edit macros. Also, it doesn’t have a counter/limiter system