nesdev.com
http://forums.nesdev.com/

Problems with Background update
http://forums.nesdev.com/viewtopic.php?f=2&t=16136
Page 1 of 1

Author:  -Basti- [ Sat Jun 24, 2017 11:23 am ]
Post subject:  Problems with Background update

Hi,
I am facing an issue while I update a background once a player (two-player Pong game) hits a score. Somehow, nearly randomly after a couple of scores, one digit of the score is drawn beside the last digit of the three digits, which display the score (1-9). This is my update routine:
Code:
    /* player1 score */
    PPU_ADDRESS = MSB(0x204b);
    PPU_ADDRESS = LSB(0x204b);
    PPU_DATA = 0x10+(player1.score >> 10);               /* 0x10 is the tile address of digit 0 in .chr file*/
    PPU_ADDRESS = MSB(0x204c);
    PPU_ADDRESS = LSB(0x204c);
    PPU_DATA = 0x10+((player1.score / 10) % 10);
    PPU_ADDRESS = MSB(0x204d);
    PPU_ADDRESS = LSB(0x204d);
    PPU_DATA = 0x10+(player1.score % 10);

    /* player2 score */
    PPU_ADDRESS = MSB(0x205b);
    PPU_ADDRESS = LSB(0x205b);
    PPU_DATA = 0x10+(player2.score >> 10);
    PPU_ADDRESS = MSB(0x205c);
    PPU_ADDRESS = LSB(0x205c);
    PPU_DATA = 0x10+((player2.score / 10) % 10);
    PPU_ADDRESS = MSB(0x205d);
    PPU_ADDRESS = LSB(0x205d);
    PPU_DATA = 0x10+(player2.score % 10);


Does someone has a glimpse why sometimes digits are placed at 0x204e or 0x205e?

Thanks in advance,
Sebastian

Author:  thefox [ Sat Jun 24, 2017 11:35 am ]
Post subject:  Re: Problems with Background update

Those divisions (and modulos) by 10 are potentially quite expensive operations. You should not be doing them in the middle of your VBlank updates. Instead, calculate the results outside VBlank, store them in some kind of a buffer (or a set of variables), and copy from there during VBlank.

If your updates take longer than the VBlank lasts (about 20 scanlines on NTSC machines), all kinds of crazy things can happen.

Author:  -Basti- [ Sat Jun 24, 2017 1:05 pm ]
Post subject:  Re: Problems with Background update

thefox wrote:
Those divisions (and modulos) by 10 are potentially quite expensive operations. You should not be doing them in the middle of your VBlank updates. Instead, calculate the results outside VBlank, store them in some kind of a buffer (or a set of variables), and copy from there during VBlank.

If your updates take longer than the VBlank lasts (about 20 scanlines on NTSC machines), all kinds of crazy things can happen.


Thank you, transferring the calculation of digits out of the NMI routine seems to solve my problem :D

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/