Saturday, March 3, 2012

The 65C02

The 65C02 microprocessor is an upgraded CMOS version of the MOS Technology 6502 8-bit CPU. Over the years it has been manufactured by Western Design Center, NCR, GTE, Rockwell, Synertek and Sanyo. It is electrically compatible with the 6502 and offers lower power consumption due to the use of CMOS technology.

The most interesting feature is that it supports some new instructions. The references listed later cover this in more detail, but briefly the new features are:

  • a new zero page addressing mode for ADC, AND, CMP, EOR, LDA ORA, SBC, and STA instructions
  • new accumulator DEC and INC instructions
  • JMP (abs,X) addressing mode
  • BRA (branch always) instruction
  • PHX PHY PLX PLY (push or pull X or Y register)
  • STZ (store zero) instruction
  • TRB (test and reset bits) instruction
  • TSB (test and set bits) instructions

Four additional instructions are available on 65C02s manufactured by Rockwell and WDC:

  • BBR BBS (branch on bit reset or set)
  • RMB SMB (reset or set memory bit)

Two additional instructions are available on 65C02s manufactured by WDC:

  • STP (stop the processor)
  • WAI (wait for interrupt)

Any unused opcodes are handled as NOPs by the 65C02 (with the 6502 the behaviour was undocumented).

Your Replica 1 may have come with a 65C02. If not (mine didn't) you can order one and replace the 6502 with a 65C02. While no longer manufactured, it is available as NOS (New Old Stock) from suppliers such as Jameco. I ordered one and received a Rockwell R65C02P2 which can run up to 2 MHz and has a date code from 2003.

65C02 on Replica (along with original 6502)
Some computers, such as the Apple IIc, shipped with a 65C02. The Apple 2GS, last of the Apple 2 series, used a 16-bit version of the 6502 processor called the 65C816.

The 65C02 will continue to run all existing 6502 code but you can also experiment with the new 65C02 instructions. You CPU will also consume less power and run cooler.

The version of the Krusader Assembler burned into ROM on the Replica 1 does not support the 65C02 but there is a 65C02 version. You can download that version from here  and program it into an EPROM (if you have the facility to do so) or run it from RAM.

One quirk of Krusader: it wants the INC and DEC instructions to be called INA and DEA. It also doesn't support the Rockwell/WDC-specific  instructions BBR, BBS, SMB. and RMB or the WDC-only STP and WAI.

Here is a screen shot showing Krusader assembling some 65C02 code:

Krusader Assembling 65C02 Code

And disassembling:
Krusader Disassembling 65C02 Code

The CA65 cross-assembler  also supports 65C02 instructions. You need to use the processor directive .PSC02 to enable it. Below is an assembler listing showing some 65C02 instructions (the code does not do anything meaningful):

ca65 V2.13.3 - (C) Copyright 1998-2012 Ullrich von Bassewitz
Main file   : 65c02.s
Current file: 65c02.s


000000r 1                       .PSC02
000000r 1  80 00                BRA next
000002r 1  65 01        next:   ADC $01
000004r 1  25 02                AND $02
000006r 1  C5 03                CMP $03
000008r 1  45 04                EOR $04
00000Ar 1  A5 05                LDA $05
00000Cr 1  05 06                ORA $06
00000Er 1  E5 07                SBC $07
000010r 1  85 08                STA $08
000012r 1  89 12                BIT #$12
000014r 1  34 34                BIT $34,X
000016r 1  3C 78 56             BIT $5678,X
000019r 1  3A                   DEC
00001Ar 1  1A                   INC
00001Br 1  DA                   PHX
00001Cr 1  5A                   PHY
00001Dr 1  FA                   PLX
00001Er 1  7A                   PLY
00001Fr 1  64 12                STZ $12
000021r 1  74 12                STZ $12,X
000023r 1  9C 56 34             STZ $3456
000026r 1  9E 56 34             STZ $3456,X
000029r 1  14 12                TRB $12
00002Br 1  1C 56 34             TRB $3456
00002Er 1  04 12                TSB $12
000030r 1  0C 56 34             TSB $3456

References

Finally, here are some good references for information on the 65C02:

  1. http://en.wikipedia.org/wiki/65c02
  2. http://www.6502.org/tutorials/65c02opcodes.html
  3. http://www.llx.com/~nparker/a2/opcodes.html

3 comments:

davecramerwdc said...

Love to see this type of Blog online for the 65xx community however some of the manufacturing and distribution information is incorrect. Feel free to contact me at david.cramer@thewesterndesigncenter.com for more correct information.

Thanks

Jeff Tranter said...

Some of the info came from Wikipedia and may be incorrect or historical. For current 65xx family devices, The Western Design Center is definitely the best source.

Ed said...

Dave, I'd be interested to learn whether all the 65C02 designs really are second sources, or in any way derived from WDC, or whether they are independent implementations.