-
Py65: 6502 Microprocessor Simulator July 1st, 2008
I’ve started a new Python project called Py65. It aims to provide building blocks for modeling 65xx microcomputer systems in software, with a focus on homebuilt hardware. Using simulation, embedded systems software can be developed and tested much faster.
In its current form, Py65 supports the original NMOS 6502 microprocessor from MOS Technology. The venerable 6502 and variants of it powered such famous microcomputers as the Commodore 64, game systems like the Atari 2600 and Nintendo Entertainment System (NES), as well as thousands of consumer and embedded devices today.
I haven’t released a package for Py65 yet but I’ll be doing this after some organizational changes are complete. For now, you can get it from its Subversion repository linked from the Py65 page on Ohloh.
The Python interactive interpreter itself can be used as a monitor:
>>> import mpu >>> mpu = mpu.MPU() >>> mpu <6502: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000> >>> mpu.memory[0x0000:0x0001] = (0x69, 0x16) #=> $0000 ADC #$16 >>> mpu.step() <6502: A=16, X=00, Y=00, Flags=20, SP=ff, PC=0002>
The simulator currently supports all legal NMOS 6502 opcodes and I have written a large unit test suite to verify its core. Most of its tests look like this one:
def test_bne_zero_set_does_not_branch(self): mpu = MPU() mpu.flags
= cpu.ZERO mpu.memory[0x0000:0x0001] = (0xD0, 0x06) #=> BNE +6 mpu.step() self.assertEquals(0x0002, mpu.pc) Py65’s own unit tests hint at what tests for your own assembly language programs could look like. I am especially interested in unit testing my own embedded software and I will be working on an assertion vocabulary and test helpers for this.
There are a lot of possibilities for what could be done with Py65. For now, I plan to include a system for mapping virtual devices into the microprocessor’s address space, add more hooks into the simulator, and include support for additional 65xx family hardware.
Py65 does not include an assembler. If you need one, I recommend André Fachat’s excellent xa assembler which is currently maintained by Cameron Kaiser.
-
Horde/Routes 0.3 Released June 15th, 2008
Horde/Routes is a URL mapping system for PHP 5. It is a direct port of the Routes, a Python library that is part of the Pylons project. Horde/Routes is a standalone library designed to be integrated into any MVC framework.
This release brings in some changes from Routes 1.8. The most noticeable change is that custom actions on RESTful routes are now delimited with the forward slash (
/) instead of the semicolon (;). This was done for parity with Ruby on Rails.I have also fixed some bugs, notably that the resource route generator failed to generate routes that recognized
PUTandDELETErequests on “formatted” resources (/messages/1.xml). This fix will be merged upstream to the Python version.I am also using the Python version and I met with Ben Bangert, the author of the Python version, at PyCon 2008. Each release of Horde/Routes has resulted in patches to the Python version. It’s nice how this small ecosystem has developed around the routes concept between these projects (Ruby on Rails, Pylons, and our work in Horde).
Since Horde/Routes 0.3, the default RESTful routes generated by Horde/Routes are fully compatible with the latest version of ActiveResource. We have a new project at work that is using Horde/Routes and ActiveResource together and it works well.
-
Parsing Quoted Strings in Ruby April 28th, 2008
Python has a nice module in the standard library called shlex that parses strings as a Unix shell would. Here’s a Python interpreter session demonstrating its usage:
>>> import shlex >>> shlex.split('foo "bar baz" qux') ['foo', 'bar baz', 'qux']
It’s useful for creating your own mini-languages or external DSLs that need to parse quoted strings like the one shown above.
We recently built an inventory tracking application in Ruby that has a user interface for selecting search filters. To expose the same search capabilities as a web service, we created a simple query language. I was looking for an
shlexequivalent in Ruby.It turns out that the Ruby Standard Library has a module called Shellwords:
>> require 'shellwords' => true >> Shellwords::shellwords('foo "bar baz" qux') => ["foo", "bar baz", "qux"]
Shellwordsis a little less capable thanshlexbut handles the most common use case just fine. It’s a convenient solution for a problem that comes up too often.Update: Ruby 1.8.7 has added the shortcut methods
Shellwords.splitandString#shellsplit. Very nice. -
Speaking at OSCON 2008 April 2nd, 2008
The OSCON 2008 website has published its talk schedule. I’ll be giving two talks at OSCON this year; one on the Python track and one on the PHP track.Supervisor as a Platform
I will quickly introduce you to Supervisor and the immediate benefits of running your server processes under it. We will then dive into how applications written specifically for Supervisor can take advantage of it as a platform — writing your own event listeners to observe Supervisor and the process lifecycle, controlling with XML-RPC, and extending the Supervisor core with your own Python extensions.
This will be an expanded version of the talk I gave with Chris McDonough at PyCon 2008. Since PyCon, there’s been quite a few interesting developments in Supervisor like the ability to extend
supervisorctland progress made on configuration reloading. We’ll touch on these as well, so if you attended the PyCon talk there will still be new and interesting material in this talk for you.Integration Testing PHP Applications
While more PHP developers are recognizing the importance and benefits of unit testing, the uptake of PHP developers using automated integration or acceptance testing is relatively slow. This testing is equally crucial to maintaining the integrity of applications.
I’m going to help get you started testing at the application level with practical tips and source code. We’ll look at how to structure your HTML markup so it’s more easily testable, making tests easier to write and maintain with CSS selectors, organizing your tests, and testing with or without a browser.
We write a lot of PHP applications with this kind of testing at Maintainable. Before the conference, we plan to release some open source PHP code to help you test that we’ll cover in the talk as well. I’d also suggest you check out Sebastian Bergmann’s tutorial session on PHPUnit’s integration with Selenium RC.
-
Fail Early March 25th, 2008
I’m pleased to have been able to contribute a recipe to Mike Clark’s new book, Advanced Rails Recipes. The concept presented in my recipe, “Fail Early”, is that you can use initializers to prevent your application from starting up under certain conditions.
Rails applications typically run under persistent application server processes, like
mongrelorthin. When a Rails application starts, it goes through a startup procedure that is performed only once. The startup includes reading the environment configuration files and running any initializers that have been set up. This can also be used as an opportunity to detect potentially dangerous situations and bail out.“Fail Early” uses the case of pending migrations to demonstrate. If the application is started while there are pending migrations for the production database, the results can wreck production data. Instead, an initializer detects this condition and exits by calling Ruby’s
Kernel.abort.Here’s another case where this idea is useful. It’s well-known that the Ruby-based MySQL driver included with Rails isn’t suitable for use in production. In fact, Rails will produce this warning in the log if it is in use:
WARNING: You’re using the Ruby-based MySQL library that ships with Rails. This library is not suited for production. Please install the C-based MySQL library instead (gem install mysql).
This can go unnoticed in the log. Instead, we can write a short initializer that detects this condition and aborts the application start if the production server is misconfigured.
config/initializers/check_mysql_driver.rb:
if RAILS_ENV == 'production' config = ActiveRecord::Base.configurations['production'] if config['adapter'] == 'mysql' ActiveRecord::Base.require_mysql if Mysql::VERSION.to_s.include?('-ruby') abort "Ruby-based MySQL driver is not suitable for production" end end end
When the initializer above is run in a production environment that has the Ruby-based MySQL driver instead of the C-based one, startup will be aborted.
$ mongrel_rails start -e production ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with production environment... Ruby-based MySQL driver is not suitable for production $
You can run many other safety checks like this at startup. Since they will be run only once and not per-request, your application incurs no performance penalty by doing so.
-
PyCon 2008 Wrap-Up March 20th, 2008
At PyCon 2008, I gave a talk titled Supervisor as a Platform together with Chris McDonough. Our talk was very well attended and the audience even included Python creator Guido van Rossum. We received a lot of positive feedback about our recent work and I suspect we picked up a good number of new users as well.
About two months ago, we began a push to build quality documentation for Supervisor using Docbook. After this was complete, we set out to build a new web presence. Our efforts culminated at PyCon 2008 when we unveiled the new Supervisor website, built by the team at Maintainable Software.
PyCon was also very productive, with hacking on Supervisor, Repoze, and general WSGI fun. I worked on a new feature to allow Supervisor’s process group configurations to be reloaded without restarting Supervisor. Meanwhile, Chris made
supervisorctlpluggable so extensions can add new commands to the Supervisor command line.I also attended quite a few interesting talks, met some new people, enjoyed hanging out with usual the Zope and Plone folks, and overall just had a good time. PyCon 2008 was great conference and I’m looking forward to next year.
-
New Rails for PHP Developers Website February 18th, 2008
Rails for PHP Developers is a new website that’s a companion to the new book by the same name. Like the book, it’s aimed towards PHP developers who have an interest in Rails and Ruby. The website features articles that alternate between Ruby and PHP focus, so PHP developers that aren’t interested in Ruby should still find it useful.
-
Supervisor Twiddler 0.2 February 17th, 2008
Supervisor Twiddler is an RPC extension for Supervisor that allows Supervisor’s configuration and state to be manipulated in ways that are not normally possible at runtime.
Changes in release 0.2:
Renamed
addProcessToGroup()toaddProgramToGroup(). The method
now supports program definitions withnumprocs> 1 and will add
all resulting processes from the program definition. It also
fixes a bug where the process config was not added to the group
properly. Requested by Roger Hoover.Added new method
log()that writes an arbitrary message to the
main supervisord log. This is useful for recording information
about your twiddling.You can download the new version and read the updated documentation on the Supervisor Twiddler page of Maintainable Software’s open source project pages.
-
Commodore Plus/4 on LCD February 16th, 2008
I thought it might be interesting to mix things up a bit by occasionally posting about some neat hardware.
Last week, I purchased the RTV VEG. This device converts composite video to VGA and also has a TV tuner. The photo above shows my Commodore Plus/4 computer connected to a Samsung 17″ LCD panel through the device. A CMD FD2000, an aftermarket 3.5″ floppy drive, rounds out the setup.
Commodore monitors were never known for reliability. Even now, two of my Commodore 1084 monitors are waiting for me to repair them. With devices like the RTV VEG, modern LCD video displays can be used with the older computers. The RTV VEG is capable of converting both composite video and separated chroma/luma (S-Video) to VGA. This works for many Commodore computers like the VIC-20, TED series, and C64.
The Commodore 128 also outputs RGBI video, which is not supported by the device. The C128 requires a monitor that can be switched between composite and RGBI such as the 1902 or 1084. Kevin Krausnick has combined with the RTV VEG with another converter so that both modes can be used on a VGA monitor at the flick of a toggle switch. This is very clever and I intend to do this as well for my C128.
When switching to 80-column (VDC) mode on the C128, you also have to switch the monitor. On the old monitors, this switch is in the front. On Kevin’s setup, he has a toggle switch on his homebuilt hardware. Years ago, I modified my 1902 monitor by replacing the video mode switch with my own microcontroller to do it automatically. I intend to do something similar again with the goal of having a C128 with an LCD panel that displays both video modes and switches between them automatically.
-
Horde/Yaml 1.0 Released January 8th, 2008
Horde/Yaml is a PHP 5 library for easily working with YAML data. This is the package’s first stable release.
Chuck Hagenbuch started the library as an adaptation of Spyc around six months ago. Since then, he and I have been quietly using and improving it. Along the way, we fixed many issues, added support for pecl/syck, and wrote a test suite with PHPUnit.
There are a couple of other libraries also derived from Spyc, notably the
sfYamlclass from the Symfony framework. Since these efforts also found and corrected issues, we incorporated as many of these fixes as we could find and added them to the test suite as we went along.At Maintainable Software, we frequently use YAML files for configuring our custom applications because our clients tend to like the format more than the alternatives. We’ve been using Horde/Yaml successfully for quite some time so we think it should generally work well for you also.
There’s a nice tutorial on working with YAML in PHP 5 over on the new Rails for PHP Developers website. It includes everything you need to get started with Horde/Yaml.




