Fetching contributors…
Cannot retrieve contributors at this time
509 lines (342 sloc) 13.6 KB

Py65 - 6502 Microprocessor Simulation in Python

Author: Mike Naberezny
Version: |version|


Simulate 6502-based microcomputer systems in Python.

Using the Monitor


Py65 includes a program called Py65Mon that functions as a machine language monitor. This kind of program is sometimes also called a debugger. Py65Mon provides a command line with many convenient commands for interacting with the simulated 6502-based system.

The monitor is started using the py65mon command:

$ py65mon

Py65 Monitor

6502: 0000 00 00 00 ff 00110000

Once the monitor has started, it will display a register dump and the dot prompt. You can then enter commands for the monitor at this prompt.

Py65Mon uses commands that are very similar to those used by the monitor included with the VICE emulator for Commodore computers. You can get a list of available commands with help or help on a specific command with help command.

Number Systems

When working with Py65Mon, you will frequently need to enter numbers, addresses, and ranges of addresses. Almost all Py65 command support entering numbers in binary, decimal, and hexadecimal.

Numbers can be entered with a prefix to specify the radix, e.g. $c000 instructs Py65Mon that the number c000 is hexadecimal. The following prefixes are supported:

  • $c000: The dollar sign indicates hexadecimal.
  • +828: The plus sign indicates decimal.
  • %0101: The percent sign indicates binary.

Numbers can also be entered without a prefix. Most of the time, working in hexadecimal will be the most convenient so this is the default radix. The number c000 will be assumed to be hexadecimal unless the default radix is changed using the radix command.

Address Ranges

Some commands accept a range of memory addresses:

.disassemble ff80:ff84
$ff80  d8        CLD
$ff81  a2 ff     LDX #$ff
$ff83  9a        TXS
$ff84  a0 1c     LDY #$1c

The syntax for a range is start:end. Each of the two parts may have a prefix to indicate the radix, or no prefix to use the default radix.

Sometimes it is useful to have the starting and ending address in a range be the same, such as when you want to inspect a single byte of memory. In this case, you can enter ff80:ff80 or simply ff80.

Assigning Labels

Large assembly language programs may have hundreds of procedures. It is difficult to remember the memory address of each procedure and the addresses may change if the program is reassembled.

You can add a label for any memory address using the add_label command. This label can then be used anywhere the address could be used:

.add_label ff80 start

.disassemble start
$ff80  d8        CLD

When using labels, you can also specify an offset (plus or minus):

.disassemble start:start+4
$ff80  d8        CLD
$ff81  a2 ff     LDX #$ff
$ff83  9a        TXS
$ff84  a0 1c     LDY #$1c

Offsets are interpreted like any other numbers. In the example above, start+4 implies that the offset (4) uses the default radix. This could also be written as start+$04 for explicit hexadecimal.


It is possible to set breakpoints to stop execution when reaching a given address or label. Breakpoints are added using the add_breakpoint command:

.disassemble start:start+4
$ff80  d8        CLD
$ff81  a2 ff     LDX #$ff
$ff83  9a        TXS
$ff84  a0 1c     LDY #$1c
.add_breakpoint $ff84
Breakpoint 0 added at $FF84
.goto $ff80
Breakpoint 0 reached.
6502: ff84 00 ff 00 ff 10110000

Note that a number is assigned to each breakpoint, similar to how VICE operates. Deleting a breakpoint can be done via the delete_breakpoint command using the breakpoint identifier given by add_breakpoint:

.add_breakpoint $ff84
Breakpoint 0 added at $FF84
.delete_breakpoint 0
Breakpoint 0 removed

Breakpoint can be listed using the list_breakpoint command:

.add_breakpoint $1234
Breakpoint 0 added at $1234
.add_breakpoint $5678
Breakpoint 1 added at $5678
.add_breakpoint $9ABC
Breakpoint 2 added at $9ABC
Breakpoint 0 : $1234
Breakpoint 1 : $5678
Breakpoint 2 : $9ABC

Keep in mind that breakpoint identifiers are not recycled throughout a session, this means that if you add three breakpoints (#0, #1, #2) and then delete breakpoint #1, the next breakpoint you add will be breakpoint #3, not #1. Also, invoking reset clears breakpoints too, not just labels.

Command Reference