The resolution of those old games, and the color depth, is much lower, that cuts down a lot. a 64x64 sprite (common flash size) is 64 times larger then an 8x8 sprite (common nes size)
If you look at a NES sprite, you will notice it can only have at max 3 colors. So it only needs 2 bits per pixels (instead of 8-32 bits for a flash game, so now the flash sprite example is 1000x larger!)
Also, since the NES is an 8 bit machine, every instruction is only 8 bits long, instead of at least 32 bits on a i386+, so code is much more compact.
And the third thing, most of the "heavy lifting", like graphics and sound, was controlled by hardware, offloading the CPU minimizing code need even more.
Well, I guess thats true still, but the hardware was much less complex, so you didn't need big drivers, you basically controlled it directly by writing control words at special memory adresses