Instead of using an Ardunio to Program an EEPROM i thought why not use the Arduino as ROM itself?
So i made this small code to use my Arduino 2560 as potential 64kB ROM. in this small program i only used 16B though.
int ROM[16] = {0x00, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
word Address;
int Prev;
int Current;
void setup() {
DDRA = 0x00; //Pins 22-29 (lower 8b of Address Input) 22 = 0, > 29 = 7
DDRC = 0x00; //Pins 30-37 (upper 8b of Address Input) 37 = 0, < 30 = 7
DDRL = 0xFF; //Pins 42-49 (8b Data Output) 49 = 0, > 42 = 7
Prev = 0xFF;
Address = 0x0000;
Serial.begin(500000);
}
void loop() {
Address = word(PINC,PINA); //Combines PORTC and PORTA into a single 16b Value
PORTL = ROM[Address]; //Reads from the ROM Array and puts it onto the Data Output
Current = Address;
if(Prev != Current){ //If the Address from one cycle beofre is the same as the Current one it will not print anything on the Serial Monitor. to keep it clean
if (PORTL < 0x10 ) {
Serial.print("$0");
}
else{
Serial.print("$");
};
Serial.print(PORTL, HEX); //Prints the Data on the current Address as HEX with leading 0.
Serial.print(" ");
if (Address < 0x0010 ) {
Serial.print("$000");
goto EOSP;
};
if (Address < 0x0100 ) {
Serial.print("$00");
goto EOSP;
};
if (Address < 0x1000 ) {
Serial.print("$0");
goto EOSP;
}
else{
Serial.print("$");
};
EOSP:
Serial.print(Address, HEX); //Prints the Currently accessed Address as HEX with leading 0s.
Serial.println();
Prev = Current; //Sets the used Address as the "previous" one, so it can be compared next cycle.
};
}
now al lthis code does is that it takes a usermade Array as Storage, and if anything accesses some Address it will present the Data on that Address to the output. it also shows the currently accessed address and Data on it over the Serial Monitor.
The problem with it is that it doesn't appear to be working on a Hardware level. The Program itself works fine i can see what data is there on the Monitor and on my connected LEDs, but the CPU i wanted to test this with doesn't appear to be getting the Data correctly
I'm trying to test a Z80 CPU with this, so as seen in the code i made a single Program that looks like this:
NOP
NOP
NOP
NOP
JP, $0000
HALT
usually this would make the CPU just jump to the first address over and over again. but it doesn't work. the CPU starts to access data very weirdly.
here is the log of the Serial Monitor while i was wirting this.
This confuses me greatly and i have no idea why this is a thing.
and i couldn't think of anything that i pinned wrong. i mean you are supposed to pull down/up input and output pins right? like every single pin (even the clock) has a Resitor to either pull it high or low.