printf problems & hangs on Amstrad CPC

Known bugs with 1.8
Post Reply
Mochilote
Member
Posts: 42
Joined: Thu Jul 19, 2007 10:54 am

printf problems & hangs on Amstrad CPC

Post by Mochilote »

I can't get printf working on cpc, it only prints '<><><><><>' and even it hangs the cpc.

This simply program:

Code: Select all

#include <stdio.h>

main()
{
        printf("HELLO WORD\n");
        printf("Z88DK\n");
        printf("ON AMSTRAD CPC\n");
        while (getk() != 13) {};
}
Compiled with:
zcc +cpc -o printf4.bin printf4.c -create-app -lndos -Ca-v

Gets this on the cpc:

Image

The program/machine is also hang. I've used the sourceforge 1.8 binaries zip.
Of course, this works perfectly on v1.7

Cheers.
norecess
Member
Posts: 73
Joined: Thu Mar 20, 2008 12:58 am

Post by norecess »

Same trouble here. Each character to be written is replaced by <><><> etc.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Wow.. it's not exactly what we meant for "stability improvements" :D
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Have you tried rebuilding cpc_clib.lib?

I'm not happy with the chaotic rebuilding of libs (i.e. random cleans) so I'm going to work on sorting that out at some point.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Not still, I just got to reproduce the problem... I'll try it.
The random cleans I'm responsible for are related to the ZX81 stuff, I decided to force a clean before and after the build process.. I also thought to leave it unchained, in such case the "zx81libs" group would fit.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Hey, I tried to rebuild the library and tried to include the 8080 version of vfprintf_mini (seems to be the only difference from the working version), but I didn't succeed.
The only quick workaround I have so far is to recover the older LIB version and put it inthe z88dk/lib/clibs folder:

http://z88dk.cvs.sourceforge.net/*check ... vision=1.7

It also proves the issue is on the library, probably for something happening during compilation.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Ok, I found the point making the programs crash, but the reason is still unclear.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code crashing:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

.fputc_cons
ld hl,2
add hl,sp
ld a,(hl)
cp 13
jr nz,nocr
call firmware
defw txt_output
ld a,10
.nocr call firmware
defw txt_output
ret

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code working:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

.fputc_cons
ld hl,2
add hl,sp
ld a,(hl)
cp 13 ; CR ?
jr nz,nocr
call $BB5A
ld a,10
.nocr
jp $BB5A
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Found the problem.

The firmware calling routine in the CRT0 stub had two errors:
- AF' wasn't saved properly, and the A register was altered before the ROM call
- The interrupt needed to be disabled after every ROM call

The latter change could have greatly improved the stability of the port, so I put in the new library recompilation the full version of stdio.. let me know if you find problems.

The required files to patch a bin 'distro' are:

http://z88dk.cvs.sourceforge.net/*check ... c_crt0.asm
http://z88dk.cvs.sourceforge.net/*check ... c_clib.lib
http://z88dk.cvs.sourceforge.net/*check ... i_clib.lib
Mochilote
Member
Posts: 42
Joined: Thu Jul 19, 2007 10:54 am

Post by Mochilote »

I have test these files and printf now works correctly :).

But i have found another bug or at least another difference with v1.7 :(:
Function getk() in v1.7 waits for a keypress and then return key code
Function getk() in v1.8 retunrs inmediately with code 0 or if a key is pressed returns key code, but never waits.

Cheers.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

It is correct.
The function you're looking for is fgetc_cons.
Mochilote
Member
Posts: 42
Joined: Thu Jul 19, 2007 10:54 am

Post by Mochilote »

stefano wrote:It is correct.
The function you're looking for is fgetc_cons.
Ok, thanks.
Post Reply