Skip to content

Commit

Permalink
Fix I/O redirection in startup
Browse files Browse the repository at this point in the history
  • Loading branch information
agn453 committed Jan 10, 2022
1 parent 8e2ebbe commit 4006b0a
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 125 deletions.
77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ emulation using RunZ80, SIMH or ZXCC.
Each release is a consolidated milestone with various updates and
patches applied.

The latest release is V3.09-10 (see Modification History below).
The latest release is V3.09-11 (see Modification History below).

If you only wish to download the latest binary distribution, download
it from
Expand Down Expand Up @@ -1220,6 +1220,79 @@ to produce a executable that doesn't require Z80 emulation for
cross-compilation.


## Code-generation issue with casting char to long

Mark Ogden supplied the following detail regarding an issue with
code generation when casting a ```char```/```unsigned char``` to a
```long```. The current compiler emits incorrect Z80 instructions.

The following snippet of code shows the problem and work-arounds.

```
void func(char *pia, unsigned char *pib) {
long a;
unsigned long b;
a = pia[1]; /* ok */
a = pib[1]; /* bad sets a = 0 */
b = pia[1]; /* bad sets b = 0 */
b = pib[1]; /* bad sets b = 0 */
/* work arounds */
/* for the simple assignment case use
* (int)pia[1], (unsigned)pia[1] or (unsigned)pib[1]
* dependent on whether you need sign extension
*
* for example -
*/
a = (unsigned) pib[1];
b = (int) pia[1];
b = (unsigned) pib[1];
/* if used in an expression you may also need to add
* another cast to (long) or (unsigned long)
* e.g. (unsigned long)(unsigned)
*/
}
```

For the three failing cases, the code generated is
```
ld l,(hl) ; picks up the char from the array
ld hl,0
ld d,l
ld e,l
```

whereas the correct optimised code should be

```
ld e,(hl)
ld hl,0
ld d,l
```


## Fix I/O redirection start-up and V3.09-11 release

When the PIPEMGR I/O redirection is not detected, the standard files
for stdin, stdout and stderr now default to use the console ```CON:```
device for compiler output. With I/O redirection, these use the
PIPEMGR pseudo device names ```RSX:``` and ```ERR:```. This fixes the
issue with the compiler front-end error message output - so the temporary
work-around I made a few days ago has been removed.

This fix has changed the start-up modules ```CRTCPM.OBJ``` and
```RRTCPM.OBJ``` to use a new ```_initrsx()``` routine when PIPEMGR is
detected (the source is in the cpm/CLEANUP.C module of LIBC).

To indicate this fix is included, I've bumped the release to V3.09-11
and updated the binary distribution library files.


--
Tony Nicholson
08-Jan-2022
11-Jan-2022
140 changes: 70 additions & 70 deletions cpm/BUILD-C.LOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,93 @@
10E>;
10E>date
A:DATE COM (User 0)
Thu 30/12/2021 07:42:10
Tue 11/01/2022 09:40:15
10E>;
10E>; Build Z80 version
10E>c -o -v c309-10.c
10E>c -o -v c309-11.c
A:C COM (User 0)
Hi-Tech C Compiler (CP/M-80) V3.09-9
Hi-Tech C Compiler (CP/M-80) V3.09-11
Copyright (C) 1984-87 HI-TECH SOFTWARE
Updated from https://github.com/agn453/HI-TECH-Z80-C
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -I0:A: C309-10.C $CTMP1.$$$
0:A:P1 $CTMP1.$$$ $CTMP2.$$$ $CTMP3.$$$
0:A:CGEN $CTMP2.$$$ $CTMP1.$$$
0:A:OPTIM $CTMP1.$$$ $CTMP2.$$$
0:A:ZAS -J -N -OC309-10.OBJ $CTMP2.$$$
ERA $CTMP1.$$$
ERA $CTMP2.$$$
ERA $CTMP3.$$$
ERA $CTMP5.$$$
0:A:LINQ -Z -Ptext=0,data,bss -C100H -OC309-10.COM 0:A:CRTCPM.OBJ C309-10.OBJ 0:A:LIBC.LIB
ERA C309-10.OBJ
ERA $$EXEC.$$$
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -I0:A: C309-11.C M:$CTMP1.$$$
0:A:P1 M:$CTMP1.$$$ M:$CTMP2.$$$ M:$CTMP3.$$$
0:A:CGEN M:$CTMP2.$$$ M:$CTMP1.$$$
0:A:OPTIM M:$CTMP1.$$$ M:$CTMP2.$$$
0:A:ZAS -J -N -OC309-11.OBJ M:$CTMP2.$$$
ERA M:$CTMP1.$$$
ERA M:$CTMP2.$$$
ERA M:$CTMP3.$$$
ERA M:$CTMP5.$$$
0:A:LINQ -Z -Ptext=0,data,bss -C100H -OC309-11.COM 0:A:CRTCPM.OBJ C309-11.OBJ 0:A:LIBC.LIB
ERA C309-11.OBJ
ERA M:$$EXEC.$$$

10E>;
10E>; Now build Z280 version
10E>;
10E>; First a Z280 version using the Z80 LIBC.C (runs on Z80)
10E>c309-10 -o -v -ec280z80.com -dZ280 c309-10.c
E:C309-10 COM
Hi-Tech C Compiler (CP/M-80) V3.09-10
10E>c309-11 -o -v -ec280z80.com -dZ280 c309-11.c
E:C309-11 COM
Hi-Tech C Compiler (CP/M-80) V3.09-11
Copyright (C) 1984-87 HI-TECH SOFTWARE
Updated from https://github.com/agn453/HI-TECH-Z80-C
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -DZ280 -I0:A: C309-10.C $CTMP1.$$$
0:A:P1 $CTMP1.$$$ $CTMP2.$$$ $CTMP3.$$$
0:A:CGEN $CTMP2.$$$ $CTMP1.$$$
0:A:OPTIM $CTMP1.$$$ $CTMP2.$$$
0:A:ZAS -J -N -OC309-10.OBJ $CTMP2.$$$
ERA $CTMP1.$$$
ERA $CTMP2.$$$
ERA $CTMP3.$$$
ERA $CTMP5.$$$
0:A:LINQ -Z -Ptext=0,data,bss -C100H -OC280Z80.COM 0:A:CRTCPM.OBJ C309-10.OBJ 0:A:LIBC.LIB
ERA C309-10.OBJ
ERA $$EXEC.$$$
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -DZ280 -I0:A: C309-11.C M:$CTMP1.$$$
0:A:P1 M:$CTMP1.$$$ M:$CTMP2.$$$ M:$CTMP3.$$$
0:A:CGEN M:$CTMP2.$$$ M:$CTMP1.$$$
0:A:OPTIM M:$CTMP1.$$$ M:$CTMP2.$$$
0:A:ZAS -J -N -OC309-11.OBJ M:$CTMP2.$$$
ERA M:$CTMP1.$$$
ERA M:$CTMP2.$$$
ERA M:$CTMP3.$$$
ERA M:$CTMP5.$$$
0:A:LINQ -Z -Ptext=0,data,bss -C100H -OC280Z80.COM 0:A:CRTCPM.OBJ C309-11.OBJ 0:A:LIBC.LIB
ERA C309-11.OBJ
ERA M:$$EXEC.$$$

10E>;
10E>; and the Z280 optimized version from it (only runs on a Z280)
10E>c280z80 -of2 -v -ec280-10.com c309-10.c
10E>c280z80 -of2 -v -ec280-11.com c309-11.c
E:C280Z80 COM
Hi-Tech C Compiler (CP/M-80) V3.09-10 [Z280 MPU version]
Hi-Tech C Compiler (CP/M-80) V3.09-11 [Z280 MPU version]
Copyright (C) 1984-87 HI-TECH SOFTWARE
Updated from https://github.com/agn453/HI-TECH-Z80-C
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -DZ280 -I0:A: C309-10.C $CTMP1.$$$
0:A:P1 $CTMP1.$$$ $CTMP2.$$$ $CTMP3.$$$
0:A:CGEN $CTMP2.$$$ $CTMP1.$$$
0:A:OPTIM -F $CTMP1.$$$ $CTMP2.$$$
0:A:OPTIMH -F $CTMP2.$$$ $CTMP5.$$$
481 bytes optimized away
1528 bytes replaced
0:A:ZAS -N -OC309-10.OBJ $CTMP5.$$$
ERA $CTMP1.$$$
ERA $CTMP2.$$$
ERA $CTMP3.$$$
ERA $CTMP5.$$$
0:A:LINQ -Z -Ptext=0,data,bss -C100H -OC280-10.COM 0:A:C280CPM.OBJ C309-10.OBJ 0:A:LIB280C.LIB
ERA C309-10.OBJ
ERA $$EXEC.$$$
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -DZ280 -I0:A: C309-11.C M:$CTMP1.$$$
0:A:P1 M:$CTMP1.$$$ M:$CTMP2.$$$ M:$CTMP3.$$$
0:A:CGEN M:$CTMP2.$$$ M:$CTMP1.$$$
0:A:OPTIM -F M:$CTMP1.$$$ M:$CTMP2.$$$
0:A:OPTIMH -F M:$CTMP2.$$$ M:$CTMP5.$$$
477 bytes optimized away
1494 bytes replaced
0:A:ZAS -N -OC309-11.OBJ M:$CTMP5.$$$
ERA M:$CTMP1.$$$
ERA M:$CTMP2.$$$
ERA M:$CTMP3.$$$
ERA M:$CTMP5.$$$
0:A:LINQ -Z -Ptext=0,data,bss -C100H -OC280-11.COM 0:A:C280CPM.OBJ C309-11.OBJ 0:A:LIB280C.LIB
ERA C309-11.OBJ
ERA M:$$EXEC.$$$

10E>;
10E>c280-10 -o2 -v optimh.c
E:C280-10 COM
Hi-Tech C Compiler (CP/M-80) V3.09-10 [Z280 MPU version]
10E>c280-11 -o2 -v optimh.c
E:C280-11 COM
Hi-Tech C Compiler (CP/M-80) V3.09-11 [Z280 MPU version]
Copyright (C) 1984-87 HI-TECH SOFTWARE
Updated from https://github.com/agn453/HI-TECH-Z80-C
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -DZ280 -I0:A: OPTIMH.C $CTMP1.$$$
0:A:P1 $CTMP1.$$$ $CTMP2.$$$ $CTMP3.$$$
0:A:CGEN $CTMP2.$$$ $CTMP1.$$$
0:A:OPTIM $CTMP1.$$$ $CTMP2.$$$
0:A:OPTIMH $CTMP2.$$$ $CTMP5.$$$
0:A:CPP -DCPM -DHI_TECH_C -Dz80 -DZ280 -I0:A: OPTIMH.C M:$CTMP1.$$$
0:A:P1 M:$CTMP1.$$$ M:$CTMP2.$$$ M:$CTMP3.$$$
0:A:CGEN M:$CTMP2.$$$ M:$CTMP1.$$$
0:A:OPTIM M:$CTMP1.$$$ M:$CTMP2.$$$
0:A:OPTIMH M:$CTMP2.$$$ M:$CTMP5.$$$
217 bytes optimized away
390 bytes replaced
0:A:ZAS -J -N -OOPTIMH.OBJ $CTMP5.$$$
ERA $CTMP1.$$$
ERA $CTMP2.$$$
ERA $CTMP3.$$$
ERA $CTMP5.$$$
0:A:ZAS -J -N -OOPTIMH.OBJ M:$CTMP5.$$$
ERA M:$CTMP1.$$$
ERA M:$CTMP2.$$$
ERA M:$CTMP3.$$$
ERA M:$CTMP5.$$$
0:A:LINQ -Z -Ptext=0,data,bss -C100H -OOPTIMH.COM 0:A:C280CPM.OBJ OPTIMH.OBJ 0:A:LIB280C.LIB
ERA OPTIMH.OBJ
ERA $$EXEC.$$$
ERA M:$$EXEC.$$$

10E>;
10E>dir c*.com [fu
Expand All @@ -103,14 +103,14 @@ Directory For Drive E: User 10
Name Bytes Recs Attributes Prot Update Create
------------ ------ ------ ------------ ------ -------------- --------------

C280-10 COM 24k 189 Dir RW None 30/12/21 07:52 30/12/21 07:52
C280-9 COM 24k 189 Dir RW None 18/08/21 15:51 18/08/21 15:51
C280Z80 COM 28k 204 Dir RW None 30/12/21 07:49 30/12/21 07:49
C309-10 COM 28k 201 Dir RW None 30/12/21 07:45 30/12/21 07:45
C309-9 COM 28k 201 Dir RW None 18/08/21 15:44 18/08/21 15:44
C280-10 COM 24k 188 Dir RW None 06/01/22 08:21 06/01/22 08:21
C280-11 COM 24k 188 Dir RW None 11/01/22 09:50 11/01/22 09:50
C280Z80 COM 28k 203 Dir RW None 11/01/22 09:46 11/01/22 09:46
C309-10 COM 28k 200 Dir RW None 10/01/22 10:48 10/01/22 10:48
C309-11 COM 28k 201 Dir RW None 11/01/22 09:43 11/01/22 09:43

Total Bytes = 132k Total Records = 984 Files Found = 5
Total 1k Blocks = 126 Used/Max Dir Entries For Drive E: 1073/2048
Total Bytes = 132k Total Records = 980 Files Found = 5
Total 1k Blocks = 125 Used/Max Dir Entries For Drive E: 1091/2048

10E>dir optimh.com [fu
A:DIR COM (User 0)
Expand All @@ -122,10 +122,10 @@ Directory For Drive E: User 10
Name Bytes Recs Attributes Prot Update Create
------------ ------ ------ ------------ ------ -------------- --------------

OPTIMH COM 20k 144 Dir RW None 30/12/21 07:55 30/12/21 07:55
OPTIMH COM 20k 144 Dir RW None 11/01/22 09:52 11/01/22 09:52

Total Bytes = 20k Total Records = 144 Files Found = 1
Total 1k Blocks = 18 Used/Max Dir Entries For Drive E: 1073/2048
Total 1k Blocks = 18 Used/Max Dir Entries For Drive E: 1091/2048

10E>;
10E>; Done
Expand Down
15 changes: 4 additions & 11 deletions cpm/C309-10.C → cpm/C309-11.C
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int main(int argc, char **argv)
signal_t prev_sig;
prev_sig=signal(SIGINT,SIG_IGN);

fprintf(stderr, "Hi-Tech C Compiler (CP/M-80) V3.09-10");
fprintf(stderr, "Hi-Tech C Compiler (CP/M-80) V3.09-11");
#ifdef Z280
fprintf(stderr, " [Z280 MPU version]");
#endif
Expand Down Expand Up @@ -795,6 +795,7 @@ void compile(char *s)
vec[j++] = tmpf1;
vec[j] = (char *)0;
doexec(cpp, vec);

if (cp = rindex(s, ':'))
s = cp+1;
*rindex(s, '.') = 0;
Expand All @@ -804,23 +805,14 @@ void compile(char *s)
if (xref)
vec[i++] = strcat(strcpy(cbuf, "-C"), crtmp);
/* error redirection */
/*AGN - temporarily ignore error redirection*/
/*
if (ebuf[0])
vec[i++] = ebuf;
*/
vec[i++] = tmpf1;
vec[i++] = tmpf2;
vec[i++] = tmpf3;
vec[i++] = (char *)0;

/* vec[0] is junk. Move everything down one slot. */
/*AGN - remove the following two lines*/
/*
for (i=0; vec[i]; ++i)
vec[i] = vec[i+1];
*/
doexec(pass1, vec);

vec[0] = tmpf2;
vec[1] = keepas && !optimize ? strcat(strcpy(tmpbuf, s), ".AS") : tmpf1;
vec[2] = (char *)0;
Expand All @@ -844,6 +836,7 @@ void compile(char *s)
vec[i++] = tmpf2;
vec[i] = (char *)0;
doexec(optim, vec);

cp = tmpf2;
#ifdef Z280
if (z280optim)
Expand Down
Loading

0 comments on commit 4006b0a

Please sign in to comment.