Page 1 of 1

Support for stdio on esxdos in ZX Next target?

Posted: Mon Jul 24, 2017 1:33 pm
by Stefan123
I saw that you have submitted a skeleton of the ZX Next target in the z88dk newlib. That's great :)

What are your plans for implementing fread() etc in stdio.h on top of esxdos?

Just for fun, I did a quick-and-dirty test shot of implementing fopen() and fread() using esxdos myself using Mike Dailly's Z80 esxdos routines in SNasm syntax. I got it to compile with z88dk and I think fopen() worked but fread() did not. My biggest problem when doing things like this is how to debug the code. I really miss being able to do source code debugging at the C level... Is there a debug version of the Spectrum printf() that prints on a dedicated debug console or to a file when running in an emulator? What is your debugging tips and tricks when debugging combined C and assembly code? I don't plan to pursue this little experiment, I'm just curious.

Regards,
Stefan

Posted: Mon Jul 24, 2017 3:45 pm
by alvin
Stefan123 wrote:What are your plans for implementing fread() etc in stdio.h on top of esxdos?
I plan to fully integrate it but as the current stdio implementation in newlib has not been updated yet for disk, I will probably add it as a hack at first given I have to be realistic about my available time over the next month. What the newlib implementation is missing is space for file pointers, which is easy enough to add, but there has to be two that are independent - one at FILE* level and one at file descriptor level. I'm not sure if this can be easily bodged but if it can, the bodge will be invisible and everything will work as expected, pending a proper integration. If this is not possible, I'll probably just expose a parallel set of functions, like how people currently use it from asm.
Just for fun, I did a quick-and-dirty test shot of implementing fopen() and fread() using esxdos myself using Mike Dailly's Z80 esxdos routines in SNasm syntax. I got it to compile with z88dk and I think fopen() worked but fread() did not. My biggest problem when doing things like this is how to debug the code. I really miss being able to do source code debugging at the C level... Is there a debug version of the Spectrum printf() that prints on a dedicated debug console or to a file when running in an emulator? What is your debugging tips and tricks when debugging combined C and assembly code? I don't plan to pursue this little experiment, I'm just curious.
I am not aware of any emulator that is specifically written to allow these "out-of-band" type interactions with the running program although I don't think it would be hard to do.

On the spectrum itself, z88dk can easily create several independent text windows on screen and have one act as a debug console using fprintf(stderr,...), fscanf(stderr,...) for example but that doesn't help you if the machine crashes. If an emulator allowed it you could also get these streams to send data to special io ports mapped by the emulator for such a thing.

What I do now is compile with "-m --list" and optionally "--c-code-in-asm" to get list files for the .c that show the compiled code translated to asm. The "-m" will give the actual memory addresses for labels in those list files. Then I debug as if it is an asm program, looking at the .c.list files as necessary to see where it is in the c code. At asm level I am not using asm-level symbols, as would be supplied by "-m", because few emulators allow that. Only ZXesurx has the beginning of this and Mike's emulator as far as I know and for those it shouldn't be hard to process the information from "-m" to be suitable for them.

Posted: Tue Aug 01, 2017 1:13 pm
by Stefan123
Thanks for the debugging tips. I noticed that you have implemented a C API for the esxdos routines now, great work :-)