My main problem is that codes change; what was once bad is now good.
Well, yes. Change happens. If you're expecting things to be eternally the same, well... in the words of the Dread Pirate Roberts, "get used to disappointment."
Can we really say slavery was once moral, or only that it was once acceptable in some moral code? I don't think it was ever moral.
See, I can't see what possible merit these sorts of questions have. People considered it moral (indeed, God's own commandment) then; now, they don't. And indeed, we should all wonder what is accepted
now that future generations will find
us culpable for. (Pollution, perhaps, or overfishing. Who knows?)
The morals changed
then not because somebody
discovered slavery was bad, but rather - somebody was able to convince several somebodies that it was, and they each convinced several more, and then in the midst of a great social upheaval, those people convinced leaders to take a stand against the practice, and the consensus of society was revealed to be that slavery was an abomination.
Sure, it was acceptable as per that society's code, but I don't think we can view morality as limited by any code.
But that's exactly what it's limited by, because the only reason slavery is viewed as immoral in our society is because society saw fit to change the code. They didn't see that "slavery is bad" was written on some hitherto-unknown tablets handed down from on high; no scientist discovered precepts against slavery written on the fabric of the universe.
We just changed our collective mind. It was a process of collaboration and conversation - and, indeed, bloodshed. But it's the same process by which society produces
anything. Everything. It's the same process that produces art and science. It's just people talking with each other about what they think is right and wrong, and what they think people should do.