Although I built ACIA into the 65C02GPD v1, I never got round to actually checking it. I'm now doing so as I want to include it in the 65C02GPD v2 but want to ensure that I've gotten it right. Also, the 65C02GPD v1 makes all ACIA serial-facing pins available where-as the redesign (v2) will have only the bare essentials required for serial comms as I need to save on space.
Would anyone mind doing a sense check on what I've designed? I'm still a little unsure on this despite having read Garth's primer a number of times. Don't worry about the 6502 bus/selects side, though - just need to check the port-side connections of the ACIA. Cheers!
Here's the circuit:
Attachment:
serial.gif [ 15.97 KiB | Viewed 1474 times ]
ALso, this is some test code for sending out '0123456789' continuosly as a test. This bit I'm also not sure about, but it sure as heck doesn't work on 65C02GPD v1. I'm still looking into it, but would appreciate knowing if the code is good.
Please note: This is an output test hence no IRQ code.
Code:
# ACIA output test
# Constants
vectorNMI = $FFFA
vectorIRQ = $FFFE
vectorRES = $FFFC
startcodeNMI = $E000
startcodeIRQ = $E200
startcodeRES = $EA00
maincode = $F000
delay40 = $C000
ACIA = $8200
ACIA_Transfer = ACIA + 0
ACIA_ResetStatus = ACIA + 1
ACIA_Command = ACIA + 2
ACIA_Control = ACIA + 3
# vector setup
PC = vectorNMI
EQUW startcodeNMI
PC = vectorIRQ
EQUW startcodeIRQ
PC = vectorRES
EQUW startcodeRES
# NMI handler
PC = startcodeNMI
RTI
# IRQ handler
PC = startcodeIRQ
RTI
# RES handler
PC = startcodeRES
LDX #$FF
TXS
SEI
CLD
JMP maincode
# main code
PC=maincode
# Reset the ACIA
LDA #0
STA ACIA_ResetStatus
# Control register
# 1 stop bit, 8 bits word length, Baud rate clock, 9600 baud
LDA #%00011110
STA ACIA_Control
# Command register
# Parity check disabled, Parity mode disabled, Receiver normal mode, TIC disabled, IRD disabled, DTR ready
LDA #%11001111
STA ACIA_Command
# send 0123456789
.sendstuff
LDA #48
.loop
STA ACIA_Transfer
JSR delay40
INC A
CMP #58
BNE loop
LDA #13
STA ACIA_Transfer
JSR delay40
BRA sendstuff
# my really rubbish software-base delay routine. does the job though.
PC = delay40
# save A, X, Y on to stack
PHA
PHX
PHY
# math
# 1 cycle = 1000ms
# 4.1ms = 4.1ms x 1000 = 4,100 cycles
# the following are in the loop
# LDY#2 = 2 cycles
# INY = 2 cycles
# CPY = 2 cycles
# BNE = 2+1 cycles
# NOP x4 = 4x2=8 cycles
# total: 19 cycles per loop
# 4,100 cycles / 19 cycles = 215.78 loops
# Round up to 240 loops
LDY#0
.loopDELAY40
NOP
NOP
NOP
NOP
INY
CPY#240
BNE loopDELAY40
# restore Y, X, A in that order
PLY
PLX
PLA
RTS