This topic comes up a lot. Emulators are programs built either from copied system code or written from scratch to mimic a console's behavior.
As a general rule, emulators themselves are considered legal, especially when you're not selling or buying them and aren't using them to tamper with the actual systems. The legal gray area usually appears when it comes to the games themselves, so downloading ROMs you don't own can cross into infringement. The emulator software and copyrighted games are two separate matters.