You can't enjoy retro games without digging the music, and a YouTube video (below) shows exactly how those tunes evolved. As explained by the 8-Bit Guy and Obsolete Geek, early PCs and Apple machines used "beeper speakers" that were driven strictly by your computer's CPU. Those only produced crude sounds, because forcing the CPU to do more actually hurt gameplay. Computers and consoles eventually got dedicated sound chips, but each used a different number of "voices," producing the distinctive differences between, say, a Nintendo NES and a Commodore 64 system.
Clever programming improved the tunes in those systems, but eventually PC sound cards came along with 9-channel Yamaha synth chips, giving music designers larger palette. A bit later, the Commodore Amiga arrived with a sampling chip, resulting in the distinctive late '80s and early '90s sounds heard in games and pop music. Modern systems generally just play music files straight from MP3s, but the music itself owes a big debt to the creativity it took just to get it to work back in the day. If you don't believe it, listen to some chiptunes or ask the composers themselves.