It is currently Mon Oct 23, 2017 3:37 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Apr 10, 2005 5:16 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7235
Location: Chexbres, VD, Switzerland
I think it would be interesting to talk about how it would be possible or not to play a sample in the DPCM channel while having timed code.
Many games doesn't use this channel at certain times to avoid gliches (I think to Earthbound), or simply have giches (like Castlevania 3) because the DPCM channel stole one cycle every x time. Often, only the DPCM frequency $f is used to have the better quality as possible.
I think it would be possible to have a timing routine for use when DPCM is playing a sample, and another one for use when it's disabled, and we could check $4015.5 to know witch one we have to execute. So we're just limited to use only one frequecey ($f) instead of be limited to don't use DPCM at all. The only problem would be if the sample stops during the timed code, the CPU will run a bit faster and this would cause gliches, so it's better to use this only when the timing code isn only there for a small part of the screen to avoid huge gliches.

PS : I enventually bought a Game Boy Advance! It's a special model who has the same design as the original Famicom ! That's cool, but it was much more expensive...

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject: It's been done
PostPosted: Mon Apr 18, 2005 5:11 pm 
Offline

Joined: Wed Mar 09, 2005 9:08 am
Posts: 348
Check out Years Behind. It uses timed code during most of the screen rendering, while playing dpcm samples at arbitrary pitch rates. It accomplishes this by using code like this in every timed scanline-loop

lda fractional_cycles
adc #113 ; for PAL, use #85 for NTSC
bcc +
+
sta fractional_cycles

And the #113 value to add to the fractional_cycles variable is then adjusted depending on which pitch rate is played. At the higher rates, you will also need to make it an additional whole cycle faster. (most easily accomplished using self-modifying code, the adc #113 is a good candidate for this as you can just change the opcode to a zeropage addition when it needs to be a cycle longer)

And like you might already have figured out, this also means that a sample can never be allowed to stop by itself when it's finished. The replay code must instead take care of the stopping samples manually, so you might need some silent padding bytes at the end of the sample.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 11:45 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7235
Location: Chexbres, VD, Switzerland
Okay. Have silent after a DPCM sample may waste a lot of spce with just $55 or $aa, but witout this, gliches would appear.
So, a calculation for the number to add would be needed (using a zp-variable would be MUCH simpler than using self-modifing code, I think), and that way it's easy to do 2 version of the rom PAL/NTSC.
Thanks.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 2:34 pm 
Offline

Joined: Wed Mar 09, 2005 9:08 am
Posts: 348
I think you misunderstood me. If you want to support the entire range of pitch rates of the DPCM, then you HAVE TO make your code take a whole cycle less (+additional fractions) per scanline above a certain pitch rate. What happens is basically that you adjust the #113/#85 value so much that it wraps around, and that means it's time to add an integer.

And like I said, I think using self-modifying code to change a zeropage operand into an immediate one is the best way to do this, since you should be using SMC already if you're writing timed scanline loops. But it is of course possible to do something like this instead:

lda skip_an_extra_cycle_or_not
bne +
+

And the space taken by the extra padding bytes for a DPCM sound shouldn't be very big either. After all, the worst case you can have is a DPCM sound being played at pitch $F at a maximum time of one frame, which should eat up less than 100 silent padding bytes per DPCM sound before your replay code turns the sample off manually.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 1:04 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7235
Location: Chexbres, VD, Switzerland
Hum, to support the entire range of pitch rates of the DPCM channel, you have to calculate the value to add every scanline once before trigerring the timed code, then I can't see why self-modifing code would be needed. Or would this method be unprecise enough to don't work ?

_________________
Life is complex: it has both real and imaginary components.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot], tokumaru and 6 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