Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: BrandonW on May 26, 2010, 05:43:54 am

Title: TI-OS BASIC For( Bug Fixed
Post by: BrandonW on May 26, 2010, 05:43:54 am
I believe I've tracked down the bug with For( loops being very slow when the first line is a lone If block with a false condition and there's no ) or newline between the For( and the If.

It's complicated and hard to explain, but basically the code that handles the For( token assumes that you've put the ) on the end of the For( line, and so when it executes the For block, instead of jumping to the start of the line containing the If, it jumps to the If token itself.

Normally this isn't a problem, but it's important for the parser to handle the start of the line because it removes a byte from the operator stack that always gets pushed when beginning parsing of the line. Because an If block with a false condition will jump over the next line (including the newline), this never gets canceled out at the beginning of the loop, and so with every iteration you lose bytes of the operator stack. This in turn causes memory leaks and confuses the parser about what temporary variables should be cleaned up, and it's forced to near-constantly "garbage collect".

Or at least that's my theory.

In any case, the For( code shouldn't be making that stupid assumption, so I patched my OS to see if I could fix it, and it appears successful. I uploaded it to http://brandonw.net/crap/84P_OS2.41_BASICFixed.8xu if anyone wants to try it.

So we could be happy with this, or we could write an oncalc patch that does this in an OS version-independent way, or we could just live with the fact that you need a ).

Thoughts?
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: calcdude84se on May 26, 2010, 07:59:03 am
Definitely not a full, patched OS. An oncalc, version-independent patch would be best, IMO.
Of course, if you don't feel like patching it, I think it wouldn't be too hard to just use )s. When I do program in BASIC, I avoid that type of For( loop anyway, or just use a ) for that reason.
But I'm not the only person here, so I wonder what others think should be done.
(Also: finally, a reason to use the OS-revalidator!)
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: ztrumpet on May 26, 2010, 08:03:39 am
That's cool!  Has TI been email and told they need to fix this glitch and how to fix it?  It's cool that it's fixed.  Great job! :D
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: BrandonW on May 26, 2010, 09:55:17 am
No, I'm still working on how to even explain this. I managed to fix it, but I'm not 100% sure it's the right way, and if you're e-mailing TI to tell them they have a bug deep in their parser code, you want to make sure you're correct and very explicit.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: TIfanx1999 on May 26, 2010, 09:57:32 am
Pretty cool that you were able to track down such an old know bug. :D Nice work! I wouldn't mind a patch, because I tend to forget these oddities sometimes.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 26, 2010, 12:41:29 pm
Wow nice, I wish I could try it but I do not have a 84+. I hope an on-calc patch that works on most recent TI-83 Plus and TI-84 Plus OSes can be done. Just make sure there won't be conflicts with any other patch you have, though (such as the xLIB fix for 2.53MP and 2.54MP)
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: meishe91 on May 26, 2010, 02:43:24 pm
What exactly is meant by an independent program to do it instead of a patch? Also, great work :) Glad to know this can be fixed now (especially for people who need to spare every byte possible when creating a program). Good luck with figuring out how to explain this to TI.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 26, 2010, 02:54:53 pm
On the TI-Nspire, to fix xLIB issues with OS 2.54MP, you need to run a small 8xp program using the Asm() command. The fix remains until the Nspire is rebooted (keypad/battery removed or keypad swapped)

Not sure about non-Nspire, though.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: Galandros on May 26, 2010, 03:23:52 pm
Wow, I was curious to know why the heck that bug existed.
You are continuing the "fixing bugs for them". :P

Nowadays many experienced TI-BASIC programmers know that they should put the closing ) in loops that use If's. And it is well documented in TI|BD. So now many of us "live with it". If someone has interest to find a patch, he would almost certainly see first how to solve the bug.

I also prefer an oncalc patcher if possible. Sending a full patched OS for just one bug is a little exaggerated.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 26, 2010, 03:34:16 pm
Yeah the issue is that a lot of BASIC coders will get told to not close parhentesises, but not about the For loop issue, meaning they'll forget that part. Such patch would help a lot
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: meishe91 on May 26, 2010, 03:38:25 pm
Ah ok, I gotcha. Thanks. Ya, I think a program would be easier.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 26, 2010, 04:09:35 pm
That said, later, if BrandonW managed to find a way to make Mathprint as fast as on the 73, find a way to fix the inverted text issues some BASIC games has and the potential bugs 2.53 MP got, he could maybe provide an OS patch including every fixes he managed to apply to his OS copy.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: meishe91 on May 26, 2010, 04:20:13 pm
Ya, a patch like that would be nice. What is the inverted text issue?
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 26, 2010, 04:32:27 pm
If you enable the inverted text flag with an ASM prog or APP like xLIB, which displays white text on black background, doing DispGraph:Disp inverted the entire homescreen content. However, in OS 2.53MP this fails in most cases.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: meishe91 on May 26, 2010, 04:39:24 pm
Oh ok, I thought you meant like something without assembly help haha. I get what you mean though.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: jsj795 on May 28, 2010, 01:32:56 am
wait, but if you make the game with patched OS and do not close the parenthesis, and you give that game to another person who does not have the patched OS, doesn't that mean the person receiving the game will notice the slow down? So this defeats the whole purpose unless the whole community gets the patched OS...
It looks like everyone needs to be "vaccinated" with BrandonW's program :D
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 28, 2010, 01:47:40 am
well it depends. If the patch is just an ASM program that needs to be ran like the ALCDFIX program, then you just send him the program (make sure he got the right OS version). Otherwise I guess he would need the entire OS, which takes about 15 mins to transfer
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: meishe91 on May 28, 2010, 03:21:52 am
Well if TI didn't leave it to BrandonW to fix their mistakes none of that would be an issue :P

What is the ALCDFIX program? Never heard of it.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 28, 2010, 03:44:43 am
It's for those with poor LCD drivers on their 83+SE and 84+. On those calcs some old ASM games will have distorted screen
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: Halifax on May 28, 2010, 07:44:09 am
What I would like to know is why TI hasn't hired BrandonW yet...They could just put one engineer on the project to keep updates coming to the TI-OS, and he already has the drive to improve it significantly; seems like a no-brainer to me.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: meishe91 on May 28, 2010, 07:57:23 am
BrandonW doesn't want to work for TI, I believe. He said during his podcast that he doesn't want to because then he wouldn't be able to really contribute to the community much due to contracts and signing of them and all that nasty stuff.

@BrandonW
I believe that is roughly what you said, right?
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on May 28, 2010, 01:19:41 pm
Yeah and he said it in #cemetech too. If he works for TI, he may no longer be allowed to release anymore info of how the calc stuff works and planned stuff. Basically, he wouldn't be able to do all the stuff he does now for the TI community. I mean, imagine if he wants game dev to happen for the TI-Nspire, then he gets hired, and TI absolutely refuses to add ASM capabilities to the Nspire: how is BrandonW gonna reveal info about how the TI-Nspire OS works and how to potentially circumvent protections in it to be able to run ASM stuff?
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: critor on September 05, 2010, 04:20:10 pm
On which OS is that Basic-For-bug present ?

Only on 84+ OSes, or even on 83+ and 73 OSes ?
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: patriotsfan on September 05, 2010, 07:09:50 pm
I think the For bug exists for the TI-83+, TI-84+, and TI-84 SE and probably for the TI-83. Not sure about the 73 though.
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: critor on September 06, 2010, 04:09:46 am
I think the For bug exists for the TI-83+, TI-84+, and TI-84 SE and probably for the TI-83. Not sure about the 73 though.

Oh... It is going to be much harder to fix that on the TI-83...

I've patched TI-84+ OSes 2.30, 2.40, and 2.43 in a similar way.

I couldn't patch other OSes (TI-84+ 2.22 and older, TI-84+ 2.53MP, TI-83+, TI-73) because I couldn't find the matching code.


I had allteady noticed some memory leaks while using loops with the TI-Basic, nut I hadn't investigated it.

Could somebody show me an example of a TI-Basic code triggering the bug?
Title: Re: TI-OS BASIC For( Bug Fixed
Post by: DJ Omnimaga on September 07, 2010, 02:20:24 am
I am sure it's on all z80 calcs except the 85 and 86 but I could be wrong. I may dig up an example I had somewhere, but it might take a few days.