Add crystal oscillator
Up until now the computer was run either by a fairly slow 555 timer or even slower single stepping. This was possible because the WDC-65C02, unlike the R-65C02, can be run by any clock from 0 … 14MHz. It's time to speed things up. Not to the full 14MHz — that might cause problems on a breadboard. Because of this only a 1 MHz oscillator is used.
Insert a 1MHz crystal oscillator
Unlike Ben Eater I permanently attached the clock module to the system so it's always ready if some debugging is needed. I also added a helpful jumper cable to quickly change between the crystal oscillator and the clock module:
Jumper cable
I have ordered a switch to be places where the jumper cable is currently for even more convenient switching. Next an update of the software is needed as the computer is now a lot faster than the display clear operation. And for all other operation it's right at the border. Best to add a busy check to all display operations:
;;
; Wait for instruction to finish
;
.proc Wait
PHA
VIA_Set_B #%00000000 ; Set Port B to all input
Busy: VIA_Out_A #LCD::RW ; Start LCD read operation.
VIA_Out_A #(LCD::RW | LCD::E) ; Enable Output if LCD status
BIT VIA::IRB
BMI Busy
VIA_Out_A #LCD::RW ; End LCD read operation
VIA_Set_B #%11111111 ; Set Port B to all output
PLA
RTS
.endproc
Using .proc
and .endproc
makes the Busy label local so it won't conflict with any future subroutine. Ben Eater also uses LDA
and AND
to check the busy flag. But that's not needed.
- When you load a value with
LDA
with the the negative flag is set when bit 7 is set. So theAND
instruction isn't needed as you could also do aBMI
(branch on minus) - The 65C02 also as a special instructions for checking bits in memory which is called
BIT
. TheBIT
operation performs andAND
between the accumulator and the address given and sets the negative, overflow and zero flag. As I'm only interested in negative flag I don't load the accumulator with any value.
You find the source code for the LCD macro on GitLab: 6502Tutorial — Kit/Library