So I paired a W65C02S with an ATMEGA644A to do some testing, below I have the output from serial as well as the source code running to interact with the 6502, howver as you can see from the output its not quite working right. It properly follows the FFFC vector, and appears to read the first opcode A9, but seems to fail after that, the next OPCODE it tries to fetch should be 0x85, but its not, it seems to be getting the PC off by 1. Also sometimes RWB doesn't go high, it will just get stuck in a low value.
Quote:
OUTPUT
-------------
Initializing...
OPCODE: 0 RW: 1 Address: 0x4a2 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x4a2 DATA: 0x00
OPCODE: 1 RW: 1 Address: 0x4a2 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x4a2 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x100 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x1ff DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x1fe DATA: 0x00
OPCODE: 0 RW: 1 Address: 0xfffc DATA: 0x00
OPCODE: 0 RW: 1 Address: 0xfffd DATA: 0x04
OPCODE: 1 RW: 1 Address: 0x400 DATA: 0xa9
OPCODE: 0 RW: 1 Address: 0x401 DATA: 0x55
OPCODE: 0 RW: 1 Address: 0x402 DATA: 0x85
OPCODE: 0 RW: 1 Address: 0x7df8 DATA: 0x7d
OPCODE: 1 RW: 1 Address: 0x403 DATA: 0x01
OPCODE: 0 RW: 1 Address: 0x404 DATA: 0xa6
OPCODE: 0 RW: 1 Address: 0xa7 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0xa7 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0xa8 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0xa7a7 DATA: 0xa7
OPCODE: 1 RW: 1 Address: 0x405 DATA: 0x01
OPCODE: 0 RW: 1 Address: 0x406 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x01 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x01 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x02 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x101 DATA: 0x00
OPCODE: 1 RW: 1 Address: 0x407 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x408 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x01 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x01 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x02 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x101 DATA: 0x00
OPCODE: 1 RW: 1 Address: 0x409 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x40a DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x01 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x01 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x02 DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x101 DATA: 0x00
OPCODE: 1 RW: 1 Address: 0x40b DATA: 0x00
OPCODE: 0 RW: 1 Address: 0x40c DATA: 0x00
-------------------------------------------------------
CODE
-------------------------------------------------------
#include <Arduino.h>
uint8_t RAMARRAY[2048];
unsigned char reverse(unsigned char b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Initializing...\n");
pinMode(12,OUTPUT);
pinMode(11,INPUT);
pinMode(10,OUTPUT);
pinMode(15,INPUT);
digitalWrite(10,LOW);
digitalWrite(12,LOW);
DDRA = 0x00;
DDRB = 0x00;
DDRC = 0x00;
delay(10);
digitalWrite(12,LOW);
delay(10);
digitalWrite(12,HIGH);
delay(10);
digitalWrite(12,LOW);
delay(10);
digitalWrite(12,HIGH);
delay(10);
digitalWrite(12,LOW);
delay(10);
digitalWrite(10,HIGH);
delay(10);
RAMARRAY[0x400]=0xA9;
RAMARRAY[0x401]=0x55;
RAMARRAY[0x402]=0x85;
RAMARRAY[0x403]=0x01;
RAMARRAY[0x404]=0xA6;
RAMARRAY[0x405]=0x01;
RAMARRAY[0x406]=0x00;
}
void loop() {
// put your main code here, to run repeatedly:
//Serial.println("Clock HIGH\n");
digitalWrite(12,HIGH);
delayMicroseconds(30);
uint16_t addr = 0;
uint8_t data = 0;
bool rw=false;
bool SYNC=false;
SYNC = digitalRead(15);
rw = digitalRead(11);
addr = reverse(PINC);
addr |= reverse(PINB)<<8;
data = PINA;
if (rw==true) {
// CPU is reading
DDRA = 0xFF;
if (addr < 2048) {
data=RAMARRAY[addr];
}
if (addr == 0xFFFC) data=0x00;
if (addr == 0xFFFD) data=0x04;
PINA = data;
//Serial.printf("Sending: 0x%02x\n",data);
} else {
// CPU is writing
if (addr < 2048) RAMARRAY[addr] = data;
}
Serial.printf("OPCODE: %d\tRW: %d\tAddress: 0x%02x\tDATA: 0x%02x\n",SYNC,rw,addr,data);
//Serial.println("Clock LOW\n");
delay(1);
digitalWrite(12,LOW);
delayMicroseconds(30);
DDRA = 0x00;
delay(1);
}
-------------------------------------------------------------
HARDWARE
-------------------------------------------------------------
PORTB is HIGH byte of ADDRESS, connected in reverse bit order
PORTC is LOW byte of ADDRESS, connected in reverse bit order
PORTA is DATA, connected in proper bit order
PIN 12 is clock
PIN 10 is RESET
PIN 11 is RWB
PIN 15 SYNC
RDY, BE, IRQ, NMI, and RESET are all pulled up with 3.3k resistors