Okay, so when v-blank is activated, the seventh bit of the ppu status register is changed to one, leading to the end of this loop. But what causes it? I found this:
The VBlank flag of the PPU is set at tick 1 (the second tick) of scanline 241, where the VBlank NMI also occurs. The PPU makes no memory accesses during these scanlines, so PPU memory can be freely accessed by the program.
So during the second "tick" (clock pulse?) of the scanline 241 the seventh bit of the PPU status register becomes one.
So I will have to:
1)Start to count ticks, both from the PPU and from the CPU
2)Start to count scanlines
Since there is about 113 cpu clocks per scanline, does that mean that at only 241*113.667 = a lot of clock cycles will the loop stops? I shall start the counting of the cpu cycles from the cpu's first instruction read? and the ppu?