0x10cAtlas / AtlasOS

An operating system for DCPU-16.
109 stars 15 forks source link

math library #36

Open rustyoz opened 12 years ago

rustyoz commented 12 years ago

a good goal would be for a library supporting

i good starting point might be entropers library https://github.com/Entroper/DCPU-16-fixedmath and a fork from vertarmis https://github.com/vietarmis/DCPU-16-fixedmath/blob/1e2e4ed49bd0e12923ee39e0b1a312fe5ef2314a/fixedmath.dasm

chessmaster42 commented 12 years ago

Sounds good and I think that we should start looking at compiling libraries into binaries using a variation of the ABI format. Make it like loading a dll.

chessmaster42 commented 12 years ago

Ignore what I said earlier. We will just compile this into the library.dasm16 file for now.

chessmaster42 commented 12 years ago

Plusmid and I are working on the format for the equivalent of .dll or .so using the ABI format for libraries. I think we should make a math lib as our first external library. The library will be setup like a normal program but will have a jumptable that is setup like this:

:libmath_api dat add_32 dat sub_32 dat mul_32 dat div_32 :libmath_api_end

Thoughts?

rustyoz commented 12 years ago

sounds good. they way atlas has gone, even though its partly my working, it is getting beyond my skills. im guessing that programs will have a code at their start to load in libraries. functions in the application go to their jump table, then to the libs jump table find the function address and then run the subroutine?

chessmaster42 commented 12 years ago

What will happen is that the program will call a function named, say, lib_run_func, and set A to a buffer with the library name and B to a buffer with the function name like this:

SET A, myLibName SET B, myLibFuncName JSR lib_run_func (this would be translated to the API location [0x1234] format)

Then the OS function lib_run_func searches through the loaded libraries list, finds the library with the matching name, then searches through the jump table of the library to find the function. If it finds it, it then runs it using params pushed onto the stack or maybe registers.

rustyoz commented 12 years ago

ok that makes sense. what about having the lib_run_func use some other registers like x and y so registers a and b which are commonly used don't need to be pushed to the stack as often. if someone makes a library using registers a and b as parameters they wouldn't need to do as much work porting it to atlas by making the functions pop a and b back from the stack.

noxer commented 12 years ago

Then X and Y need to be pushed. The problem is you never know if registers are unused or not. Chessmaster is wrong this his statement the lib_run_func will search the library table. This would take too much time. My approach is to request the library handler first and then the function addresses:

; Get Library handler SET A, my_lib_name JSR lib_get_instance SET B, A

; Get function address SET A, my_lib_func1 JSR lib_get_func

; Save address for future use SET [my_lib_addr1], A

; Call the function JSR [ly_lib_addr1]

; Free the handle (so the library can automatically be unloaded if the instance counter reaches 0) SET A, B JSR lib_free_instance

This may be a bit more compicated but this will (hopefully) be done by the compilers /assemblers later.