z88dk forums

z80 Development Kit

You are not logged in.

#1 2008-03-18 10:56:48

Mochilote
Member
From: Spain
Registered: 2007-07-19
Posts: 42
Website

printf problems & hangs on Amstrad CPC

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

This simply program:

Code:

#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:

http://img291.imageshack.us/img291/2096/printfzr1.png

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

Cheers.

Offline

 

#2 2008-03-20 01:02:49

norecess
Member
From: Montreal, Canada
Registered: 2008-03-20
Posts: 73
Website

Re: printf problems & hangs on Amstrad CPC

Same trouble here. Each character to be written is replaced by <><><> etc.

Offline

 

#3 2008-03-20 12:02:55

stefano
Administrator
Registered: 2007-07-16
Posts: 711

Re: printf problems & hangs on Amstrad CPC

Wow.. it's not exactly what we meant for "stability improvements"  big_smile

Offline

 

#4 2008-03-20 12:15:33

dom
Administrator
Registered: 2007-07-15
Posts: 745
Website

Re: printf problems & hangs on Amstrad CPC

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.

Offline

 

#5 2008-03-20 20:37:28

stefano
Administrator
Registered: 2007-07-16
Posts: 711

Re: printf problems & hangs on Amstrad CPC

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.

Offline

 

#6 2008-03-21 13:45:22

stefano
Administrator
Registered: 2007-07-16
Posts: 711

Re: printf problems & hangs on Amstrad CPC

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.

Offline

 

#7 2008-03-25 09:33:38

stefano
Administrator
Registered: 2007-07-16
Posts: 711

Re: printf problems & hangs on Amstrad CPC

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

Offline

 

#8 2008-03-25 14:24:29

stefano
Administrator
Registered: 2007-07-16
Posts: 711

Re: printf problems & hangs on Amstrad CPC

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

Offline

 

#9 2008-03-25 19:55:59

Mochilote
Member
From: Spain
Registered: 2007-07-19
Posts: 42
Website

Re: printf problems & hangs on Amstrad CPC

I have test these files and printf now works correctly smile.

But i have found another bug or at least another difference with v1.7 sad:
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.

Offline

 

#10 2008-03-25 20:12:32

stefano
Administrator
Registered: 2007-07-16
Posts: 711

Re: printf problems & hangs on Amstrad CPC

It is correct.
The function you're looking for is fgetc_cons.

Offline

 

#11 2008-03-25 21:51:17

Mochilote
Member
From: Spain
Registered: 2007-07-19
Posts: 42
Website

Re: printf problems & hangs on Amstrad CPC

stefano wrote:

It is correct.
The function you're looking for is fgetc_cons.

Ok, thanks.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson