In its current state, I have made the 6502 read NOPs (EA) and seen the program counter increment the address lines after each execution. I want to be able to run programs on my computer, to do this I will need somewhere to store those programs.
What I now want to add is some ROM. I will be using a 28256. The 28256 is a flash ROM, with a capacity of 256K (32K x 8).
Just as the 6502 has a data and address bus, so does the 28256. However, there is a problem that needs to be overcome – they do not have the same size address bus. The 6502 has 16 address line (A0 – A15) and the 28256 has 15 address lines (A0 – A14). This means that the 6502 can see from 0000000000000000 – 1111111111111111, which is FFFF in hex. This means that the 28256 can ‘see’ from 000000000000000 – 111111111111111, which is 7FFF in hex. One solution is to use the fact that the most significant bit (A15) of the 6502 will be high when at addresses that the 28256 cannot reach. If I connect A15 from the 6502 to the chip select pin on the 28256 (which is active low), when A15 is high, the 28256 will be off.
This solves one problem but creates another! When the 6502 is turned on and has been through its startup sequence, it looks in FFFC and FFFD for a program to execute. Any program that I have on the ROM would not be read, since the ROM cannot see anything in that range. One solution is to invert the bit from the A15 connection from the 6502 to the chip select on the 28256. This then alters the addresses that the 28256 can see to the range of 8000 – FFFF.
I can use an inverter to reverse the bit coming from the A15 of the 6502. I have removed the 8 resistors that I used to make the 6502 read NOPs. The circuit now looks like this:
Previously I mentioned that the 6502 that I’m using can work up to 14MHz (and maybe higher) but factors (such as other components) can limit the theoretical speed. The ROM is one of this components. Looking at the datasheet I can see that the read access time is 150ns. This means that the clock speed cannot be faster than 7MHz. Some of you may think that 150ns works out to close to 14MHz but this is not the case with a 6502! This is because the 6502 accesses memory on half of a clock cycle! In theory I would need a ROM with at least a 70ns read access time. However, it would be interesting to see how much the ROM speed can be pushed.
To test that the 6502 can read my programs, I will replicate the previous experiment in software. I will write a program in machine code that will make the 6502 read NOPs. If it works, I should see the same result as previously – the address being incremented.
rom = bytearray([0xea] * 32768)