-
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
mpu
command. - 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
d
fordisassemble
. - 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.
-
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
py65mon
command:$ py65mon Py65 Monitor <6502: A=00, X=00, Y=00, Flags=20, SP=ff, PC=0000> .
At the prompt, type
help
for a list of commands orhelp command
for 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
load
command 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
$E001
and 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=$F001 ;Originally $E001, now $F001 since Py65 0.2 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 plain
switch 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
, defineshello
as a label for address$C000
. The second command loads the binary into that address.We can now set the program counter with the
registers
command, and execute the code up toRTS
with thereturn
command.<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
step
command to step through the program. Just set the program counter to the start address again ($C000
orhello
) 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:c003
to 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.
-
Commodore LCD Firmware, Schematics, and Specifications Oct 4, 2008
Download images of the EPROMs in Bil Herd’s Commodore LCD prototype:
commodore-lcd-roms-bil-herd.zip (Added Oct 4, 2008)Download images of the EPROMs in Jeff Porter’s Commodore LCD prototype:
commodore-lcd-roms-jeff-porter.zip (Added May 24, 2023)Download the prelim spec: commodore-lcd-preliminary-spec.pdf (Added May 15, 2012)
Download more specifications: commodore-lcd-specs.zip (Added Mar 11, 2017)
Download the schematics: commodore-lcd-schematics.zip (Added May 27, 2022)
I’ve always been curious about this machine so I sent my EPROM 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!
Update May 15, 2012: Via Bil Herd, Bob Russell has provided the Preliminary Specification of the LCD. The actual prototype hardware owned by Bil Herd has quite a few differences from this spec.
Update Jan 21, 2014: Gábor Lénárt used these dumps to create a Commodore LCD emulator in JavaScript. Incredible work!
Update Nov 28, 2014: Bil Herd has posted a Commodore LCD Teardown video on YouTube.
Update Dec 7, 2016: Added a dump of the character ROM from Bil’s LCD and photos. The character ROM is socket U16, which appears to be a 2332 pinout like the C64. The character ROM itself is a 2764 EPROM with a sticker “LCD CHAR ROM“. The extra pins hang out of the socket and are tied to Vcc with hand-wiring, including the highest address line, so 4K is readable by the LCD. Bil and I dumped this 2764 in my EPROM programmer. We did not disturb the hand-wiring, so we only read 4K of it (like the LCD does). The data layout is like other Commodore character ROMs. Steve Gray created a rendering of it. The character set is interesting compared to other Commodore computers; e.g. the presence of a tilde and curly braces that were perhaps added to support the built-in terminal.
Update Mar 11, 2017: Added a new ZIP file, commodore-lcd-specs.zip, with specifications. It includes detailed technical descriptions of the LCD controller and MMU chips. These were scanned by Andy Finkel and forwarded by Bil Herd.
Update May 12, 2022: I’ve created a GitHub repository with Commodore LCD ROM disassemblies. I started with the LCD KERNAL disassembly by Gábor Lénárt and have disassembled and commented more routines.
Update May 27, 2022: Added a new ZIP file, commodore-lcd-schematics.zip, with the schematics. The original pages are owned by Bil Herd. Thanks to Bil for allowing them to be scanned and posted.
Update June 1, 2022: Johan Grip has redrawn the schematics in KiCad and released his files under the CERN Open Hardware License v2.0 Strongly-Reciprocal (CERN-OHL-S). According to this explanation, it is a “strong copyleft” license. Alternatively, the original Commodore LCD schematics are available and contain the same information.
Update May 24, 2023: Added a new ZIP file, commodore-lcd-roms-jeff-porter.zip, with dumps of the EPROM’s from Jeff Porter’s Commodore CLD prototype. Photos of Jeff’s CLCD and his printer are also available.
-
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-name
which 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-name
would load it from the mainframe if it was running the specialHOSTCM
program from Waterloo.The
HOSTCM
program 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.
-
Speaking at PyWorks 2008 Aug 29, 2008
PyWorks is a new conference from the folks at Python Magazine. It is being co-hosted with a PHP conference, php|works, and attendees of either conference have access to talks on both the Python and PHP tracks. Being a user of both languages, I think this a great idea and I’m looking forward to this format. I’ll be giving two talks at PyWorks 2008:
Microcontroller Simulation in Python
This talk will present Py65, my open-source simulation of a small microcomputer system based on the MOS 6502. The 6502 is a very famous microprocessor that was used in early microcomputers like the Commodore 64, but its design has stood up for over 30 years. Cores based on the 6502 are now widely used in embedded devices, with WDC estimating annual volumes in the hundreds of millions of units.
Using Python and software tools such as Py65, low-level software for embedded systems can be developed and tested much faster. This talk will discuss the design and implementation of Py65, how it and tools like it can help, and will also touch on other Python libraries that can assist with embedded development. (PyWorks Abstract)
URL Mapping with Routes
Routes is a Python package that provides a solution to the problem, “how do I map URLs to my code?” Its solution is an interesting one, and is actually a re-implementation of a feature from Ruby on Rails. Routes itself has also now been ported to PHP 5 as part of the Horde project. Routes is used by the Pylons web framework and other frameworks in Python, and is relatively easy to use as a standalone package.
The Routes method of URL dispatch is based around pattern matching rather than object publishing. For those new to Routes, we’ll have an introduction to the basic Routes concepts and how it works. We’ll also dive into the Routes internals and follow some URLs through their recognition phase, learning about how Routes does it job along the way. Web developers and framework implementers alike will gain a better understanding of Routes and how to use it effectively. (PyWorks Abstract)
-
Py65: 6502 Microprocessor Simulator Jul 1, 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:
>>> from py65.mpu6502 import 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.