Thanks for the quick advice! Here's what I found:
Before messing with @range, I reduce the default by 1mm, just in case the problem was having a default right at a range limit. It didn't help. Neither did setting the default to 1000. With a range of 1 to 65534 and a default of 1000, as soon as I try to step to 1001 or 999, it goes to -1.
I "commented out" the range statement, and it worked. I could set the value of 'f' beyond 64K.
This is my latest combination:
@range 1 20000
@default 1000
This works as it should. I can step up to 20000 or down to 1, but no further in either direction.
The more I think about this, the more pointless it seems, anyway. I either want my script to give me hyperfocal distance, or I want to manually focus. I can eliminate the focus setting from the script, except the choice of hyperfocal or not. But I wanted to see what was messing up the script.
It looks like CHDK is interpreting the unsigned 16-bit number as a signed one, so any value above 2^15 is seen as negative. Once I have a negative number, I can't step back into the valid range.
In fact, Parameter set 0 is still stuck with that -1. Maybe if I comment out the range statement, i can fix it. I'm surprised that deleting the CHDK.CFG file didn't. Once I get my displays set the way I want again, I'll save the file to save me the heartache of starting over.
Thanks again for the work you put into all this. I read a tutorial about HDR last night, and it had all kinds of "If only Nikon or Canon DSLRs would allow this and that" kind of stuff. And I kept thinking, "Stop whining, and try CHDK!"