Time out on read on serial bus

Basic and Machine Language

Moderator: Moderators

Post Reply
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Time out on read on serial bus

Post by wimoos »

All,

In WimBasic, in Vice, I try the following program to obtain a directory listing and save it in a file:

Code: Select all

10 OPEN2,8,1,"DIRLIST"
20 CMD2
30 EXEC">$"
40 PRINT#2
50 CLOSE2
Line 30 represents the ML code below. During the first iteration a timeout on read on the serial bus occurs.
When I try to write to a tapefile or to screen, it works as expected.
Writing to a file on a different device unit or to an emulated printer also fails.

Copying one diskfile to another, using GET# or INPUT# , works.

What causes this timeout, how can I fix it ?

Regards,

Wim.

Code: Select all

filename = "$"
LFS=1,8,0

LAE6E 	JSR  $FFC0	; open logical file
	LDX  #$01
	JSR  $FFC6	; open channel for input
	JSR  $FFCF	; skip load address
	JSR  $FFCF
LAE70	JSR  $FFCF	; skip link
	JSR  $FFCF
	LDA  $90	; check status
	BNE  LAE80		; EOF or error, exit
	JSR  LA4CC
	JSR  $FFCF
	TAX
	JSR  $FFCF	;
;
;	At this point a read timeout occurs (bit 1 in Zp$90).
;
	JSR  $DDCD	; print number in X:A
	JSR  $CB3F	; print a space
LAE78	JSR  $FFCF
	BEQ  LAE70
	JSR  $FFD2
	LDA  $90		; check for errors
	BEQ  LAE78		; none, loop to next line
LAE80	JSR  $FFCC
LAE83	LDA  #$01
	JMP  $FFC3
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Time out on read on serial bus

Post by srowe »

What does the code at LA4CC do?
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Time out on read on serial bus

Post by wimoos »

LA4CC is meant for scroll control on screen. It reads $028D and loops/waits based on shift/cbm/ctrl key combinations. During testing I'm not touching the keyboard, so effectively it only prints a $0D.

I've tried moving that call to right before the call to $DDCD, but no avail.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Time out on read on serial bus

Post by srowe »

What's the actual value in $90? the only way I can see a read timeout flagged in ACPTR is when EOI has already been set.
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Time out on read on serial bus

Post by wimoos »

The actual value is $02.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Time out on read on serial bus

Post by srowe »

I think the problem is you have both a listener and talker channel active on the device at once (as well as the VIC as a listener). I don't think the IEC wire protocol can handle that, it relies on "ownership" of the CLK and DATA lines to co-ordinate transfers.
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Time out on read on serial bus

Post by wimoos »

But I have tried with a target file on device #9. This also doesn't work.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: Time out on read on serial bus

Post by srowe »

But you still have the VIC and a disk drive as listeners on the bus, simultaneously. I think you will have to UNLISTEN the output file while the VIC receives the contents of the directory.
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Time out on read on serial bus

Post by wimoos »

The only way I could get this to work is to read the entire directory listing into memory and create a file from there, as per code below.

It looks like on the IEC you just can't have a directory and a regular file open at the same time.

Code: Select all

1 dimd$(500):open2,8,0,"$":get#2,a$:get#2,a$
2 get#2,a$:get#2,a$:get#2,a$:a=0:ifa$>""thena=asc(a$)
3 get#2,a$:b=0:ifa$>""thenb=asc(a$)
4 r$=mid$(str$(b*256+a),2)+" "
5 get#2,a$:ifa$=""d$(n)=r$:n=n+1:goto2
6 r$=r$+a$:ifst=0then5
7 close2:open130,8,1,"dirlist":fori=0ton-1:print#130,d$(i):next:close130
Regards,

Wim.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Time out on read on serial bus

Post by Mike »

wimoos wrote:It looks like on the IEC you just can't have a directory and a regular file open at the same time.
For sure you can. Look here: FE3 RAM Disk, and to quote from there:
Mike wrote:Here's a file based disk copy program, which can be used to transfer the contents of a *.d64 or *.d81 disk image [...] You just need to specify the device numbers of source and destination drive. The program then works through the entire directory of the medium in the source drive copying all PRG, SEQ and USR files. [...] the program can also be used as disk copier with either two real CBM disk drives, or as single drive disk copier with the FE3 RAM-Disk as temporary storage.
The program keeps the directory and a regular file open for read on the source drive, and yet another file open for write on the destination drive.

You need to honour that the IEC bus is effectively half-duplex only. To receive a (group of) byte(s) from a file, you have to bracket all CHRIN calls with CHKIN and CLRCHN; it is not possible to have the drive receiving data at the same time, but you can send data to other devices not on the IEC bus. Likewise, to transmit a (group of) byte(s) to a file, you have to bracket all CHROUT calls with CHKOUT and CLRCHN, again it is not possible to have the drive sending data at the same time, but you can receive data from other, non-IEC devices.

The KERNAL translates the CHKIN, CHKOUT, CLRCHN, CHRIN and CHROUT calls into the corresponding lower-level IEC (LISTEN, TALK, etc.) calls for I/O redirected to IEC.

You don't need to buffer the entire directory, line-wise conversion from "BASIC" to output will work and won't impose an arbitrary limit of 500 directory lines.

The file copy program uses a 256 byte buffer at the end of BASIC memory and - while the directory is kept open! - it reads from a file on the source drive (in 256 byte blocks), and when the buffer has been filled, 'empties' the buffer to the destination drive. Repeat, until EOF. Process next file, until end of directory.

Greetings,

Michael
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Time out on read on serial bus

Post by wimoos »

Hi Mike,

Thank you for your enlightenment on this. I have built it and tested it now and it works ! The only drawback is that the ML-routine has grown out of proportions and handling the STOP-key needs attention. I'll reconsider implementing it.
Nonetheless an learning experience, thanks again.

Regards,

Wim.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Time out on read on serial bus

Post by wimoos »

This is what it has become:

Code: Select all

filename = "$"
LFS=1,8,0

LAE6E 	JSR  $FFC0	; open logical file
	JSR  LAE77	; open channel for input
	JSR  LAE71	; read two bytes
LAE70	JSR  LAE71	; read two bytes
	LDA  $90	; check status
	BNE  LAE80	; EOF or error, exit
	JSR  $FFE1	; check stop key
	BEQ  LAE80
	JSR  LAE71	; read two bytes
	PHA
	TXA
	PHA
	JSR  LAE75	; switch to output
	JSR  $CAD7	; print <CR>
	PLA
	TAX
	PLA
	JSR  $DDCD	; print number in X:A
	JSR  $CB3F	; print a space
LAE78	JSR  LAE74	; switch to input
	JSR  $FFCF	; read byte
	BEQ  LAE70	; end-of-line
	PHA
	JSR  LAE75	; switch to output
	PLA
	JSR  $FFD2	; output byte
	LDA  $90	; check for errors
	BEQ  LAE78	; none, loop to next line
LAE80	JSR  LAE83	; close input file
;
; switch to output
;
LAE75	JSR  $FFCC	; close all channels
	LDX  $13
	JMP  $FFC9	; open for output
;
LAE83	LDA  #$01
	JMP  $FFC3	; close logical file (input)
;
;  read two bytes
;
LAE71	JSR  $FFCF	; read byte
	TAX		; save
	JMP  $FFCF	; read byte and return
;
; switch to input
;
LAE74	JSR  $FFCC	; close all channels
LAE77	LDX  #$01	;
	JMP  $FFC6	; open for input

VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
Post Reply