This is a 6502-like core which compiles to around 250-270 LUTS on a MachXO3 and runs up to 150MHz on that FPGA (100MHz stable). All instructions take 1 cycle to complete, with the exception of the first instruction after reset that takes 2 cycles.
That is about 4-16 times faster than a full 6502 core on this FPGA (WDC 6502 runs at 75MHz on this FPGA, Arlets extended 65C02 (by BigEd&Dave) runs at about 28MHz).
The N6502 has a cut-down instruction set from a normal 6502 set with a lot of restrictions:
Each opcode is two bytes including address/data. The total program memory is 512 bytes which means 256 words (or 256 instructions). Branch works in words (e.g. 2*bytes), but can be easily changed in the code for 6502 compability (but then limited to +/-128 bytes).
Data memory is a separate space of 256 bytes. So no self-modifying code with only one core.
Stack memory is separated with 256 bytes, making total memory 1024 bytes.
The following instructions are currently implemented:
Code:
// LDA #nn is $A9, %10101001
// LDA $ZP is $A5, %10100101
// LDA $ZP,X is $B5, %10110101
// LDX #nn is $A2, %10100010
// LDX $ZP is $A6, %10100110
// STA $ZP is $85, %10000101
// STA $ZP,X is $95, %10010101
// STX $ZP is $86, %10000110
// BCC $xx is $90, %10010000
// BCS $xx is $B0, %10110000
// ADC #nn is $69, %01101001
// ADC $ZP is $65, %01100101
// ADC $ZP,X is $75, %01110101
// SBC #nn is $E9, %11101001
// SBC $ZP is $E5, %11100101
// SBC $ZP,X is $F5, %11110101
// CMP #nn is $C9, %11001001
// CMP $ZP is $C5, %11000101
// CPX #nn is $E0, %11100000
// CPX $ZP is $E4, %11100100
// DEX is $CA, %11001010
// AND #nn is $29, %00101001
// AND $ZP is $25, %00100101
// AND $ZP,X is $35, %00110101
// ORA #nn is $09, %00001001
// ORA $ZP is $05, %00000101
// ORA $ZP,X is $15, %00010101
// CLC is $18, %00011000
// SEC is $38, %00111000
// TXA is $8A, %10001010
// TAX is $AA, %10101010
// ROL A is $2A, %00101010
// ROR A is $6A, %01101010
// ASL A is $0A, %00001010
// LSR A is $4A, %01001010
// PHA is $48, %01001000
// PLA is $68, %01101000
// SQR #n is $49, %01001001
// SQR $ZP is $45, %01000101
// SQR $ZP,X is,$55, %01010101
// Note: $AD, $BD, $CD, $6D, $7D, $3D, $2D, $1D and $0D also triggers (as $x5 instructions)
// NOP : all other instructions
The SQR instruction returns the Square product into the accumulator and x-register and replaces EOR. The square instruction requires a table of 512 bytes to work.
Note that all 1-byte opcodes requires an extra (unused) byte after them to become two bytes. Except for that and the difference in branch, you can use your preferred assembler for this.
Constructive comments are appreciated. The core can probably run stand-alone in some small CPLD's or as a co-processor for a full 6502. Stack sharing is not currently implemented (for multi-core systems), but is planned in a future release.
Please note that this is a core under development, so files and features may change without further notice.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Attachment:
File comment: Source files for the N6502 version 0.1.
N6502-v0.1.zip [24.69 KiB]
Downloaded 274 times