Code: Select all
ld hl, frames
ld a, (hl)
sub n
repeat cp (hl)
jr nz, repeat
Code: Select all
ld hl, frames
ld a, (hl)
sub n
repeat cp (hl)
jr nz, repeat
The power of cooperation!!antoniovillena wrote:Based on DrBeep solution
Code: Select all
ld hl, frames ld a, (hl) sub n repeat cp (hl) jr nz, repeat
Code: Select all
LD C,22
.loop: HALT
DJNZ $-1
DEC C
JR NZ,.loop
Code: Select all
ld b, N
outer push bc
inner djnz inner
pop bc
djnz outer
Likeantoniovillena wrote:Another 8 bytes solution if you don't want multiple of frames:
Aprox 7*N^2, with a limit of about 450.000 cyclesCode: Select all
ld b, N outer push bc inner djnz inner pop bc djnz outer
The old classic was "PAUSE 4E4" which fulfills the "anything larger" criteria and can (sort of) be pronounced "pause for ever".TMAOne wrote: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.
If I did proper calculation (the sum of the squares) the inner loop will be executed 5.5 million time with B=255.antoniovillena wrote:Another 8 bytes solution if you don't want multiple of frames:
Aprox 7*N^2, with a limit of about 450.000 cyclesCode: Select all
ld b, N outer push bc inner djnz inner pop bc djnz outer
TMAOne wrote:According to the User Manual,
PAUSE 50 will wait approximately 1 second.
marste wrote:If I did proper calculation (the sum of the squares) the inner loop will be executed 5.5 million time with B=255.antoniovillena wrote:Another 8 bytes solution if you don't want multiple of frames:
Aprox 7*N^2, with a limit of about 450.000 cyclesCode: Select all
ld b, N outer push bc inner djnz inner pop bc djnz outer
Considering that djnz is 3 cycles (2 last one) this means 16.5 millions clock cycles, that in fast mode at 3.5MHz should result in little less than 5 seconds (probably 5 times more in slow mode).
Nice this "optimization" attitude (and challenge participation!), I will need a lot for my 1K little project to work out!
Let's see!!
Inner loop only has 3323 cycles in the first iteration (if you put ld b,0 as maximum count). The rest of the iterations the time is decremented, so it's 256,255,254..3,2,1. Instead 256*256*13 cycles you can aproximate with 256*128*13, that it's the half.PokeMon wrote:Your calculations are wrong in this case.
DJNZ uses only register B.
So maximum execution for inner loop is 256*256 = 65536.
If you count clock cylces then DJNZ has 13 clock cycles if jumping, 8 if not.
So the inner loop is 3323 clock cycles plus 21 cycles for PUSH/POP = 3344 cycles = 1ms for 308ns cycle time (@ 3.25 MHz).
So the outer loop is maximum 256ms running time.
I would calculate about 25% running time in slow mode - so this is about 1 second in slow mode.