Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
22 May, 2013, 08:32:07 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: 1 ... 32 33 [34] 35 36 ... 42   Go Down
  Print  
Author Topic: Routines -  (Read 42535 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #495 on: 14 December, 2010, 23:02:23 »
0

That looks neat!  Nice routine Sir! Grin
Logged

Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:42:54
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #496 on: 15 December, 2010, 00:50:10 »
+1

I believe I posted some normal sorting routines a while ago, but there are probably many more times when a linked sort is in order. So here are two linked sorting libraries. LSORTBLB sorts a list of bytes whereas LSORTWLB sorts a list of words, and both are linked to a list of words (which will typically be pointers). These routines allow you to sort objects based on certain attributes.

The general syntax for a sort call:

1
sub(___, Pointer to list of values to sort, Pointer to list of words to rearrange based on sort, Number of bytes to sort)
Note: If you are sorting bytes, the last argument will be the number of values to sort. If you are sorting words, the last argument will be the number of values times 2.

Routines in LSORTBLB:
  • SBA - Sort bytes in ascending order
  • SBD - Sort bytes in descending order

Routines in LSORTWLB:
  • SWA - Sort words in ascending order
  • SWD - Sort words in descending order



As an example, say your program was managing 256 objects, and each object has 4 bytes of data: [x position, y position, x velocity, y velocity]. You have a list of pointers to the objects located at P. Let's say you want to sort the objects in this list by descending x velocity.

1
2
3
4
5
6
.Move attributes to be sorted by to a sequential section of memory
For(A,0,255)
{{A*2+P}+2}→{A+L₁}
End
.Sort
sub(SBD,L₁,P,256)

* LSORTBLB.8xp (1.55 KB - downloaded 45 times.)
* LSORTWLB.8xp (1.61 KB - downloaded 38 times.)
« Last Edit: 15 December, 2010, 01:09:46 by Runer112 » Logged
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 07:31:30
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50214


Total Post Ratings: +2613

View Profile WWW
« Reply #497 on: 15 December, 2010, 07:47:04 »
0

Oh a sorting routine? Nice! This might be handy eventually if I was to work on an item menu like Illusiat 13 Cheesy
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #498 on: 15 December, 2010, 23:45:07 »
0

Wow, that looks nice!  Great job. Smiley
Logged

Ashbad
Guest
« Reply #499 on: 16 December, 2010, 00:18:06 »
0

Draw an elliptical shape like an oval/circle


1
2
3
4
5
For(A,0,255
sin(A)//W->S
cos(A)//H->C
pxl-on(X+S,Y-C
End

W = Width inverse, the smaller the value, the wider the circle.  16 draws with outward radius of ~10 pixels
H = Height inverse, the smaller the value, the taller the circle.  16 draws with outward radius of ~10 pixels
A = used in for statement as the intermediate "angle"
S = intermediate sine value
C = intermediate cosine value
X = Elliptical center X
Y = Elliptical center Y
« Last Edit: 16 December, 2010, 00:18:43 by Ashbad » Logged
nemo
LV9 Veteran (Next: 1337)
*********
Offline Offline

Last Login: 04 April, 2013, 01:12:57
Date Registered: 16 May, 2010, 03:55:30
Posts: 1198

Total Post Ratings: +83

View Profile
« Reply #500 on: 16 December, 2010, 00:25:31 »
0


1
2
3
4
For(A,0,255
pxl-on(sin(A)//W+X,Y-(cos(A)//H)
End
yay optimization
Logged


Ashbad
Guest
« Reply #501 on: 16 December, 2010, 00:27:12 »
0

yay Wink

funny thing is, until I wrote the routine and looked up what a sine and cosine is, I had NO IDEA what they did shocked

I mean, I used before in Alg honors last year, but it was the last chapter for honors only, which was a crash course of trig basics Tongue

..and we just used the sin/cos functions like once and were never told what they did Tongue
« Last Edit: 16 December, 2010, 00:28:06 by Ashbad » Logged
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:42:54
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #502 on: 16 December, 2010, 02:04:38 »
0


1
2
3
4
For(A,0,255
pxl-on(sin(A)//W+X,Y-(cos(A)//H)
End
yay optimization


1
2
3
4
5
256→A
While
Pxl-On(sin(A)//W+X,sin(A+64)//H+Y)
A-1→A
End

Good fight Wink

And just a note: Unless you absolutely want width and height to be inverted, multiplying instead of signed dividing is probably better. The multiplication routine is smaller and faster than the signed division routine.
« Last Edit: 16 December, 2010, 02:06:21 by Runer112 » Logged
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 19:18:47
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7813


Total Post Ratings: +706

View Profile WWW
« Reply #503 on: 16 December, 2010, 02:09:05 »
0


1
2
3
4
5
257
While -1→A
Pxl-On(sin(A)//W+X,sin(A+64)//H+Y)
A
End

Even better Wink
Logged




Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:42:54
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #504 on: 16 December, 2010, 02:16:02 »
0

Ah how did I not see that!
Logged
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 19:18:47
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7813


Total Post Ratings: +706

View Profile WWW
« Reply #505 on: 16 December, 2010, 02:18:16 »
0


1
2
3
4
5
257
While -1→A
Pxl-On(sin()//W+X,sin(A+64)//H+Y)
A
End

I should stop.
Logged




DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 07:31:30
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50214


Total Post Ratings: +2613

View Profile WWW
« Reply #506 on: 16 December, 2010, 11:29:06 »
0

Nice routine guys!
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:42:54
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #507 on: 20 December, 2010, 05:43:15 »
+4

FinaleTI was wondering how he could do some basic operations on 3-byte numbers, namely addition, subtraction, and decimal display. It took me a while to get it all working, but I wrote an Axe library to do all of the above. And while I was at it, because it would only require minor modifications to this code, I wrote a similar library to perform those three operations on 4-byte numbers. No longer shall Axe be limited to 2 bytes! (At least regarding addition, subtraction, and decimal display)

Anyways, the two libraries are very similar. They accept inputs in the form of pointers to the 3- or 4-byte numbers you want to operate on and have the same three functions:
  • Addition: sub(ADD,Pointer to first argument, Pointer to second argument, Pointer to store answer to)
  • Subtraction: sub(SUB, Pointer to first argument, Pointer to second argument, Pointer to store answer to)
  • Decimal display: Disp Pointer to number to display sub(DEC) - Note that this does not return a string of a fixed length padded on the left with spaces like the usual Disp ►Dec. The string returned has any leading zeros clipped and consists only of the number itself.


To include the library in your program, have the library you want present on your calculator and insert a line reading ":prgmLIB3BYTE" or ":prgmLIB4BYTE" in the subroutine section of your code. The syntax for the commands is also included as comments under each function in the library source files, so you can look there if you need a refresher.


NOTE: The decimal display routine uses OP4-OP5 for scratch memory and OP6 to store the resulting string, so if you're wondering why any data you store there is mysteriously being corrupted, that's why.


EDIT: I just realized there was a slight flaw with my code. But I fixed it and reuploaded the two libraries before anyone could download them (I think). That's why the "by Runer112" is on the end of the filenames, I wasn't sure what else to add.

* LIB3BYTE by Runer112.8xp (1.38 KB - downloaded 45 times.)
* LIB4BYTE by Runer112.8xp (1.45 KB - downloaded 53 times.)
« Last Edit: 20 December, 2010, 09:53:11 by Runer112 » Logged
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 07:31:30
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50214


Total Post Ratings: +2613

View Profile WWW
« Reply #508 on: 20 December, 2010, 05:50:45 »
0

Hmm question, you say pointer to first argument, but I assume this grabs 3 numbers starting there, right? Just wondering. Also does the routine allows you to display such number without adding/substracting? I am curious since this might be useful for games where money or scores can go above 65536, for example.
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:42:54
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #509 on: 20 December, 2010, 05:56:20 »
0

Yes and yes. The arguments should be pointers to where you store the values, not the actual values, because the actual values wouldn't fit in Axe's 2-byte value system. For instance, if you had a 4-byte number spanning variables A-B in memory and a 4-byte number spanning variables C-D, you could add the two values and store the result in A-B like so:

1
sub(ADD,°C,°A,)
(Note the trick employed here. You can do this if you are adding two values and storing the result back into one of the values. Enter the pointer to the value that should serve as both an argument and the answer as the second argument and then leave the third argument blank.)

The display routines can display any number that you can fit in the 3 or 4 bytes of data: 0-16777215 for the 3-byte library and 0-4294967295 for the 4-byte library.



EDIT: Here's a little program I whipped up using the 4-byte library, showing its capabilities. It pases 65536 with ease, but unfortunately it can only go up to about 4 billion. Wink You might recognize the pattern...
(Note that the actual routines run a lot faster than this, I manually set it to iterate only twice per second)

You can look at the source for an example of how to use the commands.

* LIB4DSRC.8xp (0.27 KB - downloaded 37 times.)

* LIB4DEMO.gif (101.82 KB, 192x128 - viewed 244 times.)
« Last Edit: 20 December, 2010, 09:53:43 by Runer112 » Logged
Pages: 1 ... 32 33 [34] 35 36 ... 42   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.315 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.