6502 bit-banged serial code examples?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
User avatar
Michael
Posts: 633
Joined: 13 Feb 2013
Location: Michigan, USA

6502 bit-banged serial code examples?

Post by Michael »

as the title suggests, can anyone point me to code examples for bit-banged serial, please? I'd like to use a 6522 but the hardware doesn't matter that much.

tia. cheerful regards, Mike, K8LH
User avatar
GARTHWILSON
Forum Moderator
Posts: 8774
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: 6502 bit-banged serial code examples?

Post by GARTHWILSON »

For synchronous serial, I have sample code for SPI at http://wilsonminesco.com/6502primer/SPI.ASM, and for I²C in various forms at http://wilsonminesco.com/6502primer/GENRLI2C.ASM . For asynchronous (mostly meaning RS-232, but it could also be RS-422 or RS-485 with the right line drivers and receivers), someone posted code here on the forum for doing 56kbps on a 1MHz 6502 IIRC. :o
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
jds
Posts: 196
Joined: 10 Mar 2016

Re: 6502 bit-banged serial code examples?

Post by jds »

If you could find a listing of the TIM monitor ROM I’m pretty sure that it uses bit-banged serial on the 6532. The monitor listing is in the TIM manual and should be easy to find.
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: 6502 bit-banged serial code examples?

Post by Dr Jefyll »

I posted some SPI routines for 6522 here. There're also some suggestions regarding which port bits to use for what. The priority is speed, and the routines require less than 20 clocks per SPI bit.

-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: 6502 bit-banged serial code examples?

Post by BigEd »

A previous thread cooks up a serial driver, and also links to MartinB's implementation (UPURS) as seen on stardot: Edit: and a couple of our mos6502 weekly posts too, indexed here:
plasmo
Posts: 1273
Joined: 21 Dec 2018
Location: Albuquerque NM USA

Re: 6502 bit-banged serial code examples?

Post by plasmo »

Bitbang serial receive is more difficult than bitbang serial transmit. CRC65 has a hybrid solution where the serial receiver is in hardware (implemented in CPLD logic) but bitbang the transmitter to save CPLD resources. The code for bitbang transmitter is here, viewtopic.php?f=6&t=6440&hilit=Bitbang+ ... =15#p81149
Bill
pzembrod
Posts: 22
Joined: 05 Sep 2020
Contact:

Re: 6502 bit-banged serial code examples?

Post by pzembrod »

pagetable.com has some of the imho best commented C64 Kernal listings where you can find both:

Synchronous bit-banged serial: The serial IEC send (CIOUT) and receive (ACPTR) routines:
CIOUT: https://www.pagetable.com/c64ref/c64disasm/#EDDD
ACPTR: https://www.pagetable.com/c64ref/c64disasm/#EE13

Asynchronous bit-banged serial: The RS232 code, hidden within the BASIN and BASOUT routines:
Output to RS232: https://www.pagetable.com/c64ref/c64disasm/#F208
Input from RS232: https://www.pagetable.com/c64ref/c64disasm/#F1B8
I find the RS232 code harder to understand (in fact, I really don't understand it) as it uses CIA-2 timer based NMIs.
User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Re: 6502 bit-banged serial code examples?

Post by 8BIT »

I did the software for Lee Hart's "6502 Badge". That used the IRQ pin as the serial receive. Output was created by storing an 8 bit write to the EPROM area in a latch. Bit 7 of that latch was the serial TX.

The software used cycle counting to generate a 9600 baud half duplex signal. It included a 128 byte receive buffer to help with xmodem file transfers.

More info can be found here -> http://sunrise-ev.com/6502.htm

Daryl
Please visit my website -> https://sbc.rictor.org/
Post Reply