Building off of this project, I've built myself a cart-slot interface, and now I'm trying to write the software to talk to the cart. For now, I'm just dealing with non-coprocessor games. My current code is just returning all 0xFF for the entire 16MB address space. I've checked all of my wiring, as well as the pin assignments in software. I'm assuming that a read operation consists of the following steps:
-Set address (with /CART and /RD high)
-Pull /CART low
-Pull /RD low
-Read data
-Pull /CART and /RD high
Here is the interface I've built, the only difference being that all I had on hand were '573 octal latches, instead of the D-flip flops. I wrote my code such that it should work for either ('574s are posedge-triggered, '573s are active-low latched, so once the address is set, I pull the clk/latch line high, then low). All of the ALL_CAPS_NAMES are pin assignment #defines.
Any ideas what I'm doing wrong?
-Set address (with /CART and /RD high)
-Pull /CART low
-Pull /RD low
-Read data
-Pull /CART and /RD high
Here is the interface I've built, the only difference being that all I had on hand were '573 octal latches, instead of the D-flip flops. I wrote my code such that it should work for either ('574s are posedge-triggered, '573s are active-low latched, so once the address is set, I pull the clk/latch line high, then low). All of the ALL_CAPS_NAMES are pin assignment #defines.
Code:
void Init()
{
// Address lines as outputs, init to 0x00
ADDR_DDR_0 = 0xFF;
ADDR_DDR_1 = 0xFF;
ADDR_PORT_0 = 0x00;
ADDR_PORT_1 = 0x00;
// Init address latches to 0x00 and enable their outputs
delayMicroseconds(1);
LATCH_PORT |= (ADDR2_BIT | BANK_BIT | EX_BANK_BIT);
delayMicroseconds(1);
LATCH_PORT &= ~(ADDR2_BIT | BANK_BIT | EX_BANK_BIT | LATCH_OE_BIT);
// Data line defaults to input (read mode)
DATA_DDR = 0x00;
// Enable pull-up to keep data line from floating
DATA_PORT = 0xFF;
// Control lines as outputs, pulled high
CONTROL_PORT |= (CART_BIT | RD_BIT | WR_BIT | RST_BIT);
}
uint8_t ReadByte(uint16_t address)
{
// Set data line as input, pulled high
DATA_DDR = 0x00;
DATA_PORT = 0xFF;
// Pull all control lines high
CONTROL_PORT |= (CART_BIT | RD_BIT | WR_BIT);
// Set up address
ADDR_PORT_0 = address & 0xFF;
ADDR_PORT_1 = (address >> 8) & 0xFF;
delayMicroseconds(1);
LATCH_PORT |= ADDR2_BIT;
delayMicroseconds(1);
LATCH_PORT &= ~ADDR2_BIT;
// Pull CS low, then OE low
CONTROL_PORT &= ~CART_BIT;
CONTROL_PORT &= ~RD_BIT;
delayMicroseconds(1);
// Read data
uint8_t data = DATA_PIN;
// Pull all control lines high
CONTROL_PORT |= (CART_BIT | RD_BIT);
return data;
}
{
// Address lines as outputs, init to 0x00
ADDR_DDR_0 = 0xFF;
ADDR_DDR_1 = 0xFF;
ADDR_PORT_0 = 0x00;
ADDR_PORT_1 = 0x00;
// Init address latches to 0x00 and enable their outputs
delayMicroseconds(1);
LATCH_PORT |= (ADDR2_BIT | BANK_BIT | EX_BANK_BIT);
delayMicroseconds(1);
LATCH_PORT &= ~(ADDR2_BIT | BANK_BIT | EX_BANK_BIT | LATCH_OE_BIT);
// Data line defaults to input (read mode)
DATA_DDR = 0x00;
// Enable pull-up to keep data line from floating
DATA_PORT = 0xFF;
// Control lines as outputs, pulled high
CONTROL_PORT |= (CART_BIT | RD_BIT | WR_BIT | RST_BIT);
}
uint8_t ReadByte(uint16_t address)
{
// Set data line as input, pulled high
DATA_DDR = 0x00;
DATA_PORT = 0xFF;
// Pull all control lines high
CONTROL_PORT |= (CART_BIT | RD_BIT | WR_BIT);
// Set up address
ADDR_PORT_0 = address & 0xFF;
ADDR_PORT_1 = (address >> 8) & 0xFF;
delayMicroseconds(1);
LATCH_PORT |= ADDR2_BIT;
delayMicroseconds(1);
LATCH_PORT &= ~ADDR2_BIT;
// Pull CS low, then OE low
CONTROL_PORT &= ~CART_BIT;
CONTROL_PORT &= ~RD_BIT;
delayMicroseconds(1);
// Read data
uint8_t data = DATA_PIN;
// Pull all control lines high
CONTROL_PORT |= (CART_BIT | RD_BIT);
return data;
}
Any ideas what I'm doing wrong?