CP/M 3.0 I8080 is FREAD broken ?

Post Reply
jacotton
Member
Posts: 63
Joined: Fri Nov 24, 2017 1:35 am

CP/M 3.0 I8080 is FREAD broken ?

Post by jacotton »

Hi:

Debugging a C program on an 8080 computer. The fread is returning -1. It does not do this on z80.

Makefile:
toupper: main.c
zcc +cpm -clib=8080 -create-app -otoupper --list --c-code-in-asm main.c

clean:
rm *.o *.err *.lis *.def *.sym *.exe *.COM macro

install:
sudo cp ./*.COM /var/www/html/.

Program:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

FILE *in;
FILE *tmp;
char infilename[30];
char tmpfilename[30];
int c;
char *p;
char bigbuf[4098];
int flag;
int rz;
int i;
int
main (int argc, char *argv[])
{
flag = 0;
memset (infilename, 0, 80);
memset (tmpfilename, 0, 80);
strcpy (infilename, argv[1]);
if (argv[2] == 'N')
flag++;
strcpy (tmpfilename, "XYZZY.TMP");
in = fopen (infilename, "r");
if (in == 0)
{
printf ("Can't open %s\n", infilename);
exit (0);
}
tmp = fopen (tmpfilename, "a");
if (tmp == 0)
{
printf ("Can't open tmpfile");
exit (0);
}
do
{
rz = 0;
memset (bigbuf, 0, 128);
rz = fread (bigbuf, 1, 128, in);
printf ("read record, size = %d\n", rz);
if (rz != EOF)
{
for (i = 0; i < rz; i++)
{
if (flag == 0)
{
c = toupper (bigbuf);
if (c == '\n')
fputc (0x0d, tmp);
else
{
if (c != 0)
fputc (c, tmp);
}
}
else
{
c = bigbuf;
if (c == 0x0d)
{
fputc (c, tmp);
fputc (0x0a, tmp);
}
else
{
if (c != 0)
fputc (c, tmp);
}
}
}
}
else if (rz == EOF)
{
fclose (in);
fclose (tmp);
remove (tmpfilename);
exit (0);
}
}
while (rz != 0);
fflush (tmp);
fclose (in);
fclose (tmp);
remove (infilename);
rename (tmpfilename, infilename);
}
Results:
A>toupper mc.sub
read record, size = -1

A>type mc.sub
; compile an assembler program
A:M80 =$1/M
A:L80 $1,$1/N/E
ERA $1.REL
jacotton
Member
Posts: 63
Joined: Fri Nov 24, 2017 1:35 am

Re: CP/M 3.0 I8080 is FREAD broken ?

Post by jacotton »

Same code, rebuilt for z80

Results:
C>test wto.mac
read record, size = 128
read record, size = 128
read record, size = 110
read record, size = 0

Makefile;
toupper: main.c
# zcc +cpm -clib=8080 -create-app -otoupper --list --c-code-in-asm main.c
zcc +cpm -create-app -otoupper main.c

clean:
rm *.o *.err *.lis *.def *.sym *.exe *.COM macro

install:
sudo cp ./*.COM /var/www/html/.
User avatar
dom
Well known member
Posts: 1506
Joined: Sun Jul 15, 2007 10:01 pm

Re: CP/M 3.0 I8080 is FREAD broken ?

Post by dom »

I only implemented fread for 8080 in April so if you’ve not updated recently then that might be the problem.
jacotton
Member
Posts: 63
Joined: Fri Nov 24, 2017 1:35 am

Re: CP/M 3.0 I8080 is FREAD broken ?

Post by jacotton »

O.k. I'll check that.
jacotton
Member
Posts: 63
Joined: Fri Nov 24, 2017 1:35 am

Re: CP/M 3.0 I8080 is FREAD broken ?

Post by jacotton »

build date for 'not working' version
zcc - Frontend for the z88dk Cross-C Compiler - v18239-ee5024b80-20210415

I did a git pull and build. Will now retest the code.
User avatar
dom
Well known member
Posts: 1506
Joined: Sun Jul 15, 2007 10:01 pm

Re: CP/M 3.0 I8080 is FREAD broken ?

Post by dom »

Great. It should be there with the latest pull - I added the functionality on 25th April.

You’ll also benefit from the optimisations @feilipu has be doing lately.
jacotton
Member
Posts: 63
Joined: Fri Nov 24, 2017 1:35 am

Re: CP/M 3.0 I8080 is FREAD broken ?

Post by jacotton »

cool, I'll keep the git pull loop running.

jc
Post Reply