Page 1 of 1

File read trouble in ZX CP/M 2.2 by M.Williams

Posted: Tue Jan 14, 2020 7:53 am
by kegoyagl
I try to compile my project for Locomotive CP/M Plus and ZX CP/M 2.2 by Williams (https://www.worldofspectrum.org/infosee ... id=0023486) .
In Locomotive CP/M Plus file I/O works fine, I successfully read what I need right into memory address. But in ZX CP/M 2.2 I have a trouble with fread.
Code fragment is here:

Code: Select all

    FILE * f = fopen(rom_file, "rb");
    if (f == 0)
    {
        printf("ROM not found: \"%s\"\n", rom_file);
        return;
    }
    const int bytes = fread(0x8000, 1, 0x4000, f); // read ROM to RAM2
    fclose(f);
    printf("ROM \"%s\": %d bytes read\n", rom_file, bytes);
If file exists and have the right size, output is always "ROM "myfile": 16384 bytes read", in both OS, but actually in ZX CP/M 2.2 nothing is read.
If I change fread code to

Code: Select all

fread(0x8000, 0x4000, 1, f)
then in Locomotive CP/M Plus it still works well (memory is filled with file contents), but in ZX CP/M 2.2 output is "ROM "myfile": 1 bytes read", and actually that one byte is not read.
What I'm doing wrong? How to solve this trouble? Please help!

Posted: Tue Jan 14, 2020 3:17 pm
by kegoyagl
z88dk version is 1.99c.
I didn't tried nightly builds. May be I should do it.

Posted: Tue Jan 14, 2020 9:37 pm
by dom
I've spotted a couple of issues reading files in binary mode - thankfully the same problem showed up in ZXCC as well - and have submitted some code that allows be to read binary files under ZXCPM (and ZXCC).

I've not got a CP/M Plus disc image so I can't test it on that unfortunately.

It looks like there might be some stack corruption/overwriting going on somewhere: for me the program repeatedly restarts but it doesn't look like it's going to be easy to track down with all the paging that goes on under ZXCPM.

Posted: Tue Jan 14, 2020 9:50 pm
by dom
As an added bonus in the next nightly build, I've added a -subtype=zxplus3 option which will create a +3 format disc with the binary on it in one go:

zcc +cpm program.c -subtype=zxplus3 -create-app

Posted: Wed Jan 15, 2020 6:04 am
by kegoyagl
dom wrote:I've not got a CP/M Plus disc image so I can't test it on that unfortunately.
You could find a copy of CP/M Plus on https://planetemu.net . Just google it. There's disk 1 and 2.
It's totally illegal of course :cool:

Posted: Sat Jan 18, 2020 12:31 am
by kegoyagl
I've tried the latest nightly build (2020-01-17), and it seems broken for me. I just got errors at random places while compiling code. My command line is

Code: Select all

zcc.exe +cpm -vn -DAMALLOC -startup=3 -lzxcpm C:\Users\user\OneDrive\Documents\zx\src\main.c -create-app -ozx.obj
So I return to stable release 1.99c.

Posted: Sat Jan 18, 2020 10:34 am
by dom
With neither code nor errors I can't comment or assist I'm afraid.

Over the past year a number of warnings have been added to align the behaviour or sdcc and sccz80 - it might be these that you're seeing: usually adding the appropriate prototype silences these.