After a few days struggling to get my ACIA daughter board not to work on my BE6502 style machine I was running out of hair to pull out.
I figured out that the Rockwell version of the chip had an internal resistor and capacitor for the oscillator. I tried using the tx flag code and the delay workaround for the defect in the WDC version of the chip. Do I have fake chips?
I gave up and ordered myself some 68B50 ACIAs from JameCo instead. What to do in the meantime to make progress on the software side? My goal is to create a more modern development environment for these 65C02 machines on my PC that communicates using RS232. Getting WozMon, Steve Wozniac's original monitor for the Apple 1 from 1976, up and running seems like a good intermediate step.
The idea of emulating an ACIA-style port chip came to mind and a dusty old Arduino Uno stepped up to the task. Yes, it won't cope with much more than a 1kHz clock speed but that should be fine to kick the can down the road until my 68B50 arrives.
Interfacing the UnoWhile using my Mega as a debugging probe I figured out a better way of making it easy to plug in and unplug ribbon cable jumpers. You just need some sturdy insulation tape.
And I also highly recommend a label printer. Mine is a Brother P-Touch Cube driven wirelessly from a phone app.
The Ardunino Uno only has two pins which can drive interrupts (2 & 3). You also need to avoid using TX & RX (1 & 2) since they are used by the serial interface between the Uno and the PC, and we're going to need that. So, with those constraints, here are the pins on the Uno with their corresponding functions on the 65C02 board:
- P2: clock - PHI2
- P3..P10: data - D0..D7
- P11: register select - A0
- P12: chip select - from your 65C02 address decoding (active low)
- P13: read/write - RW from your 65C02
The register select simulates two registers mapped at consecutive memory addresses: a status/control register and a data read/write register, much like the ACIA chips have.
ConsoleI had some success with PuTTY on Windows. I used mostly default settings for serial but here are some helpful configuration screens.
The full code is attached. The interesting bit is in the onClock()
function. This function responds to the falling edge of the 65C02 clock. For 65C02 reads (when the Uno is writing), this does not pose a timing problem: we get the data on the bus in time.
When the 65C02 is writing we have a bit of a timing issue since the data is only valid on the bus in the 2nd half of the clock cycle. I solve this with a delay and since my slow clock is running at 1kHz, each full cycle is 1ms (1000us) and so a delay of 750us puts us in the centre of the high half of the clock cycle when the data written by the 65C02 is supposed to be stable.
The other half of the functionality is in the regular Arduino loop() which deals with Serial.read()
and Serial.write()
on the PC side.
I avoid opening the Serial Monitor in the IDE because it isn't a true console. After uploading to the Uno, I switch to PuTTY to interact.
Minimalist 65C02 Console ProgramThe simplest way to test this is to take each key received from the keyboard via the serial cable and echo it back to the console. Aside from a single instruction to "reset" our ACIA emulator, the code for this echo round trip is fairly brief.
I also emit a prompt at the start, OK
, just to get some feedback in PuTTY that things are working.
Watch Ben Eater's video on the subject to get the general gist of what is involved.
I made similar edits to Ben:
- replacing
KBD
,KBDCR
,DSP
andDSPCR
IO registers with my Uno versions (and changing the conditions for key available and buffer full) - changing the key codes from legacy Apple 1 codes to regular ASCII
- edits around STOR mode selection logic
My version also still fits within the 250 available bytes in the top page of memory. I do cheat though : my IO ports are mapped to the zero page (which I discuss in my project about using a CPLD for address decoding) and this makes the port access instructions 2 bytes long rather than 3.
Full code is attached for both the Arduino emulator and the modified version of WozMon that works with it. If you have questions or get stuck, go ahead and comment below.
CreditsOnce again, Ben Eater gets credit for driving me back toward my roots.
Of course, Steve Wozniak is the inspiring legend behind the entire home and hobby computing revolution that started almost 50 years ago.
Comments
Please log in or sign up to comment.