raxoft / z80test

Set of programs to test the implementation of the Zilog Z80 instruction set.
MIT License
99 stars 11 forks source link

How to use #2

Closed hsaturn closed 1 year ago

hsaturn commented 1 year ago

Hi Patrik

I'm the author of klive, a recent Zx spectrum emulator that is at a stone from working. I guess my z80 is not perfect. The fail occurs now in the keyboard routine.

Reading your tests, I caould not figure how to use them. Could you write a little doc that descrbes how to integrate your tests ?

hsaturn commented 1 year ago

Edit, searching more on z80 tests, I've found this use of your project. https://spectrumcomputing.co.uk/forums/viewtopic.php?t=752 And looking more at your code, I've found "Return to BASIC". So I guess now that tests can only be ran from Basic after building the test. I cannot thus use this because the emulation is not perfect enough.

Best regards

raxoft commented 1 year ago

I guess it is a different Klive than this one, right?

Well, the tests are in the TAP format, which is the most basic tape format for ZX spectrum. If your emulator can't load TAPs yet, I suggest you create a snapshot in any already existing emulator and use that. Any snapshot type would work, but of course SNA is the easiest to implement on your side. It's flawed in many ways, but for this test it will do just fine. Best point at which to create the snapshot would be right when the machine code is executed at address 32768, so you don't have to worry about BASIC at all.

However, if your emulator can't run BASIC yet, definitely start with the test for the documented instructions first, but chances are that even the test itself will not work as it needs at least rudimentary functionality of many instructions in the first place.

hsaturn commented 1 year ago

Yes, my klive is there https://github.com/hsaturn/klive

This emulator is not yet capable of reading input (TAP SNA etc).

Maybe I'm dreaming :-) but the ideal test suite would give a simple api, run only one instruction and check output. Because having tests that need the Z80 to run seems strange to me. -> test need z80 to run -> z80 needs test to be adjusted

I'd prefer an API (c/c++) such as

bool runSingleInstruction(Registers &registers, byte* instruction, uint8_t buffsize)

And the z80 test could be

for each Z80 instruction do if not runSingleInstruction ( registers, instruction ) or registers != expected_registers bad ++ done

... but ... i'm dreaming :-D

raxoft commented 1 year ago

Because having tests that need the Z80 to run seems strange to me.

Well, that was the only way to make sure it runs identical to real machines, as you can take the tap, load it to into the real machine and check the results. This is in fact how the CRCs in test vectors were created in the first place.

Technically, you could take the test vectors and write a C program which would work the way you describe. But I guess it's still much easier to get the rudimentary Z80 emulation working. The test loop itself doesn't use any fancy instructions nor flags AFAICR.

hsaturn commented 1 year ago

I can agree that rudimentary loop is easy to write, but printch has to work too, so this implies the screen emulation, memory emulation and maybe i/o emulation (for example bank switching). Sounds to me a lot harder. In addition this is coupled with a certain hardware. I want to test z80 alone, not zx spectrum, nor zx81 or amstrad, trs80 etc...

My rudimentary loop works very well (unless I couldn't see the red strippes during Zx boot, nor the initial K prompt). But I cannot run yet unit tests, even if the whole emulation is very close to work. I'm trying to find something more suitable to my needs. But it's not easy.

I've found lot of tests that run on 99.9% working emulation. These tests are very sharpen tests that in fact does not test, but verify if the CPU implements all and all features. I see them more as a check of the system trying to find some failures.

I need since the begining a test that can run from 0% to 100%. (Ok, today, it is more from ~97%), but during the first weeks of the project, I would have need a test suite capable to run from a 0% implemented emulation.

Once my emulation stable enough, I'll go back here to use these tests.

Thanks

Best regards.

hsaturn commented 1 year ago

Found this:

This z80 test does exactly what I want https://www.jsdelivr.com/package/npm/z80-test?nav=config&path=src Unfortunately, it is not written for c language.

raxoft commented 1 year ago

but printch has to work too,

Not really - simply comment out the chan-open init and replace the rst 16 with the out instruction and then you can easily hook that to log the output in your program.

As for getting the test loop itself working, in case it doesn't already, I guess you should be able to use your IDE debugger to step through the individual instructions along with the source code and find the culprit which is not working properly. It is really just a couple of the most basic instructions you need to get working, so it shouldn't be that hard.

hsaturn commented 1 year ago

This seems to looks like what I'm searching for

https://github.com/floooh/chips-test/blob/1378469a3e9ed7144e73ecdef25f3619044da175/tests/z80-fuse.c

hsaturn commented 1 year ago

rst 16

Hmmmm, yes !!! you're so right ! I did not remember that rst 16 was a char output to screen. This was 40 years ago :-D I was coding in asm with mons and gens now I remember the rst 16.

As Klive is based on "plugins" this is trivial for me to write an alternate output window with a.

So last point is: where are the SNA's you are talking about. I can only see .asm in your repo ? (Edit: Answer to myself, I did not look into the makefile ... tap files are there)

I really think the current state of my cpu matches the needs of your z80 tests. neitherless it's easy to fill the gap if needed.

I suggest you to convert this 'issue' to a discussion (I would have made it a discussion since the beginning but only 'issue' tab is available).

My opinion has changed with that reply: I can use your tests and do not have to search for an alternative.

Thanks a lot for your time.

Above this story, the goal of Klive is to provide an IDE around the spectrum that'd allow to develop (games probably ?) in C language (I'd prefer c++ but it seems that c++ is a very hard goal). The edition / compilation will be made with the IDE itself, with all the speed, power and capabilities of modern computers then execute / debug on the emulation itself. I have the emulation to be perfect enough for this next step.

raxoft commented 1 year ago

BTW, to save some time, you don't actually even have to bother with SNA - if you compile your own version with the print rerouted to out, you can just load the binary blob of the main test object itself to 32768 and let your emulator start from there (set SP to 32768, too).

Alternatively, if you don't build your own version, you can just extract the main code block from the tap file (either directly or using an emulator) and hook the rst 16 directly.

hsaturn commented 1 year ago

Hi again...

sjasm from here : https://github.com/Konamiman/Sjasm is not the right assembler. I've tried severall one (zasm etc..) none work. I've finally found this one http://www.xl2s.tk/ that seems to work. z80full.lst is generated with hexa code

 9.  00:8000  F3                  main:       di                                  ; disable interrupts
10.  00:8001  FD E5                           push    iy                          ; preserve stuff needed by BASIC

I recognize there some hexa sequences (incredible, my brain retains hexa codes. Call=CD, push hl=E5) as I used to assemble z80 with my hands !!! (Zx81 old good time :-) )

Now the next target in makefile is to create tap files. But I cannot find 'mktap' anywhere.

I'm under Linux.

This is quite frustrating. I really suggest you to write a minimal doc, with links on tools or enough information that could help to find (url can changes).

I think I'm gonna write a script to take extract hexa code from z80full.lst and convert it to a memory file. But am not sure 100% that this is what has to be done.

Best regards

raxoft commented 1 year ago

Yes, the one from http://www.xl2s.tk/ is the one (as mentioned in the other issue where someone asked about it).

The mktap is from Jan Bobrowski's test suite, used to build his tests. You can find the link on his QAOP page: https://torinak.com/~jb/qaop-java/.

For your use case however you don't need the TAP at all - just load the binary file created by sjasm directly at 32768 and you are good to go.

hsaturn commented 1 year ago

Thanks a lot. I think these two links should appear in the README.md under build section or something like that. -> I could not find any binary file generated by sjsam you are mentionning.

But, because I should have find one, I've re-read the makefile and found that the bin file could not be generated because it was deleted by the makefile itself !

So I just had to

make z80full.out

To rebuild it. (14298 bytes z80full.out)

-> Maybe this could also appear in a README.md ?

Thanks. Sorry to have bothered you, I'm an expert in c++ not in z80 since years. I have all what I need now.