In my previous 6502 post Ben showed (video #1) how to connect up the microprocessor with a few inputs so that it would run through its boot sequence. We used an Arduino Mega to monitor address and data lines so that we can see what is happening.
We now need to write a program (video #2). We know that the 6502 reads the program start address from the reset vector at 0xfffc and 0xfffd so we have to provide some hardware (memory) which is addressable. By that I mean we attach the address/data lines on the 6502 to address/data lines on a memory chip and when requested the memory chip will look at the address lines and respond with the bits at that address on the data lines.
For the program memory we use an AT28C256 32KB EEPROM. This has to be configured with a special programmer, we use a TL866II Plus programmer to write our information on to the EEPROM. The first step is to define a machine code program which the 6502 will understand. We then need to create a file containing the program and, using the programmer copy it across to the EEPROM. Ben uses Python to write a file called rom.bin which is exactly 0x8000=32KB long. The programmer copies this to the EEPROM which can then be attached to the 6502.
In order to see some results we need the 6502 to produce some output. Using a cunning scheme Ben arranges for the EEPROM input to use memory addresses 0x8000-FFFF leaving addresses 0x0000-0x7FFF for output. A multipurpose output chip called a W65C22 Versatile Interface Adapter is attached to address/data lines (lets call them busses from now on). We will use it to latch information from the data bus to an output port. We attach LEDs to the output port so that we can see the results. Another cunning scheme is required so that the W65C22 reacts when the 6502 sends to addresses 0x6000.....
Now we have hardware attached where we can store our program and we can control an output device. A short machine code program is written to configure the W65C22 for output, write output patterns to the LEDs and loop around. Awesome.
This is a packed hour long lesson, at the end of which we should understand programming an EEPROM, ROM addressing, latching output, using an output chip and writing machine code. Wow.
After the steep learning curve of video #2 we consolidate our position in video #3. Writing machine code quickly gives you a headache and it is much easier just to write the assembler code and ask an assembly program to convert it. Video #3 shows you how to install and use vasm to create rom images which can be loaded into the eeprom. This results in another LED program which is demoed below.
No comments:
Post a Comment