Menu

#168 Printing text to console in ucsim_z80 for sm83

None
closed
nobody
None
5
2024-05-26
2022-07-27
Under4Mhz
No

I'd like to print some output on the GB80 simulator for testing. I've tried the following:

// GPL 2.0
#include <stdio.h>
#include <stdint.h>

void main() {

    printf( "Start\n" );

    printf( "End\n" );
}

#ifdef __SDCC
volatile unsigned char __at 0x3fff sif;
int putchar(int c)
{
    sif = 'p';
    sif = c;

    return c;
}
#endif

// sdcc -msm83 ./print_test83.c  -o print_test83.ihx && ucsim_z80 -t GB80 -I if=rom[0x3fff] print_test83.ihx

I also tried:

// GPL 2.0
#include <stdio.h>
#include <stdint.h>

void main() {

    printf( "Start\n" );

    printf( "End\n" );
}

#ifdef __SDCC
volatile __sfr __at 0xff sif;
int putchar(int c)
{
    sif = 'p';
    sif = c;

    return c;
}
#endif

// sdcc -msm83 ./print_test83.c  -o print_test83.ihx && ucsim_z80 -t GB80 -I if=outputs[0xff] print_test83.ihx

Which I don't expect to work since GB80(sm83) has memory mapped I/O.

What am I doing wrong?

Discussion

  • Daniel Drotos

    Daniel Drotos - 2022-07-27

    I'v chacked the code I figured out that sm80 simulator defines two address spaces, rom for 0-0x5fff and xram for 0xa000-0xff7f. Write operations are eliminated if address is not in xram area. As I see in map file, sdcc uses xram over 0xc000, so 0xa000-0xbfff is free for you.

    For example, you can place sif at 0xbfff and start ucsim like: ucsim_z80 -tgb80 -Iif=xram[0xbfff] ...

     
  • Under4Mhz

    Under4Mhz - 2022-08-01

    yes, that worked. thanks.

    // GPL 2.0
    #include <stdio.h>
    #include <stdint.h>
    
    void main() {
    
        printf( "Start\n" );
    
        printf( "End\n" );
    }
    
    #ifdef __SDCC
    volatile unsigned char __at 0xbfff sif;
    int putchar(int c)
    {
        sif = 'p';
        sif = c;
    
        return c;
    }
    #endif
    
    // sdcc -msm83 ./print_test83.c  -o print_test83.ihx && ucsim_z80 -tgb80 -Iif=xram[0xbfff] print_test83.ihx
    
    sdcc -msm83 ./print_test83.c  -o print_test83.ihx && ucsim_z80 -tgb80 -Iif=xram[0xbfff] print_test83.ihx
    uCsim 0.7.5, Copyright (C) 1997 Daniel Drotos.
    0> Loading from print_test83.ihx
    134 words read from print_test83.ihx
    r
    Simulation started, PC=0x000000
    Start
    End
    
     
  • Daniel Drotos

    Daniel Drotos - 2024-05-26
    • status: open --> closed
    • Group: -->
     

Log in to post a comment.

Auth0 Logo