It is currently Thu Sep 21, 2017 9:15 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Jun 24, 2017 11:23 am 
Offline
User avatar

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


Top
 Profile  
 
PostPosted: Sat Jun 24, 2017 11:35 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2945
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: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Sat Jun 24, 2017 1:05 pm 
Offline
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group