ZX80: "Visible" msleep()

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

ZX80: "Visible" msleep()

Post by RobertK »

The ZX80 with its annoying "fast mode only" feature refreshes the screen only when it is waiting for user input.

In my program I would like to show a message for three seconds and then remove it again, and during these three seconds I would like to keep the screen "as visible as possible".

During an msleep() pause, the ZX80 screen remains black, so this is not an option.

So I tried to busy loop with repeated gen_tv_field() calls, but the result was not satisfying.

Is there a better way to do this on the ZX80? The screen may bounce at the beginning and the end of the pause, but it should be stable in between.

A crazy idea came to my mind: can we make an fgetc_cons() call and after three seconds somehow trigger a fake keyboard input, so that execution would continue? Could this be already done with the current z88dk functionality, or could this be a potential new z88dk feature?

Such a feature could also be useful for displaying various simulations (Game of Life, solar system orbits, etc.) on the ZX80.
User avatar
dom
Well known member
Posts: 2091
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Looking at the code for fgetc_cons() on the ZX80 it looks like there's an infinite loop, so in theory having it time out should be a case of adding a loop counter which has some rough calibration.

So, it's a new feature, however looking around the source code sleep() does something special for the ZX80 so it might work for you - though it might be unsatisfactory since it does the gen_tv_field() thing.
stefano
Well known member
Posts: 2151
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

I wonder if a simple equivalent program in BASIC can use PAUSE to keep the screen visible on a ZX80 as it happens on a ZX81.
.. by the way creating a pause loop able to leave the display visible is
surely possible.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

I did some testing with sleep() on the ZX80, but whatever value I use (the parameter seems to be in seconds), I don't notice any pause, it only makes the screen bounce and that's it.

Here is my test program:

Code: Select all

/* sleeptest2.c
Compile with
zcc +zx80 -o sleeptest2_ZX80 -create-app sleeptest2.c
zcc +zx81 -startup=2 -lm -o sleeptest2_ZX81 -create-app sleeptest2.c
*/
void main()
{ 
  printf("press any key for test");
  fgetc_cons();        // wait for keypress          
  printf("\nwaiting some time\n");
  // msleep(3000); // keeps the ZX80 screen black during the pause
  sleep(1);        // makes the ZX80 screen bounce but without any pause
  printf("\nfinished waiting\npress any key to exit");
  fgetc_cons();        // wait for keypress            
}
stefano
Well known member
Posts: 2151
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Sleep() is parte of the standard delay functions, I think they're calibrated for a precise delay ( which can't happen easily with the display enabled). PAUSE in turn would use the frame counter.
stefano
Well known member
Posts: 2151
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Oops, I forgot I worked on it already.
Here's what sleep() was supposed to do on zx80:
#include <zx81.h>

int sleep(int secs)
{
clock_t start = clock();
clock_t per = (clock_t) secs * CLOCKS_PER_SEC;
gen_tv_field_init(0);

while ((clock() - start) < per) {
gen_tv_field();
FRAMES++;
}
return 0;
}
stefano
Well known member
Posts: 2151
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

It took me a while to remember: that code portion never worked on a zx80.
Oddly it worked perfectly on the zx81, so I kept it with the intention of fixing it later (which never happened so far).
I can't see why it doesn't work on the zx80, though ! The hw differences shouldn't be relevant for this code portion, and a similar trick makes data run smoothly, so.. ?
Post Reply