[comp.sys.apple] serial problems

tmetro@pro-angmar.UUCP (Tom Metro) (02/06/88)

 
I am trying to write a //c serial port driver for BASIC. Writing out
to the port is quite simple, but receiving, without loosing
characters, is another matter. I purchased "Inside The Apple //c"
(by Gary Little) to obtain some more information on the //c ports. I
found out that the //c has an internal ROM routine that will use
interrupts to place characters in a buffer in auxiliary memory. Then
there is another routine used for retriving the characters from the
buffer. The procedure for using the buffer is as follows:
 
First you need to enable receiver interrupts. This is done by
storing a 0 in bit 1 of the 6551 command register.
Next ACIABUF($4FF) must be loaded with the value $Cn where n is 1
for port 1 and 2 for port 2. (I used $C2 in my case.)
 
To read the buffer you need to call the subroutine XRDSER ($C8C5)
with Y set to 0. On return from XRDSER the carry flag will be clear
if the buffer is empty; if it isn't, then the carry flag will be set
and the character will be in the accumulator.
 
I used the following program to call XRDSER and pass the character
to BASIC:
 
300 CLI
301 LDY #$00
303 JSR $C8C5 ;GET CHARACTERS
306 BCC $030D ;IF CARY CLEAR THEN BUFFER EMPTY
308 LDY #$03
30A STA ($69),Y ;PUT CHARACTER INTO CHAR% VARIABLE
30C RTS
30D LDA #$FF
30F LDY #$0A
311 STA ($69),Y ;PUT 255 INTO CARY% TO INDICATE BUFFER EMPTY
313 RTS
 
My BASIC program called this routine once in the beginning to enable
interrupts (CLI). It then sets up the port registers.
I then print a command out to my modem that I know I will get a
responce from so I can check the input routine.
Then I enter a loop which continuously calls my routine and prints a
character from the buffer.
 
This is where the problem starts. All I get is random characters
back from the routine. Nothing that resembles the characters I
should be getting back from the modem. My CARY% flag shows that the
buffer is empty (providing its working) most of the time, but it's
status seems to change randomly. One other thing that leads me to
believe that something isn't right is that I get a click from the
speaker every time the XRDSER subroutine is accessed.
 
Has anybody ever used this set of ROM routines? Is there something
I'm doing wrong? Do you know of a better way of reading the //c
ports without loosing characters and passing them to BASIC? 
I can provide a listing of the XRDSER routine (which looks OK to me)
and my BASIC program if you think it would be of any help. 
 
 

Tom Metro
tmetro@pro-angmar