>>36161304it's almost always doable on the real consoles and virtual console, but some emulators can fuck things up
in gen 1, it's done by having certain item setups in your bag, and then using a glitch item to execute the code. in gen 2, it's done by renaming PC boxes to write codes, and then using the coin case glitch to execute
there's more to it than those steps, but i'm just tl;dring you here