There is a few options that came to my mind, but all of them requires that you sign an agreement with your boss/Company.
1) Ask for an agreement telling that both parties owns the right of the software and source code. Try to avoid any “Eternal” periods of time of confidentiality since you may not know what happens in more than 5 years. So if your boss asks you for confidentiality of the source code limit the time of it.
2) When you set an agreement about the ownership of the source code and software, there is a good wording on the “IBM Customer Agreement” (http://www-05.ibm.com/support/operations/files/pdf/ica_us.pdf). Read “6.2 Materials Ownership and License”
Read “Type I Materials” and “Type II Materials” on the Type I the company owns the rights and gives you “ irrevocable, nonexclusive, worldwide, paid-up license to use, execute, reproduce, display, perform, sublicense, distribute, and prepare derivative works based on, Type I Materials. “
On “Type II Materiales” you own al the rights and you give the rights to the company of “.an irrevocable, nonexclusive, worldwide, paid-up license to use, execute, reproduce, display, perform, and distribute (within Customer’s Enterprise only)
copies of Type II Materials.”
3) Other alternative is, if you can get an agreement with your boss, is to make to dump that source code, and start a new one from scratch on your home under your own time.
But there is a lot more alternatives that goes in the middle, why don’t making a company on your own and give some stocks to you “boss/hiring company” as payment of the rights of the source code there are a lot of options. You just need to negotiate.
Good Luck. Regards.