Sunday 30 April 2023

6502 : BEN2 : Terminal and keyboard

 Intro

In the last post on 6502 a week ago I described how I was able to blink an LED and display LCD messages.  LCD displays become very boring very quickly and input has to be facilititated with buttons which dont give much capability.  Clearly the ideal solution is to use a screen and keyboard.  In the past Ben has developed a keyboard interface and a video card interface but neither of these is particularly easy or suitable for my computer.

Back in 2021 when I first got to this stage I followed Dirk Grappendorf's tutorial to attach an ACIA serial UART to my original 6502 system.  This allowed me to connect the 6502 to my PC and I could use a Putty serial terminal session to display output from the 6502 and input information/commands at the keyboard.  This is the perfect solution for me as I don't want a separate screen and keyboard kicking around so it forms the next objective for my project.

 Hardware

Very recently, in the last month, Ben has released a tutorial on connecting an ACIA UART to the 6502 system.  His hardware schematic is very similar to the one Dirk provided and I was able to use it as my guide 



There isn't any more space on my BEN2 board so I need to use the CPU headers to extend 6502 busses and control signals to a breadboard add on.  It was always my intention that BEN2 should focus on CPU, memory and VIA like Ben's original project.  My aim is build a new board JON2 which will have an ACIA on the main board and VIA, LCD plus other peripherals on a separate board.  The current project helps me to finalise wiring required for the ACIA and develop useful software for it.

The breadboard layout is quite straightforward and easy to connect up:


Test Connectivity

Using Ben's schematic the ACIA can be addressed at $5002 (COMMAND) $5003 (CONTROL) and $5000 data.  Our first 6502 assembly program (serial-1-transmit) simply sends three values to these registers.  The command and control instructions setup the serial communications parameters and the third sends a character from the 6502 to the screen.


We set up an FTDI cable attached to the ACIA/UART RX/TX wires and attach the other end to a PC USB port.  We can check which port the FTDI cable is using with the Device Manager and start Putty using the appropriate serial parameters on that port.  Now we can single step through the program and a few seconds later we see, beautiful in its simplicity:

We can also use the Arduino monitor to see what happens each clock cycle.  In the picture below you can see that commands are written in cycles 17 and 23.  The character "j" (0x6A) is written in cycle 29.

The next program (serial-2-send-message) outputs a text string to the screen, waits for input and repeats a prompt each time a character is received.  The program logic includes waiting for transmit buffer to empty before sending the next character.  The program worked fine on slow clock speeds but became unreliable at 1000Hz and above - not much use to me.

These programs were implemented by copying previous programs from my board "JON" and modifying the memory addresses.  The third serial program (serial-3-title-input-subs) started to organise the code into subroutines:
init_acia  initialise communications parameter
putc        display a character
putstr      display a string
getc        input a character
It also incorporated a subroutine "short_delay" into putc to provide an extra gap between characters of about 500 cycles (0.5 milliseconds).  Once this was incorporated the clock worked fine upto full speed 1MHz which is great news.

Basic monitor commands and subroutines

I now needed a set of subroutines to control output to the hardware.  We start off with basic subroutines to display characters and strings on terminal and LCD.  We also need the ability to output hex addresses.  These were very simple to convert from versions working on  previous hardware.  They mainly just needed the hardware memory addresses used for the terminal updated.

With these building blocks I could set up a simple monitor.   It reads a character from the terminal and carries out the associated command:

l               echo a capital L
m            show register values
n             show some LCD values
o             memory dump
p             print a newline character



The follow on shell program (monitor-3-shell-2) is more useful and contains the tools we will need going further.  It allows hexadecimal address input and allows us to jump to a specified address, jump into a subroutine at a specified address or display a range of memory.  All these are great for debugging.


End note

I am very pleased with progress over the last week.  We have been able to take programs that worked previously  (18 months ago) and port them across to our new environment without major problems.

The one main area I have put to one side is the use of ROM for library subroutines.  The current monitor program takes about 30 seconds to load; it is about 1400 bytes in size.  I could reduce this considerably by storing subroutines in ROM.  However that will introduce another set of reliability problems so I am leaving it for the moment.  It may be good to keep the monitor in a separate area of memory and just load a stub program and anything that needs testing at $8000.

The hardware and software have been working reliably and provide me with a platform to move forward to the objectives I previously had issues with.  In particular I aim to get xmodem working.  This will allow me to run programs in RAM and dispense with the Arduino Mega load process. 


No comments:

Post a Comment