Jump to content
IGNORED

Crazy TI Basic Problem


unhuman

Recommended Posts

This is really strange...

 

10 CALL KEY(1,K,S)

15 PRINT K

20 IF K=0 THEN 40

30 GOTO 10

40 PRINT "BYE"

 

When pressing the X key - it prints K=0, however, line 20 doesn't match.

 

However, if I switch line 20 to be

20 IF STR$(K)="0" THEN 40

Then it works

 

And, the former case works perfectly in XB

Link to comment
Share on other sites

Without having my reference card handy, does it have anything to do with the side of the keyboard read when you specify (1,K,S) (as opposed to 0,K,S)? I've used (0,K,S) for so long, I've forgotten what the other numbers in that first spot even do, but isn't it something about only reading from part of the keyboard? Maybe it just doesn't expect to see certain values in that case? Shot in the dark here.

Link to comment
Share on other sites

No idea. Print K prints the correct value... Just seems like the value isn't quite right. I use 1 instead of 0 since I'm checking the joystick fire button. I want to re-use the same CALL KEY result for a different function (but still the single CALL KEY). I have not experimented with 0 in BASIC.

 

K is an integer value - and the comparison should "just work" in my mind...

 

-H

Link to comment
Share on other sites

Were you using a real console? Mine's disassembled ATM. Tried in Classic99, same results as you. In fact, even INT(K)=0 and K*1=0 did not work. Now, if you do something like K-1=-1, that works.

 

Interesting, indeed. Kind of like the whole SQR(9)=3 being false thing (this is in the Users Guide.)

Link to comment
Share on other sites

I remembered one place I saw a blurb about the problem: COMPUTE!'s TI COllection Volume One (referenced in the pinned forum topic) page 13:

 

"There is a slight problem in testing for zero in the TI-99/4A console. Use logic such as IF K+1<>1 rather than IF K<>0."

 

Perhaps others will shed some light or recall other references that may help to clarify?

Link to comment
Share on other sites

This was a documented error, though I can't remember offhand where (I think I have it in one of my BASIC manual addendums.) The problem is that there are two ways to specify 0 in the Radix notation that TI BASIC uses, and (I think it was specific to CALL KEY) returns the wrong one. But yeah, you can still do valid math on it and test that way, should be faster than the string compare? (Not tested).

Link to comment
Share on other sites

This also works, and I would expect a similar method to be marginally faster than the string compare. In particular, if you used a ON K+1 GOTO, you only have to worry about 18 different results so you can easily null-route or even incorporate a simple quick compare. Hell, K=K+1 before making your comparison and decisions would probably work out, too.

 

10 CALL KEY(1,K,S)
20 IF S=0 THEN 10
30 PRINT "K=";K
40 IF K>-1 THEN 60
50 STOP
60 PRINT "YES!"
70 END

Edited by OLD CS1
Link to comment
Share on other sites

Yeah - I'm trying to find a specific key, so > check isn't quite valid... And I'm in plain old basic.... But, since it's a known issue, I'll just move on. Just amazed at how bad that is... Someone at TI should get fired for this.

 

Yes. They should ;) But IIRC (without scrolling up the thread,) I think Extended BASIC fixed the problem.

Link to comment
Share on other sites

Yeah - I'm trying to find a specific key, so > check isn't quite valid... And I'm in plain old basic.... But, since it's a known issue, I'll just move on. Just amazed at how bad that is... Someone at TI should get fired for this.

 

If it's any consolation, they probably don't work there anymore. ;) But since Microsoft wrote it, maybe someone at Microsoft should be fired. ;) (Actually, if I read the history right Microsoft hired a contractor to do it.)

Link to comment
Share on other sites

Yeah - I'm trying to find a specific key, so > check isn't quite valid... And I'm in plain old basic.... But, since it's a known issue, I'll just move on. Just amazed at how bad that is... Someone at TI should get fired for this.

 

If it's any consolation, they probably don't work there anymore. ;) But since Microsoft wrote it, maybe someone at Microsoft should be fired. ;) (Actually, if I read the history right Microsoft hired a contractor to do it.)

 

Oh - I don't think the developer should be fired. The tester and/or the management that permitted such a bug through...

 

Anyhow, it is interesting that X+0 doesn't affect the "badness" but X+1 does. Guess I'll be using that instead of STR$

Link to comment
Share on other sites

  • 4 weeks later...

Throw it in a loop and see how long a hundred passes of each takes. :)

 

:P Thanks. I was hoping for something more technical, like, "well, the source for BASIC shows that the string conversion should take 45ms, and the comparison takes 5ms, but the straight numeric comparison takes 15ms, so it is all-around quicker to use the numeric comparison."*

 

* These are not real values

Link to comment
Share on other sites

It's more accurate to measure it than to try and figure it out from the source, in all cases, all systems, all codes. It may be /possible/ to calculate what it SHOULD take, but if you fail to factor in any variable, you'll be wrong. Only measuring the code is accurate.

 

That said, you just build a loop that runs 1000 times (or for very slow things, 100 times).

 

10 FOR A=1 TO 1000
50 NEXT A

 

Run that, and time how long it takes from start to finish (add some CALL SOUNDs outside the loop if you would rather have sound than display as the trigger - remember to use negative durations though!)

 

The time this takes is your baseline - it shows how long the for loop takes to execute. The nice side of using 1000 iterations is that the number of seconds it takes, you divide by 1000 and get milliseconds, a nice convenient unit. In TI BASIC this is usually 3.

 

Now add the function you want to test into the FOR loop and run it again. For instance:

 

10 FOR A=1 TO 1000
20 K=K+1
50 NEXT A

 

Run it again, and subtract '3' from the time you get. That gives you the average number of milliseconds it takes to execute "K=K+1".

Link to comment
Share on other sites

Listen to the Lion here, OLD CS1.... That'll give you the "stuff" you need. :)

 

No doubt, I just enjoy my habit of over-thinking and over-engineering, I suppose. I sometimes dig through my 6502 code bumming instructions here and there to reduce the amount of time spent in IRQs, etc. Sometimes for practical purposes, but mostly just for fun. It is something I picked up a few years ago when I took Computer Organization and learned MIPS.

 

Great class, actually. We had a project in which you had to take a program description and write the program to make full use of the pipeline. If you stalled the pipeline even once, you failed. If you have not played with MIPS before and you like that kind of hacking, you should grab a book on it and the free "spim" MIPS emulator.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...