The thread over at
viewtopic.php?f=2&t=5862 gave me a fantastic introduction to actually getting to grips with the W65C134SXB.
I have a nice collection of Raspberry Pis, Arduinos and Teensys - and I've always had something up and running pretty quickly with them. But the W65C134SXB pretty much had me stumped at the beginning - even how to just run a program! Documentation and support communities are nowhere near as widespread as, say, the Raspberry Pi.
Consequently, that post gave me my first opening into understanding how to operate this board. Many months later, many 6502.org posts digested, many datasheets and 6502 books read, I have progressed from absolute newbie to newbie.
In the spirit of sharing, I'd like to give back some more of what I have learned to make it a little easier to deal with this SBC and take the next step on from printing a message to the console.
The previous thread mentioned outlines EasySXB and its use, so I won't go over that as the article does a fine job in that respect. EasySBX is how you communicate with the W65C134SXB.
However, for writing code, I use the Kowalski 6502 Simulator with 65C02 processor option selected. This is for a couple of reasons: you can obviously simulate and trouble-shoot code easier and, using the "File > Save Code" menu item allows the export of your code in either srec or hex formats.
To progress to a slightly more complicated use of the W65C134SXB, I decided I'd code some delays and toggle a pin that I could hook up to an oscilloscope to see if my timings were about right.
Port 4 of the W65C134SXB is a bidirectional port and, after a reset, the Port 4 data register is set to all "0"s (i.e. inputs). Memory mapping for Port 4 is as follows...
Code:
Port 4 Data Register (PD4) - $001C
Port 4 Data Direction Register (PDD4) - $001E
Taking what I have learnt from using the 6522 VIA on my own breadboard SBC, those terms looked familiar. However, the documentation at this point (for me) didn't seem overly clear as to which pins related to Port 4 and there was much flipping between the W65C134S datasheet and the W65C134SXB datasheet. I got it in the end.
Code:
Pin numbers for W65C134S (80 lead QFP)
P40 (Port 4, bit 0) = Pin 14
P41 (Port 4, bit 1) = Pin 15
...
P47 (Port 4, bit 7) = Pin 21
The W65C134SXB datasheet shows the following for J3 which is, confusingly, called "P4x Connector" and is a 2x5 male connector located to the top right of the board. The little dot on the PCB indicate pin 1 of the connector.
Code:
Pin Signal Name
1 VDD
2 VSS
3 P40 / NMIB
4 P41 / IRQB
5 P42
6 P43
7 P44
8 P45
9 P46
10 P47 / DSRB
P45 appealed to me
(
a UK joke) so pin 8 of Port 4 it was (bit 5)!
The W65C134SXB runs at 3.6864 MHz so I did some calculations around that to come up with the delays using code I found on 6502.org (thanks again!) and made adjustments to take into account the code in the main loop which toggles bit 5 of Port 4 and calls the delay subroutine.
Code:
00001 ; Generate a squarewave using delay routine.
00002 ; 1ms delay between bit inversions will equate to 2ms wavelength.
00003 ; The delay subroutine has been tweeked to take into account the
00004 ; timing of the main loop code to get as close to a 1ms loop.
00005 ; Not super accurate, but good enough for experimental outcome.
00006
00007 001C Port4 = $1C ; Port 4 Data Register. (zeropage)
00008 001E PDD4 = $1E ; Port 4 Data Direction Register. (zeropage)
00009 0010 P45 = @00010000 ; PDD4 I/O settings - bit 5 as only output. Pin 8 of J3.
00010
00011 000800 .ORG $0800
00012
00013 000800 A5 10 LDA P45 ; Load PD45 bit 5 mask.
00014 000802 85 1E STA PDD4 ; Set bit 5 of Port 4 as output.
00015 mainloop
00016 000804 A5 1C LDA Port4 ; Load the 8 bits of Port 4.
00017 000806 45 10 EOR P45 ; Flip bit 5 in Port 4.
00018 000808 85 1C STA Port4 ; Store back into Port 4.
00019 00080A 20 0F 08 JSR delay_1ms ; Call delay subroutine A & Y are destroyed.
00020 00080D 80 F5 BRA mainloop ; Loop forever.
00021
00022 ; ============================================================
00023 ; Delays based on 3.6864 MHz clock frequency.
00024 ; 1 clock cycle = 0.27127 us.
00025 ; Delay = 9 * (256*A + Y) + 8 cycles.
00026 ; ============================================================
00027 ;
00028
00029 ; 1ms delay = 1,000 us = 3,686 clock cycles.
00030 ; A = 1, Y = 149, Delay = 3,687 clock cycles..
00031 delay_1ms
00032 00080F A9 01 LDA #1
00033 000811 A0 95 LDY #149
00034 delay_1ms_loop
00035 000813 C0 01 CPY #1
00036 000815 88 DEY
00037 000816 E9 00 SBC #0
00038 000818 B0 F9 BCS delay_1ms_loop
00039 00081A 60 RTS
The outcome of all of this...
The W65C134SXB board itself.
The scope trace showing the timing is there.
Hope this helps some folk out in how to get more from their W65C134SXB.