Henk de Groot wrote: ↑
Thu Jun 22, 2017 7:41 pm
So it looks I got my source at the worse possible time. But what version would be a trusted copy?
Always grab the current build. That's where the bugfixes happen as they are found.
You definitely found a bug in sccz80 - the program is behaving correctly as the actual constant stored is +2.0 rather than -2.0. A month ago, sccz80's float parsing was completely rewritten and I guess this simple case was missed. I'll file a bug report
If you've compiled zsdcc (for linux you need to compile it separately), it does not have that issue:
(classic library, zsdcc as compiler)
zcc +zx -vn -compiler=sdcc -SO3 --max-allocs-per-node200000 --reserve-regs-iy what.c -o what.bin -lndos -lmath48 -create-app
The high optimization settings "-SO3 --max-allocs-per-node200000" can be omitted. "--reserve-regs-iy" is required unless your program disables interrupts to avoid conflict with basic's interrupt service routine. "-lmath48" chooses a different floating point package that is compatible with zsdcc (-lm chooses genmath which is not compatible).
If you add a pragma to enable the %f converter:
Code: Select all
a = -2.0;
printf("a = %f\n",a);
You can also compile with the new library:
(newlib, zsdcc as compiler)
zcc +zx -vn -clib=sdcc_iy -SO3 --max-allocs-per-node200000 what.c -o what -lm -create-app
There is no issue with basic's isr as interrupts are disabled by the new library's crt (however --reserve-regs-iy is automatically selected by clib=sdcc_iy because it leads to better code with SO3 there). The default math library for the newlib is math48 so "-lm" is fine.
Unlike the classic library, the newlib does not have zpragma scan the program to locate printf converters to enable. The default printf does not enable %f to avoid attaching the float library in casual use so you must explicitly ask for it ( https://www.z88dk.org/wiki/doku.php?id= ... figuration
) via a pragma in your program or in a separate pragmas file.
The same program can be compiled using sccz80:
(newlib, sccz80 as compiler)
zcc +zx -vn -clib=new what.c -o what -lm -create-app
However it will still suffer the same bug because the bug is in sccz80 not elsewhere.
Someone has started writing an introductory series
using zsdcc/newlib you may want to check out.
And then have a look at some examples
for newlib here.
The classic library I think you already have some familiarity with