Saturday, August 15, 2009

Playpower: The $12 Computer for the Masses

In 1985, Nintendo introduced the Famicom: an eight-bit computer and video game console. In America, it was known as the Nintendo Entertainment System (NES), and garnered widespread fame with its flagship game Mario. However, the console has been made obsolete by its successors, the Nintendo 64, GameCube, and Wii. In most developed countries, this former celebrity fills landfills. However, could it be staging a comeback as the computer of the less fortunate?

Bringing Technology to The Poor

There have been attempts to bring computers to the third world. Price is the most difficult issue: some families live on a dollar a day. The One Laptop Per Child (OLPC) project managed to create a modern laptop for about $150, but that's still a stretch for many. When even rudimentary computer skills can make someone go from "$1 per day to $1 per hour", perhaps a less fancy solution is better.

The Dawn of Home Computing

In 1976, Apple's first computer hit the shelves. The Apple I contained a MOS Technologies 6502 processor, a cheaper variant of Motorola's 6800 processor that only costed $25. This early computer would soon be joined by others -- including the Famicom -- to begin the home computer revolution. These computers are collectively referred to as 8-bit systems because their chips only worked on single bytes (1 byte = 8 bits) at a time, unlike our modern 32- and 64-bit processors. Although they're primitive by today's standards, these chips could power basic word processors, games, and spreadsheet software -- meaning they're still quite useful.

The 6502 is still cheap today, costing $14.00 per unit on Mouser Electronics. More importantly, since the Famicom's circuitry has been known for decades, other companies have pirated the design and produced cheap clones. Third-world citizens can pick up a $12 computer that plugs right into their TV sets and does everything a NES could do. That's why, unlike OLPC, Playpower's focus is not on hardware production: the computers are already out there. Instead, they envision developing quality educational and office software for these legacy systems. However, for the computer to be cheap, the software needs to be free. How will they manage that?

Open-Source Development

The obvious solution is to make the computer available to benevolent developers in first-world countries. Many great projects have been developed for free, by programmers who see beyond the bottom line -- and have loads of free time. And if the computer's only $12, what does someone this side of the Pacific have to lose? At least it would be an interesting hobby.

However, in the United States, the computer is not $12. Instead, a complete system of keyboard (with computer inside), mouse, controllers, and cartridge is about $50 at MakerSHED. And the only three reviews did not inspire confidence. Even though the controllers and mouse were good, apparently the keyboard didn't work for some. And the documentation was lacking too. There's actually a pretty good review on this guy's blog, including some pictures of the system. The general impression of the product is that, at its current stage, it's nothing more than an enigmatic "toy" that lets you waste hours trying to figure out how to make it work. That's why I'll wait until they fix it up a bit. For now, I can get a $12 Rubik's Cube that has the same effect.

My Thoughts: Make That PC Decent...

Personally, I feel the product should be of decent quality. Apparently the mouse and controllers work, and the software is fine too. But what about the keyboard? Every review I've seen (three of them) says the keyboards are crap, and some don't even work. It should also be well-documented. When developing software, I ABSOLUTELY HATE hunting for help. A lot of computers from the 8-bit era featured complete owner's manuals with the computer's circuit diagrams in the back. I can understand the need to minimize printing costs -- why not some online help. Yes, the PC must be cheap, but cheap should just mean limited in features -- not broken or hard to use.

What About Internet?

Playpower is looking into the Famicom Modem, a device that connects a NES to the Internet via a telephone line. If it can be mass-produced again, it could indeed be promising. However, the target market doesn't have the infrastructure: many places don't even have power lines, let alone telephone lines. I highly doubt the Famicom Modem would be a success with no phone jack to plug it into.

Instead, I envision a cartridge with an antenna that can connect to a long-distance wireless Internet service, and run a basic Web browser. I think that'd be incredible for developing countries. With the new WiMAX, the successor to WiFi, Internet transmissions can travel nearly 50 km at a speed of ~40 Mbit/sec. This means only a few scattered access points would be required throughout the country, as opposed to stringing cables everywhere. The prices for the WiMAX chips are set to fall below $10 in 2011, so an Internet cartridge could end up being, say...$15-$20? I wonder if this is already in progress, and if it would actually work in developing countries. After all, the required infrastructure should be very cost-effective.

Is All This a Good Idea?

That's a good question. While computers have created many new opportunities and generally improved our standard of living, they also pose many problems. The villages that welcome the Internet are also welcoming cultural assimilation. They'll be exposed to the same advertisements, ideas, and culture that the rest of the world shares, meaning they could lose the traits that make them unique. Like in the States, parents are likely to be at odds with their techno-savvy children -- who no longer respect their ancestral culture now that they're a part of something greater. This may result in the breakdown of traditional societies, leaving people worse off than they were without PC's.

There's also the well-known risks associated with computer use. The resulting vision problems and carpal tunnel syndrome will mandate additional medical infrastructure. I don't think even the Lions Club's drop boxes have enough used glasses for these poor computer nerds. Once they become disabled, they have even fewer opportunities than when they began.

More importantly, technology is still a relatively recent thing -- and wireless networks are even more recent. Electrosensitivity is a proven condition that afflicts a small fraction of the population, but suggests trouble for the rest of us. Electrosensitive individuals can detect electromagnetic fields (EMFs), which are created in the air around electric wires, devices, and antennas. Science cannot explain electrosensitivity, even though its existence has been proven -- which leads one to question our understanding of EMFs. Studies have shown a higher rate of birth defects in families living near overhead power lines. Do we really want to expose more of the world to something we don't fully understand?

All of these concerns pose a smaller risk than the starvation many currently face. However, once this technology becomes widespread, it will be too late to undo any harm it causes. In the time before the Playpower system becomes popular, I hope the organization addresses these important concerns.

What's Happening Now?

The last post on the Playpower blog was on March 12th. That's over 5 months ago, leading me to wonder if the project died an early death -- or is waiting for the next school year to start. It looks like their present task is getting the cc65 C compiler to work for the NES. Once that works, they can use the Contiki operating system -- which has a built-in text web browser and very low hardware requirements. To be honest, I probably won't even look at coding for this until I can write stuff in C. Until then, I wish them luck. It'll be neat when giving code -- not just cash -- can improve the lives of third-world citizens.

Friday, August 14, 2009

Browsing the Web in PHP

Recently, I was working with some PHP code that contacts AuthorizeNet to handle credit card payments. This process involves submitting POST data to an AuthorizeNet server over a secure connection, and decoding the results. Since it was written by a skilled coworker, it transmitted the POST data in an interesting way: using stream contexts.

What is POST Data?

Have you ever filled out a form on a Web page? When you click the Submit button, your browser packages your entries into POST data. It then sends them in a POST request to the Web site's server. Now what if you want to write a PHP script that pretends to be you, submitting the form data to that server using PHP code? That's basically how communication with AuthorizeNet works.

Stream Contexts: Turning fopen() into a "browser"

Most people who have worked with PHP or C know fopen() can open files. However, in PHP, it can also open URLs. You can use fopen() to download the HTML of the Web page at the URL you pass it. Here's the code for submitting some data over SSL (from the PHP manual page):

$data = array ('foo' => 'bar', 'bar' => 'baz');
$data = http_build_query($data);

$context_options = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);

$context = context_create_stream($context_options)
$fp = fopen('https://url', 'r', false, $context);
?>

  1. The POST data you want to send is transformed into a HTTP query string. Basically, that array becomes the string "foo=bar&bar=baz".
  2. Then, you create a context_options array that states the options for the HTTP request.
  3. The fopen() call opens the URL 'https://url' as if it were a file. It returns a stream resource, which is stored in the variable $fp. You can pass $fp to PHP's other stream functions to read the contents of the page.
You can get the page as a string by calling stream_get_contents($fp), or just output it directly with fpassthru($fp). Pretty neat, huh?

And Now for the Bugs...

There are a lot of subtleties to coding PHP. On Windows, I noticed the http_build_query function seems to use & amp; instead of & for the delimiter. Apparently, the delimiter is determined by the value of "arg_separator.output" in php.ini. You can fix this by calling http_build_query($data, '', '&').

How Is This Useful?

It's a remarkably simple way to send POST data to a server. This means you could, in theory, write your own bots for adding comments to people's pages (assuming they don't have captchas). I'm also thinking about using it to automatically submit my University of Washington schedule at 6 AM when my registration period begins. That way, I can ensure I'll get a seat in the classes I need, because my server will have signed me up before anyone else gets a chance. I also won't have to wake up at 6 AM. I could also write a proxy server with it. Maybe I'll do all this in the future, but for now -- it lets me submit credit card payments!

Wednesday, August 5, 2009

Flipcage -- my latest Javascript game plan

Once upon a Time

Imagine that you have a 12x12 grid, sitting on a black screen. A shape appears above the grid, and starts moving down. The shape is made of four square blocks, and you can rotate it 90 degrees and shift it left and right with your arrow keys. Once it lands at the bottom, another shape appears above the grid. If your shapes form a complete row, the row explodes and the blocks above it move down. And once 5 rows are completed, the entire grid rotates 90 degrees...

That sounds familar...

For most of that paragraph, you might've thought I'm making Tetris. However, in Flipcage, the block well rotates once you make at least 5 complete rows of blocks. And once it rotates, the entire formation inside settles to the bottom. This means you can add shapes to your formation from four different sides. Now that's a neat twist!

(and a really awesome pun...)

What happens if I make a column of blocks from top to bottom?

You probably think it'll become a complete row once the block well rotates. Think again.

Remember that the block well rotates once at least 5 rows are completed. That means it takes at least 1 complete row to cause a rotation. If a row is removed, your column won't go from top to bottom anymore -- so it won't become a complete row on rotation!

How about Pentris?

It might be fun if the shapes had between 1 and 5 blocks, instead of the usual 4. I played Pentris recently, and it's definitely interesting -- but needs a bigger board. Leave a comment if that sounds interesting...

Sounds cool! Where can I find it?

This game is coming soon to SoloKingdom.com. I estimate it will be out by September 2009. Stay tuned!

Pledge4Code is Online!

I'm pleased to announce that Pledge4Code.com is now online! You can now enjoy my beautiful graphics, John's code, and submit your ideas for awesome programs. Oh, and you can sign up to be notified of stuff -- although you might as well just watch our blogs. And...well, you can't really do much more than that -- yet!

The roadmap for the site is pretty simple:
  1. First, we want to let people submit and rate ideas.
  2. Then, we'll choose the best ideas and write some formal specifications.
  3. Finally, we'll start seeking people to pledge for the code!
Obviously, there's no guarantee that anything will happen, but such is the case for every company that hasn't found its market yet. Currently, Pledge4Code.com is targeting developers, but anywhere where there's a distributed need for software, we have an opportunity. Personally, I'm looking forward to building a useful and neat-looking frontend (Javascript included), so stay tuned...

I also recently managed to get Git working. Git is a fast and flexible distributed version control system. Like Subversion or CVS, it keeps track of all the changes you make to a project, and lets multiple people work on a given project simultaneously. Pledge4Code.com uses Git to manage the Web site source code. Trouble is: Git was made for Linux, meaning I had to use Cygwin (Linux in Windows) to use it. Since our setup uses public keys for security, I generated a key pair with ssh-keygen -- only to find out it didn't work. The problem is: Cygwin has two home directories, and you have to put your SSH keys in /home/(username)/.ssh/, not at ~/.ssh/ as I thought. After about an hour of trouble, I managed to get the key working. And now, I just need to set up a server. That's for next time...

By the way, I have a bunch of blogs that are just sitting around, waiting to be published. I need to run them by some people before they go online. So sit tight...it hopefully won't be that long...

Friday, July 20, 2007

Why am I here?

This is it: my first blog. Well, not my first; I've blogged before. But I always posted on Web sites of my own creation. I love to build computer programs because it's a cheap and fun hobby. But it can grow tiring, to the point at which one wonders if a hammer would be better than a rock...
I am here because I'm sick of what's been happening. I'm almost no longer a kid anymore, and it's kind of sad to see how I've wasted my time staring into a 17" world. I always wanted to do something great, but somehow, all my careful plans just never materialized. So, I'm all burned out, wondering what I could've been doing instead. Yes, I could write a blogging site on my own, with MySQL, PHP, etc., but I'm here because I don't really want history to repeat itself again.
I respect Google for its incredible online offerings, including a very useful search engine, clean-cut quick-loading interfaces, and unobtrusive text ads. So, I chose Blogger for this blog. It seems so convenient; I feel no obligation to search for an HTML editor, etc. And, just maybe, I'll actually establish an online presence, as Google's search engine will probably "see" this site. I know this site won't turn out exactly as I want it, but it'll definitely be close enough!
Since I enjoy creative writing, you'll probably find lots of my "creative" work here. However, realize that this site may only be temporary; my capricious mind could make me build a totally custom Web site for my work. I hope to focus on content rather than presentation at Blogger.com, since much of my burnout was caused by programming complex themes, etc. Maybe then I'll find the will to move on.