In your compile line "-startup=31" means you are getting a minimal crt with no streams (no stdout, stdin) so printf and scanf have nothing to connect to. As mentioned you can change your startup to something like "-startup=0" and then you will have stdin,stdout and can printf and scanf. But since that printing is done directly to screen, sp1 will overwrite it unless you tell sp1 to stay away from part of the screen or you do not draw in that part of the screen. It will also add a few k to your program size; you can keep printf small by adding a pragma that eliminates the % coverters you are not using and you can eliminate stdin entirely by adding a custom driver instantiation to your project.
Within sp1, you can use sp1_PrintAt() and sp1_PrintAtInv() to print individual characters as you've been doing. I wouldn't say it's slow but it is one char at a time and that does mean a character position calculation on each call.
sp1_PrintString() prints a string that can contain control codes. One of the things it's meant for is printing the entire screen for a level in a compact way without loops and individual PrintAt, so it should save memory if levels are printed this way. To print strings with it, you need a struct sp_pss (Print String Structure,
https://github.com/z88dk/z88dk/blob/mas ... sp1.h#L123 ) that holds print state - things like current x,y position and flags for what to do if when the text reaches the right edge or bottom of the screen.
Code: Select all
struct sp1_Rect fs = { 0, 0, 32, 24}; // rectangle covers full screen
struct sp1_pss pss = {
&fs, // print confined to this rectangle
SP1_PSSFLAG_INVALIDATE | SP1_PSSFLAG_XWRAP | SP1_PSSFLAG_YINC | SP1_PSSFLAG_YWRAP,
0, // current x
0, // current y
0, // attribute mask - overwrite underlying colour
INK_BLACK | PAPER_WHITE,
0, // sp1_update* must be consistent with x,y
0 // visit function (set to zero)
};
sp1_SetPrintPos(&pss, 10, 10); // this sets x,y and sp1_update* in pss
sp1_PrintString(&pss, "Hello World");
The printing uses background tiles. % converters as in printf do not work but if you need that you can sprintf to a buffer first and then print the string result.
The control codes it understands are listed here:
https://github.com/z88dk/z88dk/blob/mas ... ng.asm#L22
Notice that it follows the spectrum character set where \r means next line (not \n).