Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: nemo on August 25, 2010, 10:44:41 pm

Title: Hex to Sprite
Post by: nemo on August 25, 2010, 10:44:41 pm
it's memory consuming, and takes up your variables A-F, but for BASIC it's fast. your sprite data is in Str1.
Code: [Select]
10->A:11->B:12->C
13->D:14->E:15->F
For(Z,0,15
8fPart(Z/2->G
iPart(Z/2->H
expr(sub(Str1,Z+1,1
If Ans>7
Pxl-Change(H,G
If (Ans>3 and Ans<8) or Ans>11
Pxl-Change(H,G=1
If (Ans>1 and Ans<4) or (Ans>9 and Ans<12) or Ans=6 or Ans=7 or Ans>13
Pxl-Change(H,G+2
If fPart(Ans/2
Pxl-Change(H,G+3
End

to make it faster, you can change all the If's to If-Then-End's.

i also made a routine for octal data, where your sprite size is 9x8, since the data fitting into a byte isn't very important in basic. i think the following would work:
Code: [Select]
For(Z,0,23
int(9fPart(Z/3->A
iPart(Z/3->B
expr(sub(Str1,Z+1,1
If Ans>3
Pxl-Change(B,A
If Ans=2 or Ans=3 or Ans=6 or Ans=7
Pxl-Change(B,A+1
If fPart(Ans/2
Pxl-Change(B,A+2
End

but that code gives me a domain error on pxl-change, even when B and A are definitely in-bounds..



Title: Re: Hex to Sprite
Post by: Builderboy on August 26, 2010, 01:08:09 am
change 9fPart(Z/3->A to int(9fPart(Z/3->A and it should work.  The problem is rounding errors when dividing by odd numbers.  Since dividing by 3 always leaves a repeating decimal, the calculator is forced to round *somewhere*.  Then, you multiply by 3 again (when you multiply by 9 you multiply by 3 twice) and the rounded error is not lost.  So you end up with 6.000000000000001 or something.  On the homescreen this is actually displayed as 6, but if you try to pass it as an argument it gives errors.
Title: Re: Hex to Sprite
Post by: DJ Omnimaga on August 26, 2010, 04:14:18 am
Interesting, I wonder how fast does this runs? I might try it but not now because the code format isn't Source Coder and I don't feel like modifying it all right now :P.
Title: Re: Hex to Sprite
Post by: ztrumpet on August 26, 2010, 10:09:17 am
Nice job!  That should run pretty fast.  Great work. :)