You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

## Oops (an Axe library)

0 Members and 1 Guest are viewing this topic.

b/Calculator Development publicado por u/E37 September 27, 2016, 09:07:51 PM

## Oops (an Axe library)

I suppose I need to go on a general overview of what the heck Oops is.
I call it Oops for "Object Oriented Program(s)" - It is the closest (I think) to an OOP you are going to get in Axe.
Oops is really good at managing large amounts of "objects" - like the 20 fighters you need in your game that each need a different amount of ram and need to be run, added and deleted.
Maybe explaining the functions will make it a little clearer.
1. SSet( PointerToListOfLabels, PointerToListOfSizes)
This creates a stack and initializes the pointers.
Example of use:
`:Data(lPlayer^r,lShip1^r,lShip2^r)->labelPointer:Data(15^r,5^r,40^r)-> sizePointer:SSet(labelPointer,sizePointer)`
In this example, the player would get 15 bytes of memory, ship1 would get 5 and ship2 would get 40. There can be up to 256 different types declared here. (Why would anyone need that many?)
Returns 0 if failed. Returns some other number if succeed.

Adds an object. It will be type specified. 0 is the first object, 1 is the second ect. It is in the order declared in SSet(). It will be added in the index specified. 0 is first ect. A negative number here will be the end of the stack.
... And an example:
`:SAdd(0,0):SAdd(2,-1)`
Using the declarations from above, this will add a player at slot 0 (the beginning) and a Ship2 at the end of the stack.
It returns a pointer to the start of the object's data. (use this to initialize it's variables if needed) The object's data will be filled with zeros. Returns 0 if failed.

3. SDelete(Position)
It deletes the object at the specified position. A negative number is the last object on the stack.
Example:
`:SDelete(0)`
Would delete the first object on the stack.
Returns 0 if failed (if there aren't any objects on the stack)

4. SRun()
There is no arguments for this command. It runs all the objects on the stack. Each object is passed a pointer to its memory in r1.
Example (on how the object should be structured)
`:Lbl Player:r1->A:Output(0,0,{A}>Dec:Return`
Player would simply display the value of its first byte. {r1-1} is the object's type.
Note that StkNum is the current number. SDelete(StkNum) would delete the current object.
Returns: none

That's all! The library (when compiled) is less than 500 bytes!
It can be added anywhere inside the program.
The program automatically deletes stack upon exiting. (no need to clean up)
If you need to read the stack yourself, the variable Stack holds the pointer to the start of the stack.
Inicia sesión o crea una cuenta para dejar un comentario
u/Dream of Omnimaga October 06, 2016, 07:08:10 PM
Something I am curious about is the speed at which this runs at. This might broaden the audience of Axe programmers since some people prefer OOP, but if the speed/size cost is too severe then it might be a good idea to fix that (unless that was taken care of already).
u/E37 October 08, 2016, 02:15:28 PM
Quote from: DJ Omnimaga on October 06, 2016, 07:08:10 PM
Something I am curious about is the speed at which this runs at. This might broaden the audience of Axe programmers since some people prefer OOP, but if the speed/size cost is too severe then it might be a good idea to fix that (unless that was taken care of already).
There is almost no overhead. (I ran 2 objects in a loop and there was no noticeable difference than putting those objects in a loop)
Like I mentioned, It isn't a true oop. It is modified to control large amounts of "enemies" allowing the programmer to add, delete and run them easily. (Since it is designed to control 50+ "objects" at once I reduced overhead to a minimum)

The short answer is no. There is almost no slowdown due to the structure.
u/Dream of Omnimaga October 19, 2016, 02:50:03 AM
Ah ok. It's good to see the speed is fast enough then and I like that it can handle 50+ objects at once
u/c4ooo October 19, 2016, 08:01:14 PM
Well, asm is likely to be faster than the best axe code, so unless there is some major flaw in this library, it should be faster than any similar system you write in axe
u/E37 October 19, 2016, 08:30:40 PM
Quote from: c4ooo on October 19, 2016, 08:01:14 PM
Well, asm is likely to be faster than the best axe code, so unless there is some major flaw in this library, it should be faster than any similar system you write in axe
What do you mean? It is a library. Libraries are written in Axe. I included some asm opcodes, but only to add/remove memory.
u/c4ooo October 19, 2016, 08:51:10 PM
Ohh right
My point still applies though

## b/Calculator Development

Showcase your newest TI, Casio, HP, Numworks or Sharp calculator projects here, discuss programming and share or browse user tutorials!

320
Topics
Website statistics

MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators