Scope
The MON5 update contains no new functionality. It comprises some hardware changes which seemed very straightforward but have required some hard work.
- Add an LED indicator on the shift register display when interrupts are enabled.
- Update the "write-byte" option to use PB1, PB0 to control ROM write enable.
- Update the write-romx monitor download/upgrade program to use PB1, PB0
- Update music program to use PB2 instead of PA1
- Move breadboard components for shift registers/LEDs and sound to soldered AMI board.
- Amend individual bits in VIA registers rather than overwriting complete contents
Change pins used for write-byte menu option
One minor change in MON4 was converting HD44780 LCD to 4-wire control, which freed up 4 VIA pins PB0-PB3. Within MON4 I was aware that it was dangerous to share PA4 and PA3 between LED display and ROM-write functions. My work-around was to only connect PA4,3 when required to update ROM code.
With the extra pins now available I decided to use PB1,0 instead of PA4,3 to control ROM writing. PB1,0 will not be used for other functions which makes it safe to leave wires connected all the time. Previously PA4, PA3 attached LEDs provided handy indicators to show write-ROM operations so I also need to set up an LEDbar LED to indicate that ROM is being written.
Previously when writing to VIA CONFIGA/B and PORTA/B registers I have simply written an 8-bit value over-writing existing contents. It is preferable to only update the specific register bits required for a specific operation, to avoid unwanted side effects. The registers can be read as well as written and individual bits can be updated using appropriate AND, OR, EOR operations before writing back the updated values.
For extra security I decided to leave PB1, PB0 as inputs unless a write-ROM operation is in progress, this helps prevents accidently writing values to those pins.
Now that PA4 and PA3 are not connected to write-ROM pins (ROM/WE and ROM/OE) it is actually safe to leave the code which updates them in place. I do this so that we can actually load code by reconnecting those wires if necessary and we have an extra visual indication that write-ROM is taking place.
The menu option " write ROM" requires code to be copied from ROM to RAM, then executed in RAM whilst the ROM is unavailable (for reading instruction) during the writing process. For the copying process to work, there must be no absolute addresses in the "RAM code", which means there must be no subroutine calls. I had a clever idea that I could incorporate a subroutine, providing it was copied to RAM with the other code. It was a bad decision.
Change write-romx download program
Back in July as part of MON2 I developed a program write-romx which uses xmodem to download a program to RAM and then copies it to ROM. It was an excellent innovation and allowed me to finally detach the Arduino Mega "umbilical cord" I was previously using.
It works fine and hasn't needed updating since then. I now need a new version to use PB1, PB0. Although it is a standalone program some of the system subroutines it uses, together with the shared memory map have been updated since it was written, and I should carry out a general update.
Unfortunately I underestimated the pitfalls of this task and rushed into a quick implementation. Sadly, when the new version I was testing went wrong it over-wrote crucial parts of the ROM and made BEN2 unusable.😢
I had a backup ROM chip with the MON2 image loaded so I was able to update a copy of the MON2 ROM to MON3 and then to MON4. After wasting a couple of days I was back on track.
I then proceeded very carefully to make changes to write-romx, testing each small change I made. I found that the local subroutines with the RAM copy program were a very bad idea - I overlooked some detail (perhaps with the JSR mechanism) which stops them working.
Somewhat chastened and a little bit wiser, and at a slow but steady pace, I successfully updated write-romx.
Board Update
By the time MON4 was complete I had a breadboard hanging off the computer containing a shift register and LED together with a speaker connection.
When I created the AMI daughter board, there was some unused space and it was always my intention to add new hardware to AMI when appropriate.
Despite putting a lot of effort into making it easy to detach the board I was nervous about doing so. At worst failure would mean BEN2 could never be resurrected.
I carefully noted connections as I removed them from AMI, until AMI could be dismounted from its stand was available for me to solder.
My soldering is improving and I was very careful to position the connections carefully as I worked. On completion I checked the board for shorts between adjacent tracks and continuity tested all the connections.
Reconnecting AMI I was very pleased to see that BEN2 was still working and, after some minor tweaks the new shift-register/LED-bar and sound were working as well.
I dont know whether this is the final version of the BEN2 hardware but it must be close.
Documentation Update
A major part of the cutover work was bringing the schematic and board layouts up to date. One would normally expect to update these before doing the work, but as the changes developed gradually I could add them in easily enough. I will add the latest diagrams to this blog - I almost think they are artistic.