This is an email posted to nesdev by Ki a while back.  I have removed one
line at the end regarding the B flag of the cpu(the information was 
incorrect, which Ki noted in a later email).

--------------------------------------------------------------------------------

 By reading Brad's NESSOUND document, we know that there is a
"frame counter" in the NES/FC APU.  I would like to post
some more on this.

  The frame counter is reset upon any write to $4017.  It is
reset at system power-on as well, but is NOT reset upon
system reset.

  Thanks to Samus Aran, we now know the exact period of the
PPU's single frame.  In another words, we are now sure that
the NMI occurs on every 29780 2/3 CPU cycles.

  However, the APU's single frame is NOT 29780 2/3 CPU cycles.
What I mean by "APU's single frame" here is that it is the
number of CPU cycles taken between the frame IRQs.

  The APU's single frame seems to be:

    1789772.727... / 60 = 29829 6/11  [CPU CYCLE]

  Below is a simple diagram which shows the difference
in periods of the PPU's single frame and the APU's.


    RESET         29780 2/3 CPU CYCLES          NMI
PPU   |------------------------------------------|
      |           29829 6/11 CPU CYCLES          IRQ
APU   |----------|----------|----------|----------|


  Note that if you write $00 to $4017 on every NMI, the frame
IRQ would NEQint32		Packet counter(linear, starts at 0).
uint8[variable]	Data.

Structure of tcp packet data:

uint32		Packet counter("	").
uint8[variable]	Data.



Data format of server->client communications:

	uint8[4]	Controller data
	uint8		Command byte.  0 if no command. Otherwise(in decimal):

			1	Select FDS disk side.
			2	Insert/eject FDS disk.
			10	Toggle VS Unisystem dip switch editing.
			11 ... 18 Toggle VS Unisystem dip switches.
			19	Insert VS Unisystem coin.
			30	Reset NES.
			31	Power toggle NES.
			40	Save state(not implemented correctly).
			41	Load state(not implemented correctly).
			42 ... 50	Select save state slot(minus 42).

	Special message communications occurs if the "Packet counter" is 
	0xFFFFFFFF(only with TCP):
	
	uint32	Length of text data, minus the null character(the null
		character is sent, though).
	uint8[variable]	Text data.  Convert all characters <32 to space, and
			then display the text message(it's one line) as is.

Structure of client->server communication:

	uint8		Controller data(for this client).

	Over tcp channel, a text message can be sent.  It is one line,
	null terminated(remember the data and parse it and display it and 
	distribute it to the clients once the null byte is received).  
	Maximum size of message(including the null byte) should be 256 bytes.
                                                                                                                                                                                                                                                                                                                                                                                                   ./usr/share/doc/fceu/tech/README.now                                                                0000644 0000000 0000000 00000000540 07757447436 017206  0                                                                                                    ustar   root                            root                            0000000 0000000                                                                                    