Well if there's no contract, the code that you've written so far is yours.
Unfortunately this is hindsight, but ... You should have had a nondisclosure agreement before showing it to anyone. As far as I know this is the only way to protect an idea. You can't patent one, you can't copyright one.
If the you've written code that is intended to produce a particular result on a computer and someone else writes code to produce the same intended output, there is no problem unless the code is duplicated.
For example, if I show you my better mouse trap, and I have not protected it by patent or a nondisclosure agreement, you then duplicate it and sell it before I do, I have no recourse.
So if you coded your own version of an app, and they want you to write a version of the same program for them, there's not much you can do about that, as long as their code doesn't duplicate yours. Actually, if they exactly duplicated your code and there was no copyright on your code, that's OK too.. ( Oberservation - If the company assigns you to this project it puts you in the rather awkward position of having to recode your own program for the company so that it doesn't duplicate your original code.)
Even if the code you have written has a copyright, (which you should do
http://www.loc.gov/copyright/), there will probably be enough variations in the code produced by the company to obviate any copyright infringment. (i.e: Word v. WordPerfect - both wordprocessors, same function and idea, but different code)
Your problem seems to be that they are trying to steal your idea - which they (unfortunately) can do - lacking any nondisclosure agreement.
About the only thing that you can really do as far as I can see, is to beat them to market with your widget. If you can get past who owns the existing code, its just a horserace. ( Observation - if the company assigns you to this project, you are the jockey on both horses. Doesn't seem too bright on the company's part.)
Regarding the proprietorship of the extant code, you are in a very good position, I think, if the company decides to push this aspect -
The fact that they wish you to now write code, while in their employment . (Why would they instruct you to now write the code, if they already owned the code that already exists?)
Hopefully you have some documentation ( emails, etc.) showing when you first revealed your program to them, as it would tend to strengthen the above position. Any correpondence that indicated when they first laid claim to your code would show the time frame ( as a bonus, it would be beating them with their own stick.) This would be important in demonstrating that they directed you, as an employee, to write the code AFTER they claimed that they already owned the code that you had already written.
The way this company sounds, I think I would prepare myself to decide between my proprietary coding project and my employment. If you have to sign an employment agreement now, watch out for clauses that deal with existing code. I would think that they would try to make you agree that all code written while in the company's employment is their property.
I'm not a lawyer, these are just observations by an innocent bystander, but I hope something in here helps.
Good luck,
wtd