Author Topic: Routines  (Read 313377 times)

0 Members and 1 Guest are viewing this topic.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Routines
« Reply #540 on: March 30, 2011, 04:15:11 pm »
Here's a quick atan routine that I threw together last night. It's not the most accurate, but it's accurate enough for most things you'd need it for. Like Runer112's Sin and Cos routines, this uses 8.8 fixed point input and returns an 8.8 fixed point angle. Use it with sub(ATN,slope).

And I'm sure it can be optimized, so feel free to do so.

EDIT: added atan2 that accepts deltaY and deltaX inputs as one byte integers -127 to 127 and outputs an 8.8 fixed point. Use it with sub(AT2,dY,dX).
« Last Edit: March 31, 2011, 04:06:37 am by ZippyDee »
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Routines
« Reply #541 on: May 06, 2011, 11:50:28 pm »
I'm trying to update the ASCII program from before.

The option I plan on including is storing any one of the following:
Number, Hex number, Charactor, Token
to the TIOS var Ans.

How would I do this?  I've been able to create Ans as a string, but the IRC convo about how to do it got kind of confusing so I'm making a post instead.

TIA
« Last Edit: May 06, 2011, 11:51:00 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Routines
« Reply #542 on: May 07, 2011, 12:08:23 am »
Well, you'll have to convert it all yourself. For the numbers just do some math tricks to get each digit (using division and modulus; we can help you if you need help figuring out code to do this), and for tokens it's even easier (just store the value right there, since TI-BASIC strings are read as tokens anyway), but characters may become impossible. The reason is that a lot of characters are accessible only in ASM (or Axe) and don't have token equivalents.




Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Routines
« Reply #543 on: May 07, 2011, 12:12:09 am »
Well, you'll have to convert it all yourself. For the numbers just do some math tricks to get each digit (using division and modulus; we can help you if you need help figuring out code to do this)
this would be just for the hex number, or for the decimal number as well?
Quote
and for tokens it's even easier (just store the value right there, since TI-BASIC strings are read as tokens anyway), but characters may become impossible. The reason is that a lot of characters are accessible only in ASM (or Axe) and don't have token equivalents.
ok...guess I'll take that out :P
Vy'o'us pleorsdti thl'e gjaemue

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #544 on: May 26, 2011, 12:38:01 am »
A lovely animated vertical screen flipping routine! It requires a buffer to store the image to be flipped, and by default uses L3. You could change this to use any 768-byte section of RAM by replacing the StorePic and instead copying your original buffer image (probably in L6) somewhere else.

The code is both pasted below and attached as VFLIPLIB.8xp. The easiest way to include this code in your program would be to just include prgmVFLIPLIB in the subroutine section of your program and call sub(VF) to use it.

Code: [Select]
StorePic
0+128
While 1
 -128-2→θ
 cos()+129/2/2→Y
 +(≥32)-(=0)*256→Z
 ClrDraw
 64
 While 1
  -1→I
  If Z/256≠((31+(Y<32)-Y)→H*8+Z→Z/256)
   Copy(I*12+L₃,Z/256*12+L₆,12)
  End
 End!If I
 DispGraph
End!If θ+128

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Routines
« Reply #545 on: May 26, 2011, 12:28:02 pm »
Awesome ;D
Is there a way to have it invert half-way through?  Put a DrawInvr just before the second While 1 or something?
Vy'o'us pleorsdti thl'e gjaemue

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #546 on: May 26, 2011, 01:10:48 pm »
This should work:

Code: [Select]
StorePic
0+128
While 1
 -128-2→θ
 !If +64
  DrawInv ʳ
 End
 cos(θ)+129/2/2→Y
 +(≥32)-(=0)*256→Z
 ClrDraw
 64
 While 1
  -1→I
  If Z/256≠((31+(Y<32)-Y)→H*8+Z→Z/256)
   Copy(I*12+L₃,Z/256*12+L₆,12)
  End
 End!If I
 DispGraph
End!If θ+128
« Last Edit: May 26, 2011, 01:11:26 pm by Runer112 »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Routines
« Reply #547 on: May 26, 2011, 04:56:24 pm »
Nice!  That's awesome, Runer.  Excellent job there. ;D

Ashbad

  • Guest
Re: Routines
« Reply #548 on: May 26, 2011, 05:04:04 pm »
that's pretty awesome.  What's even more awesome is how optimized that is O.O

Runer++

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Routines
« Reply #549 on: June 12, 2011, 02:27:32 am »
I do not know if this has been posted before, so here are two different snippets to get the current hardware version. The first checks the hardware ports, and returns 0 for the TI-83+, 1 for the TI-84+SE, 2 for the TI-83+SE, and 3 for the TI-84+SE. So, doing AND 1 returns true for a TI-84+ or TI-84+SE.
Code: [Select]
Asm(210000 DB02 47 E680 280D 2C DB21 E603 2806 2C CB68 2801 2C)->V   . V=HW version. 23 bytes
Spoiler For Assembly Code:
Code: [Select]
ld hl, 0
in a, (2)
ld b, a
and 80h
jr z, done
inc l
in a, (21h)
and 3
jr z, done
inc l
bit 5, b
jr z, done
inc l
done: ; nothing more here!

This second one uses the rarely-used GetSysInfo bcall. It probably returns 0 for the TI-83+, 1 for the TI-83+SE, 2 for the TI-84+, and 3 for the TI-84+SE, but I cannot verify that.
Code: [Select]
Asm(EF6F4C 2E00 78 FE0D 380A 217884 EFDD50 3A7A84 6F 2600)->V   . V=HW revision. 22 bytes
Spoiler For Assembly Code:
Code: [Select]
BCALL getBaseVer ; You can probably get away with not checking the OS version, as most units in use these days will have 1.13+
ld l, 0
ld a, b
cp 0Dh
jr c, done
ld hl, OP1
BCALL GetSysInfo
ld a, (OP1+2)
ld l, a
done:
ld h, 0 ; done!


And while I'm at it, here's how to read and write to any port. $ = the small capital E used for hex notation in Axe. This first one takes the port to write to in the high byte, and the value to write in the low byte.
Code: [Select]
variable Asm(4C 45 ED41)   . Write the value (variable And $FF) to port (variable/256)$1060Asm(4C45ED14) will vertically rotate the screen by half. ($10 is the LCD command port, and $60 is a command that rotates the screen. It's useful for instant scrolling.)

This reads from the specified port.
Code: [Select]
variable1 Asm(4D ED68 2600)->variable2   . Read from port variable1 and store to variable26Asm(4DED682600)->P will probably make P a number less than 8 if the program is running from the OS, and greater than or equal to 8 if the program is running from a shell. (The code for running nostub programs happens to be on page 7 on 2.43. That can change, of course.)

This writes a value to one particular port.
Code: [Select]
value Asm(7D D3nn)   . Writes value to port nn.$60Asm(7DD310) will vertically rotate the screen by half.

This reads a value from one particular port.
Code: [Select]
Asm(DBnn 6F 2600)->variable   . Write the value in port nn to variable.Asm(DB06F62600)->P will probably make P a number less than 8 if the program is running from the OS, and greater than or equal to 8 if the program is running from a shell.

You can also inline these. For example,
Code: [Select]
If randAsm(4DED682600)>42
 some code
End
will execute some code if the value in a random port is greater than 42. May cause a hang on TI-84+s if it reads from the wrong USB port :p.
« Last Edit: June 12, 2011, 02:31:12 am by DrDnar »
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Routines
« Reply #550 on: June 12, 2011, 10:00:56 am »
Nice routines, DrDnar. I can see the first few being useful for people who want to do crystal timers in Axe :D




Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Routines
« Reply #551 on: June 12, 2011, 01:58:33 pm »
Nice routines, DrDnar. I can see the first few being useful for people who want to do crystal timers in Axe :D
That would be epic. :D
By the way, it there something like the crystal timers on the 83+?

Thanks, DrDnar.  Great routines. ;D

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Routines
« Reply #552 on: June 12, 2011, 02:05:41 pm »
Massive hardware version check optimization? 6 bytes, about one quarter the size of your code. ;)

Asm(EFBA8026006F)

Offline BrownyTCat

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 420
  • Rating: +37/-8
    • View Profile
Re: Routines
« Reply #553 on: June 12, 2011, 02:06:46 pm »
Massive hardware version check optimization? 6 bytes, about one quarter the size of your code. ;)

Asm(EFBA8026006F)
I don't even know how it works, and it's still amazing.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Routines
« Reply #554 on: June 12, 2011, 02:10:28 pm »
lol undocumented bcalls ftw :D