+3 Disk File I/O

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

+3 Disk File I/O

Post by alvin »

A message posted at WOS:
So I have this very simple program, and it doesn't want to open a file for writing:

Code: Select all

#include <stdio.h>
#include <stdlib.h>

void main()
{
        FILE *stream;

        printf("\x1B[2JTest of file IO\n");
        stream=fopen("foo", "w");

        if(!stream)
        {
                printf("Failed\n");
                return;
        }
        fprintf(stream, "foo\n");
        fclose(stream);
}
It is compiled from a Makefile, and the build output looks like this:

Code: Select all

zcc +zxansi -vn -O2 -preserve -DPLUS3   -c -o main.o main.c
zcc +zxansi -vn -O2 -preserve -DPLUS3 -o test.bin main.o -lp3
There are no compile or link errors. However, fopen always returns NULL - I can give it the filename "m:foo", "a:foo" or simply "foo". The disk doesn't spin, RAMdisk doesn't get written. I've not found an equivalent to 'perror' or a global errno, so the only thing I see is fopen returning NULL.

What am I missing here?
I don't know much about the +3 driver so I'm forwarding this here. Maybe a response can also be copied to WOS: http://www.worldofspectrum.org/forums/s ... hp?t=20781
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I've managed to forget my Wos username and password again....

I've just tried this out and it all looks ok, the file is written without problems and it contains what it's meant to.

Guess a copy of the binary and a .map file is probably useful to see what's going on - the binary should be about 4300 bytes in length if it's got the +3 file io linked in.
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Just to wrap this up here, the stack was being swapped out due to a lack of a clear 32767 before running the binary.

Wos post was here: http://www.worldofspectrum.org/forums/s ... hp?t=20781
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Another issue with the +3 file i/o at WOS:

http://www.worldofspectrum.org/forums/s ... hp?t=28816

This time with opening a file for reading with fopen("scr","r"). It's looking like z88dk is opening the file with an exclusive file lock (I didn't even know +3 DOS could do this :-P ) and not all emulators support that feature so some emulators are returning NULL. I'm thinking non-exclusive file access makes more sense and file locking should be specified some other way.
Post Reply