Some bugs in Z88dk discovered during SPECI-SPICE project

Bug reports (if you don't/won't have a Github account)
Post Reply
megaribi
New member
Posts: 3
Joined: Thu Mar 31, 2016 8:05 pm

Some bugs in Z88dk discovered during SPECI-SPICE project

Post by megaribi »

I am developing SPICE compatible electronic circuit simulator for Z80 platforms using Z88dk, and first version will be available soon at sourceforge. I like z88dk very much, it is really amazing how many plaforms it covers. During development I remarked the following bugs in the current build of z88dk.

Compiler and language:

Floating point numbers can not be array initializers, i.e.
float a[3]={1E-3, 1.0,2E5 } ;
can not be compiled.

Enterprise platform:
Compilation fails due to referencing __VideoVariables: during assembly phase. The Fix is very simple: find the label __videoVariables: at the bottom of enterprise_crt0.asm and change lowercase "v" to uppercase.

Sharp MZ platform:
Reading text from keyboard (for example gets function) shows some left arrow characters after every keystroke. It seems that MZ gets routine in Non-ANSI mode mode tries to show ANSI sequences, while command line switch to use ANSI mode has no effect. The workaround was to copy ANSI library to non-ANSI.

Camputers Lynx platform:
The libraries are missing. Probabbly did not compile.

ZX Spectrum platform:
-lmzx math option has bug in assigning integer to floating point. It is recommended to use trunc function. -lm version has not this problem. If stack pointer is very low, in -lmzx mode, machine stack and calculator stack might collide and give very unpredictable results (not an issue of z88dk, but may be to mention it). Library -lm works correctly.

Galaksija platform: This program will crash on Galaksija platform.

#include <stdio.h>
#include <math.h>
char a[1000];
float m;
main() {
puts("Hello");
m=sin(2.0);
gets(a);
puts(a);
}

If it is true that z88dk uses IY register in floating point routines, there is a problem with Galaksija, because it's IM1 routine finishes with JP (IY) and disabling interrupt is not a solution, due to software generated picture. The only solution might be IM2 routine in CRT0, or to use solution from ZX81.

Different platforms have minor problems with gets when typing non-ASCII keys like arrow keys ( for example on Amstrad CPC and Sorcer Exidy, strange characters are displayed).

Nascom 2 platform:
Virtual Nascom crashes during some FP operations, (emulator issue, or the platform uses alternative registers or IX/IY?)

TI86 platforn
gets shows integral symbol after every keystroke. Larger program crashes

Regards,
Samir
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

That's surprisingly few issues! Thanks for reporting them. Stefano is the main guy responsible for the ports, but he's having a break for a while so I'll try to fill in.
megaribi wrote:Floating point numbers can not be array initializers, i.e.
float a[3]={1E-3, 1.0,2E5 } ;
can not be compiled.
You can't actually initialise static floats at all.
Enterprise platform:
Compilation fails due to referencing __VideoVariables: during assembly phase. The Fix is very simple: find the label __videoVariables: at the bottom of enterprise_crt0.asm and change lowercase "v" to uppercase.
That's an easy one - apart from that it does work?
Camputers Lynx platform:
The libraries are missing. Probabbly did not compile.
Yup, they weren't set up to compile.
ZX Spectrum platform:
-lmzx math option has bug in assigning integer to floating point. It is recommended to use trunc function. -lm version has not this problem. If stack pointer is very low, in -lmzx mode, machine stack and calculator stack might collide and give very unpredictable results (not an issue of z88dk, but may be to mention it). Library -lm works correctly.
Have you got an example that demonstrates the integer->fp issue? I've run a couple of tests and it seems to work correctly.
Galaksija platform: This program will crash on Galaksija platform.

#include <stdio.h>
#include <math.h>
char a[1000];
float m;
main() {
puts("Hello");
m=sin(2.0);
gets(a);
puts(a);
}

If it is true that z88dk uses IY register in floating point routines, there is a problem with Galaksija, because it's IM1 routine finishes with JP (IY) and disabling interrupt is not a solution, due to software generated picture. The only solution might be IM2 routine in CRT0, or to use solution from ZX81.
The floating math library uses both ix and iy so that may well explain that one, I don't know enough about the Galaksija (yet) to look at a good solution for it.

Sharp MZ platform:
Reading text from keyboard (for example gets function) shows some left arrow characters after every keystroke. It seems that MZ gets routine in Non-ANSI mode mode tries to show ANSI sequences, while command line switch to use ANSI mode has no effect. The workaround was to copy ANSI library to non-ANSI.

Different platforms have minor problems with gets when typing non-ASCII keys like arrow keys ( for example on Amstrad CPC and Sorcer Exidy, strange characters are displayed).

Nascom 2 platform:
Virtual Nascom crashes during some FP operations, (emulator issue, or the platform uses alternative registers or IX/IY?)

TI86 platforn
gets shows integral symbol after every keystroke. Larger program crashes
I think I need to get some emulators out and give them a whirl!
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

megaribi wrote:I am developing SPICE compatible electronic circuit simulator for Z80 platforms using Z88dk, and first version will be available soon at sourceforge. I like z88dk very much, it is really amazing how many plaforms it covers. During development I remarked the following bugs in the current build of z88dk.
Interesting project!

You probably use graphics and want to support a lot of targets so the classic library is the way to go.

I'll just point out for completeness that there is a new float library in z88dk called math48 that does not use IY. However, it is currently only available through the new c library which only supports a few targets and no graphics at this time. Regarding the static float initialization, sdcc will accept this (note that sdcc's float type is 32 bits so using sdcc means loss of precision) and in the nightly build I think dom has almost got the classic library working with sdcc however the classic float library is not compatible with sdcc; the machinery to interface sdcc to the math48 library is only in the new library currently. I don't think it's too far off to get math48 incorporated into the classic lib but it's not been done yet.
megaribi
New member
Posts: 3
Joined: Thu Mar 31, 2016 8:05 pm

Post by megaribi »

This is a very simple example for assignement integer to float bug in mathzx library. Try this

#include <math.h>
#include <stdio.h>
main () {
static int i;
static float x;
char a [50];
for (i=-100;i<100;i++) {
x=i;
ftoa(x,6,a);
puts(a);
}
}

Compile with
zcc +zx -lndos -lm -create-app testzx.c

and compile with

zcc +zx -lndos -lmzx -create-app testzx.c

The first build works correctly, while the second build will show -2.14748396E9 for all negative numbers. In some cases I had also problems with positive digits, but this example is longer and condition when this happens is less predictable.


BTW:Similarly to the original SPICE 2, SPECI-SPICE will not be graphical in a first version, but it might be added later. The capabilities depend on platforms (16K platforms: linear DC analysis only, 32K: linear AC, DC and TRAN, 48K: linear and non linear circuits, 64K file operations). The build was successful and tested(correctly or with minor problems) for the following platforms: Amstrad CPC464/664/6128, CP/M-80 compatible computers, EACA Color Genie EG2000, Enterprise 48/128, Jupiter Ace , LAMBDA 8300, Linux PC , Mattel Aquarius, MSDOS PC, MSX computers, NewBrain , SAM Coupe , Sharp MZ , Sorcerer Exidy, Sord M5, Sprinter, Timex 2068 , TRS 80 (tape version), TRS 80 (disk version) , VZ 200 ,Windows PC , ZX 80 16 K, ZX 81 16K, ZX Spectrum . Compiled but not yet tested because I can not find suitable emulator: ABC (no clue how to load file in ABCWin) , Memotech MTX (only MAME knows Wav, but it does not catch file header) and Z88 (how to load BAS file in emulator Z88dream, because it does not support RS232 emulation). Compiled and failed in test: Galaksija Plud, Nascom 1. Failed to compile Lynx.

When I tried to link Galaksija with -lm81 FP operations will not reset the computer, but genetrate run time error. I guess that this undocumented library does not use IY register, but uses specific ROM calls.

The wiki remark for Amstrad CPC platfom that disabling interrupt is no longer required is not true when FP operations are used.
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Ah, negative numbers. Yup, that was faulty, now sorted I hope. Along with the other easy ones .

For the Z88 I use OZvm - create an application and then you can just insert the a.63 file into a card slot. You can also create a "flash" card which has basic files on it, but the app route is much easier to test/

Thanks for all the feedback, its really unusual that someone tries out all the platforms.

It looks like bringing math48 into the classic library could unblock the remaining ports so I need to look at what Alvin has done with it and see how hard that is to do.
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Nascom. It looks like there's an issue with alt registers which means that neither floats or longs can be used. I've updated the port to use an int only flavour of printf. This is obviously a bit of an issue for you so we might have to figure out a way around it.

Additionally, when using "Virtual Nascom" from git then there's an issue with the stack(?) (possibly because it loads up basic), but this goes away in the DOS emulator VNascom "vnascom-20080203.zip"
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Nascom again, moving the program start to 0x1000 and fixing the stack to 0xe000 gets everything working. Hopefully that gives you enough space.

Now to find a Sharp MZ emulator!
megaribi
New member
Posts: 3
Joined: Thu Mar 31, 2016 8:05 pm

Post by megaribi »

I have downloaded a new nightly build of z88dk. Thank you for recent fixes.

Just one little fix to Camputers Lynx: In the file lib/lynx_crt0.asm remove ENDIF located at the line 205 to make compilation possible and it will then work correctly.

However, Nascom (which previously partially worked until first FP operations and then crashed)now does not work at all.
E 1000 for my (long) program just shows some hex codes.
Post Reply