Hello, I am making a new general purpose 6502 machine. The idea is to build a machine I can use to enter and run all the programs from the 80s Usborne books around at that time (that I fondly remember and am busy buying on eBay when I see them). Books like "Computer Space Games" and "Computer Battle Games" and so on. All simple little games really.
The machine has a 6502 running at 1MHz, 16K of RAM, 32k of ROM and various IO. On the main board is a 6522 VIA I am using for the keyboard and other things (speaker/bleeper, stopping the processor using the Woz circuit when a debug bit is set), an 8 bit latch with LEDs attached (blinken lights - useful for debugging) and a 6551 CIA which I am using to do my video display. For that I am using a Atmel based video generator from Batsocks:
http://www.batsocks.co.uk/products/Other/TellyMate%20TTL%20Kit.htmI was going to use my own Arduino based system I have previously used in an Arduino port of the Taipan! game but the Batsocks one uses a better processor and give me a higher resolution but still works in the same way as my Arduino one.
It uses TTL serial so I have it connected to the 6551 to drive it. The actual machine will have further I/O added later as additional boards. The Batsocks outputs a composite video signal that I have going to a little LCD monitor.
The issue I have is when I send data to the display it is all garbled. But in an odd way. Upper/lower case characters are sometimes outputted fine. Numbers and symbols are not.
So I am trying to output: "ORWELL V0.1 ABCDEFGHITJKLMONOPQRSTUVWXYZ 0123456789 abcdefg"
But I get: "OÒ×ELL Ö°.± ABCDEFGHIÔJKLMONOÐÑÒÓÔÕÖ×ØÙÚ °±²³´µ¶·¸¹ abcdefg"
Yes, I have a typos in the alphabet! ORWELL is the name of the machine by the way since it's a good name for a machine that's meant to be from 1984!
At first I thought it was a baud rate issue or something to do with the crystal (and 22pF cap). I replaced the crystal with a can oscillator and it didn't help.
The baud rates are correct. I can change the rate and I still get the same sort of garbled display if the receiving end is set to the same rate. I am using 8 N 1 by the way.
If I drive the display module from a different serial source (an Arduino) it displays fine.
I rigged up a MAX232 and piped the serial output from the CIA into my PC serial port (and old PC with a real port since I use the same one to run the ROM burner though it's real parallel port). The output I get on the PC matches that on my little screen. So I know the serial I am getting out is garbled. The string looks correct in the code I am burning to the ROM.
But I can't figure out why? On the CIA I have /CTS wired to ground. I haven't done anything with the other pins. I think I have it configured to be no parity, no echo, no interrupts.
one thing I did notice this morning is the /IRQ line seems to be low with the odd positive pulse. That seems odd? I have no interrupt handler in the code yet. The code I am using is below.
The machine is at the very early stages so this is just some code to make things work for testing. If just counts up on the LEDs on the I/O port, toggles the pins on the VIA back and forth and outputs the string. Sorry for the messed up comments formatting.
Code:
interrupt = $FFFE ; Interrupt vector.
IO = $6000 ; Top of I/O space. 8 bit buffer.
via1 = $5000 ; VIA 1 I/O.
via1_b = via1 + $0 ; VIA port b.
via1_a = via1 + $1 ; VIA port a.
via1_bdir = via1 + $2 ; VIA port b direction 1 = output.
via1_adir = via1 + $3 ; VIA port a direction 1 = output.
via1_pcr = via1 + $C ; VIA peripheral control register.
via1_ier = via1 + $E ; VIA interrupt enable register.
cia1 = $4800 ; CIA 1 I/O.
cia1_d = cia1 + $0 ; CIA data register.
cia1_s = cia1 + $1 ; CIA reset/status register.
cia1_cm = cia1 + $2 ; CIA command register.
cia1_ct = cia1 + $3 ; CIA control register.
count = $3FFF ; Counter.
.ORG rom_start
;Initilisation.
LDA #$00 ; Load ACC with 0.
STA count ; Set the counter.
; Set VIA1 port up.
LDA #$FF ; Load ACC with b11111111.
STA via1_adir ; Set VIA port a all output.
; Set up serial output.
LDA #$1F ; Set up for 19200/8/1.
;LDA #$1E ; Set up for 9600/8/1.
;LDA #$1C ; Set up for 4800/8/1.
;LDA #$1A ; Set up for 2400/8/1.
STA cia1_ct ; Write to CIA control register.
LDA #$0B ; Set up N parity/echo off/rx int off/dtr active .
STA cia1_cm ; Write to CIA command register.
; Simply loop around incrementing the counter and twiddling bits on the VIA and sending serial data.
loop
INC count ; Simply increment the counter.
LDA count ; Load the counter.
STA IO ; Write to the IO port.
LDA #$55 ; Data b01010101.
STA via1_a ; Push it to the VIA port a.
LDA #$AA ; Data b10101010.
STA via1_a ; Push it to the VIA port a.
LDA string1 ; Load the length of the string into the accumulator.
BEQ done ; Check if it is zero length.
LDY #$0 ; Set index to the first character.
output_string1
LDA string1 + $1, Y ; Load up the next character.
JSR send_serial ; Send the character.
INY ; Increment.
CPY string1 ; Have we copied them all?
BNE output_string1 ; No so keep going.
done
JMP loop
; Strings.
string1 .STR "ORWELL V0.1 ABCDEFGHITJKLMONOPQRSTUVWXYZ 0123456789 abcdefg"
; Serial send subroutine. Bung the byte to send in A.
send_serial
PHA ; Save accumulator.
cia1_Wait_TX
LDA cia1_s ; Read CIA staus register.
AND #$10 ; Check if the TX buffer is empty.
BEQ cia1_Wait_TX ; Wait if not.
PLA ; Restore accumulator.
STA cia1_d ; Send to CIA data register.
RTS ; Return.
.ORG reset
.WORD rom_start
There must be something blatantly wrong I am doing but I can't see it!
Any thoughts of advice? What I was going to try next is putting the same data byte I am sending to the CIA to my debug LEDs to see what it looks like and also trying to capture the sending of the byte sent from the serial output to see what that is.
Thanks!
Simon