NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectLinear Counter in Brad's Sound Doc new  
Posted byAnonymous
Posted on5/8/03 2:36 PM
From IP212.198.0.97  



Hi,

I just can't make out how the linear counter (triangle channel) works, I have made many attempts tinkering things a bit, and between the music in the intro screen of Zelda 2, the music in the beginning temple and the music in SMB1 I can't make them all work together (only as far as the triangle channel is concerned, the rest works) : the triangle channel is either silenced, or plays too much. Different music routines seem to use that channel very differently.

Can someone explain from the beginning how the linear counter works, its relation with the length counter, and the ways its operating mode (load/count) is affected by writes to $4008, $400B *AND $4015* (for the music in the intro of Zelda 2 to work, I need to change the mode when a write to $4015 is made, but this should not be since it's not documented in Brad's doc) ?

Thanks





SubjectRe: Linear Counter in Brad's Sound Doc new  
Posted byquietust
Posted on5/8/03 3:21 PM



The only discrepancy in Brad Taylor's document is that when writing to $4008 such that D7 goes from 1 to 0, the "no change" apparently does NOT apply to the 'current CPU write cycle', but to the current linear counter cycle. My emulator does it this way, and it works fine in every game I've tried.

--
Quietust
P.S. If you don't get this note, let me know and I'll write you another.


SubjectRe: Linear Counter in Brad's Sound Doc  
Posted byAnonymous
Posted on5/8/03 3:29 PM
From IP212.198.0.97  



So you don't touch the operating mode (or anything else) of the linear counter when writes are made to $4015 ?





SubjectRe: Linear Counter in Brad's Sound Doc new  
Posted byAnonymous
Posted on5/8/03 4:09 PM
From IP212.198.0.97  



Ok here's what I do exactly (sorry to insist on little things like this, but I think I misunderstand a detail in the doc somewhere, and I don't know where).

I have a variable "LinearCounter" and a boolean variable "LinearCounterMODE" (which can be "LOAD" or "COUNT")

WRITES TO $400B :
* If bit 7 of $4008 is 1, do LinearCount = value in $4008 (bits 0-6) (Brad says "load" here, what does it mean exactly ?)
* If bit 7 of $4008 is 0, on next linear counter clock, do :
1) LinearCount = value in $4008 (bits 0-6)
2) LinearCountMODE = COUNT

WRITES TO $4008 (before writing the value):
* If bit 7 of $4008 (before the write) = 0, then, regardless of the new bit 7 being written, do : (Brad says "count", what does it mean exactly ?)
1) LinearCount = value in $4008 (bits 0-6)
2) LinearCountMODE = COUNT
* If bit 7 of $4008 (before the write) = 1, then do absolutely nothing if the bit 7 being written is 1, if it is 0, do on next linear counter clock :
1) LinearCount = value in $4008 (bits 0-6)
2) LinearCountMODE = COUNT


Is that correct ? I do not do anything with the length counter (for the triangle channel) when writes are made to $4008 or $400B.

By the way, to decide whether I update the triangle step counter or not, to condition is :
* if LinearCounterMODE == COUNT, the condition is LinearCount == 0
* if LinearCounterMODE == LOAD, the condition is (value in $4008 bits 0-6) == 0.

Is all this exactly correct ? With *exactly* this, if I do not touch the linear counter when writes are made to $4015, I get no triangle sound in the intro of zelda 2.






SubjectRe: Linear Counter in Brad's Sound Doc new  
Posted byMemblers
Posted on5/8/03 6:56 PM
From IP68.58.99.218  



I think my NSF player begins the count when $400B is written. I had to mess around with it a bit to get it working, too. I'm not sure if that's the right way to do it, but Zelda 2 and everything else seems to play fine.




SubjectRe: Linear Counter in Brad's Sound Doc new  
Posted byDisch
Posted on5/9/03 6:22 PM
From IP66.127.105.177  



I'm having this EXACT same problem. The way I had the linear counter implimented (as closely to nessound.txt as I could interpret), the counter pretty much did absolutly nothing =P

I'm gonna mess with it some more and hopefully I'll get it working. I'll post something if I come across anything




SubjectRe: Linear Counter in Brad's Sound Doc new  
Posted byDisch
Posted on5/10/03 04:19 AM
From IP66.127.105.177  



This is the closest I've been able to get so far. Not perfect... but for the most part most games I've tried seem to work. There's definatly tweaking that needs to be done.

My variables:

BYTE nLinearCounter; //the value currently in the counter
BYTE nLinearLoadValue; //the value in the 4008 register (low 7 bits only)
BYTE bLinearSignalCount; //boolean
BYTE bLinearForceSilence; //boolean
BYTE bLinearHighBit; //This is the high bit of the 4008 register
BYTE bLinearLoad; //this is the status of the counter... 1 = LOAD, 0 = COUNT


My previous errors were thinking that bLinearHighBit and bLinearLoad were one and the same (it kind of seems like it from the documentation, every time the bit changes, the mode changes... however the mode can change without the high bit changing... so it's important to track both)


When 4008 is written
============================== (note: 'val' is the value written to the register)

nLinearLoadValue = val & 0x7F;
if(bLinearLoad)
{
  bLinearForceSilence = 0; //allow the triangle wave to play
  nLinearCounter = nLinearLoadValue; //since we're in load mode, they're the same
}
if(bLinearHighBit && !(val & 0x80))
  bLinearSignalCount = 1; //signal to start count mode on the next linear count clock

bLinearHighBit = (val & 0x80);





When 400B is written
==============================

if(!bLinearHighBit)
  bLinearSignalCount = 1;
bLinearLoad = 1; //this register seems to throw us into load mode regardless of the high bit
nLinearCounter = nLinearLoadValue; //in load mode, they're the same
bLinearForceSilence = 0;




When the linear counter is clocked
================================== For each clock:

if(bLinearSignalCount) //we're supposed to enter count mode now
{
  bLinearLoad = 0;
  bLinearSignalCount = 0; //still unsure if this should go here
}

if(!bLinearLoad) //don't count if we're in load mode
{
  if(nLinearCounter)
    nLinearCounter--;
  else
    bLinearForceSilence = 1;
}




Note that bLinearForceSilence can be zero at the same time that nLinearCounter is zero. I think that's what he meant when he said that the Linear Counter's function isn't quite the same as a Terminal count.


Anyway... when bLinearForceSilence is 0, don't update the Triangle Step Counter. Or don't generate a sample. Not quite sure which one sounds better (I think the former is more accurate... but who knows).



That gets most games I tried working... though not all of them. There's still little things here and there that don't work right. Any improvment/tweaks are more than welcome ^_^ I'm dying to get this working.




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo