It is currently Mon Jul 23, 2018 9:05 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Problems with Background updatePosted: Sat Jun 24, 2017 11:23 am

Joined: Sun Sep 26, 2010 10:29 pm
Posts: 40
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_DATA = 0x10+(player1.score >> 10);               /* 0x10 is the tile address of digit 0 in .chr file*/
PPU_DATA = 0x10+((player1.score / 10) % 10);
PPU_DATA = 0x10+(player1.score % 10);

/* player2 score */
PPU_DATA = 0x10+(player2.score >> 10);
PPU_DATA = 0x10+((player2.score / 10) % 10);
PPU_DATA = 0x10+(player2.score % 10);

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

Sebastian

Top

 Post subject: Re: Problems with Background updatePosted: Sat Jun 24, 2017 11:35 am

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3090
Location: Tampere, Finland
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.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

Top

 Post subject: Re: Problems with Background updatePosted: Sat Jun 24, 2017 1:05 pm

Joined: Sun Sep 26, 2010 10:29 pm
Posts: 40
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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: orlaisadog and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki