The D9 in the Super Mario theme is acting as a perfect cadence, hinting at the key of G, as D is the dominant of G. That is why it is called a secondary dominant: it is the dominant of a different key. As the opening chord progression to this tune is D9 to G, you might think, “Doesn't this establish the key as G?”.
How do songs progress?
When we put chords together, we call the result a progression. ... When chords progress, they play with our sense of musical predictability. If you get the balance between predictability and innovation just right, you wind up with chords that sound fresh but pleasantly predictable.
What scale is Mario?
Anyway, Mario is ostensibly in C major, but it borrows from C minor, especially in the famous "Mario Cadence", or AbM - BbM - C. One of my interests is in ludomusicology and by extension just talking about multimedia music, so allow me to go off on a giant tangent haha.