cc65 and RS232 User Port Serial

Basic and Machine Language

Moderator: Moderators

groepaz
Vic 20 Nerd
Posts: 570
Joined: Wed Aug 25, 2010 5:30 pm

Re: cc65 and RS232 User Port Serial

Postby groepaz » Mon Feb 13, 2017 4:00 pm

didnt they only update the timer values? mmmh

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Mon Feb 13, 2017 5:28 pm

For what it's worth, my RS232 usage is pretty much unidirectional (at any given time.) I only transmit a couple hundred bytes at most, to 'dial' the connection and make the HTTP request. After that I receive a big uninterrupted stream of bytes (from around 20K to 200K depending on the page.) Generally when I see corruption it could be anywhere in the middle of the stream, at which point I am not transmitting. Hence I don't think it is a problem with RX and TX interfering with one another.

Interesting comment regarding the multiple versions of the C64 ROM. Is this stuff documented somewhere? Is there more than one version of the VIC-20 ROM too I wonder?

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: cc65 and RS232 User Port Serial

Postby srowe » Tue Feb 14, 2017 2:06 am

Bobbi wrote:Generally when I see corruption it could be anywhere in the middle of the stream, at which point I am not transmitting. Hence I don't think it is a problem with RX and TX interfering with one another.


That's helpful to know, I don't think the NMI code is at fault then.

Interesting comment regarding the multiple versions of the C64 ROM. Is this stuff documented somewhere? Is there more than one version of the VIC-20 ROM too I wonder?


Other than PAL vs NTSC I'm not aware of different ROM versions for the VIC.

The C64 ROM disassemblies I've found are a bit incomplete, certainly in the RS-232 code. According to Zimmers we have three versions (excluding for localized keyboards):

901227-01
This 8-kilobyte 2364 ROM is the first revision of the Commodore 64 KERNAL. The RS-232 timing table is designed for exactly 1 MHz system clock frequency, although no C64 runs at that clock rate. Unlike later KERNAL revisions, this one does not detect the video system (PAL/NTSC). This KERNAL was probably only used in early North American Commodore 64 units.

901227-02
This 8-kilobyte 2364 ROM is the second revision of the Commodore 64 KERNAL. It is the second most widely spread version.

901227-03
This 8-kilobyte 2364 ROM is the third and essentially last revision of the Commodore 64 KERNAL. It is the most widely spread version.


So -01 isn't good reference material. I will continue to make detailed notes of all of the RS-232 routines in the -03 ROM and implement for the VIC.

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: cc65 and RS232 User Port Serial

Postby srowe » Tue Feb 14, 2017 2:08 am

groepaz wrote:didnt they only update the timer values? mmmh


No, from a casual look they made non-trivial restructurings of the code that handles the timers. This may be for VIA vs CIA reasons but I need to look at it more closely.

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Thu Feb 16, 2017 3:53 pm

It seems the behaviour of VIC-20 RS232 with or without the wedge is maddeningly inconsistent. Sometimes it runs through whole RSS feeds with no apparent errors. On other occasions it gets corrupt data almost straightaway and the parser hangs. I believe srowe's wedge makes things a bit better but since it is still not perfect it is hard to be sure without conducting a rigourous statistical test. Another interesting unanswered question is whether reliability is better on one VIC-20 or another (I have three to play with here, and a C64.)

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: cc65 and RS232 User Port Serial

Postby srowe » Fri Feb 17, 2017 2:33 pm

That sounds very much like a missed interrupt. Thinking about it the VIC routine can drop Rx interrupts if a pending Tx exists as well. Because NMIs are edge triggered leaving the ISR with bits unprocessed in the IFR won't result in the routine being called again.

Here's my attempt to copy what the C64 code does: process the Tx timer then check for Rx interrupts. It's untested.
Attachments
rs-232-fix-2.zip
(6.68 KiB) Downloaded 7 times

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Fri Feb 17, 2017 7:05 pm

I will give your new wedge a try and let you know how it goes! (Have to unplug the C64 and go back to the VIC-20 :))

Incidentally I found a bug in the RSS Reader code that was leading to memory corruption on VIC-20 (but which was relatively harmless on C64). Having fixed this, the VIC-20 version runs much more reliably. I have modem echo turned off to avoid full duplex communication, and I have some delays inserted into the code to allow the modem time to respond to various commands. With these workarounds the code runs relatively reliably on both VIC-20 and C64, even with the VIC-20 kernal code (no wedge.) However I do still see some failures - the most usual one looks like the modem just hangs up unexpectedly in the middle of reception but I haven't really looked into this in any depth yet.

I will release a new version of the RSS Reader soon with these fixes.

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Fri Feb 17, 2017 7:57 pm

First indications are that the new wedge works very well indeed :)
If that is your *untested* code, I am seriously impressed!

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: cc65 and RS232 User Port Serial

Postby srowe » Sat Feb 18, 2017 3:55 pm

Keep me posted how this works out, I've finished annotating the C64 code now and I can see there's a few other minor changes. Nothing to significant though.

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Sun Feb 19, 2017 10:16 am

I'll do some more testing over the course of the weekend and let you know how it works out. Looks encouraging so far though!

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: cc65 and RS232 User Port Serial

Postby srowe » Sun Feb 19, 2017 2:05 pm

Bobbi wrote:I'll do some more testing over the course of the weekend and let you know how it works out. Looks encouraging so far though!


I think there's still way to go to make it bullet-proof. I'm currently completely re-writing the ISR it's riddled with holes (hint: try hitting RESTORE (without RUN/STOP) while your program is receiving data).

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Tue Feb 21, 2017 7:07 am

I had the opportunity to do a good bit of testing on the weekend. I left the RSS Reader running in 'kiosk mode' where it cycles through a set of eight RSS feeds from either CBC or New York Times forever. The reliability is now much improved!! On occasion I was able to download and 'stream' RSS feeds for several hours at a time before a lock up. Other times it would lock up after a few minutes of runtime. Usually any failure was recoverable by simply quitting the program with RUN/STOP-RESTORE and running it again. No power cycle required (which was the case previously sometimes.)

When the RSS Reader freezes it is just as if data stops arriving from the modem in the middle of the XML document. The screen border stops flashing (I flash the border for each received byte which gives good info on timing too.) Sometimes when this happens the modem has gone back to 'Ready' state (as shown on the modem OLED display.) Other times the modem still thinks it is 'Connected'. Occasionally this happens immediately after I dial and connect - basically I make the HTTP request and don't get anything back. (This second one could be a different issue though - there are a lot of moving pieces here!)

Another interesting thing I noticed when cycling through the news feeds forever. CBC/NYT do not update their RSS feeds that frequently so sometimes it seems you get the same content for several hours at a time. I noticed that the code was much more likely to freeze up reading NYT than CBC, and when it did freeze up it was usually at the same place in the feed. The only difference between NYT and CBC feeds that would seem to be relevant is that NYT has more articles per feed so the XML data is longer. This makes me think that long files may be getting truncated somewhere within the WiModem (which we actually suspect will be the case based on discussion with Jim Drew, the WiModem guy.)

[Things are a bit crazy right now for me, but when I get a chance I am planning to try to implement a little HTTP GET program that saves a file to disk (like wget on Linux). It will be easier to investigate data corruption using such a program rather than the RSS Reader.]

Interesting that RESTORE on its own messes up the RS-232. I guess that is because RESTORE generates an NMI. The kernal is full of such fun bugs :)

User avatar
srowe
Vic 20 Afficionado
Posts: 468
Joined: Mon Jun 16, 2014 3:19 pm

Re: cc65 and RS232 User Port Serial

Postby srowe » Thu Feb 23, 2017 8:41 am

Here's v3 of the wedge. The ISR now disables all further interrupts and processes all pending ones before re-enabling. This should cope with any combination of Tx and Rx states, as well as you pounding on the RESTORE key.

I've run it for a while receiving data at 1200 baud, I've not seen a dropped or corrupt character.
Attachments
rs-232-fix-3.zip
(7.57 KiB) Downloaded 11 times

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Thu Feb 23, 2017 3:36 pm

I will give it a whirl with the RSS Reader (which is running with the previous version of your wedge as I type this ...)

Bobbi
Vic 20 Afficionado
Posts: 347
Joined: Thu Oct 13, 2016 11:35 am
Location: Toronto
Occupation: Programmer

Re: cc65 and RS232 User Port Serial

Postby Bobbi » Thu Feb 23, 2017 7:14 pm

Looking good so far after a few hours of testing (although my code avoids RX and TX at the same time anyhow, so it may not be the best stress test.)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 3 guests