Waiting some time!

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
marste
Posts: 179
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Waiting some time!

Post by marste »

After having discussed the user input here I'm for the next help request!
(hope the result of my efforts will be nice surprise for this community! 8-))

The problem is simple: how to wait some predefined fraction of second (with minimum space requirement)?

I do not need to do anything in the meantime! :)

Thank you!
_Stefano
User avatar
TMAOne
Posts: 182
Joined: Thu Aug 16, 2012 6:56 pm
Location: Waterloo, Ontario, Canada

Re: Waiting some time!

Post by TMAOne »

According to the User Manual,

PAUSE 50 will wait approximately 1 second.
PAUSE 32767 will wait approx. 11 minutes.
PAUSE [anything larger] will wait forever.

I don't know if fractions are respected. Perhaps your application is a good way to find out? if not you could always experiment with your own construct.
300 FOR I = 1 TO 99
310 NEXT I

Frankly my ZX81 is always too slow to ever be bored with the speed of the outside world. :)
User avatar
marste
Posts: 179
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: Waiting some time!

Post by marste »

Sorry, forgot to mention in the post: should be machine code (and should consume as minimum amount of byte as possible)!...
User avatar
marste
Posts: 179
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: Waiting some time!

Post by marste »

marste wrote:Sorry, forgot to mention in the post: should be machine code (and should consume as minimum amount of byte as possible)!...
PS: I already tried something similar but seems to fast even repeating it few times:

LD B,0
WAIT: DJNZ WAIT
olofsen
Posts: 177
Joined: Wed Jan 08, 2014 12:29 pm

Re: Waiting some time!

Post by olofsen »

Perhaps using system variable FRAMES directly?
User avatar
PokeMon
Posts: 2253
Joined: Sat Sep 17, 2011 6:48 pm

Re: Waiting some time!

Post by PokeMon »

You may setup FRAMES counter for this purpose.
Frames is decremented 50 times per second (every frame displayed on TV) - 60 times for NTSC systems (US version).

You may do something in the loop as the counter is automatically decremented from the display routine in the background.
You have to be sure not to miss the zero, otherwise it will count quite long (about 11 minutes till next zero. 32767/50 seconds).
Just setup BC register with the desired time, 100 in the example is about 2 seconds.
The time is not very exact and not useful for long exact timer application (a watch for example) as it is based on a crystal with much tolerance, up to +/- 2%.
Bit 7 in B register should be set always.

Code: Select all

        LD      BC,100
        SET     7,B
        LD      ($4034),BC    ; set timer
loop:     LD      HL,($4034)
        LD      A,$7F
        AND     H
        OR      L
        JR      NZ,loop   ; wait for zero
This is working in SLOW mode only.
Frames is not decremented during FAST.

The granularity is 20ms only.
There maybe a more precise granularity but this is complex while counting scanlines (64us steps).
Not sure if you really need this. ;)
Last edited by PokeMon on Wed Aug 27, 2014 8:08 pm, edited 1 time in total.
User avatar
marste
Posts: 179
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: Waiting some time!

Post by marste »

I was already googling it quite a lot but seems that I had the answer on my PC (in the book Assembly Language on the ZX81 By Timothy Swenson An Updated Getting Started Guide) that I found moving forward to another problem!

Seems that:

Code: Select all

LD BC,number of frames to wait
CALL $0F35
Would suffice.

I will experiment both solution tomorrow! :)

Thank you in the meantime!!
User avatar
PokeMon
Posts: 2253
Joined: Sat Sep 17, 2011 6:48 pm

Re: Waiting some time!

Post by PokeMon »

Yes - this works but the time is lost.
You can not execute code while waiting.
And it is the default PAUSE behaviour - means every wait loop can be shortened simply by any keystroke. ;)
David G
Posts: 90
Joined: Thu Jul 17, 2014 7:58 am
Location: 20 North

Re: Waiting some time!

Post by David G »

Many of the old games and programs used something like this:

Code: Select all

ld      hl,5000h ;delay factor
call    DELAYHL
...

DELAYHL:
        dec     hl
        ld      a,h
        or      l
        jr      nz,DELAYHL
        ret
dr beep
Posts: 1419
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Waiting some time!

Post by dr beep »

Code: Select all


      ld b,n ; your delay counter

loop1  ld hl,frames
      ld a,(hl)
loop2      ...... do some code or NOTHING for delay only without B, A or HL (PUSH POP when needed)
      cp (hl)
      jr z,loop2 ; no alteration in timing
      djnz loop1 ; repeat for N* delay 1/50 sec.
Post Reply