By what means does the Sonic 1 "level select" code routine detect when the correct code is entered?
There are a few reasonable approaches, including:
- An input buffer of size CODE_LENGTH. When filled, a byte-by-byte comparison is made against the code definition.
- A single counter acting as an index into the code definition. When the current input generated matches the next item in the code defition, the counter is incremented. When the counter exceeds the code length, the code has been entered.
- A finite state machine that accounts for the replicated initial inputs (U,U) and will consider them as part of the correct sequence even if pressed an odd number of times. (Explanation below.)
There are some problems with both of these.
- A single counter with index will not handle 'initial repeat' cases. For example, UUUDDLRLR would fail. After pressing the second U, the routine would be expecting a D. If another U was pressed instead of the D, the counter would reset, and the user would be required to enter two more U's to complete a valid code entry.
- A byte-by-byte comparison plus input buffer solves the problem stated above, but seems too heavyweight. This is how "Street Fighter" style games detect "special move" input.
- A finite state machine would would be comparatively code-heavy, and changing the code definition would also require rewriting the state machine. Resistant to change. (While not a large concern in low-level programming, it would still prompt one to consider an alternate solution.)
Which did method did Naka choose?

