Author Topic: scripts and code snippets  (Read 10794 times)

0 Members and 1 Guest are viewing this topic.

Offline necro

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1295
  • Rating: +17/-2
  • +3 vaporal mustache
    • View Profile
scripts and code snippets
« on: September 07, 2008, 04:44:32 am »
I thought it might be nice to have a place to put bits of useful code.  Make sure to label whether its basic, psuedo code, asm, 68k c, etc.  I should have more up soon.

ti-basic:
Code: (Odd or Even) [Select]
(Ans/2)=round((Ans/2),0
I'm like a woot burger with awesome fries


VB.Net, C#, C++, Java, Game Maker

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: scripts and code snippets
« Reply #1 on: September 07, 2008, 02:59:59 pm »
we might want to separate ASM from BASIC/hybrid though, else it will get cluttered fast for people who only need help on one of them and even get confusing since people might forget to specify for which calc and language it is.

I'll go with the simple, old but useful and undocumented tricks for TI-83+ BASIC

Quote
Circle(X,Y,Radius,{i}
adding the {i} as 4th argument to Circle commands makes circles display about 4x faster than normal. No more need for ASM routines to have fast circles ^.^

Quote
Text(-1,X,Y,"ENTER TEXT HERE
adding the -1 argument allows you to display text in bigger fonts on the graph screen (same fonts than on the home screen)

The following code is for both xLIB and Celtic III flash app usage, to detect if they are enabled or not. Put at the start of your BASIC game:
Quote
:1
:real(0
:If not(Ans:Then
:Disp "XLIB NOT ENABLED
:Stop
:End

Offline Tribal

  • The Fallen
  • LV5 Advanced (Next: 300)
  • *
  • Posts: 218
  • Rating: +15/-1
    • View Profile
Re: scripts and code snippets
« Reply #2 on: September 07, 2008, 09:30:00 pm »
Let's see... I guess I'll put what I remember, I don't feel like rummaging trough my calc for them, I might later ;D


;;TI-BASIC(non-hybrid)

A replacement for randInt((lowerbound), (upperbound)):
Code: [Select]
(lowerbound)+int((upperbound)rand)the only thing about this is if it's zero or below you have to modify upperbound, for example, if you want a 0 to be lowerbound and 1 to be upperbound you would have to do '0+int(2rand)'

If you want to do:
Code: [Select]
62->Ymax
94->Xmax
You could save a few bytes by doing:
Code: [Select]
1->ΔY
1->ΔX

storing a number to a variable without messing up Ans:
Code: [Select]
For((var), (#), 0)
End

;;END IF TI-BASIC(non-hybrid)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;ASM

when reseting the carry flag, use:
Code: [Select]
or Ainstead of:
Code: [Select]
scf
ccf

if you want to multiply the 'a' registry by 2 without effecting the zero flag, use:
Code: [Select]
rlca
;instead of
;add A, A

instead of assigning CurRow and CurCol to different values you could do:
Code: [Select]
ld bc,20*256+34
ld (CurRow), bc ;loads 20 into CurRow and 34 into CurCol

;;END IF ASM
« Last Edit: September 11, 2008, 06:06:36 pm by Tribal »

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: scripts and code snippets
« Reply #3 on: September 07, 2008, 10:31:09 pm »
rlca doesnt effect the z flag, but it wont always multiply by 2 since it rotates the bits left circularly.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: scripts and code snippets
« Reply #4 on: September 07, 2008, 11:29:30 pm »
If you want to do:
Code: [Select]
62->Ymax
94->Xmax
You could save a few bytes by doing:
Code: [Select]
1->ΔY
1->ΔX
mhmm it doesn't really works, because for me it sets Xmin to -10, Xmax to 84, Ymin to -10 and Ymax to 52 x.x

Offline Tribal

  • The Fallen
  • LV5 Advanced (Next: 300)
  • *
  • Posts: 218
  • Rating: +15/-1
    • View Profile
Re: scripts and code snippets
« Reply #5 on: September 08, 2008, 07:58:43 am »
hm? that's weird... it works for me

EDIT: I think that Xmin and Ymin already have to be set to 0 >.<

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: scripts and code snippets
« Reply #6 on: September 08, 2008, 02:48:37 pm »
mhmm maybe, I guess I'll try this again. Hopefully if it works I'll be able to save a few more bytes :P

Offline Tribal

  • The Fallen
  • LV5 Advanced (Next: 300)
  • *
  • Posts: 218
  • Rating: +15/-1
    • View Profile
Re: scripts and code snippets
« Reply #7 on: September 09, 2008, 04:24:32 pm »
Yeah it does, I tried it right after I posted that, I would have re-edited but I had to go to my next class  :-\

Offline kalan_vod

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2715
  • Rating: +10/-0
    • View Profile
    • kalanrock.us
Re: scripts and code snippets
« Reply #8 on: September 10, 2008, 01:06:21 pm »
Can we just repost the old code?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: scripts and code snippets
« Reply #9 on: September 10, 2008, 08:48:48 pm »
which old code? O.o

Offline kalan_vod

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2715
  • Rating: +10/-0
    • View Profile
    • kalanrock.us
Re: scripts and code snippets
« Reply #10 on: September 12, 2008, 04:06:35 am »
Just all the old tricks and tips..

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: scripts and code snippets
« Reply #11 on: September 12, 2008, 04:09:16 am »
oh that, there are no problem, altough some might have been only on the old board, so it might take a while before we can retrieve them

Offline bfr

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 819
  • Rating: +4/-0
    • View Profile
    • bfr's website
Re: scripts and code snippets
« Reply #12 on: September 28, 2008, 09:51:04 pm »
Smallest possible TI-83+ basic quadratic solver (where the input is all done in the program, as opposed to storing inputs in variables first and then running the program, and the user doesn't have to input obscure things, like C/A into some variable):

Code: [Select]
Prompt Y1,A,C
solve(Y1,X,5
{Ans,C/A/Ans

38 bytes

I got this with the help of a little trick.  Note that it can't handle not having two real roots or when the first root found is zero, and your input should look something like:
Quote
Y1=?"X^2+X-6"
A=?1
C=?-6
to solve the equation x^2+x-6=0, for example.

If you want it to work when the first root detected is zero, you can do:

Code: [Select]
Prompt Y1,A,B
solve(Y1,X,5
{Ans,-B/A-Ans

which is 39 bytes

EDIT: I accidentally was including the names of the programs when giving their sizes, so they're actually 33 and 34 bytes
« Last Edit: October 06, 2008, 07:35:27 pm by bfr »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: scripts and code snippets
« Reply #13 on: December 08, 2008, 03:54:39 pm »
There is a very unprofessional trick to slow down a loop in TI-BASIC but it takes so few RAM.

Let says you want to have a For loop to slow down a loop where there is an animation. Instead of doing "For(Z,0,99:End" for example, just do "Rand". If you want to slow it down even more use something like "RandRand" or even "RandRandRand". This might not be very accurate and it updates the Ans variable but you save a whole lot of RAM when doing this. You can also do stuff like "cos cos cos 1" on the TI-81,82,85 and 86 or "cos(cos(cos(1" on the TI-73,83 and 84+ but it won't cause as much of a delay as rand and it takes more space since you need to use more sin/cos/tan instructions

Offline simplethinker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 695
  • Rating: +16/-5
  • snjwffl
    • View Profile
Re: scripts and code snippets
« Reply #14 on: December 08, 2008, 04:09:42 pm »
[Basic] Here's something for storing very large matrices in programs.  If you do something like
Code: [Select]
:[[1,2,3,4,5][1,2,3,4,5],[1,2,3,4,5],....]]→[A]you'll get your matrix stored in [A], as well as in Ans.  This means that until your next Ans-altering command the matrix you just stored will be taking double :o the amount of RAM used.  If your map is large, let's say 10kb, then you will need to have 20kb of free RAM at initialization, severely limiting your options.  One way to get around this is something like
Code: [Select]
:{32,32→dim([A]
:For(A,1,32
:For(B,1,32
:Z→[A](A,B
:End:End
but it would be extremely slow.

Solution:  Make the columns of the matrix into lists and use List▶matr
Code: [Select]
:List▶matr({1,1,1,...},{2,2,2,...},...,[A])For a 32x32 matrix this takes 1-2 seconds, but it saves you from having to make sure you have double the RAM needed for the matrix and certainly saves a ton of time compared with that little For( loop.
« Last Edit: December 08, 2008, 04:21:12 pm by simplethinker »
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true." -- Professor Robert Silensky



Chip's Challenge: ħ%