Userport Serial programming nonsense

Basic and Machine Language

Moderator: Moderators

Post Reply
Z0rb
Vic 20 Amateur
Posts: 41
Joined: Mon Apr 29, 2013 5:45 pm

Userport Serial programming nonsense

Post by Z0rb »

Ok it was difficult for me to pick which forum this should be posted in since it deals with both programming AND hardware. However seeing as how I have far more programming questions then hardware questions, I picked this forum.

Allow me to describe what I am playing with first, then I will describe the program I am using and then I will lay a billion questions on the 6502 Lords that dwell within the confines of said forum.

I have an Arduino Uno experimenter board that I am using to parse 300 baud data on one port to 9600 baud data on another port. This is all wrapped up nicely with the correct TTL voltages and such. The Arduino board is set up on both ends to communicate using 8,N,1, the only difference is one port is set to 300 and the other is set to 9600. The 9600 side is going into my laptop via a USB connection and for the most part is communicates flawlessly. The 300 side I am using one pin for TX and another for RX, both of which tie in with a common ground.

These pins go to the user port on the back of the VIC-20. The connector I have is a bit mislabeled so I will use the pin identifiers from the VIC-20 user Reference Guide. So I am using pin 1 and pin A for the common ground, Pin B (CB1) I am treating as the TX pin on Vic and Pin M (CB2) I am treating as the Rx pin on the Vic.

The program I am using is one I found in the book that comes with the VicModem. It is listed below.

Code: Select all

100 open 5,2,3,chr$(6)
110 dim f%(255),t%(255)
200 for j=32 to 64:t%(j)=j:next
210 t%(13)=13:t%(20)=8:rv=18:ct=0
220 for j=65 to 90:k=j+32:t%(j)=k:next
230 for j=91 to 95:t%(j)=j:next
240 for j=193 to 218:k=j-128:t%(j)=k:next
250 t%(146)=16:t%(133)=16
260 for j=0 to 255
270 k=t%(j)
280 if k<>0 then f%(k)=j:f%(k+128)=j
290 next
300 print" "chr$(147)
310 get #5,a$
320 if a$="" or st<>0 then 360
330 print" "chr$(157);chr$(f%(asc(a$)));
340 if f%(asc(a$))=34 then poke 212,0
350 goto 310
360 print chr$(rv)" "chr$(157);chr$(146);:get a$
370 if a$<>"" then print #5,chr$(t%(asc(a$)));
380 ct=ct+1
390 if ct=8 then ct=0: rv=164-rv
400 if(peek(37151)and 64)=1 then 400
410 goto 310 
Here is the issue I am having. I am able to transmit data from the Vic to my laptop via my little Arduino converter with acceptable accuracy however I am not able to transmit data FROM my PC to the Vic via my converter. I have verified that a 300 bps signal IS being sent to Pin M (CB2) on the Vic however I am not seeing any data on the Vic's screen.

Here are the questions.

Hardware
1. I noticed in some circuits for building an RS232 port for the Vic involved using a transistor to trigger a pulse from Pin 2 to Pin N to get a signal on Pin M. Is there a reason for this? I am currently sending a signal directly from the Arduino.

2. Can I test the programs sending and receiving ability by creating a loop back by shorting Pin B (CB1) to Pin M (CB2)?

3. Not that anyone here might know this but I will toss it out there. Is it possible that I need some sort of buffer in the Arduino to gather the 9600 data and then serve that data up at 300 more slowly?

Software
1. First and most important does this program look correct for sending and receiving data using these pins on the user port?

2. In line 100 open 5,2,3,chr$(6). I understand argument 1,2, and 4 but what is argument 3? The programmers reference is a bit vague here. I can see the two byte string holding control and command registers, which I understand but argument three is also labeled command and has a value of "3" what does this represent?

3. Line 110 dim f%(255),t%(255). I am familiar with arrays and such but what does the symbol "%" do when in reference to a variable or array?

4. Lines 310-330. I have a rough understanding about what is going on with these lines however I am not sure the significance of the "ST" variable. I know this is a system type variable that shows a status but of what I don't know. Can someone comment on these lines of code?

5. Line 340, I see that this is resetting the quote mode but do not understand why?

6. Line if(peek(37151)and 64)=1 then 400. I am not sure I understand what this register is being checked for it appears to have something to do with Port A. Also the argument of "AND" in the statement is it addition, or multiplication?

I know this is a lot of questions but I figure that I will lay it all out and see what comes back.

Thanks

Oh yeah one more thing, I still haven't found the area on here where I can change my user name to get rid of "VIC" at the end.
User avatar
Mike
Herr VC
Posts: 4832
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Userport Serial programming nonsense

Post by Mike »

Just two points to these two lines of the program:
Z0rbVIC wrote:

Code: Select all

370 if a$<>"" then print #5,chr$(t%(asc(a$)));
[...]
400 if(peek(37151)and 64)=1 then 400
Line 370: normally, BASIC V2 isn't too picky about the placement of spaces, but in the case of PRINT# and INPUT#, the hash character actually is part of the keyword, which won't be tokenized correctly if there is an extra space. Neither does ?# work (the correct abbreviation for PRINT# would be [P] [SHIFT-R], without '#'!)

Line 400: PEEK(37151)AND64 masks out bit 6 (value 64) out of the register value. The result either is 64 or 0, but it can't ever be 1 so I strongly suspect a typo here.
I am familiar with arrays and such but what does the symbol "%" do when in reference to a variable or array?
These indicate integer variables. They can hold integer values in the range -32768 .. +32767. Even though they'd only need 2 bytes to store the value, for single variables they still occupy 5 bytes as do floats. That is because all variable entries uniformly take 7 bytes in total, 2 bytes for the name and 5 bytes for the value - regardless whether they are a float, integer, string pointer or a pointer to a DEF FN'd function - so the interpreter can search the variable list by simply incrementing the address by 7 when the variable name doesn't match.

When used as array though integers truly only need 2 bytes per element. So they were simply used in the program to save space, as the stored values are all in the range 0..255.

Finally, floats, integers, strings, their array and defined functions are in different namespaces. A, A%, A$, the arrays A(), A%(), A$() and the function FNA() are all independent of each other (there are no arrays of defined functions, though - and the parentheses enclose the argument of FNs).
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: Userport Serial programming nonsense

Post by tlr »

Z0rbVIC wrote:These pins go to the user port on the back of the VIC-20. The connector I have is a bit mislabeled so I will use the pin identifiers from the VIC-20 user Reference Guide. So I am using pin 1 and pin A for the common ground, Pin B (CB1) I am treating as the TX pin on Vic and Pin M (CB2) I am treating as the Rx pin on the Vic.
You need to feed serial data into the vic-20 on both Pin B (CB1) and Pin C (PB0). The serial data out from the vic-20 comes on Pin M (CB2).
Z0rbVIC wrote:2. Can I test the programs sending and receiving ability by creating a loop back by shorting Pin B (CB1) to Pin M (CB2)?
Yes, but with Pin C (PB0) included as stated above.
Z0rbVIC wrote:3. Not that anyone here might know this but I will toss it out there. Is it possible that I need some sort of buffer in the Arduino to gather the 9600 data and then serve that data up at 300 more slowly?
You won't need that as long as you have correctly implemented flow control for the 9600 bps link. Having a buffer might off-load the PC side by being able to transfer chunks at a time but that probably won't matter at all with buffered I/O in a modern os.

Question: What are you trying to achieve?
Making a serial port speed gear box seems overly complicated unless you are aiming to process the data in your arduino in some way.
Z0rb
Vic 20 Amateur
Posts: 41
Joined: Mon Apr 29, 2013 5:45 pm

Re: Userport Serial programming nonsense

Post by Z0rb »

tlr wrote:You need to feed serial data into the vic-20 on both Pin B (CB1) and Pin C (PB0).
I'll give that a try. I think I am just going to make a breakout box for the userport to facilitate some experimentation.
Question: What are you trying to achieve?
Making a serial port speed gear box seems overly complicated unless you are aiming to process the data in your arduino in some way.
Well initially I want the Vic-20 to talk to a Speakjet Voice Synth. The lowest baud rate that the chip can achieve is 2400, but it's default is 9600. I also have a variety of other devices that run at 9600, but primarily I want to get the speak jet talking to the Vic. As it is right now I can probably get this working since I am able to send data from the Vic, just not receive it. It might also be a neat project to get this talking to an Ethernet Shield.
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: Userport Serial programming nonsense

Post by tlr »

Z0rbVIC wrote:Well initially I want the Vic-20 to talk to a Speakjet Voice Synth. The lowest baud rate that the chip can achieve is 2400, but it's default is 9600. I also have a variety of other devices that run at 9600, but primarily I want to get the speak jet talking to the Vic. As it is right now I can probably get this working since I am able to send data from the Vic, just not receive it. It might also be a neat project to get this talking to an Ethernet Shield.
9k6 is definately doable directly on the vic-20 if you only need half duplex (=send _or_ receive at any given time). Not with the kernal routines though.

I do 38k4 here: tinyrs 1.0.

Sending is the easiest as you only need to maintain the timing within the byte, not between bytes. At 9k6 there are ~100 cycles per bit so you might even be able to pull this off interrupt driven.

Even the original kernal might do 2k4. Anyone tried the limits on the vic-20?
Z0rb
Vic 20 Amateur
Posts: 41
Joined: Mon Apr 29, 2013 5:45 pm

Re: Userport Serial programming nonsense

Post by Z0rb »

tlr wrote: 9k6 is definately doable directly on the vic-20 if you only need half duplex (=send _or_ receive at any given time). Not with the kernal routines though.
And there in lies my issue. I am new to VIC programming, well not new I just haven't done anything like it in about 26 years ;) And as for assembly programming well I am new to that. So I am using the on board routines to get what I need. With the speak jet it appears that it only RECEIVES data at 9600, it literally will not Xmit anything back so I really only need Pin B CB1 and a ground to talk to it.

I guess my next question is. I only have a tape deck for programs, is there a way to down load programs and then convert them to the audio I need to put on the cassette to load these programs?
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: Userport Serial programming nonsense

Post by tlr »

Z0rbVIC wrote:I guess my next question is. I only have a tape deck for programs, is there a way to down load programs and then convert them to the audio I need to put on the cassette to load these programs?
Try this thread: Software we use for transfer
Z0rb
Vic 20 Amateur
Posts: 41
Joined: Mon Apr 29, 2013 5:45 pm

Re: Userport Serial programming nonsense

Post by Z0rb »

tlr wrote:
Z0rbVIC wrote:I guess my next question is. I only have a tape deck for programs, is there a way to down load programs and then convert them to the audio I need to put on the cassette to load these programs?
Try this thread: Software we use for transfer

Heh JACKPOT, thanks.
Post Reply