4

I'm trying to compile a C program with z88dk for the ZX Spectrum. Using printf(), when the text hits the bottom line of the screen on line 24 the program stops executing until a key is pressed on the keyboard - but I need printf() to not lock up waiting for a key to be pressed.

The github page for z88dk states: "The screen scrolls when line 24 is "hit", the routine used is in the 48k ROM." Is this what I need to disable? Is this scroll routine being fired, and is this what waits for user input before continuing?

In BASIC, the "scroll?" message can be disabled with POKE 23692,n and printing behaves normally. I have tried to call zx_bpoke(23692, 255); to try to disable the wait in C but this has no effect. How can I scroll without waiting for a keypress?

Is 23692 the right address to poke for the 48K ROM to disable the scroll key press routine?

An example:

#include <stdio.h>
#include <stdlib.h>
#include <z80.h>
int main() {
    for (int i = 0; i < 500; i++){
        printf("%d\n", i); //<-- will pause here until key is pressed when bottom of the screen is hit
        //attempt to disable this in the scroll routine
        z80_bpoke(23692, 255); //<-- doesn't work?

    }
}

I compile with the command:

zcc +zx -vn -startup=1 -clib=new -create-app main.c -o out

After line 23, the Spectrum waits for a key to be pressed, even when POKING at address 23692. Any help would be appreciated!

1

2 Answers 2

5

One of the complications with z88dk is that there are two libraries: classic and newlib. These days, a lot of the code is shared but there are two separate implementations of stdio and console drivers. The comment about "ROM driver" is referring to how classic scrolls the screen: it just calls address 3582 in ROM3 by default.

However, the compile line mention, uses newlib, and the console driver for startup=1 isn't the ROM printer so won't respond to a poke 23692,255, but a custom terminal driver. The behaviour of the terminal is controlled by an ioctl call disabling the IOCTL_OTERM_PAUSE flag:

#include <stdlib.h>
#include <stdio.h>
#include <z80.h>
#include <sys/ioctl.h>

int main() {
    // Disable waiting for input when the screen is scrolled
    ioctl(1, IOCTL_OTERM_PAUSE, 0);

    for (int i = 0; i < 500; i++){
        printf("%d\n", i);

    }
}

This information was taken from the following project issue: https://github.com/z88dk/z88dk/issues/682#issuecomment-379526038

1

In ZX Spectrum basic, POKE 23692,255 works fine, when done every line to be printed -- the scroll becomes effectively infinite and never requests "scroll?". Check that printf() code does not fiddle with the 23692 value and that z80_bpoke(23692, 255); really does what it is intended to do. Maybe *((char *)23692)=0; would work instead?

2
  • you mean *((char *)23692)=255; probably Commented Mar 10, 2020 at 19:43
  • 1
    actually there is no difference between 0 and 255, if set every printed line.
    – lvd
    Commented Mar 10, 2020 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .