pfalstad / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
1.71k stars 286 forks source link

Add "Invert reset pin" option to ring counter #12

Closed nulldg closed 3 years ago

nulldg commented 3 years ago

At line 156 of RingCounterElm.java, there are two different proposed visuals styles. Feel free to choose whichever one you like more.

pfalstad commented 3 years ago

I'd go with the line over.

Whenever I add a boolean flag, I always store it as a bit in "flags" which is already dumped and undumped. See FLAG_CLOCK_INHIBIT for an example (although that flag is not editable), or FLAG_RESET and FLAG_SET in DFlipFlopElm.java

Also when changing something that affects the pins I just call setupPins() again.

nulldg commented 3 years ago

Good idea. I copied this from the way CounterElm does it, but that file is an absolute monstrosity.

pfalstad commented 3 years ago

I believe someone contributed that code.

nulldg commented 3 years ago

Changes are complete now, everything seems to work.

pfalstad commented 3 years ago

This breaks existing circuits like Circuits->Sequential Logic->Traffic Light and LED Flasher.

the flag should be FLAG_RESET_HIGH or something like that instead, meaning if the flag is not present, it will work as before.

nulldg commented 3 years ago

I thought it would be automatically raised by default per flags |= FLAG_INVERT_RESET; in the constructor. Well, I can fix that too. Good catch!

pfalstad commented 3 years ago

That constructor is only called when the user creates a new ring counter. When loading from a file, we use the other constructor, which takes a StringTokenizer argument. But you can't set the flag there because then it will always get set, even if you create a new circuit with reset high.

nulldg commented 3 years ago

Sure, that was kinda boneheaded of me anyway.

nulldg commented 3 years ago

Oh wow, I feel stupid. Sorry for creating such a buggy mess!

pfalstad commented 3 years ago

Your changes are all merged already. Don't know why this is still here.