Sunday 11 September 2022

6502 Terminal

ACIA Serial Chip

My working 6502 system needs some input / output capability.  Ben Eater added a VIA (Versatile Interface Adapter) and attached an LCD display to his system.  I prefer to start with an ACIA (Asynchronous Communication Interface Adapter).  This provides me with a serial interface running at 19200 baud.

An ACIA chip was added to the breadboard and connected using an FTDI chip to a PC USB COM port.  The hardware allows me to use a Windows Terminal or Putty session providing a screen and keyboard interface.  I could attach a physical terminal, but they don't really exist anymore and a PC terminal session works just fine.  I did build a physical terminal using an LCD screen a while ago but I don't need it here.

Arduino Testing

My inspiration for the ACIA connection is Dirk Grappendorf who provides an excellent description and code to terminal I/O.  

To check my breadboard connections I designed a sketch which ran on the Mega without the need to use my CPU.  In fact I did have trouble getting the ACIA to work as an extra capacitor is required which Herr Grappendorf mentioned but I omitted as it wasn't shown on the datasheet.

The ACIA is controlled in a very simple manner.  Two bytes are written to the command and control registers specifying communication parameters.  Subsequently bytes which are inserted in the transmission register are sent to the FTDI and onwards to the PC terminal session.

6502 Machine Code


Once I was happy that wires and the ACIA were working I could write a very simple assembly program which writes the command register (address $4002) the control register (address $4003) and then loops to output a character (0x34, the digit 4) in the data register (address $4000).






The result is a 17 byte program which puts a steady stream of characters out on the terminal.  There isn't any synchronisation by the program to ensure that the terminal is ready for the next character before transmitting it, we simply send characters as fast as we can.


Add RAM

We dont actually require RAM for this version of the program to work.  RAM is required for the 6502 stack, which is used by the subroutine mechanism to store return addresses.  Adding a subroutine to the program allows us to check that RAM is still working.

Clock Speed

Initial testing is carried out using the Ben Eater clock, which is a 555 timer based solution which runs at speeds upto about 200Hz.  Previously I have built an Arduino nano-based clock which allows me to choose between a number of speeds 5 Hz, 50 Hz, 500 Hz and 5000 Hz.  When I substituted the nano clock into the system I found that it worked.  However, as expected, the system didn't work when the full-speed 1 MHz clock chip was connected.

Summary  

We have added a terminal to our 6502 system so that we can do input / output.  We wrote a very simple machine code program as a first test that output to the terminal works.  Normally the "terminal driver" would synchronise transmission and receiving but we had good results with a 5 KHz clock sending characters as fast as we could.
What we really need is a software environment to assemble and load programs so that we can better, more extensive programs - this will come next.




No comments:

Post a Comment