Waiting some time!
Waiting some time!
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! )
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
(hope the result of my efforts will be nice surprise for this community! )
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
Re: Waiting some time!
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.
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.
Re: Waiting some time!
Sorry, forgot to mention in the post: should be machine code (and should consume as minimum amount of byte as possible)!...
Re: Waiting some time!
PS: I already tried something similar but seems to fast even repeating it few times:marste wrote:Sorry, forgot to mention in the post: should be machine code (and should consume as minimum amount of byte as possible)!...
LD B,0
WAIT: DJNZ WAIT
Re: Waiting some time!
Perhaps using system variable FRAMES directly?
Re: Waiting some time!
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.
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.
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
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.
Re: Waiting some time!
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:
Would suffice.
I will experiment both solution tomorrow!
Thank you in the meantime!!
Seems that:
Code: Select all
LD BC,number of frames to wait
CALL $0F35
I will experiment both solution tomorrow!
Thank you in the meantime!!
Re: Waiting some time!
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.
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.
Re: Waiting some time!
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
Re: Waiting some time!
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.