z88dk forums

z80 Development Kit

You are not logged in.

#1 2020-01-14 07:53:07

kegoyagl
New member
Registered: 2020-01-14
Posts: 4

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

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:

    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:

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!

Offline

 

#2 2020-01-14 15:17:45

kegoyagl
New member
Registered: 2020-01-14
Posts: 4

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

z88dk version is 1.99c.
I didn't tried nightly builds. May be I should do it.

Offline

 

#3 2020-01-14 21:37:29

dom
Administrator
Registered: 2007-07-15
Posts: 1446
Website

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

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.

Offline

 

#4 2020-01-14 21:50:34

dom
Administrator
Registered: 2007-07-15
Posts: 1446
Website

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

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

Offline

 

#5 2020-01-15 06:04:38

kegoyagl
New member
Registered: 2020-01-14
Posts: 4

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

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

Offline

 

#6 2020-01-18 00:31:33

kegoyagl
New member
Registered: 2020-01-14
Posts: 4

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

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:

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.

Offline

 

#7 2020-01-18 10:34:29

dom
Administrator
Registered: 2007-07-15
Posts: 1446
Website

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

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.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson