Page 1 of 1

How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 11:18 am
by orlaisadog
The Wikipedia page on the chip (en.m.wikipedia.org/wiki/CIC_(Nintendo))
says that the chip resets every cycle, but the NesDev Wiki (http://wiki.nesdev.com/w/index.php/CIC_lockout_chip) implies it resets every second (1Hz square wave). Which is true? If it resets every second, could a game with no CIC be created by using RAM persistence over resets to hold state information?
By the way, this is my first post

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 11:28 am
by lidnariq
orlaisadog wrote:If it resets every second, could a game with no CIC be created by using RAM persistence over resets to hold state information?
Yes.

I made a trivial proof-of-concept of something like this that plays a simple song: https://forums.nesdev.com/viewtopic.php ... 47#p184247

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 11:29 am
by orlaisadog
So this could help make one of those 1 chip cartridges?

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 11:34 am
by orlaisadog
Also, would this cause a flashing screen because of PPU resets?

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 12:06 pm
by rainwarrior
Yes, a reset can cause a TV to lose signal. On a CRT they come back up really quick, but a lot of modern TVs take a few seconds, so the continual reset might make them unable to display any picture or sound at all. (Depends on the TV.)

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 12:28 pm
by orlaisadog
Which colour would the flashes be and how long? 2 frames for PPU initialization? On a CRT, could it be disguised as a lightning strike if the game has a rain effect or would that be too annoying? Anything else I'd need to know if I did this?

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 12:51 pm
by koitsu
The colours vary per PPU (read: per NES console). Really. It's been discussed before. (see Quietust's response). Grey is the most common, but I think every single person here has seen variance (some shade of green, peach, or red).

As for the duration: on the NES side, it's consistent (I believe every 1 second), but the real-world results (on screen) are going to vary because of what rainwarrior said. CRTs tend to handle video signal being dropped (line held low) quickly, so visually you see the screen flashing every 1 second. LCDs and other present-day TVs don't tend to do this, they tend to "screw around" a lot (often for several seconds) when the video signal is lost and restored; it usually has to do with logic relating to determining signal "type" (ex. 240p vs. 480p vs. 480i). So you might not see anything on Model X of a Samsung LCD, while Model Y of a Samsung LCD might show something, and Model B of a Sony might behave similarly to a CRT. There is tremendous variance that you have no control over, sadly.

If you're developing something that requires you to have specific timing or are concerned about this for a good reason, I would suggest using an actual CRT for testing/development, rather than fighting with the idiocies of LCD behaviour. Another possibility I suppose would be to use an oscilloscope instead of a TV; I imagine lidnariq could talk about that (I sure can't).

Maybe it would help us if you explained why you're asking the question. It's a good first time post and legitimate question, but your follow-up questions are perplexing -- one of those "why does this person care about that" scenarios. If we understand better the "why", maybe we can help you better. :-)

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 12:58 pm
by orlaisadog
I'm doing it for:
A: Fun
and
B: viewtopic.php?f=2&t=9342&start=90
If there was a competition I think I have an idea for a Mario game with 1 chip

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 1:11 pm
by koitsu
Oh I see... the focus being that the cartridge have basically a single chip for PRG and no other IC-based discrete logic.

I don't know how you'd deal with bypassing the CIC in that situation. Might have to be a compo that is guaranteed to run on a modded (CIC disabled) NES.

The CIC page on the Wiki describes some bypassing methods used by unlicensed game developers at the time, but as noted there later versions of the console added diodes to ensure that method of bypass can't be used (I'm not sure why it says "but not on the reset pins" in the Wiki, almost like that's implying bypass is still possible in some way through that). More a question for hardware guys than me, that's for sure.

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 1:24 pm
by orlaisadog
Yes but we can do what I just said. Also, by the length, I meant how long the flash itself would last. "2 frames for PPU initialization?" Also, could it be disguised as lightning as I said earlier?

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 2:40 pm
by lidnariq
orlaisadog wrote:Which colour would the flashes be and how long?
The PPU's palette is not changed during /RESET, but the PPU itself is forced stopped. (No video is generated at all). On an old CRT, that means the screen will probably be black? But on some it might be blue.
2 frames for PPU initialization?
Exactly 262 scanlines (312 on PAL NES). The PPU exits reset drawing the very first line of the visible field (but video is disabled), and you can start accessing the registers after the first vblank finishes. Usually you don't care about this, but in this specific case it might be worth optimizing things to start drawing sooner.
On a CRT, could it be disguised as a lightning strike if the game has a rain effect or would that be too annoying?
The PPU is held in reset, and allowed to draw, for an equal amount of time. I think it'd be too uniform to plausibly be lightning.

Yes, during that first one or two fields after the PPU were released from reset, the PPU would display whatever color you'd left in palette memory at $3F00 before the CIC asserted /RESET.
Anything else I'd need to know if I did this?
https://wiki.nesdev.com/w/index.php/PPU_power_up_state and to a lesser extent https://wiki.nesdev.com/w/index.php/CPU_power_up_state

Re: How often does the CIC chip reset?

Posted: Thu Jul 12, 2018 11:54 pm
by orlaisadog
So why do we normally wait 2 frames?

Re: How often does the CIC chip reset?

Posted: Fri Jul 13, 2018 12:07 am
by lidnariq
Because vblanks are the simplest and there aren't very many other external clock sources.

The point at which we can change the PPU is 20(2C02)/70(2C07) scanlines after the first NMI. But we can't set up any kind of timer from the PPU to let us know when that happens.

I think I've seen timed code init loops once or twice (guaranteed to take at least 312×341×5÷16 CPU instructions)

Re: How often does the CIC chip reset?

Posted: Fri Jul 13, 2018 12:36 am
by tepples
That and you can detect the TV system during the vblank wait loop, as seen in paldetect.s:

1. wait for one vblank to start (by spinning on $2002)
2. wait for enough cycles to pass second vblank on NTSC (341*262/3) but not PAL NES (341*312/3.2) and check $2002
3. wait for enough cycles to pass second vblank on PAL NES but not PAL famiclone (341*312/3) and check $2002