Join us on Discord!
You can help CodeWalrus stay online by donating here.

Oops (an Axe library)

Started by E37, September 27, 2016, 09:07:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

E37

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.

2. SAdd(Type,Position)
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.
  • Consoles, mobile devices and vintage computers owned: Ti83,Ti84!
I've never finished a project, there is always a way to improve!
What's my calc's name? Convert $37 to decimal. Look up that element in the periodic table. Then take the abbreviation of that element and you have it!
Look! A slime!    <(^.^)>

Dream of Omnimaga

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).
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

E37

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.
  • Consoles, mobile devices and vintage computers owned: Ti83,Ti84!
I've never finished a project, there is always a way to improve!
What's my calc's name? Convert $37 to decimal. Look up that element in the periodic table. Then take the abbreviation of that element and you have it!
Look! A slime!    <(^.^)>

Dream of Omnimaga

Ah ok. It's good to see the speed is fast enough then :) and I like that it can handle 50+ objects at once O.O
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

c4ooo

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 ;)

E37

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.
  • Consoles, mobile devices and vintage computers owned: Ti83,Ti84!
I've never finished a project, there is always a way to improve!
What's my calc's name? Convert $37 to decimal. Look up that element in the periodic table. Then take the abbreviation of that element and you have it!
Look! A slime!    <(^.^)>

c4ooo

Ohh right  :-X
My point still applies though :P

Powered by EzPortal