-
Py65 0.4 Released Jun 6, 2009
Py65 0.4 has been released. Py65 provides tools for simulating hardware based on 6502-like microprocessors.
Here are the highlights of this release:
- We now support an additional microprocessor simulation: the 65C02. While still a work in progress, it is fairly complete and quite usable. It is based on the W65C02S microprocessor from the Western Design Center (WDC).
- The monitor now supports assembling and disassembling the 65C02 opcodes. You can select the target microprocessor with the new
mpucommand. - There have been many other small additions and fixes to the monitor, the most useful of which is that most commands now have shortcuts such as
dfordisassemble. - A manual has been started and will be periodically published online. It is currently focused on the monitor usage.
For a complete list of changes in this release, please see the changelog. Special thanks to Oscar Lindberg for making major contributions to this release.
If you’re new to Py65, the README has an overview, installation instructions, and a link to the online documentation.
-
Supervisor 3.0a7 Released May 24, 2009
Supervisor 3.0a7 has been released. You can either easy_install it or get it from http://dist.supervisord.org/supervisor-3.0a7.tar.gz.
For the very long list of additions and fixes in this release, please see CHANGES.txt.
-
Horde/Routes 0.4 Released Mar 4, 2009
Horde/Routes 0.4 has been released. Horde/Routes is a URL mapping system for PHP 5 that provides classes for mapping URLs to the controllers and actions of an MVC system. Learn more at the project website or this presentation.
This version includes a new utility class,
Horde_Routes_Printer, a debugging aid that can print out a summary of all routes that are connected to a mapper. It is available through a convenience method fromHorde_Routes_Utils:$map = new Horde_Routes_Mapper(); $map->connect('post', ':title', array('controller'=>'posts','action'=>'show')); $map->connect('feeds', 'feeds/:format', array('controller'=>'feeds')); $map->connect(':controller/:action/:id'); $map->utils->printRoutes();
This will cause the following information to be printed to
php://output:post /:title {:controller=>"posts", :action=>"show"} feeds /feeds/:format {:controller=>"feeds", :action=>"index"} /:controller/:action/:idYou’ll see above that the name of the route (if any) is shown, the route path, and the default values for the route. If a route only matches for a certain HTTP method, this will be shown as well. It’s handy when you have a large number of routes, or resource routes.
If you’d like the debug output to go somewhere else, pass a stream resource as the first argument to
printRoutes(). The output is formatted similarly to therake routescommand from Rails. Although the notation is a little unusual for PHP, it’s compact and readable. SeeHorde_Routes_Printerif you’d like to modify the format.Since it’s release, we’re received a good amount of positive feedback on Horde/Routes. It is now being shared by the upcoming Horde 4 (Rampage), the Seagull framework, and a few others. Check out the integration guide for how to add it to your project.
-
Hide Inline Offers on Citi Card Activity Dec 27, 2008
Citi® Account Online recently revamped their credit cards website. It’s much nicer than the previous version except for one annoying addition. When viewing your account activity, it now shows yellow offers inline with the transactions:

My account activity typically shows two or three of these offers and I find them very distracting when trying to read the transactions. I haven’t been able to find an option on the website to hide these inline offers.
If you are using the Firefox browser, this problem can be solved with the Greasemonkey add-on. I’ve written a short user script for Greasemonkey that hides these offers:
// ==UserScript== // @name Hide Citi(R) Activity Inline Offers // @namespace http://mikenaberezny.com // @description Hide inline offers that make account activity unreadable. // @include https://www.accountonline.com/cards/svc/AccountActivity* // ==/UserScript== window.addEventListener('load', function() { // find all <tr class="promo-message"> elements var elements = document.evaluate( "//tr[@class='promo-message']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); // set style "display: none" on those elements for (var i = 0; i < elements.snapshotLength; i++) { elements.snapshotItem(i).style.display = 'none'; } }, true);
To install it, first install the Greasemonkey add-on and then download the user script that contains the source above: citi-inline-ads.user.js
Greasemonkey should then automatically prompt you to install it. Please note that this user script is provided to the public domain without warranty. After installation, the inline offers should appear briefly as the page loads and then will be hidden:

I’ve left the icon with the plus sign that indicates there is an offer. Clicking it or the row will still expand to show the offer. Now, you can still see when an offer is available but in a less obtrusive way that doesn’t hinder the readability of the transaction list.
Greasemonkey is a great way to customize websites to your liking. To learn more about it, Mark Pilgrim’s Dive Into Greasemonkey is an excellent guide.
-
PyWorks 2008 Slides Nov 15, 2008
Slides from my PyWorks 2008 talks are now available. This conference was shared with php|works and I enjoyed this format. It was great to see many of my Python and PHP friends at the same event. Thanks to everyone who attended my talks.
Py65: Microcontroller Simulation with Python
This talk introduced the venerable 6502 microprocessor family, building small computer systems with these parts, and then simulating those systems with Py65.
The audience participation was great. We had fun stepping through some small assembly language programs on the simulator. One attendee wrote:
This was fascinating and the speaker was awesomely enthusiastic. The overview of microcontrollers and their significance was enlightening and entertaining. The simulator design presented was fantastically simple and very Pythonic. I can’t wait to see where this project goes.
Thanks and I’m glad you enjoyed it. For updates on the Py65 simulator, please watch my blog and the Py65 project page on Ohloh.
URL Mapping with Routes
We explored the Routes library from the ground up, setting it up and then exploring its options and matching. We worked through many of the examples with live demos on the Python interactive interpreter.
The talk was attended by several Pylons users, who gained a better understanding of how Routes works by seeing it outside the context of any particular web framework.
URL Mapping with Horde/Routes
Bonus Slides! Horde/Routes is a PHP 5 library that is a direct port of Routes. Since there were so many PHP folks at this conference as well, I ported all of the examples in my Routes talk to work with Horde/Routes.
These slides will help you get acquainted with the PHP version. Since the two presentations are otherwise identical, you might also find it an interesting comparison between Python and PHP 5.
-
Py65 0.1: Introducing Py65Mon Nov 9, 2008
Py65 0.1, a 6502 microprocessor simulator written in Python, has been released and is available on the Python Package Index (PyPI). You can now easy_install it:
$ easy_install py65
Py65Mon
Since my initial announcement of Py65, there have been many bug fixes and unit tests added. The most noticeable addition is a new machine language monitor. It will be installed automatically and is started with the
py65moncommand:$ py65mon Py65 Monitor <6502: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000> .
At the prompt, type
helpfor a list of commands orhelp commandfor help on a specific command. The monitor commands are very similar to the excellent VICE Monitor, so VICE users should feel right at home.The biggest difference from VICE is that the
loadcommand requires a load address as the second argument and starts reading the binary data from byte 0. It does not expect byte 0 and 1 of the file to contain a Commodore-style load address. Also, assembling and disassembling from the monitor are not yet implemented but are planned.Hello World
Just like Michal Kowalski's 6502 Macroassembler & Simulator for Windows, Py65Mon will trap writes to
$E001and echo the bytes toSTDOUT.This is enough to get us to our first "Hello World" program running under Py65. First, we'll write a short assembly language program to print the message. Save it as
hello.asm.*=$C000 CHAROUT=$E001 HELLO: LDX #$00 LOOP: LDA MESSAGE,X BEQ DONE STA CHAROUT INX JMP LOOP DONE: RTS MESSAGE = * !text "Hello, World!" !byte 0
We then assemble the program into a binary, using Marco Baye's Acme Cross-Assembler:
src$ acme --format plain --outfile hello.bin hello.asm
The
--format plainswitch instructs Acme not to prepend the Commodore-style load address in the binary. If you'd like to get going quickly, you can also download hello.bin.With the binary ready, we can start the monitor and load it in:
src$ py65mon Py65 Monitor <6502: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000> .add_label c000 hello <6502: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000> .load "hello.bin" hello Wrote +29 bytes from $c000 to $c01c
Py65Mon supports symbolic addressing in most commands. The first command,
add_label, defineshelloas a label for address$C000. The second command loads the binary into that address.We can now set the program counter with the
registerscommand, and execute the code up toRTSwith thereturncommand.<6502: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000> .registers pc=hello <6502: A=00, X=0d, Y=00, Flags=20, SP=ff, PC=c000> .return Hello, World! <6502: A=00, X=0d, Y=00, Flags=20, SP=ff, PC=c00e> .
Now we have run the program, printed "Hello, World!", and returned to the prompt. We can see the program counter is left at
$C00E.You can also use the
stepcommand to step through the program. Just set the program counter to the start address again ($C000orhello) and repeatedly enterstep. As you are stepping repeatedly, you can simply hit ENTER to repeat the last command.From here you can also explore other commands, e.g.
mem c000:c003to display the memory in that address range. The default radix is hexadecimal. You can also prefix with$for hexadecimal or+for decimal, likemem +49152:+49155.Next Steps
Py65 and its monitor are now complete enough to run most simple 6502 programs, including many from the 6502.org Source Code Repository. The next versions will include more I/O devices and monitor commands, with the goal of running a sophisticated 6502 program like Lee's Davisons' Enhanced 6502 BASIC.
-
PHP Temporary Streams Oct 17, 2008
It’s been a while since David Sklar called out to let a thousand string concatenations bloom. That discussion produced some entertaining suggestions for putting strings together such as using
preg_replaceand calling out to MySQL withSELECT CONCAT.Here’s an approach that uses filesystem functions. When combined with some lesser-known PHP streams functionality, it has several practical applications.
Opening Files for Reading and Writing
There are several modes for opening a file that will allow you to seek to arbitrary positions in the file and read or write at those positions. One of the most frequently used of these modes is
w+, which thetmpfilefunction uses automatically.We can repeatedly write, then rewind the pointer and read:
$f = tmpfile(); fwrite($f, 'foo'); fwrite($f, 'bar'); rewind($f); $contents = stream_get_contents($f); //=> "foobar" fclose($f);
When writing to the filesystem, the above provides yet another inefficient solution to David’s exercise. Now let’s take it a bit further to see how this can be useful.
In-Memory Streams
PHP 5.1 introduced two new in-memory streams:
php://memoryandphp://temp. Thephp://memorystream operates entirely in memory. Thephp://tempstream operates in memory until it reaches a given size, then transparently switches to the filesystem.We can modify the above example to use the
php://memorystream instead of hitting the filesystem:$f = fopen('php://memory', 'w+'); fwrite($f, 'foo'); fwrite($f, 'bar'); rewind($f); $contents = stream_get_contents($f); //=> "foobar" fclose($f);
Putting a string inside a fast temporary stream can be very useful. For example, we can then attach filters to that stream.
Testing
Temporary streams are also handy for testing. There are some rather elaborate virtual file system libraries out there but many times a stream is all you need.
Zend_Log has a log handler for streams that accepts either a filename or a stream resource. We can configure it with a
php://memorystream for testing:$f = fopen('php://memory', 'w+'); $writer = new Zend_Log_Writer_Stream($f); $logger = new Zend_Log($writer);
Assuming your well-designed application has a convenient injection point for the logger instance, your test can pass it in before your test activates some action which should result in logging:
$logger->crit('critical message worth testing');
When the action has completed, the test can rewind
$fand use it as a test spy.rewind($f); $contents = stream_get_contents($f); $this->assertRegExp('/message worth testing/i', $contents); // PHPUnit
Not surprisingly, my unit tests for Zend_Log use this same technique.
Application Usage
Not long ago, we built a custom document storage system for a client. One of its more interesting features is that it integrates with an internet fax service so users can select documents in the system and then fax them. For each fax, the software automatically generates a cover page.
To make the cover page, I first made a nice template using a drawing tool and then saved it in PDF format. I then used Zend_Pdf to write over the template with dynamic content. I first demonstrated this technique in this article.
Since the cover page is only used once (during transmission) and easy to regenerate, I don’t save the output to the filesystem. Instead, I create a
php://tempstream. The instance methodZend_Pdf->render()writes the PDF output only to that stream, which is then rewound. Functions likestream_copy_to_streamorfpassthrucan then be used to send the final output where it needs to go, and the whole process normally never needs to use the disk. -
Commodore LCD Firmware Oct 4, 2008
The files below are EPROM images from Bil Herd‘s prototype Commodore LCD.
You can also download them as a single archive: commodore-lcd-roms.zip
I’ve always been curious about this machine so I sent my device programmer to Bil so that he could read the EPROMs. Bil was very kind to do this and we should all thank him for it. This is the first time that these images have been seen in many years.
Start your disassemblers!
-
PHP Developer Best Practices Sep 16, 2008
Matthew Weier O’Phinney and I gave a tutorial session at ZendCon 2008 this year titled “PHP Developer Best Practices”. The tutorial touched on source control, coding standards, testing, documentation, and more.
The slides are now available in PDF format.
We were located in Hall B of the Santa Clara Convention Center, which is a very large room that’s also used for the keynotes. Andi told us the room was selected based on the number of people who registered for our session. We initially had doubts but the attendance was greater than any previous year and the room worked out quite well. We were thankful that unlike last year, everyone was able to get a seat.
Thank you to all who attended. We enjoyed meeting many of you during the breaks and hope that you found our session helpful.
-
Commodore SuperPET Sep 1, 2008
I’ve been spending more of my free time recently restoring vintage computer hardware. I am interested in Commodore 8-bit equipment, from the PET/CBM line through to the 64/128 home computers. I think it’s important to preserve computer history to remember the machines that got us where we are today.Since much of the hardware I restore is over twenty-five years old, at least half of it is not working when I receive it. I try to repair everything I can when it’s practical. My Flickr photos page has daily progress of my chip-level repairs on this equipment.
Recently, I received a Commodore SuperPET computer. This is a remarkable machine that was a collaboration between Commodore and the Computer Systems Group at the University of Waterloo in Ontario, Canada. The SuperPET is a standard Commodore PET 8032 computer with an internal expansion that adds a powerful Motorola 6809 microprocessor, an additional 64K of expansion RAM, a fast 6551-based RS232 serial port, and custom Waterloo software in ROM.
The SuperPET can operate in MOS 6502 mode, where it is a Commodore PET 8032 with the extra 64K expansion and 6551 ACIA. Curiously, this 64K expansion memory is not compatible with the 8096. A switch on the side puts the SuperPET into 6809 mode, where it can run a number of disk-based Waterloo programming languages including BASIC, Pascal, APL, Fortan, and COBOL. When in 6809 mode, a menu in ROM prompts the user to select a language which is then loaded from disk.
My SuperPET seemed to work when I got it, with the 6502 mode working perfectly and 6809 mode showing the power-on menu. However, after obtaining the disk-based software, none of the Waterloo languages would run after loading. After verifying the disks were good, I suspected the 64K expansion RAM since the rest of the machine seemed to be working. Using technical information from the PET Index on 6502.org, I wrote several memory test programs to exercise the expansion RAM.
The expansion RAM is comprised of thirty-two 4116 DRAM chips. A couple of these had become loose from their sockets and my test program found that one of them had failed. I got a replacement from the pick-up counter at Jameco and installed it. Now, my SuperPET passes my expansion memory test and also boots all of the Waterloo languages. It is now fully functional and I’m exploring the Waterloo software.
One of the most interesting features of the Waterloo languages is how files are accessed. Commodore disk drives attached to the SuperPET are accessed with a filename like
disk8/1.program-namewhich selects unit 8, drive 1. The SuperPET was designed to be attached to a mainframe computer, known as the “host”, through its serial port. Accessing a file likehost/program-namewould load it from the mainframe if it was running the specialHOSTCMprogram from Waterloo.The
HOSTCMprogram was available for VM/CMS and other mainframe operating systems. Beyond that, I’ve not been able to find out much information about it. I would like to figure out the protocol and write a program so that a modern PC could be used as a host computer for the SuperPET.If you have any information on the SuperPET or have Commodore hardware you’d like to donate, please contact me.
